Example #1
0
        private void UpdateAllFileInfoAndAppTask()
        {
            StringBuilder sbBody    = new StringBuilder();
            StringBuilder sbSubject = new StringBuilder();

            TVFile tvFilem21_3fm = (from c in db.TVItems
                                    from ms in db.MikeScenarios
                                    from f in db.TVFiles
                                    from cc in db.TVItems
                                    where c.TVItemID == ms.MikeScenarioTVItemID &&
                                    f.TVFileTVItemID == cc.TVItemID &&
                                    cc.ParentID == c.TVItemID &&
                                    (f.FileType == (int)FileTypeEnum.M21FM || f.FileType == (int)FileTypeEnum.M3FM) &&
                                    ms.MikeScenarioTVItemID == MikeScenarioTVItemID
                                    select f).FirstOrDefault <TVFile>();

            if (tvFilem21_3fm == null)
            {
                UpdateTaskError(AppTaskID, "Error: Could not find CSSPFile of type .m21fm or .m3fm and MikeScenarioID [" + MikeScenarioTVItemID + "]");
                richTextBoxStatus.AppendText("Error: Could not find CSSPFile of type .m21fm or .m3fm and MikeScenarioID [" + MikeScenarioTVItemID + "]\r\n");
                return;
            }

            FileInfo fiServer = new FileInfo(tvFilem21_3fm.ServerFilePath + tvFilem21_3fm.ServerFileName);

            if (!fiServer.Exists)
            {
                UpdateTaskError(AppTaskID, "File [" + fiServer.FullName + "] could not be found on the server.");
                richTextBoxStatus.AppendText("File [" + fiServer.FullName + "] could not be found on the server.\r\n");
                return;
            }

            PFSFile pfsFile = new PFSFile(tvFilem21_3fm.ServerFilePath + tvFilem21_3fm.ServerFileName);

            if (pfsFile == null)
            {
                UpdateTaskError(AppTaskID, "File [" + fiServer.FullName + "] could not be parsed properly");
                richTextBoxStatus.AppendText("File [" + fiServer.FullName + "] could not be parsed properly\r\n");
                return;
            }

            LogFileName = fiServer.FullName.Replace(".m21fm", ".log").Replace(".m3fm", ".log");

            FileInfo fiLog = new FileInfo(LogFileName);

            if (!fiLog.Exists)
            {
                UpdateTaskError(AppTaskID, "File [" + fiLog.FullName + "] could not be found on the server.");
                richTextBoxStatus.AppendText("File [" + fiLog.FullName + "] could not be found on the server.\r\n");
                return;
            }

            List <int> TVItemIDToDeleteList = new List <int>();

            // doing the log file

            TVFile tvFileLog = (from c in db.TVItems
                                from ms in db.MikeScenarios
                                from f in db.TVFiles
                                from cc in db.TVItems
                                where c.TVItemID == ms.MikeScenarioTVItemID &&
                                f.TVFileTVItemID == cc.TVItemID &&
                                cc.ParentID == c.TVItemID &&
                                f.FileType == (int)FileTypeEnum.LOG &&
                                f.ServerFileName == fiLog.Name &&
                                ms.MikeScenarioTVItemID == MikeScenarioTVItemID
                                select f).FirstOrDefault <TVFile>();

            if (tvFileLog == null)
            {
                string retStr = "Error: Could not find log result file belonging to the excecuted MikeScenarioID [" + MikeScenarioTVItemID + "].";
                UpdateTaskError(AppTaskID, retStr);
                richTextBoxStatus.AppendText(retStr + "\r\n");
                return;
            }

            fiLog = new FileInfo(LogFileName);

            tvFileLog.FileSize_kb               = (int)(fiLog.Length / 1024);
            tvFileLog.FileCreatedDate_UTC       = DateTime.UtcNow;
            tvFileLog.LastUpdateDate_UTC        = DateTime.UtcNow;
            tvFileLog.LastUpdateContactTVItemID = ContactTVItemID;

            try
            {
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                UpdateTaskError(AppTaskID, "Error: Could not save modified log file belonging to the excecuted MikeScenarioID [" + MikeScenarioTVItemID + "]. \r\n Error Message: [" + ex.Message + "]");
                richTextBoxStatus.AppendText("Error: Could not save modified log file belonging to the excecuted MikeScenarioID [" + MikeScenarioTVItemID + "]. \r\n Error Message: [" + ex.Message + "]\r\n");
                return;
            }

            // doing the hydro file .dfsu

            FileInfo fiHydro = new FileInfo(HydroFileName);

            TVFile tvFileHydro = (from c in db.TVItems
                                  from ms in db.MikeScenarios
                                  from f in db.TVFiles
                                  from cc in db.TVItems
                                  where c.TVItemID == ms.MikeScenarioTVItemID &&
                                  f.TVFileTVItemID == cc.TVItemID &&
                                  cc.ParentID == c.TVItemID &&
                                  f.FileType == (int)FileTypeEnum.DFSU &&
                                  f.ServerFileName == fiHydro.Name &&
                                  ms.MikeScenarioTVItemID == MikeScenarioTVItemID
                                  select f).FirstOrDefault <TVFile>();

            if (tvFileHydro == null)
            {
                UpdateTaskError(AppTaskID, "Error: Could not find one hydrodynamic result file belonging to the excecuted MikeScenarioID [" + MikeScenarioTVItemID + "]. \r\n");
                richTextBoxStatus.AppendText("Error: Could not find one hydrodynamic result file belonging to the excecuted MikeScenarioID [" + MikeScenarioTVItemID + "]. \r\n");
                return;
            }

            fiHydro = new FileInfo(HydroFileName);

            tvFileHydro.FileSize_kb               = (int)(fiHydro.Length / 1024);
            tvFileHydro.FileCreatedDate_UTC       = DateTime.UtcNow;
            tvFileHydro.LastUpdateDate_UTC        = DateTime.UtcNow;
            tvFileHydro.LastUpdateContactTVItemID = ContactTVItemID;

            try
            {
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                UpdateTaskError(AppTaskID, "Error: Could not save modified hydrodynamic result file belonging to the excecuted MikeScenarioID [" + MikeScenarioTVItemID + "]. \r\n Error Message: [" + ex.Message + "]");
                richTextBoxStatus.AppendText("Error: Could not save hydrodynamic result file belonging to the excecuted MikeScenarioID [" + MikeScenarioTVItemID + "]. \r\n Error Message: [" + ex.Message + "]\r\n");
                return;
            }

            // doing the hydro file .dfsu
            FileInfo fiTrans = new FileInfo(TransFileName);

            TVFile tvFileTrans = (from c in db.TVItems
                                  from ms in db.MikeScenarios
                                  from f in db.TVFiles
                                  from cc in db.TVItems
                                  where c.TVItemID == ms.MikeScenarioTVItemID &&
                                  f.TVFileTVItemID == cc.TVItemID &&
                                  cc.ParentID == c.TVItemID &&
                                  f.FileType == (int)FileTypeEnum.DFSU &&
                                  f.ServerFileName == fiTrans.Name &&
                                  ms.MikeScenarioTVItemID == MikeScenarioTVItemID
                                  select f).FirstOrDefault <TVFile>();

            if (tvFileTrans == null)
            {
                UpdateTaskError(AppTaskID, "Error: Could not find one transport result file belonging to the excecuted MikeScenarioID [" + MikeScenarioTVItemID + "]. \r\n");
                richTextBoxStatus.AppendText("Error: Could not find one transport result file belonging to the excecuted MikeScenarioID [" + MikeScenarioTVItemID + "]. \r\n");
                return;
            }

            fiTrans = new FileInfo(TransFileName);

            tvFileTrans.FileSize_kb               = (int)(fiTrans.Length / 1024);
            tvFileTrans.FileCreatedDate_UTC       = DateTime.UtcNow;
            tvFileTrans.LastUpdateDate_UTC        = DateTime.UtcNow;
            tvFileTrans.LastUpdateContactTVItemID = ContactTVItemID;

            try
            {
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                UpdateTaskError(AppTaskID, "Error: Could not save modified transport result file belonging to the excecuted MikeScenarioID [" + MikeScenarioTVItemID + "]. \r\n Error Message: [" + ex.Message + "]");
                richTextBoxStatus.AppendText("Error: Could not save transport result file belonging to the excecuted MikeScenarioID [" + MikeScenarioTVItemID + "]. \r\n Error Message: [" + ex.Message + "]\r\n");
                return;
            }

            MikeScenario mikeScenario = (from c in db.MikeScenarios
                                         where c.MikeScenarioTVItemID == MikeScenarioTVItemID
                                         select c).FirstOrDefault();

            if (mikeScenario == null)
            {
                UpdateTaskError(AppTaskID, "Error: Could not find MikeScenario with MikeScenarioID [" + MikeScenarioTVItemID + "]. \r\n");
                richTextBoxStatus.AppendText("Error: Could not find MikeScenario with MikeScenarioID [" + MikeScenarioTVItemID + "]. \r\n");
                return;
            }

            if (mikeScenario.GenerateDecouplingFiles == true)
            {
                string TVTextMikeScenario = (from c in db.TVItemLanguages
                                             where c.TVItemID == MikeScenarioTVItemID &&
                                             c.Language == (int)LanguageEnum.en
                                             select c.TVText).FirstOrDefault();

                if (string.IsNullOrWhiteSpace(TVTextMikeScenario))
                {
                    UpdateTaskError(AppTaskID, "Error: Could not find TVTextMikeScenario with MikeScenarioID [" + MikeScenarioTVItemID + "]. \r\n");
                    richTextBoxStatus.AppendText("Error: Could not find TVTextMikeScenario with MikeScenarioID [" + MikeScenarioTVItemID + "]. \r\n");
                    return;
                }



                // doing the {TVTextMikeScenario}_Decoupled.m21fm or .m3fm
                FileInfo fiDecoupled = new FileInfo(FileNameM21_3fm.Replace(".m21fm", "_Decoupled.m21fm").Replace(".m3fm", "_Decoupled.m3fm"));

                FileTypeEnum fileType = (FileNameM21_3fm.EndsWith(".m21fm") ? FileTypeEnum.M21FM : FileTypeEnum.M3FM);

                TVFile tvFileDecoupled = (from c in db.TVItems
                                          from ms in db.MikeScenarios
                                          from f in db.TVFiles
                                          from cc in db.TVItems
                                          where c.TVItemID == ms.MikeScenarioTVItemID &&
                                          f.TVFileTVItemID == cc.TVItemID &&
                                          cc.ParentID == c.TVItemID &&
                                          f.FileType == (int)fileType &&
                                          f.ServerFileName == fiDecoupled.Name &&
                                          ms.MikeScenarioTVItemID == MikeScenarioTVItemID
                                          select f).FirstOrDefault <TVFile>();

                if (tvFileDecoupled == null)
                {
                    UpdateTaskError(AppTaskID, "Error: Could not find file [" + fiDecoupled.FullName + " under MikeScenarioID [" + MikeScenarioTVItemID + "]. \r\n");
                    richTextBoxStatus.AppendText("Error: Could not find file [" + fiDecoupled.FullName + " under MikeScenarioID [" + MikeScenarioTVItemID + "]. \r\n");
                    return;
                }

                fiDecoupled = new FileInfo(fiDecoupled.FullName);

                tvFileDecoupled.FileSize_kb               = (int)(fiDecoupled.Length / 1024);
                tvFileDecoupled.FileCreatedDate_UTC       = DateTime.UtcNow;
                tvFileDecoupled.LastUpdateDate_UTC        = DateTime.UtcNow;
                tvFileDecoupled.LastUpdateContactTVItemID = ContactTVItemID;

                try
                {
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    UpdateTaskError(AppTaskID, "Error: Could not save TVFile info of [" + fiDecoupled.FullName + "] MikeScenarioID [" + MikeScenarioTVItemID + "]. \r\n Error Message: [" + ex.Message + "]");
                    richTextBoxStatus.AppendText("Error: Could not save TVFile info of [" + fiDecoupled.FullName + "] MikeScenarioID [" + MikeScenarioTVItemID + "]. \r\n Error Message: [" + ex.Message + "]\r\n");
                    return;
                }

                // doing the {TVTextMikeScenario}_DecouplingArea.dfsu
                FileInfo fiDecouplingArea = new FileInfo(FileNameM21_3fm.Replace(".m21fm", "_DecouplingArea.dfsu").Replace(".m3fm", "_DecouplingArea.dfsu"));

                TVFile tvFileDecouplingArea = (from c in db.TVItems
                                               from ms in db.MikeScenarios
                                               from f in db.TVFiles
                                               from cc in db.TVItems
                                               where c.TVItemID == ms.MikeScenarioTVItemID &&
                                               f.TVFileTVItemID == cc.TVItemID &&
                                               cc.ParentID == c.TVItemID &&
                                               f.FileType == (int)FileTypeEnum.DFSU &&
                                               f.ServerFileName == fiDecouplingArea.Name &&
                                               ms.MikeScenarioTVItemID == MikeScenarioTVItemID
                                               select f).FirstOrDefault <TVFile>();

                if (fiDecouplingArea == null)
                {
                    UpdateTaskError(AppTaskID, "Error: Could not find file [" + fiDecouplingArea.FullName + " under MikeScenarioID [" + MikeScenarioTVItemID + "]. \r\n");
                    richTextBoxStatus.AppendText("Error: Could not find file [" + fiDecouplingArea.FullName + " under MikeScenarioID [" + MikeScenarioTVItemID + "]. \r\n");
                    return;
                }

                fiDecouplingArea = new FileInfo(fiDecouplingArea.FullName);

                tvFileDecouplingArea.FileSize_kb               = (int)(fiDecouplingArea.Length / 1024);
                tvFileDecouplingArea.FileCreatedDate_UTC       = DateTime.UtcNow;
                tvFileDecouplingArea.LastUpdateDate_UTC        = DateTime.UtcNow;
                tvFileDecouplingArea.LastUpdateContactTVItemID = ContactTVItemID;

                try
                {
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    UpdateTaskError(AppTaskID, "Error: Could not save TVFile info of [" + fiDecouplingArea.FullName + "] MikeScenarioID [" + MikeScenarioTVItemID + "]. \r\n Error Message: [" + ex.Message + "]");
                    richTextBoxStatus.AppendText("Error: Could not save TVFile info of [" + fiDecouplingArea.FullName + "] MikeScenarioID [" + MikeScenarioTVItemID + "]. \r\n Error Message: [" + ex.Message + "]\r\n");
                    return;
                }

                // doing the {TVTextMikeScenario}_DecouplingFlux.dfsu
                FileInfo fiDecouplingFlux = new FileInfo(FileNameM21_3fm.Replace(".m21fm", "_DecouplingFlux.dfsu").Replace(".m3fm", "_DecouplingFlux.dfsu"));

                TVFile tvFileDecouplingFlux = (from c in db.TVItems
                                               from ms in db.MikeScenarios
                                               from f in db.TVFiles
                                               from cc in db.TVItems
                                               where c.TVItemID == ms.MikeScenarioTVItemID &&
                                               f.TVFileTVItemID == cc.TVItemID &&
                                               cc.ParentID == c.TVItemID &&
                                               f.FileType == (int)FileTypeEnum.DFSU &&
                                               f.ServerFileName == fiDecouplingFlux.Name &&
                                               ms.MikeScenarioTVItemID == MikeScenarioTVItemID
                                               select f).FirstOrDefault <TVFile>();

                if (fiDecouplingFlux == null)
                {
                    UpdateTaskError(AppTaskID, "Error: Could not find file [" + fiDecouplingFlux.FullName + " under MikeScenarioID [" + MikeScenarioTVItemID + "]. \r\n");
                    richTextBoxStatus.AppendText("Error: Could not find file [" + fiDecouplingFlux.FullName + " under MikeScenarioID [" + MikeScenarioTVItemID + "]. \r\n");
                    return;
                }

                fiDecouplingFlux = new FileInfo(fiDecouplingFlux.FullName);

                tvFileDecouplingFlux.FileSize_kb               = (int)(fiDecouplingFlux.Length / 1024);
                tvFileDecouplingFlux.FileCreatedDate_UTC       = DateTime.UtcNow;
                tvFileDecouplingFlux.LastUpdateDate_UTC        = DateTime.UtcNow;
                tvFileDecouplingFlux.LastUpdateContactTVItemID = ContactTVItemID;

                try
                {
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    UpdateTaskError(AppTaskID, "Error: Could not save TVFile info of [" + fiDecouplingFlux.FullName + "] MikeScenarioID [" + MikeScenarioTVItemID + "]. \r\n Error Message: [" + ex.Message + "]");
                    richTextBoxStatus.AppendText("Error: Could not save TVFile info of [" + fiDecouplingFlux.FullName + "] MikeScenarioID [" + MikeScenarioTVItemID + "]. \r\n Error Message: [" + ex.Message + "]\r\n");
                    return;
                }
            }
        }
Example #2
0
        private string StartProcess()
        {
            // starting MzLaunch.exe application
            ProcessStartInfo pInfoMz = new ProcessStartInfo();

            MikeScenario mikeScenario = (from c in db.MikeScenarios
                                         where c.MikeScenarioTVItemID == MikeScenarioTVItemID
                                         select c).FirstOrDefault();

            if (mikeScenario == null)
            {
                string errStr = "Error: Could not find MikeScenario with MikeScenarioID [" + MikeScenarioTVItemID + "]. \r\n";
                UpdateTaskError(AppTaskID, errStr);
                richTextBoxStatus.AppendText(errStr);
                return(errStr);
            }

            string FileNameToRun = FileNameM21_3fm;

            //if (mikeScenario.UseDecouplingFiles == true)
            //{
            //    FileNameToRun = FileNameM21_3fm.Replace(".m21fm", "_Decoupled.m21fm").Replace(".3fm", "_Decoupled.3fm");
            //}

            pInfoMz.Arguments       = " \"" + FileNameToRun + "\" " + "-x";
            pInfoMz.WindowStyle     = ProcessWindowStyle.Minimized;
            pInfoMz.UseShellExecute = true;

            Process processMike = new Process();

            processMike.StartInfo = pInfoMz;
            try
            {
                pInfoMz.FileName = @"C:\Program Files (x86)\DHI\2016\bin\x64\MzLaunch.exe";
                processMike.Start();
            }
            catch (Exception ex)
            {
                string ErrorText = "File [" + pInfoMz.FileName + "] could not run. Error Message: [" + ex.Message + "]";
                richTextBoxStatus.Text = ErrorText + "\r\n";
                UpdateTaskError(AppTaskID, "");
                return(ErrorText);
            }

            UpdateTaskError(AppTaskID, "");
            UpdateTaskPercent(AppTaskID, 5);

            mikeScenario.ScenarioStatus = (int)ScenarioStatusEnum.Running;

            try
            {
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                UpdateTaskError(AppTaskID, ex.Message + (ex.InnerException != null ? " Inner: " + ex.InnerException.Message : ""));
            }

            processMike.WaitForInputIdle(2000);

            timerUpdater.Enabled  = true;
            timerUpdater.Interval = 3000;
            timerUpdater.Start();

            return("");
        }
Example #3
0
        private string Setup()
        {
            string retStr = "";

            lblAppTaskIDValue.Text      = "...";
            lblMikeScenarioIDValue.Text = "...";

            AppTask appTask = (from c in db.AppTasks
                               from t in db.TVItems
                               from m in db.MikeScenarios
                               where c.TVItemID == t.TVItemID &&
                               t.TVItemID == m.MikeScenarioTVItemID &&
                               c.AppTaskCommand == (int)AppTaskCommandEnum.MikeScenarioWaitingToRun &&
                               c.AppTaskStatus == (int)AppTaskStatusEnum.Running &&
                               t.TVType == (int)TVTypeEnum.MikeScenario &&
                               m.ScenarioStatus == (int)ScenarioStatusEnum.AskToRun
                               select c).FirstOrDefault();

            if (appTask == null)
            {
                this.Close();
            }

            AppTaskID            = appTask.AppTaskID;
            MikeScenarioTVItemID = appTask.TVItemID;
            ContactTVItemID      = appTask.LastUpdateContactTVItemID;

            lblAppTaskIDValue.Text      = AppTaskID.ToString();
            lblMikeScenarioIDValue.Text = MikeScenarioTVItemID.ToString();

            if (!DongleIsPlugged())
            {
                UpdateTaskError(AppTaskID, UpdaterRes.Mike21_3DongleNotFound);
                return(UpdaterRes.Mike21_3DongleNotFound);
            }

            this.Text = "Mike Scenario Updater " + MikeScenarioTVItemID;

            Contact contact = (from c in db.Contacts
                               where c.ContactTVItemID == ContactTVItemID
                               select c).FirstOrDefault();

            if (contact == null)
            {
                retStr = "Could not find Contact with ContactTVItemID [" + ContactTVItemID + "]";
                UpdateTaskError(AppTaskID, retStr);
                richTextBoxStatus.AppendText(retStr + "\r\n");
                return(retStr);
            }
            lblContactValue.Text = contact.FirstName + (string.IsNullOrWhiteSpace(contact.Initial) ? "" : " " + contact.Initial) + " " + contact.LastName;

            MikeScenario mikeScenario = (from c in db.MikeScenarios
                                         where c.MikeScenarioTVItemID == MikeScenarioTVItemID
                                         select c).FirstOrDefault();

            if (mikeScenario == null)
            {
                retStr = "Could not find MikeScenario with MikeScenarioTVItemID [" + MikeScenarioTVItemID + "]";
                UpdateTaskError(AppTaskID, retStr);
                richTextBoxStatus.AppendText(retStr + "\r\n");
                return(retStr);
            }

            EstimatedHydroFileSize = (long)mikeScenario.EstimatedHydroFileSize;
            EstimatedTransFileSize = (long)mikeScenario.EstimatedTransFileSize;

            lblEstimatedHydroFileSizeValue.Text = EstimatedHydroFileSize.ToString();
            lblEstimatedTransFileSizeValue.Text = EstimatedTransFileSize.ToString();


            // should get m21fm or m3fm file name

            List <TVFile> tvFilem21_3fmList = (from c in db.TVItems
                                               from ms in db.MikeScenarios
                                               from f in db.TVFiles
                                               from cc in db.TVItems
                                               where c.TVItemID == ms.MikeScenarioTVItemID &&
                                               f.TVFileTVItemID == cc.TVItemID &&
                                               cc.ParentID == c.TVItemID &&
                                               (f.FileType == (int)FileTypeEnum.M21FM || f.FileType == (int)FileTypeEnum.M3FM) &&
                                               ms.MikeScenarioTVItemID == MikeScenarioTVItemID
                                               select f).ToList <TVFile>();

            if (tvFilem21_3fmList.Count == 0)
            {
                retStr = "Error: Could not find CSSPFile of type .m21fm or .m3fm and MikeScenarioID [" + MikeScenarioTVItemID + "]";
                UpdateTaskError(AppTaskID, retStr);
                richTextBoxStatus.AppendText(retStr + "\r\n");
                return(retStr);
            }

            TVFile tvFilem21_3fm = null;

            foreach (TVFile tvFile in tvFilem21_3fmList)
            {
                if (mikeScenario.UseDecouplingFiles == true)
                {
                    if (tvFile.ServerFileName.Contains("_Decoupled"))
                    {
                        tvFilem21_3fm = tvFile;
                    }
                }
                else
                {
                    if (!tvFile.ServerFileName.Contains("_Decoupled"))
                    {
                        tvFilem21_3fm = tvFile;
                    }
                }
            }

            if (tvFilem21_3fm == null)
            {
                retStr = "Error: Could not find CSSPFile of type .m21fm or .m3fm and MikeScenarioID [" + MikeScenarioTVItemID + "]";
                UpdateTaskError(AppTaskID, retStr);
                richTextBoxStatus.AppendText(retStr + "\r\n");
                return(retStr);
            }
            FileNameM21_3fm = tvFilem21_3fm.ServerFilePath + tvFilem21_3fm.ServerFileName;

            FileInfo fim21_3fm = new FileInfo(FileNameM21_3fm);

            if (!fim21_3fm.Exists)
            {
                retStr = "Error: Could not find file [" + fim21_3fm.FullName + " with MikeScenarioID [" + MikeScenarioTVItemID + "]";
                UpdateTaskError(AppTaskID, retStr);
                richTextBoxStatus.AppendText(retStr + "\r\n");
                return(retStr);
            }

            lblCurrentFileValue.Text = @"...\" + MikeScenarioTVItemID + @"\" + fim21_3fm.Name;

            LogFileName = fim21_3fm.FullName.Replace(".m21fm", ".log").Replace(".m21fm", ".log");

            PFSFile pfsFile = new PFSFile(FileNameM21_3fm);

            if (pfsFile == null)
            {
                retStr = "File [" + FileNameM21_3fm + "] could not be parsed properly";
                UpdateTaskError(AppTaskID, retStr);
                richTextBoxStatus.AppendText(retStr + "\r\n");
                return(retStr);
            }

            HydroFileName = GetParameterResultFileName(pfsFile, "FemEngineHD/HYDRODYNAMIC_MODULE/OUTPUTS/OUTPUT_1", "file_name");
            if (string.IsNullOrWhiteSpace(HydroFileName))
            {
                retStr = "HydroFileName could not be found";
                UpdateTaskError(AppTaskID, retStr);
                richTextBoxStatus.AppendText(retStr + "\r\n");
                return(retStr);
            }

            FileInfo fileHydro = new FileInfo(tvFilem21_3fm.ServerFilePath + HydroFileName);

            if (!fileHydro.Exists)
            {
                retStr = "Error: Could not find file [" + fileHydro.FullName + "]";
                UpdateTaskError(AppTaskID, retStr);
                richTextBoxStatus.AppendText(retStr + "\r\n");
                return(retStr);
            }

            HydroFileName = fileHydro.FullName;

            lblHydroFileNameValue.Text = @"...\" + MikeScenarioTVItemID + @"\" + fileHydro.Name;

            TransFileName = GetParameterResultFileName(pfsFile, "FemEngineHD/TRANSPORT_MODULE/OUTPUTS/OUTPUT_1", "file_name");
            if (string.IsNullOrWhiteSpace(TransFileName))
            {
                retStr = "TransFileName could not be found";
                UpdateTaskError(AppTaskID, retStr);
                richTextBoxStatus.AppendText(retStr + "\r\n");
                return(retStr);
            }

            FileInfo fileTrans = new FileInfo(tvFilem21_3fm.ServerFilePath + TransFileName);

            if (!fileTrans.Exists)
            {
                retStr = "Error: Could not find file [" + fileTrans.FullName + "]";
                UpdateTaskError(AppTaskID, retStr);
                richTextBoxStatus.AppendText(retStr + "\r\n");
                return(retStr);
            }

            TransFileName = fileTrans.FullName;

            lblTransFileNameValue.Text = @"...\" + MikeScenarioTVItemID + @"\" + fileTrans.Name;

            return("");
        }
Example #4
0
        private void DoUpdate()
        {
            if (IsProcessRunning())
            {
                richTextBoxStatus.AppendText("Running ...\r\n");
                if (HydroFileName != "")
                {
                    FileInfo fiHydro = new FileInfo(HydroFileName);

                    if (EstimatedHydroFileSize > 0)
                    {
                        UpdateTaskStatusText(AppTaskID, string.Format(UpdaterRes.Running_Completed_fr, (100.0 * (float)fiHydro.Length / (float)EstimatedHydroFileSize)));
                        UpdateTaskPercent(AppTaskID, (int)(100.0 * (float)fiHydro.Length / (float)EstimatedHydroFileSize));
                        richTextBoxStatus.AppendText(string.Format("Running ... {0:F0} % completed ...\r\n", (100.0 * (float)fiHydro.Length / (float)EstimatedHydroFileSize)));
                    }
                }
                else
                {
                    FileInfo fiTrans = new FileInfo(TransFileName);

                    if (EstimatedTransFileSize > 0)
                    {
                        UpdateTaskStatusText(AppTaskID, string.Format(UpdaterRes.Running_Completed_fr, (100.0 * (float)fiTrans.Length / (float)EstimatedTransFileSize)));
                        UpdateTaskPercent(AppTaskID, (int)(100.0 * (float)fiTrans.Length / (float)EstimatedTransFileSize));
                        richTextBoxStatus.AppendText(string.Format("Running ... {0:F0} % completed ...\r\n", (100.0 * (float)fiTrans.Length / (float)EstimatedTransFileSize)));
                    }
                }
            }
            else
            {
                timerUpdater.Stop();

                richTextBoxStatus.AppendText("Not currently working\r\n");

                // should be changing MikeScenario status
                MikeScenario mikeScenarioToChange = (from ms in db.MikeScenarios
                                                     where ms.MikeScenarioTVItemID == MikeScenarioTVItemID
                                                     select ms).FirstOrDefault <MikeScenario>();

                if (mikeScenarioToChange == null)
                {
                    UpdateTaskError(AppTaskID, "Could not find MikeScenario to update. Looking for MikeScenarioID = [" + MikeScenarioTVItemID + "] ...");
                    richTextBoxStatus.AppendText("Could not find MikeScenario to update. Looking for MikeScenarioID = [" + MikeScenarioTVItemID + "] ... \r\n");
                    return;
                }

                FileInfo fiLog = new FileInfo(LogFileName);

                if (!fiLog.Exists)
                {
                    UpdateTaskError(AppTaskID, "Could not find file [" + LogFileName + "] on the server ... ");
                    richTextBoxStatus.AppendText("Could not find file [" + LogFileName + "] on the server ... \r\n");
                    return;
                }

                StringBuilder sb  = new StringBuilder();
                StreamReader  sr2 = fiLog.OpenText();
                sb.Append(sr2.ReadToEnd());
                sr2.Close();

                if (sb.ToString().Contains("Normal run completion"))
                {
                    mikeScenarioToChange.ScenarioStatus = (int)ScenarioStatusEnum.Completed;
                }
                else
                {
                    mikeScenarioToChange.ScenarioStatus = (int)ScenarioStatusEnum.Changed;
                }

                try
                {
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    UpdateTaskError(AppTaskID, "Could not update MikeScenario with .log file info. Error Message: " + ex.Message);
                    richTextBoxStatus.AppendText("Could not update MikeScenario with .log file info. Error Message: " + ex.Message + "\r\n");
                    return;
                }

                UpdateAllFileInfoAndAppTask();

                AppTask appTaskToDelete = (from c in db.AppTasks
                                           where c.AppTaskID == AppTaskID
                                           select c).FirstOrDefault();

                if (appTaskToDelete != null)
                {
                    db.AppTasks.Remove(appTaskToDelete);
                }

                try
                {
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    string retStr = "Could not delete AppTask with AppTaskID [" + AppTaskID + " Error: " + ex.Message;
                    UpdateTaskError(AppTaskID, retStr);
                    richTextBoxStatus.AppendText(retStr + "\r\n");
                    return;
                }

                timerUpdater.Start();

                DoNext();
            }
        }