/// <summary> /// POST: Creates a new simulation /// </summary> /// <param name="appname">Application name</param> /// <returns>URI of New simulation</returns> public string CreateSimulation(string appname) { string name = WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters["simulation"]; if (string.IsNullOrEmpty(name)) { var detail = new ErrorDetail( ErrorDetail.Codes.QUERYPARAM_ERROR, "Required parameter \"simulation\": Provide unique name for factory method." ); throw new WebFaultException <ErrorDetail>(detail, System.Net.HttpStatusCode.BadRequest); } ISimulationProducerContract contract = null; try { contract = ProducerSimulationContract.Create(name, name, appname); } catch (Exception ex) { string msg = String.Format("Failed to Create Simulation {0}: {1} {2}", name, ex.Message, ex.StackTrace.ToString()); Debug.WriteLine(msg, this.GetType().Name); var detail = new ErrorDetail( ErrorDetail.Codes.DATAFORMAT_ERROR, msg ); throw new WebFaultException <ErrorDetail>(detail, System.Net.HttpStatusCode.InternalServerError); } var uri = WebOperationContext.Current.IncomingRequest.UriTemplateMatch.RequestUri; return(new Uri(uri, String.Format("../simulation/{0}", name)).ToString()); }
/// <summary> /// PUT: Update Simulation /// </summary> /// <param name="name">Simulation name</param> /// <param name="sim">Simulation Resource Representation</param> /// <returns>Updated Simulation</returns> public Simulation UpdateSimulation(string nameOrID, Simulation sim) { Guid simulationId = Guid.Empty; bool isGuid = Guid.TryParse(nameOrID, out simulationId); ISimulationProducerContract contract = null; if (sim == null || sim.Name == null) { Debug.WriteLine(String.Format("Sim Name: {0}, ID: {1}, app: {2}", sim.Name, sim.Id.ToString(), sim.Application) , this.GetType().Name); string msg = String.Format("No Application specified in Simulation {0}", nameOrID); Debug.WriteLine(msg, this.GetType().Name); var detail = new ErrorDetail( ErrorDetail.Codes.DATAFORMAT_ERROR, msg ); throw new WebFaultException <ErrorDetail>(detail, System.Net.HttpStatusCode.InternalServerError); } if (!isGuid && !nameOrID.Equals(sim.Name)) { string msg = String.Format("No URL Resource Name {0} doesn't match Simulation.Name {1}", nameOrID, sim.Name); Debug.WriteLine(msg, this.GetType().Name); var detail = new ErrorDetail( ErrorDetail.Codes.DATAFORMAT_ERROR, msg ); throw new WebFaultException <ErrorDetail>(detail, System.Net.HttpStatusCode.InternalServerError); } string appname = sim.Application; try { contract = ProducerSimulationContract.Create(nameOrID, sim.Name, appname); } catch (Exception ex) { string msg = String.Format("Failed to Create Simulation {0}: {1} {2}", nameOrID, ex.Message, ex.StackTrace.ToString()); if (ex.InnerException != null) { msg += String.Format(" InnerException: {0} {1}", ex.InnerException.Message, ex.InnerException.StackTrace.ToString()); } Debug.WriteLine(msg, this.GetType().Name); var detail = new ErrorDetail( ErrorDetail.Codes.DATAFORMAT_ERROR, msg ); throw new WebFaultException <ErrorDetail>(detail, System.Net.HttpStatusCode.InternalServerError); } sim = DataMarshal.GetSimulation(nameOrID, isGuid); return(sim); }