public void EnabledMarkerProcessing(ParseType type) { var parser = GetParser(true); var item = Get(parser, type, TestConstants.PluginModKey.FileName); Assert.False(item.Enabled); Assert.Equal(TestConstants.PluginModKey, item.ModKey); item = Get(parser, type, $"*{TestConstants.PluginModKey.FileName}"); Assert.True(item.Enabled); Assert.False(item.Ghosted); Assert.Equal(TestConstants.PluginModKey, item.ModKey); }
public static CodeType GetCodeTypeFromContext(ParseInfo parseInfo, ParseType typeContext) { if (typeContext == null) { return(null); } CodeType type = null; if (!typeContext.IsDefault) { type = parseInfo.TranslateInfo.Types.GetCodeType(typeContext.Identifier.Text, parseInfo.Script.Diagnostics, typeContext.Identifier.Range); } // Get generics if (typeContext.HasTypeArgs) { // Create a list to store the generics. List <CodeType> generics = new List <CodeType>(); // Get the generics. foreach (var genericContext in typeContext.TypeArgs) { generics.Add(GetCodeTypeFromContext(parseInfo, genericContext)); } if (type is Lambda.ValueBlockLambda) { type = new Lambda.ValueBlockLambda(generics[0], generics.Skip(1).ToArray()); } else if (type is Lambda.BlockLambda) { type = new Lambda.BlockLambda(generics.ToArray()); } else if (type is Lambda.MacroLambda) { type = new Lambda.MacroLambda(generics[0], generics.Skip(1).ToArray()); } } if (type != null) { type.Call(parseInfo, typeContext.Identifier.Range); } for (int i = 0; i < typeContext.ArrayCount; i++) { type = new ArrayType(type); } return(type); }
/// <summary> /// The QueryString of the request /// </summary> /// <param name="key">QueryString key</param> /// <param name="native">Parse native or parse based on culture</param> /// <returns>DateTime</returns> public DateTime DateTimeValue(string key, ParseType parse) { if (this[key].ToString() == string.Empty) { return(new DateTime(0)); } else { return(parse == ParseType.Native ? Localization.ParseUSDateTime(this[key].ToString()) : Localization.ParseNativeDateTime(this[key].ToString())); } }
/// <summary> /// The QueryString of the request /// </summary> /// <param name="key">QueryString key</param> /// <param name="native">Parse native or parse based on culture</param> /// <returns>decimal</returns> public decimal DecimalValue(string key, ParseType parse) { if (this[key] == null) { return(0.0M); } else { return(parse == ParseType.Native ? Localization.ParseNativeDecimal(this[key].ToString()) : Localization.ParseUSDecimal(this[key].ToString())); } }
/// <summary> /// The QueryString of the request /// </summary> /// <param name="key">QueryString key</param> /// <param name="native">Parse native or parse based on culture</param> /// <returns>double</returns> public double DoubleValue(string key, ParseType parse) { if (this[key] == null) { return(0.0); } else { return(parse == ParseType.Native ? Localization.ParseNativeDouble(this[key].ToString()) : Localization.ParseUSDouble(this[key].ToString())); } }
/// <summary> /// The QueryString of the request /// </summary> /// <param name="key">QueryString key</param> /// <param name="native">Parse native or parse based on culture</param> /// <returns>long integer</returns> public long LongValue(string key, ParseType parse) { if (this[key] == null) { return(0); } else { return(parse == ParseType.Native ? Localization.ParseNativeLong(this[key].ToString()) : Localization.ParseUSLong(this[key].ToString())); } }
/// <summary> /// Recherche parmi un type saisi dans la fenetre de détail d'un port la liste des types /// qui doivent être insérés dans la couche modèle /// </summary> /// <param name="language">The language.</param> /// <param name="name">The name.</param> /// <returns></returns> public static IList <string> GetModelNamesFromClrType(Language language, string name) { if (ParseType.CanParse(language, name)) { ParseType parseType = new ParseType(language, name); TypeInstance typeInstance = parseType.TypeInstance; if (typeInstance.TypeKind == TypeKind.Type) { return(GetModelsNameRecursive(language, typeInstance)); } } return(null); }
private Color ParseColorDesignSetting(ParseType parseType, Control cntrl, string customPropertyName, Color colorValue, string settingId) { Color resultColor = colorValue; if (parseType == ParseType.SaveToFile) { MainForm._settingsXml.SetSetting(string.Format("{0}_{1}", settingId, customPropertyName), colorValue.ToArgb().ToString()); } else if (parseType == ParseType.LoadFromFile) { string str = MainForm._settingsXml.GetSetting(string.Format("{0}_{1}", settingId, customPropertyName)); if (!string.IsNullOrEmpty(str)) { resultColor = (Color.FromArgb(Convert.ToInt32(str))); } } else if (parseType == ParseType.LoadFromControl) { if (cntrl is TabControl) { AddPropertyIfNotExists(cntrl, customPropertyName, ((TabControl)cntrl).TabPages[0].BackColor, CATEGORY_DESIGN_VIEW); } else if (cntrl is DataGridView) { switch (customPropertyName) { case BACK_COLOR_PROP_NAME: AddPropertyIfNotExists(cntrl, customPropertyName, ((DataGridView)cntrl).BackgroundColor, CATEGORY_DESIGN_VIEW); break; case HEADER_STYLE_BACK_COLOR_PROP_NAME: AddPropertyIfNotExists(cntrl, customPropertyName, ((DataGridView)cntrl).ColumnHeadersDefaultCellStyle.BackColor, CATEGORY_DESIGN_VIEW); break; default: AddPropertyIfNotExists(cntrl, customPropertyName, null, CATEGORY_DESIGN_VIEW); break; } } else { //_propertyGridEx.Item.Add("Имя свойства", "Значение по-умолчанию", readOnly, "Категория", "Описание", visible); AddPropertyIfNotExists(cntrl, customPropertyName, cntrl.BackColor, CATEGORY_DESIGN_VIEW); } } return(resultColor); }
private void UnbindProgress(object sender, UnbindProgressEvents e) { FileEntry entry = e.File; string eventType = ParseType.GetStringType(entry.Type); if (e.Success) { ParseMessageType type = ParseType.GetType(entry.Type); _logs.Add(string.Format("Unbinding file: {0} was successfully completed.", entry.Name), "Events", eventType + " " + entry.Name, type); } else { _logs.Add(string.Format("Unsuccessfull unbinding file: {0} ", entry.Name), "Events", eventType + " " + entry.Name, ParseMessageType.Error); } }
private Font ParseFontDesignSetting(ParseType parseType, Control cntrl, string customPropertyName, Font fontValue, string settingId) { var cvt = new FontConverter(); Font resultFont = fontValue; if (parseType == ParseType.SaveToFile) { string fontString = cvt.ConvertToString(fontValue); MainForm._settingsXml.SetSetting(string.Format("{0}_{1}", settingId, customPropertyName), fontString); } else if (parseType == ParseType.LoadFromFile) { //string s = cvt.ConvertToString(this.Font); string str = MainForm._settingsXml.GetSetting(string.Format("{0}_{1}", settingId, customPropertyName)); if (!string.IsNullOrEmpty(str)) { resultFont = cvt.ConvertFromString(str) as Font; } } else if (parseType == ParseType.LoadFromControl) { if (cntrl is DataGridView) { switch (customPropertyName) { case HEADER_STYLE_FONT_PROP_NAME: _propertyGridEx.Item.Add(customPropertyName, ((DataGridView)cntrl).ColumnHeadersDefaultCellStyle.Font, false, CATEGORY_DESIGN_VIEW, customPropertyName, true); break; case CELL_FONT_PROP_NAME: _propertyGridEx.Item.Add(customPropertyName, ((DataGridView)cntrl).DefaultCellStyle.Font, false, CATEGORY_DESIGN_VIEW, customPropertyName, true); break; default: _propertyGridEx.Item.Add(customPropertyName, null, false, CATEGORY_DESIGN_VIEW, customPropertyName, true); break; } } else { //_propertyGridEx.Item.Add("Имя свойства", "Значение по-умолчанию", readOnly, "Категория", "Описание", visible); _propertyGridEx.Item.Add(customPropertyName, cntrl.Font, false, CATEGORY_DESIGN_VIEW, customPropertyName, true); } } return(resultFont); }
public static int TryParseValue(ParseType parseType, dynamic val, dynamic defaultValue) { switch (parseType) { case ParseType.IntType: int parseDefaultIntValue = 25; return(int.TryParse(val, out parseDefaultIntValue) ? Convert.ToInt16(val): defaultValue); case ParseType.DoubleType: double parseDefaultDoubleValue = 25.0; return(double.TryParse(val, out parseDefaultDoubleValue) ? Convert.ToDouble(val) : defaultValue); default: return(defaultValue); } }
private void RunTestFor(ParseType parseType, RepositorySourceType srcType, string languageToken, int languageThreshold) { var step = new CpdCollectionStep(parseType); Args.RepositorySourceType = srcType; var command = step.PrepareCommand(Args, Result); command.Should().NotBeEmpty(); command.ShouldContainText("net.sourceforge.pmd.cpd.CPD") .ShouldContainText("--format csv") .ShouldContainText($"--language {languageToken}") .ShouldContainText($"--minimum-tokens {languageThreshold}") .ShouldContainText($"--files '{Args.SourceDirectory}'") .ShouldContainText($"> '{Result.MetricsFile}'"); step.ValidateMetricResults("afile").Should().BeEmpty(); }
/// <summary> /// Attempts to parse the value as a date /// </summary> /// <param name="val">the value to parse</param> /// <returns>True if it parses. If it does parse, them the appropriate member fields are updated</returns> private bool ParsesAsDate(string val) { DateTime DateOut; if (DateTime.TryParse(val, out DateOut)) { // SQL Server datetime range is: 1753-01-01 through 9999-12-31 // C# DateTime.MinValue = January 1, 0001 and MaxValue is December 31, 9999 if (DateTime.Compare(DateOut, MinSQLDate) >= 0) // value in the data is >= SQL Server minimum { ++ParsesDateTime; LastParseType = ParseType.DATETIME; return(true); } } return(false); }
public static IParser Create(string fileName, ParseType parseType) { switch (parseType) { case ParseType.Achievements: return(new AchievementParser(fileName)); case ParseType.Pets: return(new PetParser(fileName)); case ParseType.Mounts: return(new MountParser(fileName)); case ParseType.BattlePets: return(new BattlePetParser(fileName)); } throw new ApplicationException("No parser defined for type " + parseType.ToString()); }
public List <EnumFileParser> ParseFile(string filename, ParseType format) { List <EnumFileParser> list; try { this._enumList.Clear(); if (!File.Exists(filename)) { throw new Exception("Requested file does not exist!"); } StreamReader reader = new StreamReader(filename); string str = string.Empty; while (reader.Peek() != -1) { str = reader.ReadLine(); if (!(str.StartsWith(";") | (str.Length <= 1))) { string[] strArray = str.Split(new char[] { '^' }); if (format == ParseType.Hex) { this._enumList.Add(new EnumFileParser(Convert.ToInt32(strArray[0].Replace("0x", string.Empty), 0x10), strArray[1].Replace("\"", string.Empty))); } else if (format == ParseType.Dec) { this._enumList.Add(new EnumFileParser(int.Parse(strArray[0]), strArray[1].Replace("\"", string.Empty))); } } } reader.Close(); list = this._enumList; } catch (Exception exception1) { ProjectData.SetProjectError(exception1); Exception exception = exception1; Interaction.MsgBox(exception.Message, MsgBoxStyle.Critical, null); list = null; ProjectData.ClearProjectError(); } return(list); }
private SchoolParser InitializeParser(ParseType parseType) { SchoolParser parser; switch (parseType) { default: parser = new SchoolParser(SchoolDataJson.text); break; case ParseType.Student: parser = new StudentParser(SchoolDataJson.text); break; case ParseType.Teacher: parser = new TeacherParser(SchoolDataJson.text); break; } return(parser); }
public static int ToInt(this decimal dec, ParseType type = ParseType.四捨五入) { var roundedDec = default(Decimal); switch (type) { case ParseType.切り上げ: roundedDec = Math.Ceiling(dec); break; case ParseType.切り捨て: roundedDec = Math.Floor(dec); break; default: roundedDec = Math.Round(dec, MidpointRounding.AwayFromZero); break; } return(decimal.ToInt16(roundedDec)); }
protected void ResetAllData(ParseType parseType) { if ((parseType & ParseType.Header) == ParseType.Header) { title = ""; artist = ""; subArtist = ""; comments = ""; genre = ""; playerCount = 1; initialBPM = 130; minBpm = float.PositiveInfinity; playLevel = 0; rank = 0; volume = 1; metaResourceDatas.Clear(); } if ((parseType & ParseType.Resources) == ParseType.Resources) { resourceDatas.Clear(); foreach (var kv in metaResourceDatas) { resourceDatas[kv.Key] = kv.Value; } } if ((parseType & ParseType.Content) == ParseType.Content) { maxCombos = 0; bmsEvents.Clear(); allChannels.Clear(); OnDataRefresh(); layout = BMSKeyLayout.None; } else if ((parseType & ParseType.Content) == ParseType.Content) { maxCombos = 0; allChannels.Clear(); layout = BMSKeyLayout.None; } }
public static SexpParser GetInstance(ParseType parseType) { switch (parseType) { case ParseType.Global: if (_globalInstance == null) { _globalInstance = new SexpParser(); _globalInstance.ParserFunc = ParseGlobal; } return _globalInstance; case ParseType.Sexp: if (_sexpInstance == null) { _sexpInstance = new SexpParser(); _sexpInstance.ParserFunc = ParseLocal; } return _sexpInstance; default: throw new ArgumentException("Unknown Sexp Parser type."); } }
/// <summary> /// Attempts to parse the value as one of the supported numeric types. /// </summary> /// <param name="val">the value to parse</param> /// <returns>True if it parses. If it does parse, them the appropriate member fields are updated</returns> private bool ParsesAsNumeric(string val) { int IntOut = -1; if (int.TryParse(val, out IntOut)) { ++ParsesInt; } long BigIntOut = -1; if (long.TryParse(val, out BigIntOut)) { ++ParsesBigInt; } decimal DecimalOut = -1; if (decimal.TryParse(val, out DecimalOut)) { ++ParsesDecimal; // keep track of the maximum range and precision int TmpPrecision = DecimalOut.Precision(); int TmpScale = DecimalOut.Scale(); if (Precision < TmpPrecision) { Precision = TmpPrecision; } if (Scale < TmpScale) { Scale = TmpScale; } } if (IntOut != -1 || BigIntOut != -1 || DecimalOut != -1) { LastParseType = ParseType.NUMERIC; return(true); } return(false); }
private void ParseBGAEvents(ParseType parseType, List <BMSEvent> bmev) { IJsonWrapper bga = bmsonData.GetChild("bga"); if ((parseType & ParseType.Resources) == ParseType.Resources) { foreach (IJsonWrapper entry in bga.GetChild("bga_header").GetChilds()) { AddResource( ResourceType.bmp, entry.GetChild("id").AsInt32(), entry.GetChild("name").AsString() ); } } if ((parseType & ParseType.Content) == ParseType.Content) { ParseBGALayer(bga.GetChild("bga_events"), 0, bmev); ParseBGALayer(bga.GetChild("layer_events"), 1, bmev); ParseBGALayer(bga.GetChild("poor_events"), -1, bmev); } }
public void ReadReplay(Stream stream, ParseType parseType = ParseType.Full) { _finished = false; _firstPacket = true; _pauseWaiter.Reset(); _timePassed.Restart(); _currentReadTimeSeconds = 0; ClearBuffer(); using var archive = new BinaryReader(stream); Thread thread = new Thread(UpdateThread); thread.IsBackground = true; thread.Start(); ReadReplay(archive, parseType); _finished = true; //Wait for thread to finish thread.Join(); }
public Result Parse(string sql, ParseType parseType) { switch (parseType) { case ParseType.CreateDatabase: return(ParseCreateDatabase(sql)); case ParseType.DropDatabase: return(ParseDropDatabase(sql)); case ParseType.CreateTable: return(ParseCreateTable(sql)); case ParseType.DropTable: return(ParseDropTable(sql)); case ParseType.Select: return(ParseSelect(sql)); case ParseType.Insert: return(ParseInsert(sql)); case ParseType.Update: return(ParseUpdate(sql)); case ParseType.Delete: return(ParseDelete(sql)); default: return(new Result()); } }
public void GetType() { // first easy pass if (Directory.Contains("dynamika")) { Parser = (ParseType)2; return; } if (Directory.Contains("chod")) { Parser = (ParseType)2; return; } if (Directory.Contains("statyka")) { Parser = (ParseType)1; return; } Regex pattern = new Regex(@"\[([^)]*)\]"); var bracketText = from line in File.ReadAllLines(Directory) let matches = pattern.Matches(line) where matches.Count > 0 select line; if (bracketText.Intersect(DynamoLabels._dynamicLabels).Any()) { Parser = (ParseType)2; return; } if (bracketText.Intersect(DynamoLabels._staticLabels).Any()) { Parser = (ParseType)1; return; } }
private static DamageRecord ParseDamage(string actionPart) { DamageRecord record = null; ParseType parseType = ParseType.UNKNOWN; string withoutMods = actionPart; int modifiersIndex = -1; if (actionPart[actionPart.Length - 1] == ')') { // using 4 here since the shortest modifier should at least be 3 even in the future. probably. modifiersIndex = actionPart.LastIndexOf('(', actionPart.Length - 4); if (modifiersIndex > -1) { withoutMods = actionPart.Substring(0, modifiersIndex); } } int pointsIndex = -1; int forIndex = -1; int fromIndex = -1; int byIndex = -1; int takenIndex = -1; int hitIndex = -1; int extraIndex = -1; int isAreIndex = -1; bool nonMelee = false; List <string> nameList = new List <string>(); StringBuilder builder = new StringBuilder(); var data = withoutMods.Split(' '); SpellResist resist = SpellResist.UNDEFINED; for (int i = 0; i < data.Length; i++) { switch (data[i]) { case "taken": takenIndex = i; int test1 = i - 1; if (test1 > 0 && data[test1] == "has") { parseType = ParseType.HASTAKEN; int test2 = i + 2; if (data.Length > test2 && data[test2] == "extra" && data[test2 - 1] == "an") { extraIndex = test2; } } else if (test1 >= 1 && data[test1] == "have" && data[test1 - 1] == "You") { parseType = ParseType.YOUHAVETAKEN; } break; case "by": byIndex = i; break; case "non-melee": nonMelee = true; break; case "is": case "are": isAreIndex = i; break; case "for": int next = i + 1; if (data.Length > next && data[next].Length > 0 && char.IsNumber(data[next][0])) { forIndex = i; } break; case "from": fromIndex = i; break; case "points": int ofIndex = i + 1; if (ofIndex < data.Length && data[ofIndex] == "of") { parseType = ParseType.POINTSOF; pointsIndex = i; int resistIndex = ofIndex + 1; if (resistIndex < data.Length && SpellResistMap.TryGetValue(data[resistIndex], out SpellResist value)) { resist = value; nonMelee = true; } } break; default: if (HitMap.ContainsKey(data[i])) { hitIndex = i; } break; } } if (parseType == ParseType.POINTSOF && forIndex > -1 && forIndex < pointsIndex && hitIndex > -1) { record = ParsePointsOf(data, nonMelee, forIndex, byIndex, hitIndex, builder, nameList); } else if (parseType == ParseType.HASTAKEN && takenIndex < fromIndex && fromIndex > -1) { record = ParseHasTaken(data, takenIndex, fromIndex, byIndex, builder); } else if (parseType == ParseType.POINTSOF && extraIndex > -1 && takenIndex > -1 && takenIndex < fromIndex) { record = ParseExtra(data, takenIndex, extraIndex, fromIndex, nameList); } // there are more messages without a specificied attacker or spell but do these first else if (parseType == ParseType.YOUHAVETAKEN && takenIndex > -1 && fromIndex > -1 && byIndex > fromIndex) { record = ParseYouHaveTaken(data, takenIndex, fromIndex, byIndex, builder); } else if (parseType == ParseType.POINTSOF && isAreIndex > -1 && byIndex > isAreIndex && forIndex > byIndex) { record = ParseDS(data, isAreIndex, byIndex, forIndex); } if (record != null && modifiersIndex > -1) { record.ModifiersMask = LineModifiersParser.Parse(actionPart.Substring(modifiersIndex + 1, actionPart.Length - 1 - modifiersIndex - 1)); } return(ValidateDamage(record, resist)); }
public RinexObsWithFilter(string filePath, ParseType parseType, ObservationFilter filter) : base(filePath, parseType) { _filter = filter; }
public RinexObsParser(string filePath, ParseType parseType) : base(filePath, parseType) { }
internal static Block ParseTiaDbUdtXml(string xml, ProjectBlockInfo projectBlockInfo, TIAOpennessControllerFolder controllerFolder, ParseType parseType) { XElement xelement = XElement.Parse(xml); var structure = xelement.Elements().FirstOrDefault(x => x.Name.LocalName.StartsWith("SW.")); var sections = structure.Element("AttributeList").Element("Interface").Elements().First(); var block = new TIADataBlock(); block.Name = projectBlockInfo.Name; if (projectBlockInfo is TIAOpennessProjectBlockInfo) { block.BlockNumber = ((TIAOpennessProjectBlockInfo)projectBlockInfo).BlockNumber; } if (parseType == ParseType.DataType) { block.BlockType = DataTypes.PLCBlockType.UDT; } else if (parseType == ParseType.Programm) { block.BlockType = DataTypes.PLCBlockType.DB; } var parameterRoot = ParseTiaDbUdtSections(sections, block, controllerFolder); block.BlockType = DataTypes.PLCBlockType.DB; block.Structure = parameterRoot; return(block); }
public static async Task <string> GetEachsTemplateStringAsync(string templateString, NameValueCollection selectedItems, NameValueCollection selectedValues, string containerClientId, IParseManager parseManager, ParseType contextType) { var context = parseManager.ContextInfo; var pageInfo = parseManager.PageInfo; var itemContainer = DbItemContainer.GetItemContainer(pageInfo); parseManager.ContextInfo = parseManager.ContextInfo.Clone(); parseManager.ContextInfo.ContextType = contextType; parseManager.ContextInfo.ContainerClientId = containerClientId; parseManager.ContextInfo.ItemContainer = itemContainer; if (selectedItems != null && selectedItems.Count > 0) { foreach (var itemType in selectedItems.AllKeys) { if (IsNumberInRange(itemContainer.SqlItem.Key + 1, itemType)) { templateString = selectedItems.Get(itemType); break; } } } var innerBuilder = new StringBuilder(templateString); await parseManager.ParseInnerContentAsync(innerBuilder); DbItemContainer.PopEachItem(pageInfo); parseManager.ContextInfo = context; return(innerBuilder.ToString()); }
public static async Task <string> GetSitesTemplateStringAsync(string templateString, string containerClientId, IParseManager parseManager, ParseType contextType) { var context = parseManager.ContextInfo; var pageInfo = parseManager.PageInfo; var itemContainer = DbItemContainer.GetItemContainer(pageInfo); var siteInfo = itemContainer.SiteItem.Value; parseManager.ContextInfo = parseManager.ContextInfo.Clone(); parseManager.ContextInfo.ContainerClientId = containerClientId; parseManager.ContextInfo.ItemContainer = itemContainer; parseManager.ContextInfo.ContextType = contextType; var preSite = pageInfo.Site; var prePageChannelId = pageInfo.PageChannelId; var prePageContentId = pageInfo.PageContentId; pageInfo.ChangeSite(siteInfo, siteInfo.Id, 0, parseManager.ContextInfo); var innerBuilder = new StringBuilder(templateString); await parseManager.ParseInnerContentAsync(innerBuilder); DbItemContainer.PopSiteItems(pageInfo); pageInfo.ChangeSite(preSite, prePageChannelId, prePageContentId, parseManager.ContextInfo); parseManager.ContextInfo = context; return(innerBuilder.ToString()); }
public static async Task <string> GetChannelsItemTemplateStringAsync(string templateString, NameValueCollection selectedItems, NameValueCollection selectedValues, string containerClientId, IParseManager parseManager, ParseType contextType) { var context = parseManager.ContextInfo; var pageInfo = parseManager.PageInfo; var itemContainer = DbItemContainer.GetItemContainer(pageInfo); var channel = itemContainer.ChannelItem.Value; parseManager.ContextInfo = parseManager.ContextInfo.Clone(); parseManager.ContextInfo.ContextType = contextType; parseManager.ContextInfo.ItemContainer = itemContainer; parseManager.ContextInfo.ContainerClientId = containerClientId; parseManager.ContextInfo.ChannelId = channel.Id; if (selectedItems != null && selectedItems.Count > 0) { foreach (var itemType in selectedItems.AllKeys) { if (StringUtils.EqualsIgnoreCase(itemType, StlItemTemplate.SelectedCurrent))//当前栏目 { if (channel.Id == pageInfo.PageChannelId) { templateString = selectedItems.Get(itemType); break; } } else if (StringUtils.EqualsIgnoreCase(itemType, StlItemTemplate.SelectedImage))//带有图片的栏目 { if (!string.IsNullOrEmpty(channel.ImageUrl)) { templateString = selectedItems.Get(itemType); break; } } else if (StringUtils.StartsWithIgnoreCase(itemType, StlItemTemplate.SelectedUp))//当前栏目的上级栏目 { var upLevel = StringUtils.EqualsIgnoreCase(itemType, StlItemTemplate.SelectedUp) ? 1 : TranslateUtils.ToInt(itemType.Substring(2)); if (upLevel > 0) { var dataManager = new StlDataManager(parseManager.DatabaseManager); var theChannelId = await dataManager.GetChannelIdByLevelAsync(pageInfo.SiteId, pageInfo.PageChannelId, upLevel, -1); if (channel.Id == theChannelId) { templateString = selectedItems.Get(itemType); break; } } } else if (StringUtils.StartsWithIgnoreCase(itemType, StlItemTemplate.SelectedTop))//当前栏目从首页向下的上级栏目栏目 { var topLevel = StringUtils.EqualsIgnoreCase(itemType, StlItemTemplate.SelectedTop) ? 1 : TranslateUtils.ToInt(itemType.Substring(3)); if (topLevel >= 0) { var dataManager = new StlDataManager(parseManager.DatabaseManager); var theChannelId = await dataManager.GetChannelIdByLevelAsync(pageInfo.SiteId, pageInfo.PageChannelId, 0, topLevel); if (channel.Id == theChannelId) { templateString = selectedItems.Get(itemType); break; } } } else if (IsNumberInRange(itemContainer.ChannelItem.Key + 1, itemType)) { templateString = selectedItems.Get(itemType); break; } } } var innerBuilder = new StringBuilder(templateString); await parseManager.ParseInnerContentAsync(innerBuilder); DbItemContainer.PopChannelItem(pageInfo); parseManager.ContextInfo = context; return(innerBuilder.ToString()); }
/// <summary> /// Validate Wiggle Parser for fixed and variable steps. /// </summary> /// <param name="nodeName">Nodename</param> /// <param name="parseType">Read using a stream/File Name.</param> private void ValidateWiggleParser(string nodeName, ParseType parseType) { // Gets the filepath. String filePath = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode); Assert.IsTrue(File.Exists(filePath)); int index = 0; WiggleAnnotation annotation = null; // Logs information to the log file ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Wiggle Parser BVT: File Exists in the Path '{0}'.", filePath)); string[] expectedValues = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.ExpectedValuesNode).Split(','); string[] expectedPoints = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.ExpectedKeysNode).Split(','); WiggleParser parser = new WiggleParser(); switch (parseType) { case ParseType.Stream: using (var stream = File.OpenRead(filePath)) { annotation = parser.ParseOne(stream); } break; default: annotation = parser.ParseOne(filePath); break; } //Validate keys and values of the parsed file. foreach (KeyValuePair<long, float> keyvaluePair in annotation) { Assert.AreEqual(long.Parse(expectedPoints[index], CultureInfo.InvariantCulture), keyvaluePair.Key); Assert.AreEqual(float.Parse(expectedValues[index], CultureInfo.InvariantCulture), keyvaluePair.Value); index++; } ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Wiggle Parser BVT: Successfully validated the parsed file")); }
public static Duration Parse( string s, ParseType pt ) { string newvalue = s.Trim(); Duration d = new Duration(); if ( newvalue == null || newvalue.Length == 0 ) throw new StringParseException("Duration must start with P or -P followed by a duration value."); int pos = 0; bool bNegative = false; int day = 0; int hour = 0; int minute = 0; int second = 0; double partsecond = 0.0; d.months = 0; d.years = 0; if (newvalue[pos] == '-') { bNegative = true; ++pos; } if (pos == newvalue.Length || newvalue[pos] != 'P') throw new StringParseException("Duration must start with P or -P followed by a duration value."); ++pos; int state = 0; // year component while ( pos != newvalue.Length ) { // no more data allowed? if (state == 8) throw new StringParseException("Extra data after duration value."); // check if ymd part is over if (newvalue[pos] == 'T') { if (state >= 4) // hour throw new StringParseException("Multiple Ts inside duration value."); state = 4; ++pos; } if (state == 3) // 'T' separator throw new StringParseException("Extra data after duration value."); // now a digit has to follow, and probably more than one if (pos == newvalue.Length || newvalue[pos] < '0' || newvalue[pos] > '9') throw new StringParseException("Invalid numeric data in duration value."); int val = 0; int digits = 0; while (pos != newvalue.Length && newvalue[pos] >= '0' && newvalue[pos] <= '9') { if (val >= 100000000) throw new StringParseException("Numeric overflow in duration value."); val = val * 10 + (newvalue[pos] - '0'); digits += 1; ++pos; } if (pos == newvalue.Length) throw new StringParseException("Duration value missing component designator."); int foundState = 8; // bad switch (newvalue[pos]) { case 'Y': if (state >= 4) foundState = 8; else foundState = 0; break; case 'M': if (state >= 4) foundState = 5; else foundState = 1; break; case 'D': if (state >= 4) foundState = 8; else foundState = 2; break; case 'H': if (state >= 4) foundState = 4; else foundState = 8; break; case 'S': if (state >= 7) foundState = 7; else if (state >= 4) foundState = 6; else foundState = 8; break; case '.': if (state >= 4) foundState = 6; else foundState = 8; break; } if (foundState == 8 || foundState < state) throw new StringParseException("Invalid or duplicate component designator."); ++pos; switch ( foundState ) { case 0: { if ( pt == ParseType.DAYTIME ) throw new StringParseException("Year not allowed in DayTimeDuration"); d.years = val; } break; case 1: { if ( pt == ParseType.DAYTIME ) throw new StringParseException("Month not allowed in DayTimeDuration"); d.months = val; } break; case 2: { if ( pt == ParseType.YEARMONTH ) throw new StringParseException("Day not allowed in YearMonthDuration"); day = val; } break; case 4: { if ( pt == ParseType.YEARMONTH ) throw new StringParseException("Hour not allowed in YearMonthDuration"); hour = val; } break; case 5: { if ( pt == ParseType.YEARMONTH ) throw new StringParseException("Minute not allowed in YearMonthDuration"); minute = val; } break; case 6: { if ( pt == ParseType.YEARMONTH ) throw new StringParseException("Second not allowed in YearMonthDuration"); second = val; } break; case 7: { if ( pt == ParseType.YEARMONTH ) throw new StringParseException("Millisecond not allowed in YearMonthDuration"); partsecond = val * System.Math.Pow(0.1, digits); } break; } state = foundState + 1; } if (state == 0) throw new StringParseException("No components given after P in duration value."); d.myValue = new System.TimeSpan(day, hour, minute, second, (int)(0)); d.myValue += new System.TimeSpan((long)(partsecond * System.TimeSpan.TicksPerSecond)); if (bNegative) { d.myValue = -d.myValue; d.years = -d.years; d.months = -d.months; } return d; }
internal static Block ParseTiaDbUdtXml(string xml, ProjectBlockInfo projectBlockInfo, TIAOpennessControllerFolder controllerFolder, ParseType parseType) { XElement xelement = XElement.Parse(xml); var structure = xelement.Elements().FirstOrDefault(x => x.Name.LocalName.StartsWith("SW.")); var sections = structure.Element("AttributeList").Element("Interface").Elements().First(); var block = new TIADataBlock(); block.Name = projectBlockInfo.Name; if (projectBlockInfo is TIAOpennessProjectBlockInfo) block.BlockNumber = ((TIAOpennessProjectBlockInfo) projectBlockInfo).BlockNumber; if (parseType == ParseType.DataType) block.BlockType = DataTypes.PLCBlockType.UDT; else if (parseType == ParseType.Programm) block.BlockType = DataTypes.PLCBlockType.DB; var parameterRoot = ParseTiaDbUdtSections(sections, block, controllerFolder); block.BlockType = DataTypes.PLCBlockType.DB; block.Structure = parameterRoot; return block; }
public static void CleanAndCopy(ParseEntity source, ParseType parseType) { try { var target = new ParseEntity { CombinedDPS = source.CombinedDPS, DPS = source.DPS, DOTPS = source.DOTPS, CombinedHPS = source.CombinedHPS, HPS = source.HPS, HOTPS = source.HOTPS, HOHPS = source.HOHPS, HMPS = source.HMPS, CombinedDTPS = source.CombinedDTPS, DTPS = source.DTPS, DTOTPS = source.DTOTPS, CombinedTotalOverallDamage = source.CombinedTotalOverallDamage, TotalOverallDamage = source.TotalOverallDamage, TotalOverallDamageOverTime = source.TotalOverallDamageOverTime, CombinedTotalOverallHealing = source.CombinedTotalOverallHealing, TotalOverallHealing = source.TotalOverallHealing, TotalOverallHealingOverTime = source.TotalOverallHealingOverTime, TotalOverallHealingOverHealing = source.TotalOverallHealingOverHealing, TotalOverallHealingMitigated = source.TotalOverallHealingMitigated, CombinedTotalOverallDamageTaken = source.CombinedTotalOverallDamageTaken, TotalOverallDamageTaken = source.TotalOverallDamageTaken, TotalOverallDamageTakenOverTime = source.TotalOverallDamageTakenOverTime, PercentOfTotalOverallDamage = source.PercentOfTotalOverallDamage, PercentOfTotalOverallDamageOverTime = source.PercentOfTotalOverallDamageOverTime, PercentOfTotalOverallHealing = source.PercentOfTotalOverallHealing, PercentOfTotalOverallHealingOverTime = source.PercentOfTotalOverallHealingOverTime, PercentOfTotalOverallHealingOverHealing = source.PercentOfTotalOverallHealingOverHealing, PercentOfTotalOverallHealingMitigated = source.PercentOfTotalOverallHealingMitigated, PercentOfTotalOverallDamageTaken = source.PercentOfTotalOverallDamageTaken, PercentOfTotalOverallDamageTakenOverTime = source.PercentOfTotalOverallDamageTakenOverTime, Players = new List<PlayerEntity>() }; foreach (var playerEntity in source.Players) { try { switch (parseType) { case ParseType.DPS: decimal dps; decimal.TryParse(Settings.Default.DPSVisibility, out dps); if (playerEntity.CombinedDPS <= dps) { continue; } break; case ParseType.DTPS: decimal dtps; decimal.TryParse(Settings.Default.DTPSVisibility, out dtps); if (playerEntity.CombinedDTPS <= dtps) { continue; } break; case ParseType.HPS: decimal hps; decimal.TryParse(Settings.Default.HPSVisibility, out hps); if (playerEntity.CombinedHPS <= hps) { continue; } break; } var entity = new PlayerEntity { Name = playerEntity.Name, Job = playerEntity.Job, CombinedDPS = playerEntity.CombinedDPS, DPS = playerEntity.DPS, DOTPS = playerEntity.DOTPS, CombinedHPS = playerEntity.CombinedHPS, HPS = playerEntity.HPS, HOTPS = playerEntity.HOTPS, HOHPS = playerEntity.HOHPS, HMPS = playerEntity.HMPS, CombinedDTPS = playerEntity.CombinedDTPS, DTPS = playerEntity.DTPS, DTOTPS = playerEntity.DTOTPS, CombinedTotalOverallDamage = playerEntity.CombinedTotalOverallDamage, TotalOverallDamage = playerEntity.TotalOverallDamage, TotalOverallDamageOverTime = playerEntity.TotalOverallDamageOverTime, CombinedTotalOverallHealing = playerEntity.CombinedTotalOverallHealing, TotalOverallHealing = playerEntity.TotalOverallHealing, TotalOverallHealingOverTime = playerEntity.TotalOverallHealingOverTime, TotalOverallHealingOverHealing = playerEntity.TotalOverallHealingOverHealing, TotalOverallHealingMitigated = playerEntity.TotalOverallHealingMitigated, CombinedTotalOverallDamageTaken = playerEntity.CombinedTotalOverallDamageTaken, TotalOverallDamageTaken = playerEntity.TotalOverallDamageTaken, TotalOverallDamageTakenOverTime = playerEntity.TotalOverallDamageTakenOverTime, PercentOfTotalOverallDamage = playerEntity.PercentOfTotalOverallDamage, PercentOfTotalOverallDamageOverTime = playerEntity.PercentOfTotalOverallDamageOverTime, PercentOfTotalOverallHealing = playerEntity.PercentOfTotalOverallHealing, PercentOfTotalOverallHealingOverTime = playerEntity.PercentOfTotalOverallHealingOverTime, PercentOfTotalOverallHealingOverHealing = playerEntity.PercentOfTotalOverallHealingOverHealing, PercentOfTotalOverallHealingMitigated = playerEntity.PercentOfTotalOverallHealingMitigated, PercentOfTotalOverallDamageTaken = playerEntity.PercentOfTotalOverallDamageTaken, PercentOfTotalOverallDamageTakenOverTime = playerEntity.PercentOfTotalOverallDamageTakenOverTime, Type = playerEntity.Type }; target.Players.Add(entity); } catch (Exception ex) { } } // sort entity based on settings switch (parseType) { case ParseType.DPS: if (target.Players.Any()) { switch (Settings.Default.DPSWidgetSortDirection) { case "Descending": switch (Settings.Default.DPSWidgetSortProperty) { case "Name": target.Players = new List<PlayerEntity>(target.Players.OrderByDescending(p => p.Name)); break; case "Job": target.Players = new List<PlayerEntity>(target.Players.OrderByDescending(p => p.Job)); break; case "DPS": target.Players = new List<PlayerEntity>(target.Players.OrderByDescending(p => p.DPS)); break; case "CombinedDPS": target.Players = new List<PlayerEntity>(target.Players.OrderByDescending(p => p.CombinedDPS)); break; case "TotalOverallDamage": target.Players = new List<PlayerEntity>(target.Players.OrderByDescending(p => p.TotalOverallDamage)); break; case "CombinedTotalOverallDamage": target.Players = new List<PlayerEntity>(target.Players.OrderByDescending(p => p.CombinedTotalOverallDamage)); break; case "PercentOfTotalOverallDamage": target.Players = new List<PlayerEntity>(target.Players.OrderByDescending(p => p.PercentOfTotalOverallDamage)); break; } break; default: switch (Settings.Default.DPSWidgetSortProperty) { case "Name": target.Players = new List<PlayerEntity>(target.Players.OrderBy(p => p.Name)); break; case "Job": target.Players = new List<PlayerEntity>(target.Players.OrderBy(p => p.Job)); break; case "DPS": target.Players = new List<PlayerEntity>(target.Players.OrderBy(p => p.DPS)); break; case "CombinedDPS": target.Players = new List<PlayerEntity>(target.Players.OrderBy(p => p.CombinedDPS)); break; case "TotalOverallDamage": target.Players = new List<PlayerEntity>(target.Players.OrderBy(p => p.TotalOverallDamage)); break; case "CombinedTotalOverallDamage": target.Players = new List<PlayerEntity>(target.Players.OrderBy(p => p.CombinedTotalOverallDamage)); break; case "PercentOfTotalOverallDamage": target.Players = new List<PlayerEntity>(target.Players.OrderBy(p => p.PercentOfTotalOverallDamage)); break; } break; } } DPSWidgetViewModel.Instance.ParseEntity = target; break; case ParseType.DTPS: if (target.Players.Any()) { switch (Settings.Default.DTPSWidgetSortDirection) { case "Descending": switch (Settings.Default.DTPSWidgetSortProperty) { case "Name": target.Players = new List<PlayerEntity>(target.Players.OrderByDescending(p => p.Name)); break; case "Job": target.Players = new List<PlayerEntity>(target.Players.OrderByDescending(p => p.Job)); break; case "DTPS": target.Players = new List<PlayerEntity>(target.Players.OrderByDescending(p => p.DTPS)); break; case "CombinedDTPS": target.Players = new List<PlayerEntity>(target.Players.OrderByDescending(p => p.CombinedDTPS)); break; case "TotalOverallDamageTaken": target.Players = new List<PlayerEntity>(target.Players.OrderByDescending(p => p.TotalOverallDamageTaken)); break; case "CombinedTotalOverallDamageTaken": target.Players = new List<PlayerEntity>(target.Players.OrderByDescending(p => p.CombinedTotalOverallDamageTaken)); break; case "PercentOfTotalOverallDamageTaken": target.Players = new List<PlayerEntity>(target.Players.OrderByDescending(p => p.PercentOfTotalOverallDamageTaken)); break; } break; default: switch (Settings.Default.DTPSWidgetSortProperty) { case "Name": target.Players = new List<PlayerEntity>(target.Players.OrderBy(p => p.Name)); break; case "Job": target.Players = new List<PlayerEntity>(target.Players.OrderBy(p => p.Job)); break; case "DTPS": target.Players = new List<PlayerEntity>(target.Players.OrderBy(p => p.DTPS)); break; case "CombinedDTPS": target.Players = new List<PlayerEntity>(target.Players.OrderBy(p => p.CombinedDTPS)); break; case "TotalOverallDamageTaken": target.Players = new List<PlayerEntity>(target.Players.OrderBy(p => p.TotalOverallDamageTaken)); break; case "CombinedTotalOverallDamageTaken": target.Players = new List<PlayerEntity>(target.Players.OrderBy(p => p.CombinedTotalOverallDamageTaken)); break; case "PercentOfTotalOverallDamageTaken": target.Players = new List<PlayerEntity>(target.Players.OrderBy(p => p.PercentOfTotalOverallDamageTaken)); break; } break; } } DTPSWidgetViewModel.Instance.ParseEntity = target; break; case ParseType.HPS: if (target.Players.Any()) { switch (Settings.Default.HPSWidgetSortDirection) { case "Descending": switch (Settings.Default.HPSWidgetSortProperty) { case "Name": target.Players = new List<PlayerEntity>(target.Players.OrderByDescending(p => p.Name)); break; case "Job": target.Players = new List<PlayerEntity>(target.Players.OrderByDescending(p => p.Job)); break; case "HPS": target.Players = new List<PlayerEntity>(target.Players.OrderByDescending(p => p.HPS)); break; case "CombinedHPS": target.Players = new List<PlayerEntity>(target.Players.OrderByDescending(p => p.CombinedHPS)); break; case "TotalOverallHealing": target.Players = new List<PlayerEntity>(target.Players.OrderByDescending(p => p.TotalOverallHealing)); break; case "CombinedTotalOverallHealing": target.Players = new List<PlayerEntity>(target.Players.OrderByDescending(p => p.CombinedTotalOverallHealing)); break; case "PercentOfTotalOverallHealing": target.Players = new List<PlayerEntity>(target.Players.OrderByDescending(p => p.PercentOfTotalOverallHealing)); break; } break; default: switch (Settings.Default.HPSWidgetSortProperty) { case "Name": target.Players = new List<PlayerEntity>(target.Players.OrderBy(p => p.Name)); break; case "Job": target.Players = new List<PlayerEntity>(target.Players.OrderBy(p => p.Job)); break; case "HPS": target.Players = new List<PlayerEntity>(target.Players.OrderBy(p => p.HPS)); break; case "CombinedHPS": target.Players = new List<PlayerEntity>(target.Players.OrderBy(p => p.CombinedHPS)); break; case "TotalOverallHealing": target.Players = new List<PlayerEntity>(target.Players.OrderBy(p => p.TotalOverallHealing)); break; case "CombinedTotalOverallHealing": target.Players = new List<PlayerEntity>(target.Players.OrderBy(p => p.CombinedTotalOverallHealing)); break; case "PercentOfTotalOverallHealing": target.Players = new List<PlayerEntity>(target.Players.OrderBy(p => p.PercentOfTotalOverallHealing)); break; } break; } } HPSWidgetViewModel.Instance.ParseEntity = target; break; } } catch (Exception ex) { } }