Esempio n. 1
0
        private void UpdateTaskPercent(int AppTaskID, int Percent)
        {
            AppTask AppTaskToUpdate = (from c in db.AppTasks
                                       where c.AppTaskID == AppTaskID
                                       select c).FirstOrDefault <AppTask>();

            if (AppTaskToUpdate == null)
            {
                return;
            }

            AppTaskToUpdate.PercentCompleted = Percent;

            try
            {
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                richTextBoxStatus.AppendText(string.Format("AppTask percent could not be updated for AppTask [{0}]", AppTaskID) + " Error Message: " + ex.Message + "\r\n");
                return;
            }
        }
Esempio n. 2
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("");
        }
Esempio n. 3
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();
            }
        }