Exemplo n.º 1
0
        public static void Main(string[] args)
        {
            var obGetter     = new ContentGetter();
            var domainsList  = FileGetter.GetDomainsFromFile();
            var countDomains = domainsList.Count();
            var obTasks      = new Task[countDomains];

            char[] arSymbolForReplace = { '/', ':', '?' };

            Console.WriteLine("Введите путь или нажмите \"Enter\"");

            var pathForResult = Console.ReadLine();

            if (string.IsNullOrEmpty(pathForResult))
            {
                pathForResult = @"D:\HtmlPages";
            }

            if (pathForResult.Substring(pathForResult.Length - 1) == "\\")
            {
                pathForResult += "\\";
            }

            Directory.CreateDirectory(pathForResult);

            for (var i = 0; i < countDomains; i++)
            {
                var domain        = domainsList.ElementAt(i);
                var changedDomain = Helper.ReplaceSymbolInString(domain, arSymbolForReplace);
                var linkList      = new HashSet <string> {
                    domain
                };
                var pathForElements = pathForResult + "\\" + changedDomain;
                var linkCrawlDelay  = Convert.ToDouble(ContentGetter.GetCrawlDelay(domain + "/" + "robots.txt").Result);

                Directory.CreateDirectory(pathForElements);

                if (domain.Substring(domain.Length - 1) == "/")
                {
                    linkCrawlDelay = Convert.ToDouble(ContentGetter.GetCrawlDelay(domain + "robots.txt").Result);
                }

                obTasks[i] = new Task(() => obGetter.GetContent(linkList, pathForElements, linkCrawlDelay));
                obTasks[i].Start();
            }

            Task.WaitAll(obTasks);

            Console.WriteLine("Страницы с сайтов были загружены");

            Console.ReadLine();
        }
Exemplo n.º 2
0
        public async Task <ItemResponse> Get(string type, string value)
        {
            var content = await ContentGetter.GetAsync(type, value).ConfigureAwait(false);

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

            var ancestors = await AncestorProvider.GetAncestorsAsync(content).ConfigureAwait(false);

            return(new ItemResponse(GetItem(content), ancestors.Select(a =>
            {
                var id = "{" + string.Join(",", PrimaryKeyGetter.Get(a)) + "}";
                return new ItemParent((a as INameable)?.Name ?? id, id);
            }).ToList().AsReadOnly()));
        }
Exemplo n.º 3
0
        public async Task <IEnumerable <string> > GetUrl(string[] id, string contentTypeId)
        {
            var contentType = ContentTypeProvider.Get(contentTypeId);

            var content = await ContentGetter.GetAsync(contentTypeId, PrimaryKeyConverter.Convert(id, contentTypeId)).ConfigureAwait(false);

            var contentRouteSegment = await UrlProvider.GetAsync(content).ConfigureAwait(false);

            var contentRoutes = ContentRouteMatcher.GetFor(contentType);

            var result = new List <string>();

            foreach (var contentRoute in contentRoutes)
            {
                result.Add(contentRoute.Apply(contentRouteSegment));
            }

            return(result.AsReadOnly());
        }
Exemplo n.º 4
0
        public async Task InitializeAsync()
        {
            foreach (var singleton in SingletonProvider.GetAll())
            {
                var content = await ContentGetter.GetAsync(singleton.ContentTypeId, singleton.KeyValues);

                var contentType = ContentTypeProvider.Get(singleton.ContentTypeId);

                if (content != null)
                {
                    continue;
                }

                content = ContentInstanceCreator.Create(contentType);

                PrimaryKeySetter.Set(singleton.KeyValues, content);

                await ContentInserter.InsertAsync(content).ConfigureAwait(false);
            }
        }
Exemplo n.º 5
0
        private async void Init()
        {
            await WaitForForm();

            Window.SetClickThrough(true);
            Window.SetAlwaysOnTop(true);
            Window.MoveTop();
            try {
                //Window.Pin(true);
            } catch { Console.WriteLine($"{nameof(IndicatorBox)} pinning failed"); }

            var area = Window.Area;

            area.BottomLeft = Monitor.Primary.Area.TopLeft;
            Window.Move(area);
            await Window.Animate(AreaSetter(Window.Area), 500, Curves.FExpo).WaitForStop();

            var transparent = false;

            while (IsAlive)
            {
                var contains = Window.ContainsMouse();
                if (!transparent && contains)
                {
                    transparent = true;
                    Window.SetOpacity(0.2);
                }
                else if (transparent && !contains)
                {
                    transparent = false;
                    Window.SetOpacity(1);
                }

                if (ContentGetter != null)
                {
                    SetContent(ContentGetter.Invoke());
                }
                await Task.Delay(UpdateDelay);
            }
        }
Exemplo n.º 6
0
        public void Initialize()
        {
            foreach (var singleton in SingletonProvider.GetAll())
            {
                var content     = ContentGetter.Get <IContent>(singleton.Id, null);
                var contentType = ContentTypeProvider.Get(singleton.ContentTypeId);

                if (content != null)
                {
                    if (content.ContentTypeId != contentType.Id)
                    {
                        throw new SingletonWithIdIsOfWrongType(singleton.Id, contentType, content.GetType(), content.ContentTypeId);
                    }

                    continue;
                }

                content = (IContent)Activator.CreateInstance(contentType.Type);

                content.Id = singleton.Id;

                ContentInserter.Insert(content);
            }
        }
Exemplo n.º 7
0
        public string Get(IContent content)
        {
            var routable = content as IRoutable;

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

            var hierarchical = content as IHierarchical;

            if (hierarchical == null)
            {
                if (routable.UrlSegment == null)
                {
                    return("/");
                }

                return(routable.UrlSegment);
            }

            var languageSpecific = content as ILanguageSpecific;

            var allContent = AncestorsRepository.GetAncestorLinks(content.Id).Reverse().Select(id => ContentGetter.Get <IContent>(id, languageSpecific?.Language));

            if (allContent.Any(c => !(c is IRoutable)))
            {
                return(null);
            }

            var segments = allContent.Cast <IRoutable>().Select(c => c.UrlSegment).ToList();

            if (segments.Any() && segments.First() == null)
            {
                segments = segments.Skip(1).ToList();
            }

            if (segments.Contains(null))
            {
                return(null);
            }

            segments.Add(routable.UrlSegment);

            return("/" + string.Join("/", segments));
        }
        public async Task <ContentResponseMessage> SaveContent([FromBody] SaveContentRequestBody data)
        {
            if (!ModelState.IsValid)
            {
                return(ContentResponseMessage.CreateFrom(ModelState));
            }

            var contentType = ContentTypeProvider.Get(data.ContentTypeId);

            var b = JsonConvert.DeserializeObject(data.Content, contentType.Type, PolymorphicFormConverter);

            if (!TryValidateModel(b))
            {
                return(ContentResponseMessage.CreateFrom(ModelState));
            }

            if (PrimaryKeyGetter.Get(b).All(id => id != null))
            {
                var a = await ContentGetter.GetAsync(contentType.Id, PrimaryKeyConverter.Convert(data.KeyValues, contentType.Id)).ConfigureAwait(false);

                foreach (var coreInterface in ContentTypeCoreInterfaceProvider.GetFor(contentType.Id))
                {
                    foreach (var propertyDefinition in coreInterface.PropertyDefinitions)
                    {
                        var display = propertyDefinition.Attributes.OfType <DisplayAttribute>().FirstOrDefault();

                        if (display != null && display.GetAutoGenerateField() == false)
                        {
                            continue;
                        }

                        propertyDefinition.Setter(a, propertyDefinition.Getter(b));
                    }
                }

                foreach (var propertyDefinition in PropertyDefinitionProvider.GetFor(contentType.Id))
                {
                    var display = propertyDefinition.Attributes.OfType <DisplayAttribute>().FirstOrDefault();

                    if (display != null && display.GetAutoGenerateField() == false)
                    {
                        continue;
                    }

                    propertyDefinition.Setter(a, propertyDefinition.Getter(b));
                }

                if (!TryValidateModel(b))
                {
                    throw new Exception("a was valid but b was not.");
                }

                await ContentUpdater.UpdateAsync(a).ConfigureAwait(false);

                return(new ContentResponseMessage(true, "Updated"));
            }
            else
            {
                await ContentCreator.CreateAsync(b).ConfigureAwait(false);

                return(new ContentResponseMessage(true, "Created"));
            }
        }