コード例 #1
0
        /// <summary>
        /// Удалить все файлы кроме указанных
        /// </summary>
        /// <param name="path"></param>
        /// <param name="exceptionFiles"></param>
        public void DeleteAll(string path, IProgress <ProgressIndicate> progress, CancellationToken token, string filesToIgnore = "")
        {
            IEnumerable <string> dirs = Directory.EnumerateFiles(path);
            int count = 0;

            foreach (var filePath in dirs)
            {
                count++;
            }

            ProgressIndicate progressindicate = new ProgressIndicate(count);

            foreach (var fileName in dirs)
            {
                if (token.IsCancellationRequested)
                {
                    return;
                }

                progressindicate.SetName(fileName);
                progressindicate.MoveNextCurrent();
                if (progress != null)
                {
                    progress.Report(progressindicate);
                }

                string ext = fileName.Substring(fileName.LastIndexOf('.'));

                if (filesToIgnore.Contains(ext) == false)
                {
                    File.Delete(fileName);
                }
            }
        }
コード例 #2
0
        public void ParsingXMLToXLS(string xlsFile, string pathXML, string xslFile, IProgress <ProgressIndicate> progress, CancellationToken token)
        {
            Excel.Workbook wb = null;
            try
            {
                if (IsUnionXMLs)
                {
                    wb = _app.Workbooks.Add();
                }
                string[]         dirs             = Directory.GetFiles(pathXML, "*.xml");
                ProgressIndicate progressindicate = new ProgressIndicate(dirs.Length);
                foreach (string filename in dirs)
                {
                    if (token.IsCancellationRequested)
                    {
                        throw new Exception("");
                    }

                    progressindicate.SetName(filename);
                    progressindicate.MoveNextCurrent();
                    if (progress != null)
                    {
                        progress.Report(progressindicate);
                    }

                    Import(xlsFile, filename, xslFile, wb);
                }
            }
            catch (Exception ex)
            {
                if (string.IsNullOrWhiteSpace(ex.Message))
                {
                    Log.Instance.Write(ex);
                }
            }
            finally
            {
                if (wb != null)
                {
                    if (string.IsNullOrWhiteSpace(FileOutput))
                    {
                        FileOutput = Path.Combine(PathExcel, "union.xlsx");
                    }

                    if (File.Exists(FileOutput))
                    {
                        File.Delete(FileOutput);
                    }
                    wb.SaveAs(FileOutput);
                    wb.Close();
                }
            }
        }
コード例 #3
0
        public void UnZipAll(string zipPath, string unzipPath, IProgress <ProgressIndicate> progress, CancellationToken token)
        {
            string[]         dirs             = Directory.GetFiles(zipPath, "*.zip");
            ProgressIndicate progressindicate = new ProgressIndicate(dirs.Length);

            foreach (string filename in dirs)
            {
                if (token.IsCancellationRequested)
                {
                    return;
                }

                progressindicate.SetName(filename);
                progressindicate.MoveNextCurrent();
                if (progress != null)
                {
                    progress.Report(progressindicate);
                }

                UnZip(filename, unzipPath);
            }
        }