Skip to content

Commit aaf06e4

Browse files
committed
Merge pull request #372 from ligershark/master
Releasing version 1.21
2 parents 062cadd + bde13a6 commit aaf06e4

File tree

85 files changed

+1370
-296
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+1370
-296
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel;
4+
using System.Globalization;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
using EnvDTE;
9+
using Microsoft.VisualStudio.Shell.Interop;
10+
using Microsoft.VisualStudio.TemplateWizard;
11+
12+
namespace LigerShark.Templates
13+
{
14+
/// <summary>
15+
/// Custom wizard used by the Angular2 item templates to produce proper names
16+
/// </summary>
17+
public class Angular2RenameWizard : Component, IWizard
18+
{
19+
public void RunStarted(object automationObject, Dictionary<string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams)
20+
{
21+
try
22+
{
23+
var safeItemName = replacementsDictionary["$safeitemname$"];
24+
var properName = safeItemName;
25+
26+
if (safeItemName.Contains("."))
27+
{
28+
var indexOfPeriod = safeItemName.IndexOf(".", StringComparison.CurrentCulture);
29+
properName = safeItemName.Remove(indexOfPeriod);
30+
}
31+
32+
properName = FromCamelCase(properName);
33+
34+
replacementsDictionary.Add("$properName$", properName);
35+
}
36+
catch (Exception ex)
37+
{
38+
LogError(ex.ToString());
39+
}
40+
41+
}
42+
43+
public void ProjectFinishedGenerating(Project project)
44+
{
45+
46+
}
47+
48+
public void ProjectItemFinishedGenerating(ProjectItem projectItem)
49+
{
50+
51+
}
52+
53+
public bool ShouldAddProjectItem(string filePath)
54+
{
55+
return true;
56+
}
57+
58+
public void BeforeOpeningFile(ProjectItem projectItem)
59+
{
60+
}
61+
62+
public void RunFinished()
63+
{
64+
}
65+
66+
private string FromCamelCase(string value)
67+
{
68+
if (string.IsNullOrEmpty(value))
69+
{
70+
return value;
71+
}
72+
if (char.IsUpper(value[0]))
73+
{
74+
return value;
75+
}
76+
77+
var chArray = value.ToCharArray();
78+
79+
if (value.Length < 3)
80+
{
81+
chArray[0] = char.ToUpper(chArray[0], CultureInfo.InvariantCulture);
82+
}
83+
else
84+
{
85+
86+
if (char.IsUpper(chArray[2]))
87+
{
88+
for (var i = 0; i < 2; i++)
89+
{
90+
chArray[i] = char.ToUpper(chArray[i], CultureInfo.InvariantCulture);
91+
}
92+
}
93+
else
94+
{
95+
chArray[0] = char.ToUpper(chArray[0], CultureInfo.InvariantCulture);
96+
}
97+
}
98+
return new string(chArray);
99+
}
100+
101+
private void LogError(string message)
102+
{
103+
try
104+
{
105+
IVsActivityLog _log = GetService(typeof(SVsActivityLog)) as IVsActivityLog;
106+
107+
_log.LogEntry(
108+
(UInt32)__ACTIVITYLOG_ENTRYTYPE.ALE_ERROR,
109+
this.ToString(),
110+
string.Format(CultureInfo.CurrentCulture, "{0}", message));
111+
}
112+
catch (Exception)
113+
{
114+
// there was likely an error getting the activity service, ignore it so it won't throw
115+
}
116+
}
117+
}
118+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel;
4+
using System.Globalization;
5+
using EnvDTE;
6+
using Microsoft.VisualStudio.Shell.Interop;
7+
using Microsoft.VisualStudio.TemplateWizard;
8+
9+
namespace LigerShark.Templates
10+
{
11+
public class AngularDirectiveUsageWizard : Component, IWizard
12+
{
13+
public void RunStarted(object automationObject, Dictionary<string, string> replacementsDictionary,
14+
WizardRunKind runKind, object[] customParams)
15+
{
16+
try
17+
{
18+
var safeItemName = replacementsDictionary["$safeitemname$"];
19+
var directiveUsage = ToDirectiveUsage(safeItemName);
20+
21+
replacementsDictionary.Add("$directiveUsage$", directiveUsage);
22+
}
23+
catch (Exception ex)
24+
{
25+
LogError(ex.ToString());
26+
}
27+
}
28+
29+
public void ProjectFinishedGenerating(Project project)
30+
{
31+
}
32+
33+
public void ProjectItemFinishedGenerating(ProjectItem projectItem)
34+
{
35+
}
36+
37+
public bool ShouldAddProjectItem(string filePath)
38+
{
39+
return true;
40+
}
41+
42+
public void BeforeOpeningFile(ProjectItem projectItem)
43+
{
44+
}
45+
46+
public void RunFinished()
47+
{
48+
}
49+
50+
private string ToDirectiveUsage(string value)
51+
{
52+
if (string.IsNullOrEmpty(value))
53+
{
54+
return value;
55+
}
56+
57+
var originalValueArrray = value.ToCharArray();
58+
59+
// Initializes the list with the first character in the original value
60+
var directiveUsage = new List<char>
61+
{
62+
char.ToLower(originalValueArrray[0])
63+
};
64+
65+
// Loops through the original value array and finds any upper case character
66+
// then adds a hyphen and converts the original character to lower case
67+
for (var i = 1; i < originalValueArrray.Length; i++)
68+
{
69+
if (char.IsUpper(originalValueArrray[i]))
70+
{
71+
directiveUsage.Add('-');
72+
directiveUsage.Add(char.ToLower(originalValueArrray[i]));
73+
}
74+
else
75+
{
76+
directiveUsage.Add(originalValueArrray[i]);
77+
}
78+
}
79+
80+
return new string(directiveUsage.ToArray());
81+
}
82+
83+
84+
private void LogError(string message)
85+
{
86+
try
87+
{
88+
var log = GetService(typeof(SVsActivityLog)) as IVsActivityLog;
89+
90+
log.LogEntry(
91+
(uint)__ACTIVITYLOG_ENTRYTYPE.ALE_ERROR,
92+
ToString(),
93+
string.Format(CultureInfo.CurrentCulture, "{0}", message));
94+
}
95+
catch (Exception)
96+
{
97+
// there was likely an error getting the activity service, ignore it so it won't throw
98+
}
99+
}
100+
}
101+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using Newtonsoft.Json;
2+
using System.IO;
3+
using System;
4+
using System.ComponentModel;
5+
6+
namespace LigerShark.Templates.DynamicBuilder
7+
{
8+
public class SettingsStore
9+
{
10+
[DefaultValue(true)]
11+
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)]
12+
public bool SendTelemetry { get; set; }
13+
14+
public static SettingsStore ReadJsonFile(string filePath)
15+
{
16+
if (string.IsNullOrEmpty(filePath)) { throw new ArgumentNullException("filePath"); }
17+
18+
if (!File.Exists(filePath))
19+
{
20+
throw new FileNotFoundException(string.Format(@"JSON settings file not found at [{0}]", filePath));
21+
}
22+
23+
return JsonConvert.DeserializeObject<SettingsStore>(File.ReadAllText(filePath));
24+
}
25+
26+
public void WriteJsonFile(string filePath, string json)
27+
{
28+
var fileInfo = new FileInfo(filePath);
29+
30+
if (!fileInfo.Directory.Exists)
31+
{
32+
fileInfo.Directory.Create();
33+
}
34+
35+
File.WriteAllText(filePath, json);
36+
}
37+
}
38+
}

LigerShark.Templates/GoogleAnalyticsWizard.cs

+23-12
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
using EnvDTE;
2+
using LigerShark.Templates.DynamicBuilder;
23
using Microsoft.VisualStudio.Shell.Interop;
34
using Microsoft.VisualStudio.TemplateWizard;
45
using System;
56
using System.Collections.Generic;
7+
using System.ComponentModel;
68
using System.Globalization;
9+
using System.IO;
710
using System.Security.Cryptography;
811
using System.Text;
9-
using System.ComponentModel;
1012

1113
namespace LigerShark.Templates
1214
{
@@ -68,19 +70,28 @@ public bool ShouldAddProjectItem(string filePath)
6870

6971
private void TrackTemplate(string templateID, string templateName, string templateType)
7072
{
71-
var result = GetHashString(Environment.UserDomainName + Environment.MachineName);
72-
var category = templateType;
73-
if (string.Compare("Project", templateType, StringComparison.OrdinalIgnoreCase) == 0)
74-
{
75-
category = "project-template";
76-
}
77-
else if (string.Compare("Item", templateType, StringComparison.OrdinalIgnoreCase) == 0)
73+
// Get the file path where the settings are being stored.
74+
var rootDir = Environment.ExpandEnvironmentVariables(@"%localappdata%\LigerShark\SideWaffle\");
75+
var filePath = Path.Combine(rootDir, "SideWaffle-Settings.json");
76+
bool telemetry = SettingsStore.ReadJsonFile(filePath).SendTelemetry;
77+
78+
if (telemetry)
7879
{
79-
category = "item-template";
80-
}
80+
var category = templateType;
81+
if (string.Compare("Project", templateType, StringComparison.OrdinalIgnoreCase) == 0)
82+
{
83+
category = "project-template";
84+
}
85+
else if (string.Compare("Item", templateType, StringComparison.OrdinalIgnoreCase) == 0)
86+
{
87+
category = "item-template";
88+
}
89+
90+
var result = GetHashString(Environment.UserDomainName + Environment.MachineName);
8191

82-
GoogleAnalyticsApi tracker = new GoogleAnalyticsApi("UA-62483606-4", result);
83-
tracker.TrackEvent(category, "add", templateName);
92+
GoogleAnalyticsApi tracker = new GoogleAnalyticsApi("UA-62483606-4", result);
93+
tracker.TrackEvent(category, "add", templateName);
94+
}
8495
}
8596

8697
public string GetHashString(string text)

LigerShark.Templates/LigerShark.Templates.csproj

+14
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@
7272
<Reference Include="Microsoft.VisualStudio.Shell.Interop.8.0, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
7373
<Reference Include="Microsoft.VisualStudio.Shell.Interop.9.0, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
7474
<Reference Include="Microsoft.VisualStudio.TextManager.Interop, Version=7.1.40304.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
75+
<Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
76+
<HintPath>..\packages\Newtonsoft.Json.8.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
77+
<Private>True</Private>
78+
</Reference>
7579
<Reference Include="stdole, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
7680
<EmbedInteropTypes>True</EmbedInteropTypes>
7781
</Reference>
@@ -84,6 +88,8 @@
8488
<Reference Include="System.Net.Http.WebRequest" />
8589
<Reference Include="System.ServiceModel" />
8690
<Reference Include="System.Web" />
91+
<Reference Include="System.Web.Extensions" />
92+
<Reference Include="System.Windows.Forms" />
8793
<Reference Include="System.Xml" />
8894
<Reference Include="Microsoft.CSharp" />
8995
<Reference Include="System.Core" />
@@ -101,10 +107,17 @@
101107
<Reference Include="Microsoft.VisualStudio.TemplateWizardInterface, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
102108
</ItemGroup>
103109
<ItemGroup>
110+
<Compile Include="DynamicBuilder\SettingsStore.cs" />
104111
<Page Include="DownloadZipWindow.xaml">
105112
<SubType>Designer</SubType>
106113
<Generator>MSBuild:Compile</Generator>
107114
</Page>
115+
<Compile Include="AngularDirectiveUsageWizard.cs">
116+
<SubType>Component</SubType>
117+
</Compile>
118+
<Compile Include="Angular2RenameWizard.cs">
119+
<SubType>Component</SubType>
120+
</Compile>
108121
<Compile Include="DirectoryHelper.cs" />
109122
<Compile Include="Downloader.cs" />
110123
<Compile Include="DownloadZipWindow.xaml.cs">
@@ -138,6 +151,7 @@
138151
<Generator>ResXFileCodeGenerator</Generator>
139152
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
140153
</EmbeddedResource>
154+
<None Include="packages.config" />
141155
<None Include="Properties\Settings.settings">
142156
<Generator>SettingsSingleFileGenerator</Generator>
143157
<LastGenOutput>Settings.Designer.cs</LastGenOutput>

LigerShark.Templates/packages.config

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="Newtonsoft.Json" version="8.0.1" targetFramework="net451" />
4+
</packages>

0 commit comments

Comments
 (0)