Skip to content

Commit

Permalink
Merge pull request #372 from ligershark/master
Browse files Browse the repository at this point in the history
Releasing version 1.21
  • Loading branch information
sayedihashimi committed Apr 20, 2016
2 parents 062cadd + bde13a6 commit aaf06e4
Show file tree
Hide file tree
Showing 85 changed files with 1,370 additions and 296 deletions.
118 changes: 118 additions & 0 deletions LigerShark.Templates/Angular2RenameWizard.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EnvDTE;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.TemplateWizard;

namespace LigerShark.Templates
{
/// <summary>
/// Custom wizard used by the Angular2 item templates to produce proper names
/// </summary>
public class Angular2RenameWizard : Component, IWizard
{
public void RunStarted(object automationObject, Dictionary<string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams)
{
try
{
var safeItemName = replacementsDictionary["$safeitemname$"];
var properName = safeItemName;

if (safeItemName.Contains("."))
{
var indexOfPeriod = safeItemName.IndexOf(".", StringComparison.CurrentCulture);
properName = safeItemName.Remove(indexOfPeriod);
}

properName = FromCamelCase(properName);

replacementsDictionary.Add("$properName$", properName);
}
catch (Exception ex)
{
LogError(ex.ToString());
}

}

public void ProjectFinishedGenerating(Project project)
{

}

public void ProjectItemFinishedGenerating(ProjectItem projectItem)
{

}

public bool ShouldAddProjectItem(string filePath)
{
return true;
}

public void BeforeOpeningFile(ProjectItem projectItem)
{
}

public void RunFinished()
{
}

private string FromCamelCase(string value)
{
if (string.IsNullOrEmpty(value))
{
return value;
}
if (char.IsUpper(value[0]))
{
return value;
}

var chArray = value.ToCharArray();

if (value.Length < 3)
{
chArray[0] = char.ToUpper(chArray[0], CultureInfo.InvariantCulture);
}
else
{

if (char.IsUpper(chArray[2]))
{
for (var i = 0; i < 2; i++)
{
chArray[i] = char.ToUpper(chArray[i], CultureInfo.InvariantCulture);
}
}
else
{
chArray[0] = char.ToUpper(chArray[0], CultureInfo.InvariantCulture);
}
}
return new string(chArray);
}

private void LogError(string message)
{
try
{
IVsActivityLog _log = GetService(typeof(SVsActivityLog)) as IVsActivityLog;

_log.LogEntry(
(UInt32)__ACTIVITYLOG_ENTRYTYPE.ALE_ERROR,
this.ToString(),
string.Format(CultureInfo.CurrentCulture, "{0}", message));
}
catch (Exception)
{
// there was likely an error getting the activity service, ignore it so it won't throw
}
}
}
}
101 changes: 101 additions & 0 deletions LigerShark.Templates/AngularDirectiveUsageWizard.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using EnvDTE;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.TemplateWizard;

namespace LigerShark.Templates
{
public class AngularDirectiveUsageWizard : Component, IWizard
{
public void RunStarted(object automationObject, Dictionary<string, string> replacementsDictionary,
WizardRunKind runKind, object[] customParams)
{
try
{
var safeItemName = replacementsDictionary["$safeitemname$"];
var directiveUsage = ToDirectiveUsage(safeItemName);

replacementsDictionary.Add("$directiveUsage$", directiveUsage);
}
catch (Exception ex)
{
LogError(ex.ToString());
}
}

public void ProjectFinishedGenerating(Project project)
{
}

public void ProjectItemFinishedGenerating(ProjectItem projectItem)
{
}

public bool ShouldAddProjectItem(string filePath)
{
return true;
}

public void BeforeOpeningFile(ProjectItem projectItem)
{
}

public void RunFinished()
{
}

private string ToDirectiveUsage(string value)
{
if (string.IsNullOrEmpty(value))
{
return value;
}

var originalValueArrray = value.ToCharArray();

// Initializes the list with the first character in the original value
var directiveUsage = new List<char>
{
char.ToLower(originalValueArrray[0])
};

// Loops through the original value array and finds any upper case character
// then adds a hyphen and converts the original character to lower case
for (var i = 1; i < originalValueArrray.Length; i++)
{
if (char.IsUpper(originalValueArrray[i]))
{
directiveUsage.Add('-');
directiveUsage.Add(char.ToLower(originalValueArrray[i]));
}
else
{
directiveUsage.Add(originalValueArrray[i]);
}
}

return new string(directiveUsage.ToArray());
}


private void LogError(string message)
{
try
{
var log = GetService(typeof(SVsActivityLog)) as IVsActivityLog;

log.LogEntry(
(uint)__ACTIVITYLOG_ENTRYTYPE.ALE_ERROR,
ToString(),
string.Format(CultureInfo.CurrentCulture, "{0}", message));
}
catch (Exception)
{
// there was likely an error getting the activity service, ignore it so it won't throw
}
}
}
}
38 changes: 38 additions & 0 deletions LigerShark.Templates/DynamicBuilder/SettingsStore.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Newtonsoft.Json;
using System.IO;
using System;
using System.ComponentModel;

namespace LigerShark.Templates.DynamicBuilder
{
public class SettingsStore
{
[DefaultValue(true)]
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)]
public bool SendTelemetry { get; set; }

public static SettingsStore ReadJsonFile(string filePath)
{
if (string.IsNullOrEmpty(filePath)) { throw new ArgumentNullException("filePath"); }

if (!File.Exists(filePath))
{
throw new FileNotFoundException(string.Format(@"JSON settings file not found at [{0}]", filePath));
}

return JsonConvert.DeserializeObject<SettingsStore>(File.ReadAllText(filePath));
}

public void WriteJsonFile(string filePath, string json)
{
var fileInfo = new FileInfo(filePath);

if (!fileInfo.Directory.Exists)
{
fileInfo.Directory.Create();
}

File.WriteAllText(filePath, json);
}
}
}
35 changes: 23 additions & 12 deletions LigerShark.Templates/GoogleAnalyticsWizard.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using EnvDTE;
using LigerShark.Templates.DynamicBuilder;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.TemplateWizard;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using System.ComponentModel;

namespace LigerShark.Templates
{
Expand Down Expand Up @@ -68,19 +70,28 @@ public bool ShouldAddProjectItem(string filePath)

private void TrackTemplate(string templateID, string templateName, string templateType)
{
var result = GetHashString(Environment.UserDomainName + Environment.MachineName);
var category = templateType;
if (string.Compare("Project", templateType, StringComparison.OrdinalIgnoreCase) == 0)
{
category = "project-template";
}
else if (string.Compare("Item", templateType, StringComparison.OrdinalIgnoreCase) == 0)
// Get the file path where the settings are being stored.
var rootDir = Environment.ExpandEnvironmentVariables(@"%localappdata%\LigerShark\SideWaffle\");
var filePath = Path.Combine(rootDir, "SideWaffle-Settings.json");
bool telemetry = SettingsStore.ReadJsonFile(filePath).SendTelemetry;

if (telemetry)
{
category = "item-template";
}
var category = templateType;
if (string.Compare("Project", templateType, StringComparison.OrdinalIgnoreCase) == 0)
{
category = "project-template";
}
else if (string.Compare("Item", templateType, StringComparison.OrdinalIgnoreCase) == 0)
{
category = "item-template";
}

var result = GetHashString(Environment.UserDomainName + Environment.MachineName);

GoogleAnalyticsApi tracker = new GoogleAnalyticsApi("UA-62483606-4", result);
tracker.TrackEvent(category, "add", templateName);
GoogleAnalyticsApi tracker = new GoogleAnalyticsApi("UA-62483606-4", result);
tracker.TrackEvent(category, "add", templateName);
}
}

public string GetHashString(string text)
Expand Down
14 changes: 14 additions & 0 deletions LigerShark.Templates/LigerShark.Templates.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@
<Reference Include="Microsoft.VisualStudio.Shell.Interop.8.0, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<Reference Include="Microsoft.VisualStudio.Shell.Interop.9.0, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<Reference Include="Microsoft.VisualStudio.TextManager.Interop, Version=7.1.40304.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.8.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="stdole, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
Expand All @@ -84,6 +88,8 @@
<Reference Include="System.Net.Http.WebRequest" />
<Reference Include="System.ServiceModel" />
<Reference Include="System.Web" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" />
Expand All @@ -101,10 +107,17 @@
<Reference Include="Microsoft.VisualStudio.TemplateWizardInterface, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
</ItemGroup>
<ItemGroup>
<Compile Include="DynamicBuilder\SettingsStore.cs" />
<Page Include="DownloadZipWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Compile Include="AngularDirectiveUsageWizard.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Angular2RenameWizard.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="DirectoryHelper.cs" />
<Compile Include="Downloader.cs" />
<Compile Include="DownloadZipWindow.xaml.cs">
Expand Down Expand Up @@ -138,6 +151,7 @@
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
Expand Down
4 changes: 4 additions & 0 deletions LigerShark.Templates/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="8.0.1" targetFramework="net451" />
</packages>
Loading

0 comments on commit aaf06e4

Please sign in to comment.