Ejemplo n.º 1
0
        private static void getDwgAndMdlFilesByFcrs(string searchDir, string[] fcrNumbers, ref List <FCR> fcrFileNames)
        {
            List <string> dirs = FolderTools.Class1.ListDirs(searchDir);

            //Dictionary<string, List<string>> fcrFileNames = new Dictionary<string, List<string>>();
            foreach (string folder in dirs)
            {
                for (int i = 0; i < fcrNumbers.Length; i++)
                {
                    string folderName = folder.Substring(folder.LastIndexOf("\\") + 1);
                    if (folderName.Length > 6)
                    {
                        string FCR = folderName.Substring(0, 6);
                        if (fcrNumbers[i].Equals(FCR))
                        {
                            //get info
                            string        dwgFolder = folder + @"\DRAWINGS";
                            string        mdlFolder = folder + @"\IFC";
                            List <string> fileNames = new List <string>(getFileNames(dwgFolder));
                            fileNames.AddRange(getFileNames(mdlFolder, "*.ifc"));

                            List <file> newFiles = new List <file>();
                            foreach (string rawFileName in fileNames)
                            {
                                file newFile = new file();
                                newFile.sketchPrefix = rawFileName.Substring(0, 9);
                                newFile.fileName     = rawFileName.Substring(10, rawFileName.LastIndexOf("-") - 10);
                                char letter = char.Parse(rawFileName.Substring(rawFileName.LastIndexOf("-") + 1, 1));
                                newFile.revisionLetterIndex = char.ToUpper(letter) - 64;
                                newFile.revisionNumber      = int.Parse(rawFileName.Substring(rawFileName.LastIndexOf(".") - 2, 2));

                                newFiles.Add(newFile);
                            }

                            //save info
                            FCR newFCR = new FCR();
                            newFCR.FcrNumber = FCR;
                            newFCR.Files     = newFiles;
                            fcrFileNames.Add(newFCR);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private static Dictionary <string, file> returnLatestFiles(List <FCR> FCRs)
        {
            Dictionary <string, file> latestRevisions = new Dictionary <string, file>();

            foreach (FCR FCR in FCRs)
            {
                foreach (file file in FCR.Files)
                {
                    if (latestRevisions.ContainsKey(file.fileName))
                    {
                        //get infor for comparison
                        file latestFile        = latestRevisions[file.fileName];
                        int  latestLetterIndex = latestFile.revisionLetterIndex;
                        int  latestNumber      = latestFile.revisionNumber;

                        //if letter index is lower then the latest then replace the full revision
                        if (latestLetterIndex < file.revisionLetterIndex)
                        {
                            latestFile.revisionLetterIndex = file.revisionLetterIndex;
                            latestFile.revisionNumber      = file.revisionNumber;
                        }

                        //if the same letter index but lower number then replace the full revision
                        else if (latestLetterIndex.Equals(file.revisionLetterIndex))
                        {
                            if (latestNumber < file.revisionNumber)
                            {
                                latestFile.revisionLetterIndex = file.revisionLetterIndex;
                                latestFile.revisionNumber      = file.revisionNumber;
                            }
                        }
                    }
                    else
                    {
                        latestRevisions.Add(file.fileName, new file(file));
                    }
                }
            }
            return(latestRevisions);
        }
Ejemplo n.º 3
0
        private static void removeOldRevisionsAndDuplicates(Dictionary <string, file> latestRevisions, ref List <FCR> FCRs)
        {
            foreach (string latestFileName in latestRevisions.Keys)
            {
                bool duplicate  = false;
                file latestFile = latestRevisions[latestFileName];

                foreach (FCR FCR in FCRs)
                {
                    List <int> toDelete = new List <int>();

                    //find files to delete
                    for (int i = 0; i < FCR.Files.Count; i++)
                    {
                        file file = FCR.Files[i];
                        if (file.fileName.Equals(latestFileName))
                        {
                            //if the file is the latest file and is not a duplicate, mark as found
                            if (file.revisionLetterIndex.Equals(latestFile.revisionLetterIndex) && file.revisionNumber.Equals(latestFile.revisionNumber) && !duplicate)
                            {
                                duplicate = true;
                            }
                            //if its not most up to date or its a duplicate then remove
                            else
                            {
                                toDelete.Add(i);
                            }
                        }
                    }

                    //delete outdated files
                    for (int i = toDelete.Count - 1; i >= 0; i--)
                    {
                        FCR.Files.RemoveAt(toDelete[i]);
                    }
                }
            }
        }