private static FieldProperties FieldPropertiesFor(string className, IReflectField field) { FieldProperties fp = new FieldProperties(field.GetName(), field.GetFieldType().GetName()); FieldDetails fd = new FieldDetails(className, fp.Field); fp.m_isPublic = fd.GetModifier(); fp.m_isIndexed = fd.IsIndexed(); return(fp); }
public string CastedValueOrNullConstant(object value, string name, string className) { IType type = new FieldDetails(className, name).GetFieldType(); if (type == null) { return(null); } return(value != null && value.ToString() != "null" ? type.Cast(value).ToString() : "null"); }
protected override void ShowFieldPrompt(FieldDetails fieldDetails) { base.ShowFieldPrompt(fieldDetails); // Raise the task for the first field prompt shown if (this.promptShownTask != null && this.promptShownTask.Task.Status == TaskStatus.WaitingForActivation) { this.promptShownTask.SetResult(true); } }
public override string AddField(FieldDetails fieldDetails, string parentHash) { var type = fieldDetails.Type; TypeMapper(ref type); Property property = new(type, fieldDetails.Name, parentHash); property.Hash = Tools.ByteToHex(Tools.GetSha256Hash(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(property)))); Memory.Add(property); return(property.Hash); }
public override string AddField(FieldDetails fieldDetails, string parentHash) { var type = fieldDetails.Type; TypeMapper(ref type); Field field = new(fieldDetails.Modifier, type, fieldDetails.Name, parentHash); field.Hash = Tools.ByteToHex(Tools.GetSha256Hash(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(field)))); Memory.Add(field); return(field.Hash); }
public object CheckIfObjectCanBeCasted(string classname, string fieldname, object data) { if (null == data && "null" == data.ToString()) { return(false); } IType objectType = new FieldDetails(classname, fieldname).GetFieldType(); if (objectType == null) { return(null); } return(objectType.Cast(data)); }
protected override void ShowFieldPrompt(FieldDetails fieldDetails) { base.ShowFieldPrompt(fieldDetails); messageSender .SendRequestAsync( ShowInputPromptRequest.Type, new ShowInputPromptRequest { Name = fieldDetails.Name, Label = fieldDetails.Label }, true) .ContinueWith(HandlePromptResponse) .ConfigureAwait(false); }
public bool ValidateDataType(string classname, string fieldname, object data) { if (null == data && "null" == data.ToString()) { return(false); } IType objectType = new FieldDetails(classname, fieldname).GetFieldType(); if (objectType == null) { return(false); } objectType.Cast(data); return(true); }
protected override void ShowFieldPrompt(FieldDetails fieldDetails) { // Write the prompt to the console first so that there's a record // of it occurring base.ShowFieldPrompt(fieldDetails); messageSender .SendRequest( ShowInputPromptRequest.Type, new ShowInputPromptRequest { Name = fieldDetails.Name, Label = fieldDetails.Label }, true) .ContinueWith(HandlePromptResponse) .ConfigureAwait(false); }
/// <summary> /// /// </summary> /// <param name="promptCaption"></param> /// <param name="promptMessage"></param> /// <param name="fieldDescriptions"></param> /// <returns></returns> public override Dictionary <string, PSObject> Prompt( string promptCaption, string promptMessage, Collection <FieldDescription> fieldDescriptions) { FieldDetails[] fields = fieldDescriptions .Select(f => { return(FieldDetails.Create(f, this.Logger)); }) .ToArray(); CancellationTokenSource cancellationToken = new CancellationTokenSource(); Task <Dictionary <string, object> > promptTask = this.CreateInputPromptHandler() .PromptForInput( promptCaption, promptMessage, fields, cancellationToken.Token); // Run the prompt task and wait for it to return this.WaitForPromptCompletion( promptTask, "Prompt", cancellationToken); // Convert all values to PSObjects var psObjectDict = new Dictionary <string, PSObject>(); // The result will be null if the prompt was cancelled if (promptTask.Result != null) { // Convert all values to PSObjects foreach (var keyValuePair in promptTask.Result) { psObjectDict.Add( keyValuePair.Key, keyValuePair.Value != null ? PSObject.AsPSObject(keyValuePair.Value) : null); } } // Return the result return(psObjectDict); }
public static void SaveValues(long id, string attribName, object newValue, int offset) { try { object targetObject = Db4oClient.Client.Ext().GetByID(id); Db4oClient.Client.Ext().Activate(targetObject, 2); IReflectClass rclass = DataLayerCommon.ReflectClassFor(targetObject); IReflectField rfield = DataLayerCommon.GetDeclaredFieldInHeirarchy(rclass, attribName); IType type = new FieldDetails(rclass.GetName(), attribName).GetFieldType(); object obj = rfield.Get(targetObject); if (obj is IDictionary) { SaveDictionary(targetObject, attribName, newValue, KeyAtIndex((IDictionary)obj, offset / 2)); } else { if (rfield != null && !(rfield is GenericVirtualField || rfield.IsStatic())) { if (type.IsArray || type.IsCollection) { IList list = obj as IList; if (null != list) { list[offset] = newValue; rfield.Set(targetObject, list); } } } } } catch (Exception oEx) { Db4oClient.Client.Rollback(); LoggingHelper.HandleException(oEx); } }
public TableDetails GetSchema() { MLPEntities context = new MLPEntities(); TableDetails td = new TableDetails(); td.TableName = this.TableName; var tblNoteProperties = context .GetType() .GetProperties() .Where(p => p.PropertyType.IsGenericType && p.PropertyType.GetGenericTypeDefinition() == typeof(DbSet <>)) .Select(p => p.PropertyType.GetGenericArguments()[0]) .Where(t => t.Name == this.TableName) .SelectMany(t => t.GetProperties()) .ToArray(); var names = (from t in tblNoteProperties where !t.Name.StartsWith("tbl") select t.Name).ToList(); var objectContext = ((IObjectContextAdapter)context).ObjectContext; var entityType = objectContext.MetadataWorkspace.GetItems <EntityType>(DataSpace.CSpace).Where(e => e.Name == td.TableName).First(); foreach (var col in names) { FieldDetails f = new FieldDetails(); f.FieldName = col; f.ConvertField(); var facets = entityType.Properties[col].TypeUsage.Facets; var nullable = (from c in facets where c.Name == "Nullable" select c).First(); if (nullable != null) { f.Nullable = (bool)nullable.Value; } var MaxLength = from c in facets where c.Name == "MaxLength" select c; if (MaxLength.Any() && !f.FieldName.StartsWith("txt")) { Facet facet = MaxLength.First(); if (facet.Value.ToString() == "Max") { f.FieldLengthMax = true; } else { f.FieldLength = Convert.ToInt16(facet.Value); f.FieldLengthMax = false; } } f.ConvertField(); //defaults switch (f.ModifiedFieldType) { case "string": f.DefaultValue = "\"\""; break; case "DateTime": case "DateTime?": f.DefaultValue = "new System.DateTime(1900, 1, 1)"; break; case "bool": f.DefaultValue = "true"; break; case "int": case "int?": case "float": case "decimal": f.DefaultValue = "0"; break; default: f.DefaultValue = "\"\""; break; } td.Fields.Add(f); } //foreach (var f in td.Fields) //{ // f.ConvertField(); //} td.UpdateIdField(); return(td); }
public static bool CheckForPrimitiveFields(string classname, string fieldname) { FieldDetails fl = new FieldDetails(classname, fieldname); return(fl.IsPrimitive()); }
private static FieldProperties FieldPropertiesFor(string className, IReflectField field) { FieldProperties fp = new FieldProperties(field.GetName(), field.GetFieldType().GetName()); FieldDetails fd = new FieldDetails(className, fp.Field); fp.m_isPublic = fd.GetModifier(); fp.m_isIndexed = fd.IsIndexed(); return fp; }
public static bool CheckForCollection(string classname, string fieldname) { FieldDetails fl = new FieldDetails(classname, fieldname); return(fl.IsCollection()); }
public static bool CheckForArray(string classname, string fieldname) { FieldDetails fl = new FieldDetails(classname, fieldname); return fl.IsArray(); }
public static bool CheckForCollection(string classname, string fieldname) { FieldDetails fl = new FieldDetails(classname, fieldname); return fl.IsCollection(); }
public static bool CheckForPrimitiveFields(string classname, string fieldname) { FieldDetails fl = new FieldDetails(classname, fieldname); return fl.IsPrimitive(); }
public static bool CheckForCollection(string className, string fieldname) { IType type = new FieldDetails(className, fieldname).GetFieldType(); return(CheckIsCollection(type)); }
public static bool CheckForArray(string classname, string fieldname) { FieldDetails fl = new FieldDetails(classname, fieldname); return(fl.IsArray()); }
protected override void ShowFieldPrompt(FieldDetails fieldDetails) { this.LastField = fieldDetails; }
public abstract string AddField(FieldDetails fieldDetails, string parentHash);