-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #372 from ligershark/master
Releasing version 1.21
- Loading branch information
Showing
85 changed files
with
1,370 additions
and
296 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.