/// <summary> /// insert this into the db /// </summary> /// <returns>the object with ID and other db fields set</returns> public override IData Create() { var parms = new Dictionary <string, object>(); DimensionalModelData returnValue = default(DimensionalModelData); var sql = new StringBuilder(); sql.Append("insert into [dbo].[DimensionalModelData]([Name], [Model], [ModelType])"); sql.Append(" values(@Name,@Model,@ModelType)"); sql.Append(" select * from [dbo].[DimensionalModelData] where ID = Scope_Identity()"); parms.Add("Name", Name); parms.Add("Model", SerializeModel()); parms.Add("ModelType", (short)ModelType); try { var ds = SqlWrapper.RunDataset(sql.ToString(), CommandType.Text, parms); if (ds.Rows != null) { foreach (DataRow dr in ds.Rows) { Fill(dr); returnValue = this; } } } catch (Exception ex) { LoggingUtility.LogError(ex); } return(returnValue); }
public DimensionalModel(int length, int height, int width, string modelJson, long backingDataId, string compJson) { Length = length; Height = height; Width = width; Composition = DeserializeMaterialCompositions(compJson); ModelBackingData = new DimensionalModelData(backingDataId, modelJson); }
//for 0 dimension models public DimensionalModel(int length, int height, int width) { Length = length; Height = height; Width = width; Composition = new Dictionary <string, IMaterial>(); ModelBackingData = new DimensionalModelData(); ModelBackingData.ModelType = DimensionalModelType.None; }
public DimensionalModel(global::System.Data.DataRow dr) { Length = DataUtility.GetFromDataRow <int>(dr, "DimensionalModelLength"); Height = DataUtility.GetFromDataRow <int>(dr, "DimensionalModelHeight"); Width = DataUtility.GetFromDataRow <int>(dr, "DimensionalModelWidth"); long outDimModId = DataUtility.GetFromDataRow <long>(dr, "DimensionalModelID"); if (outDimModId > 0) { ModelBackingData = ReferenceWrapper.GetOne <DimensionalModelData>(outDimModId); string materialComps = DataUtility.GetFromDataRow <string>(dr, "DimensionalModelMaterialCompositions"); Composition = DeserializeMaterialCompositions(materialComps); } else //0 dimensional models don't have an actual model { ModelBackingData = new DimensionalModelData(); ModelBackingData.ModelType = DimensionalModelType.None; Composition = new Dictionary <string, IMaterial>(); } }
public ActionResult AddDimensionalModelData(AddEditDimensionalModelDataViewModel vModel, HttpPostedFileBase modelFile) { string message = string.Empty; var authedUser = UserManager.FindById(User.Identity.GetUserId()); try { if (modelFile.ContentLength == 0) message = "You must post a comma delimited file with the model in it."; byte[] bytes = new byte[modelFile.InputStream.Length]; modelFile.InputStream.Read(bytes, 0, (int)modelFile.InputStream.Length); var fileContents = Encoding.UTF8.GetString(bytes); var newObj = new DimensionalModelData(fileContents); newObj.Name = vModel.NewName; newObj.ModelType = vModel.NewModelType; if (newObj.IsModelValid()) { if (newObj.Create() == null) message = "Error; Creation failed."; else { LoggingUtility.LogAdminCommandUsage("*WEB* - AddDimensionalModelData[" + newObj.ID.ToString() + "]", authedUser.GameAccount.GlobalIdentityHandle); message = "Creation Successful."; } } else message = "Invalid model file; Model files must contain 11 planes of a tag name followed by 11 rows of 11 nodes."; } catch (Exception ex) { LoggingUtility.LogError(ex); message = "Error; Creation failed."; } return RedirectToAction("ManageDimensionalModelData", new { Message = message }); }