Пример #1
0
        /// <summary>
        /// 解析新浪视频视频文件源地址
        /// </summary>
        public ParseResult Parse(ParseRequest request)
        {
            ParseResult pr = new ParseResult();
            //合并完整url
            string url = @"http://v.iask.com/v_play.php?vid=" + request.Id;
            string source = Network.GetHtmlSource(url, Encoding.UTF8, request.Proxy);
            //视频总长度
            string totallength = Regex.Match(source, @"<timelength>(?<timelength>\d+)</timelength>").Groups["timelength"].Value;
            //Framecount
            string framecount = Regex.Match(source, @"<framecount>(?<framecount>\d+)</framecount>").Groups["framecount"].Value;
            //src
            string src = Regex.Match(source, @"<src>(?<src>\d+)</src>").Groups["src"].Value;

            pr.SpecificResult.Add("totallength", totallength);
            pr.SpecificResult.Add("framecount", framecount);
            pr.SpecificResult.Add("src", src);

            //vstr
            string vstr = Regex.Match(source, @"(?<=<vstr><!\[CDATA\[)\w+").Value;

            //视频信息
            Regex r = new Regex(@"<durl>.+?<order>(?<order>\d+)</order>.+?<length>(?<length>\d+)</length>.+?<url><!\[CDATA\[(?<url>.+?)\]\]></url>.+?</durl>", RegexOptions.Singleline);
            MatchCollection matches = r.Matches(source);
            foreach (Match item in matches)
            {
                var pri = new ParseResultItem();
                pri.RealAddress = new Uri(item.Groups["url"].Value +
                    (string.IsNullOrEmpty(vstr) ? "" : "?vstr=" + vstr));
                pri.Information.Add("order", item.Groups["order"].Value);
                pri.Information.Add("length", item.Groups["length"].Value);
                pr.Items.Add(pri);
            }
            //返回结果
            return pr;
        }
Пример #2
0
        /// <summary>
        /// 解析任意视频源地址
        /// </summary>
        public ParseResult Parse(ParseRequest request)
        {
            //返回值
            ParseResult pr = new ParseResult();
            //分辨率
            string resolution = request.SpecificConfiguration.ContainsKey("resolution") ? request.SpecificConfiguration["resolution"] : "";
            //修正url
            string url = "http://www.flvcd.com/parse.php?kw=" + Tools.UrlEncode(request.Id) + resolution;

            //取得网页源文件
            string src = Network.GetHtmlSource(url, Encoding.GetEncoding("GB2312"), request.Proxy);

            //检查是否需要密码
            if (src.Contains("请输入密码"))
            {
                url = url + "&passwd=" + request.Password;
                src = Network.GetHtmlSource(url, Encoding.GetEncoding("GB2312"), request.Proxy);
            }

            //取得内容
            Regex rContent = new Regex("<input type=\"hidden\" name=\"inf\".+\">", RegexOptions.Singleline);
            Match mContent = rContent.Match(src);
            string content = mContent.Value;

            //取得各Part下载地址
            List<string> partUrls = new List<string>();
            Regex rPartUrls = new Regex(@"<U>(?<url>.+)");
            MatchCollection mcPartUrls = rPartUrls.Matches(content);
            foreach (Match item in mcPartUrls)
            {
                pr.Items.Add(new ParseResultItem() { RealAddress = new Uri(item.Groups["url"].Value) });
            }
            return pr;
        }
Пример #3
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////
        // OBJECT
        /////////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Initializes an instance of the <c>MainControl</c> class.
        /// </summary>
        public MainControl()
        {
            InitializeComponent();

            // Register display item classification types (so breakpoint indicator styles are registered)
            new DisplayItemClassificationTypeProvider().RegisterAll();

            // Set the header/footer text to make the editor work as a method body
            editor.Document.SetHeaderAndFooterText("using System; using System.Diagnostics; using System.IO; private class Program { private void Execute() {\r\n", "\r\n}}");

            //
            // NOTE: Make sure that you've read through the add-on language's 'Getting Started' topic
            //   since it tells you how to set up an ambient parse request dispatcher and an ambient
            //   code repository within your application OnStartup code, and add related cleanup in your
            //   application OnExit code.  These steps are essential to having the add-on perform well.
            //

            // Initialize the project assembly (enables support for automated IntelliPrompt features)
            projectAssembly = new CSharpProjectAssembly("SampleBrowser");
            var assemblyLoader = new BackgroundWorker();

            assemblyLoader.DoWork += DotNetProjectAssemblyReferenceLoader;
            assemblyLoader.RunWorkerAsync();

            // Load the .NET Languages Add-on C# language and register the project assembly on it
            var language = new CSharpSyntaxLanguage();

            language.RegisterProjectAssembly(projectAssembly);

            // Register an indicator quick info provider
            language.RegisterService(new IndicatorQuickInfoProvider());

            // Register an event sink that allows for handling of clicks in the indicator margin
            language.RegisterService(new DebuggingPointerInputEventSink());

            // Assign the language
            editor.Document.Language = language;

            this.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, (DispatcherOperationCallback) delegate(object arg) {
                // Since we are initializing some default breakpoints, make sure the document parse completes in the worker thread first
                AmbientParseRequestDispatcherProvider.Dispatcher.WaitForParse(ParseRequest.GetParseHashKey(editor.Document));

                // Add some indicators (this is dispatched since this sample relies on the document's AST being available and parsing occurs asynchronously)
                DebuggingHelper.ToggleBreakpoint(new TextSnapshotOffset(editor.ActiveView.CurrentSnapshot, editor.ActiveView.CurrentSnapshot.Lines[19].StartOffset), true);
                DebuggingHelper.ToggleBreakpoint(new TextSnapshotOffset(editor.ActiveView.CurrentSnapshot, editor.ActiveView.CurrentSnapshot.Lines[23].StartOffset), false);
                DebuggingHelper.ToggleBreakpoint(new TextSnapshotOffset(editor.ActiveView.CurrentSnapshot, editor.ActiveView.CurrentSnapshot.Lines[28].StartOffset), true);
                return(null);
            }, null);
        }
Пример #4
0
 internal void HandleQuickInfoResponse(ParseRequest req)
 {
     if (req.Line == this.quickInfoLine && req.Col == this.quickInfoIdx)
     {
         if (req.Scope == null)
         {
             this.quickInfoText = null;
         }
         else
         {
             this.quickInfoText = req.Scope.GetDataTipText(req.Line, req.Col, out this.quickInfoSpan);
         }
         this.gotQuickInfo = true;
     }
 }
 public void CheckRandomExmaple()
 {
     input = new List <string>()
     {
         "name=",             // 1 nodes; 2 ways
         "wikipedia",         // 1 nodes; 1 way
         "route_master=tram", // 0 nodes 1 way
         "tram_stop=yes"      // 1 nodes 0 way
     };
     results = new ParseRequest(input);
     Assert.AreEqual(new OSMTag("name"), results.Requests[0]);
     Assert.AreEqual(new OSMTag("wikipedia"), results.Requests[1]);
     Assert.AreEqual(new OSMTag("route_master", "tram"), results.Requests[2]);
     Assert.AreEqual(new OSMTag("tram_stop", "yes"), results.Requests[3]);
 }
Пример #6
0
        public async Task <IActionResult> ParseWebSite([FromBody] ParseRequest request)
        {
            if (!Uri.TryCreate(request.Url, UriKind.Absolute, out var uri))
            {
                return(new BadRequestObjectResult(request.Url));
            }

            var options = new Options(request.ParsingRules,
                                      request.ContentValidationRules, request.ResponseValidationRules);

            var result = await _mediator.Send(new ParseWebSiteRequest(uri,
                                                                      request.MaxDepth == 0 ? 1 : request.MaxDepth, options));

            return(new OkObjectResult(result));
        }
Пример #7
0
 /// <summary>Runs the code.</summary>
 /// <param name="result">The parse result.</param>
 /// <param name="request">The parse request.</param>
 /// <returns>The await handle</returns>
 private static async Task RunCode(ParseResult result, ParseRequest request)
 {
     try
     {
         var scriptOptions = ScriptOptions.Default;
         scriptOptions = scriptOptions.AddReferences(typeof(TemplateService).Assembly);
         scriptOptions = scriptOptions.AddReferences(typeof(Dictionary <string, string>).Assembly);
         scriptOptions = scriptOptions.AddImports("System", "RazorEngineSandbox.Data", "System.Collections.Generic");
         //scriptOptions.all
         result.Model = await CSharpScript.EvaluateAsync(request.Code, scriptOptions);
     }
     catch (CompilationErrorException e)
     {
         result.CodeDiagnostics = e.Message;
     }
 }
Пример #8
0
        public async Task <IActionResult> Run(
            [HttpTrigger(
                 "post",
                 Route = Routes.ExportZip
                 )] ParseRequest data
            )
        {
            try
            {
                var(kml, mode) = data;

                kmlParser.Options.Mode = mode;

                var parsedKml    = kmlParser.ParseKml(kml);
                var exportStream = await zipper.Zip(
                    new[] {
        public void GotoTest()
        {
            // This method is not implemented, so the only check is that it does not
            // crashes and that returns null.
            ParseRequest request = new ParseRequest(false);

            request.Reason = ParseReason.DisplayMemberList;
            AuthoringScope scope = ConsoleAuthoringScope.CreateScope(request);

            Assert.IsNotNull(scope);
            TextSpan span;

            Assert.IsNull(scope.Goto(
                              Microsoft.VisualStudio.VSConstants.VSStd97CmdID.ClearPane,
                              null, 0, 0, out span));
        }
        public void TestParse_IncorrectPassword()
        {
            var testFile = TestFiles.PasswordProtected;
            var options  = new ParseOptions
            {
                FileInfo     = testFile.ToFileInfo(),
                TemplatePath = "templates/document-template.json",
                Template     = GetTemplate()
            };

            options.FileInfo.Password = "******";
            var request = new ParseRequest(options);
            var ex      = Assert.Throws <ApiException>(() => { ParseApi.Parse(request); });

            Assert.AreEqual($"Password provided for file '{testFile.FullName}' is incorrect.", ex.Message);
        }
Пример #11
0
        /// <summary>
        /// Factory function for the scope.
        /// </summary>
        public static ConsoleAuthoringScope CreateScope(ParseRequest request)
        {
            if (null == request)
            {
                return(null);
            }
            ConsoleAuthoringScope scope = null;

            if (request.Reason == ParseReason.MemberSelect ||
                request.Reason == ParseReason.DisplayMemberList ||
                request.Reason == ParseReason.CompleteWord)
            {
                scope = new ConsoleAuthoringScope();
            }
            return(scope);
        }
Пример #12
0
        private static CMakeItemDeclarations CreateSubcommandDeclarations(
            CMakeCommandId id, ParseRequest req, Source source,
            List <string> priorParameters)
        {
            IEnumerable <string> subcommands = CMakeSubcommandMethods.GetSubcommands(id);

            if (subcommands == null)
            {
                return(null);
            }

            CMakeItemDeclarations decls = new CMakeItemDeclarations();

            decls.AddItems(subcommands, CMakeItemDeclarations.ItemType.Command);
            return(decls);
        }
Пример #13
0
        public override AuthoringScope ParseSource(ParseRequest req)
        {
            Debug.Print("ParseSource at ({0}:{1}), reason {2}", req.Line, req.Col, req.Reason);
            var source = (LightSource)this.GetSource(req.FileName);

            switch (req.Reason)
            {
            case ParseReason.Check:
                var parsed = ParseAndProcess(req.Text);
                if (parsed.Messages.Count > 0)
                {
                    foreach (var message in parsed.Messages)
                    {
                        var span = new TextSpan();
                        span.iStartLine  = span.iEndLine = message.Location.Line;
                        span.iStartIndex = message.Location.Column - 1;
                        span.iEndIndex   = message.Location.Column;
                        req.Sink.AddError(req.FileName, message.Text, span, Severity.Error);
                    }
                }
                source.Parsed = parsed;
                break;

            case ParseReason.DisplayMemberList:
                // Parse the line specified in req.Line for the two
                // tokens just before req.Col to obtain the identifier
                // and the member connector symbol.
                // Examine existing parse tree for members of the identifier
                // and return a list of members in your version of the
                // Declarations class as stored in the AuthoringScope
                // object.
                break;

            case ParseReason.MethodTip:
                // Parse the line specified in req.Line for the token
                // just before req.Col to obtain the name of the method
                // being entered.
                // Examine the existing parse tree for all method signatures
                // with the same name and return a list of those signatures
                // in your version of the Methods class as stored in the
                // AuthoringScope object.
                break;
            }

            return(new LightAuthoringScope(source.Parsed != null ? source.Parsed.Root : null));
        }
Пример #14
0
 /// <summary>Runs the template.</summary>
 /// <param name="result">The parse result.</param>
 /// <param name="request">The parse request.</param>
 private void RunTemplate(ParseResult result, ParseRequest request)
 {
     if (result.Model != null)
     {
         try
         {
             Type modelType = result.Model.GetType() == typeof(Bestellung) ? typeof(Bestellung) : null;
             var  name      = request.Template.GetHashCode().ToString("X");
             this.service.Compile(request.Template, name, modelType);
             result.Value = this.service.Run(name, modelType, result.Model);
         }
         catch (Exception e)
         {
             result.TemplateDiagnostics = e.Message;
         }
     }
 }
        public void TestParse_SavedTemplate()
        {
            var templatePath = "templates/document-template.json";
            var template     = new CreateTemplateOptions()
            {
                Template     = GetTemplate(),
                TemplatePath = templatePath
            };
            var templateRequest = new CreateTemplateRequest(template);

            var resultTemplate = TemplateApi.CreateTemplate(templateRequest);

            Assert.IsNotNull(resultTemplate);

            var testFile = TestFiles.TemplateDocumentDocx;

            var options = new ParseOptions
            {
                FileInfo     = testFile.ToFileInfo(),
                TemplatePath = templatePath
            };
            var request = new ParseRequest(options);
            var result  = ParseApi.Parse(request);

            Assert.IsNotNull(result);
            Assert.IsNotEmpty(result.FieldsData);
            Assert.AreEqual(4, result.Count);

            var dataFieldNames = new[] { "FIELD1", "RELATEDFIELD2", "REGEX", "TABLECELLS" };

            foreach (var field in result.FieldsData)
            {
                Assert.IsTrue(dataFieldNames.Contains(field.Name));
            }

            var table = result.FieldsData.First(x => string.Equals(x.Name, "TABLECELLS")).PageArea.PageTableArea;

            if (table != null)
            {
                Assert.AreEqual(4, table.ColumnCount);
                Assert.AreEqual(3, table.RowCount);
                Assert.AreEqual(
                    "Cell 12",
                    table.PageTableAreaCells.First(x => x.ColumnIndex == 2 && x.RowIndex == 1).PageArea.PageTextArea.Text);
            }
        }
Пример #16
0
        public async Task <IActionResult> Parse(
            bool?json,
            [FromBody] ParseRequest request,
            [FromHeader(Name = ApiKeyHeader)] string key)
        {
            if (request is null ||
                string.IsNullOrWhiteSpace(request.Data))
            {
                return(BadRequest("Empty"));
            }

            var api = context.Apis
                      .Include(a => a.User)
                      .First(a => a.Key.Equals(key));

            if (!restriction.IsAllowedTimeout(api))
            {
                return(StatusCode(429, "Timeout"));
            }

            if (!restriction.IsAllowedSize(api, request.Data.Length))
            {
                return(StatusCode(413, "Size"));
            }

            api.LastUsed = DateTime.Now;

            var parseResult = await parseAsync.ParseAsync(request.Data);

            if (json == true)
            {
                parseResult = JsonConvert.SerializeXNode(XElement.Parse(parseResult));
            }

            context.Conversions.Add(new Conversion
            {
                Initial = compress.Compress(request.Data),
                Result  = compress.Compress(parseResult),
                Type    = json == true ? ParseType.Json : ParseType.Xml,
                Time    = api.LastUsed,
                UserId  = api.UserId,
            });
            await context.SaveChangesAsync();

            return(Content(parseResult, json == true ? ContentTypeJson : ContentTypeXml));
        }
Пример #17
0
        public static void Run()
        {
            var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
            var apiInstance   = new ParseApi(configuration);

            try
            {
                var options = new ParseOptions
                {
                    FileInfo = new FileInfo {
                        FilePath = "containers/archive/companies.zip", StorageName = Common.MyStorage
                    },
                    ContainerItemInfo = new ContainerItemInfo {
                        RelativePath = "companies.docx"
                    },
                    Template = TemplateUtils.GetTemplate()
                };

                var request = new ParseRequest(options);

                var response = apiInstance.Parse(request);

                foreach (var data in response.FieldsData)
                {
                    if (data.PageArea.PageTextArea != null)
                    {
                        Console.WriteLine($"Field name: {data.Name}. Text : {data.PageArea.PageTextArea.Text}");
                    }

                    if (data.PageArea.PageTableArea != null)
                    {
                        Console.WriteLine($"Table name: {data.Name}.");

                        foreach (var cell in data.PageArea.PageTableArea.PageTableAreaCells)
                        {
                            Console.WriteLine(
                                $"Table cell. Row {cell.RowIndex} column {cell.ColumnIndex}. Text: {cell.PageArea.PageTextArea.Text}");
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception while calling ParseApi: " + e.Message);
            }
        }
Пример #18
0
        async IAsyncEnumerable <ParsedImage> IImageParsingStrategy.ParseAsync(ParseRequest request, IProgress <ParseProgress> progress)
        {
            var collection = await Task.FromResult(new ParsedImage[]
            {
                new ParsedImage
                {
                    Category = Category,
                    Image    = Image.FromFile(_options.WarmupImagePath),
                    Keyword  = Keyword
                }
            });

            foreach (var image in collection)
            {
                yield return(image);
            }
        }
Пример #19
0
        public override AuthoringScope ParseSource(ParseRequest req)
        {
            if (null == req)
            {
                throw new ArgumentNullException("req");
            }
            Debug.Print("ParseSource at ({0}:{1}), reason {2}", req.Line, req.Col, req.Reason);
            PythonSource source = null;

            if (specialSources.TryGetValue(req.View, out source) && (null != source.ScopeCreator))
            {
                return(source.ScopeCreator(req));
            }
            PythonSink sink = new PythonSink(req.Sink);

            return(new PythonScope(modules.AnalyzeModule(sink, req.FileName, req.Text), this));
        }
        public static void Run()
        {
            // For example purposes create template if not exists.
            TemplateUtils.CreateIfNotExist("templates/companies.json");

            var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
            var apiInstance   = new ParseApi(configuration);

            try
            {
                var options = new ParseOptions
                {
                    FileInfo = new FileInfo {
                        FilePath = "words-processing/docx/companies.docx", StorageName = Common.MyStorage
                    },
                    TemplatePath = "templates/companies.json"
                };

                var request = new ParseRequest(options);

                var response = apiInstance.Parse(request);

                foreach (var data in response.FieldsData)
                {
                    if (data.PageArea.PageTextArea != null)
                    {
                        Console.WriteLine($"Field name: {data.Name}. Text : {data.PageArea.PageTextArea.Text}");
                    }

                    if (data.PageArea.PageTableArea != null)
                    {
                        Console.WriteLine($"Table name: {data.Name}.");

                        foreach (var cell in data.PageArea.PageTableArea.PageTableAreaCells)
                        {
                            Console.WriteLine(
                                $"Table cell. Row {cell.RowIndex} column {cell.ColumnIndex}. Text: {cell.PageArea.PageTextArea.Text}");
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception while calling ParseApi: " + e.Message);
            }
        }
        public override AuthoringScope ParseSource(ParseRequest req)
        {
            if (req == null)
            {
                return(null);
            }

            var scope = new CQLAuthoringScope();

            req.Scope = scope;

            if (req.Reason == ParseReason.Check)
            {
            }

            if (m_scanner != null && req.Reason == ParseReason.MemberSelect || req.Reason == ParseReason.MemberSelectAndHighlightBraces && req.TokenInfo != null)
            {
                var token = m_scanner.GetToken(req.TokenInfo.Token);

                if (token != null)
                {
                    if (token.Type == 4)                     // [
                    {
                        scope.AddDeclaration(new CQLDeclaration("Encounter", 0, "An encounter with the patient"));
                        scope.AddDeclaration(new CQLDeclaration("Procedure", 0, "A procedure"));
                        scope.AddDeclaration(new CQLDeclaration("Medication", 0, "A medication"));
                    }

                    if (token.Type == 3)                     // ,
                    {
                        scope.AddDeclaration(new CQLDeclaration("Performed", 0, "An action performed"));
                        scope.AddDeclaration(new CQLDeclaration("Proposed", 0, "An action performed"));
                        scope.AddDeclaration(new CQLDeclaration("Ordered", 0, "An action performed"));
                    }

                    if (token.Type == 5)                     // :
                    {
                        scope.AddDeclaration(new CQLDeclaration("\"Inpatient\"", 0, "Inpatient encounter"));
                        scope.AddDeclaration(new CQLDeclaration("\"Outpatient\"", 0, "Outpatient encounter"));
                        scope.AddDeclaration(new CQLDeclaration("\"Face-to-face Interaction\"", 0, "Face-to-face interaction"));
                    }
                }
            }

            return(scope);
        }
        public void CreateScopeTest()
        {
            Assert.IsNull(ConsoleAuthoringScope.CreateScope(null));

            ParseRequest request = new ParseRequest(false);

            request.Reason = ParseReason.None;
            Assert.IsNull(ConsoleAuthoringScope.CreateScope(request));

            request.Reason = ParseReason.MemberSelect;
            Assert.IsNotNull(ConsoleAuthoringScope.CreateScope(request));

            request.Reason = ParseReason.HighlightBraces;
            Assert.IsNull(ConsoleAuthoringScope.CreateScope(request));

            request.Reason = ParseReason.MemberSelectAndHighlightBraces;
            Assert.IsNull(ConsoleAuthoringScope.CreateScope(request));

            request.Reason = ParseReason.MatchBraces;
            Assert.IsNull(ConsoleAuthoringScope.CreateScope(request));

            request.Reason = ParseReason.Check;
            Assert.IsNull(ConsoleAuthoringScope.CreateScope(request));

            request.Reason = ParseReason.CompleteWord;
            Assert.IsNotNull(ConsoleAuthoringScope.CreateScope(request));

            request.Reason = ParseReason.DisplayMemberList;
            Assert.IsNotNull(ConsoleAuthoringScope.CreateScope(request));

            request.Reason = ParseReason.QuickInfo;
            Assert.IsNull(ConsoleAuthoringScope.CreateScope(request));

            request.Reason = ParseReason.MethodTip;
            Assert.IsNull(ConsoleAuthoringScope.CreateScope(request));

            request.Reason = ParseReason.Autos;
            Assert.IsNull(ConsoleAuthoringScope.CreateScope(request));

            request.Reason = ParseReason.CodeSpan;
            Assert.IsNull(ConsoleAuthoringScope.CreateScope(request));

            request.Reason = ParseReason.Goto;
            Assert.IsNull(ConsoleAuthoringScope.CreateScope(request));
        }
Пример #23
0
        /// <summary>Runs the template.</summary>
        /// <param name="result">The parse result.</param>
        /// <param name="request">The parse request.</param>
        private string RunTemplate(Match match, ParseRequest request, ParseResult result)
        {
            if (!result.IsValid)
            {
                return(match.Value);
            }

            try
            {
                return(this.service.Run(request.Name, modelType, match));
            }
            catch (Exception e)
            {
                result.IsValid          = false;
                result.RazorDiagnostics = e.Message;
            }

            return(match.Value);
        }
Пример #24
0
        public async Task <LightDocument> Process(ParseRequest request)
        {
            if (splitter == null)
            {
                log.LogInformation("Constructing NEW {0} splitter...", id);
                Interlocked.Exchange(ref current, 0);
                splitter = factory();
            }

            LightDocument result = await splitter.Process(request).ConfigureAwait(false);

            if (Interlocked.Increment(ref current) >= maxProcessing)
            {
                splitter.Dispose();
                splitter = null;
            }

            return(result);
        }
Пример #25
0
        private ParseResult RunRegex(ParseResult result, ParseRequest request, Func <Match, ParseRequest, ParseResult, string> matchEvaluation)
        {
            if (!result.IsValid)
            {
                return(result);
            }

            try
            {
                result.Value = Regex.Replace(request.Input, request.RegExPattern, m => matchEvaluation(m, request, result));
            }
            catch (Exception e)
            {
                result.IsValid          = false;
                result.RegExDiagnostics = e.Message;
            }

            return(result);
        }
        public void GetDeclarationsNullView()
        {
            // Create the authoring scope.
            ParseRequest request = new ParseRequest(false);

            request.Reason = ParseReason.DisplayMemberList;
            AuthoringScope scope = ConsoleAuthoringScope.CreateScope(request);

            Assert.IsNotNull(scope);

            // Create a mock IConsoleText
            BaseMock mockConsoleText = MockFactories.ConsoleTextFactory.GetInstance();

            mockConsoleText.AddMethodReturnValues(
                string.Format("{0}.{1}", typeof(IConsoleText).FullName, "TextOfLine"),
                new object[] { "dte." });
            ConsoleAuthoringScope.PythonConsole = mockConsoleText as IConsoleText;

            // Creeate a TokenInfo
            TokenInfo tokenInfo = new TokenInfo();

            // Call GetDeclarations.
            bool exceptionThrown = false;

            try
            {
                scope.GetDeclarations(null, 0, 0, tokenInfo, ParseReason.DisplayMemberList);
            }
            catch (ArgumentNullException)
            {
                exceptionThrown = true;
            }
            catch (System.Reflection.TargetInvocationException e)
            {
                ArgumentNullException inner = e.InnerException as ArgumentNullException;
                if (null != inner)
                {
                    exceptionThrown = true;
                }
            }
            Assert.IsTrue(exceptionThrown);
        }
Пример #27
0
        private static CMakeItemDeclarations CreateSourceDeclarations(CMakeCommandId id,
                                                                      ParseRequest req, Source source, List <string> priorParameters)
        {
            CMakeSourceDeclarations decls = new CMakeSourceDeclarations(req.FileName);

            decls.FindIncludeFiles();
            if (_commandKeywords.ContainsKey(id))
            {
                decls.AddItems(_commandKeywords[id],
                               CMakeItemDeclarations.ItemType.Command);
            }
            if (id == CMakeCommandId.AddExecutable || id == CMakeCommandId.AddLibrary)
            {
                // Exclude all files that already appear in the parameter list, except
                // for the first token, which is the name of the executable to be
                // generated.
                decls.ExcludeItems(priorParameters.Skip(1));
            }
            return(decls);
        }
Пример #28
0
        private ParseResult CompileTemplate(ParseResult result, ParseRequest request)
        {
            if (!result.IsValid)
            {
                return(result);
            }

            try
            {
                request.Name = request.Template.GetHashCode().ToString("X");
                this.service.Compile(request.Template, request.Name, modelType);
            }
            catch (Exception e)
            {
                result.IsValid          = false;
                result.RazorDiagnostics = e.Message;
            }

            return(result);
        }
Пример #29
0
        public void ParseWaysGivenDoubleKeyViaXMLReader()
        {
            var query = new OSMTag("addr:street", "Swanston Street");
            var test  = new ParseRequest(new List <OSMTag>()
            {
                query
            });
            var results = fetchResultsViaXMLReader(OSMXMLs, test, OSMGeometryType.Way);

            Assert.AreEqual(2, CountWaysForMetaData(results, query));

            var rawQuery = new List <string>()
            {
                "addr:street=Swanston Street"
            };

            test    = new ParseRequest(rawQuery);
            results = fetchResultsViaXMLReader(OSMXMLs, test, OSMGeometryType.Way);
            Assert.AreEqual(2, CountWaysForMetaData(results, query));
        }
Пример #30
0
 /// <summary>
 /// 解析QQ视频源地址
 /// </summary>
 public ParseResult Parse(ParseRequest request)
 {
     ParseResult pr = new ParseResult();
     //完整url
     string url = @"http://vv.video.qq.com/geturl?ran=0.16436194255948067&otype=xml&vid=%ID%&platform=1&format=2".Replace(@"%ID%", request.Id);
     string xmldoc = Network.GetHtmlSource(url, Encoding.UTF8, request.Proxy);
     Regex r = new Regex(@"\<url\>(?<url>.*?)\</url\>");
     MatchCollection mc = r.Matches(xmldoc);
     if (mc.Count != 0)
     {
         foreach (Match item in mc)
         {
             pr.Items.Add(new ParseResultItem() { RealAddress = new Uri(item.Groups[@"url"].Value) });
         }
         return pr;
     }
     else
     {
         pr.Items.Add(new ParseResultItem() { RealAddress = new Uri(@"http://web.qqvideo.tc.qq.com/" + request.Id + ".flv") });
         return pr;
     }
 }
Пример #31
0
        private static CMakeItemDeclarations CreateSetPropertyDeclarations(
            CMakeCommandId id, ParseRequest req, Source source,
            List <string> priorParameters)
        {
            CMakeItemDeclarations decls = null;
            int propertyIndex           = priorParameters.IndexOf("PROPERTY");

            if (propertyIndex < 0)
            {
                CMakePropertyType type = CMakeProperties.GetPropertyTypeFromKeyword(
                    priorParameters[0]);
                if (_propObjMethods.ContainsKey(type) &&
                    !priorParameters.Any(x => _setPropertyKeywords.Contains(x)))
                {
                    decls = _propObjMethods[type](id, req, source, priorParameters);
                }
                else
                {
                    decls = new CMakeItemDeclarations();
                }
                if (priorParameters.Count > 1 || type == CMakePropertyType.Global)
                {
                    decls.AddItems(_setPropertyKeywords,
                                   CMakeItemDeclarations.ItemType.Command);
                }
                decls.ExcludeItems(priorParameters.Skip(1));
            }
            else if (propertyIndex == priorParameters.Count - 1)
            {
                CMakePropertyType type = CMakeProperties.GetPropertyTypeFromKeyword(
                    priorParameters[0]);
                IEnumerable <string> properties = CMakeProperties.GetPropertiesOfType(
                    type);
                decls = new CMakeItemDeclarations();
                decls.AddItems(properties, CMakeItemDeclarations.ItemType.Property);
            }
            return(decls);
        }
Пример #32
0
        private static Babel.Parser.Parser ParseText(string text, bool trace = false)
        {
            Babel.Parser.ErrorHandler handler = new Babel.Parser.ErrorHandler();
            Babel.Lexer.Scanner       scanner = new Babel.Lexer.Scanner();
            Babel.Parser.Parser       parser  = new Babel.Parser.Parser(); // use noarg constructor
            parser.Trace    = trace;
            parser.scanner  = scanner;
            scanner.Handler = handler;
            parser.SetHandler(handler);
            scanner.SetSourceText(text);

            var request = new ParseRequest(true);

            request.Sink = new AuthoringSink(ParseReason.None, 0, 0, Babel.Parser.Parser.MaxErrors);
            parser.MBWInit(request);
            var result = parser.Parse();

            if (handler.Errors)
            {
                throw new Exception(handler.ToString());
            }
            return(parser);
        }
Пример #33
0
        public IActionResult Run(
            [HttpTrigger(
                 "post",
                 Route = Routes.Parse
                 )] ParseRequest data
            )
        {
            try
            {
                var(kml, mode) = data;

                kmlParser.Options.Mode = mode;

                return(LogOkObject(new
                {
                    ParsedKml = kmlParser.ParseKml(kml)
                }));
            }
            catch (Exception ex)
            {
                return(LogException(ex));
            }
        }
Пример #34
0
        /// <summary>
        /// 解析土豆视频
        /// </summary>
        /// <remarks>接受的AutoAnswer对象需要以<i>tudou</i>作为前缀</remarks>
        public ParseResult Parse(ParseRequest request)
        {
            ParseResult pr = new ParseResult();
            int t;
            if(!int.TryParse(request.Id,out t)) //测试iid是否是真实的(应该为数字)
            {
                //取得土豆网页面源代码
                string tudousource = Network.GetHtmlSource("http://www.tudou.com/programs/view/" + request.Id + "/", Encoding.GetEncoding("GB2312"), request.Proxy);
                //取得iid
                Regex r1 = new Regex(@"(I|i)id = (?<iid>\d.*)");
                Match m1 = r1.Match(tudousource);
                request.Id = m1.Groups["iid"].ToString();
            }

            string xmlurl = @"http://v2.tudou.com/v?st=1%2C2%2C3%2C4%2C99&it=" + request.Id + "&pw=" + request.Password;
            string xmldoc = Network.GetHtmlSource(xmlurl, Encoding.UTF8, request.Proxy);
            Regex rVideo = new Regex("<f [^>]+brt=\"(?<brt>\\d+)\">(?<url>[^<]+)</f>");
            MatchCollection mcVideo = rVideo.Matches(xmldoc);

            //默认url
            string defaultUrl = "";

            //将 数字-清晰度 存入到字典中
            var resolutiondict = new Dictionary<string, string>();
            resolutiondict.Add("1", "流畅 256P");
            resolutiondict.Add("2", "清晰 360P");
            resolutiondict.Add("3", "高清 720P");
            //resolutiondict.Add("4", "高清 1080P");
            resolutiondict.Add("99", "原画");

            //将 清晰度-地址 存入到字典中
            var videodict = new Dictionary<string, string>();
            foreach (Match item in mcVideo)
            {
                string brt = item.Groups["brt"].Value;
                string url = item.Groups["url"].Value;
                if (string.IsNullOrEmpty(defaultUrl))
                    defaultUrl = url;
                if (resolutiondict.ContainsKey(brt))
                {
                    brt = resolutiondict[brt];
                }
                if (!videodict.ContainsValue(brt)) //不覆盖已有的 清晰度-地址 对
                    videodict.Add(url, brt);
            }

            //自动应答
            if (request.AutoAnswers.Count > 0)
            {
                string answer;
                foreach (var item in request.AutoAnswers)
                {
                    if (item.Prefix == "tudou")
                    {
                        if (resolutiondict.ContainsKey(item.Identify)) //如果自动应答设置中有"1"/"2"/"3"/"99"
                        {
                            answer = resolutiondict[item.Identify]; //取得描述(如"流畅 256P")
                            foreach (var u in videodict.Keys) //从字典中查找描述信息所属的URL
                            {
                                if (videodict[u].Equals(answer))
                                {
                                    pr.Items.Add(new ParseResultItem(new Uri(u)));
                                    return pr;
                                }
                            }
                        }
                    }
                }
            }

            string urladdress;
            //只在视频清晰度数量多余1个时进行选择
            if (videodict.Count > 1)
            {
                urladdress = ToolForm.CreateSingleSelectForm("请选择视频清晰度:", videodict, defaultUrl, request.AutoAnswers, "tudou");

                //DEBUG
                //全都加到结果集里
                /*foreach (var item in videodict)
                {
                    pr.Items.Add(new ParseResultItem(new Uri(item.Key)));
                }*/
            }
            else //如果只有一个清晰度,不进行选择
            {
                urladdress = defaultUrl;

                //DEBUG
                //pr.Items.Add(new ParseResultItem(new Uri(urladdress)));
            }

            pr.Items.Add(new ParseResultItem(new Uri(urladdress)));
            return pr;
        }
Пример #35
0
        /// <summary>
        /// 解析优酷视频源文件地址
        /// </summary>
        ///<remarks>自动应答会检查前缀为<i>youku</i>的所有设置</remarks>
        public ParseResult Parse(ParseRequest request)
        {
            ParseResult pr = new ParseResult();
            string urlpre = @"http://v.youku.com/player/getPlayList/VideoIDS/%ID%/timezone/+08/version/5/source/video?n=3&ran=4656&password=%PW%";
            string url = urlpre.Replace(@"%ID%", request.Id).Replace(@"%PW%", request.Password);
            string xmldoc = Network.GetHtmlSource(url, Encoding.UTF8, request.Proxy);
            //选择语言
            Regex rLang = new Regex(@"(?<=""audiolang"":\[).+?(?=\])");
            Match mLang = rLang.Match(xmldoc);
            if (mLang.Success) //如果存在多种语言
            {
                string langs = mLang.Value;
                Regex rLanguage = new Regex(@"""lang"":""(?<lang>.+?)"",""vid"":""(?<vid>.+?)""");
                MatchCollection mcLanguages = rLanguage.Matches(langs);
                Dictionary<string, string> langDict = new Dictionary<string, string>();
                foreach (Match mLanguage in mcLanguages)
                {
                    langDict.Add(mLanguage.Groups["vid"].Value, Tools.ReplaceUnicode2Str(mLanguage.Groups["lang"].Value));
                }
                //string chosenId = ToolForm.CreateSingleSelectForm("您正在下载的视频有多种语言版本,请选择语言:", langDict, "", request.AutoAnswers, "youku");
                string chosenId = "";
                foreach (KeyValuePair<string, string> kvp in langDict)
                {
                    chosenId = kvp.Key;
                    break;
                }
                request.Id = chosenId;
                url = urlpre.Replace(@"%ID%", request.Id).Replace(@"%PW%", request.Password);
                xmldoc = Network.GetHtmlSource(url, Encoding.UTF8, request.Proxy);
            }

            //正则表达式提取各个参数
            string regexstring = "\"seed\":(?<seed>\\w+),.+\"key1\":\"(?<key1>\\w+)\",\"key2\":\"(?<key2>\\w+)\".+\"streamfileids\":{\"(?<fileposfix>\\w+)\":\"(?<fileID>[0-9\\*]+)";
            Regex r = new Regex(regexstring);
            Match m = r.Match(xmldoc);
            //提取参数
            double seed = Double.Parse(m.Groups["seed"].Value);
            string key1 = m.Groups["key1"].Value;
            string key2 = m.Groups["key2"].Value;

            //提取各视频参数
            Regex rStreamFileIds = new Regex(@"""streamfileids"":{(?<fileids>.+?)}");
            Match mStreamFileIds = rStreamFileIds.Match(xmldoc);
            string fileIds = mStreamFileIds.Groups["fileids"].Value;

            var dict = new Dictionary<string, string>();
            string defaultres = "";
            //是否有超清模式
            if (fileIds.Contains("hd2"))
            {
                dict.Add("hd2", "超清(hd2)");
                defaultres = "hd2";
            }
            //是否有高清模式
            if (fileIds.Contains("mp4"))
            {
                dict.Add("mp4", "高清(mp4)");
                defaultres = "mp4";
            }
            //是否有普通清晰度
            if (fileIds.Contains("flv"))
            {
                dict.Add("flv", "标清(flv)");
                defaultres = "flv";
            }

            string fileposfix = null;
            string strSelect = null;

            //自动应答
            if (request.AutoAnswers.Count > 0)
            {
                foreach (var item in request.AutoAnswers)
                {
                    if (item.Prefix == "youku")
                    {
                        if (fileIds.Contains(item.Identify))
                        {
                            strSelect = item.Identify;
                            fileposfix = item.Identify;
                            break;
                        }
                    }
                }
            }

            if (string.IsNullOrEmpty(fileposfix))
            {
                //如果多余一种清晰度
                if (dict.Count > 1)
                {
                    fileposfix = ToolForm.CreateSingleSelectForm("您正在下载优酷视频,请选择视频清晰度:", dict, defaultres, request.AutoAnswers, "youku");
                }
                else
                {
                    fileposfix = defaultres;
                }
                strSelect = fileposfix;
            }

            //修正高清
            if (fileposfix == "hd2") fileposfix = "flv";

            //取得FileID
            Regex rFileID = new Regex(@"""" + strSelect + @""":""(?<fileid>.+?)""");
            Match mFileID = rFileID.Match(fileIds);
            string fileID = mFileID.Groups["fileid"].Value;

            //提取视频个数
            int flv_no = 0;
            string regexFlvNo = @"""segs"":{""\w+"":\[(?<content>.+?)\]";
            Regex rn = new Regex(regexFlvNo);
            Match mn = rn.Match(xmldoc);
            char[] tmp_content = mn.Groups["content"].Value.ToCharArray();
            foreach (char item in tmp_content)
            {
                if (item == '{') flv_no++;
            }

            //提取key
            Regex rSegs = new Regex(@"segs"":{(?<segs>.+?)},""streamsizes");
            Match mSegs = rSegs.Match(xmldoc);
            string segs = mSegs.Groups["segs"].Value;
            Regex rSegsSub = new Regex(@"""" + strSelect + @""":\[(?<segssub>.+?)\]");
            Match mSegsSub = rSegsSub.Match(segs);
            string segssub = mSegsSub.Groups["segssub"].Value;

            string regexKey = @"""k"":""(?<k>\w+)"",""k2"":""(?<k2>\w+)""";
            MatchCollection mcKey = Regex.Matches(segssub, regexKey);
            List<string> keys = new List<string>();
            foreach (Match mKey in mcKey)
            {
                keys.Add("?K=" + mKey.Groups["k"].Value + ",k2:" + mKey.Groups["k2"].Value);
            }

            //生成sid
            string sid = genSid();
            //生成fileid
            string fileid = getFileID(fileID, seed);
            //生成key
            //string key = genKey(key1, key2);
            //添加各个地址
            List<string> lst = new List<string>();
            for (int i = 0; i < flv_no; i++)
            {
                //得到地址
                string u = "http://f.youku.com/player/getFlvPath/sid/" + sid + "_" + string.Format("{0:D2}", i) +
                    "/st/" + fileposfix + "/fileid/" + fileid.Substring(0, 8) + string.Format("{0:D2}", i)
                    + fileid.Substring(10) + keys[i];
                //添加地址
                pr.Items.Add(new ParseResultItem(new Uri(u)));
            }

            //提取各项详细信息
            MatchCollection mcSegs = Regex.Matches(segssub, @"{.+?}");
            for (int i = 0; i < mcSegs.Count; i++)
            {
                MatchCollection mcKeys = Regex.Matches(mcSegs[i].Value, @"""(?<key>\w+)"":""(?<value>\w+)""");
                foreach (Match mkey in mcKeys)
                {
                    string k = mkey.Groups["key"].Value;
                    string v = mkey.Groups["value"].Value;
                    //修正length和order
                    if (k.Equals("seconds"))
                    {
                        k = "length";
                        v = (Int32.Parse(v) * 1000).ToString();
                    }
                    if (k.Equals("no")) k = "order";
                    pr.Items[i].Information.Add(k, v);
                }
            }

            return pr;
        }
Пример #36
0
 public IAsyncResult BeginParse(ParseRequest request, ParseResultHandler handler);
Пример #37
0
 public virtual void OnParseComplete(ParseRequest req);
Пример #38
0
 public abstract AuthoringScope ParseSource(ParseRequest req);