private static ILanguagePackage SelectLanguage(RecorderLanguages languageCode) { ILanguagePackage languagePackage = null; switch (languageCode) { case RecorderLanguages.PowerShell: languagePackage = new PsLanguage(); break; case RecorderLanguages.CSharp: languagePackage = new CsLanguage(); break; case RecorderLanguages.Java: languagePackage = new JavaLanguage(); break; default: //throw new Exception("Invalid value for RecorderLanguages"); languagePackage = new PsLanguage(); break; } return(languagePackage); }
public void SetCurrentLanguage(string languageCode) { ILanguagePackage package = m_AllPackages.FirstOrDefault(x => x.LanguageCode == languageCode); if (package == null) { throw new Exception("Specified language package could not be found."); } m_PackageSource.LoadPackage(package); this.CurrentPackage = package; }
public I18NOptions AddPackage(ILanguagePackage package) { if (package == null) { throw new ArgumentNullException(nameof(package)); } lock (__lock_package) { if (TryRegisterLanguageOnce(package.Language)) { AddPackageInternal(package); } else if (__languagePackages.TryGetValue(package.Language, out var pkg) && pkg.IsFuture()) { __languagePackages[package.Language] = package.Merge(__languagePackages[package.Language]); } else { throw new ArgumentException($"Language package '{package.Language}' has been added."); } } return(this); }
public static TPackage Merge <TPackage>(this TPackage target, ILanguagePackage package) where TPackage : class, ILanguagePackage { if (package == null) { throw new ArgumentNullException(nameof(package)); } if (target == null) { throw new ArgumentNullException(nameof(target)); } if (!package.IsFuture()) { throw new ArgumentException($"package '{package.Language.ToLocaleString()}' should be an instance of FutureFillingPackage."); } foreach (var resource in package.Resources) { target.AddResource(resource.Value); } package.Dispose(); return(target); }
/// <summary> /// Creates the LanguagePackageFragmentTranslator. The first parameter /// defines the language package to use. /// </summary> /// <param name="languagePackage">The language package to use for this translator.</param> public LanguagePackageFragmentTranslator(ILanguagePackage languagePackage) { _languagePackage = languagePackage; }
/// <summary> /// Creates the RRuleParser. With <see cref="TextBuilder" /> as TextBuilder. /// </summary> /// <param name="languagePackage">The language to use.</param> public RRuleParser(ILanguagePackage languagePackage) : this(new TextBuilder(new LanguagePackageFragmentTranslator(languagePackage))) { }
internal static string ConvertCodeSequenceToCode( IRecordedCodeSequence codeSequence, ILanguagePackage languagePackage, string commonData) { string webCode = string.Empty; string actCode = string.Empty; string dataCode = string.Empty; codeSequence.Header.Add(languagePackage.RegionOpen); foreach (IRecordedItem recordedItem in codeSequence.Items) { string recordedData = string.Empty; string additionalData = string.Empty; RecordedWebElement webElement = recordedItem as RecordedWebElement; RecordedAction actionElement = recordedItem as RecordedAction; RecordedData dataElement = recordedItem as RecordedData; //codeSequence.Data.Add(languagePackage.SingleLineComment); //if (null != (recordedItem as RecordedWebElement)) { if (null != webElement) { //additionalData += // "\r\n\r\n#region element's properties"; //codeSequence.Data.Add(languagePackage.SingleLineComment); additionalData += languagePackage.SingleLineComment; additionalData += //"\r\n# Displayed = "; "Displayed = "; additionalData += //(recordedItem as RecordedWebElement).Displayed.ToString(); //webElement.Displayed; webElement.UserData["Displayed"]; additionalData += languagePackage.Separator; additionalData += "Enabled = "; additionalData += //(recordedItem as RecordedWebElement).Enabled.ToString(); //webElement.Enabled; webElement.UserData["Enabled"]; additionalData += languagePackage.Separator; additionalData += "Location = "; additionalData += //(recordedItem as RecordedWebElement).Location.ToString(); //webElement.Location; webElement.UserData["Location"]; additionalData += languagePackage.Separator; additionalData += "Selected = "; additionalData += //(recordedItem as RecordedWebElement).Selected.ToString(); //webElement.Selected; webElement.UserData["Selected"]; additionalData += languagePackage.Separator; additionalData += "Size = "; additionalData += //(recordedItem as RecordedWebElement).Size.ToString(); //webElement.Size; webElement.UserData["Size"]; additionalData += languagePackage.Separator; additionalData += "TagName = "; additionalData += //(recordedItem as RecordedWebElement).TagName; //webElement.TagName; webElement.UserData["TagName"]; codeSequence.Data.Add(additionalData); additionalData = string.Empty; string tempTextData = //(recordedItem as RecordedWebElement).Text; //webElement.Text; webElement.UserData["Text"].ToString(); if (null != tempTextData && string.Empty != tempTextData) {// && tempTextData.Contains("\r\n")) { if (tempTextData.Contains("\r\n")) { additionalData += //"\r\n# Text = \r\n@\"\r\n"; languagePackage.HereStringOpen; additionalData += tempTextData; additionalData += //"\r\n\"@"; languagePackage.HereStringClose; } else { additionalData += languagePackage.SingleLineComment; additionalData += "\r\nText = "; additionalData += tempTextData; } codeSequence.Data.Add(additionalData); additionalData = string.Empty; } // recordedData += // //(recordedItem as RecordedWebElement).UserData["code"]; // webElement.UserData["code"]; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // here should be better code generation for new cmdlets // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! codeSequence.Code.Add(webElement.UserData["code"].ToString()); //} else if (null != (recordedItem as RecordedAction)) { } else if (null != actionElement) { // recordedData += // //((RecordedAction)recordedItem).UserData["code"]; // actionElement.UserData["code"]; codeSequence.Code.Add(actionElement.UserData["code"].ToString()); //} else if (null != (recordedItem as RecordedData)) { } else if (null != dataElement) { additionalData += "\r\n#"; //foreach (string key in (recordedItem as RecordedData).UserData.Keys) { foreach (string key in dataElement.UserData.Keys) { //Console.WriteLine("dataItem's key = " + key); if ("XPath" == key) { //Console.WriteLine("XPath = "); additionalData += "XPath = "; string sTemp = "XPath = "; //Console.WriteLine("dataElement.UserData[key].GetType().Name = " + dataElement.UserData[key].GetType().Name); //foreach (var xpathPart in ((ReadOnlyCollection<object>)((RecordedData)recordedItem).UserData[key])) { foreach (var xpathPart in ((ReadOnlyCollection<object>)dataElement.UserData[key])) { additionalData += "/"; sTemp += "/"; additionalData += xpathPart; sTemp += xpathPart; } codeSequence.Code.Add("\"" + additionalData + "\""); additionalData += ";"; Console.WriteLine(sTemp); } else { string sTemp2 = string.Empty; additionalData += " "; additionalData += key; sTemp2 += key; additionalData += " = "; sTemp2 += " = "; additionalData += //(recordedItem as RecordedData).UserData[key]; dataElement.UserData[key]; sTemp2 += dataElement.UserData[key]; Console.WriteLine(sTemp2); additionalData += ";"; } } additionalData += "\r\n#endregion element's properties"; } else { Console.WriteLine("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< unused element !!!!!!!!!!!!!!!!!!!!! >>>>>>>>>>>>>>"); } commonData += additionalData; commonData += recordedData; } commonData += codeSequence.Header; foreach (string dataString in codeSequence.Data) { commonData += dataString; } foreach (string codeString in codeSequence.Code) { commonData += codeString; } return commonData; }
public void LoadPackage(ILanguagePackage pack) { ((TextLanguagePackage)pack).LoadFullData(); }
internal static string ConvertCodeSequenceToCode( IRecordedCodeSequence codeSequence, ILanguagePackage languagePackage, string commonData) { var webCode = string.Empty; var actCode = string.Empty; var dataCode = string.Empty; codeSequence.Header.Add(languagePackage.RegionOpen); foreach (var recordedItem in codeSequence.Items) { var recordedData = string.Empty; var additionalData = string.Empty; var webElement = recordedItem as RecordedWebElement; var actionElement = recordedItem as RecordedAction; var dataElement = recordedItem as RecordedData; //codeSequence.Data.Add(languagePackage.SingleLineComment); //if (null != (recordedItem as RecordedWebElement)) { if (null != webElement) { //additionalData += // "\r\n\r\n#region element's properties"; //codeSequence.Data.Add(languagePackage.SingleLineComment); additionalData += languagePackage.SingleLineComment; additionalData += //"\r\n# Displayed = "; "Displayed = "; additionalData += //(recordedItem as RecordedWebElement).Displayed.ToString(); //webElement.Displayed; webElement.UserData["Displayed"]; additionalData += languagePackage.Separator; additionalData += "Enabled = "; additionalData += //(recordedItem as RecordedWebElement).Enabled.ToString(); //webElement.Enabled; webElement.UserData["Enabled"]; additionalData += languagePackage.Separator; additionalData += "Location = "; additionalData += //(recordedItem as RecordedWebElement).Location.ToString(); //webElement.Location; webElement.UserData["Location"]; additionalData += languagePackage.Separator; additionalData += "Selected = "; additionalData += //(recordedItem as RecordedWebElement).Selected.ToString(); //webElement.Selected; webElement.UserData["Selected"]; additionalData += languagePackage.Separator; additionalData += "Size = "; additionalData += //(recordedItem as RecordedWebElement).Size.ToString(); //webElement.Size; webElement.UserData["Size"]; additionalData += languagePackage.Separator; additionalData += "TagName = "; additionalData += //(recordedItem as RecordedWebElement).TagName; //webElement.TagName; webElement.UserData["TagName"]; codeSequence.Data.Add(additionalData); additionalData = string.Empty; var tempTextData = //(recordedItem as RecordedWebElement).Text; //webElement.Text; webElement.UserData["Text"].ToString(); if (null != tempTextData && string.Empty != tempTextData) // && tempTextData.Contains("\r\n")) { { if (tempTextData.Contains("\r\n")) { additionalData += //"\r\n# Text = \r\n@\"\r\n"; languagePackage.HereStringOpen; additionalData += tempTextData; additionalData += //"\r\n\"@"; languagePackage.HereStringClose; } else { additionalData += languagePackage.SingleLineComment; additionalData += "\r\nText = "; additionalData += tempTextData; } codeSequence.Data.Add(additionalData); additionalData = string.Empty; } // recordedData += // //(recordedItem as RecordedWebElement).UserData["code"]; // webElement.UserData["code"]; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // here should be better code generation for new cmdlets // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! codeSequence.Code.Add(webElement.UserData["code"].ToString()); //} else if (null != (recordedItem as RecordedAction)) { } else if (null != actionElement) { // recordedData += // //((RecordedAction)recordedItem).UserData["code"]; // actionElement.UserData["code"]; codeSequence.Code.Add(actionElement.UserData["code"].ToString()); //} else if (null != (recordedItem as RecordedData)) { } else if (null != dataElement) { additionalData += "\r\n#"; //foreach (string key in (recordedItem as RecordedData).UserData.Keys) { foreach (var key in dataElement.UserData.Keys) { //Console.WriteLine("dataItem's key = " + key); if ("XPath" == key) { //Console.WriteLine("XPath = "); additionalData += "XPath = "; var sTemp = "XPath = "; //Console.WriteLine("dataElement.UserData[key].GetType().Name = " + dataElement.UserData[key].GetType().Name); //foreach (var xpathPart in ((ReadOnlyCollection<object>)((RecordedData)recordedItem).UserData[key])) { foreach (var xpathPart in ((ReadOnlyCollection <object>)dataElement.UserData[key])) { additionalData += "/"; sTemp += "/"; additionalData += xpathPart; sTemp += xpathPart; } codeSequence.Code.Add("\"" + additionalData + "\""); additionalData += ";"; Console.WriteLine(sTemp); } else { var sTemp2 = string.Empty; additionalData += " "; additionalData += key; sTemp2 += key; additionalData += " = "; sTemp2 += " = "; additionalData += //(recordedItem as RecordedData).UserData[key]; dataElement.UserData[key]; sTemp2 += dataElement.UserData[key]; Console.WriteLine(sTemp2); additionalData += ";"; } } additionalData += "\r\n#endregion element's properties"; } else { Console.WriteLine("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< unused element !!!!!!!!!!!!!!!!!!!!! >>>>>>>>>>>>>>"); } commonData += additionalData; commonData += recordedData; } commonData += codeSequence.Header; foreach (var dataString in codeSequence.Data) { commonData += dataString; } foreach (var codeString in codeSequence.Code) { commonData += codeString; } return(commonData); }
public static bool IsFuture(this ILanguagePackage package) { return(package is FutureFillingPackage); }
private void AddPackageInternal(ILanguagePackage package) { __languagePackages.Add(package.Language, package); }