Ejemplo n.º 1
0
 protected override void InitializeSinter(Data.Contract.Behaviors.IJobConsumerContract job,
                                          string workingDir, string config)
 {
     if (IsSupported(job) == false)
     {
         throw new ArgumentException(String.Format("Excel:  Found wrong Application {0}", job.ApplicationName));
     }
     sim            = new sinter.sinter_SimExcel();
     sim.setupFile  = new sinter.sinter_JsonSetupFile();
     sim.workingDir = workingDir;
     sim.setupFile.parseFile(config);
 }
Ejemplo n.º 2
0
 protected override bool IsSupported(Data.Contract.Behaviors.IJobConsumerContract job)
 {
     return(job.ApplicationName != null && job.ApplicationName.ToLower().Equals("excel"));
 }
Ejemplo n.º 3
0
        protected override bool RunNoReset(Data.Contract.Behaviors.IJobConsumerContract job)
        {
            //throw new NotImplementedException();
            if (job.SimulationId != last_simulation_name)
            {
                return(false);
            }

            if ((sim.GetType() == typeof(sinter.sinter_SimExcel)))
            {
                // hack to see whether Excel has already been initialized
                // should implement an interface "closed"
                try
                {
                    bool test = ((sinter.sinter_SimExcel)sim).Vis;
                }
                catch (NullReferenceException)
                {
                    return(false);
                }
            }

            if (last_simulation_success == false)
            {
                return(false);
            }

            IProcess process = null;

            Debug.WriteLine(String.Format("Reusing Sinter({0}) : Job {1}", job.ApplicationName, job.Id),
                            "ExcelSinterConsumer.RunNoReset");

            try
            {
                process = job.Setup();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message, "ExcelSinterConsumer.RunNoReset.DoSetup");
                Debug.WriteLine(ex.StackTrace, "ExcelSinterConsumer.RunNoReset.DoSetup");
                throw;
            }

            job.Message("Setup: Reusing Sinter Excel");
            Debug.WriteLine(String.Format("Move Job {0} to state Running", job.Id),
                            "ExcelSinterConsumer.RunNoReset");

            job.Running();

            IDictionary <String, Object> inputDict = null;
            String  data     = null;
            JObject defaults = null;
            JObject inputs   = null;

            // NOTE: Quick Fix. Serializing Dicts into string json
            // and back to JObject because of API change to sinter.
            // Better to refactor interfaces, etc to hand back strings
            try
            {
                inputDict = process.Input;
                data      = JsonConvert.SerializeObject(inputDict);
                inputs    = JObject.Parse(data);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(String.Format("Move Job {0} to state error", job.Id),
                                "ExcelSinterConsumer.RunNoReset");
                Debug.WriteLine(ex.Message, "ExcelSinterConsumer.RunNoReset");
                Debug.WriteLine(ex.StackTrace, "ExcelSinterConsumer.RunNoReset");
                sim.closeSim();
                job.Error("Failed to Create Inputs to Simulation (Bad Simulation defaults or Job inputs)");
                job.Message(ex.StackTrace.ToString());
                throw;
            }

            Debug.WriteLine("Run", "ExcelSinterConsumer.RunNoReset");
            try
            {
                DoRun(job, sim, defaults, inputs);
            }
            catch (System.Data.SqlClient.SqlException ex)
            {
                Debug.WriteLine("SqlException: " + ex.Message, "ExcelSinterConsumer.RunNoReset");
                Debug.WriteLine(ex.StackTrace, "ExcelSinterConsumer.RunNoReset");
                sim.closeSim();
                sim = null;
                throw;
            }
            catch (Exception ex)
            {
                Debug.WriteLine("DoRun Exception Close", "ExcelSinterConsumer.RunNoReset");
                Debug.WriteLine(ex.Message, "ExcelSinterConsumer.RunNoReset");
                Debug.WriteLine(ex.StackTrace, "ExcelSinterConsumer.RunNoReset");
                //if (CheckTerminate() == false)
                if (isTerminated == false)
                {
                    job.Error("Exception: " + ex.Message);
                    sim.closeSim();
                }
                sim = null;
                throw;
            }

            Debug.WriteLine("Finalize", "ExcelSinterConsumer.RunNoReset");
            try
            {
                DoFinalize(sim, job, process);
            }
            catch (System.Data.SqlClient.SqlException ex)
            {
                Debug.WriteLine("SqlException: " + ex.Message, "ExcelSinterConsumer.RunNoReset");
                Debug.WriteLine(ex.StackTrace, "ExcelSinterConsumer.RunNoReset");
                sim.closeSim();
                sim = null;
                throw;
            }
            catch (DbEntityValidationException dbEx)
            {
                Debug.WriteLine("DbEntityValidationException: " + dbEx.Message, "ExcelSinterConsumer.RunNoReset");
                Debug.WriteLine(dbEx.StackTrace, "ExcelSinterConsumer.RunNoReset");

                var msg = String.Empty;
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        msg += String.Format("Property: {0} Error: {1}",
                                             validationError.PropertyName,
                                             validationError.ErrorMessage);
                        Debug.WriteLine(msg, "ExcelSinterConsumer.RunNoReset");
                        Trace.TraceInformation("Property: {0} Error: {1}",
                                               validationError.PropertyName,
                                               validationError.ErrorMessage);
                        msg += ". \n";
                    }
                }

                job.Error("Exception: " + msg);
                sim.closeSim();
                sim = null;
                throw;
            }
            catch (Exception ex)
            {
                Debug.WriteLine("DoFinalize Exception Close", "ExcelSinterConsumer.RunNoReset");
                Debug.WriteLine(ex.Message, "ExcelSinterConsumer.RunNoReset");
                Debug.WriteLine(ex.StackTrace, "ExcelSinterConsumer.RunNoReset");
                job.Error("Exception: " + ex.Message);
                sim.closeSim();
                sim = null;
                throw;
            }
            return(true);
        }