コード例 #1
0
ファイル: AbstractSimulation.cs プロジェクト: matrix4x4/Space
        /// <summary>Creates a deep copy of the object, reusing the given object.</summary>
        /// <param name="into">The object to copy into.</param>
        /// <returns>The copy.</returns>
        public virtual void CopyInto(ISimulation into)
        {
            Debug.Assert(into.GetType().TypeHandle.Equals(GetType().TypeHandle));
            Debug.Assert(into != this);

            var copy = (AbstractSimulation)into;

            copy.CurrentFrame = CurrentFrame;
            Manager.CopyInto(copy.Manager);
            copy.Commands.Clear();
            copy.Commands.AddRange(Commands);
        }
コード例 #2
0
        private void doSimulation(String sinterconf, String defaultsfile,
                                  String infilename, String outfilename, String canonicalOutputFilename)
        {
            String workingDir = Path.GetDirectoryName(sinterconf);

            StreamReader defaultsStream = null;

            if (defaultsfile != null)
            {
                defaultsStream = new StreamReader(defaultsfile);
            }
            StreamReader inStream       = new StreamReader(infilename);
            StreamWriter outStream      = new StreamWriter(outfilename);
            StreamReader canonOutStream = new StreamReader(canonicalOutputFilename);

            //this function returns 0 if no error
            //another integer for errors
            StreamReader inFileStream = new StreamReader(sinterconf);
            string       setupString  = "";

            setupString = inFileStream.ReadToEnd();
            inFileStream.Close();

            //ISimulation stest = sinter_Factory.createSinter(setupString); //Need to change this to setup file contents string

            ISimulation stest = sinter_Factory.createSinter(setupString);

            //sinter_SetupFile thisSetupFile = sinter_SetupFile.determineFileTypeAndParse(setupString);
            //ISimulation stest = new sinter_SimExcel();
            //stest.setupFile.parseFile(setupString);
            //((sinter_Sim)stest).makeIOTree();

            Debug.WriteLine("SINTER: " + stest.GetType().Name, GetType().Name);
            stest.workingDir = workingDir;
            //stest.readSetup(sinterconf); //Read the setup file also opens sim
            stest.openSim(); //connect to aspen
            stest.Vis = false;
            Console.WriteLine(stest.Vis);
            //      stest.Layout();  //figure out spreadsheet layout
            stest.dialogSuppress = true;
            stest.resetSim();

            //The console version reads in json, the actual version just pulls the dictionary from the database
            string  injson       = "";
            string  defaultsjson = "";
            string  canonOutJson = "";
            JObject inputDict    = null;
            JObject defaultsDict = null;
            JObject canonOutDict = null;

            try
            {
                injson       = inStream.ReadToEnd();
                inputDict    = JObject.Parse(injson);       // JsonConvert.DeserializeObject<Dictionary<String, Object>>(injson);
                canonOutJson = canonOutStream.ReadToEnd();
                canonOutDict = JObject.Parse(canonOutJson); // JsonConvert.DeserializeObject<Dictionary<String, Object>>(injson);

                if (defaultsStream != null)
                {
                    defaultsjson = defaultsStream.ReadToEnd();
                    defaultsDict = JObject.Parse(defaultsjson); // Convert.DeserializeObject<Dictionary<String, Object>>(defaultsjson);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception reading input file! " + ex.Message);
            }
            finally
            {
                inStream.Close();
            }


            if (defaultsDict != null)
            {
                stest.sendDefaults(defaultsDict);
            }
            stest.sendInputs(inputDict);
            stest.sendInputsToSim();
            stest.runSim();
            stest.recvOutputsFromSim();
            sinter.sinter_AppError runStatus = stest.runStatus;
            Console.WriteLine("RunStatus: {0}", (int)runStatus);

            Console.WriteLine("Errors:");
            string[] errorList = stest.errorsBasic();
            foreach (string error in errorList)
            {
                Console.Write(error);
            }

            Console.WriteLine();

            Console.WriteLine("Warnings:");
            string[] warnList = stest.warningsBasic();
            foreach (string error in warnList)
            {
                Console.Write(error);
            }

            Console.WriteLine();


            JObject outputDict = stest.getOutputs();

            Debug.WriteLine("Output: " + outputDict, GetType().Name);

            JsonSerializerSettings jss = new JsonSerializerSettings();

            jss.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
            string jsonOutput = JsonConvert.SerializeObject(outputDict, Formatting.Indented, jss);

            outStream.WriteLine(jsonOutput);

            stest.closeSim();

            outStream.Close();

            JObject outTok    = (JObject)outputDict["outputs"];
            JObject canOutTok = (JObject)canonOutDict["outputs"];

            Assert.IsTrue(outputsEqual(outTok, canOutTok));

//            Assert.IsTrue(outputDict.Equals(canonOutDict));
        }