protected C With <T, S, Tid>( RepositoryBase <T> repository, string name, string template = null, Action <S> configurer = null) where T : IEntity where S : EntitySetupBase <T, Tid> where Tid : IEquatable <Tid> { var item = ObjectFactory.CreateInstance <T>(); TemplateManager.ApplyTemplate(item, template); Func <T, Tid> creator = (i) => { DataCreatorFactory.GetCreator <T>().Create(i); return(Activator.CreateInstance <S>().GetId(i)); }; var itemSetup = (S)Activator.CreateInstance(typeof(S)) as S; itemSetup.Initialize(item, creator, this); configurer?.Invoke(itemSetup); repository.Add(name, itemSetup.Final); return((C)this); }
internal static MenuItem CreateAddFromTemplateButton(Type context, Action <object> add) { MenuItem b = new MenuItem() { Header = LocalizationManager.Current.Interface["Control_AddFromTemplate"] }; b.Click += new RoutedEventHandler((sender, e) => { OpenFileDialog ofd = new OpenFileDialog() { Filter = $"{LocalizationManager.Current.General["Project_TemplateFilter"]}|*.npctemplate", Multiselect = false }; if (ofd.ShowDialog() == true) { try { var template = TemplateManager.LoadTemplate(ofd.FileName); if (template != null) { if (TemplateManager.IsCorrectContext(template, context)) { TemplateManager.PrepareTemplate(template); if (template.Inputs.Count > 0) { TemplateManager.AskForInput(template); } var result = TemplateManager.ApplyTemplate(template); add.Invoke(result); } else { App.NotificationManager.Notify(LocalizationManager.Current.Notification.Translate("Template_InvalidContext")); } } else { App.NotificationManager.Notify(LocalizationManager.Current.Notification.Translate("Template_InvalidFile")); } } catch (Exception ex) { App.NotificationManager.Notify(LocalizationManager.Current.Notification.Translate("Template_Error")); App.Logger.LogException("Could not add item from template", ex: ex); } } }); b.Icon = new PackIconMaterial() { Kind = PackIconMaterialKind.FolderPlusOutline }; (b.Icon as PackIconMaterial).SetResourceReference(PackIconMaterial.ForegroundProperty, "AccentColor"); return(b); }
public void GivenTheUsers( string template = null, Characteristics characteristics = null, Dictionary<string, User> users = null) { foreach (var user in users.Values) TemplateManager.ApplyTemplate(user, template); foreach (var user in users.Values) base.Repository.CharacteristicsTransitionMethods[characteristics](user); foreach (var key in users.Keys) Add(key, users[key]); }
public void GivenThetestObjects( string template = null, Characteristics characteristics = null, Dictionary <string, TestObject> testObjects = null) { foreach (var testObject in testObjects.Values) { TemplateManager.ApplyTemplate(testObject, template); Repository.DecorateNewItem(testObject); Repository.CharacteristicsTransitionMethods[characteristics](testObject); } foreach (var key in testObjects.Keys) { Add(key, testObjects[key]); } }
public void GivenTheStores( string template = null, Characteristics characteristics = null, Dictionary <string, Store> stores = null) { foreach (var store in stores.Values) { TemplateManager.ApplyTemplate(store, template); Repository.DecorateNewItem(store); Repository.CharacteristicsTransitionMethods[characteristics](store); } foreach (var key in stores.Keys) { Add(key, stores[key]); } }
public void GivenTheDealers( string template = null, Characteristics characteristics = null, Dictionary <string, Dealer> dealers = null) { foreach (var dealer in dealers.Values) { TemplateManager.ApplyTemplate(dealer, template); Repository.DecorateNewItem(dealer); Repository.CharacteristicsTransitionMethods[characteristics](dealer); } foreach (var key in dealers.Keys) { Add(key, dealers[key]); } }
public void GivenTheInventoryLocations( string template = null, Characteristics characteristics = null, Dictionary <string, InventoryLocation> inventoryLocations = null) { foreach (var inventoryLocation in inventoryLocations.Values) { TemplateManager.ApplyTemplate(inventoryLocation, template); Repository.DecorateNewItem(inventoryLocation); Repository.CharacteristicsTransitionMethods[characteristics](inventoryLocation); } foreach (var key in inventoryLocations.Keys) { Add(key, inventoryLocations[key]); } }
public void GivenTheItems( string template = null, Characteristics characteristics = null, Dictionary <string, Item> items = null) { foreach (var item in items.Values) { TemplateManager.ApplyTemplate(item, template); Repository.DecorateNewItem(item); Repository.CharacteristicsTransitionMethods[characteristics](item); } foreach (var key in items.Keys) { Add(key, items[key]); } }
public void GivenTheEmployeesOfType(string type, Dictionary <string, Employee> employees) => employees.Keys.ToList().ForEach(k => Add(k, TemplateManager.ApplyTemplate(employees[k], type)));