public bool TryWrite <T>(T model, out string message, string filepath = "") where T : class, new() { bool b = false; message = string.Empty; filepath = !String.IsNullOrWhiteSpace(filepath) ? filepath : Filepath <T>(); try { //JsonSerializerOptions options = new JsonSerializerOptions() //{ // WriteIndented = true, // IgnoreReadOnlyProperties = true, // PropertyNamingPolicy = JsonNamingPolicy.CamelCase //}; //var json = JsonConvert.SerializeObject(model, Formatting.Indented); //File.WriteAllText(filepath, json); GenericObjectManager.WriteGenericItem <T>(model, filepath); b = true; } catch (Exception ex) { message = ex.InnerException != null ? ex.InnerException.Message : ex.Message; } return(b); }
public bool TryRead <T>(string filepath, out List <T> list, out string message) where T : class, new() { bool b = false; list = null; message = string.Empty; try { if (File.Exists(filepath)) { //string filecontents = File.ReadAllText(filepath); //if (!string.IsNullOrWhiteSpace(filecontents)) //{ // list = JsonConvert.DeserializeObject<List<T>>(filecontents); // b = true; //} list = GenericObjectManager.ReadGenericList <T>(filepath); b = true; } } catch (Exception ex) { message = ex.InnerException != null ? ex.InnerException.Message : ex.Message; } return(b); }
public void Create_NotExists_Null() { var manager = new GenericObjectManager <TaskActivity>(); TaskActivity activity = manager.GetObject("DNE", ""); activity.Should().BeNull(); }
public bool TryRead <T>(out List <T> list, out string message, string filepath = "") where T : class, new() { bool b = false; message = string.Empty; list = new List <T>(); filepath = !String.IsNullOrWhiteSpace(filepath) ? filepath : Filepath <T>(); try { if (File.Exists(filepath)) { list = GenericObjectManager.ReadGenericList <T>(filepath); string filecontents = File.ReadAllText(filepath); if (!string.IsNullOrWhiteSpace(filecontents)) { //list = JsonConvert.DeserializeObject<List<T>>(filecontents); } //b = list.Count > 0; } } catch (Exception ex) { message = ex.InnerException != null ? ex.InnerException.Message : ex.Message; } return(b); }
private void UploadStateMachine() { bool b = false; if (DataService.TryLocateFile(out FileInfo info)) { try { if (info.Extension.Equals(".xml", StringComparison.OrdinalIgnoreCase)) { Machine = GenericObjectManager.ReadGenericItem <StateMachine>(info.FullName); b = true; } else if (info.Extension.Equals(".json", StringComparison.OrdinalIgnoreCase)) { string text = File.ReadAllText(info.FullName); Machine = JsonConvert.DeserializeObject <StateMachine>(text); b = true; } if (b) { //Machine.SetState(); //Workflow = new WorkflowViewModel(Machine); } } catch (Exception ex) { string message = ex.InnerException != null ? ex.InnerException.Message : ex.Message; MessageBox.Show(message); } } }
public void Create_OpenGeneric_NotNull(Type type) { var manager = new GenericObjectManager <TaskActivity>(); manager.Add(new ActivityObjectCreator(new TaskActivityDescriptor(typeof(TestActivity <>)))); TaskActivity activity = manager.GetObject(TypeShortName.ToString(type, false), string.Empty); activity.Should().NotBeNull(); activity.As <WrapperActivity>().Descriptor.Type.Should().Be(type); }
public void Create_Exists_NotNull() { var manager = new GenericObjectManager <TaskActivity>(); manager.Add(new ActivityObjectCreator(s_descriptor)); TaskActivity activity = manager.GetObject(s_descriptor.Name, s_descriptor.Version); activity.Should().NotBeNull(); activity.As <WrapperActivity>().Descriptor.Type.Should().Be(s_descriptor.Type); }
public void Add_Exists_Throws() { var manager = new GenericObjectManager <TaskActivity>(); manager.Add(new ActivityObjectCreator(s_descriptor)); Action act = () => manager.Add(new ActivityObjectCreator(s_descriptor)); act.Should().Throw <InvalidOperationException>(); }
public void Create_ClosedGeneric_NotNull() { var descriptor = TaskActivityDescriptor.Create <TestActivity <object> >(); var manager = new GenericObjectManager <TaskActivity>(); manager.Add(new ActivityObjectCreator(descriptor)); TaskActivity activity = manager.GetObject(descriptor.Name, descriptor.Version); activity.Should().NotBeNull(); activity.As <WrapperActivity>().Descriptor.Type.Should().Be(descriptor.Type); TaskActivity activity2 = manager.GetObject(typeof(TestActivity <int>).FullName, descriptor.Version); activity2.Should().BeNull(); }
public void Add_NotExists_Succeeds() { var manager = new GenericObjectManager <TaskActivity>(); manager.Add(new ActivityObjectCreator(s_descriptor)); }
public static StateMachine Clone(this StateMachine model) { StateMachine clone = GenericObjectManager.Clone <StateMachine>(model); return(clone); }