public IResponse Execute(SessionContext sessionContext, string parameter) { Profile profile = new Profile(); var properties = PropertiesWorker.GetDisplayProperties(typeof(Profile)); Console.WriteLine("Заполните анкету, отвечая на вопросы"); for (int step = 0; step <= (properties.Count() - 1);) { var property = properties[step]; var displayAttribute = properties[step].GetCustomAttribute <DisplayAttribute>(); Console.WriteLine($"{displayAttribute.Order}. {displayAttribute.Prompt?? displayAttribute.Name}"); var s = Console.ReadLine(); if (String.IsNullOrWhiteSpace(s)) { continue; } string [] cmdCheckStr = s.Split(" "); IChangeStepCommand cmd; if (changeStepCmdDict.TryGetValue(cmdCheckStr [0], out cmd)) { // Пришла команда на изменение номера шага var param = s.Substring(cmdCheckStr[0].Length); step = cmd.Execute(step, param); } else { int nextStep = ValidatePropertyValue(profile, property, s); step += nextStep; } } return(new Response(ResponseType.Entity, profile)); }
public object Deserialize(Stream serializationStream) { var entity = new E(); var properties = PropertiesWorker.GetDisplayProperties(typeof(E)); using (var fr = new StreamReader(serializationStream)) { foreach (PropertyInfo propertyInfo in properties) { var strvalue = fr.ReadLine().Split(": ")[1]; SetValue(ref entity, propertyInfo, strvalue); } fr.ReadLine(); properties = PropertiesWorker.GetNotDisplayProperties(typeof(E)); foreach (PropertyInfo propertyInfo in properties) { var strvalue = fr.ReadLine().Split(": ")[1]; SetValue(ref entity, propertyInfo, strvalue); } } return(entity); }
public void Serialize(Stream serializationStream, object graph) { var sw = new StreamWriter(serializationStream); var properties = PropertiesWorker.GetDisplayProperties(graph.GetType()); foreach (var propertyInfo in properties) { var strvalue = propertyInfo.GetValue(graph).ToString(); DisplayAttribute display = PropertiesWorker.GetDisplayAttribute(propertyInfo); sw.WriteLine($"{display.Order}. {display.Name}: {strvalue}"); } sw.WriteLine(); sw.WriteLine($"Анкета заполнена: {((Entity)graph).DateCreated.ToString("dd.MM.yyyy")}"); sw.Flush(); }