Beispiel #1
0
        static int ProcessImages(string article_uid, List <CONTENT_ITEM> ContentItems)
        {
            int NumberOfImages = 0;

            foreach (CONTENT_ITEM ContentItem in ContentItems)
            {
                string       uid        = ContentItem.CONTENT_ITEM_UID;
                List <IMAGE> ImageItems = BusinessModel.GetImageItems(uid);
                foreach (IMAGE ImageItem in ImageItems)
                {
                    string errmsg     = "";
                    string imgurl     = ImageItem.IMAGE_URL;
                    bool   fileExists = false;
                    string ImageUrl   = ConfigurationManager.AppSettings["ImageUrl"];
                    if (imgurl.StartsWith(ImageUrl))
                    {
                        string uncBasePath = ConfigurationManager.AppSettings["uncBasePath"];
                        string image_unc   = imgurl.Replace(ImageUrl, string.Format(@"{0}\", uncBasePath)).Replace(@"/", @"\");
                        string dom         = ConfigurationManager.AppSettings["uncDomain"];
                        string user        = ConfigurationManager.AppSettings["uncUser"];
                        string pwd         = ConfigurationManager.AppSettings["uncPwd"];
                        fileExists = DoesFileExist(uncBasePath, user, pwd, dom, image_unc);
                    }
                    else
                    {
                        fileExists = rc.ImageExists(ImageItem.IMAGE_URL);
                    }
                    if (fileExists)
                    {
                        int?   filesize   = (ImageItem.FILE_SIZE == null) ? 0 : ImageItem.FILE_SIZE;
                        string caption    = (ImageItem.CAPTION == null) ? "" : ImageItem.CAPTION;
                        string media_type = (ImageItem.MEDIA_SIZE_TYPE_UCODE == null) ? "" : ImageItem.MEDIA_SIZE_TYPE_UCODE;
                        Dbcommon.spExecute("LoadImage", ref errmsg, "@article_uid", article_uid, "@asset_uid", uid, "@imagepath", ImageItem.IMAGE_URL, "@position", "0", "@width", ImageItem.WIDTH, "@height", ImageItem.HEIGHT, "@caption", caption, "@filesize", filesize, "@media_type", media_type);
                        if (errmsg.Length > 0)
                        {
                            writetolog(string.Format("Article id: {0} LoadImage {1} ", article_uid, errmsg));
                        }
                        else
                        {
                            NumberOfImages += 1;
                        }
                    }// end if fileExists
                    if (!fileExists)
                    {
                        Console.WriteLine("Image does not exist {0}", ImageItem.IMAGE_URL);
                    }
                } // foreach IMAGE
            }     // foreach contentitem
            return(NumberOfImages);
        }         // ProcessImages
Beispiel #2
0
        }         // ProcessFreeForms

        static void UpdateRelatedContent(string article_uid, List <CONTENT_ITEM_REL> RelatedContentitems, ref int NumberOfImages)
        {
            NumberOfImages = 0;
            int NumberofPdfs = 0, Numberoffreeforms = 0;
            Predicate <CONTENT_ITEM> FindImage = (CONTENT_ITEM p) => { return(p.CONTENT_TYPE_UID == (int)BusinessModel.asset.image); };
            Predicate <CONTENT_ITEM> FindPdf = (CONTENT_ITEM p) => { return(p.CONTENT_TYPE_UID == (int)BusinessModel.asset.pdf); };
            Predicate <CONTENT_ITEM> FreeForm = (CONTENT_ITEM p) => { return(p.CONTENT_TYPE_UID == (int)BusinessModel.asset.freeform); };

            List <CONTENT_ITEM> MyContentItems = new List <CONTENT_ITEM>();

            foreach (CONTENT_ITEM_REL RelatedContentitem in RelatedContentitems)
            {
                string uid = RelatedContentitem.RELATED_CONTENT_ITEM_UID;
                List <CONTENT_ITEM> ContentItems = BusinessModel.GetContentItems(uid);
                MyContentItems.AddRange(ContentItems);
            }
            List <CONTENT_ITEM> ImageContentItems = MyContentItems.FindAll(FindImage);

            if (ImageContentItems.Count > 0)
            {
                NumberOfImages = ProcessImages(article_uid, ImageContentItems);
            }

            List <CONTENT_ITEM> PdfContentItems = MyContentItems.FindAll(FindPdf);

            if (PdfContentItems.Count > 0)
            {
                NumberofPdfs = ProcessPdfs(article_uid, PdfContentItems);
            }
            List <CONTENT_ITEM> FreeformContentItems = MyContentItems.FindAll(FreeForm);

            if (FreeformContentItems.Count > 0)
            {
                Numberoffreeforms = ProcessFreeForms(article_uid, FreeformContentItems);
            }
        } //UpdateRelatedContent
Beispiel #3
0
        static void Main(string[] args)
        {
            int           articleCount = 0;
            bool          show_help    = false;
            List <string> extra;
            List <string> siteCodes  = new List <string>();
            List <string> Logfiles   = new List <string>();
            List <string> startDates = new List <string>();
            List <string> endDates   = new List <string>();
            var           p          = new OptionSet()
            {
                { "c|sitecode=", " (required) the source Site Code.", v => siteCodes.Add(v) },
                { "s|start=", " (required) the start Date.", v => startDates.Add(v) },
                { "e|end=", " (required) the End Date.", v => endDates.Add(v) },
                { "l|log=", " (required) log filename.", v => Logfiles.Add(v) },
                { "h|help", " Show this message and exit", v => show_help = v != null },
            };

            try
            {
                extra = p.Parse(args);
            }
            catch (OptionException e)
            {
                Console.Write("migration: ");
                Console.WriteLine(e.Message);
                Console.WriteLine("Try migration --help for more information.");
                return;
            }

            if (show_help)
            {
                ShowHelp(p);
                Console.ReadLine();
                return;
            }

            bool valid = true;

            if (!CheckArgument(siteCodes, "sitecode"))
            {
                valid = false;
            }
            if (!CheckArgument(Logfiles, "Log"))
            {
                valid = false;
            }
            if (!CheckArgument(startDates, "start"))
            {
                valid = false;
            }
            if (!CheckArgument(endDates, "end"))
            {
                valid = false;
            }
            if (!valid)
            {
                wait();
                return;
            }

            string   siteid    = siteCodes[0];
            DateTime startdate = DateTime.ParseExact(startDates[0], "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture);
            DateTime stopDate  = DateTime.ParseExact(endDates[0], "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture);

            LogFileName = Logfiles[0];
            List <CONTENT_ITEM> ContentItemRows = BusinessModel.GetContentItems(siteid, (int)BusinessModel.asset.article, startdate, stopDate);

            Console.WriteLine("Total Articles: {0} ", ContentItemRows.Count);
            int      total       = ContentItemRows.Count;
            float    throttle    = 0;
            DateTime startwatch2 = DateTime.Now;
            int      cnt         = 0;

            foreach (CONTENT_ITEM ContentItemRow in ContentItemRows)
            {
                string article_uid    = ContentItemRow.CONTENT_ITEM_UID;
                int    NumberOfImages = 0;
                bool   articleExists  = BusinessRule.BusinessRule.DoesArticleExist(article_uid);
                if (!articleExists)
                {
                    //   Console.WriteLine("Start Get Related Content Articles: {0} ", article_uid);

                    List <CONTENT_ITEM_REL> RelatedContentitems = BusinessModel.GetRelatedContentitems(article_uid);
                    if (RelatedContentitems.Count > 0)
                    {
                        UpdateRelatedContent(article_uid, RelatedContentitems, ref NumberOfImages);
                    } // RelatedContentitems
                    //   Console.WriteLine("Finished Get Related Content Articles: {0} ", article_uid);

                    UpdateArticle(siteid, article_uid, ContentItemRow, NumberOfImages);
                }
                else
                {
                    // Console.WriteLine(string.Format("Article: {0} exists already skip...", article_uid));
                }
                articleCount += 1;
                if ((articleCount % 100) == 0)
                {
                    TimeSpan t2        = DateTime.Now.Subtract(startwatch2);
                    int      remaining = total - articleCount;
                    float    avg       = (float)t2.Seconds / 100;
                    throttle += avg;
                    cnt      += 1;
                    avg       = throttle / (float)cnt;
                    float    totaverage = (float)remaining * avg; // Number of seconds remaining
                    TimeSpan t3         = TimeSpan.FromSeconds(totaverage);
                    Console.WriteLine(string.Format("{0}/{1} Remaining Time Est: {2}", articleCount, total, t3));
                    startwatch2 = DateTime.Now;
                }
            } // foreach
        }     // main