Пример #1
0
        public static Dictionary <string, List <dynamic> > DetachModel(string workspacePath, List <List <string> > FolderLocations, string saveLocation, bool detach, bool openCentral, bool debugMode = true, bool circumventPerspectiveViews = true)
        {
            Stopwatch      counter   = Stopwatch.StartNew();
            List <dynamic> Central   = new List <dynamic>();
            List <dynamic> Holding   = new List <dynamic>();
            List <dynamic> Failed    = new List <dynamic>();
            List <dynamic> container = new List <dynamic>();

            DeleteJournalFile(saveLocation);
            counter.Start();
            foreach (var item in FolderLocations)
            {
                var            fileName = IdentifyYear.GetRevitYearSingle(item[0], item[1]);
                List <dynamic> cont     = new List <dynamic>(FileConfirmation(fileName, workspacePath, item[1], saveLocation, debugMode, circumventPerspectiveViews, detach, openCentral));
                Central.Add(cont[0]);
                Holding.Add(cont[1]);
                Failed.Add(cont[2]);
            }
            counter.Stop();
            TimeSpan       ct          = counter.Elapsed;
            string         elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ct.Hours, ct.Minutes, ct.Seconds, ct.Milliseconds / 10);
            List <dynamic> Run         = new List <dynamic>
            {
                elapsedTime
            };

            //Return to Dynamo the Container of Everything that Happened.
            return(new Dictionary <string, List <dynamic> >
            {
                { "Central File Path", Central },
                { "Journal File Path", Holding },
                { "Run Time", Run },
                { "Failed Message", Failed }
            });
        }
Пример #2
0
        private static string ContentProcess(int i, int ring, int prjKey, List <dynamic> YearList, List <dynamic> Holding, string CentralPath, string newConn)
        {
            string processPath;
            string args;
            //int key = ring + i;
            int           year    = YearList[i];
            string        journal = Holding[i][0];
            List <string> temp    = YearSwitch(i, year, journal);

            processPath = temp[0];
            args        = temp[1];
            DateTime   dateEx   = DateTime.Now;
            List <int> sqlEarly = TidalWave.SQL.InsertInto(newConn, Holding[i][1], dateEx);
            //returns the runID and the projectTableID to send to the .csv
            double fileSize = IdentifyYear.FileSize(CentralPath);
            string csvEarly = CSVPath(CentralPath);

            if (File.Exists(csvEarly))
            {
                File.Delete(csvEarly);
            }
            string         sub        = CSVWriter(sqlEarly, csvEarly, fileSize);
            int            exitCode   = Process.ByPathAndArguments(processPath, args);
            int            send       = sqlEarly[0];
            string         select     = "SELECT * FROM [drRunStat] WHERE rsKey = " + send;
            List <dynamic> SelectComp = TidalWave.SQL.Select(newConn, select);

            if (SelectComp[4] == null || SelectComp[4] == "")
            {
                TidalWave.SQL.Update(dateEx, send, newConn, 2);
                return("Failure");
            }
            else if (SelectComp[4] = true)
            {
                TidalWave.SQL.Update(dateEx, send, newConn, 1);
                return("Succes");
            }
            else
            {
                TidalWave.SQL.Update(dateEx, send, newConn, 0);
                return("Failure");
            };
        }
Пример #3
0
        public static Dictionary <string, List <dynamic> > ByFolderPath(string workspacePath, List <List <string> > FolderLocations, string saveLocation, bool debugMode = true, bool circumventPerspectiveViews = false)
        {
            Stopwatch      counter   = Stopwatch.StartNew();
            List <dynamic> Central   = new List <dynamic>();
            List <dynamic> Holding   = new List <dynamic>();
            List <dynamic> Failed    = new List <dynamic>();
            List <dynamic> container = new List <dynamic>();

            DeleteJournalFile(saveLocation);

            foreach (var item in FolderLocations)
            {
                //Next Line will loop through a folder location and return the Revit Files that exists there.
                //It returns the Year(Build) the file is saved in and also if it is connected to a Central Model.
                var            fileName = IdentifyYear.GetRevitYearSingle(item[0], item[1]);
                List <dynamic> cont     = new List <dynamic>(FileConfirmation(fileName, workspacePath, item[1], saveLocation, debugMode, circumventPerspectiveViews));
                Central.Add(cont[0]);
                Holding.Add(cont[1]);
                Failed.Add(cont[2]);
            }
            counter.Stop();
            TimeSpan ct          = counter.Elapsed;
            string   elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ct.Hours, ct.Minutes, ct.Seconds, ct.Milliseconds / 10);

            Debug.WriteLine(elapsedTime);
            //List of Central Files
            //foreach (var k in Holding)
            //    Proj.Add(k[0]);

            List <dynamic> Find = new List <dynamic>();

            Find.Add(elapsedTime);
            //Return to Dynamo the Container of Everything that Happened.
            return(new Dictionary <string, List <dynamic> >
            {
                { "Central File Path", Central },
                { "Journal File Path", Holding },
                { "Find Time", Find },
                { "Failed Message", Failed }
            });
        }
Пример #4
0
        private static string ContentProcess(int i, int prjKey, string Year, List <string> Holding, string CentralPath, string newConn, string SQLSelect)
        {
            string processPath;
            string args;
            //int key = ring + i;
            int year = Convert.ToInt32(Year);
            //int year = Year;
            string        journal = Holding[0];
            List <string> temp    = YearSwitch(i, year, journal);

            processPath = temp[0];
            args        = temp[1];
            DateTime   dateEx   = DateTime.Now;
            List <int> sqlEarly = new List <int>();

            if (newConn != "" && newConn != null)
            {
                sqlEarly = TidalWave.SQL.InsertInto(newConn, Holding[1], dateEx);
            }
            //returns the runID and the projectTableID to send to the .csv
            double fileSize = IdentifyYear.FileSize(CentralPath);
            string csvEarly = CSVPath(CentralPath);

            if (File.Exists(csvEarly))
            {
                File.Delete(csvEarly);
            }
            if (newConn != "" && newConn != null)
            {
                string sub = CSVWriter(sqlEarly, csvEarly, fileSize, CentralPath);
            }
            else
            {
                List <int> vs = new List <int>();
                vs.Add(0);
                vs.Add(1);
                string sub = CSVWriter(vs, csvEarly, fileSize, CentralPath);
            }
            int exitCode = Process.ByPathAndArguments(processPath, args);

            //int send = sqlEarly[0];
            if (newConn != "" && newConn != null)
            {
                string         select     = SQLSelect + sqlEarly[0];
                List <dynamic> SelectComp = TidalWave.SQL.Select(newConn, select);
                if (SelectComp[4] == null || SelectComp[4] == "")
                {
                    TidalWave.SQL.Update(dateEx, sqlEarly[0], newConn, 2);
                    return("Failure");
                }
                else if (SelectComp[4] = true)
                {
                    TidalWave.SQL.Update(dateEx, sqlEarly[0], newConn, 1);
                    return("Success");
                }
                else
                {
                    TidalWave.SQL.Update(dateEx, sqlEarly[0], newConn, 0);
                    return("Failure");
                };
            }
            else
            {
                return(exitCode.ToString());
            };
        }
Пример #5
0
        public static Dictionary <string, List <dynamic> > ByFolderPath(string workspacePath, List <List <string> > FolderLocations, string SQLConnectionString = "", string SQLQuery = "", string saveLocation = "", bool debugMode = true, bool circumventPerspectiveViews = false, int multithreading = 0)
        {
            Stopwatch counter = Stopwatch.StartNew();
            List <List <dynamic> > container = new List <List <dynamic> >();
            List <dynamic>         Central   = new List <dynamic>();
            List <dynamic>         Holding   = new List <dynamic>();
            List <dynamic>         Failed    = new List <dynamic>();
            List <dynamic>         YearList  = new List <dynamic>();
            List <dynamic>         Status    = new List <dynamic>();
            List <dynamic>         Proj      = new List <dynamic>();
            //string processPath;
            string path = "";

            DeleteJournalFile(saveLocation);
            int ring;
            int prjKey = 0;
            //string prjNum = null;

            //Open the SQL Connection.
            SqlConnection newConn = TidalWave.SQL.ConnectionOpen(SQLConnectionString);

            //Get the highest Key for the Run Statistics.
            if (newConn != null && newConn.State == ConnectionState.Open)
            {
                List <dynamic> dbInfo = TidalWave.SQL.Select(SQLConnectionString, SQLQuery);
                if (dbInfo[0] is int)
                {
                    ring = dbInfo[0];
                    ring++;
                }
                else
                {
                    ring = 0;
                    ring++;
                }

                string         sqlPrj  = "SELECT MAX(psKey) from [drPrjStat]";
                List <dynamic> prjStat = TidalWave.SQL.Select(SQLConnectionString, sqlPrj);
                if (prjStat[0] is int)
                {
                    prjKey = prjStat[0];
                    prjKey++;
                }
                else
                {
                    prjKey = 0;
                    prjKey++;
                }
            }
            else
            {
                ring = 0;
            };


            foreach (var item in FolderLocations)
            {
                //Next Line will loop through a folder location and return the Revit Files that exists there.
                //It returns the Year(Build) the file is saved in and also if it is connected to a Central Model.
                var fileName = IdentifyYear.GetRevitYearSingle(item[0], item[1]);
                if (fileName.Count > 0 && fileName[0] != null)
                {
                    //fileName should be returned in a List of List, nested list containing the Central Model Path and the Project Number
                    foreach (var d in fileName)
                    {
                        //var d below is a nested list containing the Central Model Path and the Project Number
                        foreach (var c in d)
                        {
                            //set workshare to bool, this was removed from the Dynamo Automation nodes, so forcing it to false.
                            bool workshare = false;
                            //give a clean list to insert content
                            List <dynamic> tempPrj = new List <dynamic>();

                            //tempPrj.Clear();

                            try
                            {
                                //get the 0 instance of what is in the list, should be the Revit Year
                                string quasi = c[0];
                                //Attempt to parse the string of Year to an Integer
                                int RevitYear;
                                int.TryParse(quasi, out RevitYear);
                                //get the 1 instance of what is in the list, should be the Central Model Path
                                int finding = c[1].IndexOf(":");
                                //document it
                                path = c[1].Substring(finding + 2);


                                //check if the file is younger than two weeks
                                DateTime modDate = File.GetLastWriteTime(path);
                                //below is to change it from two weeks.
                                DateTime mod1Date = DateTime.Now.AddDays(-14);
                                //compare the dates, older than two weeks returns -1.
                                int compareDate = DateTime.Compare(modDate, mod1Date);
                                //check if the File Path could be found in the files Structured Storage can be found.
                                if (CheckFilePath(path, "revitFilePath") == false && compareDate > 0)
                                {
                                    Failed.Add("No File Path was found for: " + path);
                                }
                                //check if the File Path exists and can be accessed
                                else if (!File.Exists(path) && compareDate > 0)
                                {
                                    Failed.Add("The File does not exist for: " + path);
                                }
                                //check if the file is older than two weeks
                                else if (compareDate < 0)
                                {
                                    Failed.Add("The File is older than the time allotment. " + path);
                                }
                                //if the Central File Path already exists, do nothing
                                else if (Central.Contains(path))
                                {
                                    Failed.Add("Duplicate Found. Omitting from Sequence. " + path);
                                }
                                //all is true, lets move forward
                                else
                                {
                                    //add the Central model path to a List
                                    Central.Add(path);
                                    //run a method
                                    int modelYear = RevitVersionAsInt(RevitYear);
                                    //add the model year to a List
                                    YearList.Add(modelYear);
                                    //match that with the Dynamo Year
                                    string dynVersion = GetDynamoVersion(RevitYear);
                                    // Create journal string
                                    string journalString = BuildJournalStart(debugMode);
                                    //if the path cannot be found, attempt working on a local model
                                    if (path == "")
                                    {
                                        journalString += BuildProjectOpen(c[2], circumventPerspectiveViews, workshare);
                                    }
                                    //else fetch the central model
                                    else
                                    {
                                        workshare      = true;
                                        journalString += BuildProjectOpen(path, circumventPerspectiveViews, workshare);
                                    }
                                    //Add the Dyanmo Build to the Journal Squence with our Workspace we want to run
                                    journalString += BuildDynamoLaunch(workspacePath, RevitYear, dynVersion);
                                    // In newer Revit versions the slave graph will only run if there are no journal commands after launching Dynamo.
                                    // The slave graph will then need to terminte itself.
                                    if (RevitYear < 2017)
                                    {
                                        journalString += BuildProjectClose();
                                        journalString += BuildJournalEnd();
                                    }
                                    // Create journal file
                                    string journaling = WriteJournalFile(saveLocation, journalString, item[1], modelYear);
                                    tempPrj.Add(journaling);
                                    Debug.WriteLine(journaling);
                                    tempPrj.Add(item[1]);
                                    Debug.WriteLine(item[1]);
                                    //Add the journal file to a list for us to work over later out of this loop
                                    Holding.Add(tempPrj);
                                }
                            }
                            //something failed miserably. Do not stop, log it and move on to the next item.
                            catch
                            {
                                if (c[1] == null)
                                {
                                    string exmsg = String.Format("The file path is null. Cannot operate over null Central Path: Journal 628");
                                    Failed.Add(exmsg);
                                }
                                else
                                {
                                    string exmsg = String.Format("The file path [{0}] received an error where it could not find the last modified date and time of the file: Signficant Error: ", c[1]);
                                    Failed.Add(exmsg);
                                }
                            }
                        }
                    }
                }
                //larger methods failed. Log and move on.
                else
                {
                    if (fileName.Count == 0 || fileName[0] == null)
                    {
                        string exmsg = String.Format("Error in finding folder for File. File was null.");
                        Failed.Add(exmsg);
                    }
                    else
                    {
                        string exmsg = String.Format("Error in finding folder for File [{0}]", fileName[0]);
                        Failed.Add(exmsg);
                    };
                };
            }
            counter.Stop();
            TimeSpan ct          = counter.Elapsed;
            string   elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ct.Hours, ct.Minutes, ct.Seconds, ct.Milliseconds / 10);

            Debug.WriteLine(elapsedTime);
            counter.Reset();
            counter.Start();
            //List of Central Files
            container.Add(Central);
            foreach (string i in Central)
            {
                Debug.WriteLine(i);
            }
            foreach (var k in Holding)
            {
                Proj.Add(k[0]);
            }
            //List of Journal Files
            container.Add(Proj);

            //List of Files that are not going to run. Keep this to compare against later.
            container.Add(Failed);
            Debug.WriteLine(Failed);
            try
            {
                //If the user selected multithreading and there are Central Files
                if (multithreading >= 1 && Central.Count > 0)
                {
                    //Set the number of Processes you want to run parallel
                    ParallelOptions options = new ParallelOptions()
                    {
                        MaxDegreeOfParallelism = multithreading
                    };
                    try
                    {
                        string status;
                        //generate content for the process
                        Parallel.ForEach(Central, options, (x, y, i) =>
                        {
                            int key = unchecked ((int)i);
                            status  = ContentProcess(key, ring, prjKey, YearList, Holding, Central[key], SQLConnectionString);
                            Status.Add(status);
                        });
                    }
                    catch (Exception)
                    {
                        //Failed.Add(Holding[i] + "threw an " + e);

                        throw new Exception();
                    }
                }
                //then multithreading is not true
                else if (multithreading < 1 && Central.Count > 0)
                {
                    for (int i = 0; i < Central.Count; i++)
                    {
                        string status = ContentProcess(i, ring, prjKey, YearList, Holding, Central[i], SQLConnectionString);
                        Status.Add(status);
                    }
                    ;
                }
                else
                {
                    string exmsg = "The List 'Central' contained no content and is not Valid. Terminating Process";
                    Failed.Add(exmsg);
                };
            }
            finally
            {
                //Closing the SQL Connection.
                TidalWave.SQL.ConnectionClose(newConn);
            };
            counter.Stop();
            TimeSpan       ts           = counter.Elapsed;
            string         elapsedTime2 = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10);
            List <dynamic> Find         = new List <dynamic>();
            List <dynamic> Run          = new List <dynamic>();

            Find.Add(elapsedTime);
            Run.Add(elapsedTime2);
            Debug.WriteLine(elapsedTime2);
            container.Add(Status);
            //Return to Dynamo the Container of Everything that Happened.
            return(new Dictionary <string, List <dynamic> >
            {
                { "Central File Path", Central },
                { "Journal File Path", Proj },
                { "Find Time", Find },
                { "Run Time", Run },
                { "Failed Message", Failed },
                { "Failed Status", Status }
            });
        }