Esempio n. 1
0
        public void RunScenario(RunParameters parameters,bool showWindow)
        {
            if (Scenario == null)
            {
                MsgTools.ShowInfo(RiverSystemOptions.NEED_PROJECT_OPEN_MESSAGE);
                return;
            }

//            ProjectManager.Instance.SaveAuditLogMessage("Open run scenario window");
//            Scenario.outputManager = new Obsolete.Recording.OutputManager();

            if(parameters!=null)
                ApplyRunParameters(parameters);

            if (IsRunnable())
            {
               
                //                JobRunner.BeforeRun += new BeforeTemporalRunHandler(JobRunner_BeforeRun);
                Scenario.RunManager.UpdateEvent = new EventHandler<JobRunEventArgs>(JobRunner_Update);

                ScenarioRunWindow runWindow = null;
                var startOfRun = DateTime.Now;

                if (showWindow)
                {
                    runWindow = new ScenarioRunWindow(Scenario);
                    //runWindow.SetOwner(this);
                    //runWindow.WindowStartupLocation = WindowStartupLocation.CenterOwner;
                    //Enabled = false;
                    runWindow.Show();
                    ProjectManager.Instance.SaveAuditLogMessage("Run started at " + DateTime.Now);
                }


                Task x = Task.Factory.StartNew(() => Scenario.RunManager.Execute());
                while (!x.IsCompleted)
                {
                    Thread.Sleep(50);
                    Application.DoEvents();
                }

//                LogRunEnd(startOfRun);

                if (showWindow)
                {
                    ProjectManager.Instance.SaveAuditLogMessage("Run finished at " + DateTime.Now + " and took " + TimeTools.TimeSpanString(DateTime.Now - startOfRun));
                    runWindow.Close();
                    runWindow.Dispose();
                }
                //if so then run
                //running = true;

                //runControl = new ScenarioRunWindow(Scenario);
                //runControl.SetOwner(MainForm.Instance);
                //runControl.Show();

                //Scenario.RunManager.Execute();
                //                lock (lockObj)
                //                {
                //while (running)
                //{
                //    Thread.Sleep(50);
                //    Application.DoEvents();
                //    //Monitor.Wait(lockObj);
                //}
                //                }

                //runControl.Close();
                //runControl.Dispose();
            }

//            ProjectManager.Instance.SaveAuditLogMessage("Close run scenario window");
        }
Esempio n. 2
0
        public void TriggerRun(RunParameters parameters)
        {
            Log("Triggering a run.");
            ScenarioInvoker si = new ScenarioInvoker { Scenario = Scenario };
            try
            {
                si.RunScenario(parameters,RunningInGUI);
            }
            catch (Exception e)
            {
                Log("Run Failed");
                Log(e.Message);
                Log(e.StackTrace);
            }
            Run r = RunsForId("latest")[0];

            WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.Redirect;
            WebOperationContext.Current.OutgoingResponse.Headers.Add("Location",
                                                                     WebOperationContext.Current.IncomingRequest.Headers
                                                                         ["Location"] +
                                                                     String.Format("runs/{0}", r.RunNumber));
        }
Esempio n. 3
0
        //private void LogRunEnd(DateTime startOfRun)
        //{
        //    Type t = typeof (RunTracker);
        //    MethodInfo method = t.GetMethod("RunCompleted", BindingFlags.Public | BindingFlags.Static);

        //    try
        //    {
        //        method.Invoke(null, new object[] {Scenario.Project, Scenario, startOfRun});
        //    }
        //    catch(Exception)
        //    {
        //        method.Invoke(null, new object[] { Scenario.Project, startOfRun });
        //    }
        //}

        private void ApplyRunParameters(RunParameters parameters)
        {
            RunningConfiguration configuration = Scenario.CurrentConfiguration;
            Type configType = configuration.GetType();
            foreach (var entry in parameters.Params)
            {
                var prop = configType.GetProperty(entry.Key, BindingFlags.Instance | BindingFlags.Public);
                if (prop == null)
                {
                    throw new NotImplementedException(String.Format(
                        "Running configuration doesn't have a property: {0}", entry.Key));
                }
                if (prop.PropertyType == typeof (DateTime))
                {
                    DateTime dt = DateTime.ParseExact(entry.Value.ToString(), "dd/MM/yyyy", CultureInfo.InvariantCulture);
                    prop.SetValue(configuration,dt);
                }
                else if (prop.PropertyType == typeof (InputSet))
                {
                    InputSet set = Scenario.Network.InputSets.FirstOrDefault(ipSet => ipSet.Name == (string)entry.Value);
                    prop.SetValue(configuration,set);
                }
                else
                {
                    prop.SetValue(configuration, entry.Value);
                }
            }
        }