///// <summary> ///// Gets the id of entity. ///// </summary> ///// <value>The entity id or null for new instance.</value> //[TikProperty(".id", typeof(string), true, TikPropertyEditMode.ReadOnly)] //public string Id //{ // get { return properties.GetAsStringOrNull(".id"); } //} /// <summary> /// See <see cref="ITikEntity.LoadFromEntityRow"/> for details. /// Calls <see cref="OnCustomLoadFromEntityRow"/>. /// </summary> /// <remarks>Sets object state to unmodified by <see cref="MarkClear"/> call!</remarks> public void LoadFromEntityRow(ITikEntityRow entityRow) { //attributes.CreateAttribute(".id", entityRow.GetValue(".Id")); TikEntityMetadata entityMetadata = TikEntityMetadata.Get(GetType()); foreach (KeyValuePair <string, TikPropertyAttribute> propPair in entityMetadata.Properties) { if (propPair.Value.PropertyType == typeof(string)) { Properties.CreatePropertyWithValue(propPair.Key, entityRow.GetStringValueOrNull(propPair.Key, propPair.Value.Mandatory)); } else if ((propPair.Value.PropertyType == typeof(long)) || propPair.Value.PropertyType == typeof(long?)) { Properties.CreatePropertyWithValue(propPair.Key, entityRow.GetInt64ValueOrNull(propPair.Key, propPair.Value.Mandatory)); //long.Parse(entityRow.GetValue(propPair.Key), System.Globalization.CultureInfo.CurrentCulture) } else if ((propPair.Value.PropertyType == typeof(bool)) || (propPair.Value.PropertyType == typeof(bool?))) { Properties.CreatePropertyWithValue(propPair.Key, entityRow.GetBoolValueOrNull(propPair.Key, propPair.Value.Mandatory)); //string.Equals(entityRow.GetValue(propPair.Key), "true", StringComparison.OrdinalIgnoreCase) } else { throw new NotImplementedException(string.Format(CultureInfo.CurrentCulture, "Not supported property '{0}' type '{1}' in {2}.", propPair.Key, propPair.Value.PropertyType, this)); } //catch (FormatException ex) //{ // throw new FormatException(string.Format("Value '{0}' of property '{1}' can not be parsed to type '{2}' in {3}", // entityRow.GetStringValue(propPair.Key), propPair.Key, propPair.Value.PropertyType, this), ex); //} } OnCustomLoadFromEntityRow(entityRow); MarkClear(); }
internal TikPropertyParser(TikSession session, string request, List <string> responseDataRows) { Guard.ArgumentNotNull(responseDataRows, "responseDataRows"); Guard.ArgumentNotNullOrEmptyString(request, "request"); //entityPath string[] items = request.Split('\n'); if (items[0].Contains(@"/print")) //remove /print sufix if present { this.entityPath = items[0].Substring(0, items[0].IndexOf(@"/print")); } else { this.entityPath = items[0]; } StringHelper.GetEntityFqn(entityPath, out entityNamespace, out entityName); //response -> properties props = new Dictionary <string, FieldType>(); entityExampleRow = ""; foreach (string responseDataRow in responseDataRows) { if (responseDataRow.StartsWith("!re")) { if (string.IsNullOrEmpty(entityExampleRow)) { entityExampleRow = responseDataRow; } ITikEntityRow row = session.Connector.CreateEntityRow(responseDataRow); foreach (string key in row.Keys) { bool nullable = StringHelper.DetermineFieldNulable(key); FieldType fieldType = StringHelper.DetermineFieldTypeFromValue(row.GetStringValueOrNull(key, true), nullable); if (!props.ContainsKey(key)) { props.Add(key, fieldType); } else { FieldType actualType = props[key]; if (actualType != fieldType) //set type=string if there more than one variant { props[key] = nullable ? FieldType.StringNulable : FieldType.String; } } } } } }
/// <summary> /// Called to perform additional custom load entity state (properties) from given <paramref name="entityRow"/>. /// </summary> /// <param name="entityRow">The entity row.</param> protected virtual void OnCustomLoadFromEntityRow(ITikEntityRow entityRow) { //dummy }
///// <summary> ///// Gets the id of entity. ///// </summary> ///// <value>The entity id or null for new instance.</value> //[TikProperty(".id", typeof(string), true, TikPropertyEditMode.ReadOnly)] //public string Id //{ // get { return properties.GetAsStringOrNull(".id"); } //} /// <summary> /// See <see cref="ITikEntity.LoadFromEntityRow"/> for details. /// Calls <see cref="OnCustomLoadFromEntityRow"/>. /// </summary> /// <remarks>Sets object state to unmodified by <see cref="MarkClear"/> call!</remarks> public void LoadFromEntityRow(ITikEntityRow entityRow) { //attributes.CreateAttribute(".id", entityRow.GetValue(".Id")); TikEntityMetadata entityMetadata = TikEntityMetadata.Get(GetType()); foreach (KeyValuePair<string, TikPropertyAttribute> propPair in entityMetadata.Properties) { if (propPair.Value.PropertyType == typeof(string)) Properties. CreatePropertyWithValue(propPair.Key, entityRow.GetStringValueOrNull(propPair.Key, propPair.Value.Mandatory)); else if ((propPair.Value.PropertyType == typeof(long)) || propPair.Value.PropertyType == typeof(long?)) Properties.CreatePropertyWithValue(propPair.Key, entityRow.GetInt64ValueOrNull(propPair.Key, propPair.Value.Mandatory)); //long.Parse(entityRow.GetValue(propPair.Key), System.Globalization.CultureInfo.CurrentCulture) else if ((propPair.Value.PropertyType == typeof(bool)) || (propPair.Value.PropertyType == typeof(bool?))) Properties.CreatePropertyWithValue(propPair.Key, entityRow.GetBoolValueOrNull(propPair.Key, propPair.Value.Mandatory)); //string.Equals(entityRow.GetValue(propPair.Key), "true", StringComparison.OrdinalIgnoreCase) else throw new NotImplementedException(string.Format(CultureInfo.CurrentCulture, "Not supported property '{0}' type '{1}' in {2}.", propPair.Key, propPair.Value.PropertyType, this)); //catch (FormatException ex) //{ // throw new FormatException(string.Format("Value '{0}' of property '{1}' can not be parsed to type '{2}' in {3}", // entityRow.GetStringValue(propPair.Key), propPair.Key, propPair.Value.PropertyType, this), ex); //} } OnCustomLoadFromEntityRow(entityRow); MarkClear(); }