static void Main(string[] args)
        {
            Console.WriteLine("Please insert rootPath");

            var rootPath = Console.ReadLine();

            if (String.IsNullOrEmpty(rootPath))
            {
                rootPath = @"C:\projects\Moznosti CMS\WebCMS";
            }
            IWebDriver driver = new ChromeDriver();

            driver.Url = "https://kraken.io/web-interface";
            driver.Manage().Window.Maximize();

            RecursiveFileProcessor.ProcessDirectory(rootPath);

            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);


            driver.FindElement(By.ClassName("lossless")).Click();

            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
            Console.WriteLine("These images are larger than 1mb, please use another tools to optimise (ex. Photoshop)");
            //RecursiveFileProcessor.GetImagesPaths.ToList().ForEach(i => Console.WriteLine("" + i.ToString()));

            //group by folders

            //for each folder
            var dict = RecursiveFileProcessor.GetImagesPathsWithDirs();

            foreach (KeyValuePair <string, List <string> > entry in dict)
            {
                if (entry.Value.Count == 0)
                {
                    dict.Remove(entry.Key);
                    continue;
                }
                Console.WriteLine("\n" + "Dir is:" + entry.Key + "\n");
                entry.Value.ForEach(i => Console.WriteLine("" + i.ToString()));
            }
            //driver.FindElement(By.ClassName("wi-drop-zone")).SendKeys(@"C:\projects\Moznosti CMS\WebCMS\images\logo.jpg");

            UploadFile(driver, @"C:\projects\Moznosti CMS\WebCMS\images\logo.jpg");
        }
示例#2
0
        static void Main(string[] args)
        {
            var rootPath = "";

            if (args.Length > 0)
            {
                rootPath = args[0];
            }
            else
            {
                while (true)
                {
                    Console.WriteLine("insert root of site");
                    rootPath = Console.ReadLine();
                    if (!System.IO.Directory.Exists(rootPath))
                    {
                        Console.WriteLine("folder does not exsist");
                    }
                    else
                    {
                        break;
                    }
                }
            }

            RecursiveFileProcessor.ProcessDirectory(rootPath);
            var dict    = RecursiveFileProcessor.GetImagesPathsWithDirs();
            var counter = 0;

            var    errorImglast  = rootPath + @"\imgError.txt";
            bool   errorExist    = false;
            string imagePathLast = "";
            bool   flag          = false;

            foreach (KeyValuePair <string, List <string> > entry in dict)
            {
                if (entry.Value.Count == 0)
                {
                    dict.Remove(entry.Key);
                    continue;
                }
                foreach (var imgPath in entry.Value)
                {
                    //if (File.Exists(errorImglast))
                    //{
                    //    string[] lines = File.ReadAllLines(errorImglast);
                    //    errorExist = true;
                    //    imagePathLast = lines[lines.Length - 1];
                    //}
                    //try
                    //{
                    //   if(errorExist)
                    //    {
                    //    if(imgPath == imagePathLast || flag)
                    //    {
                    //        Console.WriteLine("Uploading img:" + imgPath + "...");
                    //        //upload file
                    //        myUtils.UploadImg(imgPath);

                    //        Console.WriteLine("uploaded finished");
                    //        //download file
                    //        var imgBites = myUtils.DownloadImg(imgPath);
                    //        //write info
                    //        myUtils.ImgLog(imgPath, imgBites.Length);

                    //        //rewrite file
                    //        myUtils.OverrideImg(imgPath, imgBites);
                    //        flag = true;
                    //    }
                    //    else
                    //    {
                    //        Console.WriteLine("miss " + imgPath);
                    //    }
                    //}
                    try
                    {
                        Console.WriteLine("Uploading img:" + imgPath + "...");
                        //upload file

                        myUtils.UploadImg(imgPath);

                        Console.WriteLine("uploaded finished");
                        //download file
                        var imgBites = myUtils.DownloadImg(imgPath);
                        //write info
                        myUtils.ImgLog(imgPath, imgBites.Length);

                        //rewrite file
                        myUtils.OverrideImg(imgPath, imgBites);
                    }
                    catch (Exception ex) {
                        Console.WriteLine("error " + ex.ToString());
                    }
                }
                myUtils.SaveImgReport(rootPath + "\\");
            }
        }