Esempio n. 1
0
        /// <summary>
        /// ورودی آدرس فایل خروجی آدرس پوشه ای که باید فشرده سازی شود
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public static async Task <ReturnedSaveFuncInfoWithValue <string> > Move2Temp(string filePath, Guid guid, EnBackUpType type)
        {
            var ret = new ReturnedSaveFuncInfoWithValue <string>();

            try
            {
                string   tempDIR   = TempDirName();
                FileInfo tempInfor = new FileInfo(filePath);
                if (!File.Exists(filePath))
                {
                    var msg = $"path not exists : {filePath}";
                    await DatabaseAction.BackUpLogAsync(guid, type, EnBackUpStatus.Error, filePath, msg);

                    ret.AddReturnedValue(ReturnedState.Error, msg);
                    return(ret);
                }
                var retFilePath = Path.Combine(tempDIR, tempInfor.Name);
                File.Move(filePath, retFilePath);
                ret.value = tempDIR;
                await DatabaseAction.BackUpLogAsync(guid, type, EnBackUpStatus.Success, filePath, "انتقال فایل به پوشه Temp انجام شد");
            }
            catch (Exception ex)
            {
                await DatabaseAction.BackUpLogAsync(guid, type, EnBackUpStatus.Error, filePath, ex.Message);

                WebErrorLog.ErrorInstence.StartErrorLog(ex);
                ret.AddReturnedValue(ex);
            }
            return(ret);
        }
        public async Task <ReturnedSaveFuncInfo> CompressFileAsync(string pathForZipDirectory, string zipFilePath, Guid guid, EnBackUpType type)
        {
            var ret  = new ReturnedSaveFuncInfo();
            int line = 0;

            try
            {
                line        = 1;
                zipFilePath = zipFilePath.ToLower();
                line        = 2;
                var inf = new FileInfo(zipFilePath);
                line        = 3;
                zipFilePath = inf.FullName.Replace(inf.Extension, ".npz2");
                using (var archive = ArchiveFactory.Create(ArchiveType.GZip))
                {
                    line = 48;
                    archive.AddAllFromDirectory(pathForZipDirectory);
                    line = 51;
                    archive.SaveTo(zipFilePath, CompressionType.GZip);
                }

                line = 52;
                line = 53;
                Directory.Delete(pathForZipDirectory, true);
                await DatabaseAction.BackUpLogAsync(guid, type, EnBackUpStatus.Success, zipFilePath,
                                                    "فایل فشره شده ایجاد شد");
            }
            catch (OperationCanceledException ex) { ret.AddReturnedValue(ex); }
            catch (Exception ex)
            {
                await DatabaseAction.BackUpLogAsync(guid, type, EnBackUpStatus.Error, zipFilePath,
                                                    ex.Message);

                WebErrorLog.ErrorInstence.StartErrorLog(ex, $"Line:{line}");
                ret.AddReturnedValue(ex);
            }
            return(ret);
        }