Ejemplo n.º 1
0
        private void RemoveTemplateCommand_Executed(object obj)
        {
            TemplateViewModelBase tbase = SelectedTemplate as TemplateViewModelBase;

            try
            {
                if (File.Exists(Path.Combine(_TemplatesFolder, tbase.Naam + ".xml")))
                {
                    File.Delete(Path.Combine(_TemplatesFolder, tbase.Naam + ".xml"));
                }
                Templates.Remove(SelectedTemplate);
            }
            catch (Exception e)
            {
                System.Windows.MessageBox.Show($"Fout bij verwijderen template {tbase.Naam}:{Environment.NewLine}{e.ToString()}");
            }
        }
Ejemplo n.º 2
0
        private void ApplyTemplateCommand_Executed(object obj)
        {
            TemplateViewModelBase tb = SelectedTemplate as TemplateViewModelBase;

            string ApplyString = (string)obj;

            if (tb.HasReplaceValue && string.IsNullOrWhiteSpace(ApplyString))
            {
                TLCGen.Views.ApplyTemplateWindow dialog = new Views.ApplyTemplateWindow();
                dialog.ShowDialog();
                ApplyString = dialog.TemplateApplyString;
            }

            if (!tb.HasReplaceValue || !string.IsNullOrWhiteSpace(ApplyString))
            {
                if (tb.HasReplaceValue)
                {
                    string   list  = ApplyString.Replace(" ", "");
                    string[] elems = list.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (string s in elems)
                    {
                        List <object> templateitems = tb.GetItems();
                        List <T2>     actualitems   = new List <T2>();
                        foreach (object o in templateitems)
                        {
                            T2 oc = DeepCloner.DeepClone <T2>((T2)o);
                            ((ITemplatable)oc).SetAllIdentifyingNames("##", s);
                            actualitems.Add(oc);
                        }
                        _ContainingTab.AddFromTemplate(actualitems);
                    }
                }
                else
                {
                    List <object> templateitems = tb.GetItems();
                    List <T2>     actualitems   = new List <T2>();
                    foreach (object o in templateitems)
                    {
                        T2 oc = DeepCloner.DeepClone <T2>((T2)o);
                        actualitems.Add(oc);
                    }
                    _ContainingTab.AddFromTemplate(actualitems);
                }
            }
        }
Ejemplo n.º 3
0
        private void SaveTemplateCommand_Executed(object obj)
        {
            TLCGen.Views.NewTemplateWindow dialog = new Views.NewTemplateWindow();

            List <object> _items = _ContainingTab.GetTemplatableItems();
            List <T2>     items  = new List <T2>();

            foreach (object o in _items)
            {
                T2 oc = DeepCloner.DeepClone <T2>((T2)o);
                ((ITemplatable)oc).ClearAllReferences();
                items.Add(oc);
            }
            ITemplatable item = (ITemplatable)items[0];

            dialog.TemplateReplace = Regex.Replace(item.GetIdentifyingName(), _ReplaceRegex, "{0}");
            dialog.ShowDialog();

            if (!string.IsNullOrWhiteSpace(dialog.TemplateNaam))
            {
                using (XmlWriter writer = XmlWriter.Create(Path.Combine(_TemplatesFolder, dialog.TemplateNaam + ".xml")))
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(T1));
                    if (!string.IsNullOrWhiteSpace(dialog.TemplateReplace))
                    {
                        foreach (ITemplatable it in items)
                        {
                            it.SetAllIdentifyingNames(dialog.TemplateReplace, "##");
                        }
                    }
                    T1 template = (T1)Activator.CreateInstance(typeof(T1), items);
                    TemplateViewModelBase tbase = template as TemplateViewModelBase;
                    tbase.Naam = dialog.TemplateNaam;
                    if (!string.IsNullOrWhiteSpace(dialog.TemplateReplace))
                    {
                        tbase.HasReplaceValue = true;
                    }
                    serializer.Serialize(writer, template);
                    writer.Close();
                    Templates.Add(template);
                }
            }
        }