public void TestSimulationProducerContract() { var app = ApplicationProducerContract.Get("AspenPlus"); Assert.IsNotNull(app); ISimulationProducerContract simulation_contract = AspenSimulationContract.Create("test", "AspenPlus"); Assert.IsNotNull(simulation_contract); byte[] data; using (var fstream = File.Open("mea.bkp", FileMode.Open)) { using (var ms = new MemoryStream()) { fstream.CopyTo(ms); data = ms.ToArray(); } } System.Threading.Thread.Sleep(10); simulation_contract.UpdateInput("aspenfile", data, "plain/text"); data = null; using (var fstream = File.Open("mea-sinter.txt", FileMode.Open)) { using (var ms = new MemoryStream()) { fstream.CopyTo(ms); data = ms.ToArray(); } } System.Threading.Thread.Sleep(10); simulation_contract.UpdateInput("configuration", data, "plain/text"); }
internal static ISimulationProducerContract CreateExcelSimulation(String spreadsheet, String sinter) { var app = ApplicationProducerContract.Get("Excel"); Assert.IsNotNull(app); ISimulationProducerContract simulation_contract = AspenSimulationContract.Create("test", "Excel"); Assert.IsNotNull(simulation_contract); byte[] data; using (var fstream = File.Open(spreadsheet, FileMode.Open)) { using (var ms = new MemoryStream()) { fstream.CopyTo(ms); data = ms.ToArray(); } } System.Threading.Thread.Sleep(10); simulation_contract.UpdateInput("spreadsheet", data, "plain/text"); data = null; using (var fstream = File.Open(sinter, FileMode.Open)) { using (var ms = new MemoryStream()) { fstream.CopyTo(ms); data = ms.ToArray(); } } System.Threading.Thread.Sleep(10); simulation_contract.UpdateInput("configuration", data, "plain/text"); return(simulation_contract); }
public void TestSimulationProducerConsumerContracts() { var simulation_name = "TestSimulationProducerConsumerContracts"; var input_name = "configuration"; ISimulationProducerContract contract = AspenSimulationContract.Create(simulation_name, "ACM"); using (var container = new Turbine.Data.TurbineModelContainer()) { var obj = container.Simulations.Single <Turbine.Data.Simulation>(s => s.Name == simulation_name); var input = obj.SimulationStagedInputs.Single <Turbine.Data.SimulationStagedInput>(i => i.Name == input_name); Assert.IsNull(input.Hash); Assert.IsNull(input.Content); Debug.WriteLine("SimulationStagedInput: " + input.Name, this.GetType().Name); input_name = "aclm"; input = obj.SimulationStagedInputs.Single <Turbine.Data.SimulationStagedInput>(i => i.Name == input_name); Assert.IsNull(input.Hash); Assert.IsNull(input.Content); Debug.WriteLine("SimulationStagedInput: " + input.Name, this.GetType().Name); } input_name = "configuration"; contract = AspenSimulationContract.Get(simulation_name); byte[] data = Encoding.UTF8.GetBytes("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); var provider = System.Security.Cryptography.MD5CryptoServiceProvider.Create(); byte[] hash = provider.ComputeHash(data); var sb = new StringBuilder(); foreach (byte b in hash) { sb.Append(b.ToString("X2")); } string hval = sb.ToString(); var content_type = "plain/text"; bool success = contract.UpdateInput(input_name, data, content_type); using (var container = new Turbine.Data.TurbineModelContainer()) { var obj = container.Simulations.OrderByDescending(q => q.Create).First <Turbine.Data.Simulation>(s => s.Name == simulation_name); var input = obj.SimulationStagedInputs.Single <Turbine.Data.SimulationStagedInput>(i => i.Name == input_name); Debug.WriteLine(String.Format("SimulationStagedInput: {0}, {1}, {2}", input.Name, input.Hash, Encoding.UTF8.GetString(input.Content)), this.GetType().Name); Assert.AreEqual(input.Hash, hval); Assert.AreEqual(Encoding.UTF8.GetString(input.Content), "ABCDEFGHIJKLMNOPQRSTUVWXYZ"); } }
public void TestWrongParameter() { var app = ApplicationProducerContract.Get("Excel"); Assert.IsNotNull(app); ISimulationProducerContract simulation_contract = AspenSimulationContract.Create("test", "Excel"); Assert.IsNotNull(simulation_contract); byte[] data; using (var fstream = File.Open("exceltest.xlsm", FileMode.Open)) { using (var ms = new MemoryStream()) { fstream.CopyTo(ms); data = ms.ToArray(); } } Assert.IsTrue(data.Length > 0); System.Threading.Thread.Sleep(10); simulation_contract.UpdateInput("wrongparameter", data, "plain/text"); }
public void TestSessionProducerConsumerContracts() { // producers ISessionProducerContract producer = new AspenSessionProducerContract(); Guid session_id = producer.Create(); Assert.IsNotNull(session_id); ISimulationProducerContract simulation_contract = AspenSimulationContract.Create("testX", "AspenPlus"); var bytes = File.ReadAllBytes("mea-sinter.txt"); Assert.IsNotNull(bytes); Assert.IsTrue(bytes.Length > 0); System.Threading.Thread.Sleep(100); simulation_contract.UpdateInput("configuration", bytes, "plain/text"); bytes = File.ReadAllBytes("mea.bkp"); Assert.IsNotNull(bytes); Assert.IsTrue(bytes.Length > 0); System.Threading.Thread.Sleep(100); simulation_contract.UpdateInput("aspenfile", bytes, "plain/text"); IJobProducerContract job_producer_contract = simulation_contract.NewJob(session_id, false, true); job_producer_contract = simulation_contract.NewJob(session_id, false, true); IConsumerRegistrationContract contract = Turbine.Consumer.AppUtility.GetConsumerRegistrationContract(); contract.Register(); IJobConsumerContract job = contract.Queue.GetNext(); Assert.IsNull(job); job_producer_contract.Submit(); job = contract.Queue.GetNext(); Assert.IsNotNull(job); Assert.AreEqual(job.Id, job_producer_contract.Id); job.Setup(); SimpleFile backup = null; SimpleFile config = null; foreach (var f in job.GetSimulationInputFiles()) { if (f.name == "configuration") { config = f; } else { backup = f; } } Assert.AreEqual(config.name, "configuration"); String filename = SinterHelperFunctions .getBackupFilename(System.Text.Encoding.ASCII.GetString(config.content)); Assert.AreEqual(backup.name, "aspenfile"); // NEED TO SET INPUT Before Setting to Run //j try { job.Running(); Assert.Fail("Job.Process.Input Must be set before setting job to run"); } catch (InvalidStateChangeException) {} job.Process.Input = new Dictionary <string, Object>(); job.Running(); job.Success(); job = contract.Queue.GetNext(); Assert.IsNull(job); }
public void TestExcelSpreadsheet1() { var app = ApplicationProducerContract.Get("Excel"); Assert.IsNotNull(app); ISimulationProducerContract simulation_contract = AspenSimulationContract.Create("test", "Excel"); Assert.IsNotNull(simulation_contract); byte[] data; using (var fstream = File.Open(@"exceltest.xlsm", FileMode.Open)) { using (var ms = new MemoryStream()) { fstream.CopyTo(ms); data = ms.ToArray(); } } Assert.IsTrue(data.Length > 0); System.Threading.Thread.Sleep(10); simulation_contract.UpdateInput("spreadsheet", data, "plain/text"); data = null; using (var fstream = File.Open("exceltest-sinter.json", FileMode.Open)) { using (var ms = new MemoryStream()) { fstream.CopyTo(ms); data = ms.ToArray(); } } Assert.IsTrue(data.Length > 0); System.Threading.Thread.Sleep(10); simulation_contract.UpdateInput("configuration", data, "plain/text"); System.Threading.Thread.Sleep(10); var guid = Guid.NewGuid(); var job_producer_contract = simulation_contract.NewJob(guid, false, false); job_producer_contract.Process.Input = new Dictionary <string, Object>() { }; job_producer_contract.Submit(); System.Threading.Thread.Sleep(10); IConsumerRegistrationContract contract = Turbine.Consumer.AppUtility.GetConsumerRegistrationContract(); Assert.IsNull(contract.Queue); contract.Register(); Turbine.Consumer.Contract.SinterConsumer consumer = new Turbine.Consumer.Excel.ExcelSinterConsumer(); //Utility.CheckBaseDirectory(); consumer.Run(); int jobID = job_producer_contract.Id; Debug.WriteLine("Job GUID" + guid.ToString(), GetType().Name); Dictionary <string, Object> json = null; using (Turbine.Data.TurbineModelContainer container = new Turbine.Data.TurbineModelContainer()) { Turbine.Data.Job entity = container.Jobs.Single(s => s.Id == job_producer_contract.Id); json = Newtonsoft.Json.JsonConvert.DeserializeObject <Dictionary <string, Object> >(entity.Process.Output); } string output = Newtonsoft.Json.JsonConvert.SerializeObject(json); Debug.WriteLine("OUTPUT: " + output, GetType().Name); }