Beispiel #1
0
        /// <summary>
        /// Starts (or reuses) the process resource that is specified by the <see cref="P:System.Diagnostics.Process.StartInfo" />
        /// property of this <see cref="T:System.Diagnostics.Process" /> component and associates it with the component.
        /// </summary>
        /// <returns>true if a process resource is started; false if no new process resource is started
        /// (for example, if an existing process is reused).</returns>
        /// <exception cref="T:System.InvalidOperationException">No file name was specified in the
        /// <see cref="T:System.Diagnostics.Process" /> component's <see cref="P:System.Diagnostics.Process.StartInfo" />.
        /// -or- The <see cref="P:System.Diagnostics.ProcessStartInfo.UseShellExecute" /> member of the
        /// <see cref="P:System.Diagnostics.Process.StartInfo" /> property is true while
        /// <see cref="P:System.Diagnostics.ProcessStartInfo.RedirectStandardInput" />,
        /// <see cref="P:System.Diagnostics.ProcessStartInfo.RedirectStandardOutput" />,
        /// or <see cref="P:System.Diagnostics.ProcessStartInfo.RedirectStandardError" /> is true.
        /// </exception>
        /// <exception cref="T:System.ComponentModel.Win32Exception">There was an error in opening the associated file. </exception>
        /// <exception cref="T:System.ObjectDisposedException">The process object has already been disposed. </exception>
        public virtual bool Start()
        {
            // temporary switch until code is proven to be stable.
            if (_enableCustomUserLogin)
            {
                if (!string.IsNullOrWhiteSpace(StartInfo.Arguments))
                {
                    throw new ArgumentException("StartInfo.Arguments is not allowed when starting a process as a user. use ArgumentObject.");
                }
            }

            bool successfulStart = false;

            if (_enableCustomUserLogin && StartInfo != null && !string.IsNullOrWhiteSpace(StartInfo.UserName))
            {
                using (Impersonator imp = new Impersonator())
                {
                    imp.Impersonate(StartInfo.UserName, StartInfo.Domain, StartInfo.Password, StartWithCreateProcessAsUser);
                    successfulStart = true;
                }
            }
            else
            {
                _process.StartInfo.Arguments = JsonConvert.SerializeObject(new
                {
                    name       = ArgumentObject["name"],
                    owner      = ArgumentObject["owner"],
                    parameters = ArgumentObject.ContainsKey("parameters") ? ArgumentObject["parameters"] : string.Empty
                });
                successfulStart = _process.Start();
            }

            return(successfulStart);
        }
Beispiel #2
0
        public Main(string[] arguments, int ti = -1, Action <int, string> u = null)
        {
            ArgumentObject args = new ArgumentObject(arguments);

            Restart :;
            if (args.arguments.mn == "nvl")
            {
                NovelDownload(args.arguments, ti, u);
            }
            else if (args.arguments.mn == "ani")
            {
                AnimeDownload(args.arguments, ti, u);
            }
            else
            {
                if (!searchMN(ref args))
                {
                    u?.Invoke(ti, "Error: could not parse command (Failure to parse website to ani/nvl flag.. you can retry with ani/nvl flag)");
                    ADLUpdates.CallError(new Exception("Error: Could not parse command (mn selector)"));
                    return;
                }
                else
                {
                    goto Restart;
                }
            }
        }
        /// <summary>
        /// Starts the application with the input provided by the user.
        /// </summary>
        /// <param name="sender">Object which initiated the event signal.</param>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        private void Start_Click(object sender, RoutedEventArgs e)
        {
            if (!this.stressManager.CurrentlyRunning)
            {
                this.stressManager.CurrentlyRunning = true;

                // Set OS Logging to true so debug prints are written to the output window of the
                // Visual Studio Debugger, or set to false to have debug prints written to an
                // alljoyn.log file in Documents Library
                AllJoyn.Debug.UseOSLogging(false);
                AllJoyn.Debug.SetDebugLevel("ALLJOYN", 7);
                AllJoyn.Debug.SetDebugLevel("ALLJOYN_OBJ", 7);

                // Get the input from the user
                ArgumentObject argObj = new ArgumentObject();
                argObj.NumOfIterations      = (uint)IterationSlider.Value;
                argObj.NumOfTasks           = (uint)TreadSlider.Value;
                argObj.StopThreadBeforeJoin = StopTreadsSwitch.IsOn;
                argObj.DeleteBusAttachments = DeleteBusSwitch.IsOn;
                argObj.IsMultipoint         = MultipointSwitch.IsOn;
                argObj.StressOperation      = (StressType)StressTypeComboBox.SelectedValue;

                if (!argObj.DeleteBusAttachments)
                {
                    argObj.NumOfIterations = 1;
                }

                this.stressManager.RunStressOperations(argObj);
            }
        }
Beispiel #4
0
        public IEnumerable <ProductCategoryObject> GetProductOrCategory(ArgumentObject args)
        {
            if (Debug)
            {
                Console.WriteLine(args.ToString());
            }
            foreach (var block in GetHtmlNode(args).SelectNodes(BlockExp))
            {
                yield return(new ProductCategoryObject(
                                 PropertiesCategory.ToDictionary(x => x.Key, x => x.Value(block, args)), isCategory: true));

                foreach (var reference in block._SelectNodes(block.XPath + RefProductExp))
                {
                    var arguments = new ArgumentObject(url: Url + reference.Attributes["href"].Value, args: args.Args);
                    if (Debug)
                    {
                        Console.WriteLine(arguments.ToString());
                    }
                    var node = GetHtmlNode(arguments);
                    //File.WriteAllText("tmp.html", node.InnerHtml);
                    yield return(new ProductCategoryObject(
                                     SinglePropertiesProduct.ToDictionary(x => x.Key, x => x.Value(node, arguments)),
                                     PluralPropertiesProduct.ToDictionary(x => x.Key, x => x.Value(node, arguments))));
                }
            }
        }
Beispiel #5
0
        public static ExtractorBase ResumeDownload(string mdataLock, int ti, Action <int, string> u)
        {
            int          guragura = 0;
            argumentList rawr;

            using (FileStream fs = new FileStream(mdataLock, FileMode.Open))
                using (ZipArchive zarch = new ZipArchive(fs, ZipArchiveMode.Read))
                {
                    using (StreamReader sw = new StreamReader(zarch.GetEntry("part").Open()))
                    {
                        guragura = int.Parse(sw.ReadLine());
                    }
                    using (StreamReader sw = new StreamReader(zarch.GetEntry("mDat").Open()))
                    {
                        rawr        = new ArgumentObject(sw.ReadLine().Split(' ')).arguments;
                        rawr.resume = true;
                    }
                }

            switch (rawr.term.SiteFromString())
            {
            case Site.HAnime: return(new HAnime(rawr, ti, u)
                {
                    m3uLocation = guragura
                });

            default: throw new NotImplementedException("Site is not implemented yet");
            }
        }
Beispiel #6
0
        public HtmlNode GetHtmlNode(ArgumentObject args)
        {
            var web = new HtmlWeb {
                OverrideEncoding = Encoding.Default
            };

            return(web.Load(args.Url).DocumentNode);
        }
Beispiel #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker bw = sender as BackgroundWorker;

            ArgumentObject arg = e.Argument as ArgumentObject;

            string        dir          = arg.dir;
            List <string> videoList    = arg.videoList;
            List <string> subtitleList = arg.subtitleList;

            int counter = 0;

            DirectoryInfo di = new DirectoryInfo(logdir);

            if (!di.Exists)
            {
                di.Create();
            }
            FileInfo fi = new FileInfo(logfile);

            if (!fi.Exists)
            {
                fi.Create();
                using (TextWriter writerr = new StreamWriter(logpath))
                {
                    writerr.WriteLine(separator);
                    writerr.WriteLine("Dátum: " + today);
                    writerr.WriteLine(separator);
                    writerr.WriteLine();
                }
            }

            FileStream fs = new FileStream(logpath, FileMode.Append, FileAccess.Write);

            writer = new StreamWriter(fs);

            writer.WriteLine(separator);
            writer.WriteLine("Idő: " + DateTime.Now.ToString("HH:mm:ss"));
            writer.WriteLine("Könyvtár: " + dir);
            writer.WriteLine(separator);
            writer.WriteLine();
            writer.WriteLine(separator);

            foreach (string videoName in videoList)
            {
                //Console.WriteLine("v: "+videoName);
                string subName = SearchForSubtitle(videoName, subtitleList, arg.ignoretitle);
                if (subName.Length != 0)
                {
                    //Console.WriteLine("sub: "+subName);
                    writeLog(subName, Rename(videoName, subName, dir));
                }
                //System.Threading.Thread.Sleep(100);
                bw.ReportProgress(counter++);
            }
        }
Beispiel #8
0
        private void ParseArgs(string[] x, int id)
        {
            ArgumentObject parsedArgs = ArgumentObject.Parse(x);

            if (parsedArgs.arguments.help)
            {
                PrintHelp();
                return;
            }
        }
Beispiel #9
0
        public static void Parse()
        {
            var parser = new LiquiMolyClass(
                isCategory: node => node
                ._SelectNodes(@"//div[@class='filter-block']")
                .Count != 0,
                findProducts: (node, args) => node
                ._SelectNodes(@"//*[@id='products_grid']/div/div/a")
                .Select(x => new ArgumentObject(x.Attributes["href"].Value))
                .ToArray(),
                singlePropertiesCategory: new Dictionary <string, Search <string> >
            {
                ["Наименование"] = (node, args) => node
                                   .SelectSingleNode(@"//ul[@class]/li[contains(@class, ""active"")]/a")
                                   .InnerText
            },
                singlePropertiesProduct: new Dictionary <string, Search <string> >
            {
                ["Наименование"] = (node, args) => node
                                   .SelectSingleNode(@"//h1")
                                   .InnerHtml,
                [@"""Код артикула"""] = (node, args) => node
                                        .SelectSingleNode(@"//*[@id='top']/div[6]/div[1]/div[2]/div[1]/span[2]")
                                        .InnerText,
                [@"Габариты"] = (node, args) => node
                                .SelectSingleNode(@"//*[@id='top']/div[6]/div[1]/div[2]/div[5]/span[2]")
                                .InnerText,
                [@"Цена"] = (node, args) => node
                            .SelectSingleNode(@"//*[@id='top']/div[6]/div[1]/div[2]/div[6]/a/span[1]")
                            .InnerText,
                [@"Описание"] = (node, args) => node
                                .SelectSingleNode(@"//*[@id='top']/div[6]/div[1]/div[2]/div[7]")
                                .InnerHtml +
                                string.Join("\n", node
                                            ._SelectNodes(@"//*[@id='top']/div[6]/div[1]/div[2]/div[position() > 1 and position() < last() - 1]")
                                            .Select(x => x.InnerHtml))
            },
                pluralPropertiesProduct: new Dictionary <string, Search <string[]> >
            {
                ["Изображения"] = (node, args) => node
                                  ._SelectNodes(@"//*[@id='top']/div[6]/div[1]/div[1]/div[1]/div/img")
                                  .Select(x => @"https://mdi-toys.ru" + x.Attributes["src"].Value)
                                  .ToArray()
            }
                );
            var arguments = new ArgumentObject(url: "https://mdi-toys.ru/catalog/",
                                               args: new object[] { 0 });
            var collection = parser.GetProductOrCategory(
                parser.GetLinks(arguments, @".//*[@id='top']/div[6]/div/div/ul[1]/li[position() > 1]/a"));

            Import.Write(path: "mdi-toys.csv",
                         collection: collection.ToArray(),
                         headers: Constants.WebAsystKeys,
                         format: Constants.WebAsystFormatter);
        }
Beispiel #10
0
        static void parg(string[] args, int id)
        {
            ArgumentObject parsedArgs = ArgumentObject.Parse(args);

            if (parsedArgs.arguments.help)
            {
                PrintHelp();
                return;
            }
            ADLCore.Interfaces.Main mn = new ADLCore.Interfaces.Main(parsedArgs, id, new Action <int, string>(UpdateTask));
        }
Beispiel #11
0
        public static void Parse()
        {
            var parser = new LiquiMolyClass(
                isCategory: node => node
                ._SelectNodes(@".//*[@id='appPartZoomCompprd1appPart1zvc_Zoom_ProductBundle__0_0_def_0']")
                .Count == 0,
                findProducts: (node, args) =>
            {
                var a = node
                        ._SelectNodes(@"//a[contains(@href, 'product')]");
                return(node
                       ._SelectNodes(@"//*[contains(@class,'pgg_cg1_galleryDisplayer')]/div/a")
                       .Select(x => new ArgumentObject(x.Attributes["href"].Value))
                       .ToArray());
            },
                singlePropertiesCategory: new Dictionary <string, Search <string> >
            {
                ["Наименование"] = (node, args) => "ТД-Дворики",
            },
                singlePropertiesProduct: new Dictionary <string, Search <string> >
            {
                ["Наименование"] = (node, args) => node
                                   .SelectSingleNode(@".//*[@id='appPartZoomCompprd1appPart1zvc_ZoomDetails_ProductBundle__0_0_2_titlerichTextContainer']/p")
                                   .InnerText,
                ["Описание"] = (node, args) => node
                               ?.SelectSingleNode(@".//*[@id='appPartZoomCompprd1appPart1zvc_ZoomDetails_ProductBundle__0_0_2_overviewrichTextContainer']/p")
                               ?.InnerHtml ?? String.Empty +
                               node
                               ?.SelectSingleNode(@".//*[@id='appPartZoomCompprd1appPart1zvc_ZoomDetails_ProductBundle__0_0_2_detailsrichTextContainer']/p")
                               ?.InnerHtml ?? String.Empty,
                ["Цена"] = (node, args) => node
                           .SelectSingleNode(@".//*[@id='appPartZoomCompprd1appPart1zvc_ZoomDetails_ProductBundle__0_0_2_pricerichTextContainer']/p")
                           .InnerText.Replace("руб.", String.Empty).Replace(",", String.Empty),
            },
                pluralPropertiesProduct: new Dictionary <string, Search <string[]> >
            {
                ["Изображения"] = (node, args) => node
                                  ._SelectNodes(@"//div[@class='s_xUSelectableSliderGalleryDefaultSkinimageItem']//img")
                                  .Select(x => x.Attributes["src"].Value)
                                  .Select(x => x.Substring(0, x.IndexOf("v1")))
                                  .ToArray()
            }
                );
            var argument = new ArgumentObject(
                url: @"http://www.td-dvoriki.com/toy-shop-cjg9",
                args: new object[] { 0 });

            var collection = parser.GetProductOrCategory(argument);

            Import.Write(path: "tddvoriki.csv",
                         collection: collection.ToArray(),
                         headers: Constants.WebAsystKeys,
                         format: Constants.WebAsystFormatter);
        }
Beispiel #12
0
        /// <summary>
        /// Outputs 'msg' to the text box in the UI of the application. We have to dispatch this to
        /// the UI thread.
        /// </summary>
        /// <param name="msg">Message that will be output in the text box of the UI.</param>
        public async void OutputLine(string msg)
        {
            ArgumentObject ao = new ArgumentObject();

            ao.TextBox = this.TextBlockSignalConsumer; // control in our Xaml page
            ao.Text    = msg + "\n";
            await Dispatcher.RunAsync(
                CoreDispatcherPriority.Normal,
                new DispatchedHandler(ao.OnDispatched));

            System.Diagnostics.Debug.WriteLine(msg);
        }
Beispiel #13
0
        private void backgroundWorkerMoveto_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker bw = sender as BackgroundWorker;

            ArgumentObject arg = e.Argument as ArgumentObject;

            allpath = new ArrayList();
            GetAllCheckedFolderPath(arg.TNC);

            string destpath = arg.Path;

            int counter = 0;


            foreach (string nodepath in allpath)
            {
                DirectoryInfo dir = new DirectoryInfo(nodepath);
                if (bw.CancellationPending == true)
                {
                    e.Cancel = true;
                    break;
                }
                try
                {
                    foreach (FileInfo file in dir.GetFiles())
                    {
                        bool finished = false;
                        foreach (object item in this.videoCheckedListBox.CheckedItems)
                        {
                            if (file.Extension.Equals("." + item.ToString()))
                            {
                                bw.ReportProgress(counter, file.Name);
                                finished = MoveTo(dir.FullName, destpath, file.Name);
                                continue;
                            }
                        }
                        if (finished)
                        {
                            //FileSystem.DeleteDirectory(dir.FullName, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin);
                            Console.WriteLine(file.Name + " has been deleted.");
                        }
                    }
                    counter++;
                }
                catch (IOException ex)
                {
                    MessageBox.Show(dir.Name + " device not ready", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            bw.ReportProgress(counter, "");
        }
Beispiel #14
0
        /// <summary>
        /// Outputs 'msg' to the text box in the UI of the application as well as the debug output
        /// console.
        /// </summary>
        /// <param name="msg">Message that will be output in the text box of the UI.</param>
        public void OutputLine(string msg)
        {
            // If this is attempted at OnNavigatedTo() time the result is null.
            this.GetScrollBar();

            string         timestampedMsg = DateTime.Now.ToString() + ": " + msg;
            ArgumentObject ao             = new ArgumentObject(timestampedMsg + "\n", this.textBoxOutput, this.Scrollbar);

            Dispatcher.RunAsync(
                CoreDispatcherPriority.Normal,
                new DispatchedHandler(ao.OnDispatched)).AsTask();

            System.Diagnostics.Debug.WriteLine(timestampedMsg);
        }
        /// <summary>
        /// Outputs 'msg' to the text box in the UI of the application
        /// </summary>
        /// <param name="msg">Message that will be output in the text box of the UI</param>
        /// <param name="completed">A value to indicate the file transfer has been completed.</param>
        public void OutputLine(string msg, bool completed = false)
        {
            if (completed)
            {
                this.ButtonRunClient.IsEnabled = true;
                this.BusObject = null;
            }

            ArgumentObject ao = new ArgumentObject();

            ao.TextBox = this.TextBlockClient;
            ao.Text    = msg + "\n";
            Dispatcher.RunAsync(
                CoreDispatcherPriority.Normal,
                new DispatchedHandler(ao.OnDispatched)).AsTask();
            System.Diagnostics.Debug.WriteLine(msg);
        }
Beispiel #16
0
        public static void Parse()
        {
            var alterna = new AlternaClass(
                blockExp: @"//div[contains(@class, ""level_2"")]/div[@class=""item""]",
                refProductExp: @"//div[@class=""uss_shop_name""]/a",
                singlePropertiesProduct: new Dictionary <string, Search <string> >
            {
                ["Изображения"] = (node, o) => node
                                  .SelectSingleNode(@"//a[@class=""enlarge_image_inside""]")
                                  .Attributes["href"].Value,
                ["Наименование"] = (node, o) => node
                                   .SelectSingleNode(@"//h1")
                                   .InnerText,
                ["Цена"] = (node, o) => node
                           .SelectSingleNode(@"//div[@class=""uss_shop_price""]/span")
                           .InnerText,
                ["Описание"] = (node, o) => node
                               .SelectSingleNode(@"//div[@class=""uss_shop_full_description""]")
                               .InnerHtml,
                ["Габариты"] = (node, o) => node
                               .SelectSingleNode(@"//div[@class=""uss_shop_technical_data""]/div[@class=""uss_shop_description""]")
                               .InnerText,
            },
                propertiesCategory: new Dictionary <string, Search <string> >
            {
                ["Наименование"] = (node, o) => new string('!', (int)o.Args[0]) + node
                                   .SelectSingleNode(node.XPath + @"//div[contains(@class, ""name"") and contains(@class, ""level_2"")]")
                                   .InnerText.Trim()
            });
            var arguments = new ArgumentObject(url: "http://xn--80aaoxlrm3f.xn--p1ai/store/13488/",
                                               args: new object[] { 1 });
            var collection = alterna.GetProductOrCategory(arguments);

            collection = new[]
            {
                new ProductCategoryObject(
                    new Dictionary <string, string> {
                    ["Наименование"] = "Мебель детская"
                }, isCategory: true)
            }.Extend(collection);
            Import.Write(path: "alterna.csv",
                         collection: collection.ToArray(),
                         headers: Constants.WebAsystKeys,
                         format: Constants.WebAsystFormatter);
        }
Beispiel #17
0
        public static ExtractorBase ResumeDownload(string mdataLock, int ti, Action <int, string> u)
        {
            int          guragura = 0;
            argumentList rawr;

            using (FileStream fs = new FileStream(mdataLock, FileMode.Open))
                using (ZipArchive zarch = new ZipArchive(fs, ZipArchiveMode.Read))
                {
                    using (StreamReader sw = new StreamReader(zarch.GetEntry("part").Open()))
                    {
                        guragura = int.Parse(sw.ReadLine());
                    }
                    using (StreamReader sw = new StreamReader(zarch.GetEntry("mDat").Open()))
                    {
                        rawr        = new ArgumentObject(sw.ReadLine().Split(' ')).arguments;
                        rawr.resume = true;
                    }
                }
            throw new Exception("Not implemented yet");
        }
Beispiel #18
0
        private bool searchMN(ref ArgumentObject args)
        {
            switch (args.arguments.term.SiteFromString())
            {
            case Site.HAnime: args[0] = "ani"; args[0] = "ani";  return(true);

            case Site.Vidstreaming: args[0] = args[0] = "ani"; return(true);

            case Site.ScribbleHub: args[0] = args[0] = "nvl"; return(true);

            case Site.wuxiaWorldA: args[0] = args[0] = "nvl"; return(true);

            case Site.wuxiaWorldB: args[0] = args[0] = "nvl"; return(true);

            case Site.NovelFull: args[0] = args[0] = "nvl"; return(true);

            default:
                return(false);
            }
        }
        public static void Parse()
        {
            var singlePropertiesProduct = new Dictionary <string, Search <string> >
            {
                ["Наименование"] = (node, args) => node
                                   .SelectSingleNode(@"//*[@id='wow']/div/h2")
                                   .InnerText,
                [@"""Код артикула"""] = (node, args) => node
                                        .SelectSingleNode(@"//*[@id='wow']/div/div[3]/p[1]/b")
                                        .InnerText,
                [@"Описание"] = (node, args) => node
                                .SelectSingleNode(@".//*[@id='hidetext']")
                                .InnerHtml
            };
            var parser = new AlternaClass(
                url: @"http://www.igrushka.perm.ru",
                blockExp: @"//div[contains(@class,'main_menu_sect')]",
                refProductExp: @"//menu/li/a",
                propertiesCategory: new Dictionary <string, Search <string> >
            {
                ["Наименование"] = (node, args) => node
                                   .InnerText
            },
                singlePropertiesProduct: singlePropertiesProduct,
                pluralPropertiesProduct: new Dictionary <string, Search <string[]> >
            {
                ["Изображения"] = (node, args) => node
                                  ._SelectNodes(@"//div[@id='slid_box']/img")
                                  .Select(x => "http://www.igrushka.perm.ru/toys/" + x.Attributes["src"].Value)
                                  .ToArray()
            }
                );
            var arguments = new ArgumentObject(url: "http://www.igrushka.perm.ru/toys/",
                                               args: new object[] { 0 });
            var collection = parser.GetProductOrCategory(arguments);

            Import.Write(path: "IgrushkaPerm.csv",
                         collection: collection.ToArray(),
                         headers: Constants.WebAsystKeys,
                         format: Constants.WebAsystFormatter);
        }
Beispiel #20
0
        private void ParseArgs(string[] x, int id)
        {
            ArgumentObject parsedArgs = new ArgumentObject(x);

            if (parsedArgs.arguments.help)
            {
                PrintHelp();
                return;
            }
            parsedArgs.arguments.l       = true;
            parsedArgs.arguments.android = true;
            if (parsedArgs.arguments.mn == "ani")
            {
                parsedArgs.arguments.export = rot + "/";
            }
            else
            {
                parsedArgs.arguments.export = rotNovelDir;
            }
            ADLCore.Interfaces.Main mn = new ADLCore.Interfaces.Main(parsedArgs, id, new Action <int, string>(UpdateTask));
        }
Beispiel #21
0
        public static void Parse()
        {
            var mainUrl = @"http://www.gratwest.ru";
            var singlePropertiesProduct = new Dictionary <string, Search <string> >
            {
                ["Наименование"] = (node, args) => node
                                   .SelectSingleNode(@"//h1")
                                   .InnerText.Trim(),
                [@"""Код артикула"""] = (node, args) => "GW-" + node
                                        .SelectSingleNode(@".//div[@class='clearfix' and count(child::div)=3]/div[2]/b[1]")
                                        .InnerText,
                ["Цена"] = (node, args) => node
                           .SelectSingleNode(@".//*[contains(@id,'ajax_div_')]/p[2]/nobr/span")
                           .InnerText.Replace("руб", string.Empty).Replace(" ", string.Empty),
                ["Размеры"] = (node, args) => node
                              .SelectSingleNode(@".//div[@class='clearfix' and count(child::div)=3]/div[2]/b[3]")
                              .InnerText,
                ["Валюта"] = (node, o) => "RUB",
                [@"""Доступен для заказа"""] = (node, o) => "1",
                [@"Статус"]  = (node, o) => "1",
                ["Описание"] = (node, args) => node
                               .SelectSingleNode(@".//*[@id='detail_dop_info']")
                               .InnerHtml +
                               node.SelectSingleNode(@".//table[@class='catalog-detail']")
                               .InnerHtml
            };

            singlePropertiesProduct["Заголовок"] =
                (node, args) => singlePropertiesProduct["Наименование"](node, args);
            singlePropertiesProduct[@"""Ссылка на витрину"""] = (node, args) =>
                                                                Humanization.GetHumanLink(singlePropertiesProduct["Наименование"](node, args)
                                                                                          + "-" + singlePropertiesProduct[@"""Код артикула"""](node, args));
            //singlePropertiesProduct[@"""Возраст детей"""] = (node, args) =>
            //    Regex.Match(singlePropertiesProduct["Описание"](node, args),
            //        @"Для\s+детей\s+от\s+\d+\s+лет",
            //        RegexOptions.IgnoreCase).Value;

            var parser = new LiquiMolyClass(
                isCategory: node => node
                ._SelectNodes(@"//*[@class='catalog-item-sorting']")
                .Count != 0,
                findProducts: (node, args) => node
                ._SelectNodes(@"//*[@class='catalog-item-title']/a")
                .Select(x => new ArgumentObject(mainUrl + x.Attributes["href"].Value))
                .ToArray(),
                singlePropertiesProduct: singlePropertiesProduct,
                singlePropertiesCategory: new Dictionary <string, Search <string> >
            {
                ["Наименование"] = (node, args) => new string('!', (int)args.Args[0]) + node
                                   .SelectSingleNode(@".//*[@id='breadcrumb']/span")
                                   .InnerText,
            },
                pluralPropertiesProduct: new Dictionary <string, Search <string[]> >
            {
                ["Изображения"] = (node, args) => node
                                  ._SelectNodes(@"//div[@class='clearfix' and count(child::div)=3]/div[1]//img")
                                  .Select(x => mainUrl + x.Attributes["src"].Value)
                                  .ToArray(),
            },
                encoding: Encoding.Default,
                xPathPagination: (node, args) => Enumerable.Range(2, 11)
                .Select(x =>
                        new ArgumentObject($"http://www.gratwest.ru/catalog/36355/?elcount=20&PAGEN_1={x}"))
                .ToArray()
                );
            var argument = new ArgumentObject(
                url: @"http://www.gratwest.ru/catalog/36355/",
                args: new object[] { 2 });
            var collection = parser.GetProductOrCategory(argument);

            collection = new[]
            {
                new ProductCategoryObject(
                    new Dictionary <string, string> {
                    ["Наименование"] = "Temporary2"
                }, isCategory: true),
                new ProductCategoryObject(
                    new Dictionary <string, string> {
                    ["Наименование"] = "!Gratwest"
                }, isCategory: true)
            }.Extend(collection);
            Import.Write(path: @"..\..\..\CSV\gratwest.csv",
                         collection: collection.ToArray(),
                         headers: Constants.WebAsystKeys,
                         format: Constants.WebAsystFormatter);
        }
Beispiel #22
0
        public static void Parse()
        {
            var random    = new Random();
            var URL       = @"http://www.geokont.ru";
            var badString = "НЕТ В НАЛИЧИИ";

            var singlePropertiesProduct = new Dictionary <string, Search <string> >
            {
                ["Наименование"] = (node, args) => node
                                   .SelectSingleNode(@"//*[@class='prodHead']/h3")
                                   .InnerText,
                ["Цена"] = (node, args) => {
                    var a = Regex.Replace(node
                                          .SelectSingleNode(@"//*[@class='prodCard'][2]/p[4]/text()")
                                          .InnerText, @"\s+", string.Empty);
                    return(a.Substring(0, a.Length - 7).Replace(" ", ""));
                },
                [@"""Код артикула"""] = (node, args) => "GEK",
                //[@"""Возраст детей"""] = (node, args) => {
                //    var a = Regex.Replace(node
                //        .SelectSingleNode(@"//*[@class='prodCard'][2]/p[2]")
                //        .InnerText, @"Возраст: ", string.Empty);
                //    return a;
                //},
                ["Описание"] = (node, args) =>
                {
                    var first = node
                                .SelectSingleNode(@"//*[@class='prodCard'][2]/p[1]/text()")
                                ?.InnerText.Replace(badString, string.Empty) ?? string.Empty;
                    var second = node
                                 .SelectSingleNode(@"//*[@class='prodCard'][2]/p[2]")
                                 .InnerText;

                    return(first + second);
                },
                ["Валюта"] = (node, o) => "RUB",
                [@"""Доступен для заказа"""] = (node, o) => "1",
                [@"Статус"] = (node, o) => "1",
            };

            singlePropertiesProduct["Заголовок"] =
                (node, args) => singlePropertiesProduct["Наименование"](node, args);
            singlePropertiesProduct[@"""Ссылка на витрину"""] = (node, args) =>
                                                                Humanization.GetHumanLink(singlePropertiesProduct["Наименование"](node, args) + "-GEK-" + random.Next());

            var parser = new LiquiMolyClass(
                isCategory: node => node
                ._SelectNodes(@"//*[@class='cardsPr']/div/*[@class='smallProdTbl']")
                .Count != 0,
                findProducts: (node, args) =>
            {
                var a = node
                        ._SelectNodes(@"//*[@class='container-fluid body-content']/div[last()]//td[@class='smProdHead']/a")
                        .Select(x => new ArgumentObject(URL + x.Attributes["href"].Value))
                        .ToArray();
                return(a);
            },
                singlePropertiesCategory: new Dictionary <string, Search <string> >
            {
                ["Наименование"] = (node, args) => {
                    var b = node.InnerText;
                    var a = new string('!', (int)args.Args[0]) +
                            Regex.Match(node.InnerHtml, @"<h2 class=""grpHead"">(.*?)</h2>", RegexOptions.Singleline).Groups[1].ToString().Trim();
                    return(a);
                }
            },
                singlePropertiesProduct: singlePropertiesProduct,
                pluralPropertiesProduct: new Dictionary <string, Search <string[]> >
            {
                ["Изображения"] = (node, args) => {
                    var a = node
                            ._SelectNodes(@"//a[@id='popupImg']")
                            .Select(x => URL + x.Attributes["href"].Value)
                            .ToArray();
                    return(a);
                }
            },
                encoding: Encoding.UTF8
                );

            var argument = new ArgumentObject(
                url: @"http://www.geokont.ru/ProductGroup/",
                args: new object[] { 2 });

            var collection =
                parser.GetProductOrCategory(parser.GetLinks(argument,
                                                            @"//*[@class='vBlock' and position() < last()]/a",
                                                            prefix: URL));

            collection = new[]
            {
                new ProductCategoryObject(
                    new Dictionary <string, string> {
                    ["Наименование"] = "Temporary2"
                }, isCategory: true),
                new ProductCategoryObject(
                    new Dictionary <string, string> {
                    ["Наименование"] = "!GeoCont"
                }, isCategory: true)
            }.Extend(collection);

            Import.Write(path: "../../../CSV/geoCont.csv",
                         collection: collection.ToArray(),
                         headers: Constants.WebAsystKeys,
                         format: Constants.WebAsystFormatter);
        }
Beispiel #23
0
        /////////////////////////////////////////////////////////////////////////////////

        private EXPR CreateArgumentListEXPR(
            ArgumentObject[] arguments,
            Dictionary<int, LocalVariableSymbol> dictionary,
            int startIndex,
            int endIndex)
        {
            EXPR args = null;
            EXPR last = null;

            if (arguments != null)
            {
                for (int i = startIndex; i < endIndex; i++)
                {
                    ArgumentObject argument = arguments[i];
                    EXPR arg = CreateArgumentEXPR(argument, dictionary[i]);

                    if (args == null)
                    {
                        args = arg;
                        last = args;
                    }
                    else
                    {
                        // Lists are right-heavy.
                        _exprFactory.AppendItemToList(arg, ref args, ref last);
                    }
                }
            }
            return args;
        }
Beispiel #24
0
        /////////////////////////////////////////////////////////////////////////////////
        // We take the ArgumentObjects to verify - if the parameter expression tells us 
        // we have a ref parameter, but the argument object tells us we're not passed by ref,
        // then it means it was a ref that the compiler had to insert. This is used when
        // we have a call off of a struct for example. If thats the case, don't treat the 
        // local as a ref type.

        private void PopulateLocalScope(
            DynamicMetaObjectBinder payload,
            Scope pScope,
            ArgumentObject[] arguments,
            IEnumerable<Expression> parameterExpressions,
            Dictionary<int, LocalVariableSymbol> dictionary)
        {
            // We use the compile time types for the local variables, and then 
            // cast them to the runtime types for the expression tree.

            int i = 0;
            foreach (Expression parameter in parameterExpressions)
            {
                CType type = _symbolTable.GetCTypeFromType(parameter.Type);

                // Make sure we're not setting ref for the receiver of a call - the argument
                // will be marked as ref if we're calling off a struct, but we don't want 
                // to persist that in our system.
                bool isFirstParamOfCallOrInvoke = false;
                if (i == 0 && IsBinderThatCanHaveRefReceiver(payload))
                {
                    isFirstParamOfCallOrInvoke = true;
                }

                // If we have a ref or out, get the parameter modifier type.
                if ((parameter is ParameterExpression && (parameter as ParameterExpression).IsByRef) &&
                    (arguments[i].Info.IsByRef || arguments[i].Info.IsOut))
                {
                    // If we're the first param of a call or invoke, and we're ref, it must be
                    // because of structs. Don't persist the parameter modifier type.
                    if (!isFirstParamOfCallOrInvoke)
                    {
                        type = _semanticChecker.GetTypeManager().GetParameterModifier(type, arguments[i].Info.IsOut);
                    }
                }
                LocalVariableSymbol local = _semanticChecker.GetGlobalSymbolFactory().CreateLocalVar(_semanticChecker.GetNameManager().Add("p" + i), pScope, type);
                local.fUsedInAnonMeth = true;

                dictionary.Add(i++, local);
                isFirstParamOfCallOrInvoke = false;
            }
        }
Beispiel #25
0
        /////////////////////////////////////////////////////////////////////////////////

        private void AddConversionsForArguments(ArgumentObject[] arguments)
        {
            foreach (ArgumentObject arg in arguments)
            {
                _symbolTable.AddConversionsForType(arg.Type);
            }
        }
Beispiel #26
0
        /////////////////////////////////////////////////////////////////////////////////

        private ArgumentObject[] CreateArgumentArray(
                DynamicMetaObjectBinder payload,
                IEnumerable<Expression> parameters,
                DynamicMetaObject[] args)
        {
            // Check the payloads to see whether or not we need to get the runtime types for
            // these arguments.

            List<ArgumentObject> list = new List<ArgumentObject>();
            Func<DynamicMetaObjectBinder, CSharpArgumentInfo, Expression, DynamicMetaObject, int, Type> getArgumentType = null;
            Func<DynamicMetaObjectBinder, int, CSharpArgumentInfo> getArgumentInfo = null;

            // Quick delegate to set the type.
            if (payload is ICSharpInvokeOrInvokeMemberBinder)
            {
                getArgumentInfo = (p, index) => (p as ICSharpInvokeOrInvokeMemberBinder).ArgumentInfo[index];
            }
            else if (payload is CSharpBinaryOperationBinder)
            {
                getArgumentInfo = (p, index) => (p as CSharpBinaryOperationBinder).ArgumentInfo[index];
            }
            else if (payload is CSharpUnaryOperationBinder)
            {
                getArgumentInfo = (p, index) => (p as CSharpUnaryOperationBinder).ArgumentInfo[index];
            }
            else if (payload is CSharpGetMemberBinder)
            {
                getArgumentInfo = (p, index) => (p as CSharpGetMemberBinder).ArgumentInfo[index];
            }
            else if (payload is CSharpSetMemberBinder)
            {
                getArgumentInfo = (p, index) => (p as CSharpSetMemberBinder).ArgumentInfo[index];
            }
            else if (payload is CSharpGetIndexBinder)
            {
                getArgumentInfo = (p, index) => (p as CSharpGetIndexBinder).ArgumentInfo[index];
            }
            else if (payload is CSharpSetIndexBinder)
            {
                getArgumentInfo = (p, index) => (p as CSharpSetIndexBinder).ArgumentInfo[index];
            }
            else if (payload is CSharpConvertBinder || payload is CSharpIsEventBinder)
            {
                getArgumentInfo = (p, index) => CSharpArgumentInfo.None;
            }
            else
            {
                Debug.Assert(false, "Unknown payload kind");
                throw Error.InternalCompilerError();
            }
            getArgumentType = (p, argInfo, param, arg, index) =>
                {
                    Type t = argInfo.UseCompileTimeType ? param.Type : arg.LimitType;
                    Debug.Assert(t != null);

                    if ((argInfo.Flags & (CSharpArgumentInfoFlags.IsRef | CSharpArgumentInfoFlags.IsOut)) != 0)
                    {
                        // If we have a ref our an out parameter, make the byref type.
                        // If we have the receiver of a call or invoke that is ref, it must be because of 
                        // a struct caller. Don't persist the ref for that.
                        if (!(index == 0 && IsBinderThatCanHaveRefReceiver(p)))
                        {
                            t = t.MakeByRefType();
                        }
                    }
                    else if (!argInfo.UseCompileTimeType)
                    {
                        // If we don't have ref or out, then pick the best type to represent this value.
                        // If the runtime value has a type that is not accessible, then we pick an
                        // accessible type that is "closest" in some sense, where we recursively widen
                        // components of type that can validly vary covariantly.

                        // This ensures that the type we pick is something that the user could have written.

                        CType actualType = _symbolTable.GetCTypeFromType(t);
                        CType bestType;

                        bool res = _semanticChecker.GetTypeManager().GetBestAccessibleType(_semanticChecker, _bindingContext, actualType, out bestType);
                        
                        // Since the actual type of these arguments are never going to be pointer
                        // types or ref/out types (they are in fact boxed into an object), we have
                        // a guarantee that we will always be able to find a best accessible type
                        // (which, in the worst case, may be object).
                        Debug.Assert(res, "Unexpected failure of GetBestAccessibleType in construction of argument array");

                        t = bestType.AssociatedSystemType;
                    }

                    return t;
                };

            int i = 0;
            foreach (var curParam in parameters)
            {
                ArgumentObject a = new ArgumentObject();
                a.Value = args[i].Value;
                a.Info = getArgumentInfo(payload, i);
                a.Type = getArgumentType(payload, a.Info, curParam, args[i], i);

                Debug.Assert(a.Type != null);
                list.Add(a);

                ++i;
            }

            return list.ToArray();
        }
Beispiel #27
0
        public static void Parse()
        {
            var url = "http://tomik.ru/";
            var singlePropertiesProduct = new Dictionary <string, Search <string> >()
            {
                [@"Наименование"] = (node, args) => node
                                    .SelectSingleNode(@"//h1[@class]")
                                    .InnerText,
                [@"Цена"] = (node, args) => node
                            .SelectSingleNode(@"//div[contains(@class, 'price')]/span")
                            .InnerText,
                [@"Деталей"] = (node, args) => node
                               .SelectSingleNode(@".//*[@id='toy-block']/div/div/div/div/div/div[3]/div[1]/div[2]")
                               .InnerText.Substring(9),
                [@"""Код артикула"""] = (node, args) => node
                                        .SelectSingleNode(@".//*[@id='toy-block']/div/div/div/div/div/div[3]/div[1]/div[3]")
                                        .InnerText.Substring(9),
                [@"Габариты"] = (node, args) => node
                                .SelectSingleNode(@".//*[@id='toy-block']/div/div/div/div/div/div[3]/div[1]/div[4]")
                                .InnerText.Substring(8),
                [@"Вес"] = (node, args) => node
                           .SelectSingleNode(@".//*[@id='toy-block']/div/div/div/div/div/div[3]/div[1]/div[5]")
                           .InnerText.Substring(5),
                ["Валюта"] = (node, o) => "RUB",
                [@"""Доступен для заказа"""] = (node, o) => "1",
                [@"Статус"] = (node, o) => "1",
            };

            singlePropertiesProduct["Заголовок"] = (node, args) => singlePropertiesProduct["Наименование"](node, args);
            singlePropertiesProduct[@"""Ссылка на витрину"""] = (node, args) =>
                                                                Humanization.GetHumanLink(singlePropertiesProduct["Наименование"](node, args));

            var parser = new LiquiMolyClass(
                isCategory: node => node
                ._SelectNodes(@"//h1[@class=""popular-items-cell-T""]")
                .Count == 0,
                findSubcatalogs: (node, args) => node
                ._SelectNodes(@"//div[@class=""container-fluid""]/div[3]/div/a")
                .Select(x => new ArgumentObject(url: url + x.Attributes["href"].Value
                                                , args: new object[] { (int)args.Args[0] + 1 }))
                .ToArray(),
                findProducts: (node, args) => node
                ._SelectNodes(@"//section[contains(@class, ""items-category"")]/div/div/div/div/div/a")
                .Select(x => new ArgumentObject(url: url + x.Attributes["href"].Value, args: args.Args))
                .ToArray(),
                pluralPropertiesProduct: new Dictionary <string, Search <string[]> >
            {
                ["Изображения"] = (node, args) => node
                                  ._SelectNodes(@"//img[@id]")
                                  .Select(x => url + x.Attributes["src"].Value)
                                  .Where(x => !x.Equals(String.Empty))
                                  .Distinct()
                                  .ToArray()
            },
                singlePropertiesCategory: new Dictionary <string, Search <string> >
            {
                ["Наименование"] = (node, args) => new string('!', (int)args.Args[0]) + node
                                   .SelectSingleNode(@"//h1")
                                   .InnerText,
            },
                singlePropertiesProduct: singlePropertiesProduct
                );

            var argument = new ArgumentObject(
                //prefix: @"http://tomik.ru/",
                url: @"http://tomik.ru/katalog/nastolnye-igry/domino/",
                //prefix: @"http://tomik.ru/katalog/elochnye-igrushki/podarki/kopiya-shnurovka-elochka-naryadnaya,-6-detalej.html",
                args: new object[] { 0 });
            var links = parser
                        .GetLinks(argument, @".//*[@id='sidebar']/div[2]/ul/li/a")
                        .Select(x => new ArgumentObject(url: url + x.Url,
                                                        args: x.Args));

            var collection =
                //parser.GetProductOrCategory(links);
                parser.GetProductOrCategory(argument);

            Import.Write(path: "tomik.csv",
                         collection: collection.ToArray(),
                         headers: Constants.WebAsystKeys,
                         format: Constants.WebAsystFormatter);
        }
Beispiel #28
0
        public static void Parse()
        {
            var URL = @"http://addinol.ru";

            var singlePropertiesProduct = new Dictionary <string, Search <string> >
            {
                ["Наименование"] = (node, args) => node
                                   .SelectSingleNode(@"//h1")
                                   .InnerText,
                ["Описание"] = (node, args) => node
                               .SelectSingleNode(@"//*[@id='art_container']/p")
                               ?.InnerHtml ?? string.Empty,
                ["Валюта"] = (node, o) => "RUB",
                [@"""Доступен для заказа"""] = (node, o) => "1",
                [@"Статус"] = (node, o) => "1",
            };

            singlePropertiesProduct["Заголовок"] =
                (node, args) => singlePropertiesProduct["Наименование"](node, args);
            singlePropertiesProduct[@"""Ссылка на витрину"""] = (node, args) =>
                                                                Humanization.GetHumanLink(singlePropertiesProduct["Наименование"](node, args));

            var parser = new LiquiMolyClass(
                isCategory: node => node
                ._SelectNodes(@"//*[@id='art_container']")
                .Count == 0,
                findProducts: (node, args) => node
                ._SelectNodes(@"//h2/a")
                .Select(x => new ArgumentObject(URL + x.Attributes["href"].Value))
                .ToArray(),
                singlePropertiesCategory: new Dictionary <string, Search <string> >
            {
                ["Наименование"] = (node, args) =>
                {
                    var sub1 = node
                               .SelectSingleNode(@"//li[contains(@class, 'submenu_sel')]/a")
                               .InnerText;
                    var sub2 = node
                               .SelectSingleNode(@".//*[contains(@class, 'submenu_2_sel')]/a")
                               ?.InnerText;

                    return(new string('!', (int)args.Args[0]) + (sub2 != null ? sub2 : sub1).Trim());
                }
            },
                findSubcatalogs: (node, args) =>
            {
                if ((int)args.Args[0] < 2)
                {
                    return(node
                           ._SelectNodes(@"//li[contains(@class, 'submenu_sel')]/ul/li/a")
                           .Select(x => new ArgumentObject(URL + x.Attributes["href"].Value,
                                                           new object[] { (int)args.Args[0] + 1 }))
                           .ToArray());
                }
                else
                {
                    return(new ArgumentObject[0]);
                }
            },
                singlePropertiesProduct: singlePropertiesProduct,
                pluralPropertiesProduct: new Dictionary <string, Search <string[]> >
            {
                ["Изображения"] = (node, args) => {
                    var a = node
                            ._SelectNodes(@"//*[@id='right_col']/div/a")
                            .Select(x => x.Attributes["href"].Value)
                            .ToArray();
                    return(a);
                }
            },
                encoding: Encoding.UTF8
                );

            var argument = new ArgumentObject(
                url: @"http://addinol.ru/index.php?id=15804",
                args: new object[] { 1 });

            var collection =
                parser.GetProductOrCategory(parser.GetLinks(argument,
                                                            @"//*[@class='submenu' and position() < 4]/a",
                                                            prefix: URL));

            collection = Merger.Merge(
                collection: collection,
                other: AddinolDataExtractorExample.Extract(),
                setKeyCollection: o => o.SingleProperties["Наименование"],
                setKeyOtherCollection: o => o.SingleProperties["Наименование"]);

            collection = JoinerArticles.JoinInOrderEnumerable(collection, "Наименование",
                                                              productFieldsForPluralProp: new[] { "Изображения" },
                                                              productFieldsForSingleProp: new[] { "Описание" });

            collection = new[]
            {
                new ProductCategoryObject(
                    new Dictionary <string, string> {
                    ["Наименование"] = "Addinol"
                }, isCategory: true)
            }.Extend(collection);

            Import.Write(path: "../../../CSV/addinol.csv",
                         collection: collection.ToArray(),
                         headers: Constants.WebAsystKeys,
                         format: Constants.WebAsystFormatter);
        }
Beispiel #29
0
        /////////////////////////////////////////////////////////////////////////////////

        private EXPR CreateCallingObjectForCall(
            ICSharpInvokeOrInvokeMemberBinder payload,
            ArgumentObject[] arguments,
            Dictionary<int, LocalVariableSymbol> dictionary)
        {
            // Here we have a regular call, so create the calling object off of the first
            // parameter and pass it through.
            EXPR callingObject;
            if (payload.StaticCall)
            {
                if (arguments[0].Value == null || !(arguments[0].Value is Type))
                {
                    Debug.Assert(false, "Cannot make static call without specifying a type");
                    throw Error.InternalCompilerError();
                }
                Type t = arguments[0].Value as Type;
                callingObject = _exprFactory.CreateClass(_symbolTable.GetCTypeFromType(t), null, t.GetTypeInfo().ContainsGenericParameters ?
                        _exprFactory.CreateTypeArguments(SymbolLoader.getBSymmgr().AllocParams(_symbolTable.GetCTypeArrayFromTypes(t.GetGenericArguments())), null) : null);
            }
            else
            {
                // If we have a null argument, just bail and throw.
                if (!arguments[0].Info.UseCompileTimeType && arguments[0].Value == null)
                {
                    throw Error.NullReferenceOnMemberException();
                }

                callingObject = _binder.mustConvert(
                    CreateArgumentEXPR(arguments[0], dictionary[0]),
                    _symbolTable.GetCTypeFromType(arguments[0].Type));

                if (arguments[0].Type.GetTypeInfo().IsValueType && callingObject.isCAST())
                {
                    // If we have a struct type, unbox it.
                    callingObject.flags |= EXPRFLAG.EXF_UNBOXRUNTIME;
                }
            }
            return callingObject;
        }
Beispiel #30
0
        public static void Parse()
        {
            var URL = @"https://masteras.ru";

            var singlePropertiesProduct = new Dictionary <string, Search <string> >
            {
                ["Наименование"] = (node, args) => node
                                   .SelectSingleNode(@"//*[@id='product-top']/div[2]/h1")
                                   .InnerText,
                [@"""Код артикула"""] = (node, args) => "SER-" + node
                                        .SelectSingleNode(@"//*[@class='sku']/span")
                                        .InnerText
                                        .Trim(),
                ["Цена"] = (node, args) => node
                           .SelectSingleNode(@"//*[@id='product-top']/div[2]/div[1]/p/span")
                           ?.InnerText
                           .Replace(" ", string.Empty) ?? string.Empty,
                ["Описание"] = (node, args) => node
                               .SelectSingleNode(@"//*[@class='hide-me closed']")
                               ?.InnerText ?? string.Empty,
                ["Валюта"] = (node, o) => "RUB",
                [@"""Доступен для заказа"""] = (node, o) => "1",
                [@"Статус"] = (node, o) => "1",
            };

            singlePropertiesProduct["Заголовок"] =
                (node, args) => singlePropertiesProduct["Наименование"](node, args);
            singlePropertiesProduct[@"""Ссылка на витрину"""] = (node, args) =>
                                                                Humanization.GetHumanLink(singlePropertiesProduct["Наименование"](node, args)
                                                                                          + "-" + singlePropertiesProduct[@"""Код артикула"""](node, args));

            var parser = new LiquiMolyClass(
                isCategory: node => node
                ._SelectNodes(@"//*[@class='sku']/span")
                .Count == 0,
                findProducts: (node, args) =>
            {
                var prods = node
                            .SelectNodes(@"//a[@class='product-title']")
                            .Select(x => new ArgumentObject(x.Attributes["href"].Value))
                            .ToArray();

                return((int)args.Args[0] > 1 ? prods : new ArgumentObject[0]);
            },
                singlePropertiesCategory: new Dictionary <string, Search <string> >
            {
                ["Наименование"] = (node, args) =>
                {
                    var a = node
                            .SelectSingleNode(@"//*[@id='cat-description']/h2")
                            ?.InnerText.Trim() ?? string.Empty;

                    var b = node
                            .SelectSingleNode(@"//*[@id='categories']/h2")
                            ?.InnerText.Trim() ?? string.Empty;

                    return(new string('!', (int)args.Args[0]) + (a == string.Empty ? b : a));
                }
            },
                singlePropertiesProduct: singlePropertiesProduct,
                pluralPropertiesProduct: new Dictionary <string, Search <string[]> >
            {
                ["Изображения"] = (node, args) => node
                                  ._SelectNodes(@"//*[@id='photos']/div/a/img")
                                  .Select(x => x.Attributes["src"].Value)
                                  .ToArray()
            },
                xPathPagination: (node, args) =>
            {
                var number = int.Parse(node
                                       .SelectSingleNode(@"//*[@class='page-numbers']/li[last() -1]/a")
                                       ?.InnerText ?? "1");

                return(Enumerable.Range(2, number - 1)
                       .Select(x => args.Url + $"page/{x}/")
                       .Select(x => new ArgumentObject(x))
                       .ToArray());
            },
                encoding: Encoding.UTF8
                );

            var argument = new ArgumentObject(
                url: @"https://masteras.ru/shop/",
                args: new object[] { 2 });

            var collection =
                parser.GetProductOrCategory(parser.GetLinks(argument,
                                                            @"//*[@class='descr']/../../a",
                                                            prefix: ""));

            collection = new[]
            {
                new ProductCategoryObject(
                    new Dictionary <string, string> {
                    ["Наименование"] = "Temporary2"
                }, isCategory: true),
                new ProductCategoryObject(
                    new Dictionary <string, string> {
                    ["Наименование"] = "!Masteras"
                }, isCategory: true)
            }.Extend(collection);

            //collection = JoinerArticles.JoinInOrderEnumerable(collection, "Наименование",
            //    productFieldsForPluralProp: new[] { "Изображения" },
            //    productFieldsForSingleProp: new[] { "Описание" });

            Import.Write(path: "../../../CSV/masteras.csv",
                         collection: collection.ToArray(),
                         headers: Constants.WebAsystKeys,
                         format: Constants.WebAsystFormatter);
        }
Beispiel #31
0
        public static void Parse()
        {
            var URL = @"http://www.lavatoys.ru";

            var singlePropertiesProduct = new Dictionary <string, Search <string> >
            {
                ["Наименование"] = (node, args) => node
                                   .SelectSingleNode(@"//*[@class='toy__title']")
                                   .InnerText,
                [@"""Код артикула"""] = (node, args) => "LVS-" + node
                                        .SelectSingleNode(@"//*[@class='toy__article']")
                                        .InnerText,
                [@"""Зачеркнутая цена"""] = (node, args) => Regex.Replace(node
                                                                          .SelectSingleNode(@"//*[@class='toy__old-price']")
                                                                          ?.InnerText ?? string.Empty, @"\s+", string.Empty),
                ["Цена"] = (node, args) => Regex.Replace(node
                                                         .SelectSingleNode(@"//*[@class='toy__price-right']/strong")
                                                         .InnerText, @"\s+", string.Empty),
                ["Описание"] = (node, args) => string.Format("Издает звук {0} при нажатии на игрушку", node
                                                             .SelectSingleNode(@"//*[@class='toy__song']")
                                                             ?.InnerText ?? string.Empty),
                ["Размеры"] = (node, args) =>
                {
                    var length = node
                                 .SelectSingleNode(@"//*[@class='toy__params-row'][2]/td[2]")
                                 .InnerText;
                    var remp = length.Contains("см");

                    return(length.Contains("см") ? "Высота: " + length : string.Empty);
                },
                ["Валюта"] = (node, o) => "RUB",
                [@"""Доступен для заказа"""] = (node, o) => "1",
                [@"Статус"] = (node, o) => "1",
            };

            singlePropertiesProduct["Заголовок"] =
                (node, args) => singlePropertiesProduct["Наименование"](node, args);
            singlePropertiesProduct[@"""Ссылка на витрину"""] = (node, args) =>
                                                                Humanization.GetHumanLink(singlePropertiesProduct["Наименование"](node, args)
                                                                                          + "-" + singlePropertiesProduct[@"""Код артикула"""](node, args));

            var parser = new LiquiMolyClass(
                isCategory: node => node
                ._SelectNodes(@"//*[@class='js-content__back-button']")
                .Count == 0,
                findProducts: (node, args) => node
                ._SelectNodes(@"//a[@class='catalog-item__image-wrapper']")
                .Select(x => new ArgumentObject(URL + x.Attributes["href"].Value))
                .ToArray(),
                singlePropertiesCategory: new Dictionary <string, Search <string> >
            {
                ["Наименование"] = (node, args) => new string('!', (int)args.Args[0]) + node
                                   .SelectSingleNode(@"//h1[@class='catalog-items__title']")
                                   .InnerText
                                   .Split(':')[1]
                                   .Trim()
            },
                singlePropertiesProduct: singlePropertiesProduct,
                pluralPropertiesProduct: new Dictionary <string, Search <string[]> >
            {
                ["Изображения"] = (node, args) => node
                                  ._SelectNodes(@"//*[@class='js-widget']")
                                  .Select(x => URL + x.Attributes["src"].Value)
                                  .ToArray()
            },
                encoding: Encoding.UTF8,
                xPathPagination: (node, args) => node
                ._SelectNodes(@"//nav[@class='paginator paginator_position_top']/a[@class='paginator__item']")
                .Select(x => new ArgumentObject(URL + x.Attributes["href"].Value))
                .ToArray()
                );

            var argument = new ArgumentObject(
                url: @"http://www.lavatoys.ru/catalogue/",
                args: new object[] { 2 });

            var collection =
                parser.GetProductOrCategory(parser.GetLinks(argument,
                                                            @"//*[@class='nav__col nav__col_width_half nav__col_type_catalog-groups']/a[@class='nav__item']",
                                                            prefix: @"http://www.lavatoys.ru"));

            collection = new[]
            {
                new ProductCategoryObject(
                    new Dictionary <string, string> {
                    ["Наименование"] = "Temporary2"
                }, isCategory: true),
                new ProductCategoryObject(
                    new Dictionary <string, string> {
                    ["Наименование"] = "!LavaToys"
                }, isCategory: true)
            }.Extend(collection);

            Import.Write(path: "../../../CSV/lavaToys.csv",
                         collection: collection.ToArray(),
                         headers: Constants.WebAsystKeys,
                         format: Constants.WebAsystFormatter);
        }
        /// <summary>
        /// Outputs 'msg' to the text box in the UI of the application
        /// </summary>
        /// <param name="msg">Message that will be output in the text box of the UI</param>
        /// <param name="completed">A value to indicate the file transfer has been completed.</param>
        public void OutputLine(string msg, bool completed = false)
        {
            if (completed)
            {
                this.ButtonRunClient.IsEnabled = true;
                this.BusObject = null;
            }

            ArgumentObject ao = new ArgumentObject();
            ao.TextBox = this.TextBlockClient;
            ao.Text = msg + "\n";
            Dispatcher.RunAsync(
                CoreDispatcherPriority.Normal,
                new DispatchedHandler(ao.OnDispatched)).AsTask();
            System.Diagnostics.Debug.WriteLine(msg);
        }
Beispiel #33
0
        public static void Parse()
        {
            var random = new Random();
            var URL    = @"http://valda.ru";
            var singlePropertiesProduct = new Dictionary <string, Search <string> >
            {
                ["Цена"] = (node, args) => node
                           .SelectSingleNode(@"//div[@class='add2cart']/span[2]")
                           ?.Attributes["data-price"]?.Value ??
                           node.SelectSingleNode(@"//div[@class='add2cart']/span[3]")
                           .Attributes["data-price"].Value,
                [@"""Код артикула"""] = (node, args) => "VD-" + node
                                        .SelectSingleNode(@"//div[@itemprop]/*[contains(@class, 'hint')]")
                                        ?.InnerText ?? string.Empty,
                ["Наименование"] = (node, args) => node
                                   .SelectSingleNode(@"//article/h1/span")
                                   .InnerText,
                ["Описание"] = (node, args) => (node
                                                .SelectSingleNode(@".//*[@id='product-description']")
                                                ?.InnerHtml ?? string.Empty) +
                               (node.SelectSingleNode(@".//*[@id='cart-form']/p")
                                ?.InnerHtml ?? string.Empty) +
                               (node.SelectSingleNode(@".//*[@id='cart-form']/table")
                                ?.InnerHtml ?? string.Empty),
                ["Валюта"] = (node, o) => "RUB",
                [@"""Доступен для заказа"""] = (node, o) => "1",
                [@"Статус"] = (node, o) => "1",
                [@"""Зачеркнутая цена"""] = (node, args) => node
                                            .SelectSingleNode(@"//span[@class='compare-at-price nowrap']")
                                            ?.InnerText?.Replace(" ", string.Empty) ?? string.Empty,
                //[@"""Возраст детей"""] = (node, args) =>
                //{
                //    return Regex.Match(node.InnerText, @"Возраст.*\s+\w+", RegexOptions.IgnoreCase).Value;
                //}
            };

            singlePropertiesProduct["Заголовок"] =
                (node, args) => singlePropertiesProduct["Наименование"](node, args);
            singlePropertiesProduct[@"""Ссылка на витрину"""] = (node, args) =>
                                                                Humanization.GetHumanLink(singlePropertiesProduct["Наименование"](node, args) + "-VD-" + random.Next());
            var parser = new LiquiMolyClass(
                isCategory: node => node
                ._SelectNodes(@"//*[@id='product-list']")
                .Count != 0,
                findProducts: (node, args) => node
                ._SelectNodes(@"//*[@id='product-list']/ul/li/a")
                .Select(x => new ArgumentObject(URL + x.Attributes["href"].Value))
                .ToArray(),
                singlePropertiesProduct: singlePropertiesProduct,
                pluralPropertiesProduct: new Dictionary <string, Search <string[]> >
            {
                ["Изображения"] = (node, args) =>
                {
                    var result = node
                                 ._SelectNodes(@"//div[@id='product-gallery']/div/a")
                                 .Select(x => URL + x.Attributes["href"].Value)
                                 .ToArray();
                    return(result.Length != 0
                            ? result
                            : new [] { URL + node.SelectSingleNode(@".//*[@id='product-image']")
                                       .Attributes["src"].Value });
                }
            },
                singlePropertiesCategory: new Dictionary <string, Search <string> >
            {
                ["Наименование"] = (node, args) => new string('!', (int)args.Args[0]) + node
                                   .SelectSingleNode(@".//*[@id='page-content']/h1")
                                   .InnerText.Trim()
            }
                );
            var argument = new ArgumentObject(
                url: URL,
                //prefix: @"http://oksva-tm.ru/catalog/15",
                args: new object[] { 2 });

            var collection =
                parser.GetProductOrCategory(parser.GetLinks(argument,
                                                            @".//*[@id='page-content']/div[1]/ul/li/a",
                                                            prefix: URL));

            //parser.GetProductOrCategory(argument);
            collection = new[]
            {
                new ProductCategoryObject(
                    new Dictionary <string, string> {
                    ["Наименование"] = "Temporary2"
                }, isCategory: true),
                new ProductCategoryObject(
                    new Dictionary <string, string> {
                    ["Наименование"] = "!valda"
                }, isCategory: true)
            }.Extend(collection);
            Import.Write(path: @"..\..\..\CSV\valda.csv",
                         collection: collection.ToArray(),
                         headers: Constants.WebAsystKeys,
                         format: Constants.WebAsystFormatter);
        }
Beispiel #34
0
        /////////////////////////////////////////////////////////////////////////////////

        private Expression CreateExpressionTreeFromResult(
            IEnumerable<Expression> parameters,
            ArgumentObject[] arguments,
            Scope pScope,
            EXPR pResult)
        {
            // (3) - Place the result in a return statement and create the EXPRBOUNDLAMBDA.
            EXPRBOUNDLAMBDA boundLambda = GenerateBoundLambda(arguments, pScope, pResult);

            // (4) - Rewrite the EXPRBOUNDLAMBDA into an expression tree.
            EXPR exprTree = ExpressionTreeRewriter.Rewrite(boundLambda, _exprFactory, SymbolLoader);

            // (5) - Create the actual Expression Tree
            Expression e = ExpressionTreeCallRewriter.Rewrite(SymbolLoader.GetTypeManager(), exprTree, parameters);
            return e;
        }
Beispiel #35
0
        /////////////////////////////////////////////////////////////////////////////////

        private EXPR BindBinaryOperation(
                CSharpBinaryOperationBinder payload,
                ArgumentObject[] arguments,
                Dictionary<int, LocalVariableSymbol> dictionary)
        {
            if (arguments.Length != 2)
            {
                throw Error.BindBinaryOperatorRequireTwoArguments();
            }

            ExpressionKind ek = Operators.GetExpressionKind(GetOperatorKind(payload.Operation, payload.IsLogicalOperation));
            EXPR arg1 = CreateArgumentEXPR(arguments[0], dictionary[0]);
            EXPR arg2 = CreateArgumentEXPR(arguments[1], dictionary[1]);

            arg1.errorString = Operators.GetDisplayName(GetOperatorKind(payload.Operation, payload.IsLogicalOperation));
            arg2.errorString = Operators.GetDisplayName(GetOperatorKind(payload.Operation, payload.IsLogicalOperation));

            if (ek > ExpressionKind.EK_MULTIOFFSET)
            {
                ek = (ExpressionKind)(ek - ExpressionKind.EK_MULTIOFFSET);
            }
            return _binder.BindStandardBinop(ek, arg1, arg2);
        }
Beispiel #36
0
        /////////////////////////////////////////////////////////////////////////////////

        private void PopulateSymbolTableWithPayloadInformation(
            DynamicMetaObjectBinder payload,
            Type callingType,
            ArgumentObject[] arguments)
        {
            ICSharpInvokeOrInvokeMemberBinder callOrInvoke;
            CSharpGetMemberBinder getmember;
            CSharpSetMemberBinder setmember;

            if ((callOrInvoke = payload as ICSharpInvokeOrInvokeMemberBinder) != null)
            {
                Type type;

                if (callOrInvoke.StaticCall)
                {
                    if (arguments[0].Value == null || !(arguments[0].Value is Type))
                    {
                        Debug.Assert(false, "Cannot make static call without specifying a type");
                        throw Error.InternalCompilerError();
                    }
                    type = arguments[0].Value as Type;
                }
                else
                {
                    type = callingType;
                }
                _symbolTable.PopulateSymbolTableWithName(
                    callOrInvoke.Name,
                    callOrInvoke.TypeArguments,
                    type);

                // If it looks like we're invoking a get_ or a set_, load the property as well.
                // This is because we need COM indexed properties called via method calls to 
                // work the same as it used to.
                if (callOrInvoke.Name.StartsWith("set_", StringComparison.Ordinal) ||
                    callOrInvoke.Name.StartsWith("get_", StringComparison.Ordinal))
                {
                    _symbolTable.PopulateSymbolTableWithName(
                        callOrInvoke.Name.Substring(4), //remove prefix
                        callOrInvoke.TypeArguments,
                        type);
                }
            }
            else if ((getmember = payload as CSharpGetMemberBinder) != null)
            {
                _symbolTable.PopulateSymbolTableWithName(
                    getmember.Name,
                    null,
                    arguments[0].Type);
            }
            else if ((setmember = payload as CSharpSetMemberBinder) != null)
            {
                _symbolTable.PopulateSymbolTableWithName(
                    setmember.Name,
                    null,
                    arguments[0].Type);
            }
            else if (payload is CSharpGetIndexBinder || payload is CSharpSetIndexBinder)
            {
                _symbolTable.PopulateSymbolTableWithName(
                    SpecialNames.Indexer,
                    null,
                    arguments[0].Type);
            }
            else if (payload is CSharpBinaryOperationBinder)
            {
                CSharpBinaryOperationBinder op = payload as CSharpBinaryOperationBinder;
                if (GetCLROperatorName(op.Operation) == null)
                {
                    Debug.Assert(false, "Unknown operator: " + op.Operation);
                    throw Error.InternalCompilerError();
                }
                _symbolTable.PopulateSymbolTableWithName(
                    GetCLROperatorName(op.Operation),
                    null,
                    arguments[0].Type);
                _symbolTable.PopulateSymbolTableWithName(
                    GetCLROperatorName(op.Operation),
                    null,
                    arguments[1].Type);
            }
            else if (payload is CSharpUnaryOperationBinder)
            {
                CSharpUnaryOperationBinder op = payload as CSharpUnaryOperationBinder;
                _symbolTable.PopulateSymbolTableWithName(
                    GetCLROperatorName(op.Operation),
                    null,
                    arguments[0].Type);
            }
            else if (payload is CSharpIsEventBinder)
            {
                CSharpIsEventBinder op = payload as CSharpIsEventBinder;

                // Populate the symbol table with the LHS.
                _symbolTable.PopulateSymbolTableWithName(
                    op.Name,
                    null,
                    arguments[0].Info.IsStaticType ? arguments[0].Value as Type : arguments[0].Type);
            }
            else if (!(payload is CSharpConvertBinder))
            {
                // Conversions don't need to do anything, since they're just conversions!
                // After we add payload information, we add conversions for all argument
                // types anyway, so that will get handled there.
                //
                // All other unknown payload types will generate an error.

                Debug.Assert(false, "Unknown payload kind");
                throw Error.InternalCompilerError();
            }
        }
Beispiel #37
0
        /////////////////////////////////////////////////////////////////////////////////

        private EXPR BindProperty(
            DynamicMetaObjectBinder payload,
            ArgumentObject argument,
            LocalVariableSymbol local,
            EXPR optionalIndexerArguments,
            bool fEventsPermitted)
        {
            // If our argument is a static type, then we're calling a static property.
            EXPR callingObject = argument.Info.IsStaticType ?
                _exprFactory.CreateClass(_symbolTable.GetCTypeFromType(argument.Value as Type), null, null) :
                CreateLocal(argument.Type, argument.Info.IsOut, local);

            if (!argument.Info.UseCompileTimeType && argument.Value == null)
            {
                throw Error.NullReferenceOnMemberException();
            }

            // If our argument is a struct type, unbox it.
            if (argument.Type.GetTypeInfo().IsValueType && callingObject.isCAST())
            {
                // If we have a struct type, unbox it.
                callingObject.flags |= EXPRFLAG.EXF_UNBOXRUNTIME;
            }
            string name = GetName(payload);
            BindingFlag bindFlags = GetBindingFlags(payload);

            MemberLookup mem = new MemberLookup();
            SymWithType swt = _symbolTable.LookupMember(name, callingObject, _bindingContext.ContextForMemberLookup(), 0, mem, false, false);
            if (swt == null)
            {
                if (optionalIndexerArguments != null)
                {
                    int numIndexArguments = ExpressionIterator.Count(optionalIndexerArguments);
                    // We could have an array access here. See if its just an array.
                    if ((argument.Type.IsArray && argument.Type.GetArrayRank() == numIndexArguments) ||
                        argument.Type == typeof(string))
                    {
                        return CreateArray(callingObject, optionalIndexerArguments);
                    }
                }
                mem.ReportErrors();
                Debug.Assert(false, "Why didn't member lookup report an error?");
            }

            switch (swt.Sym.getKind())
            {
                case SYMKIND.SK_MethodSymbol:
                    throw Error.BindPropertyFailedMethodGroup(name);

                case SYMKIND.SK_PropertySymbol:
                    if (swt.Sym is IndexerSymbol)
                    {
                        return CreateIndexer(swt, callingObject, optionalIndexerArguments, bindFlags);
                    }
                    else
                    {
                        BindingFlag flags = 0;
                        if (payload is CSharpGetMemberBinder || payload is CSharpGetIndexBinder)
                        {
                            flags = BindingFlag.BIND_RVALUEREQUIRED;
                        }

                        // Properties can be LValues.
                        callingObject.flags |= EXPRFLAG.EXF_LVALUE;
                        return CreateProperty(swt, callingObject, flags);
                    }

                case SYMKIND.SK_FieldSymbol:
                    return CreateField(swt, callingObject);

                case SYMKIND.SK_EventSymbol:
                    if (fEventsPermitted)
                    {
                        return CreateEvent(swt, callingObject);
                    }
                    else
                    {
                        throw Error.BindPropertyFailedEvent(name);
                    }

                default:
                    Debug.Assert(false, "Unexpected type returned from lookup");
                    throw Error.InternalCompilerError();
            }
        }
Beispiel #38
0
        /////////////////////////////////////////////////////////////////////////////////

        private EXPR DispatchPayload(
            DynamicMetaObjectBinder payload,
            ArgumentObject[] arguments,
            Dictionary<int, LocalVariableSymbol> dictionary)
        {
            EXPR pResult = null;
            if (payload is CSharpBinaryOperationBinder)
            {
                pResult = BindBinaryOperation(payload as CSharpBinaryOperationBinder, arguments, dictionary);
            }
            else if (payload is CSharpUnaryOperationBinder)
            {
                pResult = BindUnaryOperation(payload as CSharpUnaryOperationBinder, arguments, dictionary);
            }
            else if (payload is CSharpSetMemberBinder)
            {
                pResult = BindAssignment(payload as CSharpSetMemberBinder, arguments, dictionary);
            }
            else if (payload is CSharpConvertBinder)
            {
                Debug.Assert(arguments.Length == 1);
                {
                    CSharpConvertBinder conversion = payload as CSharpConvertBinder;
                    switch (conversion.ConversionKind)
                    {
                        case CSharpConversionKind.ImplicitConversion:
                            pResult = BindImplicitConversion(arguments, conversion.Type, dictionary, false);
                            break;
                        case CSharpConversionKind.ExplicitConversion:
                            pResult = BindExplicitConversion(arguments, conversion.Type, dictionary);
                            break;
                        case CSharpConversionKind.ArrayCreationConversion:
                            pResult = BindImplicitConversion(arguments, conversion.Type, dictionary, true);
                            break;
                        default:
                            Debug.Assert(false, "Unknown conversion kind");
                            throw Error.InternalCompilerError();
                    }
                }
            }
            else if (payload is ICSharpInvokeOrInvokeMemberBinder)
            {
                EXPR callingObject = CreateCallingObjectForCall(payload as ICSharpInvokeOrInvokeMemberBinder, arguments, dictionary);
                pResult = BindCall(payload as ICSharpInvokeOrInvokeMemberBinder, callingObject, arguments, dictionary);
            }
            else if (payload is CSharpGetMemberBinder)
            {
                Debug.Assert(arguments.Length == 1);
                pResult = BindProperty(payload, arguments[0], dictionary[0], null, false);
            }
            else if (payload is CSharpGetIndexBinder)
            {
                EXPR indexerArguments = CreateArgumentListEXPR(arguments, dictionary, 1, arguments.Length);
                pResult = BindProperty(payload, arguments[0], dictionary[0], indexerArguments, false);
            }
            else if (payload is CSharpSetIndexBinder)
            {
                pResult = BindAssignment(payload as CSharpSetIndexBinder, arguments, dictionary);
            }
            else if (payload is CSharpIsEventBinder)
            {
                pResult = BindIsEvent(payload as CSharpIsEventBinder, arguments, dictionary);
            }
            else
            {
                Debug.Assert(false, "Unknown payload kind");
                throw Error.InternalCompilerError();
            }
            return pResult;
        }
Beispiel #39
0
        /////////////////////////////////////////////////////////////////////////////////

        private EXPR BindImplicitConversion(
            ArgumentObject[] arguments,
            Type returnType,
            Dictionary<int, LocalVariableSymbol> dictionary,
            bool bIsArrayCreationConversion)
        {
            if (arguments.Length != 1)
            {
                throw Error.BindImplicitConversionRequireOneArgument();
            }

            // Load the conversions on the target.
            _symbolTable.AddConversionsForType(returnType);

            EXPR argument = CreateArgumentEXPR(arguments[0], dictionary[0]);
            CType destinationType = _symbolTable.GetCTypeFromType(returnType);

            if (bIsArrayCreationConversion)
            {
                // If we are converting for an array index, we want to convert to int, uint,
                // long, or ulong, depending on what the argument will allow. However, since
                // the compiler had to pick a particular type for the return value when it
                // made the callsite, we need to make sure that we ultimately return a type
                // of that value. So we "mustConvert" to the best type that chooseArrayIndexType
                // can find, and then we cast the result of that to the returnType, which is
                // incidentally Int32 in the existing compiler. For that cast, we do not consider
                // user defined conversions (since the convert is guaranteed to return one of
                // the primitive types), and we check for overflow since we don't want truncation.

                CType pDestType = _binder.chooseArrayIndexType(argument);
                if (null == pDestType)
                {
                    pDestType = SymbolLoader.GetReqPredefType(PredefinedType.PT_INT, true);
                }

                return _binder.mustCast(
                    _binder.mustConvert(argument, pDestType),
                    destinationType,
                    CONVERTTYPE.CHECKOVERFLOW | CONVERTTYPE.NOUDC);
            }

            return _binder.mustConvert(argument, destinationType);
        }
Beispiel #40
0
        /////////////////////////////////////////////////////////////////////////////////

        private EXPRBOUNDLAMBDA GenerateBoundLambda(
            ArgumentObject[] arguments,
            Scope pScope,
            EXPR call)
        {
            // We don't actually need the real delegate type here - we just need SOME delegate type.
            // This is because we never attempt any conversions on the lambda itself.
            AggregateType delegateType = _symbolTable.GetCTypeFromType(typeof(Func<>)).AsAggregateType();
            LocalVariableSymbol thisLocal = _semanticChecker.GetGlobalSymbolFactory().CreateLocalVar(_semanticChecker.GetNameManager().Add("this"), pScope, _symbolTable.GetCTypeFromType(typeof(object)));
            thisLocal.isThis = true;
            EXPRBOUNDLAMBDA boundLambda = _exprFactory.CreateAnonymousMethod(delegateType);
            EXPRUNBOUNDLAMBDA unboundLambda = _exprFactory.CreateLambda();

            List<Type> paramTypes = new List<Type>();
            foreach (ArgumentObject o in arguments)
            {
                paramTypes.Add(o.Type);
            }
            boundLambda.Initialize(pScope);

            EXPRRETURN returnStatement = _exprFactory.CreateReturn(0, pScope, call);
            EXPRBLOCK block = _exprFactory.CreateBlock(null, returnStatement, pScope);
            boundLambda.OptionalBody = block;
            return boundLambda;
        }
Beispiel #41
0
        /////////////////////////////////////////////////////////////////////////////////

        private EXPR BindExplicitConversion(ArgumentObject[] arguments, Type returnType, Dictionary<int, LocalVariableSymbol> dictionary)
        {
            if (arguments.Length != 1)
            {
                throw Error.BindExplicitConversionRequireOneArgument();
            }

            // Load the conversions on the target.
            _symbolTable.AddConversionsForType(returnType);

            EXPR argument = CreateArgumentEXPR(arguments[0], dictionary[0]);
            CType destinationType = _symbolTable.GetCTypeFromType(returnType);

            return _binder.mustCast(argument, destinationType);
        }
Beispiel #42
0
        /////////////////////////////////////////////////////////////////////////////////

        private EXPR CreateArgumentEXPR(ArgumentObject argument, LocalVariableSymbol local)
        {
            EXPR arg;
            if (argument.Info.LiteralConstant)
            {
                if (argument.Value == null)
                {
                    if (argument.Info.UseCompileTimeType)
                    {
                        arg = _exprFactory.CreateConstant(_symbolTable.GetCTypeFromType(argument.Type), new CONSTVAL());
                    }
                    else
                    {
                        arg = _exprFactory.CreateNull();
                    }
                }
                else
                {
                    arg = _exprFactory.CreateConstant(_symbolTable.GetCTypeFromType(argument.Type), new CONSTVAL(argument.Value));
                }
            }
            else
            {
                // If we have a dynamic argument and it was null, the type is going to be Object.
                // But we want it to be typed NullType so we can have null conversions.

                if (!argument.Info.UseCompileTimeType && argument.Value == null)
                {
                    arg = _exprFactory.CreateNull();
                }
                else
                {
                    arg = CreateLocal(argument.Type, argument.Info.IsOut, local);
                }
            }

            // Now check if we have a named thing. If so, wrap this thing in a named argument.
            if (argument.Info.NamedArgument)
            {
                Debug.Assert(argument.Info.Name != null);
                arg = _exprFactory.CreateNamedArgumentSpecification(SymbolTable.GetName(argument.Info.Name, _semanticChecker.GetNameManager()), arg);
            }

            // If we have an object that was "dynamic" at compile time, we need
            // to be able to convert it to every interface that the actual value
            // implements. This allows conversion binders and overload resolution
            // to behave as though type information is available for these EXPRs,
            // even though it may be the case that the actual runtime type is
            // inaccessible and therefore unused.

            // This comes in handy for, e.g., iterators (they are nested private
            // classes), and COM RCWs without type information (they do not expose
            // their interfaces in a usual way).

            // It is critical that arg.RuntimeObject is non-null only when the
            // compile time type of the argument is dynamic, otherwise normal C#
            // semantics on typed arguments will be broken.

            if (!argument.Info.UseCompileTimeType && argument.Value != null)
            {
                arg.RuntimeObject = argument.Value;
                arg.RuntimeObjectActualType = _symbolTable.GetCTypeFromType(argument.Value.GetType());
            }

            return arg;
        }
Beispiel #43
0
        /////////////////////////////////////////////////////////////////////////////////

        private EXPR BindAssignment(
            DynamicMetaObjectBinder payload,
            ArgumentObject[] arguments,
            Dictionary<int, LocalVariableSymbol> dictionary)
        {
            if (arguments.Length < 2)
            {
                throw Error.BindBinaryAssignmentRequireTwoArguments();
            }
            string name = GetName(payload);

            // Find the lhs and rhs.
            EXPR lhs;
            EXPR indexerArguments = null;
            bool bIsCompound = false;

            if (payload is CSharpSetIndexBinder)
            {
                // Get the list of indexer arguments - this is the list of arguments minus the last one.
                indexerArguments = CreateArgumentListEXPR(arguments, dictionary, 1, arguments.Length - 1);
                bIsCompound = (payload as CSharpSetIndexBinder).IsCompoundAssignment;
            }
            else
            {
                bIsCompound = (payload as CSharpSetMemberBinder).IsCompoundAssignment;
            }
            _symbolTable.PopulateSymbolTableWithName(name, null, arguments[0].Type);
            lhs = BindProperty(payload, arguments[0], dictionary[0], indexerArguments, false);

            int indexOfLast = arguments.Length - 1;
            EXPR rhs = CreateArgumentEXPR(arguments[indexOfLast], dictionary[indexOfLast]);

            if (arguments[0] == null)
            {
                throw Error.BindBinaryAssignmentFailedNullReference();
            }

            return _binder.bindAssignment(lhs, rhs, bIsCompound);
        }
Beispiel #44
0
        public static void Parse()
        {
            var singlePropertiesProduct = new Dictionary <string, Search <string> >
            {
                ["Наименование"] = (node, o) => node
                                   .SelectSingleNode(@"//div[@id='content']//h1")
                                   .InnerText,
                ["Цена"] = (node, o) => node
                           .SelectSingleNode(@"//div[@id=""content""]//table/tr[1]/td[2]/span")
                           .InnerText.Replace("руб.", String.Empty)
                           .Replace(" ", String.Empty),
                [@"""Код артикула"""] = (node, o) => node
                                        .SelectSingleNode(@"//div[@id='content']/div[2]/div/table/tr/td[2]/table/tr[3]/td[2]")
                                        .InnerText,
                ["Размеры"] = (node, o) => node
                              .SelectSingleNode(@"//div[@id='content']/div[2]/div/table/tr/td[2]/table/tr[5]/td[2]")
                              .InnerText,
                ["Описание"] = (node, o) => node
                               .SelectSingleNode(@"//div[@id='description']")
                               .InnerHtml,
                ["Валюта"] = (node, o) => "RUB",
                [@"""Доступен для заказа"""] = (node, o) => "1",
                [@"Статус"] = (node, o) => "1",
            };

            singlePropertiesProduct["Заголовок"] = (node, args) => singlePropertiesProduct["Наименование"](node, args);
            singlePropertiesProduct[@"""Ссылка на витрину"""] = (node, args) =>
                                                                Humanization.GetHumanLink(singlePropertiesProduct["Наименование"](node, args));
            singlePropertiesProduct[@"""Краткое описание"""] = (node, args) => singlePropertiesProduct["Описание"](node, args)
                                                               .Split('.')[0];
            var parser = new LiquiMolyClass(
                isCategory: node => node.SelectNodes(@"//*[@class=""list""]")?.Any() ?? false,
                findProducts: (node, o) => node
                ._SelectNodes(@"//a[img[contains(@id, 'image')]]")
                .Select(x => new ArgumentObject(url: x.Attributes["href"].Value))
                .ToArray(),
                findSubcatalogs: (node, o) => node
                ._SelectNodes(@"//div[@class=""citem""]/a[img]")
                .Select(x => new ArgumentObject(url: x.Attributes["href"].Value
                                                , args: new object[] { (int)o.Args[0] + 1 }))
                .ToArray(),
                singlePropertiesCategory: new Dictionary <string, Search <string> >
            {
                ["Наименование"] = (node, o) => new string('!', (int)o.Args[0]) + node
                                   .SelectSingleNode(@"//div[@id='content']//h1")
                                   .InnerText
            },
                singlePropertiesProduct: singlePropertiesProduct,
                pluralPropertiesProduct: new Dictionary <string, Search <string[]> >
            {
                ["Изображения"] = (node, o) => node
                                  .SelectNodes(@"//div[@id='content']//table//a[@class=""sc_menu_item""]")
                                  .Select(x => x.Attributes["href"].Value)
                                  .ToArray()
            },
                xPathPagination: (node, args) => node
                ._SelectNodes(@"//div[@class=""pagination""]/div[@class=""links""]/a[position() < last() - 1]")
                .Select(x => new ArgumentObject(
                            WebUtility.HtmlDecode(@"http://oksva-tm.ru" + x.Attributes["href"].Value)))
                .ToArray()
                );
            var argument = new ArgumentObject(
                url: @"http://www.pelikan-7.ru/index.php?route=common/home",
                //prefix: @"http://www.pelikan-7.ru/index.php?route=product/category&path=38_45",
                args: new object[] { 0 });

            var collection =
                parser.GetProductOrCategory(parser.GetLinks(argument, @".//*[@id='category_menu']/ul/li/a"));

            //parser.GetProductOrCategory(argument);
            Import.Write(path: "pelikan7.csv",
                         collection: collection.ToArray(),
                         headers: Constants.WebAsystKeys,
                         format: Constants.WebAsystFormatter);
        }
Beispiel #45
0
        /////////////////////////////////////////////////////////////////////////////////

        private EXPR BindIsEvent(
            CSharpIsEventBinder binder,
            ArgumentObject[] arguments,
            Dictionary<int, LocalVariableSymbol> dictionary)
        {
            // The IsEvent binder will never be called without an instance object. This 
            // is because the compiler only gen's this code for dynamic dots.

            EXPR callingObject = CreateLocal(arguments[0].Type, false, dictionary[0]);
            MemberLookup mem = new MemberLookup();
            CType boolType = SymbolLoader.GetReqPredefType(PredefinedType.PT_BOOL);
            bool result = false;

            if (arguments[0].Value == null)
            {
                throw Error.NullReferenceOnMemberException();
            }

            Debug.Assert(_bindingContext.ContextForMemberLookup() != null);
            SymWithType swt = _symbolTable.LookupMember(
                    binder.Name,
                    callingObject,
                    _bindingContext.ContextForMemberLookup(),
                    0,
                    mem,
                    false,
                    false);

            // If lookup returns an actual event, then this is an event.
            if (swt != null && swt.Sym.getKind() == SYMKIND.SK_EventSymbol)
            {
                result = true;
            }

            // If lookup returns the backing field of a field-like event, then
            // this is an event. This is due to the Dev10 design change around
            // the binding of +=, and the fact that the "IsEvent" binding question
            // is only ever asked about the LHS of a += or -=.
            if (swt != null && swt.Sym.getKind() == SYMKIND.SK_FieldSymbol && swt.Sym.AsFieldSymbol().isEvent)
            {
                result = true;
            }

            return _exprFactory.CreateConstant(boolType, ConstValFactory.GetBool(result));
        }
Beispiel #46
0
        public static void Parse()
        {
            var random = new Random();
            var URL    = @"http://www.vesna.kirov.ru";
            var suffix = @"?page_count=1000&sort=PROPERTY_IS_AVAILABLE|DESC&PAGEN_1=13";
            var singlePropertiesProduct = new Dictionary <string, Search <string> >
            {
                ["Наименование"] = (node, args) => node
                                   .SelectSingleNode(@"//h1")
                                   ?.InnerText ?? string.Empty,
                [@"""Код артикула"""] = (node, args) =>
                {
                    Thread.Sleep(1000);
                    Console.WriteLine("Delay");
                    return("VS-" + node
                           .SelectSingleNode(@".//*[@id='content']/div[2]/div/div/div[1]/div[2]/div[2]")
                           ?.InnerText?.Substring(9) ?? string.Empty);
                },
                ["Цена"] = (node, args) => node
                           .SelectSingleNode(@".//*[@id='content']//div[contains(@class, 'pro-roght-price')]")
                           ?.InnerText?.TrimEnd(new[] { '₽', ' ' }) ?? string.Empty,
                ["Описание"] = (node, args) => node
                               .SelectSingleNode(@".//*[@id='tabs']/div/div[1]")
                               ?.InnerHtml ?? string.Empty +
                               node
                               .SelectSingleNode(@".//*[@id='tabs']/div/div[2]")
                               ?.InnerHtml?.Replace("pro-info-list", string.Empty) ?? string.Empty,
                ["Валюта"] = (node, o) => "RUB",
                [@"""Доступен для заказа"""] = (node, o) => "1",
                [@"Статус"] = (node, o) => "1",
            };

            singlePropertiesProduct["Заголовок"] =
                (node, args) => singlePropertiesProduct["Наименование"](node, args);
            singlePropertiesProduct[@"""Ссылка на витрину"""] = (node, args) =>
                                                                Humanization.GetHumanLink(singlePropertiesProduct["Наименование"](node, args) + "-VS-" + random.Next());

            var parser = new LiquiMolyClass(
                isCategory: node => node
                ._SelectNodes(@"//span[contains(text(), 'Сортировка')]")
                .Count != 0,
                findProducts: (node, args) => node
                ._SelectNodes(@"//div[@class='catalog-item']/div[1]/a[1]")
                .Select(x => new ArgumentObject(URL + x.Attributes["href"].Value))
                .ToArray(),
                singlePropertiesCategory: new Dictionary <string, Search <string> >
            {
                ["Наименование"] = (node, args) => new string('!', (int)args.Args[0]) + node
                                   .SelectSingleNode(@"//h1")
                                   .InnerText,
            },
                pluralPropertiesProduct: new Dictionary <string, Search <string[]> >
            {
                ["Изображения"] = (node, args) => node
                                  ._SelectNodes(@"//*[contains(@class,'pic-default')]/div/a/img")
                                  .Select(x => URL + x.Attributes["data-zoom-image"].Value)
                                  .ToArray()
            },
                singlePropertiesProduct: singlePropertiesProduct
                );
            var arguments = new ArgumentObject(
                url: URL,
                //url: @"http://vesna.kirov.ru/catalog/igrushki-iz-pvh/" + suffix,
                args: new object[] { 2 });
            var collection = parser.GetProductOrCategory(parser.GetLinks(args: arguments,
                                                                         prefix: URL,
                                                                         xPath: @".//*[@id='header']/div[2]/div/nav/ul/li[1]/div/ul/li/a",
                                                                         suffix: suffix));

            //var collection = parser.GetProductOrCategory(arguments);
            collection = new[]
            {
                new ProductCategoryObject(
                    new Dictionary <string, string> {
                    ["Наименование"] = "Temporary2"
                }, isCategory: true),
                new ProductCategoryObject(
                    new Dictionary <string, string> {
                    ["Наименование"] = "!VesnaKirov"
                }, isCategory: true)
            }.Extend(collection);
            Import.Write(path: @"..\..\..\CSV\VesnaKirov.csv",
                         collection: collection.ToArray(),
                         headers: Constants.WebAsystKeys,
                         format: Constants.WebAsystFormatter);
        }
Beispiel #47
0
        private bool DeferBinding(
            DynamicMetaObjectBinder payload,
            ArgumentObject[] arguments,
            DynamicMetaObject[] args,
            Dictionary<int, LocalVariableSymbol> dictionary,
            out DynamicMetaObject deferredBinding)
        {
            // This method deals with any deferrals we need to do. We check deferrals up front
            // and bail early if we need to do them.

            // (1) InvokeMember deferral.
            //
            // This is the deferral for the d.Foo() scenario where Foo actually binds to a 
            // field or property, and not a method group that is invocable. We defer to
            // the standard GetMember/Invoke pattern.

            if (payload is CSharpInvokeMemberBinder)
            {
                ICSharpInvokeOrInvokeMemberBinder callPayload = payload as ICSharpInvokeOrInvokeMemberBinder;
                int arity = callPayload.TypeArguments != null ? callPayload.TypeArguments.Count : 0;
                MemberLookup mem = new MemberLookup();
                EXPR callingObject = CreateCallingObjectForCall(callPayload, arguments, dictionary);

                Debug.Assert(_bindingContext.ContextForMemberLookup() != null);
                SymWithType swt = _symbolTable.LookupMember(
                        callPayload.Name,
                        callingObject,
                        _bindingContext.ContextForMemberLookup(),
                        arity,
                        mem,
                        (callPayload.Flags & CSharpCallFlags.EventHookup) != 0,
                        true);

                if (swt != null && swt.Sym.getKind() != SYMKIND.SK_MethodSymbol)
                {
                    // The GetMember only has one argument, and we need to just take the first arg info.
                    CSharpGetMemberBinder getMember = new CSharpGetMemberBinder(callPayload.Name, false, callPayload.CallingContext, new CSharpArgumentInfo[] { callPayload.ArgumentInfo[0] });

                    // The Invoke has the remaining argument infos. However, we need to redo the first one
                    // to correspond to the GetMember result.
                    CSharpArgumentInfo[] argInfos = new CSharpArgumentInfo[callPayload.ArgumentInfo.Count];
                    callPayload.ArgumentInfo.CopyTo(argInfos, 0);

                    argInfos[0] = CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null);
                    CSharpInvokeBinder invoke = new CSharpInvokeBinder(callPayload.Flags, callPayload.CallingContext, argInfos);

                    DynamicMetaObject[] newArgs = new DynamicMetaObject[args.Length - 1];
                    Array.Copy(args, 1, newArgs, 0, args.Length - 1);
                    deferredBinding = invoke.Defer(getMember.Defer(args[0]), newArgs);
                    return true;
                }
            }

            deferredBinding = null;
            return false;
        }
Beispiel #48
0
        /////////////////////////////////////////////////////////////////////////////////

        private EXPR BindCall(
            ICSharpInvokeOrInvokeMemberBinder payload,
            EXPR callingObject,
            ArgumentObject[] arguments,
            Dictionary<int, LocalVariableSymbol> dictionary)
        {
            if (payload is InvokeBinder && !callingObject.type.isDelegateType())
            {
                throw Error.BindInvokeFailedNonDelegate();
            }

            EXPR pResult = null;
            int arity = payload.TypeArguments != null ? payload.TypeArguments.Count : 0;
            MemberLookup mem = new MemberLookup();

            Debug.Assert(_bindingContext.ContextForMemberLookup() != null);
            SymWithType swt = _symbolTable.LookupMember(
                    payload.Name,
                    callingObject,
                    _bindingContext.ContextForMemberLookup(),
                    arity,
                    mem,
                    (payload.Flags & CSharpCallFlags.EventHookup) != 0,
                    true);
            if (swt == null)
            {
                mem.ReportErrors();
                Debug.Assert(false, "Why didn't member lookup report an error?");
            }

            if (swt.Sym.getKind() != SYMKIND.SK_MethodSymbol)
            {
                Debug.Assert(false, "Unexpected type returned from lookup");
                throw Error.InternalCompilerError();
            }

            // At this point, we're set up to do binding. We need to do the following:
            //
            // 1) Create the EXPRLOCALs for the arguments, linking them to the local
            //    variable symbols defined above.
            // 2) Create the EXPRMEMGRP for the call and the EXPRLOCAL for the object
            //    of the call, and link the correct local variable symbol as above.
            // 3) Do overload resolution to get back an EXPRCALL.
            //
            // Our caller takes care of the rest.

            // First we need to check the sym that we got back. If we got back a static 
            // method, then we may be in the situation where the user called the method
            // via a simple name call through the phantom overload. If thats the case,
            // then we want to sub in a type instead of the object.
            EXPRMEMGRP memGroup = CreateMemberGroupEXPR(payload.Name, payload.TypeArguments, callingObject, swt.Sym.getKind());
            if ((payload.Flags & CSharpCallFlags.SimpleNameCall) != 0)
            {
                callingObject.flags |= EXPRFLAG.EXF_SIMPLENAME;
            }

            if ((payload.Flags & CSharpCallFlags.EventHookup) != 0)
            {
                mem = new MemberLookup();
                SymWithType swtEvent = _symbolTable.LookupMember(
                        payload.Name.Split('_')[1],
                        callingObject,
                        _bindingContext.ContextForMemberLookup(),
                        arity,
                        mem,
                        (payload.Flags & CSharpCallFlags.EventHookup) != 0,
                        true);
                if (swtEvent == null)
                {
                    mem.ReportErrors();
                    Debug.Assert(false, "Why didn't member lookup report an error?");
                }

                CType eventCType = null;
                if (swtEvent.Sym.getKind() == SYMKIND.SK_FieldSymbol)
                {
                    eventCType = swtEvent.Field().GetType();
                }
                else if (swtEvent.Sym.getKind() == SYMKIND.SK_EventSymbol)
                {
                    eventCType = swtEvent.Event().type;
                }

                Type eventType = SymbolLoader.GetTypeManager().SubstType(eventCType, swtEvent.Ats).AssociatedSystemType;

                if (eventType != null)
                {
                    // If we have an event hookup, first find the event itself.
                    BindImplicitConversion(new ArgumentObject[] { arguments[1] }, eventType, dictionary, false);
                }
                memGroup.flags &= ~EXPRFLAG.EXF_USERCALLABLE;

                if (swtEvent.Sym.getKind() == SYMKIND.SK_EventSymbol && swtEvent.Event().IsWindowsRuntimeEvent)
                {
                    return BindWinRTEventAccessor(
                                    new EventWithType(swtEvent.Event(), swtEvent.Ats),
                                    callingObject,
                                    arguments,
                                    dictionary,
                                    payload.Name.StartsWith("add_", StringComparison.Ordinal)); //isAddAccessor?
                }
            }

            // Check if we have a potential call to an indexed property accessor.
            // If so, we'll flag overload resolution to let us call non-callables.
            if ((payload.Name.StartsWith("set_", StringComparison.Ordinal) && swt.Sym.AsMethodSymbol().Params.Size > 1) ||
                (payload.Name.StartsWith("get_", StringComparison.Ordinal) && swt.Sym.AsMethodSymbol().Params.Size > 0))
            {
                memGroup.flags &= ~EXPRFLAG.EXF_USERCALLABLE;
            }

            pResult = _binder.BindMethodGroupToArguments(// Tree
                BindingFlag.BIND_RVALUEREQUIRED | BindingFlag.BIND_STMTEXPRONLY, memGroup, CreateArgumentListEXPR(arguments, dictionary, 1, arguments.Length));

            // If overload resolution failed, throw an error.
            if (pResult == null || !pResult.isOK())
            {
                throw Error.BindCallFailedOverloadResolution();
            }
            CheckForConditionalMethodError(pResult);

            return ReorderArgumentsForNamedAndOptional(callingObject, pResult);
        }
        /// <summary>
        /// Outputs 'msg' to the text box in the UI of the application as well as the debug output
        /// console.
        /// </summary>
        /// <param name="msg">Message that will be output in the text box of the UI.</param>
        public void OutputLine(string msg)
        {
            // If this is attempted at OnNavigatedTo() time the result is null.
            this.GetScrollBar();

            string timestampedMsg = DateTime.Now.ToString() + ": " + msg;
            ArgumentObject ao = new ArgumentObject(timestampedMsg + "\n", this.textBoxOutput, this.Scrollbar);

            Dispatcher.RunAsync(
                CoreDispatcherPriority.Normal,
                new DispatchedHandler(ao.OnDispatched)).AsTask();

            System.Diagnostics.Debug.WriteLine(timestampedMsg);
        }
 /// <summary>
 /// Outputs 'msg' to the text box in the UI of the application. We have to dispatch this to
 /// the UI thread.
 /// </summary>
 /// <param name="msg">Message that will be output in the text box of the UI.</param>
 public async void OutputLine(string msg)
 {
     ArgumentObject ao = new ArgumentObject();
     ao.TextBox = this.TextBlockService; // This is the control in our Xaml page.
     ao.Text = msg + "\n";
     await Dispatcher.RunAsync(
         CoreDispatcherPriority.Normal,
         new DispatchedHandler(ao.OnDispatched));
     System.Diagnostics.Debug.WriteLine(msg);
 }
Beispiel #51
0
        private EXPR BindWinRTEventAccessor(EventWithType ewt, EXPR callingObject, ArgumentObject[] arguments, Dictionary<int, LocalVariableSymbol> dictionary, bool isAddAccessor)
        {
            // We want to generate either:
            // WindowsRuntimeMarshal.AddEventHandler<delegType>(new Func<delegType, EventRegistrationToken>(x.add_foo), new Action<EventRegistrationToken>(x.remove_foo), value)
            // or
            // WindowsRuntimeMarshal.RemoveEventHandler<delegType>(new Action<EventRegistrationToken>(x.remove_foo), value)

            Type evtType = ewt.Event().type.AssociatedSystemType;

            // Get new Action<EventRegistrationToken>(x.remove_foo)
            MethPropWithInst removemwi = new MethPropWithInst(ewt.Event().methRemove, ewt.Ats);
            EXPRMEMGRP removeMethGrp = _exprFactory.CreateMemGroup(callingObject, removemwi);
            removeMethGrp.flags &= ~EXPRFLAG.EXF_USERCALLABLE;
            Type eventRegistrationTokenType = SymbolTable.EventRegistrationTokenType;
            Type actionType = Expression.GetActionType(eventRegistrationTokenType);
            EXPR removeMethArg = _binder.mustConvert(removeMethGrp, _symbolTable.GetCTypeFromType(actionType));

            // The value
            EXPR delegateVal = CreateArgumentEXPR(arguments[1], dictionary[1]);
            EXPRLIST args;
            string methodName;

            if (isAddAccessor)
            {
                // Get new Func<delegType, EventRegistrationToken>(x.add_foo)
                MethPropWithInst addmwi = new MethPropWithInst(ewt.Event().methAdd, ewt.Ats);
                EXPRMEMGRP addMethGrp = _exprFactory.CreateMemGroup(callingObject, addmwi);
                addMethGrp.flags &= ~EXPRFLAG.EXF_USERCALLABLE;
                Type funcType = Expression.GetFuncType(evtType, eventRegistrationTokenType);
                EXPR addMethArg = _binder.mustConvert(addMethGrp, _symbolTable.GetCTypeFromType(funcType));

                args = _exprFactory.CreateList(addMethArg, removeMethArg, delegateVal);
                methodName = SymbolLoader.GetNameManager().GetPredefName(PredefinedName.PN_ADDEVENTHANDLER).Text;
            }
            else
            {
                args = _exprFactory.CreateList(removeMethArg, delegateVal);
                methodName = SymbolLoader.GetNameManager().GetPredefName(PredefinedName.PN_REMOVEEVENTHANDLER).Text;
            }

            // WindowsRuntimeMarshal.Add\RemoveEventHandler(...)
            Type windowsRuntimeMarshalType = SymbolTable.WindowsRuntimeMarshalType;
            _symbolTable.PopulateSymbolTableWithName(methodName, new List<Type> { evtType }, windowsRuntimeMarshalType);
            EXPRCLASS marshalClass = _exprFactory.CreateClass(_symbolTable.GetCTypeFromType(windowsRuntimeMarshalType), null, null);
            EXPRMEMGRP addEventGrp = CreateMemberGroupEXPR(methodName, new List<Type> { evtType }, marshalClass, SYMKIND.SK_MethodSymbol);
            EXPR expr = _binder.BindMethodGroupToArguments(
                BindingFlag.BIND_RVALUEREQUIRED | BindingFlag.BIND_STMTEXPRONLY,
                addEventGrp,
                args);

            return expr;
        }
Beispiel #52
0
        private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker bw = sender as BackgroundWorker;

            ArgumentObject arg = e.Argument as ArgumentObject;

            string link = arg.link;

            //DataGridView datagridview = arg.dgv;

            while (link != "")
            {
                if (bw.CancellationPending == true)
                {
                    e.Cancel = true;
                    break;
                }

                nextpagelink = "";

                using (WebClient client = new WebClient())
                {
                    client.Encoding = System.Text.Encoding.UTF8;
                    string resultPage = "";
                    try
                    {
                        resultPage = client.DownloadString(link);
                    }
                    catch (WebException ex)
                    {
                        MessageBox.Show("Nem sikerült csatlakozni a " + website + " oldalhoz!" + Environment.NewLine + "Ellenőrizd az internet kapcsolatod!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        break;
                    }

                    StreamWriter tw = new StreamWriter(webpagefile);
                    tw.Write(resultPage);
                    tw.Close();
                    //Console.WriteLine("letöltve");


                    HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                    doc.Load(webpagefile, System.Text.Encoding.UTF8);
                    //Console.WriteLine("betöltve");

                    string expression = @"//tr[@id='vilagit']";                   //ebbe a tagbe vannak a sorozatok egyessével
                    var    nodes      = doc.DocumentNode.SelectNodes(expression); // az oldalon található összes sorozat bejegyzés

                    if (nodes == null)
                    {
                        File.Delete(webpagefile);
                        break;
                    }


                    foreach (var node in nodes)
                    {
                        //int newrowIndex = this.subtitleListDataGridView.Rows.Add();
                        //DataGridViewRow newrow = this.subtitleListDataGridView.Rows[newrowIndex];
                        //Console.WriteLine(this.subtitleListDataGridView.RowTemplate);
                        //DataGridViewRow newrow = this.subtitleListDataGridView.RowTemplate;
                        FillRow(node);

                        //bw.ReportProgress(1, newrow);
                    }
                    // következő oldal ">"
                    var nextPageNode = doc.DocumentNode.SelectSingleNode(@"//div[@class='pagination']");
                    if (nextPageNode != null)
                    {
                        nav      = nextPageNode.CreateNavigator();
                        expr     = nav.Compile(@"./a[.='>']");
                        iterator = nav.Select(expr);
                        while (iterator.MoveNext())
                        {
                            XPathNavigator nav2 = iterator.Current.Clone();
                            //Console.WriteLine("link:" + website + nav2.GetAttribute("href", ""));
                            nextpagelink = website + nav2.GetAttribute("href", "");
                        }
                    }
                }
                // ha vége a feldolgozásnak file törlés
                File.Delete(webpagefile);

                link = nextpagelink;
            }
        }
Beispiel #53
0
        /////////////////////////////////////////////////////////////////////////////////

        private EXPR BindUnaryOperation(
            CSharpUnaryOperationBinder payload,
            ArgumentObject[] arguments,
            Dictionary<int, LocalVariableSymbol> dictionary)
        {
            if (arguments.Length != 1)
            {
                throw Error.BindUnaryOperatorRequireOneArgument();
            }

            OperatorKind op = GetOperatorKind(payload.Operation);
            EXPR arg1 = CreateArgumentEXPR(arguments[0], dictionary[0]);
            arg1.errorString = Operators.GetDisplayName(GetOperatorKind(payload.Operation));

            if (op == OperatorKind.OP_TRUE || op == OperatorKind.OP_FALSE)
            {
                // For true and false, we try to convert to bool first. If that
                // doesn't work, then we look for user defined operators.
                EXPR result = _binder.tryConvert(arg1, SymbolLoader.GetReqPredefType(PredefinedType.PT_BOOL));
                if (result != null && op == OperatorKind.OP_FALSE)
                {
                    // If we can convert to bool, we need to negate the thing if we're looking for false.
                    result = _binder.BindStandardUnaryOperator(OperatorKind.OP_LOGNOT, result);
                }

                if (result == null)
                {
                    result = _binder.bindUDUnop(op == OperatorKind.OP_TRUE ? ExpressionKind.EK_TRUE : ExpressionKind.EK_FALSE, arg1);
                }

                // If the result is STILL null, then that means theres no implicit conversion to bool,
                // and no user-defined operators for true and false. Just do a must convert to report
                // the error.
                if (result == null)
                {
                    result = _binder.mustConvert(arg1, SymbolLoader.GetReqPredefType(PredefinedType.PT_BOOL));
                }
                return result;
            }
            return _binder.BindStandardUnaryOperator(op, arg1);
        }