Ejemplo n.º 1
0
 public void close()
 {
     modelToRun.Reader = null;
     modelToRun.Writer = null;
     S8Machine.getSIMU8().Close();
     //S8Machine.getSIMU8().Quit();
     modelToRun = null;
     GC.Collect();
     GC.WaitForPendingFinalizers();
 }
Ejemplo n.º 2
0
 public void close()
 {
     S8Machine.getSIMU8().Close();
 }
Ejemplo n.º 3
0
        string[] getBasedonExcel(Stream data)
        {
            /*
             * resultStringArray[0] = RTNstatus;
             * resultStringArray[1] = RTNTag;
             * resultStringArray[2] = RTNValue;
             */
            string[] resultStringArray = new string[3];

            ERFSIMUL MySim = null;

            //new Excel.Application();
            Excel.Application xlApp  = null; //new Excel.Application();
            Excel.Workbook    xlbook = null;
            bool S8LoadFlag          = false;

            StreamReader sr         = new StreamReader(data);
            string       stringData = sr.ReadToEnd();

            //string path = @"c:\MyTest.txt";
            int timestamp = Convert.ToInt32(DateTime.UtcNow.AddHours(8).Subtract(new DateTime(1970, 1, 1)).TotalSeconds);

            string MyID     = OperationContext.Current.SessionId;
            string filename = xmlBase + "ERPModel.XML";
            //string datafilename = @"~/XML/H_ER.xlsx";
            string datafilename = xmlBase + timestamp + ".xlsx";

            string value = stringData.Substring(4);

            string[] inputText = value.Split(new string[] { "%2C" }, StringSplitOptions.RemoveEmptyEntries);


            resultStringArray[1] = value;
            string path1 = System.Web.Hosting.HostingEnvironment.MapPath(filename);
            string path2 = System.Web.Hosting.HostingEnvironment.MapPath(datafilename);

            //RTNTag = "'" + MyID + "'";

            //string filename = path1 + "TableTest1.XML";
            try
            {
                if (inputText[0] == "A")
                {
                    string info = run_cmd("E:/Project/OpenSrcData/data/createModelData.py", "-o " + path2);

                    //StreamWriter sw = new StreamWriter(
                    //    System.Web.Hosting.HostingEnvironment.MapPath(@"~/XML/Result2.csv"));

                    //RTNValue = "' >>"+ans+">> '";
                    //sw.WriteLine("name,value,mean,sd-,sd+");
                    /////////////////////////////////////////////////////
                    //Excel.Workbook wb =

                    if (File.Exists(path2) == true)
                    {
                        //xlApp = new Excel.Application();
                        //initailExcel();
                        xlApp         = new Excel.Application();
                        xlApp.Visible = false;
                        //xlApp.DisplayAlerts = false;
                        //initailExcel();
                        xlbook = xlApp.Workbooks.Open(path2);
                        S8Machine.getSIMU8().Open(path1);
                        S8LoadFlag = true;
                        MySim      = new ERFSIMUL(S8Machine);
                        MySim.Load(path1);
                        //MySim.SetInputVariable(value);
                        //sw.WriteLine(inputText[1]);
                        MySim.SetTimesAnsLength(int.Parse(inputText[1]), Double.Parse(inputText[2]));
                        MySim.Run();
                        //RTNValue = MySim.GetResults();
                        resultStringArray[2] = MySim.GetJSON(Double.Parse(inputText[2]));

                        resultStringArray[0] = "VALUE";
                        //xlApp.Quit();
                    }
                    else
                    {
                        resultStringArray[0] = "ERROR";
                        resultStringArray[2] = "' Open xlsx error: " + info + "'";
                    }
                    /////////////////////////////////////////////////////
                    //sw.Close();
                }
            }
            catch (Exception ex)
            {
                resultStringArray[0] = "ERROR";
                resultStringArray[2] = "'" + ex.ToString() + "'";
                //RTNValue = "'" + RTNValue + "'";
            }
            finally
            {
                if (xlbook != null)
                {
                    xlbook.Close(Type.Missing, Type.Missing, Type.Missing);
                    xlbook = null;
                }

                if (xlApp != null)
                {
                    xlApp.Quit();
                    xlApp = null;
                }

                if (File.Exists(path2) == true)
                {
                    File.Delete(path2);
                }

                if (S8LoadFlag != false)
                {
                    S8Machine.getSIMU8().Close();
                }

                GC.Collect();
            }
            return(resultStringArray);
        }
Ejemplo n.º 4
0
        public List <Forecast_data> Forcasting(string time)
        {
            //StringBuilder strReturnValue = new StringBuilder();
            // return username prefixed as shown below
            //strReturnValue.Append(string.Format("You have entered userName as {0}", time));
            //return strReturnValue.ToString();

            //StreamReader sr = new StreamReader(data);
            //string stringData = sr.ReadToEnd();

            //string path = @"c:\MyTest.txt";
            int replicationnum = 5;
            int timestamp      = Convert.ToInt32(DateTime.UtcNow.AddHours(8).Subtract(new DateTime(1970, 1, 1)).TotalSeconds);

            //string MyID = OperationContext.Current.SessionId;
            string filename = @"~/XML/ERPModel_SS.XML";
            //string datafilename = @"~/XML/H_ER.xlsx";
            //string datafilename = @"~/XML/" + timestamp + ".xlsx";

            List <Forecast_data> RTNValue = null;

            //string RTNTag = "";


            RTNValue = new List <Forecast_data>();

            //Forecast_data current = null;
            int timestamp1 = Convert.ToInt32(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds);

            string path1 = System.Web.Hosting.HostingEnvironment.MapPath(filename);
            //string path2 = System.Web.Hosting.HostingEnvironment.MapPath(datafilename);

            //RTNTag = "'" + MyID + "'";
            //Excel.Workbook wb = null;
            //bool S8LoadFlag = false;
            //string filename = path1 + "TableTest1.XML";
            ERFSIMUL MySim = null;

            try
            {
                //string ans = run_cmd("E:/Project/OpenSrcData/data/createModelData.py", "1");
                //ScriptEngine engine = Python.CreateEngine();
                //xlApp = new Excel.Application();
                //engine.ExecuteFile("E:/Project/OpenSrcData/data/createModelData.py");
                //run_cmd("E:/Project/OpenSrcData/data/createModelData.py", "1");

                run_cmd("E:/Project/OpenSrcData/data/createModelDataSS.py", "-o " + xmlBase);

                //StreamWriter sw = new StreamWriter(
                //    System.Web.Hosting.HostingEnvironment.MapPath(@"~/XML/Result2.csv"));

                //RTNValue = "' >>"+ans+">> '";
                //sw.WriteLine("name,value,mean,sd-,sd+");
                /////////////////////////////////////////////////////
                //wb = xlApp.Workbooks.Open(path2);
                S8Machine.getSIMU8().Open(path1);
                //S8LoadFlag = true;
                MySim = new ERFSIMUL(S8Machine);
                MySim.Load(path1);
                //MySim.SetInputVariable(value);
                //sw.WriteLine(inputText[1]);
                List <S8Spreadsheet> NewSS = LoadSpreadsheet(MySim.InputVariables);
                MySim.SetTimesAnsLength(replicationnum, Double.Parse(time));
                MySim.SetSSInputVariable(NewSS);
                MySim.Run();
                RTNValue = MySim.GetHospitals(Double.Parse(time));
                MySim.Reset();
                //Forecast_data tmp = new Forecast_data();
                //tmp.Hospital_ID = "OK";
                //RTNValue.Add(tmp);
            }
            catch (Exception ex)
            {
                Forecast_data Err = new Forecast_data();
                Err.Hospital_ID = ex.ToString();

                RTNValue.Add(Err);
            }
            finally
            {
                //S8Machine.getSIMU8().Close();
                if (MySim != null)
                {
                    MySim.close();
                }
            }

            //RTNValue = ;

            //return RTNValue;
            return(RTNValue);
        }