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);
        }
        string[] getBasedonCSV(Stream data)
        {
            /*
             * resultStringArray[0] = RTNstatus;
             * resultStringArray[1] = RTNTag;
             * resultStringArray[2] = RTNValue;
             */
            string[] resultStringArray = new string[3];


            //new Excel.Application();
            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_SS.XML";
            //string datafilename = @"~/XML/H_ER.xlsx";
            //string datafilename = @"~/XML/" + 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);

            try
            {
                if (inputText[0] == "A")
                {
                    //S8Machine = new Simul8Runner();
                    ERFSIMUL MySim = null;
                    string   info  = run_cmd("E:/Project/OpenSrcData/data/createModelDataSS.py", "");

                    S8Machine.getSIMU8().Open(path1);
                    S8LoadFlag = true;
                    MySim      = new ERFSIMUL(S8Machine);
                    MySim.Load(path1);

                    List <S8Spreadsheet> NewSS = LoadSpreadsheet(MySim.InputVariables);
                    MySim.SetTimesAnsLength(int.Parse(inputText[1]), Double.Parse(inputText[2]));
                    MySim.SetSSInputVariable(NewSS);
                    MySim.Run();
                    //RTNValue = MySim.GetResults();
                    resultStringArray[2] = MySim.GetJSON(Double.Parse(inputText[2]));

                    resultStringArray[0] = "VALUE";
                }
            }
            catch (Exception ex)
            {
                resultStringArray[0] = "ERROR";
                resultStringArray[2] = "'" + ex.ToString() + "'";
                //RTNValue = "'" + RTNValue + "'";
            }
            finally
            {
                //if (S8LoadFlag != false)
                //{
                S8Machine.getSIMU8().Close();
                //S8Machine.getSIMU8().Quit();


                //}

                //if (S8Machine!=null)
                //    S8Machine.CloseSimul8COMServer();


                GC.Collect();
            }
            return(resultStringArray);
        }