Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
crwilcox committed Feb 8, 2016
2 parents e127be6 + 5b4be23 commit 397b519
Show file tree
Hide file tree
Showing 429 changed files with 103,196 additions and 19,118 deletions.
24 changes: 24 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Set the default behavior (used when a rule below doesn't match)
* text=auto
*.cs text
*.R text
*.*proj text
*.targets text
*.settings text
*.vssettings text

*.dll -text
*.lib -text
*.sln -text
*.ico -text
*.bmp -text
*.png -text
*.snk -text
*.mht -text
*.pickle -text
*.Rdata -text
*.Rhistory -text

# Some Windows-specific files should always be CRLF
*.bat eol=crlf
*.cmd eol=crlf
Binary file added lib/Microsoft.Office.Interop.Excel.dll
Binary file not shown.
2 changes: 2 additions & 0 deletions src/CodeCoverage.runsettings
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
<Function>^boost::.*</Function>
<Function>^websocketpp::.*</Function>
<Function>^__sc.*</Function>
<Function>.*Resources.*</Function>
<Function>.*ClassificationFormat.*</Function>
</Exclude>
</Functions>
</CodeCoverage>
Expand Down
30 changes: 30 additions & 0 deletions src/Common/Core/Impl/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,35 @@ public static string Replace(this string s, string oldValue, string newValue, in
.Replace(oldValue, newValue, start, length)
.ToString();
}

public static string RemoveWhiteSpaceLines(this string text) {
var sb = new StringBuilder(text);
var lineBreakIndex = sb.Length;
var isWhiteSpaceOnly = true;
for (var i = sb.Length - 1; i >= 0; i--) {
var ch = sb[i];
if (ch == '\r' || ch == '\n') {
if (ch == '\n' && i > 0 && sb[i - 1] == '\r') {
i--;
}

if (isWhiteSpaceOnly) {
sb.Remove(i, lineBreakIndex - i);
} else if (i == 0) {
var rn = sb.Length > 1 && sb[0] == '\r' && sb[1] == '\n';
sb.Remove(0, rn ? 2 : 1);
break;
}

lineBreakIndex = i;
isWhiteSpaceOnly = true;
}

isWhiteSpaceOnly = isWhiteSpaceOnly && char.IsWhiteSpace(ch);
}

return sb.ToString();
}

}
}
1 change: 1 addition & 0 deletions src/Common/Core/Impl/Microsoft.Common.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<Compile Include="..\..\..\GlobalAssemblyInfo.cs">
<Link>Properties\GlobalAssemblyInfo.cs</Link>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Extensions\AssemblyExtensions.cs" />
<Compile Include="Collections\DictionaryExtension.cs" />
<Compile Include="Diagnostics\Check.cs" />
Expand Down
11 changes: 11 additions & 0 deletions src/Common/Core/Impl/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Runtime.CompilerServices;

#if SIGN
[assembly: InternalsVisibleTo("Microsoft.VisualStudio.R.Package.Test, PublicKey=002400000480000094000000060200000024000052534131000400000100010007D1FA57C4AED9F0A32E84AA0FAEFD0DE9E8FD6AEC8F87FB03766C834C99921EB23BE79AD9D5DCC1DD9AD236132102900B723CF980957FC4E177108FC607774F29E8320E92EA05ECE4E821C0A5EFE8F1645C4C0C93C1AB99285D622CAA652C1DFAD63D745D6F2DE5F17E5EAF0FC4963D261C8A12436518206DC093344D5AD293")]
[assembly: InternalsVisibleTo("Microsoft.VisualStudio.R.Interactive.Test, PublicKey=002400000480000094000000060200000024000052534131000400000100010007D1FA57C4AED9F0A32E84AA0FAEFD0DE9E8FD6AEC8F87FB03766C834C99921EB23BE79AD9D5DCC1DD9AD236132102900B723CF980957FC4E177108FC607774F29E8320E92EA05ECE4E821C0A5EFE8F1645C4C0C93C1AB99285D622CAA652C1DFAD63D745D6F2DE5F17E5EAF0FC4963D261C8A12436518206DC093344D5AD293")]
[assembly: InternalsVisibleTo("Microsoft.R.Common.Core.Test, PublicKey=002400000480000094000000060200000024000052534131000400000100010007D1FA57C4AED9F0A32E84AA0FAEFD0DE9E8FD6AEC8F87FB03766C834C99921EB23BE79AD9D5DCC1DD9AD236132102900B723CF980957FC4E177108FC607774F29E8320E92EA05ECE4E821C0A5EFE8F1645C4C0C93C1AB99285D622CAA652C1DFAD63D745D6F2DE5F17E5EAF0FC4963D261C8A12436518206DC093344D5AD293")]
#else
[assembly: InternalsVisibleTo("Microsoft.R.Common.Core.Test")]
[assembly: InternalsVisibleTo("Microsoft.VisualStudio.R.Package.Test")]
[assembly: InternalsVisibleTo("Microsoft.VisualStudio.R.Interactive.Test")]
#endif
9 changes: 9 additions & 0 deletions src/Common/Core/Impl/Shell/ICoreShell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ public interface ICoreShell: ICompositionCatalog {
/// </summary>
void ShowErrorMessage(string message);

/// <summary>
/// Shows the context menu with the specified command ID at the specified location
/// </summary>
/// <param name="contextMenuGroup"></param>
/// <param name="contextMenuId"></param>
/// <param name="x"></param>
/// <param name="y"></param>
void ShowContextMenu(Guid contextMenuGroup, int contextMenuId, int x, int y);

/// <summary>
/// Displays message with specified buttons in a host-specific UI
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions src/Common/Core/Impl/TaskUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

namespace Microsoft.Common.Core {
public static class TaskUtilities {
public static Task CompletedTask = Task.FromResult(0);

public static bool IsOnBackgroundThread() {
var taskScheduler = TaskScheduler.Current;
var syncContext = SynchronizationContext.Current;
Expand Down
4 changes: 2 additions & 2 deletions src/Common/Core/Impl/Telemetry/ITelemetryRecorder.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System.Collections.Generic;
using System;

namespace Microsoft.Common.Core.Telemetry {
/// <summary>
/// Represents object that records telemetry events and is called by
/// the telemetry service. In Visual Studio environment maps to IVsTelemetryService
/// whereas in tests can be replaced by an object that writes events to a string.
/// </summary>
public interface ITelemetryRecorder {
public interface ITelemetryRecorder : IDisposable {
/// <summary>
/// True if telemetry is actually being recorded
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions src/Common/Core/Impl/Telemetry/TelemetryArea.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace Microsoft.Common.Core.Telemetry {
public enum TelemetryArea {
// Keep these sorted
Build,
Configuration,
Debugger,
Editor,
History,
Expand Down
39 changes: 28 additions & 11 deletions src/Common/Core/Impl/Telemetry/TelemetryServiceBase.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using Microsoft.Common.Core.Diagnostics;

namespace Microsoft.Common.Core.Telemetry {
/// <summary>
/// Base telemetry service implementation, common to production code and test cases.
/// </summary>
public abstract class TelemetryServiceBase : ITelemetryService {
public abstract class TelemetryServiceBase : ITelemetryService, IDisposable {
public string EventNamePrefix { get; private set; }
public string PropertyNamePrefix { get; private set; }

Expand Down Expand Up @@ -51,23 +52,39 @@ public bool CanCollectPrivateInformation {
public void ReportEvent(TelemetryArea area, string eventName, object parameters = null) {
Check.ArgumentStringNullOrEmpty("eventName", eventName);

IDictionary<string, object> dict = DictionaryExtension.FromAnonymousObject(parameters);
IDictionary<string, object> dictWithPrefix = new Dictionary<string, object>();
string completeEventName = MakeEventName(area, eventName);
if (parameters == null) {
this.TelemetryRecorder.RecordEvent(completeEventName);
} else if (parameters is string) {
this.TelemetryRecorder.RecordEvent(completeEventName, parameters as string);
} else {
IDictionary<string, object> dict = DictionaryExtension.FromAnonymousObject(parameters);
IDictionary<string, object> dictWithPrefix = new Dictionary<string, object>();

foreach (KeyValuePair<string, object> kvp in dict) {
Check.ArgumentStringNullOrEmpty("parameterName", kvp.Key);
Check.ArgumentNull("parameterValue", kvp.Value);

dictWithPrefix[this.PropertyNamePrefix + area.ToString() + "." + kvp.Key] = kvp.Value;
foreach (KeyValuePair<string, object> kvp in dict) {
Check.ArgumentStringNullOrEmpty("parameterName", kvp.Key);
dictWithPrefix[this.PropertyNamePrefix + area.ToString() + "." + kvp.Key] = kvp.Value ?? string.Empty;
}
this.TelemetryRecorder.RecordEvent(completeEventName, dictWithPrefix);
}

this.TelemetryRecorder.RecordEvent(this.EventNamePrefix + area.ToString() + "/" + eventName, dictWithPrefix);
}

/// <summary>
/// Start a telemetry activity, dispose of the return value when the activity is complete
/// </summary>
public abstract ITelemetryActivity StartActivity(TelemetryArea area, string eventName);
#endregion

private string MakeEventName(TelemetryArea area, string eventName) {
return this.EventNamePrefix + area.ToString() + "/" + eventName;
}

protected virtual void Dispose(bool disposing) { }

public void Dispose() {
Dispose(true);
TelemetryRecorder?.Dispose();
TelemetryRecorder = null;
}
}
}
8 changes: 8 additions & 0 deletions src/Common/Core/Test/Controls/ControlTestScript.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Windows;
using System.Xml.Serialization;
using Microsoft.Common.Core.Test.Script;
using Microsoft.Common.Core.Test.Utility;
using Microsoft.UnitTests.Core.Threading;
Expand All @@ -21,6 +23,12 @@ public void Dispose() {
ControlWindow.Close();
}

public DependencyObject Control {
get {
return ControlWindow.Control;
}
}

public string WriteVisualTree(bool writeProperties = true) {
VisualTreeWriter w = new VisualTreeWriter();
string tree = null;
Expand Down
22 changes: 20 additions & 2 deletions src/Common/Core/Test/Controls/ControlWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Microsoft.Common.Core.Test.Controls {
/// Control window
/// </summary>
[ExcludeFromCodeCoverage]
internal static class ControlWindow {
public static class ControlWindow {
[ExcludeFromCodeCoverage]
class ControlTestRequest {
public Type ControlType { get; }
Expand All @@ -23,10 +23,17 @@ public ControlTestRequest(Type controlType) {
}
}

/// <summary>
/// Component that is being tested. May be same as <see cref="Control"/>
/// or may be different if component is <see cref="IVisualComponent"/>
/// </summary>
public static object Component { get; private set; }

/// <summary>
/// Control that is being tested
/// </summary>
public static Control Control { get; private set; }

/// <summary>
/// WPF window that contains the control
/// </summary>
Expand Down Expand Up @@ -59,7 +66,14 @@ private static void CreateWindowInstance(ControlTestRequest request, ManualReset
Window.Width = 800;
Window.Height = 600;

Control = Activator.CreateInstance(request.ControlType) as Control;
Component = Activator.CreateInstance(request.ControlType);
if(Component is Control) {
Control = Component as Control;
}
else {
Control = Component.GetType().GetProperty("Control").GetValue(Component) as Control;
}

Window.Title = "Control - " + request.ControlType.ToString();
Window.Content = Control;

Expand All @@ -76,6 +90,10 @@ public static void Close() {
var action = new Action(() => {
IDisposable disp = Window.Content as IDisposable;
disp?.Dispose();

disp = Component as IDisposable;
disp?.Dispose();

Window.Close();
});

Expand Down
3 changes: 2 additions & 1 deletion src/Common/Core/Test/Microsoft.Common.Core.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
<Compile Include="Disposables\CountdownDisposableTest.cs" />
<Compile Include="Disposables\DisposableTest.cs" />
<Compile Include="EnumerableExtensionsTest.cs" />
<Compile Include="Script\EventsPump.cs" />
<Compile Include="IO\SubstituteFactories\DirectoryInfoFactory.cs" />
<Compile Include="IO\SubstituteFactories\FileInfoFactory.cs" />
<Compile Include="Script\TestScript.cs" />
Expand All @@ -111,7 +112,7 @@
<Compile Include="Telemetry\FileTelemetryRecorder.cs" />
<Compile Include="Telemetry\ITelemetryTestSupport.cs" />
<Compile Include="Telemetry\SimpleTelemetryEvent.cs" />
<Compile Include="Telemetry\StringTelemetryRecorder.cs" />
<Compile Include="Telemetry\TestTelemetryRecorder.cs" />
<Compile Include="Telemetry\StringTelemetryRecorderTests.cs" />
<Compile Include="Telemetry\TelemetryTestService.cs" />
<Compile Include="Telemetry\TelemetryTestServiceTests.cs" />
Expand Down
17 changes: 17 additions & 0 deletions src/Common/Core/Test/Script/EventsPump.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Threading;
using Microsoft.UnitTests.Core.Threading;

namespace Microsoft.Common.Core.Test.Script {
public static class EventsPump {
public static void DoEvents(int ms) {
UIThreadHelper.Instance.Invoke(() => {
int time = 0;
while (time < ms) {
TestScript.DoEvents();
Thread.Sleep(20);
time += 20;
}
});
}
}
}
27 changes: 27 additions & 0 deletions src/Common/Core/Test/StringExtensionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,32 @@ public class StringExtensionsTest {
public void Replace(string s, string oldValue, string newValue, int start, int length, string expected) {
s.Replace(oldValue, newValue, start, length).Should().Be(expected);
}

[CompositeTest]
[InlineData("\n", "")]
[InlineData("\r\n", "")]
[InlineData("\r\r\n", "")]
[InlineData("aa", "aa")]
[InlineData("aa\n", "aa")]
[InlineData("aa\r", "aa")]
[InlineData("aa\r\n", "aa")]
[InlineData("\raa", "aa")]
[InlineData("\naa", "aa")]
[InlineData("\r\naa", "aa")]
[InlineData(" aa\r\n", " aa")]
[InlineData("\r\n aa\r\n", " aa")]
[InlineData("aa\nbb", "aa\nbb")]
[InlineData("aa\rbb", "aa\rbb")]
[InlineData("aa\r\nbb", "aa\r\nbb")]
[InlineData("aa\n\r\nbb", "aa\r\nbb")]
[InlineData("aa\r\n\r\nbb", "aa\r\nbb")]
[InlineData("aa\r\nbb\n", "aa\r\nbb")]
[InlineData("aa\n\r\nbb\r\n", "aa\r\nbb")]
[InlineData("aa\r\n\r\nbb\r", "aa\r\nbb")]
[InlineData("aa\r\n \r\nbb\r\n", "aa\r\nbb")]
[InlineData("aa\r\n \r\nbb\r\n \r\n cc \r\n", "aa\r\nbb\r\n cc ")]
public void RemoveWhiteSpaceLines(string s, string expected) {
s.RemoveWhiteSpaceLines().Should().Be(expected);
}
}
}
2 changes: 2 additions & 0 deletions src/Common/Core/Test/Telemetry/FileTelemetryRecorder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,7 @@ public void RecordActivity(object telemetryActivity) {
}
}
}

public void Dispose() { }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class StringTelemetryRecorderTests {
[CompositeTest]
[InlineData("event")]
public void StringTelemetryRecorder_SimpleEventTest(string eventName) {
var telemetryRecorder = new StringTelemetryRecorder();
var telemetryRecorder = new TestTelemetryRecorder();
telemetryRecorder.RecordEvent(eventName);

string log = telemetryRecorder.SessionLog;
Expand All @@ -20,7 +20,7 @@ public void StringTelemetryRecorder_SimpleEventTest(string eventName) {
[CompositeTest]
[InlineData("event", "parameter1", "value1", "parameter2", "value2")]
public void StringTelemetryRecorder_EventWithDictionaryTest(string eventName, string parameter1, string value1, string parameter2, string value2) {
var telemetryRecorder = new StringTelemetryRecorder();
var telemetryRecorder = new TestTelemetryRecorder();
telemetryRecorder.RecordEvent(eventName, new Dictionary<string, object>() { { parameter1, value1 }, { parameter2, value2 } });

string log = telemetryRecorder.SessionLog;
Expand All @@ -30,7 +30,7 @@ public void StringTelemetryRecorder_EventWithDictionaryTest(string eventName, st
[CompositeTest]
[InlineData("event")]
public void StringTelemetryRecorder_EventWithAnonymousCollectionTest(string eventName) {
var telemetryRecorder = new StringTelemetryRecorder();
var telemetryRecorder = new TestTelemetryRecorder();
telemetryRecorder.RecordEvent(eventName, new { parameter1 = "value1", parameter2 = "value2" });

string log = telemetryRecorder.SessionLog;
Expand Down
2 changes: 1 addition & 1 deletion src/Common/Core/Test/Telemetry/TelemetryTestService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public sealed class TelemetryTestService : TelemetryServiceBase, ITelemetryTestS
public static readonly string PropertyNamePrefixString = "Test.RTVS.";

public TelemetryTestService(string eventNamePrefix, string propertyNamePrefix) :
base(eventNamePrefix, propertyNamePrefix, new StringTelemetryRecorder()) {
base(eventNamePrefix, propertyNamePrefix, new TestTelemetryRecorder()) {

}

Expand Down
Loading

0 comments on commit 397b519

Please sign in to comment.