Пример #1
0
        private bool IsExclusion(string file)
        {
            var fileInfo = new FileInfo(file);

            if (!(fileInfo.Length > 0 && fileInfo.Length <= MaxSize))
            {
                FileDetails fileDetails = CommonUtility.CreateFileDetails(file,
                                                                          Runner,
                                                                          Logger,
                                                                          EnvironmentInfo);
                if (null != fileDetails)
                {
                    FileExclusions.Add(fileDetails);
                }
                return(true);
            }
            return(false);
        }
Пример #2
0
        public static FileDetails CreateFileDetails(string path,
                                                    string runner,
                                                    ILog logger            = null,
                                                    string environmentInfo = null)
        {
            FileDetails sample = null;

            var shouldSkip = !DemandFileAccessPersission(path, logger, environmentInfo) ||
                             CommonUtility.IsFileUsedbyAnotherProcess(path, logger, environmentInfo);

            if (!shouldSkip)
            {
                shouldSkip = true;
                var       info = new FileInfo(path);
                Exception ex   = null;
                try
                {
                    sample = new FileDetails
                    {
                        Hash = info.MD5().ToString(),
                        FileNameWithoutPath = info.Name,
                        FilePath            = path,
                        FileSize            = info.Length,
                        Status = StatusType.UnSubmitted,
                        Date   = DateTime.Now,
                        Runner = runner
                    };
                    shouldSkip = false;
                }
                catch (UnauthorizedAccessException exUnAuth) { ex = exUnAuth; }
                catch (System.IO.IOException exIO) { ex = exIO; }
                if (null != ex)
                {
                    logger.Warn(string.Format(@"--- Exception caught at Get File Details, sample in processing : {3}, the error was:{2}{0}, stack trace:{2}{1}",
                                              null != ex.InnerException ? ex.InnerException.Message : ex.Message,
                                              ex.StackTrace,
                                              Environment.NewLine,
                                              path).StringConcat(environmentInfo, true));
                }
            }

            return(sample);
        }