Esempio n. 1
0
        public List<String> Import(ImportSiteMessage message)
        {
            Data.Hash importHash = Data.Hash.New(message.ImportHash);
            Data.Guid subscriptionId = Data.Guid.New(message.SubscriptionId);
            Boolean deleteExisting = message.DeleteExisting;

            List<String> status = new List<String>();

            byte[] data;

            AddStatus(importHash, status, "Site import started at " + UtcDateTime.Now.ToString());
            CmsSubscription subscription = SubscriptionManager.GetSubscription(subscriptionId);
            CmsTheme defaultTheme = ThemeManager.Instance.GetDefaultBySite(subscriptionId);

            //Check if the import-template already exists
            CmsTemplate template = TemplateManager.Instance.GetTemplate(subscriptionId, "import-template");
            if (template == null)
            {
                template = new CmsTemplate();
                template.Content = "{content}";
                template.Name = "import-template";
                template.IsGlobalTemplateType = false;
                template.LastSaved = UtcDateTime.Now;
                template.SubscriptionGuid = subscriptionId.Value;
                template.Theme = defaultTheme;

                TemplateManager.Instance.Save(template);
                AddStatus(importHash, status, "Successfully created and associated import template to deafult theme");
            }

            IDictionary<ImportType, IList<ImportedItem>> items = this.GetImportedItems(importHash);

            //Check if we need to delete the existing site
            if (deleteExisting)
            {
                //Erase all of the existing data
                SubscriptionManager.Erase(subscription.Guid, false, false);
                SessionProvider.Instance.Close();
                SessionProvider.Instance.GetOpenSession();

                //Setup the default
                SiteHelper.Configure(subscription.Guid);
            }

            //First, import all of the images
            IList<ImportedItem> images = items[ImportType.Image];
            foreach (ImportedItem image in images)
            {
                CmsUrl uri = new CmsUrl(image.Uri);
                data = SimpleWebClient.GetResponse(uri.ToUri());

                ImageManager.Instance.AddImage(subscriptionId, StorageClientConst.RootFolder, uri.Path, image.ContentType, data);
                AddStatus(importHash, status, "Successfully imported image: " + uri.ToString() + " (" + image.ContentType + ")");
            }

            //Create the sitemap and then add the page itself
            CmsSitePath root = CmsSiteMap.Instance.GetPath(subscriptionId, CmsSiteMap.RootPath);

            Dictionary<CmsUrl, int> cssUses = new Dictionary<CmsUrl, int>();
            Dictionary<CmsUrl, int> jsUses = new Dictionary<CmsUrl, int>();

            IList<ImportedItem> pages = NormalizeImport(items[ImportType.Page]);
            foreach (ImportedItem page in pages)
            {
                try
                {
                    CmsUrl uri = new CmsUrl(page.Uri);
                    CmsUrlWalker walker = new CmsUrlWalker(uri);

                    while (walker.Next())
                    {
                        String parent = walker.GetParentPath();
                        String current = walker.GetIndividualPath();
                        String fullpath = CmsSiteMap.PathCombine(parent, current);
                        int depth = walker.Depth;

                        if (!walker.IsLast)
                        {
                            //Check if the current path exists, if not, create it
                            if (!CmsSiteMap.Instance.Exists(subscriptionId, fullpath))
                                CmsSiteMap.Instance.AddChildDirectory(subscriptionId, parent, current);
                        }
                    }

                    String pageName = walker.GetIndividualPath();
                    CmsPage newpage = GetPage(template.Name, subscription.Culture, pageName, message.ReplacePhoneNumbers, page, cssUses, jsUses);
                    newpage.SubscriptionId = subscriptionId.Value;

                    //Add the page to the cms system
                    PageManager.Instance.AddNewPage(walker.GetParentPath(), pageName, newpage);
                    AddStatus(importHash, status, "Successfully imported page " + page.Uri);
                }
                catch (Exception ex)
                {
                    if (!ex.Message.Contains("404"))
                        Logging.Database.Write("import-site-manager", "Failed to import page: " + page.Uri + ", cause:" + ex.Message + ", stack:" + ex.StackTrace);
                    AddStatus(importHash, status, "Failed to import page " + page.Uri + ", Reason:" + ex.Message);
                }
            }

            //Import the css
            IList<ImportedItem> css = items[ImportType.Css];

            int sortOrder = 0;
            CssManager cssManager = new CssManager(null);
            cssManager.SubscriptionId = subscriptionId;
            foreach (ImportedItem item in css)
            {
                CmsUrl uri = new CmsUrl(item.Uri);
                data = SimpleWebClient.GetResponse(uri.ToUri());

                cssManager.Save(defaultTheme.ThemeGuid, uri.Path, data, true, 0);
                cssManager.UpdateSortInfo(defaultTheme, uri.Path, sortOrder++);
                AddStatus(importHash, status, "Successfully imported css file: " + uri.ToString());
            }

            //Import the javascript
            IList<ImportedItem> js = items[ImportType.Javascript];

            sortOrder = 0;
            JavascriptManager jsManager = new JavascriptManager(null);
            jsManager.SubscriptionId = subscriptionId;
            foreach (ImportedItem item in js)
            {
                CmsUrl uri = new CmsUrl(item.Uri);
                data = SimpleWebClient.GetResponse(uri.ToUri());

                jsManager.Save(defaultTheme.ThemeGuid, uri.Path, data, true, 0);
                jsManager.UpdateSortInfo(defaultTheme, uri.Path, sortOrder++);
                AddStatus(importHash, status, "Successfully imported javascript file: " + uri.ToString());
            }

            //Import any documents
            IList<ImportedItem> documents = items[ImportType.Document];
            foreach (ImportedItem item in documents)
            {
                CmsUrl uri = new CmsUrl(item.Uri);

                ContentFileUploadImpl handler = new ContentFileUploadImpl();
                String filename = uri.Path;
                if (ContentFileUploadImpl.IsValidFileType(filename))
                {
                    data = SimpleWebClient.GetResponse(uri.ToUri());

                    handler.Save(subscriptionId, data, uri.Path, true);
                }
            }

            AddStatus(importHash, status, "Site import completed successfully at " + UtcDateTime.Now.ToString());

            ImportedItemDao dao = new ImportedItemDao();
            dao.DeleteAllByImportHash(importHash);

            return status;
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            IList<ImportedItem> imports = ImportManager.Instance.GetImportedItems(Data.Hash.New("39815301DDC751A5086141163128A817"))[ImportType.Page];
            imports = ImportManager.NormalizeImport(imports);
            foreach (ImportedItem page in imports)
            {
                CmsUrl uri = new CmsUrl(page.Uri);
                CmsUrlWalker walker = new CmsUrlWalker(uri);

                while (walker.Next())
                {
                    String parent = walker.GetParentPath();
                    String current = walker.GetIndividualPath();
                    String fullpath = CmsSiteMap.PathCombine(parent, current);
                    int depth = walker.Depth;

                    if (!walker.IsLast)
                    {
                        //Check if the current path exists, if not, create it
                        //if (!CmsSiteMap.Instance.Exists(subscriptionId, fullpath))
                            Console.WriteLine("Adding directory " + current + " as child of " + parent);
                            //CmsSiteMap.Instance.AddChildDirectory(subscriptionId, parent, current);
                    }
                }
                String pageName = walker.GetIndividualPath();
                Console.WriteLine("Adding page:" + pageName + " as child of " + walker.GetParentPath());
            }
            Console.ReadLine();

            /*
            ImportedItem item = new ImportedItem();
            item.Uri = "tesT";
            item.Expires = DateTime.Now;
            item.Inserted = DateTime.Now;

            ImportedItemDao dao = new ImportedItemDao();
            using (Transaction tx = new Transaction())
            {
                dao.Save<ImportedItem>(item);
                tx.Commit();
            }
            */

            /*
            String html = "<img src=\"../images/test.jpg\" /><img src=\"http://www.google.com/image.jpg\" /><img src='images/blah.gif'>";
            html = new ImageRewriter("location").Rewrite(html);
            */

            /*
            GooeyCrawler crawler = new GooeyCrawler(new Uri("http://tribecadentaldesign.com"));
            crawler.AddPipelineStep(new CssImageProcessor());
            crawler.AddPipelineStep(new ConsoleOutputProcessor());
            //crawler.AddPipelineStep(new DatabasePersistenceProcessor(Data.Guid.Empty));
            crawler.Progress += new EventHandler<Business.Import.Events.CrawlProgressEventArgs>(crawler_Progress);
            crawler.Crawl();
            */

            /*
            CmsUrl url = new CmsUrl("http://www.a123systems.com/Collateral/Templates/English-US/images/topnav_about_on.gif");
            CmsUrlWalker walker = new CmsUrlWalker(url);
            while (walker.Next())
            {
                int depth = walker.Depth;
                String indivdual = walker.GetIndividualPath();
                String path = walker.GetCurrentPath();

                Console.WriteLine(walker.GetParentPath() + "," + walker.GetCurrentPath() + "," + depth);
            }
            */

            /*
            ImportedItem item = new ImportedItem();
            item.Uri = "http://www.a123systems.com/Collateral/Flash/English-US/Animation/bae_pack.html";
            CmsUrl uri = new CmsUrl(item.Uri);
            CmsUrlWalker walker = new CmsUrlWalker(uri);

            while (walker.Next())
            {
                String parent = walker.GetParentPath();
                String current = walker.GetIndividualPath();
                String fullpath = CmsSiteMap.PathCombine(parent, current);
                int depth = walker.Depth;

                if (!walker.IsLast)
                {
                    //Check if the current path exists, if not, create it
                    if (!CmsSiteMap.Instance.Exists("99a2a4a3-6748-4155-8bf2-fb781b7d8ccc", fullpath))
                        CmsSiteMap.Instance.AddChildDirectory("99a2a4a3-6748-4155-8bf2-fb781b7d8ccc", parent, current);
                }
            }

            String pageName = walker.GetIndividualPath();
            CmsPage page = ImportManager.Instance.GetPage("copyright.htm", "en-us", "import-template", item);
            */

            /*
            TwilioClient client = new TwilioClient("ACe6a95690dcdee460400d44ae94e4e637", "707b003f01b09e45d998a487828c8625");
            client.SearchAvailableLocalNumbers("123");
            */

            /*
            client.PurchasePhoneNumber("816", "http://control.gooeycms.com/twilio-handler.aspx");
            */

            /*
            IList<AvailablePhoneNumber> numbers = client.SearchAvailableLocalNumbers("816");
            foreach (AvailablePhoneNumber number in numbers)
            {
                System.Console.WriteLine(number.FriendName);
            }

            IList<AvailablePhoneNumber> numbers2 = client.SearchAvailableTollFreeNumbers();
            foreach (AvailablePhoneNumber number in numbers2)
            {
                System.Console.WriteLine(number.FriendName);
            }
            System.Console.ReadLine();
            */

            /*
            GooeyCrawler crawler = new GooeyCrawler(new Uri("http://www.emaildatasource.com/"));
            crawler.GetSiteMap();
            */

            /*
            WebSiteDownloaderOptions options = new WebSiteDownloaderOptions();
            options.DownloadUri = new Uri("http://www.firstmgt.com");
            options.MaximumLinkDepth = 3;
            options.StayOnSite = true;

            WebSiteDownloader downloader = new WebSiteDownloader(options);
            downloader.Process();
             */

            /*
            String test = "\u001FTESTING\u001FTESTING1\u001FTESTING2";
            Console.WriteLine(test);

            String[] items = test.Split('\u001F');
            foreach (String item in items)
                Console.WriteLine(item);
            Console.ReadLine();
             */
            /*
            string test =
            @"
            #H1 Header
            ##H2 Header
            ###H3 Header
            ####H4 Header

            *Hello World*
            **Hello World2**

            Link Style 1 [Google][1]
            Link Style 2 [Google](http://www.google.com ""Title Attribute"")
            Link Style 3 [Google][google]
            Link Style 4 http://www.google.com
            Link Style 5 <http://www.google.com>?

            [1]: http:/www.google.com ""Title Attribute""
            [google]: http://www.google.com ""Title Attribute""

            This is a test <*****@*****.**>

            + Item 1
            + Item 2
            + Item 3 With Sub Items
            - Must be tabbed or indented
            * Sub list again
            - More content

            This paragraph is still part of item 3

            > This is a blockquote
            > Blockquote Line 2
            >
            > Newline in the blockquote

            ![Image Alt Text](http://w3.org/Icons/valid-xhtml10)

            Testing manual line break{BR}
            This is a test{BR}

            [form responseTemplate=""myresponse.tpl"" emailTo=""*****@*****.**"" submitText=""Register""]
            [table]
            --------------
            <textbox fname>
            ||
            Hello World
            ---------------
            ---------------
            This is a test
            ||
            <textarea cols=15 rows=5 comments>
            -----------------
            [/table]
            [/form]
            ";
            MarkdownSharp.Markdown m = new MarkdownSharp.Markdown();
            m.AutoHyperlink = true;
            m.LinkEmails = true;
            String result = m.Transform(test);

            Console.WriteLine(test);
            Console.WriteLine("----------------");
            Console.WriteLine(result);
            Console.ReadLine();

            File.WriteAllText("c:\\markup.txt",test + "\r\n----------------\r\n" + result);
            File.WriteAllText("c:\\markup.html", "<html><head></head><body>" + result + "</body></html>");
            }
            */
        }