Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
 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]);
 }
Exemplo n.º 4
0
 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]);
     }
 }
Exemplo n.º 5
0
 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]);
     }
 }
Exemplo n.º 6
0
 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]);
     }
 }
Exemplo n.º 7
0
 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]);
     }
 }
Exemplo n.º 8
0
 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]);
     }
 }
Exemplo n.º 9
0
 public void GivenTheEmployeesOfType(string type, Dictionary <string, Employee> employees)
 => employees.Keys.ToList().ForEach(k => Add(k, TemplateManager.ApplyTemplate(employees[k], type)));