Exemplo n.º 1
0
        /// <summary>
        /// Analyzes website and creates XML document
        /// </summary>
        /// <param name="config">Website's config</param>
        /// <returns>
        /// Updated website's config
        /// </returns>
        public WebsiteModel AnalyzeWebsite(WebsiteModel config)
        {
            CrawlerHelper crawlHelper = new CrawlerHelper();
            OrganizerHelper orgHelper = new OrganizerHelper();

            config.OrganizerConfig = new OrganizerModel();
            config.ExportConfig = new ExportModel();
            config.ExportConfig.Xml = string.Empty;

            var crawler = crawlHelper.ConfigureCrawler(config.CrawlerConfig);
            var list = crawler.Crawl();

            var analyzer = new WebsiteAnalyzer(config.AnalyzerConfig);
            var analyticsRunner = new AnalyticsRunner(crawler, analyzer);

            var site = analyticsRunner.Run(list);

            site.Name = config.Name;

            using (var sw = new StringWriter())
            {
                var serializer = new XmlSerializer(typeof(Site));
                serializer.Serialize(sw, site);

                config.ExportConfig.Xml = sw.ToString();
            }
                
            config.OrganizerConfig.Pages = orgHelper.AddChildren(site.Root, site);

            return config;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Updates website's config if needed and maps it to database mirror
        /// </summary>
        /// <param name="website">Website's mirror for XML comparsion</param>
        /// <param name="config">Website's config</param>
        /// <returns>
        /// Database mirror
        /// </returns>
        public WebsiteMirror MapModelToMirror(WebsiteMirror website, WebsiteModel config)
        {
            OrganizerHelper orgHelper = new OrganizerHelper();

            website.Name = config.Name;

            website.Xml = config.ExportConfig.Xml;
            website.Xsl = config.ExportConfig.Xsl;

            config.ExportConfig.Xml = string.Empty;
            config.ExportConfig.Xsl = string.Empty;

            // If XML is downloaded, retrieve it from the database, and deserialize and update each page of config.OrganizerModel
            if (website.Xml != string.Empty && website.Xml != null)
            {
                Site site;

                // Deserialize XML
                using (var sw = new StringReader(website.Xml))
                {
                    var serializer = new XmlSerializer(typeof(Site));
                    site = (Site)serializer.Deserialize(sw);
                }

                // Find changes in pages and properties (names, properties) and handle them
                orgHelper.UpdateChildren(site.Root, site, config);                

                // Turn the object into XML
                using (var sw = new StringWriter())
                {
                    var serializer = new XmlSerializer(typeof(Site));
                    serializer.Serialize(sw, site);

                    website.Xml = sw.ToString();
                }

                // Update each page of config.OrganizerModel
                config.OrganizerConfig.Pages = orgHelper.AddChildren(site.Root, site);
            }

            // Finally, update website's config
            website.Config = JsonConvert.SerializeObject(config);

            return website;
        }
Exemplo n.º 3
0
        public WebsiteModel PostRunImport(WebsiteModel config)
        {
            OrganizerHelper orgHelper = new OrganizerHelper();

            //apply XSL
            string finalXml;
            if(config.ExportConfig.Xsl == null || config.ExportConfig.Xsl.Length == 0)
            {
                finalXml = config.ExportConfig.Xml;
            }
            else
            {
                finalXml = orgHelper.XslTransform(config.ExportConfig.Xml, config.ExportConfig.Xsl);
            }

            // na serializer zavolat novou metodu, která deserializuje jen XML - do objektu Site
            Site site;

            using (var sw = new StringReader(finalXml))
            {
                var serializer = new XmlSerializer(typeof(Site));
                site = (Site)serializer.Deserialize(sw);
            }

            WebpackImporter importer = new WebpackImporter();
            importer.Import(site,ApplicationContext.Current);

            //ApplicationContext.Services.ContentTypeService
             
            return config;
        }
Exemplo n.º 4
0
        public WebsiteModel PostTransformXml(WebsiteModel config)
        {
            OrganizerHelper orgHelper = new OrganizerHelper();

            config.ExportConfig.XmlPreview = config.ExportConfig.Xsl != string.Empty ? orgHelper.XslTransform(config.ExportConfig.Xml, config.ExportConfig.Xsl) : config.ExportConfig.Xml;
            
            return config;
        }