Esempio n. 1
0
        internal static void DoAdmin()
        {
            SwitchablePolicyConfigFacade globalExtensionConfigFacade = EM_AppContext.Instance.GetSwitchablePolicyConfigFacade();
            SwitchablePolicyConfig       globalExtensionConfig       = globalExtensionConfigFacade.GetSwitchablePolicyConfig();

            try
            {
                List <ExtensionOrGroup> extensions = new List <ExtensionOrGroup>();
                foreach (var sp in globalExtensionConfig.SwitchablePolicy)
                {
                    extensions.Add(new ExtensionOrGroup(sp));
                }

                AdminExtensionsOrGroupsForm adminDialog = new AdminExtensionsOrGroupsForm("Administrate Global Extensions", extensions, true);

                if (adminDialog.ShowDialog() == DialogResult.Cancel)
                {
                    return;
                }

                foreach (ExtensionOrGroup add in adminDialog.added)
                {
                    globalExtensionConfig.SwitchablePolicy.AddSwitchablePolicyRow(Guid.NewGuid().ToString(), add.name, add.shortName, add.look.ToXml());
                }

                foreach (ExtensionOrGroup change in adminDialog.changed)
                {
                    SwitchablePolicyConfig.SwitchablePolicyRow changeRow = (from ext in globalExtensionConfig.SwitchablePolicy where ext.ID == change.id select ext).First();
                    changeRow.LongName = change.name; changeRow.NamePattern = change.shortName; changeRow.Look = change.look.ToXml();
                }

                List <SwitchablePolicyConfig.SwitchablePolicyRow> delRow = (from ext in globalExtensionConfig.SwitchablePolicy select ext).ToList();
                for (int i = delRow.Count - 1; i >= 0; --i)
                {
                    if (adminDialog.deletedIds.Contains(delRow[i].ID))
                    {
                        delRow[i].Delete();
                    }
                }

                globalExtensionConfigFacade.AcceptChanges();
                globalExtensionConfigFacade.WriteXML();

                foreach (EM_UI_MainForm mainForm in EM_AppContext.Instance.GetOpenCountriesMainForms())
                {
                    mainForm.treeList.Refresh();                                                                                     // update look if necessary
                }
            }
            catch (Exception exception)
            {
                globalExtensionConfigFacade.RejectChanges();
                UserInfoHandler.ShowException(exception);
            }
        }
        internal override void PerformAction()
        {
            DataConfig dataConfig = CountryAdministrator.GetDataConfigFacade(cc).GetDataConfig();
            List <ExtensionOrGroup> extensions = new List <ExtensionOrGroup>();

            foreach (DataConfig.ExtensionRow ext in from e in dataConfig.Extension select e)
            {
                extensions.Add(new ExtensionOrGroup(ext));
            }

            using (AdminExtensionsOrGroupsForm adminDialog = new AdminExtensionsOrGroupsForm("Administrate Country Specific Extensions", extensions))
            {
                if (adminDialog.ShowDialog() == DialogResult.Cancel)
                {
                    actionIsCanceled = true; return;
                }

                foreach (ExtensionOrGroup addEx in adminDialog.added)
                {
                    dataConfig.Extension.AddExtensionRow(Guid.NewGuid().ToString(), addEx.name, addEx.shortName, addEx.look.ToXml());
                }

                foreach (ExtensionOrGroup changeEx in adminDialog.changed)
                {
                    DataConfig.ExtensionRow exRow = (from e in dataConfig.Extension where e.ID == changeEx.id select e).First();
                    exRow.Name = changeEx.name; exRow.ShortName = changeEx.shortName; exRow.Look = changeEx.look.ToXml();
                }

                List <DataConfig.ExtensionRow> ex = (from e in dataConfig.Extension select e).ToList();
                for (int i = ex.Count - 1; i >= 0; --i)
                {
                    if (adminDialog.deletedIds.Contains(ex[i].ID))
                    {
                        ex[i].Delete();
                    }
                }

                // prepare for DoAfterCommitWork (updating tree)
                CountryConfig countryConfig = CountryAdministrator.GetCountryConfigFacade(cc).GetCountryConfig();
                foreach (string polID in from ep in countryConfig.Extension_Policy where adminDialog.deletedIds.Contains(ep.ExtensionID) select ep.PolicyID)
                {
                    delExPolRows.Add((from p in countryConfig.Policy where p.ID == polID select p).FirstOrDefault());
                }
                foreach (string funID in from ef in countryConfig.Extension_Function where adminDialog.deletedIds.Contains(ef.ExtensionID) select ef.FunctionID)
                {
                    delExFunRows.Add((from f in countryConfig.Function where f.ID == funID select f).FirstOrDefault());
                }

                // deleteExtensionContent
                List <CountryConfig.Extension_PolicyRow>    delPolicyRows    = new List <CountryConfig.Extension_PolicyRow>();
                List <CountryConfig.Extension_FunctionRow>  delFunctionRows  = new List <CountryConfig.Extension_FunctionRow>();
                List <CountryConfig.Extension_ParameterRow> delParameterRows = new List <CountryConfig.Extension_ParameterRow>();
                foreach (string extensionID in adminDialog.deletedIds)
                {
                    delPolicyRows.AddRange((from pe in countryConfig.Extension_Policy where pe.ExtensionID == extensionID select pe).ToList());
                    delFunctionRows.AddRange((from fe in countryConfig.Extension_Function where fe.ExtensionID == extensionID select fe).ToList());
                    delParameterRows.AddRange((from pe in countryConfig.Extension_Parameter where pe.ExtensionID == extensionID select pe).ToList());
                }
                for (int i = delPolicyRows.Count - 1; i >= 0; --i)
                {
                    delPolicyRows[i].Delete();
                }
                for (int i = delFunctionRows.Count - 1; i >= 0; --i)
                {
                    delFunctionRows[i].Delete();
                }
                for (int i = delParameterRows.Count - 1; i >= 0; --i)
                {
                    delParameterRows[i].Delete();
                }
            }
        }