Example #1
0
        public static void DoWork()
        {
            string timeStamp = DateTime.Now.ToString("yyyyMMdd_hhmmss");

            csvOutputFileSpec      = Environment.CurrentDirectory + "\\ManageMaintenanceBanners-" + timeStamp + Constants.CSVExtension;
            csvOutputFileHasHeader = System.IO.File.Exists(csvOutputFileSpec);

            Logger.OpenLog("ManageMaintenanceBanners", timeStamp);
            Logger.LogInfoMessage(String.Format("Scan starting {0}", DateTime.Now.ToString()), true);

            BannerOperation operationToPerform = BannerOperation.None;

            if (!ReadInputOptions(ref operationToPerform))
            {
                System.Console.ForegroundColor = System.ConsoleColor.Yellow;
                Logger.LogInfoMessage("Operation aborted by user.", true);
                Logger.LogInfoMessage(String.Format("Scan aborted {0}", DateTime.Now.ToString()), true);
                Logger.CloseLog();
                System.Console.ResetColor();
                return;
            }

            string cdnAbsoluteUrl = String.Empty;

            if (operationToPerform == BannerOperation.Add)
            {
                if (!ReadCdnUrl(ref cdnAbsoluteUrl))
                {
                    System.Console.ForegroundColor = System.ConsoleColor.Red;
                    Logger.LogErrorMessage("CDN Library Folder Url was not specified.");
                    Logger.LogInfoMessage(String.Format("Scan aborted {0}", DateTime.Now.ToString()), true);
                    Logger.CloseLog();
                    System.Console.ResetColor();
                    return;
                }
            }

            string inputFileSpec = Environment.CurrentDirectory + "\\" + Constants.UsageReport_SitesInputFileName;

            if (!System.IO.File.Exists(inputFileSpec))
            {
                System.Console.ForegroundColor = System.ConsoleColor.Red;
                Logger.LogErrorMessage(String.Format("Input file {0} is not available", inputFileSpec), true);
                Logger.LogInfoMessage(String.Format("Scan aborted {0}", DateTime.Now.ToString()), true);
                Logger.CloseLog();
                System.Console.ResetColor();
                return;
            }

            string[] siteUrls = Helper.ReadInputFile(inputFileSpec, false);
            Logger.LogInfoMessage(String.Format("Preparing to process a total of {0} sites ...", siteUrls.Length), true);

            foreach (string siteUrl in siteUrls)
            {
                ProcessSite(siteUrl, operationToPerform, cdnAbsoluteUrl);
            }

            Logger.LogInfoMessage(String.Format("Scan completed {0}", DateTime.Now.ToString()), true);
            Logger.CloseLog();
        }
Example #2
0
        private static void ProcessSite(string siteUrl, BannerOperation operationToPerform, string cdnAbsoluteUrl)
        {
            try
            {
                Logger.LogInfoMessage(String.Format("Processing Site: {0} ...", siteUrl), true);

                using (ClientContext userContext = Helper.CreateAuthenticatedUserContext(Program.AdminDomain, Program.AdminUsername, Program.AdminPassword, siteUrl))
                {
                    Site site = userContext.Site;
                    Web  root = userContext.Site.RootWeb;
                    userContext.Load(site);
                    userContext.Load(root);
                    userContext.ExecuteQuery();

                    switch (operationToPerform)
                    {
                    case BannerOperation.Add:
                        // We remove any existing items before adding the new one
                        DeleteJsLinks(userContext, site);
                        AddJsLinks(userContext, site, cdnAbsoluteUrl);
                        break;

                    case BannerOperation.Remove:
                        DeleteJsLinks(userContext, site);
                        break;

                    case BannerOperation.None:
                    default:
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.LogErrorMessage(String.Format("ProcessSite() failed for site [{0}]: Error={1}", siteUrl, ex.Message), false);
                ExceptionCsv.WriteException(
                    "N/A", siteUrl, "N/A",
                    "MaintenanceBanner",
                    ex.Message, ex.ToString(), "ProcessSite", ex.GetType().ToString(),
                    String.Format("ProcessSite() failed for site [{0}]", siteUrl)
                    );
            }
        }
Example #3
0
        /// <summary>
        /// metodo que conta os cliques... ou add visualizacao
        /// </summary>
        /// <param name="banners"></param>
        /// <param name="acao"></param>
        /// <param name="db"></param>
        /// <returns></returns>
        public string BannerCount(Banners banners, BannerOperation acao, ref ModeloDados db)
        {
            string url = string.Empty;

            //if (banners != null)
            //{
            //    var registro = new BannersVisualizacoesCliques();


            //    if (acao == BannerOperation.Visualizacao)
            //    {
            //        registro = new BannersVisualizacoesCliques
            //        {
            //            CodigoBanner = banners.Id,
            //            Visualizacao = true,
            //            Clique = false,
            //            DataCadastro = DateTime.Now
            //        };
            //    }
            //    else
            //    {
            //        registro = new BannersVisualizacoesCliques
            //        {
            //            CodigoBanner = banners.Id,
            //            Visualizacao = false,
            //            Clique = true,
            //            DataCadastro = DateTime.Now
            //        };

            //url = banners.Link;
            //    }
            //    db.Entry(registro).State = EntityState.Added;
            //    db.SaveChanges();

            //}

            return(url);
        }
Example #4
0
        private static bool ReadInputOptions(ref BannerOperation operationToPerform)
        {
            bool operationSelected = false;

            string processOption = string.Empty;

            System.Console.ForegroundColor = System.ConsoleColor.White;
            Logger.LogMessage("Please type an operation number and press [Enter] to execute the specified operation:");
            Logger.LogMessage("1. Add Maintenance Banner to Sites");
            Logger.LogMessage("2. Remove Maintenance Banner from Sites");
            Logger.LogMessage("3. Exit to Transformation Menu");
            System.Console.ResetColor();
            processOption = System.Console.ReadLine();

            switch (processOption)
            {
            case "1":
                operationToPerform = BannerOperation.Add;
                operationSelected  = true;
                Logger.LogInfoMessage(String.Format("Selected Operation = {0} Banners", operationToPerform.ToString()), false);
                break;

            case "2":
                operationToPerform = BannerOperation.Remove;
                operationSelected  = true;
                Logger.LogInfoMessage(String.Format("Selected Operation = {0} Banners", operationToPerform.ToString()), false);
                break;

            case "3":
            default:
                operationToPerform = BannerOperation.None;
                operationSelected  = false;
                break;
            }

            return(operationSelected);
        }