示例#1
0
        public static void CheckFiles(string d, int DaysNumber, Uploading mongoDB_Test)
        {
            //Check files in folder
            // Make a reference to info of a directory.
            DirectoryInfo di = new DirectoryInfo(d);

            // Get a reference to each file in that directory.

            FileInfo[] fiArr = di.GetFiles();

            //Extensions list
            var FileExt = new List <string> {
                ext
            };

            List <string> FileFullNames = Directory.EnumerateFiles(d, "*_*_*_*_*_*_*_*", SearchOption.TopDirectoryOnly).
                                          Where(s => FileExt.Contains(Path.GetExtension(s).TrimStart((char)46).ToLowerInvariant())).ToList();

            foreach (string fn in FileFullNames)
            {
                FileInfo f = new FileInfo(fn);

                List <string> field = new List <string>();

                if (f.LastWriteTime > DateTime.Now.AddDays(-DaysNumber))
                {
                    char[] charsToTrim = { ' ' };

                    string[] SplitString = f.LastWriteTime.ToString().Split(charsToTrim);

                    //LastWriteDate
                    field.Add(SplitString[0]);

                    //LastWriteTime
                    field.Add(SplitString[1]);

                    //Length
                    field.Add(f.Length.ToString());

                    //Directory name
                    field.Add(f.DirectoryName);

                    //File name parsing
                    string line = f.Name;
                    field.AddRange(FieldsGet(line));


                    if (Uploading.ColName == null)
                    {
                        Uploading.ColName = DateTime.Now.ToString("yyMMdd") + "_" + field[8] + "_" + field[10] + "_" + ext + "_" + DaysNumber;
                        mongoDB_Test.CheckCollectionsNames();

                        dS_Output.DS_StreamWriter("\n" + "Files has been found: ");
                    }

                    dS_Output.DS_StreamWriter(f.Name);

                    mongoDB_Test.InsertOneDoc(field);
                }
            }
        }
        public void Program()
        {
            //New form creation
            DS_Form newForm = new DS_Form();

            string FolderPathNWD = newForm.DS_OpenFolderDialogForm("", "Set directory for projects with NWF files:").ToString();

            if (FolderPathNWD == "")
            {
                newForm.Close();
                return;
            }
            SourseFolderPath = FolderPathNWD;
            string CurDateTime = DateTime.Now.ToString("yyMMdd_HHmmss");

            DS_Output dS_Output = new DS_Output
            {
                DS_WritePath = SourseFolderPath + "\\" + "Log_ClashVPReport_" + CurDateTime + ".txt"
            };

            SavedFiles.Clear();
            SavedFiles.Add("Files has been saved: " + "\n");
            FilesWithNoClashTests.Clear();
            FilesWithNoClashTests.Add("No clash tests exist in files: " + "\n");
            FilesWithNoClashRes.Clear();
            FilesWithNoClashRes.Add("No clashes are in files: " + "\n");

            FilesCheck(SourseFolderPath);

            DirIterate(SourseFolderPath);


            //Start log writing
            if (SavedFiles.Count > 1)
            {
                SavedFiles.Add("\n");
                foreach (string s in SavedFiles)
                {
                    dS_Output.DS_StreamWriter(s);
                }
            }
            else
            {
                dS_Output.DS_StreamWriter("No NWF files have been found in this folder.");
                MessageBox.Show("Errors occurred!" + "\n" + "Look at " + dS_Output.DS_WritePath + " for details.");
                return;
            }

            if (FilesWithNoClashTests.Count > 1)
            {
                FilesWithNoClashTests.Add("\n");
                foreach (string s in FilesWithNoClashTests)
                {
                    dS_Output.DS_StreamWriter(s);
                }
            }

            if (FilesWithNoClashRes.Count > 1)
            {
                FilesWithNoClashRes.Add("\n");
                foreach (string s in FilesWithNoClashRes)
                {
                    dS_Output.DS_StreamWriter(s);
                }
            }

            MessageBox.Show("Process complete! See report: " + "\n" + dS_Output.DS_WritePath);
        }