public CollectionModel GetGridFormDataSource([FromUri] string dataObjectUID, [FromUri] string activityUID) { try { var dataObject = StepDataObject.Parse(dataObjectUID); var activity = ProjectItem.Parse(activityUID); FixedList <Posting> list = PostingList.GetPostings(dataObject.DataItem, activity, dataObject.DataItem.DataType); var data = list.Select(x => { var json = x.ExtensionData.ToDictionary(); json.Add("uid", x.UID); if (dataObject.DataItem.Terms == "Actividades.CNH.CustomGrid") { json = Reporting.SubtaskCNH.LoadFields(dataObject, json, activity); } return(json); }); return(new CollectionModel(this.Request, data.ToArray())); } catch (Exception e) { throw base.CreateHttpException(e); } }
public static StepFile simpleStepRepresentation() { StepDataObject entity0 = new StepDataObject("IFCPROJECT", StepValue.CreateString("3MD_HkJ6X2EwpfIbCFm0g_"), StepValue.CreateLineReference(2), StepValue.CreateString("Default Project"), StepValue.CreateString("Description of Default Project"), StepValue.CreateNull(), StepValue.CreateFloat(-22.4), StepValue.CreateNull(), StepValue.CreateArray( StepValue.CreateLineReference(20) ), StepValue.CreateLineReference(7) ); StepDataObject entity1 = new StepDataObject("IFCOWNERHISTORY", StepValue.CreateLineReference(3), StepValue.CreateNestedEntity(new StepDataObject("IFCTEXT", StepValue.CreateString("foobar"))), StepValue.CreateNull(), StepValue.CreateEnum("ADDED"), StepValue.CreateNull(), StepValue.CreateBoolean(false), StepValue.CreateOverridden(), StepValue.CreateInteger(1217620436) ); StepFile sf = new StepFile(); appendHeaderToStepFile(sf, createHeader()); sf.Data.Add(1, entity0); sf.Data.Add(2, entity1); return(sf); }
/// <summary> /// binds the data from the FILE_NAME object of the STEP HEADER section /// </summary> /// <param name="sdo"></param> /// <param name="header"></param> private void bindFileName(StepDataObject sdo, iso_10303_28_header header) { if (sdo == null) { throw new ArgumentNullException("sdo"); } if (header == null) { throw new ArgumentNullException("header"); } if (sdo.ObjectName != "FILE_NAME") { throw new ArgumentException(String.Format(CultureInfo.InvariantCulture, "bindFileName(StepDataObject, iso_10303_28_header) should only be called for StepDataObject FILE_NAME, and not {0}", sdo.ObjectName)); } if (sdo.Properties == null || sdo.Properties.Count != 7) { throw new ArgumentException("sdo does not have the correct number of properties"); } header.name = (string)sdo.Properties[0].Value; header.time_stamp = (DateTime)sdo.Properties[1].Value; header.author = (string)((IList <StepValue>)sdo.Properties[2].Value)[0].Value; //FIXME only copies first value in the array as header.author is a string, and not a list header.organization = (string)((IList <StepValue>)sdo.Properties[3].Value)[0].Value; //FIXME only copies first value in the array as header.author is a string, and not a list header.preprocessor_version = (string)sdo.Properties[4].Value; header.originating_system = (string)sdo.Properties[5].Value; header.authorization = (string)sdo.Properties[6].Value; }
public void AssertObject(string expectedName, int expectedPropertiesCount, StepDataObject actual) { Assert.IsNotNull(actual); Assert.AreEqual(expectedName, actual.ObjectName); Assert.IsNotNull(actual.Properties); Assert.AreEqual(expectedPropertiesCount, actual.Properties.Count); }
private StepDataObject ExtractFileName(iso_10303 iso10303) { if (iso10303 == null) { throw new ArgumentNullException("iso10303"); } iso_10303_28_header header = iso10303.iso_10303_28_header; if (header == null) { throw new ArgumentNullException("iso10303.iso_10303_28_header"); } StepDataObject sdo = new StepDataObject(); sdo.ObjectName = "FILE_NAME"; sdo.Properties.Add(StepValue.CreateString(header.name)); sdo.Properties.Add(StepValue.CreateDate(header.time_stamp)); sdo.Properties.Add(StepValue.CreateArray(StepValue.CreateString(header.author))); //FIXME header.organization is a string and not a list, but the Step file expects an array sdo.Properties.Add(StepValue.CreateArray(StepValue.CreateString(header.organization))); sdo.Properties.Add(StepValue.CreateString(header.preprocessor_version)); sdo.Properties.Add(StepValue.CreateString(header.originating_system)); sdo.Properties.Add(StepValue.CreateString(header.authorization)); return(sdo); }
public SingleObjectModel AddStepRequirement([FromUri] string stepUID, [FromBody] object body) { try { var step = ProjectItem.Parse(stepUID); var requirement = base.GetJsonFromBody(body); StepDataObject dataObject; if (!requirement.HasValue("uid")) { dataObject = new StepDataObject(step, requirement); } else { dataObject = StepDataObject.Parse(requirement.Get <string>("uid")); dataObject.Update(requirement); } dataObject.Save(); return(new SingleObjectModel(this.Request, dataObject.ToResponse(), typeof(StepDataObject).FullName)); } catch (Exception e) { throw base.CreateHttpException(e); } }
internal static void WriteStepDataObject(StepDataObject o) { var op = DataOperation.Parse("writeSTPStepDataObject", o.Id, o.UID, o.DataItem.Id, o.Step.Id, o.Activity.Id, o.MediaFile.Id, o.FormId, o.FormData.ToString(), o.Configuration.ToString(), o.ExtensionData.ToString(), (char)o.Status); DataWriter.Execute(op); }
public void CanParseObjectNamesBeginningWithE() { StepReader sr = createStepReader(ExampleData.ObjectNameBeginningWithE()); StepFile result = SUT.Deserialize(sr); List <StepDataObject> values = new List <StepDataObject>(result.Data.Values); StepDataObject entity0 = values[0]; Assert.AreEqual("EXAMPLE", entity0.ObjectName); }
/// <summary> /// Extracts StepDataObjects from a .Net object /// </summary> /// <param name="iso10303"></param> /// <returns></returns> public StepFile Extract(iso_10303 iso10303) { if (iso10303 == null) { throw new ArgumentNullException("iso10303"); } if (iso10303.iso_10303_28_header == null) { throw new ArgumentNullException("iso10303.iso_10303_28_header"); } if (iso10303.uos == null) { throw new ArgumentNullException("iso10303.uos"); } StepFile stepFile = new StepFile(); //header stepFile.Header.Add(GenerateFileDescription( )); stepFile.Header.Add(ExtractFileName(iso10303)); stepFile.Header.Add(ExtractFileSchema(iso10303)); //data uos1 uos1 = iso10303.uos as uos1; if (uos1 == null) //no data { logger.Error("Extract(iso_10303) could not extract, as iso10303.uos was not a type of uos1"); return(stepFile); } //putting the entities in a dictionary so we can deal with references foreach (Entity e in uos1.Items) { if (!this._entityRegister.isAlreadyRegistered(e)) { this._entityRegister.RegisterEntity(e); this._queuedEntities.Enqueue(e); } } while (this._queuedEntities.Count > 0) { Entity e = this._queuedEntities.Dequeue(); int entityId = this._entityRegister.getEntityId(e); StepDataObject sdo = this.ExtractObject(e); stepFile.Data.Add(entityId, sdo); } //clear entityQueue, so next time this method is run it starts empty this._entityRegister = new StepBinderEntityRegister(); return(stepFile); }
public NoDataModel RemoveStepRequirement([FromUri] string requirementUID) { try { var dataObject = StepDataObject.Parse(requirementUID); dataObject.Delete(); return(new NoDataModel(this.Request)); } catch (Exception e) { throw base.CreateHttpException(e); } }
public void CanCorrectlyDeserializeAmbiguousNumber() { StepReader sr = createStepReader(ExampleData.AmbiguousNumberString()); StepFile result = SUT.Deserialize(sr); List <StepDataObject> values = new List <StepDataObject>(result.Data.Values); StepDataObject entity0 = values[0]; Assert.IsNotNull(entity0); Assert.IsNotNull(entity0.Properties); Assert.AreEqual(1, entity0.Properties.Count); AssertFloat(1E-5, entity0.Properties[0]); }
public static IDictionary <string, object> LoadFields(StepDataObject dataObject, IDictionary <string, object> json, ProjectItem activity) { var subtask = SubtaskCNH.Parse(Convert.ToInt32(json["subtarea"])); json.Add("subtaskCode", subtask.SubtaskCode); json.Add("subtaskName", subtask.SubtaskName); json.Add("subactivityName", subtask.SubactivityName); return(json); }
static internal object ToResponse(this StepDataObject dataObject) { return(new { uid = dataObject.UID, type = dataObject.DataItem.NamedKey, name = dataObject.Name, description = dataObject.Description, dataObject = dataObject.DataItem.ToResponse(), optional = dataObject.Optional, legalBasis = dataObject.LegalBasis, }); }
public void AssertNestedObject(string expectedName, int expectedNumberOfProperties, StepValue actual) { Assert.IsNotNull(actual); Assert.IsNotNull(actual.Value); Assert.AreEqual(StepToken.StartEntity, actual.Token); Assert.AreEqual(typeof(StepDataObject), actual.ValueType); StepDataObject sdo = actual.Value as StepDataObject; Assert.IsNotNull(sdo); AssertObject(expectedName, expectedNumberOfProperties, sdo); }
private StepDataObject ExtractFileSchema(iso_10303 iso10303) { if (iso10303 == null) { throw new ArgumentNullException("iso10303"); } StepDataObject sdo = new StepDataObject(); sdo.ObjectName = "FILE_SCHEMA"; sdo.Properties.Add(StepValue.CreateArray(StepValue.CreateString("IFC2X3"))); return(sdo); }
public CollectionModel GetStepRequirementsList([FromUri] string stepUID) { try { var step = ProjectItem.Parse(stepUID); FixedList <StepDataObject> dataObjects = StepDataObject.GetListFor(step); return(new CollectionModel(this.Request, dataObjects.ToResponse(), typeof(StepDataObject).FullName)); } catch (Exception e) { throw base.CreateHttpException(e); } }
public CollectionModel GetActivityDataObjects([FromUri] string activityUID) { try { var activity = ProjectItem.Parse(activityUID); FixedList <StepDataObject> dataObjects = StepDataObject.GetListForAction(activity); return(new CollectionModel(this.Request, dataObjects.ToResponse(activity), typeof(StepDataObject).FullName)); } catch (Exception e) { throw base.CreateHttpException(e); } }
private void SerializeEntity(IStepWriter writer, int entityId, StepDataObject sdo) { if (writer == null) { throw new ArgumentNullException("writer"); } if (sdo == null) { throw new ArgumentNullException("sdo"); } writer.WriteLineIdentifier(entityId); SerializeObject(writer, sdo); }
/// <summary> /// Populates a .Net instance's properties with the data given in the Step Data Object /// </summary> /// <param name="obj">The empty .Net instance which will be populated</param> /// <param name="sdoId">The unique Id of the StepDataObject</param> /// <param name="sdo">The Step Data Object with data to inject into the .Net object</param> /// <param name="typeProperties">The type properties applicable to the .Net instance</param> private void populateObject(ref Object obj, int sdoId, StepDataObject sdo, IList <PropertyInfo> typeProperties) { if (obj == null) { throw new ArgumentNullException("obj"); } if (typeProperties == null || typeProperties.Count < 1) { throw new ArgumentNullException("typeProperties"); } if (sdo == null) { throw new ArgumentNullException("sdo"); } if (sdo.Properties == null) { throw new ArgumentException("sdo.Properties is null"); } if (sdo.Properties.Count != typeProperties.Count) { throw new StepBindingException(String.Format(CultureInfo.InvariantCulture, "The number of data values, {0}, provided by the STEP data object, {1}, does not equal the number of properties, {2}, available in the .Net object, {3}", sdo.Properties.Count, sdo.ObjectName, typeProperties.Count, obj.GetType().FullName)); } for (int propertyIndex = 0; propertyIndex < sdo.Properties.Count; propertyIndex++) { StepValue sv = sdo.Properties[propertyIndex]; PropertyInfo pi = typeProperties[propertyIndex]; if (pi == null) { throw new StepBindingException(String.Format(CultureInfo.InvariantCulture, "A null property was found at index {0} of the cached properties provided for type {1}", propertyIndex, obj.GetType().Name)); } populateProperty(pi, ref obj, sv, sdoId); } }
public SingleObjectModel RemoveUploadedFile([FromUri] string dataObjectUID, [FromUri] string activityUID) { try { var dataObject = StepDataObject.Parse(dataObjectUID); var activity = ProjectItem.Parse(activityUID); var autofill = new Autofill(dataObject, activity); autofill.RemoveFile(); return(new SingleObjectModel(this.Request, autofill.ToResponse(), typeof(StepDataObject).FullName)); } catch (Exception e) { throw base.CreateHttpException(e); } }
/// <summary> /// Converts a StepDataObject to a .Net object, entering the data into its properties /// or, for references, adding an entry /// </summary> /// <param name="sdoId">The unique Id of the Step Data Object being converted</param> /// <param name="sdo">The Step Data Object which is to be converted to a .Net object.</param> /// <returns></returns> private Object bindObject(int sdoId, StepDataObject sdo) { if (sdo == null) { throw new ArgumentNullException("sdo"); } string name = sdo.ObjectName; Object instance = createObject(sdo.ObjectName); IList <PropertyInfo> typeProperties; //get the properties from the cache try{ typeProperties = _cache.getPropertiesOfEntity(instance.GetType()); }catch (KeyNotFoundException knfe) { string msg = String.Format(CultureInfo.InvariantCulture, "Could not find the key {0} in our entityProperties cache", instance.GetType().FullName); logger.Error(msg); //return instance; //FIXME should we throw an exception instead?? throw new StepBindingException(msg, knfe); } //debugging logger.Debug("Property Names : "); foreach (PropertyInfo pi in typeProperties) { logger.Debug(String.Format("\t{0}", pi.Name)); } if (typeProperties.Count != sdo.Properties.Count) { throw new StepBindingException(String.Format(CultureInfo.InvariantCulture, "The number of properties ( {0} ) in the Step entity, {1}, do not equal the number of properties ({2}) in the object, {3}", sdo.Properties.Count, sdo.ObjectName, typeProperties.Count, instance.GetType().FullName)); } populateObject(ref instance, sdoId, sdo, typeProperties); return(instance); }
public SingleObjectModel SetDataFormFields([FromUri] string dataObjectUID, [FromUri] string activityUID, [FromBody] object body) { try { var dataObject = StepDataObject.Parse(dataObjectUID); var json = JsonObject.Parse(body); var eventType = json.Get <string>("type"); var formData = JsonObject.Parse(json.Get <string>("payload/formData")); var activity = ProjectItem.Parse(activityUID); Posting posting; if (eventType == "created") { posting = new Posting(dataObject.DataItem.DataType, dataObject.DataItem, activity); posting.ExtensionData = formData; posting.Save(); } else if (eventType == "updated") { posting = Posting.Parse(json.Get <string>("payload/uid")); posting.ExtensionData = formData; posting.Save(); } else if (eventType == "deleted") { posting = Posting.Parse(json.Get <string>("payload/uid")); posting.Delete(); } else { throw Assertion.EnsureNoReachThisCode($"Unrecognized event {eventType}."); } return(new SingleObjectModel(this.Request, dataObject.ToResponse(activity), typeof(StepDataObject).FullName)); } catch (Exception e) { throw base.CreateHttpException(e); } }
internal StepDataObject ExtractObject(Object obj) { if (obj == null) { throw new ArgumentNullException("entity"); } Type objType = obj.GetType(); StepDataObject sdo = new StepDataObject(); sdo.ObjectName = GetObjectName(objType); IList <PropertyInfo> objProps = this._cache.getPropertiesOfEntity(objType); foreach (PropertyInfo pi in objProps) { sdo.Properties.Add(ExtractProperty(obj, pi)); } return(sdo); }
/// <summary> /// Maps a STEP entity to a .Net object /// </summary> /// <param name="pi"></param> /// <param name="obj"></param> /// <param name="sv"></param> private void mapObject(PropertyInfo pi, ref Object obj, StepValue sv) { if (pi == null) { throw new ArgumentNullException("pi"); } if (obj == null) { throw new ArgumentNullException("obj"); } if (sv.Value == null) { throw new ArgumentNullException("sv.Value"); } StepDataObject sdo = sv.Value as StepDataObject; if (sdo == null) { throw new ArgumentException("sv.Value is not of type StepDataObject"); } Object nestedObj = bindObject(-1, sdo); //as a quirk of the automatically generated schema //nested properties are wrapped in an intermediate class. Object wrappingObj = Activator.CreateInstance(pi.PropertyType); logger.Debug("Attempting to find \"Item\" property for type of " + pi.PropertyType); PropertyInfo wrappingProp = pi.PropertyType.GetProperty("Item", BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance); if (wrappingProp == null) { throw new StepBindingException("Could not find a suitable property in the wrapping class around a nested object"); } wrappingProp.SetValue(wrappingObj, nestedObj, null); //now insert the wrapping object pi.SetValue(obj, wrappingObj, null); }
private void SerializeObject(IStepWriter writer, StepDataObject sdo) { if (writer == null) { throw new ArgumentNullException("writer"); } if (sdo == null) { throw new ArgumentNullException("sdo"); } if (String.IsNullOrEmpty(sdo.ObjectName)) { throw new ArgumentNullException("sdo.ObjectName"); } writer.WriteObjectName(sdo.ObjectName); writer.WriteStartObject(); foreach (StepValue sv in sdo.Properties) { SerializeProperty(writer, sv); } writer.WriteEndObject(); }
// static internal object ToResponse(this DataStore dataStore) { // return new { // uid = dataStore.UID, // type = dataStore.NamedKey, // family = dataStore.Family, // name = dataStore.Name, // description = dataStore.Description, // templateUrl = dataStore.Template.Replace("~", libraryBaseAddress) // }; //} static internal object ToResponse(this StepDataObject dataObject, ProjectItem activity) { return(new { uid = dataObject.UID, type = dataObject.DataItem.NamedKey, entity = dataObject.Step.ToIdentifiableResponse(x => x.Name), subject = activity.ToIdentifiableResponse(x => x.Name), action = dataObject.Action, family = dataObject.DataItem.Family, name = dataObject.Name, description = dataObject.Description, isOptional = dataObject.Optional == "Mandatory", mediaFormat = dataObject.MediaFormat, autofillFileUrl = String.Empty, uploadedFileUrl = String.Empty, templateUrl = dataObject.DataItem.Template.Replace("~", libraryBaseAddress), decorator = dataObject.DataItem.Terms, status = dataObject.Status, dataObject = dataObject.DataItem.ToResponse(), optional = dataObject.Optional, legalBasis = dataObject.LegalBasis, }); }
public SingleObjectModel GetDataFormFields([FromUri] string dataObjectUID) { try { var dataObject = StepDataObject.Parse(dataObjectUID); var fields = dataObject.DataItem.GetFormFields(); var values = dataObject.GetFormFields(); foreach (DataFormField field in fields) { if (values.ContainsKey(field.Key)) { field.Value = Convert.ToString(values[field.Key]); } } return(new SingleObjectModel(this.Request, fields, typeof(DataFormField).FullName)); } catch (Exception e) { throw base.CreateHttpException(e); } }
static internal FixedList <JsonObject> GetSasisopaTasksList(StepDataObject dataObject) { return(GetJsonsFromPostings("Sasisopa.Task")); }
private static Autofill ConvertToAutofill(StepDataObject dataObject, ProjectItem activity) { return(new Autofill(dataObject, activity)); }
/// <summary> /// Attempts to read a nested entity /// </summary> /// <param name="reader"></param> /// <returns></returns> private StepDataObject deserializeEntity(IStepReader reader) { if (reader == null) { throw new ArgumentNullException("reader"); } StepDataObject edo = new StepDataObject(); bool entityStarted = false; //nested entities are already on the EntityName token if (reader.TokenType == StepToken.EntityName) { edo.ObjectName = getObjectName(reader); } while (reader.Read()) { logger.Debug(String.Format(CultureInfo.InvariantCulture, "deserializer read token {0}. value {1}", reader.TokenType, reader.Value)); switch (reader.TokenType) { case StepToken.EntityName: if (!entityStarted) { edo.ObjectName = getObjectName(reader); } else //it's a nested entity { edo.Properties.Add(deserializeNestedEntity(reader)); } continue; case StepToken.LineReference: edo.Properties.Add(deserializeLineReference(reader)); continue; case StepToken.Enumeration: case StepToken.Boolean: case StepToken.Integer: case StepToken.Float: case StepToken.String: case StepToken.Date: edo.Properties.Add(deserializeProperty(reader)); continue; case StepToken.StartArray: edo.Properties.Add(deserializeArray(reader)); continue; case StepToken.StartEntity: if (!entityStarted) { entityStarted = true; } else { throw new StepSerializerException(String.Format(CultureInfo.InvariantCulture, "A token was found which was not expected: {0}", reader.TokenType)); } continue; case StepToken.Operator: case StepToken.Comment: continue; case StepToken.Overridden: edo.Properties.Add(deserializeOverridden()); continue; case StepToken.Null: edo.Properties.Add(deserializeNull()); continue; case StepToken.EndEntity: return(edo); case StepToken.EndLine: case StepToken.EndSection: case StepToken.EndSTEP: case StepToken.StartSTEP: case StepToken.StartSection: throw new StepSerializerException(String.Format(CultureInfo.InvariantCulture, "A token was found which was not expected: {0}", reader.TokenType)); default: throw new NotImplementedException(String.Format(CultureInfo.InvariantCulture, "The {0} ExpressToken type is not yet implemented by deserializeEntity()", reader.TokenType)); } //TODO should do some verification here (properties are after entityStart and before EntityEnd etc.) } throw new StepSerializerException("The reader reached the end without finding an endEntity token"); }