private void FetchDataFromJSONFiles(string path, ParserType type) { IEnumerable <string> jsonFiles = Directory.EnumerateFiles(path, "*.*", SearchOption.AllDirectories); List <string> failedJsons = new List <string>(); int fileIndex = 0; foreach (string jsonFile in jsonFiles) { try { using (StreamReader sr = new StreamReader(jsonFile)) { string json = sr.ReadToEnd(); switch (type) { case ParserType.Car: this.DispatchCarFromJSON(json); break; case ParserType.Bid: this.DispatchBidsFromJSON(json, fileIndex++); break; default: throw new InvalidOperationException("Parser type not supported."); } } } catch (JsonException) { failedJsons.Add(jsonFile); } } }
/// <summary> /// Creates a new instance. /// </summary> /// <param name="order"><see cref="Parsing.ParserType"/></param> /// <param name="converter">Converter instance.</param> /// <param name="validator">Validator instance chain.</param> /// <param name="mapper">Mapper instance.</param> protected ArgumentParser(ParserType order, IValueConverter <TValue> converter, IValidator <TValue>?validator, IMapper <TOptions, TValue> mapper ) : this(null, order, converter, validator, mapper) { }
/// <summary> /// 解析, /// </summary> /// <param name="text"></param> /// <param name="type"> 提供三种标签集合, 全部支持, 大部分支持, 最少 </param> /// <returns></returns> public static string ConvertUbbToHtml(string text, ParserType type) { UbbParser parser; parser = GetUbbParser(type); return(parser.UbbToHtml(text)); }
private void treeViewTypes_AfterLabelEdit(object sender, NodeLabelEditEventArgs e) { removeToolStripMenuItem.ShortcutKeys = Keys.Delete; if (e.Label != null) { if (e.Node.Tag is ParserType) { if (!ParserUtils.IsValidIdentifier(e.Label)) { MessageBox.Show(this, String.Format(CANAPE.Properties.Resources.ParserDocumentControl_InvalidIdentifier, e.Label), CANAPE.Properties.Resources.ParserDocumentControl_InvalidIdentifierCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); e.CancelEdit = true; EditNodeLabel(e.Node); } else if (_document.FindType(e.Label) != null) { MessageBox.Show(this, String.Format(CANAPE.Properties.Resources.ParserDocumentControl_TypeNameExists, e.Label), CANAPE.Properties.Resources.ParserDocumentControl_TypeNameExistsCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); e.CancelEdit = true; EditNodeLabel(e.Node); } else { ParserType type = (ParserType)e.Node.Tag; type.Name = e.Label; } } } }
private void duplicateTypeToolStripMenuItem_Click(object sender, EventArgs e) { try { if (treeViewTypes.SelectedNode != null) { ParserType type = treeViewTypes.SelectedNode.Tag as ParserType; if (type != null) { ParserType newType = type.Copy(); newType.Name = "Copy_" + newType.Name; _document.AddParserType(newType); treeViewTypes.SelectedNode = AddTreeNode(newType, true); } } } catch (Exception ex) { MessageBox.Show(this, ex.Message, Properties.Resources.MessageBox_ErrorString, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <inheritdoc /> public ContextResult MapArguments(ParseContext context, object options, ParserType parserType) { return(OrderedParserTypes .SelectMany(type => _runtimeCommands.Select(command => new { type, command })) .TakeWhile(_ => context.Reset()) .Aggregate(ContextResult.NoMatch, (result, pair) => result | pair.command.MapArguments(context, options, pair.type))); }
protected override ISyntaxParser <IN, OUT> BuildSyntaxParser(ParserConfiguration <IN, OUT> conf, ParserType parserType, string rootRule) { ISyntaxParser <IN, OUT> parser = null; switch (parserType) { case ParserType.LL_RECURSIVE_DESCENT: { parser = new RecursiveDescentSyntaxParser <IN, OUT>(conf, rootRule); break; } case ParserType.EBNF_LL_RECURSIVE_DESCENT: { parser = new EBNFRecursiveDescentSyntaxParser <IN, OUT>(conf, rootRule); break; } default: { parser = null; break; } } return(parser); }
static public ParserNode Parse(string data, ParserType parserType, bool strict) { switch (parserType) { case ParserType.Balanced: return(BalancedVisitor.Parse(data, strict)); case ParserType.Columns: return(ColumnsVisitor.Parse(data, strict)); case ParserType.CSharp: return(CSharpVisitor.Parse(data, strict)); case ParserType.CSV: return(CSVVisitor.Parse(data, strict)); case ParserType.ExactColumns: return(ExactColumnsVisitor.Parse(data, strict)); case ParserType.HTML: return(HTMLVisitor.Parse(data, strict)); case ParserType.JSON: return(JSONVisitor.Parse(data, strict)); case ParserType.SQL: return(SQLVisitor.Parse(data, strict)); case ParserType.TSV: return(TSVVisitor.Parse(data, strict)); case ParserType.XML: return(XMLVisitor.Parse(data, strict)); default: throw new ArgumentException("Unable to parse this type"); } }
private static UbbParser GetUbbParser(ParserType type) { switch (type) { case ParserType.Full: if (fullParser == null) { fullParser = new UbbParser(CreateHandlers( "ALIGN", "B", "U", "I", "S", "FONT", "COLOR", "EMAIL", "IMG" , "FLASH", "WMA", "MP3", "WMV", "SIZE", "RM", "QQ", "TABLE", "URL" , "SUB", "SUP", "BGCOLOR", "INDENT", "LIST", "MSN", "QUOTE", "BR" )); } return(fullParser); case ParserType.Normal: if (normalParser == null) { normalParser = new UbbParser(CreateHandlers("B", "I", "U", "SIZE", "IMG", "COLOR", "S", "BGCOLOR", "URL", "FONT", "EMAIL", "FLASH")); } return(normalParser); case ParserType.Simple: if (simpleParser == null) { simpleParser = new UbbParser(CreateHandlers("B", "I", "U", "SIZE", "IMG", "COLOR", "S", "BGCOLOR")); } return(simpleParser); } return(new UbbParser()); }
private string GetNameByParserType(ParserType Type) { switch (Type) { case ParserType.Page: return(Resources.PageParser); case ParserType.Item: return(Resources.ItemParser); case ParserType.Npc: return(Resources.NpcDataParser); case ParserType.NpcLocale: return(Resources.NpcLocaleParser); case ParserType.Quest: return(Resources.QuestDataParser); case ParserType.QuestLocale: return(Resources.QuestLocaleParser); case ParserType.Trainer: return(Resources.TrainerParser); case ParserType.Vendor: return(Resources.VendorParser); default: throw new InvalidOperationException(Type.ToString()); } }
public string ToString(string ending, ParserType tableType = ParserType.Columns) { var result = new List <List <string> >(); result.Add(Headers.ToList()); result.AddRange(Rows.Select(row => row.Select(item => item.ToString()).ToList())); switch (tableType) { case ParserType.TSV: return(string.Join("", result.Select(items => string.Join("\t", items.Select(item => ToTCSV(item, '\t'))) + ending))); case ParserType.CSV: return(string.Join("", result.Select(items => string.Join(",", items.Select(item => ToTCSV(item, ','))) + ending))); case ParserType.Columns: { var newLineChars = new char[] { '\r', '\n' }; result = result.Select(row => row.Select(value => value.Trim()).ToList()).ToList(); var columnWidths = Enumerable.Range(0, Headers.Count).Select(column => result.Max(line => line[column].IndexOfAny(newLineChars) == -1 ? line[column].Length : 0)).ToList(); return(string.Join("", result.AsParallel().AsOrdered().Select(line => "║ " + string.Join(" │ ", Enumerable.Range(0, Headers.Count).Select(column => line[column] + new string(' ', Math.Max(columnWidths[column] - line[column].Length, 0)))) + " ║" + ending))); } case ParserType.ExactColumns: { var newLineChars = new char[] { '\r', '\n' }; result = result.Select(row => row.Select(value => $@"""{value.Replace(@"""", @"""""")}""").ToList()).ToList(); var columnWidths = Enumerable.Range(0, Headers.Count).Select(column => result.Max(line => line[column].IndexOfAny(newLineChars) == -1 ? line[column].Length : 0)).ToList(); return(string.Join("", result.AsParallel().AsOrdered().Select(line => "║ " + string.Join(" │ ", Enumerable.Range(0, Headers.Count).Select(column => line[column] + new string(' ', Math.Max(columnWidths[column] - line[column].Length, 0)))) + " ║" + ending))); } default: throw new ArgumentException("Invalid output type"); } }
public bool TryGetValue(string typeName, out ParserType outType) { if (Types.Builtin.TryGetValue(typeName, out var builtinType)) { outType = builtinType; return(true); } if (_ownTypeCache.TryGetValue(typeName, out var ownCachedType)) { outType = ownCachedType; return(true); } try { outType = _ownTypeCache[typeName] = new CustomType(_generator.GetCachedTypeGraph(typeName)); return(true); } catch (FileNotFoundException) { } outType = default; return(false); }
public MyParser(Template template, ParserType parserType, IValueConverter <string> converter, IValidator <string> validator, IMapper <object, string> mapper) : base(template, parserType, converter, validator, mapper) { }
public FunctionDeclare(string name, IStatement arguments, IStatement statements, ParserType type) { _name = name; _arguments = arguments; _statements = statements; _type = type; }
public static IParser GetParser(ParserType type_) { switch (type_) { case ParserType.Bbg_PX_Last: case ParserType.Bbg_ASW: case ParserType.Bbg_Yld: return Singleton<BloombergImpl>.Instance; case ParserType.TA_EDFut: case ParserType.TA_ERFut: case ParserType.TA_L_Fut: case ParserType.TA_Euribor: case ParserType.TA_GBBLibor: case ParserType.TA_USDLibor: return Singleton<RatesSpreadsImpl>.Instance; case ParserType.CMT_Yield: return Singleton<CMTImpl>.Instance; case ParserType.CMT_ASW: return Singleton<CMTASWImpl>.Instance; case ParserType.Asian_ASW: case ParserType.Asian_ASW_UnAdj: return Singleton<AsiaAswImpl>.Instance; case ParserType.CarbonDF: return Singleton<CarbonDataFrameImpl>.Instance; default: throw new Exception(string.Format("Need to hook up implementation for {0}", type_)); } }
public void ParseFile(string fileUrl) { ParserType type = GetExtention(fileUrl); parser = Factory.GetParser(type.ToString()); parser.FileUrl = fileUrl; parser.Parse(); }
/// <summary> /// Initializes a new instance of the <see cref="ParserCrossEvaluator"/> class. /// </summary> /// <param name="languageCode">The language of the training data.</param> /// <param name="parameters">The machine learning train parameters.</param> /// <param name="parserType">The parser model type.</param> /// <param name="monitors">The training monitors.</param> /// <param name="headRules">The headrules.</param> public ParserCrossEvaluator(string languageCode, TrainingParameters parameters, AbstractHeadRules headRules, ParserType parserType, params IEvaluationMonitor <Parse>[] monitors) { this.languageCode = languageCode; this.parameters = parameters; this.headRules = headRules; this.parserType = parserType; this.monitors = monitors; }
public ParserModel(string languageCode, IMaxentModel buildModel, IMaxentModel checkModel, IMaxentModel attachModel, POSModel parserTagger, ChunkerModel chunkerTagger, AbstractHeadRules headRules, ParserType modelType) : this( languageCode, buildModel, checkModel, attachModel, parserTagger, chunkerTagger, headRules, modelType, null) { }
public ParserModel(string languageCode, IMaxentModel buildModel, IMaxentModel checkModel, POSModel parserTagger, ChunkerModel chunkerTagger, AbstractHeadRules headRules, ParserType type, Dictionary <string, string> manifestInfoEntries) : this( languageCode, buildModel, checkModel, null, parserTagger, chunkerTagger, headRules, type, manifestInfoEntries) { }
/// <summary> /// Constructor utilizing the client defined connector /// </summary> /// <param name="parser">Which data format should be retrieved</param> /// <param name="connector">Connection class used to retrieve the data</param> public AviationWeather(ParserType parser, IConnector connector) { _parserType = parser; _connector = connector; _metarAccessor = new METARAccessor(_parserType, _connector); _tafAccessor = new TAFAccessor(_parserType, _connector); _stationDataAccessor = new StationDataAccessor(_parserType, _connector); }
// this method is created for testing purpose public void SetUpWrapper(ParserType parserType, string inputText) { foreach (var productWrapper in m_wrappers) { productWrapper.ParserType = parserType; productWrapper.InputText = inputText; } }
static public Result Run(Window parent, ParserType tableType) { var dialog = new TableConvertDialog(tableType) { Owner = parent }; return(dialog.ShowDialog() ? dialog.result : null); }
/// <summary> /// Gets the file parser from file extension. /// </summary> /// <param name="fileName">Name of the file.</param> /// <returns>Returns the specific parser which will be used for parsing the input file.</returns> public IFileParser GetFileParserFromFileExtension(string fileName) { ParserType type = GetExtension(fileName); IFileParser parser = Parsers[type.ToString()]; parser.FilePath = fileName; return(parser); }
public void ParseFile(string FileName) { ValidateFile.Validate(FileName); ParserType type = GetExtention(FileName); parser = Factory.GetObject(type.ToString()); parser.FileName = FileName; parser.Read(); }
public static IBuildResultParser Create(ParserType parserType) { if (FactoryDictionary.TryGetValue(parserType, out var testResultParser)) { return(testResultParser()); } throw new ArgumentException(nameof(parserType)); }
/// <summary> /// Remove a parser type from the document /// </summary> /// <param name="type"></param> public void RemoveParserType(ParserType type) { _types.Remove(type); type.DirtyChanged -= new EventHandler(type_DirtyChanged); UpdateContainer(); Dirty = true; }
/// <summary> /// Add a new parser type /// </summary> /// <param name="type">The type to add</param> public void AddParserType(ParserType type) { _types.Add(type); type.DirtyChanged += new EventHandler(type_DirtyChanged); UpdateContainer(); Dirty = true; }
public static IBalanceParser Get(ParserType type) { switch (type) { case ParserType.GjExcel: return(new Parsers.GjExcelParserShoes()); } throw new NotImplementedException("No Parser is defined for type: " + type); }
public override Task<ParseResult> Parse(ParserType parserType_, string givenString_, DateTime firstDate_) { return new Task<ParseResult>(() => { var lastDigit = givenString_.Substring(givenString_.Length - 1, 1); int n; bool isNumeric = int.TryParse(lastDigit, out n); if (!isNumeric) n = 1; else givenString_ = givenString_.TrimEnd(n.ToString().ToCharArray()); var market = givenString_.Market(); if (string.IsNullOrEmpty(market)) { return new ParseResult() { ParseError = "No market is found for the given input", GivenString = givenString_ }; } var moniker = ("BLIM.roll.fctd." + market.ToLower() + "." + givenString_.ToLower()); string column; switch (parserType_) { case ParserType.Asian_ASW: column = n == 1 ? "smoothspread" : "dsmoothspread"; break; case ParserType.Asian_ASW_UnAdj: column = n == 1 ? "spread" : "dspread"; break; default: throw new ArgumentOutOfRangeException("parserType not supported in AsiaAswImpl", parserType_, null); } var cc_ = Carbon.Carbon.GetInstance().GetCarbonClientInstance(); var con = DataFrameHelper.GetDataFrameByRow(name_: moniker, keyExtractor_: x => (DateTime) x, valueExtractor_: (dict, vals) => dict.ContainsKey(column) ? vals[dict[column]] as double? : null, cc_: cc_).Result; if (con == null) { return new ParseResult() { ParseError = "Unable to retrieve asian invoice spreads from carbon", GivenString = givenString_ }; } var data = con.Data.Where(d => d.Key >= firstDate_).Select(s => s.Key).Select(k => con[k][0] ?? double.NaN).ToArray(); //var fileredData = data.Where(d => d.x.HasValue && d.x.Value >= firstDate_); return new ParseResult() { GivenString = givenString_, Series = new DatedDataCollectionGen<double>(con.Data.Where(d => d.Key >= firstDate_).Select(s => s.Key).ToArray(), data), }; }); }
public override string GetHelpString(ParserType parserType_) { StringBuilder b = new StringBuilder(); b.AppendLine("Simply type in the instrument name same as what stored in Carbon"); b.AppendLine(); b.AppendLine("For example:"); b.AppendLine("for ccy pair, type: USDJPY"); return b.ToString(); }
/// <summary> /// Maps the arguments found in the given context to the options instance using a set of /// parsers defined in a configuration. /// </summary> /// <param name="options">Options type.</param> /// <param name="parsers">Parsers used to process the context arguments.</param> /// <param name="parseContext">Context that contains the command line arguments.</param> /// <param name="parserType">Parser type filter.</param> /// <returns><see cref="ContextResult"/></returns> internal static ContextResult Map(TOptions options, IEnumerable <IArgumentParser <TOptions> > parsers, ParseContext parseContext, ParserType parserType) { return(parsers .Where(p => p.ParserType == parserType) .TakeWhile(p => parseContext.Reset()) .Aggregate(ContextResult.NoMatch, (current, parser) => InvokeParser(options, parseContext, current, parser))); }
public static IParser GetUsersParser(ParserType type) { switch (type) { case ParserType.CSV: return new UsersFileParser(); break; default: throw new Exception("Unknown type!"); } }
public ParseModel(string modelID, ParserType type) { this.hsModel = new Hashtable(); this.sbFieldParam = new StringBuilder(); this.modelID = modelID; this.Init(); this.tableReferenceInfo = this.hsModel["CustomCol"].ToString(); this.modelType = type; this._pageName = CutTableNamePreFix(this.hsModel["TableName"].ToString()); }
static internal string Comment(ParserType type, TextData data, Range range) { switch (type) { case ParserType.CSharp: return CSharpVisitor.Comment(data, range); case ParserType.HTML: case ParserType.XML: return HTMLVisitor.Comment(data, range); default: throw new Exception("Cannot comment this content type"); } }
private IResponseParser <T> ChooseResponseParser(ParserType parserInstance) { switch (parserInstance) { case ParserType.EntityCollectionResponseParser: return(new EntityCollectionResponseParser <T>()); default: return(new ResponseParser <T>()); } }
public override IParser CreateParser(ParserType type) { switch (type) { case ParserType.SIMPLEXMLPARSER: return(new SimpleXmlParser()); default: throw new InvalidEnumArgumentException("type", (int)type, typeof(ParserType)); } }
public override string GetHelpString(ParserType parserType_) { StringBuilder b = new StringBuilder(); b.AppendLine("You can type a bloomberg ticker, just as you would in the bloomberg application"); b.AppendLine(); b.AppendLine("For example:"); b.AppendLine("TY1 Comdty = Rolled front TY contract (rolling dictated by your own setting on 'GFUT <GO>'"); b.AppendLine(".MyCIX StructureIndex = a CIX you may have created using 'CIX <GO>'"); return b.ToString(); }
static public ParserNode Parse(string data, ParserType parserType) { switch (parserType) { case ParserType.Balanced: return BalancedVisitor.Parse(data); case ParserType.Columns: return ColumnsVisitor.Parse(data); case ParserType.CSharp: return CSharpVisitor.Parse(data); case ParserType.CSV: return CSVVisitor.Parse(data); case ParserType.ExactColumns: return ExactColumnsVisitor.Parse(data); case ParserType.HTML: return HTMLVisitor.Parse(data); case ParserType.JSON: return JSONVisitor.Parse(data); case ParserType.SQL: return SQLVisitor.Parse(data); case ParserType.TSV: return TSVVisitor.Parse(data); case ParserType.XML: return XMLVisitor.Parse(data); default: throw new ArgumentException("Unable to parse this type"); } }
public string Parse(ParserType type) { var tmp = string.Empty; switch (type) { case ParserType.XCODER: var statement = new StatementParser(Options); var temp = statement.Build(Options.StatementParameters); Options.Code = new StringBuilder(temp); var varies = new VariableParser(Options); tmp = varies.Build(Options.VariableParameter); break; default: throw new ArgumentOutOfRangeException("type"); } Options.Code = null; return tmp; }
public override string GetHelpString(ParserType parserType_) { switch (parserType_) { case ParserType.TA_EDFut: case ParserType.TA_ERFut: case ParserType.TA_L_Fut: return RatesSpreads.Display.StructureCreator.GetFutExample("Example of accepted inputs:"); case ParserType.TA_Euribor: case ParserType.TA_GBBLibor: case ParserType.TA_USDLibor: return RatesSpreads.Display.StructureCreator.GetIRExample("Example of accepted inputs:"); default: return null; } }
public HttpParser (ParserType type) { this.type = type; switch (type) { case ParserType.HTTP_REQUEST: this.state = State.start_req; break; case ParserType.HTTP_RESPONSE: this.state = State.start_res; break; case ParserType.HTTP_BOTH: this.state = State.start_res_or_res; break; default: throw new HttpException ("can't happen, invalid ParserType enum"); } }
public override Task<ParseResult> Parse(ParserType parserType_, string givenString_, DateTime firstDate_) { return new Task<ParseResult>(() => { var result = CMTs.InputStringParser.ParseToCombination(Data.BondCurves.NONE, Focus.Yield, givenString_); if (!string.IsNullOrEmpty(result.Item1)) return new ParseResult() { ParseError = result.Item1, GivenString = givenString_ }; else return new ParseResult() { GivenString = givenString_, Series = result.Item2.GetSubValues(firstDate_, DateTime.Today) }; }); }
public string Parse(ParserType type) { var tmp = string.Empty; switch (type) { case ParserType.XCODER: var scope = new ScopeParser(Options); scope.OnParse += (scope_OnParse); var output = scope.Parse(); var param = new ParamParser(Options); output = param.Parse(new StringBuilder(output)); tmp = output; scope.Release(); param.Release(); break; default: throw new ArgumentOutOfRangeException("type"); } Options.Code = null; return tmp; }
/// <summary> /// Initializes a new instance of the <see cref="ParserModel"/> using the specified models and head rules. /// </summary> /// <param name="languageCode">The language code.</param> /// <param name="buildModel">The model to assign constituent labels.</param> /// <param name="checkModel">The model to determine a constituent is complete.</param> /// <param name="attachModel">The attach model.</param> /// <param name="parserTagger">The model to assign pos-tags.</param> /// <param name="chunkerTagger">The model to assign flat constituent labels.</param> /// <param name="headRules">The head rules.</param> /// <param name="modelType">Type of the model.</param> /// <param name="manifestInfoEntries">The manifest information entries.</param> /// <exception cref="System.ArgumentException"> /// If the <paramref name="modelType"/> is equal to <see cref="Parser.ParserType.Chunking"/> the <paramref name="attachModel"/> must be <c>null</c>. /// or /// If the <paramref name="modelType"/> is equal to <see cref="Parser.ParserType.TreeInsert"/> the <paramref name="attachModel"/> must not be <c>null</c>. /// </exception> /// <exception cref="ArgumentOutOfRangeException"> /// Unknown <paramref name="modelType"/> value. /// </exception> public ParserModel( string languageCode, IMaxentModel buildModel, IMaxentModel checkModel, IMaxentModel attachModel, POSModel parserTagger, ChunkerModel chunkerTagger, AbstractHeadRules headRules, ParserType modelType, Dictionary<string, string> manifestInfoEntries) : base(ComponentName, languageCode, manifestInfoEntries) { switch (modelType) { case ParserType.Chunking: if (attachModel != null) throw new ArgumentException(@"attachModel must be null for chunking parser!", "attachModel"); Manifest[ParserTypeParameter] = "CHUNKING"; break; case ParserType.TreeInsert: if (attachModel == null) throw new ArgumentException(@"attachModel must not be null for treeinsert parser!", "attachModel"); Manifest[ParserTypeParameter] = "TREEINSERT"; artifactMap[EntryAttachModel] = attachModel; break; default: throw new ArgumentOutOfRangeException("modelType", "Unknown model type"); } artifactMap[EntryBuildModel] = buildModel; artifactMap[EntryCheckModel] = checkModel; artifactMap[EntryParserTaggerModel] = parserTagger; artifactMap[EntryChunkerTaggerModel] = chunkerTagger; artifactMap[EntryHeadRules] = headRules; CheckArtifactMap(); }
/// <summary> /// Return the relevant parser based on the type /// </summary> /// <param name="parserType"></param> /// <returns></returns> public static IParser GetParser(ParserType parserType) { IParser parser = null; switch(parserType) { case ParserType.Conversion: parser = new ConversionParser(ConversionData.GetConversionData()); break; case ParserType.Separator: parser = new SeparatorParser(new Store.SeparatorData()); break; case ParserType.Input: parser = new InputParser(); break; case ParserType.Question: parser = new QuestionParser(); break; default: break; } return parser; }
public override Task<ParseResult> Parse(ParserType parserType_, string givenString_, DateTime firstDate_) { return new Task<ParseResult>(() => { var carbon = Carbon.Carbon.GetInstance().GetCarbonClientInstance(); var b = TimeSeriesCache.Get(givenString_, carbon).Result; if (b == null || b.Length == 0) { return new ParseResult() { ParseError = string.Format("No data returned from Carbon DataFrame for given instrument name '{0}'", givenString_), GivenString = givenString_ }; } return new ParseResult() { GivenString = givenString_, Series = b.GetSubValues(x => x < firstDate_), }; }); }
override public Task<ParseResult> Parse(ParserType parserType_, string givenString_, DateTime firstDate_) { return new Task<ParseResult>(() => { var fld = "PX_LAST"; switch (parserType_) { case ParserType.Bbg_Yld: fld = "YLD_YTM_MID"; break; case ParserType.Bbg_ASW: fld = "ASSET_SWAP_SPD_MID"; break; case ParserType.Bbg_PX_Last: fld = "PX_LAST"; break; } var b = BbgTalk.HistoryRequester.GetHistory(firstDate_, givenString_, fld, false); if (b == null || b.Length == 0) { return new ParseResult() { ParseError = string.Format("No data returned from bloomberg for given ticker '{0}'", givenString_), GivenString = givenString_ }; } return new ParseResult() { GivenString = givenString_, Series = b }; }); }
//public override Task<ParseResult> Parse(ParserType parserType_, string givenString_, DateTime firstDate_) //{ // return new Task<ParseResult>(() => // { // var con = Singleton<SI.Data.AsianInvoiceSpreads>.Instance.GetNewDataFrameAsync().Result ?? // Singleton<SI.Data.AsianInvoiceSpreads>.Instance.GetNewDataFrameAsync(forceRetry_: true).Result; // if (con == null) // { // return new ParseResult() // { // ParseError="Unable to retrieve asian invoice spreads from mongo server", // GivenString=givenString_ // }; // } // int index = -1; // for (int i = 0; i < con.ColumnHeadings.Length; ++i) // { // if (String.Compare(con.ColumnHeadings[i], givenString_.Trim(), StringComparison.OrdinalIgnoreCase) == 0) // { // index = i; // break; // } // } // if (index==-1) // { // return new ParseResult() // { // ParseError="Given string not found as a heading", // GivenString = givenString_ // }; // } // return new ParseResult() // { // GivenString=givenString_, // Series = new DatedDataCollectionGen<double>(con.Dates,con.Data.Select(c=>c[index]).ToArray()).GetSubValues(x=>x < firstDate_) // }; // }); //} public override string GetHelpString(ParserType parserType_) { return "Enter one of the series names (saved by Brian Lim). e.g. JB1, JB2"; }
public abstract string GetHelpString(ParserType parserType_);
abstract public Task<ParseResult> Parse(ParserType parserType_, string givenString_, DateTime firstDate_);
public override string GetHelpString(ParserType parserType_) { return CMTs.Display.SeasonalityPlugin.getHelpString(); }
public override Task<ParseResult> Parse(ParserType parserType_, string givenString_, DateTime firstDate_) { return new Task<ParseResult>(() => { string curveString; switch (parserType_) { case ParserType.TA_Euribor: curveString = CurveNames.EUR6M; break; case ParserType.TA_GBBLibor: curveString = CurveNames.GBP6M; break; case ParserType.TA_USDLibor: curveString = CurveNames.USD3M; break; case ParserType.TA_EDFut: curveString = CurveNames.EDCurve; break; case ParserType.TA_ERFut: curveString = CurveNames.ERCurve; break; case ParserType.TA_L_Fut: curveString = CurveNames.L_Curve; break; default: { return new ParseResult() { ParseError = string.Format("{0} is not a parse type I can deal with", EnumDescriptionAttribute.GetDescription(parserType_)), GivenString = givenString_ }; } } var result = RatesSpreads.CustomStructureHelper.CustomBuildFutures(curveString, givenString_); if (result.ErrorString != null) return new ParseResult() { ParseError = result.ErrorString, GivenString = givenString_ }; else if (result.CanCreateStructure()) { var instrument = result.ParseResult.CreateInstrument(); //result.Task.Start(); //Task.WaitAll(result.Task); return new ParseResult() { GivenString = givenString_, Series = instrument.A_Prices.GetSubValues(firstDate_, DateTime.Today) }; } else return new ParseResult() { ParseError="There was an error parsing given string" }; }); }
private string GetNameByParserType(ParserType type) { switch (type) { case ParserType.Page: return Resources.PageParser; case ParserType.Item: return Resources.ItemParser; case ParserType.Npc: return Resources.NpcDataParser; case ParserType.NpcLocale: return Resources.NpcLocaleParser; case ParserType.Quest: return Resources.QuestDataParser; case ParserType.QuestLocale: return Resources.QuestLocaleParser; case ParserType.Trainer: return Resources.TrainerParser; case ParserType.Vendor: return Resources.VendorParser; } return string.Empty; }
/** Execute the parser with the currently available data contained in * the buffer. The buffers position() and limit() need to be set * correctly (obviously) and a will be updated approriately when the * method returns to reflect the consumed data. */ public void Execute(ParserSettings settings, ByteBuffer data) { int p = (int) data.Position; int p_err = p; // this is used for pretty printing errors. // In case the headers don't provide information about the content // length, `execute` needs to be called with an empty buffer to // indicate that all the data has been send be the client/server, // else there is no way of knowing the message is complete. int len = (int) (data.Length - data.Position); if (0 == len) { if (State.body_identity_eof == state) settings.RaiseOnMessageComplete(this); } // in case the _previous_ call to the parser only has data to get to // the middle of certain fields, we need to update marks to point at // the beginning of the current buffer. switch (state) { case State.header_field: header_field_mark = p; break; case State.header_value: header_value_mark = p; break; case State.req_fragment: fragment_mark = p; url_mark = p; break; case State.req_query_string: query_string_mark = p; url_mark = p; break; case State.req_path: path_mark = p; // JACKSON ADDED, I assume java can fall through? url_mark = p; break; case State.req_host: case State.req_schema: case State.req_schema_slash: case State.req_schema_slash_slash: case State.req_port: case State.req_query_string_start: case State.req_fragment_start: url_mark = p; break; } // this is where the work gets done, traverse the available data... while (data.Position != data.Length) { p = (int) data.Position; int pe = (int) data.Length; byte ch = data.ReadByte (); // the current character to process. int c = -1; // utility variably used for up- and downcasing etc. int to_read = 0; // used to keep track of how much of body, etc. is left to read if (parsing_header (state)) { ++nread; if (nread > HTTP_MAX_HEADER_SIZE) { settings.RaiseOnError (this, "possible buffer overflow", data, p_err); } } switch (state) { /* * this state is used after a 'Connection: close' message * the parser will error out if it reads another message */ case State.dead: settings.RaiseOnError (this, "Connection already closed", data, p_err); // JACKSON: Added this break break; case State.start_res_or_res: if (CR == ch || LF == ch){ break; } flags = 0; content_length = -1; settings.RaiseOnMessageBegin (this); if (H == ch) state = State.res_or_resp_H; else { type = ParserType.HTTP_REQUEST; method = start_req_method_assign (ch); if (HttpMethod.ERROR == method) settings.RaiseOnError (this, "invalid method", data, p_err); index = 1; state = State.req_method; } break; case State.res_or_resp_H: if (T == ch) { type = ParserType.HTTP_RESPONSE; state = State.res_HT; } else { if (E != ch) settings.RaiseOnError (this, "not E", data, p_err); type = ParserType.HTTP_REQUEST; method = HttpMethod.HTTP_HEAD; index = 2; state = State.req_method; } break; case State.start_res: flags = 0; content_length = -1; settings.RaiseOnMessageBegin (this); switch (ch) { case H: state = State.res_H; break; case CR: case LF: break; default: settings.RaiseOnError (this, "Not H or CR/LF", data, p_err); break; } break; case State.res_H: if (strict && T != ch) settings.RaiseOnError (this, "Not T", data, p_err); state = State.res_HT; break; case State.res_HT: if (strict && T != ch) settings.RaiseOnError (this, "Not T2", data, p_err); state = State.res_HTT; break; case State.res_HTT: if (strict && P != ch) settings.RaiseOnError (this, "Not P", data, p_err); state = State.res_HTTP; break; case State.res_HTTP: if (strict && SLASH != ch) settings.RaiseOnError (this, "Not '/'", data, p_err); state = State.res_first_http_major; break; case State.res_first_http_major: if (!isDigit (ch)) settings.RaiseOnError (this, "Not a digit", data, p_err); http_major = (int) ch - 0x30; state = State.res_http_major; break; /* major HTTP version or dot */ case State.res_http_major: if (DOT == ch) { state = State.res_http_minor; break; } if (!isDigit (ch)) settings.RaiseOnError(this, "Not a digit", data, p_err); http_major *= 10; http_major += (ch - 0x30); if (http_major > 999) settings.RaiseOnError(this, "invalid http major version: " + http_major, data, p_err); break; /* first digit of minor HTTP version */ case State.res_first_http_minor: if (!isDigit (ch)) settings.RaiseOnError (this, "Not a digit", data, p_err); http_minor = (int)ch - 0x30; state = State.res_http_minor; break; /* minor HTTP version or end of request line */ case State.res_http_minor: if (SPACE == ch) { state = State.res_first_status_code; break; } if (!isDigit (ch)) settings.RaiseOnError(this, "Not a digit", data, p_err); http_minor *= 10; http_minor += (ch - 0x30); if (http_minor > 999) settings.RaiseOnError(this, "invalid http minor version: " + http_minor, data, p_err); break; case State.res_first_status_code: if (!isDigit (ch)) { if (SPACE == ch) break; settings.RaiseOnError (this, "Not a digit (status code)", data, p_err); } status_code = (int)ch - 0x30; state = State.res_status_code; break; case State.res_status_code: if (!isDigit (ch)) { switch (ch) { case SPACE: state = State.res_status; break; case CR: state = State.res_line_almost_done; break; case LF: state = State.header_field_start; break; default: settings.RaiseOnError(this, "not a valid status code", data, p_err); break; } break; } status_code *= 10; status_code += (int)ch - 0x30; if (status_code > 999) settings.RaiseOnError(this, "ridiculous status code:"+status_code, data, p_err); break; case State.res_status: /* the human readable status. e.g. "NOT FOUND" * we are not humans so just ignore this * we are not men, we are devo. */ if (CR == ch) { state = State.res_line_almost_done; break; } if (LF == ch) { state = State.header_field_start; break; } break; case State.res_line_almost_done: if (strict && LF != ch) settings.RaiseOnError (this, "not LF", data, p_err); state = State.header_field_start; break; case State.start_req: if (CR==ch || LF == LF) break; flags = 0; content_length = -1; settings.RaiseOnMessageBegin (this); method = start_req_method_assign (ch); if (HttpMethod.ERROR == method) settings.RaiseOnError (this, "invalid method", data, p_err); index = 1; state = State.req_method; break; case State.req_method: if (0 == ch) settings.RaiseOnError( this, "NULL in method", data, p_err); byte [] arr = HttpMethodBytes.GetBytes (method); if (SPACE == ch && index == arr.Length) state = State.req_spaces_before_url; else if (arr[index] == ch) { // wuhu! } else if (HttpMethod.HTTP_CONNECT == method) { if (1 == index && H == ch) { method = HttpMethod.HTTP_CHECKOUT; } else if (2 == index && P == ch) { method = HttpMethod.HTTP_COPY; } } else if (HttpMethod.HTTP_MKCOL == method) { if (1 == index && O == ch) { method = HttpMethod.HTTP_MOVE; } else if (1 == index && E == ch) { method = HttpMethod.HTTP_MERGE; } else if (2 == index && A == ch) { method = HttpMethod.HTTP_MKACTIVITY; } } else if (1 == index && HttpMethod.HTTP_POST == method && R == ch) { method = HttpMethod.HTTP_PROPFIND; } else if (1 == index && HttpMethod.HTTP_POST == method && U == ch) { method = HttpMethod.HTTP_PUT; } else if (4 == index && HttpMethod.HTTP_PROPFIND == method && P == ch) { method = HttpMethod.HTTP_PROPPATCH; } else { settings.RaiseOnError (this, "Invalid HTTP method", data, p_err); } ++index; break; /*__________________URL__________________*/ case State.req_spaces_before_url: if (SPACE == ch) break; if (SLASH == ch) { url_mark = p; path_mark = p; state = State.req_path; break; } if (isAtoZ (ch)) { url_mark = p; state = State.req_schema; break; } settings.RaiseOnError (this, "Invalid something", data, p_err); break; case State.req_schema: if (isAtoZ (ch)) break; if (COLON == ch) { state = State.req_schema_slash; break; } else if (DOT == ch) { state = State.req_host; break; } settings.RaiseOnError (this, "invalid char in schema: "+ch, data, p_err); break; case State.req_schema_slash: if (strict && SLASH != ch) settings.RaiseOnError (this, "invalid char in schema, not /", data, p_err); state = State.req_schema_slash_slash; break; case State.req_schema_slash_slash: if (strict && SLASH != ch) settings.RaiseOnError(this, "invalid char in schema, not /", data, p_err); state = State.req_host; break; case State.req_host: if (isAtoZ (ch)) break; if (isDigit (ch) || DOT == ch || DASH == ch) break; switch (ch) { case COLON: state = State.req_port; break; case SLASH: path_mark = p; break; case SPACE: /* The request line looks like: * "GET http://foo.bar.com HTTP/1.1" * That is, there is no path. */ settings.RaiseOnUrl (this, data, url_mark, p-url_mark); url_mark = -1; state = State.req_http_start; break; default: settings.RaiseOnError(this, "host error in method line", data, p_err); break; } break; case State.req_port: if (isDigit (ch)) break; switch (ch) { case SLASH: path_mark = p; state = State.req_path; break; case SPACE: /* The request line looks like: * "GET http://foo.bar.com:1234 HTTP/1.1" * That is, there is no path. */ settings.RaiseOnUrl (this,data,url_mark,p-url_mark); url_mark = -1; state = State.req_http_start; break; default: settings.RaiseOnError (this, "invalid port", data, p_err); break; } break; case State.req_path: if (usual (ch)) break; switch (ch) { case SPACE: settings.RaiseOnUrl (this,data,url_mark, p-url_mark); url_mark = -1; settings.RaiseOnPath(this,data,path_mark, p-path_mark); path_mark = -1; state = State.req_http_start; break; case CR: settings.RaiseOnUrl(this,data,url_mark, p-url_mark); url_mark = -1; settings.RaiseOnPath(this,data,path_mark, p-path_mark); path_mark = -1; http_minor = 9; state = State.res_line_almost_done; break; case LF: settings.RaiseOnUrl(this,data,url_mark, p-url_mark); url_mark = -1; settings.RaiseOnPath(this,data,path_mark, p-path_mark); path_mark = -1; http_minor = 9; state = State.header_field_start; break; case QMARK: settings.RaiseOnPath(this,data,path_mark, p-path_mark); path_mark = -1; state = State.req_query_string_start; break; case HASH: settings.RaiseOnPath(this,data,path_mark, p-path_mark); path_mark = -1; state = State.req_fragment_start; break; default: settings.RaiseOnError(this, "unexpected char in path", data, p_err); break; } break; case State.req_query_string_start: if (usual(ch)) { query_string_mark = p; state = State.req_query_string; break; } switch (ch) { case QMARK: break; case SPACE: settings.RaiseOnUrl(this, data, url_mark, p-url_mark); url_mark = -1; state = State.req_http_start; break; case CR: settings.RaiseOnUrl(this,data,url_mark, p-url_mark); url_mark = -1; http_minor = 9; state = State.res_line_almost_done; break; case LF: settings.RaiseOnUrl(this,data,url_mark, p-url_mark); url_mark = -1; http_minor = 9; state = State.header_field_start; break; case HASH: state = State.req_fragment_start; break; default: settings.RaiseOnError(this, "unexpected char in path", data, p_err); break; } break; case State.req_query_string: if (usual(ch)) { break; } switch (ch) { case QMARK: break; // allow extra '?' in query string case SPACE: settings.RaiseOnUrl(this, data, url_mark, p-url_mark); url_mark = -1; settings.RaiseOnQueryString(this, data, query_string_mark, p-query_string_mark); query_string_mark = -1; state = State.req_http_start; break; case CR: settings.RaiseOnUrl(this,data,url_mark, p-url_mark); url_mark = -1; settings.RaiseOnQueryString(this, data, query_string_mark, p-query_string_mark); query_string_mark = -1; http_minor = 9; state = State.res_line_almost_done; break; case LF: settings.RaiseOnUrl(this,data,url_mark, p-url_mark); url_mark = -1; settings.RaiseOnQueryString(this, data, query_string_mark, p-query_string_mark); query_string_mark = -1; http_minor = 9; state = State.header_field_start; break; case HASH: settings.RaiseOnQueryString(this, data, query_string_mark, p-query_string_mark); query_string_mark = -1; state = State.req_fragment_start; break; default: settings.RaiseOnError(this, "unexpected char in path", data, p_err); break; } break; case State.req_fragment_start: if (usual(ch)) { fragment_mark = p; state = State.req_fragment; break; } switch (ch) { case SPACE: settings.RaiseOnUrl(this, data, url_mark, p-url_mark); url_mark = -1; state = State.req_http_start; break; case CR: settings.RaiseOnUrl(this,data,url_mark, p-url_mark); url_mark = -1; http_minor = 9; state = State.res_line_almost_done; break; case LF: settings.RaiseOnUrl(this,data,url_mark, p-url_mark); url_mark = -1; http_minor = 9; state = State.header_field_start; break; case QMARK: fragment_mark = p; state = State.req_fragment; break; case HASH: break; default: settings.RaiseOnError(this, "unexpected char in path", data, p_err); break; } break; case State.req_fragment: if (usual(ch)) { break; } switch (ch) { case SPACE: settings.RaiseOnUrl(this, data, url_mark, p-url_mark); url_mark = -1; settings.RaiseOnFragment(this, data, fragment_mark, p-fragment_mark); fragment_mark = -1; state = State.req_http_start; break; case CR: settings.RaiseOnUrl(this,data,url_mark, p-url_mark); url_mark = -1; settings.RaiseOnFragment(this, data, query_string_mark, p-query_string_mark); fragment_mark = -1; http_minor = 9; state = State.res_line_almost_done; break; case LF: settings.RaiseOnUrl(this,data,url_mark, p-url_mark); url_mark = -1; settings.RaiseOnFragment(this, data, query_string_mark, p-query_string_mark); fragment_mark = -1; http_minor = 9; state = State.header_field_start; break; case QMARK: case HASH: break; default: settings.RaiseOnError(this, "unexpected char in path", data, p_err); break; } break; /******************* URL *******************/ /******************* HTTP 1.1 *******************/ case State.req_http_start: switch (ch) { case H: state = State.req_http_H; break; case SPACE: break; default: settings.RaiseOnError(this, "error in req_http_H", data, p_err); break; } break; case State.req_http_H: if (strict && T != ch) settings.RaiseOnError(this, "unexpected char", data, p_err); state = State.req_http_HT; break; case State.req_http_HT: if (strict && T != ch) settings.RaiseOnError(this, "unexpected char", data, p_err); state = State.req_http_HTT; break; case State.req_http_HTT: if (strict && P != ch) settings.RaiseOnError(this, "unexpected char", data, p_err); state = State.req_http_HTTP; break; case State.req_http_HTTP: if (strict && SLASH != ch) settings.RaiseOnError(this, "unexpected char", data, p_err); state = State.req_first_http_major; break; /* first digit of major HTTP version */ case State.req_first_http_major: if (!isDigit(ch)) settings.RaiseOnError(this, "non digit in http major", data, p_err); http_major = (int)ch - 0x30; state = State.req_http_major; break; /* major HTTP version or dot */ case State.req_http_major: if (DOT == ch) { state = State.req_first_http_minor; break; } if (!isDigit(ch)) settings.RaiseOnError(this, "non digit in http major", data, p_err); http_major *= 10; http_major += (int)ch - 0x30; if (http_major > 999) settings.RaiseOnError(this, "ridiculous http major", data, p_err); break; /* first digit of minor HTTP version */ case State.req_first_http_minor: if (!isDigit(ch)) settings.RaiseOnError(this, "non digit in http minor", data, p_err); http_minor = (int)ch - 0x30; state = State.req_http_minor; break; case State.req_http_minor: if (ch == CR) { state = State.req_line_almost_done; break; } if (ch == LF) { state = State.header_field_start; break; } /* XXX allow spaces after digit? */ if (!isDigit(ch)) settings.RaiseOnError(this, "non digit in http minor", data, p_err); http_minor *= 10; http_minor += (int)ch - 0x30; if (http_minor > 999) settings.RaiseOnError(this, "ridiculous http minor", data, p_err); break; /* end of request line */ case State.req_line_almost_done: { if (ch != LF) settings.RaiseOnError(this, "missing LF after request line", data, p_err); state = State.header_field_start; break; } /******************* HTTP 1.1 *******************/ /******************* Header *******************/ case State.header_field_start: { if (ch == CR) { state = State.headers_almost_done; break; } if (ch == LF) { /* they might be just sending \n instead of \r\n so this would be * the second \n to denote the end of headers*/ state = State.headers_almost_done; if (!headers_almost_done(ch, settings)) settings.RaiseOnError(this, "header not properly completed", data, p_err); break; } c = upper(ch); if (c == 0) { settings.RaiseOnError(this, "invalid char in header", data, p_err); }; header_field_mark = p; index = 0; state = State.header_field; switch (c) { case C: header_state = HState.C; break; case P: header_state = HState.matching_proxy_connection; break; case T: header_state = HState.matching_transfer_encoding; break; case U: header_state = HState.matching_upgrade; break; default: header_state = HState.general; break; } break; } case State.header_field: { c = UPCASE[ch]; if (0 != c) { switch (header_state) { case HState.general: break; case HState.C: index++; header_state = (O == c ? HState.CO : HState.general); break; case HState.CO: index++; header_state = (N == c ? HState.CON : HState.general); break; case HState.CON: index++; switch (c) { case N: header_state = HState.matching_connection; break; case T: header_state = HState.matching_content_length; break; default: header_state = HState.general; break; } break; /* connection */ case HState.matching_connection: index++; if (index > CONNECTION.Length || c != CONNECTION[index]) { header_state = HState.general; } else if (index == CONNECTION.Length-1) { header_state = HState.connection; } break; /* proxy-connection */ case HState.matching_proxy_connection: index++; if (index > PROXY_CONNECTION.Length || c != PROXY_CONNECTION[index]) { header_state = HState.general; } else if (index == PROXY_CONNECTION.Length-1) { header_state = HState.connection; } break; /* content-length */ case HState.matching_content_length: index++; if (index > CONTENT_LENGTH.Length || c != CONTENT_LENGTH[index]) { header_state = HState.general; } else if (index == CONTENT_LENGTH.Length-1) { header_state = HState.content_length; } break; /* transfer-encoding */ case HState.matching_transfer_encoding: index++; if (index > TRANSFER_ENCODING.Length || c != TRANSFER_ENCODING[index]) { header_state = HState.general; } else if (index == TRANSFER_ENCODING.Length-1) { header_state = HState.transfer_encoding; } break; /* upgrade */ case HState.matching_upgrade: index++; if (index > UPGRADE.Length || c != UPGRADE[index]) { header_state = HState.general; } else if (index == UPGRADE.Length-1) { header_state = HState.upgrade; } break; case HState.connection: case HState.content_length: case HState.transfer_encoding: case HState. upgrade: if (SPACE != ch) header_state = HState.general; break; default: settings.RaiseOnError(this, "Unknown Header State", data, p_err); break; } // switch: header_state break; } // 0 != c if (COLON == ch) { settings.RaiseOnHeaderField(this, data, header_field_mark, p-header_field_mark); header_field_mark = -1; state = State.header_value_start; break; } if (CR == ch) { state = State.header_almost_done; settings.RaiseOnHeaderField(this, data, header_field_mark, p-header_field_mark); header_field_mark = -1; break; } if (ch == LF) { settings.RaiseOnHeaderField(this, data, header_field_mark, p-header_field_mark); header_field_mark = -1; state = State.header_field_start; break; } settings.RaiseOnError(this, "invalid header field", data, p_err); break; } case State.header_value_start: { if (SPACE == ch) break; header_value_mark = p; state = State.header_value; index = 0; c = UPCASE[ch]; if (c == 0) { if (CR == ch) { settings.RaiseOnHeaderValue(this, data, header_value_mark, p-header_value_mark); header_value_mark = -1; header_state = HState.general; state = State.header_almost_done; break; } if (LF == ch) { settings.RaiseOnHeaderValue(this, data, header_value_mark, p-header_value_mark); header_value_mark = -1; state = State.header_field_start; break; } header_state = HState.general; break; } switch (header_state) { case HState.upgrade: flags |= F_UPGRADE; header_state = HState.general; break; case HState.transfer_encoding: /* looking for 'Transfer-Encoding: chunked' */ if (C == c) { header_state = HState.matching_transfer_encoding_chunked; } else { header_state = HState.general; } break; case HState.content_length: if (!isDigit(ch)) { settings.RaiseOnError(this, "Content-Length not numeric", data, p_err); } content_length = (int)ch - 0x30; break; case HState.connection: /* looking for 'Connection: keep-alive' */ if (K == c) { header_state = HState.matching_connection_keep_alive; /* looking for 'Connection: close' */ } else if (C == c) { header_state = HState.matching_connection_close; } else { header_state = HState.general; } break; default: header_state = HState.general; break; } break; } // header value start case State.header_value: { c = UPCASE[ch]; if (c == 0) { if (CR == ch) { settings.RaiseOnHeaderValue(this, data, header_value_mark, p-header_value_mark); header_value_mark = -1; state = State.header_almost_done; break; } if (LF == ch) { settings.RaiseOnHeaderValue(this, data, header_value_mark, p-header_value_mark); header_value_mark = -1; if (!header_almost_done(ch)) { settings.RaiseOnError(this,"incorrect header ending, expection LF", data, p_err); } break; } break; } switch (header_state) { case HState.general: break; case HState.connection: case HState.transfer_encoding: settings.RaiseOnError(this, "Shouldn't be here", data, p_err); break; case HState.content_length: if (ch == ' ') break; if (!isDigit(ch)) settings.RaiseOnError(this, "Content-Length not numeric", data, p_err); content_length *= 10; content_length += (int)ch - 0x30; break; /* Transfer-Encoding: chunked */ case HState.matching_transfer_encoding_chunked: index++; if (index > CHUNKED.Length || c != CHUNKED[index]) { header_state = HState.general; } else if (index == CHUNKED.Length-1) { header_state = HState.transfer_encoding_chunked; } break; /* looking for 'Connection: keep-alive' */ case HState.matching_connection_keep_alive: index++; if (index > KEEP_ALIVE.Length || c != KEEP_ALIVE[index]) { header_state = HState.general; } else if (index == KEEP_ALIVE.Length-1) { header_state = HState.connection_keep_alive; } break; /* looking for 'Connection: close' */ case HState.matching_connection_close: index++; if (index > CLOSE.Length || c != CLOSE[index]) { header_state = HState.general; } else if (index == CLOSE.Length-1) { header_state = HState.connection_close; } break; case HState.transfer_encoding_chunked: case HState.connection_keep_alive: case HState.connection_close: if (SPACE != ch) header_state = HState.general; break; default: state = State.header_value; header_state = HState.general; break; } break; } // header_value case State.header_almost_done: if (!header_almost_done(ch)) settings.RaiseOnError(this,"incorrect header ending, expection LF", data, p_err); break; case State.headers_almost_done: if (!headers_almost_done(ch, settings)) settings.RaiseOnError(this, "header not properly completed", data, p_err); break; /******************* Header *******************/ /******************* Body *******************/ case State.body_identity: to_read = min(pe - p, content_length); //TODO change to use buffer? if (to_read > 0) { settings.RaiseOnBody(this, data, p, to_read); data.Position = p+to_read; content_length -= to_read; if (content_length == 0) { settings.RaiseOnMessageComplete(this); state = new_message(); } } break; case State.body_identity_eof: to_read = pe - p; // TODO change to use buffer ? if (to_read > 0) { settings.RaiseOnBody(this, data, p, to_read); data.Position = p+to_read; } break; /******************* Body *******************/ /******************* Chunk *******************/ case State.chunk_size_start: if (0 == (flags & F_CHUNKED)) settings.RaiseOnError(this, "not chunked", data, p_err); c = UNHEX[ch]; if (c == -1) { Console.WriteLine ("THE CHAR: '{0}'", (char) ch); settings.RaiseOnError(this, "invalid hex char in chunk content length", data, p_err); } content_length = c; state = State.chunk_size; break; case State.chunk_size: if (0 == (flags & F_CHUNKED)) settings.RaiseOnError(this, "not chunked", data, p_err); if (CR == ch) { state = State.chunk_size_almost_done; break; } c = UNHEX[ch]; if (c == -1) { if (SEMI == ch || SPACE == ch) { state = State.chunk_parameters; break; } Console.WriteLine ("THE CHAR: '{0}'", (char) ch); settings.RaiseOnError(this, "invalid hex char in chunk content length", data, p_err); } content_length *= 16; content_length += c; break; case State.chunk_parameters: if (0 == (flags & F_CHUNKED)) settings.RaiseOnError(this, "not chunked", data, p_err); /* just ignore this shit. TODO check for overflow */ if (CR == ch) { state = State.chunk_size_almost_done; break; } break; case State.chunk_size_almost_done: if (0 == (flags & F_CHUNKED)) { settings.RaiseOnError(this, "not chunked", data, p_err); } if (strict && LF != ch) { settings.RaiseOnError(this, "expected LF at end of chunk size", data, p_err); } if (0 == content_length) { flags |= F_TRAILING; state = State.header_field_start; } else { state = State.chunk_data; } break; case State.chunk_data: { if (0 == (flags & F_CHUNKED)) { settings.RaiseOnError(this, "not chunked", data, p_err); } to_read = min(pe-p, content_length); if (to_read > 0) { settings.RaiseOnBody(this, data, p, to_read); data.Position = p+to_read; } if (to_read == content_length) { state = State.chunk_data_almost_done; } content_length -= to_read; break; } case State.chunk_data_almost_done: if (0 == (flags & F_CHUNKED)) { settings.RaiseOnError(this, "not chunked", data, p_err); } if (strict && CR != ch) { settings.RaiseOnError(this, "chunk data terminated incorrectly, expected CR", data, p_err); } state = State.chunk_data_done; break; case State.chunk_data_done: if (0 == (flags & F_CHUNKED)) { settings.RaiseOnError(this, "not chunked", data, p_err); } if (strict && LF != ch) { settings.RaiseOnError(this, "chunk data terminated incorrectly, expected LF", data, p_err); } state = State.chunk_size_start; break; /******************* Chunk *******************/ default: settings.RaiseOnError(this, "unhandled state", data, p_err); break; } // switch } // while p = (int) data.Position; /* Reaching this point assumes that we only received part of a * message, inform the callbacks about the progress made so far*/ settings.RaiseOnHeaderField (this, data, header_field_mark, p-header_field_mark); settings.RaiseOnHeaderValue (this, data, header_value_mark, p-header_value_mark); settings.RaiseOnFragment (this, data, fragment_mark, p-fragment_mark); settings.RaiseOnQueryString (this, data, query_string_mark, p-query_string_mark); settings.RaiseOnPath (this, data, path_mark, p-path_mark); settings.RaiseOnUrl (this, data, url_mark, p-url_mark); }
public static IBalanceParser Get(ParserType type) { switch (type) { case ParserType.GjExcel: return new Parsers.GjExcelParserShoes(); } throw new NotImplementedException("No Parser is defined for type: " + type); }
private string GetNameByParserType(ParserType Type) { switch (Type) { case ParserType.Page: return Resources.PageParser; case ParserType.Item: return Resources.ItemParser; case ParserType.Npc: return Resources.NpcDataParser; case ParserType.NpcLocale: return Resources.NpcLocaleParser; case ParserType.Quest: return Resources.QuestDataParser; case ParserType.QuestLocale: return Resources.QuestLocaleParser; case ParserType.Trainer: return Resources.TrainerParser; case ParserType.Vendor: return Resources.VendorParser; default: throw new InvalidOperationException(Type.ToString()); } }
/// <summary> /// Initializes a new instance of the <see cref="ParserModel"/> using the specified models and head rules without manifest information entries. /// </summary> /// <param name="languageCode">The language code.</param> /// <param name="buildModel">The model to assign constituent labels.</param> /// <param name="checkModel">The model to determine a constituent is complete.</param> /// <param name="attachModel">The attach model.</param> /// <param name="parserTagger">The model to assign pos-tags.</param> /// <param name="chunkerTagger">The model to assign flat constituent labels.</param> /// <param name="headRules">The head rules.</param> /// <param name="modelType">Type of the model.</param> /// <exception cref="System.ArgumentException"> /// If the <paramref name="modelType"/> is equal to <see cref="Parser.ParserType.Chunking"/> the <paramref name="attachModel"/> must be <c>null</c>. /// or /// If the <paramref name="modelType"/> is equal to <see cref="Parser.ParserType.TreeInsert"/> the <paramref name="attachModel"/> must not be <c>null</c>. /// </exception> /// <exception cref="ArgumentOutOfRangeException"> /// Unknown <paramref name="modelType"/> value. /// </exception> public ParserModel( string languageCode, IMaxentModel buildModel, IMaxentModel checkModel, IMaxentModel attachModel, POSModel parserTagger, ChunkerModel chunkerTagger, AbstractHeadRules headRules, ParserType modelType) : this( languageCode, buildModel, checkModel, attachModel, parserTagger, chunkerTagger, headRules, modelType, null) { }
public ParserAttribute(ParserType type) { Type = type; }
static public string Reformat(ParserNode node, string input, ParserType parserType) { switch (parserType) { case ParserType.HTML: return HTMLVisitor.Format(node, input); case ParserType.JSON: return JSONVisitor.Format(node, input); case ParserType.XML: return XMLVisitor.Format(node, input); default: throw new Exception("Unable to reformat this type"); } }