diff --git a/.vs/Nadia.C.Sharp/xs/UserPrefs.xml b/.vs/Nadia.C.Sharp/xs/UserPrefs.xml new file mode 100644 index 0000000..94a4738 --- /dev/null +++ b/.vs/Nadia.C.Sharp/xs/UserPrefs.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.vs/Nadia.C.Sharp/xs/sqlite3/db.lock b/.vs/Nadia.C.Sharp/xs/sqlite3/db.lock new file mode 100644 index 0000000..e69de29 diff --git a/.vs/Nadia.C.Sharp/xs/sqlite3/storage.ide b/.vs/Nadia.C.Sharp/xs/sqlite3/storage.ide new file mode 100644 index 0000000..95e892b Binary files /dev/null and b/.vs/Nadia.C.Sharp/xs/sqlite3/storage.ide differ diff --git a/.vs/Nadia.C.Sharp/xs/sqlite3/storage.ide-shm b/.vs/Nadia.C.Sharp/xs/sqlite3/storage.ide-shm new file mode 100644 index 0000000..b0b416b Binary files /dev/null and b/.vs/Nadia.C.Sharp/xs/sqlite3/storage.ide-shm differ diff --git a/.vs/Nadia.C.Sharp/xs/sqlite3/storage.ide-wal b/.vs/Nadia.C.Sharp/xs/sqlite3/storage.ide-wal new file mode 100644 index 0000000..1a4cc40 Binary files /dev/null and b/.vs/Nadia.C.Sharp/xs/sqlite3/storage.ide-wal differ diff --git a/Nadia.C.Sharp.sln b/Nadia.C.Sharp.sln new file mode 100644 index 0000000..fc55385 --- /dev/null +++ b/Nadia.C.Sharp.sln @@ -0,0 +1,17 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nadia.C.Sharp", "Nadia.C.Sharp\Nadia.C.Sharp.csproj", "{E5A172D3-CE33-4031-84EA-35835913261E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x86 = Debug|x86 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E5A172D3-CE33-4031-84EA-35835913261E}.Debug|x86.ActiveCfg = Debug|x86 + {E5A172D3-CE33-4031-84EA-35835913261E}.Debug|x86.Build.0 = Debug|x86 + {E5A172D3-CE33-4031-84EA-35835913261E}.Release|x86.ActiveCfg = Release|x86 + {E5A172D3-CE33-4031-84EA-35835913261E}.Release|x86.Build.0 = Release|x86 + EndGlobalSection +EndGlobal diff --git a/Nadia.C.Sharp/.vs/Nadia.C.Sharp/xs/UserPrefs.xml b/Nadia.C.Sharp/.vs/Nadia.C.Sharp/xs/UserPrefs.xml new file mode 100644 index 0000000..68de3ff --- /dev/null +++ b/Nadia.C.Sharp/.vs/Nadia.C.Sharp/xs/UserPrefs.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Nadia.C.Sharp/.vs/Nadia.C.Sharp/xs/sqlite3/db.lock b/Nadia.C.Sharp/.vs/Nadia.C.Sharp/xs/sqlite3/db.lock new file mode 100644 index 0000000..e69de29 diff --git a/Nadia.C.Sharp/.vs/Nadia.C.Sharp/xs/sqlite3/storage.ide b/Nadia.C.Sharp/.vs/Nadia.C.Sharp/xs/sqlite3/storage.ide new file mode 100644 index 0000000..94d093b Binary files /dev/null and b/Nadia.C.Sharp/.vs/Nadia.C.Sharp/xs/sqlite3/storage.ide differ diff --git a/Nadia.C.Sharp/.vs/Nadia.C.Sharp/xs/sqlite3/storage.ide-shm b/Nadia.C.Sharp/.vs/Nadia.C.Sharp/xs/sqlite3/storage.ide-shm new file mode 100644 index 0000000..0187c93 Binary files /dev/null and b/Nadia.C.Sharp/.vs/Nadia.C.Sharp/xs/sqlite3/storage.ide-shm differ diff --git a/Nadia.C.Sharp/.vs/Nadia.C.Sharp/xs/sqlite3/storage.ide-wal b/Nadia.C.Sharp/.vs/Nadia.C.Sharp/xs/sqlite3/storage.ide-wal new file mode 100644 index 0000000..bb239d1 Binary files /dev/null and b/Nadia.C.Sharp/.vs/Nadia.C.Sharp/xs/sqlite3/storage.ide-wal differ diff --git a/Nadia.C.Sharp/FactValue Folder/FactBooleanValue.cs b/Nadia.C.Sharp/FactValue Folder/FactBooleanValue.cs new file mode 100644 index 0000000..560409f --- /dev/null +++ b/Nadia.C.Sharp/FactValue Folder/FactBooleanValue.cs @@ -0,0 +1,49 @@ +using System; +namespace Nadia.C.Sharp.FactValueFolder +{ + public class FactBooleanValue : FactValue + { + private bool value; + private bool? defaultValue; //bool? means nullable bool primative type + + public FactBooleanValue(bool booleanValue) + { + SetValue(booleanValue); + } + + + public void SetValue(bool booleanValue) + { + this.value = booleanValue; + } + + public FactValue NegatingValue() + { + return FactValue.Parse(!this.value); + } + + public override FactValueType GetFactValueType() + { + return FactValueType.BOOLEAN; + } + + + public override void SetDefaultValue(T defaultValue) + { + this.defaultValue = (bool)Convert.ChangeType(defaultValue, typeof(bool)); + } + + + public override T GetValue() + { + return (T)Convert.ChangeType(this.value, typeof(T)); + } + + + public override T GetDefaultValue() + { + return (T)Convert.ChangeType(this.defaultValue, typeof(T)); + } + + } +} diff --git a/Nadia.C.Sharp/FactValue Folder/FactDateValue.cs b/Nadia.C.Sharp/FactValue Folder/FactDateValue.cs new file mode 100644 index 0000000..2bb6b4a --- /dev/null +++ b/Nadia.C.Sharp/FactValue Folder/FactDateValue.cs @@ -0,0 +1,44 @@ +using System; +namespace Nadia.C.Sharp.FactValueFolder +{ + public class FactDateValue : FactValue + { + private DateTime value; + private DateTime defaultValue; + + public FactDateValue(DateTime date) + { + SetValue(date); + } + + public void SetValue(DateTime cal) + { + this.value = cal; + } + + + public override T GetValue() + { + return (T)Convert.ChangeType(this.value, typeof(T)); + } + + + + public override T GetDefaultValue() + { + return (T)Convert.ChangeType(this.defaultValue, typeof(T)); + } + + + public override FactValueType GetFactValueType() + { + return FactValueType.DATE; + } + + public override void SetDefaultValue(T defaultValue) + { + this.defaultValue = (DateTime)Convert.ChangeType(defaultValue, typeof(DateTime)); + } + + } +} diff --git a/Nadia.C.Sharp/FactValue Folder/FactDefiStringValue.cs b/Nadia.C.Sharp/FactValue Folder/FactDefiStringValue.cs new file mode 100644 index 0000000..7d1bbb8 --- /dev/null +++ b/Nadia.C.Sharp/FactValue Folder/FactDefiStringValue.cs @@ -0,0 +1,50 @@ +using System; +using System.Text.RegularExpressions; + +namespace Nadia.C.Sharp.FactValueFolder +{ + public class FactDefiStringValue : FactValue + { + private string value; + private string defaultValue; + private string pattern = @"^("")(.*)("")(.)*"; + //private Regex regex = new Regex(pattern); + private Match match; + + public FactDefiStringValue(string s) + { + match = Regex.Match(s, pattern); + if (match.Success) + { + SetValue(match.Groups[2].Value); + } + } + public void SetValue(string s) + { + this.value = s; + } + + + public override FactValueType GetFactValueType() + { + return FactValueType.DEFI_STRING; + } + + public override void SetDefaultValue(T defaultValue) + { + this.defaultValue = defaultValue.ToString(); + } + + public override T GetValue() + { + // TODO Auto-generated method stub + return (T)Convert.ChangeType(this.value, typeof(T)); + } + + public override T GetDefaultValue() + { + // TODO Auto-generated method stub + return (T)Convert.ChangeType(this.defaultValue, typeof(T)); + } + } +} diff --git a/Nadia.C.Sharp/FactValue Folder/FactDoubleValue.cs b/Nadia.C.Sharp/FactValue Folder/FactDoubleValue.cs new file mode 100644 index 0000000..43e7eb2 --- /dev/null +++ b/Nadia.C.Sharp/FactValue Folder/FactDoubleValue.cs @@ -0,0 +1,45 @@ +using System; +namespace Nadia.C.Sharp.FactValueFolder +{ + public class FactDoubleValue : FactValue + { + private double value; + private double? defaultValue; //double? means nullable double primative type + + public FactDoubleValue(double d) + { + SetValue(d); + } + + public void SetValue(double d) + { + this.value = d; + } + + + public override T GetValue() + { + return (T)Convert.ChangeType(this.value, typeof(T)); + } + + + + public override T GetDefaultValue() + { + return (T)Convert.ChangeType(this.defaultValue, typeof(T)); + } + + + public override FactValueType GetFactValueType() + { + return FactValueType.DECIMAL; + } + + + public override void SetDefaultValue(T defaultValue) + { + this.defaultValue = (double)Convert.ChangeType(defaultValue, typeof(double)); + } + + } +} diff --git a/Nadia.C.Sharp/FactValue Folder/FactHashValue.cs b/Nadia.C.Sharp/FactValue Folder/FactHashValue.cs new file mode 100644 index 0000000..0340840 --- /dev/null +++ b/Nadia.C.Sharp/FactValue Folder/FactHashValue.cs @@ -0,0 +1,46 @@ +using System; +namespace Nadia.C.Sharp.FactValueFolder +{ + public class FactHashValue : FactValue + { + private String value; + private String defaultValue; + + public FactHashValue(String hash) + { + SetValue(hash); + } + + + + public void SetValue(String hash) + { + this.value = hash; + } + + + public override FactValueType GetFactValueType() + { + return FactValueType.HASH; + } + + + public override void SetDefaultValue(T defaultValue) + { + this.defaultValue = (string)Convert.ChangeType(defaultValue, typeof(string)); + } + + + public override T GetValue() + { + return (T)Convert.ChangeType(this.value, typeof(T)); + } + + + public override T GetDefaultValue() + { + return (T)Convert.ChangeType(this.defaultValue, typeof(T)); + } + + } +} diff --git a/Nadia.C.Sharp/FactValue Folder/FactIntegerValue.cs b/Nadia.C.Sharp/FactValue Folder/FactIntegerValue.cs new file mode 100644 index 0000000..21393eb --- /dev/null +++ b/Nadia.C.Sharp/FactValue Folder/FactIntegerValue.cs @@ -0,0 +1,49 @@ +using System; +namespace Nadia.C.Sharp.FactValueFolder +{ + public class FactIntegerValue : FactValue + { + private int value; + private int? defaultValue = null; //int? means nullable int primative type + + public FactIntegerValue(int i) + { + SetValue(i); + } + + + + public void SetValue(int value) + { + this.value = value; + } + + + + public override FactValueType GetFactValueType() + { + return FactValueType.INTEGER; + } + + + public override void SetDefaultValue(T defaultValue) + { + this.defaultValue = (int)Convert.ChangeType(defaultValue, typeof(int)); + } + + + public override T GetValue() + { + return (T)Convert.ChangeType(this.value, typeof(T)); + } + + + + public override T GetDefaultValue() + { + // TODO Auto-generated method stub + return (T)Convert.ChangeType(this.defaultValue, typeof(T)); + } + + } +} diff --git a/Nadia.C.Sharp/FactValue Folder/FactListValue.cs b/Nadia.C.Sharp/FactValue Folder/FactListValue.cs new file mode 100644 index 0000000..7b89dcf --- /dev/null +++ b/Nadia.C.Sharp/FactValue Folder/FactListValue.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections; +using System.Collections.Generic; + +namespace Nadia.C.Sharp.FactValueFolder +{ + public class FactListValue : FactValue //where T: IList + { + private T listValue; + private FactValue defaultValue; + + public FactListValue(T i) + { + SetListValue(i); + } + + public void SetListValue(T listValue) + { + this.listValue = listValue; + } + + public void AddFactValueToListValue(FactValue fv) + { + (this.listValue as List>).Add(fv); + } + + + public override FactValueType GetFactValueType() + { + return FactValueType.LIST; + } + + + + public override void SetDefaultValue(T defaultValue) + { + this.defaultValue = (FactValue)Convert.ChangeType(defaultValue, typeof(FactValue)); + } + + public override T GetValue() + { + return (T)Convert.ChangeType(this.listValue, typeof(T)); + } + + public override T GetDefaultValue() + { + + return (T)Convert.ChangeType(this.defaultValue, typeof(T)); + } + + } +} diff --git a/Nadia.C.Sharp/FactValue Folder/FactStringValue.cs b/Nadia.C.Sharp/FactValue Folder/FactStringValue.cs new file mode 100644 index 0000000..2661df5 --- /dev/null +++ b/Nadia.C.Sharp/FactValue Folder/FactStringValue.cs @@ -0,0 +1,45 @@ +using System; +namespace Nadia.C.Sharp.FactValueFolder +{ + public class FactStringValue : FactValue + { + private string value; + private string defaultValue; + + public FactStringValue(string s) + { + SetValue(s); + } + + + public void SetValue(string s) + { + this.value = s; + } + + + public override FactValueType GetFactValueType() + { + return FactValueType.STRING; + } + + + public override void SetDefaultValue(T defaultValue) + { + this.defaultValue = defaultValue.ToString(); + } + + + public override T GetValue() + { + // TODO Auto-generated method stub + return (T)Convert.ChangeType(this.value, typeof(T)); + } + + public override T GetDefaultValue() + { + // TODO Auto-generated method stub + return (T)Convert.ChangeType(this.defaultValue, typeof(T)); + } + } +} diff --git a/Nadia.C.Sharp/FactValue Folder/FactURLValue.cs b/Nadia.C.Sharp/FactValue Folder/FactURLValue.cs new file mode 100644 index 0000000..dae0cf2 --- /dev/null +++ b/Nadia.C.Sharp/FactValue Folder/FactURLValue.cs @@ -0,0 +1,48 @@ +using System; +namespace Nadia.C.Sharp.FactValueFolder +{ + public class FactURLValue : FactValue + { + + private String value; + private String defaultValue; + + public FactURLValue(String url) + { + SetValue(url); + } + + + + public void SetValue(String url) + { + this.value = url; + } + + public override FactValueType GetFactValueType() + { + return FactValueType.URL; + } + + + + public override void SetDefaultValue(T defaultValue) + { + this.defaultValue = (string)Convert.ChangeType(defaultValue, typeof(string)); + } + + + + public override T GetValue() + { + return (T)Convert.ChangeType(this.value, typeof(T)); + } + + + public override T GetDefaultValue() + { + return (T)Convert.ChangeType(this.defaultValue, typeof(T)); + } + + } +} diff --git a/Nadia.C.Sharp/FactValue Folder/FactUUIDValue.cs b/Nadia.C.Sharp/FactValue Folder/FactUUIDValue.cs new file mode 100644 index 0000000..04c76f6 --- /dev/null +++ b/Nadia.C.Sharp/FactValue Folder/FactUUIDValue.cs @@ -0,0 +1,46 @@ +using System; +namespace Nadia.C.Sharp.FactValueFolder +{ + public class FactUUIDValue : FactValue + { + private String value; + private String defaultValue; + + public FactUUIDValue(String uuid) + { + SetValue(uuid); + } + + + + public void SetValue(String uuid) + { + this.value = uuid; + } + + + + public override FactValueType GetFactValueType() + { + return FactValueType.UUID; + } + + + public override void SetDefaultValue(T defaultValue) + { + this.defaultValue = (string)Convert.ChangeType(defaultValue, typeof(string)); + } + + public override T GetValue() + { + return (T)Convert.ChangeType(this.value, typeof(T)); + } + + + public override T GetDefaultValue() + { + return (T)Convert.ChangeType(this.defaultValue, typeof(T)); + } + + } +} diff --git a/Nadia.C.Sharp/FactValue Folder/FactValue.cs b/Nadia.C.Sharp/FactValue Folder/FactValue.cs new file mode 100644 index 0000000..bbf3143 --- /dev/null +++ b/Nadia.C.Sharp/FactValue Folder/FactValue.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; + + +namespace Nadia.C.Sharp.FactValueFolder +{ + public abstract class FactValue + { + + public static FactDefiStringValue ParseDefiString(string s) + { + return new FactDefiStringValue(s); + } + + public static FactStringValue Parse(string s) + { + return new FactStringValue(s); + } + + public static FactIntegerValue Parse(int i) + { + return new FactIntegerValue(i); + } + + public static FactDateValue Parse(DateTime cal) + { + return new FactDateValue(cal); + } + + public static FactDoubleValue Parse(double d) + { + return new FactDoubleValue(d); + } + + + public static FactBooleanValue Parse(bool b) + { + return new FactBooleanValue(b); + } + + + public static FactListValue ParseList(T l) + { + return new FactListValue(l); + } + + public static FactURLValue ParseURL(String url) + { + return new FactURLValue(url); + } + + public static FactHashValue ParseHash(String hash) + { + return new FactHashValue(hash); + } + + public static FactUUIDValue ParseUUID(String uuid) + { + return new FactUUIDValue(uuid); + } + + + public abstract FactValueType GetFactValueType(); + public abstract void SetDefaultValue(T str); + public abstract T GetValue(); + public abstract T GetDefaultValue(); + + } +} diff --git a/Nadia.C.Sharp/FactValue Folder/FactValueType.cs b/Nadia.C.Sharp/FactValue Folder/FactValueType.cs new file mode 100644 index 0000000..dee4f54 --- /dev/null +++ b/Nadia.C.Sharp/FactValue Folder/FactValueType.cs @@ -0,0 +1,8 @@ +using System; +namespace Nadia.C.Sharp.FactValueFolder +{ + public enum FactValueType + { + DEFI_STRING, TEXT, STRING, INTEGER, DOUBLE, NUMBER, DATE, DECIMAL, BOOLEAN, LIST, RULE, RULE_SET, OBJECT, UNKNOWN, URL, HASH, UUID, NULL, + } +} diff --git a/Nadia.C.Sharp/Nadia.C.Sharp.csproj b/Nadia.C.Sharp/Nadia.C.Sharp.csproj new file mode 100644 index 0000000..74773bc --- /dev/null +++ b/Nadia.C.Sharp/Nadia.C.Sharp.csproj @@ -0,0 +1,79 @@ + + + + + Debug + x86 + {E5A172D3-CE33-4031-84EA-35835913261E} + Exe + Nadia.C.Sharp + Nadia.C.Sharp + v4.7 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + true + x86 + + + true + bin\Release + prompt + 4 + true + x86 + + + + + packages\Jint.2.11.58\lib\net451\Jint.dll + + + + + + + packages\Noesis.Javascript.0.7.1.0\lib\net40\x86\Noesis.Javascript.dll + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Nadia.C.Sharp/Nadia.C.Sharp.sln b/Nadia.C.Sharp/Nadia.C.Sharp.sln new file mode 100644 index 0000000..34a24da --- /dev/null +++ b/Nadia.C.Sharp/Nadia.C.Sharp.sln @@ -0,0 +1,17 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nadia.C.Sharp", "Nadia.C.Sharp.csproj", "{E5A172D3-CE33-4031-84EA-35835913261E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x86 = Debug|x86 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E5A172D3-CE33-4031-84EA-35835913261E}.Debug|x86.ActiveCfg = Debug|x86 + {E5A172D3-CE33-4031-84EA-35835913261E}.Debug|x86.Build.0 = Debug|x86 + {E5A172D3-CE33-4031-84EA-35835913261E}.Release|x86.ActiveCfg = Release|x86 + {E5A172D3-CE33-4031-84EA-35835913261E}.Release|x86.Build.0 = Release|x86 + EndGlobalSection +EndGlobal diff --git a/Nadia.C.Sharp/Node Folder/ComparisonLine.cs b/Nadia.C.Sharp/Node Folder/ComparisonLine.cs new file mode 100644 index 0000000..8a17f49 --- /dev/null +++ b/Nadia.C.Sharp/Node Folder/ComparisonLine.cs @@ -0,0 +1,161 @@ +using System; +using System.Collections.Generic; +using System.Text.RegularExpressions; +using Nadia.C.Sharp.FactValueFolder; +using Nadia.C.Sharp.RuleParserFolder; + +namespace Nadia.C.Sharp.NodeFolder +{ + public class ComparisonLine : Node + { + private string operatorString; + + private string lhs; + private FactValue rhs; + + public ComparisonLine(string childText, Tokens tokens) : base(childText, tokens) + { + + } + + + public override void Initialisation(string childText, Tokens tokens) + { + + /* + * this line pattern is as (^[ML]+)(O)([MLNoDaDeHaUrlId]*$) + */ + + this.nodeName = childText; + /* + * In javascript engine '=' operator means assigning a value, hence if the operator is '=' then it needs to be replaced with '=='. + */ + int operatorIndex = tokens.tokensStringList.IndexOf("O"); + this.operatorString = Regex.IsMatch(tokens.tokensList[operatorIndex], @"=") ? "==" : tokens.tokensList[operatorIndex]; + + if (operatorString.Equals("==")) + { + this.variableName = childText.Split('=')[0].Trim(); + } + else + { + string[] splitor = new string[] { this.operatorString }; + + this.variableName = childText.Split(splitor, StringSplitOptions.None)[0]; + } + this.lhs = variableName; + + int tokensStringListSize = tokens.tokensStringList.Count; + String lastToken = tokens.tokensList[tokensStringListSize - 1]; + String lastTokenString = tokens.tokensStringList[tokensStringListSize - 1]; + this.SetValue(lastTokenString, lastToken); + this.rhs = this.value; + + + } + + + + public String GetRuleName() + { + return this.nodeName; + } + + public String GetLHS() + { + return this.lhs; + } + + public FactValue GetRHS() + { + return this.rhs; + } + + + public override LineType GetLineType() + { + return LineType.COMPARISON; + } + + + public override FactValue SelfEvaluate(Dictionary> workingMemory, Jint.Engine jint) + { + + /* + * Negation type can only be used for this line type + * + */ + + FactValue workingMemoryLhsValue = workingMemory.ContainsKey(this.variableName) ? workingMemory[this.variableName] : null; + FactValue workingMemoryRhsValue = this.GetRHS().GetType().Equals(FactValueType.STRING) ? + workingMemory[this.GetRHS().GetValue().ToString()] + : + this.GetRHS(); + + String script = ""; + + /* + * There will NOT be the case of that workingMemoryRhsValue is null because the node must be in following format; + * - A = 12231 (int or double) + * - A = Adam sandler (String) + * - A = 11/11/1977 (Date) + * - A = 123123dfae1421412aer(Hash) + * - A = 1241414-12421312-142421312(UUID) + * - A = true(Boolean) + * - A = www.aiBrain.com(URL) + * - A = B(another variable) + */ + + /* + * if it is about date comparison then string of 'script' needs rewriting + */ + if ((workingMemoryLhsValue != null && workingMemoryLhsValue.GetType().Equals(FactValueType.DATE)) || (workingMemoryRhsValue != null && workingMemoryRhsValue.GetType().Equals(FactValueType.DATE))) + { + Boolean returnValue; + switch (this.operatorString) + { + case ">": + returnValue = ((DateTime)(object)workingMemoryLhsValue.GetValue()).CompareTo(((DateTime)(object)workingMemoryRhsValue.GetValue())) > 0 ? true : false; + return FactValue.Parse(returnValue); + + case ">=": + returnValue = ((DateTime)(object)workingMemoryLhsValue.GetValue()).CompareTo(((DateTime)(object)workingMemoryRhsValue.GetValue())) >= 0 ? true : false; + return FactValue.Parse(returnValue); + + case "<": + returnValue = ((DateTime)(object)workingMemoryLhsValue.GetValue()).CompareTo(((DateTime)(object)workingMemoryRhsValue.GetValue())) < 0 ? true : false; + return FactValue.Parse(returnValue); + + case "<=": + returnValue = ((DateTime)(object)workingMemoryLhsValue.GetValue()).CompareTo(((DateTime)(object)workingMemoryRhsValue.GetValue())) <= 0 ? true : false; + return FactValue.Parse(returnValue); + + } + // script = "new Date("+((FactDateValue)workingMemoryLhsValue).getValue().getYear()+"/"+((FactDateValue)workingMemoryLhsValue).getValue().getMonthValue()+"/"+((FactDateValue)workingMemoryLhsValue).getValue().getDayOfMonth()+")"+operator+"new Date("+((FactDateValue)workingMemoryRhsValue).getValue().getYear()+"/"+((FactDateValue)workingMemoryRhsValue).getValue().getMonthValue()+"/"+((FactDateValue)workingMemoryRhsValue).getValue().getDayOfMonth()+");" ; + } + else if (workingMemoryLhsValue.GetType().Equals(FactValueType.DECIMAL) || workingMemoryLhsValue.GetType().Equals(FactValueType.DOUBLE) + || workingMemoryLhsValue.GetType().Equals(FactValueType.INTEGER) || workingMemoryLhsValue.GetType().Equals(FactValueType.NUMBER)) + { + script = workingMemoryLhsValue.GetValue().ToString() + operatorString + workingMemoryRhsValue.GetValue().ToString(); + } + else + { + if (workingMemoryRhsValue != null && workingMemoryLhsValue != null) + { + script = "'" + workingMemoryLhsValue.GetValue().ToString() + "' " + operatorString + " '" + workingMemoryRhsValue.GetValue().ToString() + "'"; + } + + } + Boolean result; + FactValue fv = null; + if (workingMemoryRhsValue != null && workingMemoryLhsValue != null) + { + result = Convert.ToBoolean(jint.Execute(script).GetCompletionValue()); + fv = FactValue.Parse(result); + } + + + return fv; + } + } +} diff --git a/Nadia.C.Sharp/Node Folder/Dependency.cs b/Nadia.C.Sharp/Node Folder/Dependency.cs new file mode 100644 index 0000000..77225b7 --- /dev/null +++ b/Nadia.C.Sharp/Node Folder/Dependency.cs @@ -0,0 +1,38 @@ +using System; +namespace Nadia.C.Sharp.NodeFolder +{ + public class Dependency + { + private int dependencyType; //this variable is to store 'AND/OR' DependencyType between Nodes + private Node parent; // this variable is to store a parent Node of this dependency + private Node child; // this variable is to store a child Node of this dependency + + // public Dependency(Node child, String DependencyType) + public Dependency(Node parent, Node child, int dependencyType) + { + this.parent = parent; + this.child = child; + this.dependencyType = dependencyType; + } + + public Node GetParentNode() + { + return parent; + } + public void SetParentNode(Node parentNode) + { + this.parent = parentNode; + } + public Node GetChildNode() + { + return child; + } + + public int GetDependencyType() + { + return dependencyType; + } + + } + +} diff --git a/Nadia.C.Sharp/Node Folder/DependencyMatrix.cs b/Nadia.C.Sharp/Node Folder/DependencyMatrix.cs new file mode 100644 index 0000000..f2ef021 --- /dev/null +++ b/Nadia.C.Sharp/Node Folder/DependencyMatrix.cs @@ -0,0 +1,83 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Nadia.C.Sharp.NodeFolder +{ + public class DependencyMatrix + { + + /* + * order of dependency type + * 1. MANDATORY + * 2. OPTIONAL + * 3. POSSIBLE + * 4. AND + * 5. OR + * 6. NOT + * 7. KNOWN + * + * int value will be '1' if any one of them is true case otherwise '0' + * for instance, if a rule is in 'MANDATORY AND NOT' dependency then + * dependency type value is '1001010' + * + * if there is no dependency then value is 0000000 + */ + private int[][] dependencyMatrix; + private int dependencyMatrixSize; + + public DependencyMatrix(int[][] dependencyMatrix) + { + this.dependencyMatrix = dependencyMatrix; + this.dependencyMatrixSize = this.dependencyMatrix[0].Length; + } + + public int[][] GetDependencyMatrixArray() + { + return this.dependencyMatrix; + } + + public int GetDependencyType(int parentRuleId, int childRuleId) + { + return this.dependencyMatrix[parentRuleId][childRuleId]; + } + + + public List GetToChildDependencyList(int nodeId) + { + return Enumerable.Range(0, dependencyMatrixSize).Where(i => i != nodeId && this.dependencyMatrix[nodeId][i] != 0).ToList(); + } + + public List GetOrToChildDependencyList(int nodeId) + { + int orDependency = DependencyType.GetOr(); + + return Enumerable.Range(0, this.dependencyMatrixSize).Where(i => i != nodeId && (this.dependencyMatrix[nodeId][i] & orDependency) == orDependency).ToList(); + } + + public List GetAndToChildDependencyList(int nodeId) + { + int andDependency = DependencyType.GetAnd(); + + return Enumerable.Range(0, this.dependencyMatrixSize).Where(i => i != nodeId && (this.dependencyMatrix[nodeId][i] & andDependency) == andDependency).ToList(); + } + + public List GetMandatoryToChildDependencyList(int nodeId) + { + int mandatoryDependency = DependencyType.GetMandatory(); + return Enumerable.Range(0, this.dependencyMatrixSize).Where(i => i != nodeId && (this.dependencyMatrix[nodeId][i] & mandatoryDependency) == mandatoryDependency).ToList(); + } + + + public List getFromParentDependencyList(int nodeId) + { + return Enumerable.Range(0, this.dependencyMatrixSize).Where(i => i != nodeId && this.dependencyMatrix[i][nodeId] != 0).ToList(); + } + + public bool hasMandatoryChildNode(int nodeId) + { + return GetMandatoryToChildDependencyList(nodeId).Count() > 0; + } + + } +} diff --git a/Nadia.C.Sharp/Node Folder/DependencyType.cs b/Nadia.C.Sharp/Node Folder/DependencyType.cs new file mode 100644 index 0000000..5aec707 --- /dev/null +++ b/Nadia.C.Sharp/Node Folder/DependencyType.cs @@ -0,0 +1,51 @@ +using System; +namespace Nadia.C.Sharp.NodeFolder +{ + public class DependencyType + { + + private static int mandatory = 64; // 1000000 + private static int optional = 32; // 0100000 + private static int possible = 16; // 0010000 + private static int and = 8; // 0001000 + private static int or = 4; // 0000100 + private static int not = 2; // 0000010 + private static int known = 1; // 0000001 + + public static int GetMandatory() + { + return mandatory; + } + + public static int GetOptional() + { + return optional; + } + + public static int GetPossible() + { + return possible; + } + + public static int GetAnd() + { + return and; + } + + public static int GetOr() + { + return or; + } + + public static int GetNot() + { + return not; + } + + public static int GetKnown() + { + return known; + } + + } +} diff --git a/Nadia.C.Sharp/Node Folder/ExprConclusionLine.cs b/Nadia.C.Sharp/Node Folder/ExprConclusionLine.cs new file mode 100644 index 0000000..298dde1 --- /dev/null +++ b/Nadia.C.Sharp/Node Folder/ExprConclusionLine.cs @@ -0,0 +1,158 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text.RegularExpressions; +using Nadia.C.Sharp.FactValueFolder; +using Nadia.C.Sharp.RuleParserFolder; + +namespace Nadia.C.Sharp.NodeFolder +{ + public class ExprConclusionLine : Node + { + private FactValue equation; + private string dateFormatter = @"dd/MM/yyyy"; + + + public ExprConclusionLine(String parentText, Tokens tokens): base(parentText, tokens) + { + + } + + public override void Initialisation(String parentText, Tokens tokens) + { + this.nodeName = parentText; + String[] tempArray = Regex.Split(parentText, "IS CALC"); + variableName = tempArray[0].Trim(); + int indexOfCInTokensStringList = tokens.tokensStringList.IndexOf("C"); + this.SetValue(tokens.tokensStringList[indexOfCInTokensStringList].Trim(), tokens.tokensList[indexOfCInTokensStringList].Trim()); + this.equation = this.value; + } + + + public FactValue GetEquation() + { + return this.equation; + } + public void SetEquation(FactValue newEquation) + { + this.equation = newEquation; + } + + + + public override LineType GetLineType() + { + return LineType.EXPR_CONCLUSION; + } + + + public override FactValue SelfEvaluate(Dictionary> workingMemory, Jint.Engine jint) + { + /* + * calculation can only handle int, double(long) and difference in years between two dates at the moment. + * if difference in days or months is required then new 'keyword' must be introduced such as 'Diff Years', 'Diff Days', or 'Diff Months' + */ + string equationInString = this.equation.GetValue().ToString(); + string pattern = @"[-+/*()?:;,.""](\s*)"; + string datePattern = @"([0-2]?[0-9]|3[0-1])/(0?[0-9]|1[0-2])/([0-9][0-9])?[0-9][0-9]|([0-9][0-9])?[0-9][0-9]/(0?[0-9]|1[0-2])/([0-2]?[0-9]|3[0-1])"; + + + /* + * logic for this is as follows; + * 1. replace all variables with actual values from 'workingMemory' + * 2. find out if equation is about date (difference in years) calculation or not + * 3. if it is about date then call 'java.time.LocalDate'and 'java.time.temporal.ChronoUnit' package then do the calculation + * 3-1. if it is about int or double(long) then use plain Javascript + * + */ + + string script = equationInString; + string tempScript = script; + + if (Regex.IsMatch(equationInString, pattern)) + { + string[] tempArray = Regex.Split(equationInString, pattern); + int tempArrayLength = tempArray.Length; + string tempItem; + for (int i = 0; i < tempArrayLength; i++) + { + tempItem = tempArray[i]; + if (!String.IsNullOrEmpty(tempItem.Trim()) && workingMemory[tempItem.Trim()] != null) + { + FactValue tempFv = workingMemory[tempItem.Trim()]; + if (tempFv.GetValue().GetType().FullName.Equals(DateTime.Now.GetType().FullName)) + { + /* + * below line is temporary solution. + * Within next iteration it needs to be that this node should take dateFormatter for its constructor to determine which date format it needs + */ + string tempStr = DateTime.ParseExact(tempFv.GetValue().ToString(), dateFormatter, CultureInfo.InvariantCulture).ToString(); + tempScript = tempScript.Replace(tempScript.Trim(), tempStr); + } + else + { + tempScript = tempScript.Replace(tempItem.Trim(), workingMemory[tempItem.Trim()].GetValue().ToString().Trim()); + } + + } + } + } + + Match dateMatcher = Regex.Match(tempScript, datePattern); + List dateStringList = new List(); + while(dateMatcher.Success) + { + dateStringList.Add(dateMatcher.Value); + } + // if dateStringList.size() == 0 then there is no string in date format + script = tempScript; + //if(dateStringList.size() != 0) // case of date calculation + //{ + // string[] date1Array = dateStringList.get(0).trim().split("/"); + // string[] date2Array = dateStringList.get(1).trim().split("/"); + // script = "var localDate = java.time.LocalDate; var chronoUnit = java.time.temporal.ChronoUnit; var diffYears = chronoUnit.YEARS.between(localDate.of("+date2Array[2].trim()+","+date2Array[1].trim()+","+date2Array[0].trim()+"), localDate.of("+date1Array[2].trim()+","+date1Array[1].trim()+","+date1Array[0].trim()+")); diffYears;"; + //} + // else // case of int or double calculation + // { + // don't need to do anything due to script itself can be evaluated as it is + // } + + + FactValue returnValue = null; + + // try { + // string nashornResult = nashorn.eval(script).toString(); + // switch(Tokenizer.getTokens(nashornResult).tokensString) + // { + // case "No": + // returnValue = FactValue.parse(Integer.parseInt(nashornResult)); + // break; + // case "De": + // returnValue = FactValue.parse(Double.parseDouble(nashornResult)); + // break; + //// there is no function for outcome to be a date at the moment E.g. The determination IS CALC (enrollment date + 5 days) + //// case "Da": + //// DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy"); + //// LocalDate factValueInDate = LocalDate.parse(nashornResult, formatter); + //// returnValue = FactValue.parse(factValueInDate); + //// break; + // default: + // if(this.isBoolean(nashornResult)) + // { + // returnValue = FactValue.parse(nashornResult); + // } + // else + // { + // returnValue = FactValue.parse(nashornResult); + // } + // break; + + // } + //} catch (ScriptException e) { + // e.printStackTrace(); + //} + return returnValue; + } + + } +} diff --git a/Nadia.C.Sharp/Node Folder/LineType.cs b/Nadia.C.Sharp/Node Folder/LineType.cs new file mode 100644 index 0000000..e5e31bb --- /dev/null +++ b/Nadia.C.Sharp/Node Folder/LineType.cs @@ -0,0 +1,8 @@ +using System; +namespace Nadia.C.Sharp.NodeFolder +{ + public enum LineType + { + META, VALUE_CONCLUSION, EXPR_CONCLUSION, COMPARISON, ITERATE, WARNING, + } +} \ No newline at end of file diff --git a/Nadia.C.Sharp/Node Folder/Node.cs b/Nadia.C.Sharp/Node Folder/Node.cs new file mode 100644 index 0000000..7d26671 --- /dev/null +++ b/Nadia.C.Sharp/Node Folder/Node.cs @@ -0,0 +1,174 @@ +using System; +using System.Collections.Generic; +using System.Text.RegularExpressions; +using Nadia.C.Sharp.FactValueFolder; +using Nadia.C.Sharp.RuleParserFolder; + +namespace Nadia.C.Sharp.NodeFolder +{ + public abstract class Node + { + + protected static int staticNodeId = 0; + protected int nodeId; + protected string nodeName; + protected int nodeLine; + protected string variableName; + protected FactValue value; + protected Tokens tokens; + + public Node(string parentText, Tokens tokens) + { + nodeId = staticNodeId; + staticNodeId++; + this.tokens = tokens; + + Initialisation(parentText, tokens); + } + + public abstract void Initialisation(string parentText, Tokens tokens); + public abstract LineType GetLineType(); + public abstract FactValue SelfEvaluate(Dictionary> workingMemory, Jint.Engine nashorn); + + public void SetNodeLine(int nodeLine) + { + this.nodeLine = nodeLine; + } + public int GetNodeLine() + { + return this.nodeLine; + } + + public static int GetStaticNodeId() + { + return staticNodeId; + } + public int GetNodeId() + { + return this.nodeId; + } + public string GetNodeName() + { + return this.nodeName; + } + + public Tokens GetTokens() + { + return this.tokens; + } + + public string GetVariableName() + { + return variableName; + } + public void SetNodeVariable(string newVariableName) + { + this.variableName = newVariableName; + } + + public FactValue GetFactValue() + { + return this.value; + } + + protected void SetValue(string lastTokenstring, string lastToken) + { + switch (lastTokenstring) + { + case "No": + int intValue = 0; + Int32.TryParse(lastToken, out intValue); + + this.value = FactValue.Parse(intValue); + break; + case "Do": + double doubleValue = 0.0; + Double.TryParse(lastToken, out doubleValue); + + this.value = FactValue.Parse(doubleValue); + break; + case "Da": + DateTime dateValue; + DateTime.TryParseExact(lastToken, "dd/MM/yyyy", null, System.Globalization.DateTimeStyles.None, out dateValue); + + this.value = FactValue.Parse(dateValue); + break; + case "Url": + this.value = FactValue.ParseURL(lastToken); + break; + case "Id": + this.value = FactValue.ParseUUID(lastToken); + break; + case "Ha": + this.value = FactValue.ParseHash(lastToken); + break; + case "Q": + this.value = FactValue.ParseDefiString(lastToken); + break; + case "L": + case "M": + case "U": + case "C": + if (this.IsBoolean(lastToken)) + { + this.value = string.Equals(lastToken, "false", StringComparison.OrdinalIgnoreCase)? FactValue.Parse(false) : FactValue.Parse(true); + } + else + { + Regex regex = new Regex(@"^([""\“])(.*)([""\”]$)"); + Match match = regex.Match(lastToken); + + if (match.Success) + { + string newS = match.Groups[2].Value; + this.value = FactValue.ParseDefiString(newS); + } + else + { + this.value = FactValue.Parse(lastToken); + } + } + break; + } + } + public void SetValue(FactValue fv) + { + this.value = fv; + } + protected bool IsBoolean(string str) + { + return Regex.IsMatch(str,@"[FfAaLlSsEe]+") || Regex.IsMatch(str, @"[TtRrUuEe]+") ? true : false; + } + + protected bool IsInteger(string str) + { + return string.Equals(str,@"No") ? true : false; + } + + protected bool IsDouble(string str) + { + return string.Equals(str, @"De") ? true : false; + } + + protected bool IsDate(string str) + { + return string.Equals(str, @"Da") ? true : false; + } + + protected bool IsURL(string str) + { + return string.Equals(str, @"Url") ? true : false; + } + + protected bool IsHash(string str) + { + return string.Equals(str, @"Ha") ? true : false; + } + + protected bool IsGUID(string str) + { + return string.Equals(str, @"Id") ? true : false; + } + + } +} diff --git a/Nadia.C.Sharp/Program.cs b/Nadia.C.Sharp/Program.cs new file mode 100644 index 0000000..c688263 --- /dev/null +++ b/Nadia.C.Sharp/Program.cs @@ -0,0 +1,118 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text.RegularExpressions; +using Jint; +using Nadia.C.Sharp.RuleParserFolder; + +namespace Nadia.C.Sharp +{ + class MainClass + { + public static void Main(string[] args) + { + //string fileName = @"/Users/deanlee/Desktop/Programming/C#/Nadia.C.Sharp/Nadia.C.Sharp/Tokenizer_Testing.txt"; + //StreamReader file = new StreamReader(fileName); + //string line; + //string textString = String.Empty; + //int lineTracking = 0; + //Tokens tk = null; + //while((line = file.ReadLine())!= null) + //{ + // line = line.Trim(); + // var re = Regex.IsMatch(line, @"^\/.*"); + // if (!line.Equals("") && !Regex.IsMatch(line,@"^\/.*")) + // { + // if (lineTracking == 0) + // { + // textString = line; + // tk = Tokenizer.GetTokens(line); + // lineTracking++; + + // } + // else if (lineTracking == 1) + // { + // Console.WriteLine($"text string: {textString}"); + // Console.WriteLine($"tk.tokenString: {tk.tokensString}"); + // Console.WriteLine($"expected tokenString line : {line}"); + // Console.WriteLine($"\n"); + + // if (!tk.tokensString.Equals(line)) + // { + // Console.WriteLine($"above line is not same as below line"); + // return; + // } + // else + // { + // lineTracking = 0; + // } + // } + // } + + //} + //file.Close(); + + string str = "\"this is defi String \""; + Regex regex = new Regex(@"^([""\“])(.*)([""\”]$)"); + Match match = regex.Match(str); + + if (match.Success) + { + Console.WriteLine($"match.Groups: {match.Groups}"); + Console.WriteLine($"match.Groups[0].Value: {match.Groups[0].Value}"); + Console.WriteLine($"match.Groups[1].Value: {match.Groups[1].Value}"); + Console.WriteLine($"match.Groups[2].Value: {match.Groups[2].Value}"); + Console.WriteLine($"match.Groups[3].Value: {match.Groups[3].Value}"); + } + + string dateString = "11/11/1977 < 12/12/1988"; + string datePattern = @"([0-2]?[0-9]|3[0-1])/(0?[0-9]|1[0-2])/([0-9][0-9])?[0-9][0-9]|([0-9][0-9])?[0-9][0-9]/(0?[0-9]|1[0-2])/([0-2]?[0-9]|3[0-1])"; + MatchCollection mc = Regex.Matches(dateString, datePattern); + + + foreach(Match mat in mc) + { + Console.WriteLine("--------------------------------------------"); + //for (int i = 0; i < mat.Groups.Count; i++) + //{ + // Console.WriteLine($"mat.Groups{i} : {mat.Groups[i]}"); + //} + Console.WriteLine($"mat.Groups[0]: {mat.Groups[0]}"); + Console.WriteLine("--------------------------------------------"); + } + + + //string line = "3+4"; + + + //var engine = new Jint.Engine(); + //Console.WriteLine(engine.Execute(line).GetCompletionValue()); + + //DateTime dateTime = DateTime.ParseExact("11/09/2017", "dd/MM/yyyy"); + List testList = new List(); + testList.Add(3); + testList.Add(5); + testList.Add(2); + testList.Add(9); + testList.Add(11); + testList.Add(13); + testList.Add(23); + testList.Add(6); + + List var = Enumerable.Range(0, testList.Count).Where(i => testList[i] < 10).ToList(); + + foreach( int num in var) + { + Console.WriteLine(num); + } + + int int1 = 3; + int int2 = 6; + + Console.WriteLine(int1 & int2); + + + } + } +} diff --git a/Nadia.C.Sharp/Properties/AssemblyInfo.cs b/Nadia.C.Sharp/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..524395b --- /dev/null +++ b/Nadia.C.Sharp/Properties/AssemblyInfo.cs @@ -0,0 +1,26 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle("Nadia.C.Sharp")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("${AuthorCopyright}")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] diff --git a/Nadia.C.Sharp/RuleParser Folder/Tokenizer.cs b/Nadia.C.Sharp/RuleParser Folder/Tokenizer.cs new file mode 100644 index 0000000..28e876b --- /dev/null +++ b/Nadia.C.Sharp/RuleParser Folder/Tokenizer.cs @@ -0,0 +1,77 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics.Contracts; +using System.Text.RegularExpressions; + +namespace Nadia.C.Sharp.RuleParserFolder +{ + public class Tokenizer + { + private static Regex spaceRegex = new Regex(@"^\s+"); + private static Regex iterateRegex = new Regex(@"^(ITERATE:([\s]*)LIST OF)(.)"); + private static Regex upperRegex = new Regex(@"^([:'’,\.\p{Lu}_\s]+(?!\p{Ll}))"); + private static Regex lowerRegex = new Regex(@"^([\p{Ll}-'’,\.\s]+(?!\d))"); + private static Regex mixedRegex = new Regex(@"^(\p{Lu}[\p{Ll}-'’,\.\s]+)+"); + private static Regex operatorRegex = new Regex(@"^([<>=]+)"); + private static Regex calculationRegex = new Regex(@"^(\()([\s|\d+(?!/.)|\w|\W]*)(\))"); + private static Regex numberRegex = new Regex(@"^(\d+)(?!/|\.|\d)+"); + private static Regex decimalNumberRegex = new Regex(@"^([\d]+\.\d+)(?!\d)"); + private static Regex dateRegex = new Regex(@"^([0-2]?[0-9]|3[0-1])/(0?[0-9]|1[0-2])/([0-9][0-9])?[0-9][0-9]|^([0-9][0-9])?[0-9][0-9]/(0?[0-9]|1[0-2])/([0-2]?[0-9]|3[0-1])"); + private static Regex urlRegex = new Regex(@"^(ht|f)tps?\:(\p{L}|\p{N}|\p{P}|^[a-fA-F0-9]+|\s)*$"); + private static Regex guidRegex = new Regex(@"^(\{?[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}\}?)"); + private static Regex hashRegex = new Regex(@"^([-]?)([0-9a-fA-F]{10,}$)(?!\-)*"); + private static Regex quotedRegex = new Regex(@"^([""\“])(.*)([""\”])(\.)*"); + /* + * the order of Pattern in the array of 'matchPatterns' is extremely important because some patterns won't work if other patterns are invoked earlier than them + * especially 'I' pattern. 'I' pattern must come before 'U' pattern, 'Url' pattern must come before 'L' pattern with current patterns. + */ + private static Regex[] matchPatterns = { spaceRegex, quotedRegex, iterateRegex, mixedRegex, upperRegex, urlRegex, operatorRegex, calculationRegex, + hashRegex, numberRegex, decimalNumberRegex, dateRegex, guidRegex, lowerRegex }; + private static string[] tokenType = { "S", "Q", "I", "M", "U", "Url", "O", "C", "Ha", "No", "De", "Da", "Id", "L" }; + + public static Tokens GetTokens(string text) + { + List tokenStringList = new List(); + List tokenList = new List(); + string tokenString = String.Empty; + int textLength = text.Length; + + while (textLength != 0) + { + + for (int i = 0; i < matchPatterns.Length; i++) + { + Regex regex = matchPatterns[i]; + Match match = regex.Match(text); + + if (match.Success == true) + { + var group = match.Groups[0].Value; + + // ignore space tokens + if (!tokenType[i].Equals("S")) + { + tokenStringList.Add(tokenType[i]); + tokenList.Add(group.Trim()); + tokenString += tokenType[i]; + } + + text = text.Substring(group.Length).Trim(); + textLength = text.Length; + break; + } + if (i >= matchPatterns.Length - 1) + { + textLength = 0; + tokenString = "WARNING"; + } + } + + } + + Tokens tokens = new Tokens(tokenList, tokenStringList, tokenString); + return tokens; + + } + } +} diff --git a/Nadia.C.Sharp/RuleParser Folder/Tokens.cs b/Nadia.C.Sharp/RuleParser Folder/Tokens.cs new file mode 100644 index 0000000..8b0bd37 --- /dev/null +++ b/Nadia.C.Sharp/RuleParser Folder/Tokens.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; + +namespace Nadia.C.Sharp.RuleParserFolder +{ + public class Tokens + { + public List tokensList; + public List tokensStringList; + public string tokensString; + + public Tokens(List tl, List tsl, string ts) + { + tokensList = tl; + tokensStringList = tsl; + tokensString = ts; + } + + public Tokens(){ + + } + } +} diff --git a/Nadia.C.Sharp/Tokenizer_Testing.txt b/Nadia.C.Sharp/Tokenizer_Testing.txt new file mode 100644 index 0000000..58754ff --- /dev/null +++ b/Nadia.C.Sharp/Tokenizer_Testing.txt @@ -0,0 +1,93 @@ +//this file has been tested with TokenizerTesting.java in testingPackage, and passed the testing. +// as you may see, the testing set consists of two lines. First line is for a rule string, and second line is an outcome of Tokenizer. + +INPUT person’s name AS TEXT +ULU + +this line is for UUID ffa4788a-a33f-11e7-abc4-cec278b6b50a +LUId + +FIXED service start date IS 1/1/1988 +ULUDa + +we have information about a person +L + +OR we have person’s name and dob +UL + +AND KNOWN person’s name +UL + +OR person’s name IS IN LIST: name list +ULUL + +person’s nationality IS Australian +LUM + +person made it to Las Vegas +LM + +AND NOT person’s name = “troy jones” +ULOQ + +AND the person’s dob > 01/01/1990 +ULODa + +AND the person is currently studying +UL + +person is eligible for a premium service +L + +AND person's drinking habit = frequent drinker +ULOL + +AND person's account IS IN LIST: premium account type +ULUL + +AND person’s nationality = "Australian" +ULOQ + +person's drinking habit IS social drinker +LUL + +AND number of drinks the person consumes a week > 0 +ULONo + +AND number of drinks the person consumes a week < ffa4788a-a33f-11e7-abc4-cec278b6b50a +ULOId + +AND number of drinks the person consumes a week > https://www.theGroomHomepage.com.au +ULOUrl + +AND number of drinks the person consumes a week < 093059d79d009662a0a7f70c74cec934a73c1becc8ac813cdcc4995f2aeb882c +ULOHa + + +number of drinks the person consumes a week IS CALC ( (number of drinks the person consumes an hour * hours of drinks a day)*5) +LUC + +year difference between 6/04/1994 and check-up date>= 3 +LDaLONo + +year difference between 6/04/1994 and check-up date IS CALC (check-up date - 6/04/1994) +LDaLUC + +person is eligible for platinum service +L + +this is for quoted match, “this is double quoted” sentence. +LQL + +the person’s age IS around "50" +LULQ + +FIXED the groom's homepage IS https://www.theGroomHomepage.com.au +ULUUrl + +the price of a good is 12.35 +LDe + +Australian law was initiated date IS 19/11/1900 +MUDa diff --git a/Nadia.C.Sharp/bin/Debug/ChakraCore.dll b/Nadia.C.Sharp/bin/Debug/ChakraCore.dll new file mode 100755 index 0000000..f5e3395 Binary files /dev/null and b/Nadia.C.Sharp/bin/Debug/ChakraCore.dll differ diff --git a/Nadia.C.Sharp/bin/Debug/Jint.dll b/Nadia.C.Sharp/bin/Debug/Jint.dll new file mode 100755 index 0000000..c8392b7 Binary files /dev/null and b/Nadia.C.Sharp/bin/Debug/Jint.dll differ diff --git a/Nadia.C.Sharp/bin/Debug/Nadia.C.Sharp.exe b/Nadia.C.Sharp/bin/Debug/Nadia.C.Sharp.exe new file mode 100644 index 0000000..4f809cf Binary files /dev/null and b/Nadia.C.Sharp/bin/Debug/Nadia.C.Sharp.exe differ diff --git a/Nadia.C.Sharp/bin/Debug/Nadia.C.Sharp.pdb b/Nadia.C.Sharp/bin/Debug/Nadia.C.Sharp.pdb new file mode 100644 index 0000000..3b7b92b Binary files /dev/null and b/Nadia.C.Sharp/bin/Debug/Nadia.C.Sharp.pdb differ diff --git a/Nadia.C.Sharp/bin/Debug/Noesis.Javascript.dll b/Nadia.C.Sharp/bin/Debug/Noesis.Javascript.dll new file mode 100755 index 0000000..3016d76 Binary files /dev/null and b/Nadia.C.Sharp/bin/Debug/Noesis.Javascript.dll differ diff --git a/Nadia.C.Sharp/obj/x86/Debug/Nadia.C.Sharp.csproj.CopyComplete b/Nadia.C.Sharp/obj/x86/Debug/Nadia.C.Sharp.csproj.CopyComplete new file mode 100644 index 0000000..e69de29 diff --git a/Nadia.C.Sharp/obj/x86/Debug/Nadia.C.Sharp.csproj.CoreCompileInputs.cache b/Nadia.C.Sharp/obj/x86/Debug/Nadia.C.Sharp.csproj.CoreCompileInputs.cache new file mode 100644 index 0000000..e756965 --- /dev/null +++ b/Nadia.C.Sharp/obj/x86/Debug/Nadia.C.Sharp.csproj.CoreCompileInputs.cache @@ -0,0 +1 @@ +d0ead907287dd10d580054bad904c381eb509b97 diff --git a/Nadia.C.Sharp/obj/x86/Debug/Nadia.C.Sharp.csproj.FileListAbsolute.txt b/Nadia.C.Sharp/obj/x86/Debug/Nadia.C.Sharp.csproj.FileListAbsolute.txt new file mode 100644 index 0000000..d896307 --- /dev/null +++ b/Nadia.C.Sharp/obj/x86/Debug/Nadia.C.Sharp.csproj.FileListAbsolute.txt @@ -0,0 +1,9 @@ +/Users/deanlee/Desktop/Programming/C#/Nadia.C.Sharp/Nadia.C.Sharp/bin/Debug/Nadia.C.Sharp.exe +/Users/deanlee/Desktop/Programming/C#/Nadia.C.Sharp/Nadia.C.Sharp/bin/Debug/Nadia.C.Sharp.pdb +/Users/deanlee/Desktop/Programming/C#/Nadia.C.Sharp/Nadia.C.Sharp/bin/Debug/Jint.dll +/Users/deanlee/Desktop/Programming/C#/Nadia.C.Sharp/Nadia.C.Sharp/obj/x86/Debug/Nadia.C.Sharp.csproj.CoreCompileInputs.cache +/Users/deanlee/Desktop/Programming/C#/Nadia.C.Sharp/Nadia.C.Sharp/obj/x86/Debug/Nadia.C.Sharp.exe +/Users/deanlee/Desktop/Programming/C#/Nadia.C.Sharp/Nadia.C.Sharp/obj/x86/Debug/Nadia.C.Sharp.pdb +/Users/deanlee/Desktop/Programming/C#/Nadia.C.Sharp/Nadia.C.Sharp/bin/Debug/ChakraCore.dll +/Users/deanlee/Desktop/Programming/C#/Nadia.C.Sharp/Nadia.C.Sharp/bin/Debug/Noesis.Javascript.dll +/Users/deanlee/Desktop/Programming/C#/Nadia.C.Sharp/Nadia.C.Sharp/obj/x86/Debug/Nadia.C.Sharp.csprojResolveAssemblyReference.cache diff --git a/Nadia.C.Sharp/obj/x86/Debug/Nadia.C.Sharp.csprojResolveAssemblyReference.cache b/Nadia.C.Sharp/obj/x86/Debug/Nadia.C.Sharp.csprojResolveAssemblyReference.cache new file mode 100644 index 0000000..44dddc6 Binary files /dev/null and b/Nadia.C.Sharp/obj/x86/Debug/Nadia.C.Sharp.csprojResolveAssemblyReference.cache differ diff --git a/Nadia.C.Sharp/obj/x86/Debug/Nadia.C.Sharp.exe b/Nadia.C.Sharp/obj/x86/Debug/Nadia.C.Sharp.exe new file mode 100644 index 0000000..4f809cf Binary files /dev/null and b/Nadia.C.Sharp/obj/x86/Debug/Nadia.C.Sharp.exe differ diff --git a/Nadia.C.Sharp/obj/x86/Debug/Nadia.C.Sharp.pdb b/Nadia.C.Sharp/obj/x86/Debug/Nadia.C.Sharp.pdb new file mode 100644 index 0000000..3b7b92b Binary files /dev/null and b/Nadia.C.Sharp/obj/x86/Debug/Nadia.C.Sharp.pdb differ diff --git a/Nadia.C.Sharp/packages.config b/Nadia.C.Sharp/packages.config new file mode 100644 index 0000000..add46bd --- /dev/null +++ b/Nadia.C.Sharp/packages.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Nadia.C.Sharp/packages/Jint.2.11.58/Jint.2.11.58.nupkg b/Nadia.C.Sharp/packages/Jint.2.11.58/Jint.2.11.58.nupkg new file mode 100644 index 0000000..6efca6b Binary files /dev/null and b/Nadia.C.Sharp/packages/Jint.2.11.58/Jint.2.11.58.nupkg differ diff --git a/Nadia.C.Sharp/packages/Jint.2.11.58/lib/net40/Jint.dll b/Nadia.C.Sharp/packages/Jint.2.11.58/lib/net40/Jint.dll new file mode 100755 index 0000000..437d2bb Binary files /dev/null and b/Nadia.C.Sharp/packages/Jint.2.11.58/lib/net40/Jint.dll differ diff --git a/Nadia.C.Sharp/packages/Jint.2.11.58/lib/net45/Jint.dll b/Nadia.C.Sharp/packages/Jint.2.11.58/lib/net45/Jint.dll new file mode 100755 index 0000000..ff8a4cc Binary files /dev/null and b/Nadia.C.Sharp/packages/Jint.2.11.58/lib/net45/Jint.dll differ diff --git a/Nadia.C.Sharp/packages/Jint.2.11.58/lib/net451/Jint.dll b/Nadia.C.Sharp/packages/Jint.2.11.58/lib/net451/Jint.dll new file mode 100755 index 0000000..c8392b7 Binary files /dev/null and b/Nadia.C.Sharp/packages/Jint.2.11.58/lib/net451/Jint.dll differ diff --git a/Nadia.C.Sharp/packages/Jint.2.11.58/lib/netstandard1.3/Jint.dll b/Nadia.C.Sharp/packages/Jint.2.11.58/lib/netstandard1.3/Jint.dll new file mode 100755 index 0000000..c95344a Binary files /dev/null and b/Nadia.C.Sharp/packages/Jint.2.11.58/lib/netstandard1.3/Jint.dll differ diff --git a/Nadia.C.Sharp/packages/Jint.2.11.58/lib/netstandard2.0/Jint.dll b/Nadia.C.Sharp/packages/Jint.2.11.58/lib/netstandard2.0/Jint.dll new file mode 100755 index 0000000..ef62a7d Binary files /dev/null and b/Nadia.C.Sharp/packages/Jint.2.11.58/lib/netstandard2.0/Jint.dll differ diff --git a/Nadia.C.Sharp/packages/Microsoft.ChakraCore.1.11.0/.signature.p7s b/Nadia.C.Sharp/packages/Microsoft.ChakraCore.1.11.0/.signature.p7s new file mode 100755 index 0000000..b44e7fc Binary files /dev/null and b/Nadia.C.Sharp/packages/Microsoft.ChakraCore.1.11.0/.signature.p7s differ diff --git a/Nadia.C.Sharp/packages/Microsoft.ChakraCore.1.11.0/Microsoft.ChakraCore.1.11.0.nupkg b/Nadia.C.Sharp/packages/Microsoft.ChakraCore.1.11.0/Microsoft.ChakraCore.1.11.0.nupkg new file mode 100644 index 0000000..59c4119 Binary files /dev/null and b/Nadia.C.Sharp/packages/Microsoft.ChakraCore.1.11.0/Microsoft.ChakraCore.1.11.0.nupkg differ diff --git a/Nadia.C.Sharp/packages/Microsoft.ChakraCore.1.11.0/build/netstandard1.0/Microsoft.ChakraCore.props b/Nadia.C.Sharp/packages/Microsoft.ChakraCore.1.11.0/build/netstandard1.0/Microsoft.ChakraCore.props new file mode 100755 index 0000000..2f9163d --- /dev/null +++ b/Nadia.C.Sharp/packages/Microsoft.ChakraCore.1.11.0/build/netstandard1.0/Microsoft.ChakraCore.props @@ -0,0 +1,36 @@ + + + + + x86\%(Filename)%(Extension) + PreserveNewest + False + + + x64\%(Filename)%(Extension) + PreserveNewest + False + + + + + %(Filename)%(Extension) + PreserveNewest + False + + + + + %(Filename)%(Extension) + PreserveNewest + False + + + + + %(Filename)%(Extension) + PreserveNewest + False + + + diff --git a/Nadia.C.Sharp/packages/Microsoft.ChakraCore.1.11.0/lib/netstandard1.0/_._ b/Nadia.C.Sharp/packages/Microsoft.ChakraCore.1.11.0/lib/netstandard1.0/_._ new file mode 100755 index 0000000..e69de29 diff --git a/Nadia.C.Sharp/packages/Microsoft.ChakraCore.1.11.0/runtimes/win7-x64/native/ChakraCore.dll b/Nadia.C.Sharp/packages/Microsoft.ChakraCore.1.11.0/runtimes/win7-x64/native/ChakraCore.dll new file mode 100755 index 0000000..831a030 Binary files /dev/null and b/Nadia.C.Sharp/packages/Microsoft.ChakraCore.1.11.0/runtimes/win7-x64/native/ChakraCore.dll differ diff --git a/Nadia.C.Sharp/packages/Microsoft.ChakraCore.1.11.0/runtimes/win7-x86/native/ChakraCore.dll b/Nadia.C.Sharp/packages/Microsoft.ChakraCore.1.11.0/runtimes/win7-x86/native/ChakraCore.dll new file mode 100755 index 0000000..f5e3395 Binary files /dev/null and b/Nadia.C.Sharp/packages/Microsoft.ChakraCore.1.11.0/runtimes/win7-x86/native/ChakraCore.dll differ diff --git a/Nadia.C.Sharp/packages/Microsoft.ChakraCore.1.11.0/runtimes/win8-arm/native/ChakraCore.dll b/Nadia.C.Sharp/packages/Microsoft.ChakraCore.1.11.0/runtimes/win8-arm/native/ChakraCore.dll new file mode 100755 index 0000000..b5416d3 Binary files /dev/null and b/Nadia.C.Sharp/packages/Microsoft.ChakraCore.1.11.0/runtimes/win8-arm/native/ChakraCore.dll differ diff --git a/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/NativeBinaries/net35/amd64/Microsoft.VC90.CRT/Microsoft.VC90.CRT.manifest b/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/NativeBinaries/net35/amd64/Microsoft.VC90.CRT/Microsoft.VC90.CRT.manifest new file mode 100755 index 0000000..39ae1a7 --- /dev/null +++ b/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/NativeBinaries/net35/amd64/Microsoft.VC90.CRT/Microsoft.VC90.CRT.manifest @@ -0,0 +1,6 @@ + + + + + BYWvegEUfCyiVJwy7tplZYDLDYQ= VVIEvvi79NP3Y8CQaV7j2x7YotU= nS1i+ikFcD/ifqiOGZFwsZG9X/A= + \ No newline at end of file diff --git a/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/NativeBinaries/net35/amd64/Microsoft.VC90.CRT/msvcm90.dll b/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/NativeBinaries/net35/amd64/Microsoft.VC90.CRT/msvcm90.dll new file mode 100755 index 0000000..5189c38 Binary files /dev/null and b/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/NativeBinaries/net35/amd64/Microsoft.VC90.CRT/msvcm90.dll differ diff --git a/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/NativeBinaries/net35/amd64/Microsoft.VC90.CRT/msvcp90.dll b/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/NativeBinaries/net35/amd64/Microsoft.VC90.CRT/msvcp90.dll new file mode 100755 index 0000000..9616b18 Binary files /dev/null and b/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/NativeBinaries/net35/amd64/Microsoft.VC90.CRT/msvcp90.dll differ diff --git a/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/NativeBinaries/net35/amd64/Microsoft.VC90.CRT/msvcr90.dll b/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/NativeBinaries/net35/amd64/Microsoft.VC90.CRT/msvcr90.dll new file mode 100755 index 0000000..07afcb9 Binary files /dev/null and b/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/NativeBinaries/net35/amd64/Microsoft.VC90.CRT/msvcr90.dll differ diff --git a/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/NativeBinaries/net35/x86/Microsoft.VC90.CRT/Microsoft.VC90.CRT.manifest b/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/NativeBinaries/net35/x86/Microsoft.VC90.CRT/Microsoft.VC90.CRT.manifest new file mode 100755 index 0000000..594cb76 --- /dev/null +++ b/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/NativeBinaries/net35/x86/Microsoft.VC90.CRT/Microsoft.VC90.CRT.manifest @@ -0,0 +1,6 @@ + + + + + S83+LBs1RkUxSkzia1WysaAhLbk= cKyCmIKF+fcGn6qaBhKuun+wAcQ= r+4y/NnOFgaANxNXoHL1jF95DUg= + \ No newline at end of file diff --git a/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/NativeBinaries/net35/x86/Microsoft.VC90.CRT/msvcm90.dll b/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/NativeBinaries/net35/x86/Microsoft.VC90.CRT/msvcm90.dll new file mode 100755 index 0000000..434353d Binary files /dev/null and b/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/NativeBinaries/net35/x86/Microsoft.VC90.CRT/msvcm90.dll differ diff --git a/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/NativeBinaries/net35/x86/Microsoft.VC90.CRT/msvcp90.dll b/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/NativeBinaries/net35/x86/Microsoft.VC90.CRT/msvcp90.dll new file mode 100755 index 0000000..af6cc3d Binary files /dev/null and b/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/NativeBinaries/net35/x86/Microsoft.VC90.CRT/msvcp90.dll differ diff --git a/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/NativeBinaries/net35/x86/Microsoft.VC90.CRT/msvcr90.dll b/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/NativeBinaries/net35/x86/Microsoft.VC90.CRT/msvcr90.dll new file mode 100755 index 0000000..ec7f83a Binary files /dev/null and b/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/NativeBinaries/net35/x86/Microsoft.VC90.CRT/msvcr90.dll differ diff --git a/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/NativeBinaries/net40/amd64/Microsoft.VC100.CRT/msvcp100.dll b/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/NativeBinaries/net40/amd64/Microsoft.VC100.CRT/msvcp100.dll new file mode 100755 index 0000000..68fa0d3 Binary files /dev/null and b/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/NativeBinaries/net40/amd64/Microsoft.VC100.CRT/msvcp100.dll differ diff --git a/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/NativeBinaries/net40/amd64/Microsoft.VC100.CRT/msvcr100.dll b/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/NativeBinaries/net40/amd64/Microsoft.VC100.CRT/msvcr100.dll new file mode 100755 index 0000000..0318fb0 Binary files /dev/null and b/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/NativeBinaries/net40/amd64/Microsoft.VC100.CRT/msvcr100.dll differ diff --git a/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/NativeBinaries/net40/x86/Microsoft.VC100.CRT/msvcp100.dll b/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/NativeBinaries/net40/x86/Microsoft.VC100.CRT/msvcp100.dll new file mode 100755 index 0000000..e9eae44 Binary files /dev/null and b/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/NativeBinaries/net40/x86/Microsoft.VC100.CRT/msvcp100.dll differ diff --git a/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/NativeBinaries/net40/x86/Microsoft.VC100.CRT/msvcr100.dll b/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/NativeBinaries/net40/x86/Microsoft.VC100.CRT/msvcr100.dll new file mode 100755 index 0000000..fd91c89 Binary files /dev/null and b/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/NativeBinaries/net40/x86/Microsoft.VC100.CRT/msvcr100.dll differ diff --git a/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/Noesis.Javascript.0.7.1.0.nupkg b/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/Noesis.Javascript.0.7.1.0.nupkg new file mode 100644 index 0000000..36628d3 Binary files /dev/null and b/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/Noesis.Javascript.0.7.1.0.nupkg differ diff --git a/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/lib/net35/amd64/Noesis.Javascript.dll b/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/lib/net35/amd64/Noesis.Javascript.dll new file mode 100755 index 0000000..66b2058 Binary files /dev/null and b/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/lib/net35/amd64/Noesis.Javascript.dll differ diff --git a/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/lib/net35/x86/Noesis.Javascript.dll b/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/lib/net35/x86/Noesis.Javascript.dll new file mode 100755 index 0000000..d11f1c0 Binary files /dev/null and b/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/lib/net35/x86/Noesis.Javascript.dll differ diff --git a/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/lib/net40/amd64/Noesis.Javascript.dll b/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/lib/net40/amd64/Noesis.Javascript.dll new file mode 100755 index 0000000..88dcdb2 Binary files /dev/null and b/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/lib/net40/amd64/Noesis.Javascript.dll differ diff --git a/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/lib/net40/x86/Noesis.Javascript.dll b/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/lib/net40/x86/Noesis.Javascript.dll new file mode 100755 index 0000000..3016d76 Binary files /dev/null and b/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/lib/net40/x86/Noesis.Javascript.dll differ diff --git a/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/tools/net35/Install.ps1 b/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/tools/net35/Install.ps1 new file mode 100755 index 0000000..95a99ee --- /dev/null +++ b/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/tools/net35/Install.ps1 @@ -0,0 +1,160 @@ +param($installPath, $toolsPath, $package, $project) + +Import-Module (Join-Path $toolsPath VS.psd1) +$nativeBinDirectory = Join-Path $installPath "NativeBinaries\net35" +if ($project.Type -eq 'Web Site') { + $projectRoot = Get-ProjectRoot $project + if (!$projectRoot) { + return; + } + + $binDirectory = Join-Path $projectRoot "bin" + $libDirectory = Join-Path $installPath "lib\net35" + Add-FilesToDirectory $libDirectory $binDirectory + Add-FilesToDirectory $nativeBinDirectory $binDirectory +} +elseif($project.ExtenderNames -contains "WebApplication") { + $depAsm = Ensure-Folder $Project "_bin_deployableAssemblies"; + if($depAsm) { + $amd64 = Ensure-Folder $depAsm "amd64"; + if($amd64) { + $amd64dir = (Join-Path $nativeBinDirectory "amd64") + $crt64 = Ensure-Folder $amd64 "Microsoft.VC90.CRT"; + if($crt64) { + $crt64dir = (Join-Path $amd64dir "Microsoft.VC90.CRT") + Add-ProjectItem $crt64 (Join-Path $crt64dir "Microsoft.VC90.CRT.manifest"); + Add-ProjectItem $crt64 (Join-Path $crt64dir "msvcm90.dll"); + Add-ProjectItem $crt64 (Join-Path $crt64dir "msvcp90.dll"); + Add-ProjectItem $crt64 (Join-Path $crt64dir "msvcr90.dll"); + } + } + $x86 = Ensure-Folder $depAsm "x86"; + if($x86) { + $x86dir = (Join-Path $nativeBinDirectory "x86") + $crt32 = Ensure-Folder $x86 "Microsoft.VC90.CRT"; + if($crt32) { + $crt32dir = (Join-Path $x86dir "Microsoft.VC90.CRT") + Add-ProjectItem $crt32 (Join-Path $crt32dir "Microsoft.VC90.CRT.manifest"); + Add-ProjectItem $crt64 (Join-Path $crt32dir "msvcm90.dll"); + Add-ProjectItem $crt64 (Join-Path $crt32dir "msvcp90.dll"); + Add-ProjectItem $crt64 (Join-Path $crt32dir "msvcr90.dll"); + } + } + } +} +else { + Add-PostBuildEvent $project $installPath +} + +$project.Object.References | Where-Object { $_.Name -eq 'Noesis.Javascript' } | ForEach-Object { write-host $_.Name } + +Remove-Module VS + + +$allowedReferences = @("^(Noesis\.Javascript)(,.*)?$") + +# Full assembly name is required +Add-Type -AssemblyName 'Microsoft.Build, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' + +$projectCollection = [Microsoft.Build.Evaluation.ProjectCollection]::GlobalProjectCollection + +$allProjects = $projectCollection.GetLoadedProjects($project.Object.Project.FullName).GetEnumerator(); + +if($allProjects.MoveNext()) +{ + $currentProject = $allProjects.Current + + foreach($Reference in $currentProject.GetItems('Reference') | % {$_}) + { + $allowedReferenceMatches = $allowedReferences | ? {$Reference.Xml.Include -match $_} + + if (($allowedReferenceMatches | Measure-Object).Count -gt 0) + { + $allowedReferenceMatch = $allowedReferenceMatches | Select-Object -First 1 + $include = $Reference.Xml.Include -replace $allowedReferenceMatch, '$1' + $hintPath = $Reference.GetMetadataValue("HintPath") + + write-host "Matched againt $hintPath" + + #If it is x64 specific add condition (Include 'Any Cpu' as x64) + if ($hintPath -match '.*\\(amd64|x64)\\.*\.dll$') + { + $Reference.Xml.Condition = '''$(PlatformTarget)'' != ''x86''' + + $condition = $Reference.Xml.Condition + write-host "hintPath = $hintPath" + write-host "condition = $condition" + + #Visual Studio doesnt allow the same reference twice (so try add friends) + $matchingReferences = $currentProject.GetItems('Reference') | ? {($_.Xml.Include -match $allowedReferenceMatch) -and ($_.GetMetadataValue("HintPath") -match ".*\\(x86)\\.*\.dll$")} + + if (($matchingReferences | Measure-Object).Count -eq 0) + { + $x86 = $hintPath -replace '(.*\\)(amd64|x64)(\\.*\.dll)$', '$1x86$3' + $x86Path = Join-Path $installPath $x86 + + if (Test-Path $x86Path) { + #Add + write-host "Adding reference to $x86" + + $metaData = new-object "System.Collections.Generic.Dictionary``2[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]" + $metaData.Add("HintPath", $x86) + $currentProject.AddItem('Reference', $include, $metaData) + + $newReference = $currentProject.GetItems('Reference') | ? {($_.Xml.Include -eq $include) -and ($_.GetMetadataValue("HintPath") -eq $x86)} | Select-Object -First 1 + + $newReference.Xml.Condition = '''$(PlatformTarget)'' == ''x86''' + } + } + } + + #If it is x86 specific add condition + if ($hintPath -match '.*\\x86\\.*\.dll$') + { + $Reference.Xml.Condition = '''$(PlatformTarget)'' == ''x86''' + + $condition = $Reference.Xml.Condition + write-host "hintPath = $hintPath" + write-host "condition = $condition" + + #Visual Studio doesnt allow the same reference twice (so try add friends) + $matchingReferences = $currentProject.GetItems('Reference') | ? {($_.Xml.Include -match $allowedReferenceMatch) -and ($_.GetMetadataValue("HintPath") -match ".*\\(amd64|x64)\\.*\.dll$")} + + if (($matchingReferences | Measure-Object).Count -eq 0) + { + $x64 = $hintPath -replace '(.*\\)(x86)(\\.*\.dll)$', '$1x64$3' + $x64Path = Join-Path $installPath $x64 + + if (Test-Path $x64Path) { + #Add + write-host "Adding reference to $x64" + + $metaData = new-object "System.Collections.Generic.Dictionary``2[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]" + $metaData.Add("HintPath", $x64) + $currentProject.AddItem('Reference', $include, $metaData) + + $newReference = $currentProject.GetItems('Reference') | ? {($_.Xml.Include -eq $include) -and ($_.GetMetadataValue("HintPath") -eq $x64)} | Select-Object -First 1 + + $newReference.Xml.Condition = '''$(PlatformTarget)'' != ''x86''' + } else { + $amd64 = $hintPath -replace '(.*\\)(x86)(\\.*\.dll)$', '$1amd64$3' + $amd64Path = Join-Path $installPath $amd64 + + if (Test-Path $amd64Path) { + #Add + write-host "Adding reference to $amd64" + + $metaData = new-object "System.Collections.Generic.Dictionary``2[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]" + $metaData.Add("HintPath", $amd64) + $currentProject.AddItem('Reference', $include, $metaData) + + $newReference = $currentProject.GetItems('Reference') | ? {($_.Xml.Include -eq $include) -and ($_.GetMetadataValue("HintPath") -eq $amd64)} | Select-Object -First 1 + + $newReference.Xml.Condition = '''$(PlatformTarget)'' != ''x86''' + } + } + } + } + } + } +} \ No newline at end of file diff --git a/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/tools/net35/Uninstall.ps1 b/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/tools/net35/Uninstall.ps1 new file mode 100755 index 0000000..72912ce --- /dev/null +++ b/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/tools/net35/Uninstall.ps1 @@ -0,0 +1,67 @@ +param($installPath, $toolsPath, $package, $project) + +Import-Module (Join-Path $toolsPath VS.psd1) +if ($project.Type -eq 'Web Site') { + $projectRoot = Get-ProjectRoot $project + if (!$projectRoot) { + return; + } + + $binDirectory = Join-Path $projectRoot "bin" + $libDirectory = Join-Path $installPath "lib\net35" + $nativeBinDirectory = Join-Path $installPath "NativeBinaries" + + Remove-FilesFromDirectory $libDirectory $binDirectory + Remove-FilesFromDirectory $nativeBinDirectory $binDirectory +} +elseif($project.ExtenderNames -contains "WebApplication") { + $depAsm = Get-ChildProjectItem $Project "_bin_deployableAssemblies"; + if($depAsm) { + $amd64 = Get-ChildProjectItem $depAsm "amd64"; + if($amd64) { + $crt64 = Get-ChildProjectItem $amd64 "Microsoft.VC90.CRT"; + if($crt64) { + Remove-Child $crt64 "Microsoft.VC90.CRT.manifest"; + Remove-Child $crt64 "msvcm90.dll"; + Remove-Child $crt64 "msvcp90.dll"; + Remove-Child $crt64 "msvcr90.dll"; + Remove-EmptyFolder $crt64; + } + Remove-EmptyFolder $amd64; + } + $x86 = Get-ChildProjectItem $depAsm "x86"; + if($x86) { + $crt32 = Get-ChildProjectItem $x86 "Microsoft.VC90.CRT"; + if($crt32) { + Remove-Child $crt32 "Microsoft.VC90.CRT.manifest"; + Remove-Child $crt32 "msvcm90.dll"; + Remove-Child $crt32 "msvcp90.dll"; + Remove-Child $crt32 "msvcr90.dll"; + Remove-EmptyFolder $crt32; + } + Remove-EmptyFolder $x86; + } + } + Remove-EmptyFolder $depAsm +} +else { + Remove-PostBuildEvent $project $installPath +} +Remove-Module VS + +$allowedReferences = @("Noesis.Javascript") + +# Full assembly name is required +Add-Type -AssemblyName 'Microsoft.Build, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' + +$projectCollection = [Microsoft.Build.Evaluation.ProjectCollection]::GlobalProjectCollection + +$allProjects = $projectCollection.GetLoadedProjects($project.Object.Project.FullName).GetEnumerator(); + +if($allProjects.MoveNext()) +{ + foreach($Reference in $allProjects.Current.GetItems('Reference') | ? {$allowedReferences -contains $_.UnevaluatedInclude }) + { + $allProjects.Current.RemoveItem($Reference) + } +} \ No newline at end of file diff --git a/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/tools/net35/VS.psd1 b/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/tools/net35/VS.psd1 new file mode 100755 index 0000000..18ccb71 --- /dev/null +++ b/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/tools/net35/VS.psd1 @@ -0,0 +1,78 @@ +@{ + +# Script module or binary module file associated with this manifest +ModuleToProcess = 'VS.psm1' + +# Version number of this module. +ModuleVersion = '0.1' + +# ID used to uniquely identify this module +GUID = 'b1ab5d7d-d317-4c6d-97b8-4620f93082d3' + +# Author of this module +Author = 'Microsoft Corporation' + +# Company or vendor of this module +CompanyName = 'Microsoft Corporation' + +# Copyright statement for this module +Copyright = '(c) 2011 Microsoft Corporation. All rights reserved.' + +# Description of the functionality provided by this module +Description = 'Powershell wrapper for NuGet.VisualStudio' + +# Minimum version of the Windows PowerShell engine required by this module +PowerShellVersion = '2.0' + +# Name of the Windows PowerShell host required by this module +PowerShellHostName = 'Package Manager Host' + +# Minimum version of the Windows PowerShell host required by this module +PowerShellHostVersion = '1.2' + +# Minimum version of the .NET Framework required by this module +DotNetFrameworkVersion = '3.5' + +# Minimum version of the common language runtime (CLR) required by this module +CLRVersion = '' + +# Processor architecture (None, X86, Amd64, IA64) required by this module +ProcessorArchitecture = '' + +# Modules that must be imported into the global environment prior to importing this module +RequiredModules = @() + +# Assemblies that must be loaded prior to importing this module +RequiredAssemblies = @() + +# Script files (.ps1) that are run in the caller's environment prior to importing this module +ScriptsToProcess = @() + +# Type files (.ps1xml) to be loaded when importing this module +TypesToProcess = @() + +# Format files (.ps1xml) to be loaded when importing this module +FormatsToProcess = @() + +# Modules to import as nested modules of the module specified in ModuleToProcess +NestedModules = @('VS.psm1') + +# Functions to export from this module +FunctionsToExport = '*' + +# Cmdlets to export from this module +CmdletsToExport = '' + +# Variables to export from this module +VariablesToExport = '' + +# Aliases to export from this module +AliasesToExport = '' + +# List of all files packaged with this module +FileList = @() + +# Private data to pass to the module specified in ModuleToProcess +PrivateData = '' + +} \ No newline at end of file diff --git a/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/tools/net35/VS.psm1 b/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/tools/net35/VS.psm1 new file mode 100755 index 0000000..5754153 --- /dev/null +++ b/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/tools/net35/VS.psm1 @@ -0,0 +1,133 @@ +function Get-VsFileSystem { + $componentModel = Get-VSComponentModel + $fileSystemProvider = $componentModel.GetService([NuGet.VisualStudio.IFileSystemProvider]) + $solutionManager = $componentModel.GetService([NuGet.VisualStudio.ISolutionManager]) + + $fileSystem = $fileSystemProvider.GetFileSystem($solutionManager.SolutionDirectory) + + return $fileSystem +} + +function Add-PostBuildEvent ($project, $installPath) { + $currentPostBuildCmd = $project.Properties.Item("PostBuildEvent").Value + $sqlCEPostBuildCmd = Get-PostBuildCommand $installPath + # Append our post build command if it's not already there + if (!$currentPostBuildCmd.Contains($sqlCEPostBuildCmd)) { + $project.Properties.Item("PostBuildEvent").Value += $SqlCEPostBuildCmd + } +} + +function Add-FilesToDirectory ($srcDirectory, $destDirectory) { + ls $srcDirectory -Recurse -Filter *.dll | %{ + $srcPath = $_.FullName + + $relativePath = $srcPath.Substring($srcDirectory.Length + 1) + $destPath = Join-Path $destDirectory $relativePath + + $fileSystem = Get-VsFileSystem + if (!(Test-Path $destPath)) { + $fileStream = $null + try { + $fileStream = [System.IO.File]::OpenRead($_.FullName) + $fileSystem.AddFile($destPath, $fileStream) + } catch { + # We don't want an exception to surface if we can't add the file for some reason + } finally { + if ($fileStream -ne $null) { + $fileStream.Dispose() + } + } + } + } +} + +function Remove-FilesFromDirectory ($srcDirectory, $destDirectory) { + $fileSystem = Get-VsFileSystem + + ls $srcDirectory -Recurse -Filter *.dll | %{ + $relativePath = $_.FullName.Substring($srcDirectory.Length + 1) + $fileInBin = Join-Path $destDirectory $relativePath + if ($fileSystem.FileExists($fileInBin) -and ((Get-Item $fileInBin).Length -eq $_.Length)) { + # If a corresponding file exists in bin and has the exact file size as the one inside the package, it's most likely the same file. + try { + $fileSystem.DeleteFile($fileInBin) + } catch { + # We don't want an exception to surface if we can't delete the file + } + } + } +} + +function Remove-PostBuildEvent ($project, $installPath) { + $sqlCEPostBuildCmd = Get-PostBuildCommand $installPath + + try { + # Get the current Post Build Event cmd + $currentPostBuildCmd = $project.Properties.Item("PostBuildEvent").Value + + # Remove our post build command from it (if it's there) + $project.Properties.Item("PostBuildEvent").Value = $currentPostBuildCmd.Replace($SqlCEPostBuildCmd, '') + } catch { + # Accessing $project.Properties might throw + } +} + +function Get-PostBuildCommand ($installPath) { + Write-Host $dte.Solution.FullName $installPath + $solutionDir = [IO.Path]::GetDirectoryName($dte.Solution.FullName) + "\" + $path = $installPath.Replace($solutionDir, "`$(SolutionDir)") + + $NativeAssembliesDir = Join-Path $path "NativeBinaries" + $x86 = $(Join-Path $NativeAssembliesDir "net35\x86\*.*") + $x64 = $(Join-Path $NativeAssembliesDir "net35\amd64\*.*") + + return " + if not exist `"`$(TargetDir)x86`" md `"`$(TargetDir)x86`" + xcopy /s /y `"$x86`" `"`$(TargetDir)x86`" + if not exist `"`$(TargetDir)amd64`" md `"`$(TargetDir)amd64`" + xcopy /s /y `"$x64`" `"`$(TargetDir)amd64`"" +} + +function Get-ProjectRoot($project) { + try { + $project.Properties.Item("FullPath").Value + } catch { + + } +} + +function Get-ChildProjectItem($parent, $name) { + try { + return $parent.ProjectItems.Item($name); + } catch { + + } +} + +function Ensure-Folder($parent, $name) { + $item = Get-ChildProjectItem $parent $name + if(!$item) { + $item = (Get-Interface $parent.ProjectItems "EnvDTE.ProjectItems").AddFolder($name) + } + return $item; +} + +function Remove-Child($parent, $name) { + $item = Get-ChildProjectItem $parent $name + if($item) { + (Get-Interface $item "EnvDTE.ProjectItem").Delete() + } +} + +function Remove-EmptyFolder($item) { + if($item.ProjectItems.Count -eq 0) { + (Get-Interface $item "EnvDTE.ProjectItem").Delete() + } +} + +function Add-ProjectItem($item, $src, $itemtype = "None") { + $newitem = (Get-Interface $item.ProjectItems "EnvDTE.ProjectItems").AddFromFileCopy($src) + $newitem.Properties.Item("ItemType").Value = $itemtype +} + +Export-ModuleMember -function Add-PostBuildEvent, Add-FilesToDirectory, Remove-PostBuildEvent, Remove-FilesFromDirectory, Get-ProjectRoot, Get-ChildProjectItem, Ensure-Folder, Remove-Child, Remove-EmptyFolder, Add-ProjectItem \ No newline at end of file diff --git a/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/tools/net40/Install.ps1 b/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/tools/net40/Install.ps1 new file mode 100755 index 0000000..5edee8d --- /dev/null +++ b/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/tools/net40/Install.ps1 @@ -0,0 +1,154 @@ +param($installPath, $toolsPath, $package, $project) + +Import-Module (Join-Path $toolsPath VS.psd1) +$nativeBinDirectory = Join-Path $installPath "NativeBinaries\net40" +if ($project.Type -eq 'Web Site') { + $projectRoot = Get-ProjectRoot $project + if (!$projectRoot) { + return; + } + + $binDirectory = Join-Path $projectRoot "bin" + $libDirectory = Join-Path $installPath "lib\net40" + Add-FilesToDirectory $libDirectory $binDirectory + Add-FilesToDirectory $nativeBinDirectory $binDirectory +} +elseif($project.ExtenderNames -contains "WebApplication") { + $depAsm = Ensure-Folder $Project "_bin_deployableAssemblies"; + if($depAsm) { + $amd64 = Ensure-Folder $depAsm "amd64"; + if($amd64) { + $amd64dir = (Join-Path $nativeBinDirectory "amd64") + $crt64 = Ensure-Folder $amd64 "Microsoft.VC100.CRT"; + if($crt64) { + $crt64dir = (Join-Path $amd64dir "Microsoft.VC100.CRT") + Add-ProjectItem $crt64 (Join-Path $crt64dir "msvcp100.dll"); + Add-ProjectItem $crt64 (Join-Path $crt64dir "msvcr100.dll"); + } + } + $x86 = Ensure-Folder $depAsm "x86"; + if($x86) { + $x86dir = (Join-Path $nativeBinDirectory "x86") + $crt32 = Ensure-Folder $x86 "Microsoft.VC100.CRT"; + if($crt32) { + $crt32dir = (Join-Path $x86dir "Microsoft.VC100.CRT") + Add-ProjectItem $crt64 (Join-Path $crt32dir "msvcp100.dll"); + Add-ProjectItem $crt64 (Join-Path $crt32dir "msvcr100.dll"); + } + } + } +} +else { + Add-PostBuildEvent $project $installPath +} + +Remove-Module VS + + +$allowedReferences = @("^(Noesis\.Javascript)(,.*)?$") + +# Full assembly name is required +Add-Type -AssemblyName 'Microsoft.Build, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' + +$projectCollection = [Microsoft.Build.Evaluation.ProjectCollection]::GlobalProjectCollection + +$allProjects = $projectCollection.GetLoadedProjects($project.Object.Project.FullName).GetEnumerator(); + +if($allProjects.MoveNext()) +{ + $currentProject = $allProjects.Current + + foreach($Reference in $currentProject.GetItems('Reference') | % {$_}) + { + $allowedReferenceMatches = $allowedReferences | ? {$Reference.Xml.Include -match $_} + + if (($allowedReferenceMatches | Measure-Object).Count -gt 0) + { + $allowedReferenceMatch = $allowedReferenceMatches | Select-Object -First 1 + $include = $Reference.Xml.Include -replace $allowedReferenceMatch, '$1' + $hintPath = $Reference.GetMetadataValue("HintPath") + + write-host "Matched againt $hintPath" + + #If it is x64 specific add condition (Include 'Any Cpu' as x64) + if ($hintPath -match '.*\\(amd64|x64)\\.*\.dll$') + { + $Reference.Xml.Condition = '''$(PlatformTarget)'' != ''x86''' + + $condition = $Reference.Xml.Condition + write-host "hintPath = $hintPath" + write-host "condition = $condition" + + #Visual Studio doesnt allow the same reference twice (so try add friends) + $matchingReferences = $currentProject.GetItems('Reference') | ? {($_.Xml.Include -match $allowedReferenceMatch) -and ($_.GetMetadataValue("HintPath") -match ".*\\(x86)\\.*\.dll$")} + + if (($matchingReferences | Measure-Object).Count -eq 0) + { + $x86 = $hintPath -replace '(.*\\)(amd64|x64)(\\.*\.dll)$', '$1x86$3' + $x86Path = Join-Path $installPath $x86 + + if (Test-Path $x86Path) { + #Add + write-host "Adding reference to $x86" + + $metaData = new-object "System.Collections.Generic.Dictionary``2[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]" + $metaData.Add("HintPath", $x86) + $currentProject.AddItem('Reference', $include, $metaData) + + $newReference = $currentProject.GetItems('Reference') | ? {($_.Xml.Include -eq $include) -and ($_.GetMetadataValue("HintPath") -eq $x86)} | Select-Object -First 1 + + $newReference.Xml.Condition = '''$(PlatformTarget)'' == ''x86''' + } + } + } + + #If it is x86 specific add condition + if ($hintPath -match '.*\\x86\\.*\.dll$') + { + $Reference.Xml.Condition = '''$(PlatformTarget)'' == ''x86''' + + $condition = $Reference.Xml.Condition + write-host "hintPath = $hintPath" + write-host "condition = $condition" + + #Visual Studio doesnt allow the same reference twice (so try add friends) + $matchingReferences = $currentProject.GetItems('Reference') | ? {($_.Xml.Include -match $allowedReferenceMatch) -and ($_.GetMetadataValue("HintPath") -match ".*\\(amd64|x64)\\.*\.dll$")} + + if (($matchingReferences | Measure-Object).Count -eq 0) + { + $x64 = $hintPath -replace '(.*\\)(x86)(\\.*\.dll)$', '$1x64$3' + $x64Path = Join-Path $installPath $x64 + + if (Test-Path $x64Path) { + #Add + write-host "Adding reference to $x64" + + $metaData = new-object "System.Collections.Generic.Dictionary``2[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]" + $metaData.Add("HintPath", $x64) + $currentProject.AddItem('Reference', $include, $metaData) + + $newReference = $currentProject.GetItems('Reference') | ? {($_.Xml.Include -eq $include) -and ($_.GetMetadataValue("HintPath") -eq $x64)} | Select-Object -First 1 + + $newReference.Xml.Condition = '''$(PlatformTarget)'' != ''x86''' + } else { + $amd64 = $hintPath -replace '(.*\\)(x86)(\\.*\.dll)$', '$1amd64$3' + $amd64Path = Join-Path $installPath $amd64 + + if (Test-Path $amd64Path) { + #Add + write-host "Adding reference to $amd64" + + $metaData = new-object "System.Collections.Generic.Dictionary``2[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]" + $metaData.Add("HintPath", $amd64) + $currentProject.AddItem('Reference', $include, $metaData) + + $newReference = $currentProject.GetItems('Reference') | ? {($_.Xml.Include -eq $include) -and ($_.GetMetadataValue("HintPath") -eq $amd64)} | Select-Object -First 1 + + $newReference.Xml.Condition = '''$(PlatformTarget)'' != ''x86''' + } + } + } + } + } + } +} \ No newline at end of file diff --git a/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/tools/net40/Uninstall.ps1 b/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/tools/net40/Uninstall.ps1 new file mode 100755 index 0000000..6a284e6 --- /dev/null +++ b/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/tools/net40/Uninstall.ps1 @@ -0,0 +1,65 @@ +param($installPath, $toolsPath, $package, $project) + +Import-Module (Join-Path $toolsPath VS.psd1) +if ($project.Type -eq 'Web Site') { + $projectRoot = Get-ProjectRoot $project + if (!$projectRoot) { + return; + } + + $binDirectory = Join-Path $projectRoot "bin" + $libDirectory = Join-Path $installPath "lib\net40" + $nativeBinDirectory = Join-Path $installPath "NativeBinaries" + + Remove-FilesFromDirectory $libDirectory $binDirectory + Remove-FilesFromDirectory $nativeBinDirectory $binDirectory +} +elseif($project.ExtenderNames -contains "WebApplication") { + $depAsm = Get-ChildProjectItem $Project "_bin_deployableAssemblies"; + if($depAsm) { + $amd64 = Get-ChildProjectItem $depAsm "amd64"; + if($amd64) { + $crt64 = Get-ChildProjectItem $amd64 "Microsoft.VC100.CRT"; + if($crt64) { + Remove-Child $crt64 "Microsoft.VC90.CRT.manifest"; + Remove-Child $crt64 "msvcp100.dll"; + Remove-Child $crt64 "msvcr100.dll"; + Remove-EmptyFolder $crt64; + } + Remove-EmptyFolder $amd64; + } + $x86 = Get-ChildProjectItem $depAsm "x86"; + if($x86) { + $crt32 = Get-ChildProjectItem $x86 "Microsoft.VC100.CRT"; + if($crt32) { + Remove-Child $crt32 "Microsoft.VC100.CRT.manifest"; + Remove-Child $crt32 "msvcp100.dll"; + Remove-Child $crt32 "msvcr100.dll"; + Remove-EmptyFolder $crt32; + } + Remove-EmptyFolder $x86; + } + } + Remove-EmptyFolder $depAsm +} +else { + Remove-PostBuildEvent $project $installPath +} +Remove-Module VS + +$allowedReferences = @("Noesis.Javascript") + +# Full assembly name is required +Add-Type -AssemblyName 'Microsoft.Build, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' + +$projectCollection = [Microsoft.Build.Evaluation.ProjectCollection]::GlobalProjectCollection + +$allProjects = $projectCollection.GetLoadedProjects($project.Object.Project.FullName).GetEnumerator(); + +if($allProjects.MoveNext()) +{ + foreach($Reference in $allProjects.Current.GetItems('Reference') | ? {$allowedReferences -contains $_.UnevaluatedInclude }) + { + $allProjects.Current.RemoveItem($Reference) + } +} \ No newline at end of file diff --git a/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/tools/net40/VS.psd1 b/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/tools/net40/VS.psd1 new file mode 100755 index 0000000..38bfeb9 --- /dev/null +++ b/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/tools/net40/VS.psd1 @@ -0,0 +1,78 @@ +@{ + +# Script module or binary module file associated with this manifest +ModuleToProcess = 'VS.psm1' + +# Version number of this module. +ModuleVersion = '0.1' + +# ID used to uniquely identify this module +GUID = 'b1ab5d7d-d317-4c6d-97b8-4620f93082d3' + +# Author of this module +Author = 'Microsoft Corporation' + +# Company or vendor of this module +CompanyName = 'Microsoft Corporation' + +# Copyright statement for this module +Copyright = '(c) 2011 Microsoft Corporation. All rights reserved.' + +# Description of the functionality provided by this module +Description = 'Powershell wrapper for NuGet.VisualStudio' + +# Minimum version of the Windows PowerShell engine required by this module +PowerShellVersion = '2.0' + +# Name of the Windows PowerShell host required by this module +PowerShellHostName = 'Package Manager Host' + +# Minimum version of the Windows PowerShell host required by this module +PowerShellHostVersion = '1.2' + +# Minimum version of the .NET Framework required by this module +DotNetFrameworkVersion = '4.0' + +# Minimum version of the common language runtime (CLR) required by this module +CLRVersion = '' + +# Processor architecture (None, X86, Amd64, IA64) required by this module +ProcessorArchitecture = '' + +# Modules that must be imported into the global environment prior to importing this module +RequiredModules = @() + +# Assemblies that must be loaded prior to importing this module +RequiredAssemblies = @() + +# Script files (.ps1) that are run in the caller's environment prior to importing this module +ScriptsToProcess = @() + +# Type files (.ps1xml) to be loaded when importing this module +TypesToProcess = @() + +# Format files (.ps1xml) to be loaded when importing this module +FormatsToProcess = @() + +# Modules to import as nested modules of the module specified in ModuleToProcess +NestedModules = @('VS.psm1') + +# Functions to export from this module +FunctionsToExport = '*' + +# Cmdlets to export from this module +CmdletsToExport = '' + +# Variables to export from this module +VariablesToExport = '' + +# Aliases to export from this module +AliasesToExport = '' + +# List of all files packaged with this module +FileList = @() + +# Private data to pass to the module specified in ModuleToProcess +PrivateData = '' + +} \ No newline at end of file diff --git a/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/tools/net40/VS.psm1 b/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/tools/net40/VS.psm1 new file mode 100755 index 0000000..e7d8295 --- /dev/null +++ b/Nadia.C.Sharp/packages/Noesis.Javascript.0.7.1.0/tools/net40/VS.psm1 @@ -0,0 +1,133 @@ +function Get-VsFileSystem { + $componentModel = Get-VSComponentModel + $fileSystemProvider = $componentModel.GetService([NuGet.VisualStudio.IFileSystemProvider]) + $solutionManager = $componentModel.GetService([NuGet.VisualStudio.ISolutionManager]) + + $fileSystem = $fileSystemProvider.GetFileSystem($solutionManager.SolutionDirectory) + + return $fileSystem +} + +function Add-PostBuildEvent ($project, $installPath) { + $currentPostBuildCmd = $project.Properties.Item("PostBuildEvent").Value + $sqlCEPostBuildCmd = Get-PostBuildCommand $installPath + # Append our post build command if it's not already there + if (!$currentPostBuildCmd.Contains($sqlCEPostBuildCmd)) { + $project.Properties.Item("PostBuildEvent").Value += $SqlCEPostBuildCmd + } +} + +function Add-FilesToDirectory ($srcDirectory, $destDirectory) { + ls $srcDirectory -Recurse -Filter *.dll | %{ + $srcPath = $_.FullName + + $relativePath = $srcPath.Substring($srcDirectory.Length + 1) + $destPath = Join-Path $destDirectory $relativePath + + $fileSystem = Get-VsFileSystem + if (!(Test-Path $destPath)) { + $fileStream = $null + try { + $fileStream = [System.IO.File]::OpenRead($_.FullName) + $fileSystem.AddFile($destPath, $fileStream) + } catch { + # We don't want an exception to surface if we can't add the file for some reason + } finally { + if ($fileStream -ne $null) { + $fileStream.Dispose() + } + } + } + } +} + +function Remove-FilesFromDirectory ($srcDirectory, $destDirectory) { + $fileSystem = Get-VsFileSystem + + ls $srcDirectory -Recurse -Filter *.dll | %{ + $relativePath = $_.FullName.Substring($srcDirectory.Length + 1) + $fileInBin = Join-Path $destDirectory $relativePath + if ($fileSystem.FileExists($fileInBin) -and ((Get-Item $fileInBin).Length -eq $_.Length)) { + # If a corresponding file exists in bin and has the exact file size as the one inside the package, it's most likely the same file. + try { + $fileSystem.DeleteFile($fileInBin) + } catch { + # We don't want an exception to surface if we can't delete the file + } + } + } +} + +function Remove-PostBuildEvent ($project, $installPath) { + $sqlCEPostBuildCmd = Get-PostBuildCommand $installPath + + try { + # Get the current Post Build Event cmd + $currentPostBuildCmd = $project.Properties.Item("PostBuildEvent").Value + + # Remove our post build command from it (if it's there) + $project.Properties.Item("PostBuildEvent").Value = $currentPostBuildCmd.Replace($SqlCEPostBuildCmd, '') + } catch { + # Accessing $project.Properties might throw + } +} + +function Get-PostBuildCommand ($installPath) { + Write-Host $dte.Solution.FullName $installPath + $solutionDir = [IO.Path]::GetDirectoryName($dte.Solution.FullName) + "\" + $path = $installPath.Replace($solutionDir, "`$(SolutionDir)") + + $NativeAssembliesDir = Join-Path $path "NativeBinaries" + $x86 = $(Join-Path $NativeAssembliesDir "net40\x86\*.*") + $x64 = $(Join-Path $NativeAssembliesDir "net40\amd64\*.*") + + return " + if not exist `"`$(TargetDir)x86`" md `"`$(TargetDir)x86`" + xcopy /s /y `"$x86`" `"`$(TargetDir)x86`" + if not exist `"`$(TargetDir)amd64`" md `"`$(TargetDir)amd64`" + xcopy /s /y `"$x64`" `"`$(TargetDir)amd64`"" +} + +function Get-ProjectRoot($project) { + try { + $project.Properties.Item("FullPath").Value + } catch { + + } +} + +function Get-ChildProjectItem($parent, $name) { + try { + return $parent.ProjectItems.Item($name); + } catch { + + } +} + +function Ensure-Folder($parent, $name) { + $item = Get-ChildProjectItem $parent $name + if(!$item) { + $item = (Get-Interface $parent.ProjectItems "EnvDTE.ProjectItems").AddFolder($name) + } + return $item; +} + +function Remove-Child($parent, $name) { + $item = Get-ChildProjectItem $parent $name + if($item) { + (Get-Interface $item "EnvDTE.ProjectItem").Delete() + } +} + +function Remove-EmptyFolder($item) { + if($item.ProjectItems.Count -eq 0) { + (Get-Interface $item "EnvDTE.ProjectItem").Delete() + } +} + +function Add-ProjectItem($item, $src, $itemtype = "None") { + $newitem = (Get-Interface $item.ProjectItems "EnvDTE.ProjectItems").AddFromFileCopy($src) + $newitem.Properties.Item("ItemType").Value = $itemtype +} + +Export-ModuleMember -function Add-PostBuildEvent, Add-FilesToDirectory, Remove-PostBuildEvent, Remove-FilesFromDirectory, Get-ProjectRoot, Get-ChildProjectItem, Ensure-Folder, Remove-Child, Remove-EmptyFolder, Add-ProjectItem