Beispiel #1
0
        private static void SampleTwo(string[] args)
        {
            var argThings = new ArgsActions();

            argThings.SetOption("-a", () => Console.WriteLine("-a option selected"));
            argThings.SetOption("-e", () => Console.WriteLine("-e option selected"));

            var processor = new ArgsProcessor(argThings);

            processor.Process(args);
        }
Beispiel #2
0
        public static void  Test()
        {
            //实际上就是一种表驱动编程方法的实践
            Console.WriteLine("【委托的使用,字典的使用,以及[,]多维操作符的自定义】");
            ArgsActions aas = new ArgsActions();
            DoAction    da  = new DoAction();
            Action      a1  = da.PrintAdd;
            Action      a2  = da.PrintMod;

            aas.SetOption("add", a1);
            aas.SetOption("mod", a2);
            ArgsProcessor ap = new ArgsProcessor(aas);

            ap.Process(new string[] { "add", "mod" });
        }
Beispiel #3
0
            internal static void TestCorrectness()
            {
                ArgsProcessor ap = new ArgsProcessor();

                ap.Process(
                    new string[] { "cc", "-o", "test", "test.c", "-h", "-O3", "--verbose", "test.cc.log" },
                    new string[] { "-o", "--verbose" },
                    new string[] { "/h", "-h", "-O3" });

                foreach (var item in ap.PlainArgs)
                {
                    Console.Write(item + " ");
                }
                Console.WriteLine();
                foreach (var item in ap.MapArgs)
                {
                    Console.Write(item + " ");
                }
                Console.WriteLine();
                foreach (var item in ap.SwitchArgs)
                {
                    Console.Write(item + " ");
                }
                Console.WriteLine();
                Console.WriteLine();

                ap.Process(
                    new string[] { },
                    new string[] { "-o", "--verbose" });

                foreach (var item in ap.PlainArgs)
                {
                    Console.Write(item + " ");
                }
                Console.WriteLine();
                foreach (var item in ap.MapArgs)
                {
                    Console.Write(item + " ");
                }
                Console.WriteLine();
                foreach (var item in ap.SwitchArgs)
                {
                    Console.Write(item + " ");
                }
                Console.WriteLine();
                Console.WriteLine();

                ap.Process(null);
                foreach (var item in ap.PlainArgs)
                {
                    Console.Write(item + " ");
                }
                Console.WriteLine();
                foreach (var item in ap.MapArgs)
                {
                    Console.Write(item + " ");
                }
                Console.WriteLine();
                foreach (var item in ap.SwitchArgs)
                {
                    Console.Write(item + " ");
                }
                Console.WriteLine();
                Console.WriteLine();

                ap.Process(
                    new string[] { "cc", "-o", "test", "test.c", "-h", "-O3", "--verbose", "test.cc.log" },
                    switchs: new string[] { "/h", "-h", "-O3" });
                foreach (var item in ap.PlainArgs)
                {
                    Console.Write(item + " ");
                }
                Console.WriteLine();
                foreach (var item in ap.MapArgs)
                {
                    Console.Write(item + " ");
                }
                Console.WriteLine();
                foreach (var item in ap.SwitchArgs)
                {
                    Console.Write(item + " ");
                }
                Console.WriteLine();
                Console.WriteLine();
            }
Beispiel #4
0
        internal static void Handle(RawBrowserMessageEnvelop envelop)
        {
            //Log.Debug("Type: " + envelop.MessageType);
            if (envelop.MessageType == "videoIds")
            {
                foreach (var item in envelop.VideoIds)
                {
                    ApplicationContext.VideoTracker.AddVideoDownload(item);
                }
                return;
            }

            if (envelop.MessageType == "clear")
            {
                ApplicationContext.VideoTracker.ClearVideoList();
                return;
            }

            if (envelop.MessageType == "sync")
            {
                return;
            }

            if (envelop.MessageType == "custom")
            {
                var args = ArgsProcessor.ParseArgs(envelop.CustomData.Split('\r'));
                ArgsProcessor.Process(args);
                return;
            }

            var rawMessage = envelop.Message;

            if (rawMessage == null && envelop.Messages == null)
            {
                Log.Debug("Raw message/messages is null");
                return;
            }
            ;

            switch (envelop.MessageType)
            {
            case "download":
            {
                var message = Parse(rawMessage);
                if (!(Helpers.IsBlockedHost(message.Url) || Helpers.IsCompressedJSorCSS(message.Url)))
                {
                    ApplicationContext.CoreService.AddDownload(message);
                }
                break;
            }

            case "links":
            {
                var messages = new List <Message>(envelop.Messages.Length);
                foreach (var msg in envelop.Messages)
                {
                    var message = Parse(msg);
                    messages.Add(message);
                }
                ApplicationContext.CoreService.AddBatchLinks(messages);
                break;
            }

            case "video":
            {
                var message     = Parse(rawMessage);
                var contentType = message.GetResponseHeaderFirstValue("Content-Type");

                if (VideoUrlHelper.IsYtFormat(contentType))
                {
                    VideoUrlHelper.ProcessPostYtFormats(message);
                }

                //if (VideoUrlHelper.IsFBFormat(contentType, message.Url))
                //{
                //    VideoUrlHelper.ProcessPostFBFormats(message, ApplicationContext.Core);
                //}

                if (VideoUrlHelper.IsHLS(contentType))
                {
                    VideoUrlHelper.ProcessHLSVideo(message);
                }

                if (VideoUrlHelper.IsDASH(contentType))
                {
                    VideoUrlHelper.ProcessDashVideo(message);
                }

                if (!VideoUrlHelper.ProcessYtDashSegment(message))
                {
                    if (VideoUrlHelper.IsNormalVideo(contentType, message.Url, message.GetContentLength()))
                    {
                        VideoUrlHelper.ProcessNormalVideo(message);
                    }
                }
                break;
            }
            }
        }
Beispiel #5
0
            internal static void TestCorrectness() {
                ArgsProcessor ap = new ArgsProcessor();
                ap.Process(
                    new string[] { "cc", "-o", "test", "test.c", "-h", "-O3", "--verbose", "test.cc.log" },
                    new string[] { "-o", "--verbose" },
                    new string[] { "/h", "-h", "-O3" });

                foreach (var item in ap.PlainArgs) {
                    Console.Write(item + " ");
                }
                Console.WriteLine();
                foreach (var item in ap.MapArgs) {
                    Console.Write(item + " ");
                }
                Console.WriteLine();
                foreach (var item in ap.SwitchArgs) {
                    Console.Write(item + " ");
                }
                Console.WriteLine();
                Console.WriteLine();

                ap.Process(
                    new string[] { },
                    new string[] { "-o", "--verbose" });

                foreach (var item in ap.PlainArgs) {
                    Console.Write(item + " ");
                }
                Console.WriteLine();
                foreach (var item in ap.MapArgs) {
                    Console.Write(item + " ");
                }
                Console.WriteLine();
                foreach (var item in ap.SwitchArgs) {
                    Console.Write(item + " ");
                }
                Console.WriteLine();
                Console.WriteLine();

                ap.Process(null);
                foreach (var item in ap.PlainArgs) {
                    Console.Write(item + " ");
                }
                Console.WriteLine();
                foreach (var item in ap.MapArgs) {
                    Console.Write(item + " ");
                }
                Console.WriteLine();
                foreach (var item in ap.SwitchArgs) {
                    Console.Write(item + " ");
                }
                Console.WriteLine();
                Console.WriteLine();

                ap.Process(
                    new string[] { "cc", "-o", "test", "test.c", "-h", "-O3", "--verbose", "test.cc.log" },
                    switchs: new string[] { "/h", "-h", "-O3" });
                foreach (var item in ap.PlainArgs) {
                    Console.Write(item + " ");
                }
                Console.WriteLine();
                foreach (var item in ap.MapArgs) {
                    Console.Write(item + " ");
                }
                Console.WriteLine();
                foreach (var item in ap.SwitchArgs) {
                    Console.Write(item + " ");
                }
                Console.WriteLine();
                Console.WriteLine();
            }