Пример #1
0
        /// <summary>
        /// Thread versuib of Get product. Get ll products in Shopify
        /// </summary>
        public static void GetProductThread()
        {
            int           total = Task.Run(() => { return(getProductService.CountAsync()); }).Result;
            int           pages = (int)Math.Ceiling(total / (decimal)limit);
            ProductFilter pf    = new ProductFilter()
            {
                Limit = limit
            };

            for (int i = 1; i <= pages; i++)
            {
                pf.Page = i;
                productQueue.AddRange(Task.Run(() => { return(getProductService.ListAsync(pf)); }).Result);
            }
            productDone = true;
            GeneralAdapter.OutputString("GetProductThread done.");
        }
Пример #2
0
        private Task <Exception> GetLink(Url link, SemaphoreSlim semaphore)
        {
            return(Task.Run(async() =>
            {
                await semaphore.WaitAsync();
                try
                {
                    using (var client = _client.Create())
                    {
                        var result = await client.Download(link).ConfigureAwait(false);
                        if (result.Data.IsEmpty() || !result.Data.ToLowerInvariant().Contains("<html"))
                        {
                            if (result.ErrorCode != 404)
                            {
                                throw new ApplicationException($"Empty data. Page {link}. Code {result.ErrorCode}");
                            }
                            return null;
                        }

                        result.Data = _simplifier.Simplify(result.Data);
                        _queue.AddRange(
                            HtmlHelpers.GetAllLinks(result.Data, result.Url)
                            .Select(x => x.Fix())
                            .Where(x => x != null && x.Domain == _domain.Domain)
                            );

                        _writer.Write(result.Data, result.Url.ToString());
                        return null;
                    }
                }
                catch (Exception ex)
                {
                    return ex;
                }
                finally
                {
                    semaphore.Release();
                }
            }));
        }
Пример #3
0
        /// <summary>
        /// Get the path-detectable protections associated with a single path
        /// </summary>
        /// <param name="path">Path of the directory to scan</param>
        /// <param name="files">Files contained within</param>
        /// <returns>Dictionary of list of strings representing the found protections</returns>
        private ConcurrentDictionary <string, ConcurrentQueue <string> > GetDirectoryPathProtections(string path, List <string> files)
        {
            // Create an empty queue for protections
            var protections = new ConcurrentQueue <string>();

            // Preprocess the list of files
            files = files.Select(f => f.Replace('\\', '/')).ToList();

            // Iterate through all path checks
            Parallel.ForEach(pathCheckClasses, pathCheckClass =>
            {
                ConcurrentQueue <string> protection = pathCheckClass.CheckDirectoryPath(path, files);
                if (protection != null)
                {
                    protections.AddRange(protection);
                }
            });

            // Create and return the dictionary
            return(new ConcurrentDictionary <string, ConcurrentQueue <string> >
            {
                [path] = protections
            });
        }