コード例 #1
0
        protected override void Execute(CodeActivityContext context)
        {
            try
            {
                long   resultBytes = 0;
                double resultMB    = 0;
                localOutPutPath = string.Empty;

                localPath   = DirectoryPath.Get(context);
                localSubDir = IncludeSubDir.Get(context);
                localSearch = FindDirectoryName.Get(context);

                this.Validate();

                resultBytes = FindDirectorySize(new DirectoryInfo(localPath), localSubDir);
                if (resultBytes > 0)
                {
                    resultMB = resultBytes / 1024;
                    resultMB = resultMB / 1024;
                    resultMB = System.Math.Round(resultMB, 2);
                }

                SizeBytes.Set(context, resultBytes);
                SizeMB.Set(context, resultMB);
                if (!string.IsNullOrEmpty(localOutPutPath))
                {
                    OutPutPath.Set(context, localOutPutPath);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #2
0
        private void DeleteFilesInDirectory(CodeActivityContext context)
        {
            try {
                string   _directoryPath     = DirectoryPath.Get(context);
                string   _fileExtension     = FileExtension.Get(context);
                int      _dayCountFrom      = Convert.ToInt16(DayCountFrom.Get(context));
                int      _dayCountTo        = Convert.ToInt16(DayCountTo.Get(context));
                bool     _timestampCategory = Convert.ToBoolean((int)TimestampCategory);
                string[] fileList           = Helper.DirectoryHelper.GetDirectoryFiles(directoryPath: _directoryPath, fileExtension: _fileExtension, timestampCategory: _timestampCategory, dayCountFrom: _dayCountFrom, dayCountTo: _dayCountTo);

                foreach (string file in fileList)
                {
                    try {
                        File.Delete(file);
                    } catch (Exception ex) {
                        throw ex;
                    }
                }
            } catch (Exception ex) {
                if (Convert.ToBoolean((int)ContinueOnError))
                {
                }
                else
                {
                    throw ex;
                }
            }
        }
コード例 #3
0
        protected override async Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken token)
        {
            var dir           = DirectoryPath.Get(context);
            var time          = Timeout.Get(context);
            var searchPattern = SearchPattern.Get(context) ?? "*.*";
            var afterDate     = CalculateDate(dir);
            var filePath      = await ExecuteWithTimeoutAsync(context, token, ExecuteMainAsync(dir, searchPattern, afterDate, token), time).ConfigureAwait(false);

            return(ctx => Result.Set(ctx, filePath != null ? new FileInfo(filePath) : null));
        }
コード例 #4
0
        protected override void Execute(CodeActivityContext context)
        {
            this.IsSucessfull.Set(context, false);
            string        directoryPath = DirectoryPath.Get(context);
            DirectoryInfo dirInfo       = new DirectoryInfo(directoryPath);

            if (dirInfo.Exists)
            {
                foreach (FileInfo fileInfo in dirInfo.GetFiles())
                {
                    fileInfo.Delete();
                }

                this.IsSucessfull.Set(context, true);
            }
            else
            {
                this.IsSucessfull.Set(context, false);
            }
        }
コード例 #5
0
        protected override void Execute(CodeActivityContext context)
        {
            if (!Active.Get(context))
            {
                return;
            }

            try
            {
                string DirPath = DirectoryPath.Get(context);
                string ZipPath = ZipFileName.Get(context);

                ZipFile.CreateFromDirectory(DirPath, ZipPath);
            }
            catch (Exception ex)
            {
                var record = new CustomTrackingRecord("Warning");
                record.Data.Add(new KeyValuePair <string, object>("Message", "Error while zipping.\n" + ex.ToString()));
                context.Track(record);
            }
        }