/// <summary>
        /// Delete files in queue
        /// </summary>
        /// <param name="fileList"></param>
        private void DeleteFiles(List <string> fileList)
        {
            Queue      myQueue         = new Queue();
            int        maxTryCount     = 200;
            int        currentTryCount = 0;
            FileWorker fileWorker      = new FileWorker();

            foreach (string s in fileList)
            {
                myQueue.Enqueue(s);
            }

            while (myQueue.Count != 0 && maxTryCount > currentTryCount)
            {
                string s = myQueue.Dequeue().ToString();
                currentTryCount++;
                try
                {
                    System.Threading.Thread.Sleep(20);
                    fileWorker.DeleteFiles(s);
                    System.Threading.Thread.Sleep(20);
                }
                catch (Exception ex)
                {
                    myQueue.Enqueue(s);
                    fileWorker.Logs("Level 2 Error" + ex.Message);
                }
            }
        }
Example #2
0
        /// <summary>
        /// Validate files after convert and delete lost ones
        /// </summary>
        /// <param name="listOfFiles"></param>
        /// <param name="extension"></param>
        public static void PosValidateExpectedFiles(List <string> listOfFiles, string extension = "xlsb")
        {
            FileWorker    fw            = new FileWorker();
            List <string> expectedFiles = new List <string>();

            foreach (string filePath in listOfFiles)
            {
                string fileWithoutExt = Helper.SplitExstansionByDotAndTakeName(filePath);
                expectedFiles.Add(fileWithoutExt + "." + extension);
            }

            int isExistsCount = 0;

            foreach (string newFilePath in expectedFiles)
            {
                if (File.Exists(newFilePath))
                {
                    isExistsCount++;
                }
            }
            if (isExistsCount == listOfFiles.Count)
            {
                foreach (string oldFilePath in listOfFiles)
                {
                    if (File.Exists(oldFilePath))
                    {
                        try
                        {
                            fw.DeleteFiles(oldFilePath);
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                    }
                    else
                    {
                        continue;
                    }
                }
            }
        }