internal override void DoAfterCommitWork() // adapt spine switches for deleted extensions (directly in tree, as a full update takes too long)
        {
            foreach (CountryConfig.PolicyRow polRow in delExPolRows)
            {
                if (polRow == null)
                {
                    continue;
                }
                SetSwitch(polRow.ID, polRow.SystemID, false, ExtensionAndGroupManager.GetExtensionAdaptedSwitch(polRow), !ExtensionAndGroupManager.ShowExtensionSwitchEditor(polRow));
                foreach (CountryConfig.FunctionRow funRow in polRow.GetFunctionRows())
                {
                    SetSwitch(funRow.ID, polRow.SystemID, true, ExtensionAndGroupManager.GetExtensionAdaptedSwitch(funRow), !ExtensionAndGroupManager.ShowExtensionSwitchEditor(funRow));
                }
            }
            foreach (CountryConfig.FunctionRow funRow in delExFunRows)
            {
                if (funRow == null)
                {
                    continue;
                }
                SetSwitch(funRow.ID, funRow.PolicyRow.SystemID, true, ExtensionAndGroupManager.GetExtensionAdaptedSwitch(funRow), !ExtensionAndGroupManager.ShowExtensionSwitchEditor(funRow));
            }

            void SetSwitch(string rowID, string sysID, bool isFun, string origSwitch, bool changeOldStyleXmlSwitchToToggle)
            {
                KeyValuePair <TreeListNode, TreeListColumn> cell = mainForm.GetTreeListBuilder().GetCellByDataRow(rowID, sysID, isFun);

                if (cell.Key != null && cell.Value != null)
                {
                    cell.Key.SetValue(cell.Value,
                                      changeOldStyleXmlSwitchToToggle && origSwitch == DefPar.Value.SWITCH ? DefPar.Value.TOGGLE : origSwitch);
                }
            }
        }
        internal override void PerformAction()
        {
            CountryConfig countryConfig = CountryAdministrator.GetCountryConfigFacade(cc).GetCountryConfig();

            ExtensionAndGroupMenuManager.GetSelectionPolFunPar(cc, out selectedPolRows, out selectedFunRows, out List <CountryConfig.ParameterRow> parRows);
            string extensionID = (from e in ExtensionAndGroupManager.GetExtensions(cc) where e.Name == extensionName select e.ID).FirstOrDefault(); if (extensionID == null)
            {
                return;
            }

            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 (CountryConfig.PolicyRow policyRow in selectedPolRows)
            {
                selectedFunRows.AddRange(policyRow.GetFunctionRows()); // to make sure that all functions of the policy are removed as well - note: the AddContent-function
                // does not remove a single function if its parent-policy is added (later)
                foreach (CountryConfig.Extension_PolicyRow del in from pe in countryConfig.Extension_Policy where pe.ExtensionID == extensionID& pe.PolicyID == policyRow.ID select pe)
                {
                    if (!delPolicyRows.Contains(del))
                    {
                        delPolicyRows.Add(del);                               // theoretically (but stupidly) this can be 2 (off and on)
                    }
                }
            }
            foreach (CountryConfig.FunctionRow functionRow in selectedFunRows)
            {
                parRows.AddRange(functionRow.GetParameterRows()); // see above
                foreach (CountryConfig.Extension_FunctionRow del in from fe in countryConfig.Extension_Function where fe.ExtensionID == extensionID& fe.FunctionID == functionRow.ID select fe)
                {
                    if (!delFunctionRows.Contains(del))
                    {
                        delFunctionRows.Add(del);
                    }
                }
            }
            foreach (CountryConfig.ParameterRow parameterRow in parRows)
            {
                foreach (CountryConfig.Extension_ParameterRow del in from pe in countryConfig.Extension_Parameter where pe.ExtensionID == extensionID& pe.ParameterID == parameterRow.ID select pe)
                {
                    if (!delParameterRows.Contains(del))
                    {
                        delParameterRows.Add(del);
                    }
                }
            }
            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();
            }
        }
Ejemplo n.º 3
0
        internal IsExtensionMember(CountryConfig countryConfig, DataConfig dataConfig, string extensionName, bool onOnly)
        {
            List <GlobLocExtensionRow> extensions = ExtensionAndGroupManager.GetExtensions((countryConfig.Country.Rows[0] as CountryConfig.CountryRow).ShortName);
            string extensionID = (from e in extensions where e.Name == extensionName select e.ID).FirstOrDefault(); if (extensionID == null)

            {
                return;
            }

            policyIDs    = (from pe in countryConfig.Extension_Policy where pe.ExtensionID == extensionID && (!onOnly || !pe.BaseOff) select pe.PolicyID).ToList();
            functionIDs  = (from fe in countryConfig.Extension_Function where fe.ExtensionID == extensionID && (!onOnly || !fe.BaseOff) select fe.FunctionID).ToList();
            parameterIDs = (from pe in countryConfig.Extension_Parameter where pe.ExtensionID == extensionID && (!onOnly || !pe.BaseOff) select pe.ParameterID).ToList();
        }
        internal override void PerformAction()
        {
            SetExtensionSwitchesForm setSwitchesDialog = new SetExtensionSwitchesForm(_cc);

            if (setSwitchesDialog.ShowDialog() == DialogResult.Cancel)
            {
                _actionIsCanceled = true; return;
            }

            //store the redefined switches in the data-config
            foreach (ExtensionSwitchDefaultValue extensionSwitchDefaultValue in setSwitchesDialog.GetExtensionDefaultSwitches())
            {
                ExtensionAndGroupManager.SetExtensionDefaultSwitch(CountryAdministrator.GetDataConfigFacade(_cc).GetDataConfig(),
                                                                   extensionSwitchDefaultValue._dbSystemConfigRow, extensionSwitchDefaultValue._extensionID, extensionSwitchDefaultValue._defaultValue);
            }

            //remove any "relics", i.e. default values of switchable policies, which were deleted
            ExtensionAndGroupManager.ExtensionDefaultSwitches_RemoveRelics(_cc);
        }
Ejemplo n.º 5
0
        internal SetExtensionSwitchesForm(string countryShortName)
        {
            InitializeComponent();

            try
            {
                _countryShortName = countryShortName;
                labelCountry.Text = _countryShortName;
                _dataConfig       = CountryAdministrator.GetDataConfigFacade(_countryShortName).GetDataConfig();

                _extensionDefaultSwitches = new List <ExtensionSwitchDefaultValue>();
                foreach (GlobLocExtensionRow e in ExtensionAndGroupManager.GetExtensions(_countryShortName))
                {
                    ListViewItem item = lvSwitchablePolicies.Items.Add(e.Name); item.SubItems.Add(e.ShortName); item.Tag = e.ID;

                    //store initial default values of the policy switches in this structure,
                    //which is necessary as the dialog changes between switchable policies and the changed values need to be buffered
                    //(actual database changes are performed after closing the dialog with OK)
                    foreach (DataConfig.DataBaseRow dataBaseRow in from db in _dataConfig.DataBase select db)
                    {
                        foreach (DataConfig.DBSystemConfigRow dbSystemConfigRow in from ds in _dataConfig.DBSystemConfig where ds.DataBaseID == dataBaseRow.ID select ds)
                        {
                            _extensionDefaultSwitches.Add(new ExtensionSwitchDefaultValue(e.ID, dbSystemConfigRow,
                                                                                          ExtensionAndGroupManager.GetExtensionDefaultSwitch(dbSystemConfigRow, e.ID))); //returns n/a if switch does not (yet) exist
                        }
                    }
                }

                InitSwitchTable(); //draw columns (systems) and rows (datasets) of the table

                if (lvSwitchablePolicies.Items.Count > 0)
                {
                    lvSwitchablePolicies.Items[0].Checked = true; //select the first switchable policy
                }
                UpdateSwitchTable();                              //fill the table with the switch values of this policy
            }
            catch (Exception exception)
            {
                UserInfoHandler.ShowException(exception);
            }
        }
Ejemplo n.º 6
0
        internal override void PerformAction()
        {
            string extensionID = (from e in ExtensionAndGroupManager.GetExtensions(cc) where e.Name.ToLower() == extensionName.ToLower() select e.ID).FirstOrDefault();

            if (extensionID == null)
            {
                actionIsCanceled = true; return;
            }

            CountryConfigFacade countryConfigFacade = CountryAdministrator.GetCountryConfigFacade(cc);
            CountryConfig       countryConfig       = CountryAdministrator.GetCountryConfigFacade(cc).GetCountryConfig();

            List <string> polIDs = (from pe in countryConfig.Extension_Policy where pe.ExtensionID == extensionID && pe.BaseOff == false select pe.PolicyID).ToList();
            List <string> funIDs = (from fe in countryConfig.Extension_Function where fe.ExtensionID == extensionID && fe.BaseOff == false select fe.FunctionID).ToList();
            List <string> parIDs = (from pe in countryConfig.Extension_Parameter where pe.ExtensionID == extensionID && pe.BaseOff == false select pe.ParameterID).ToList();

            if (!polIDs.Any() && !funIDs.Any() && !polIDs.Any())
            {
                actionIsCanceled = true; return;
            }

            string yn = set ? DefPar.Value.YES : DefPar.Value.NO;

            foreach (string polID in polIDs)
            {
                countryConfigFacade.GetPolicyRowByID(polID).Private = yn;
            }
            foreach (string funID in funIDs)
            {
                countryConfigFacade.GetFunctionRowByID(funID).Private = yn;
            }
            foreach (string parID in parIDs)
            {
                countryConfigFacade.GetParameterRowByID(parID).Private = yn;
            }
        }
        internal override void PerformAction()
        {
            CountryConfig countryConfig = CountryAdministrator.GetCountryConfigFacade(cc).GetCountryConfig();

            ExtensionAndGroupMenuManager.GetSelectionPolFunPar(cc, out List <CountryConfig.PolicyRow> polRows, out List <CountryConfig.FunctionRow> funRows, out List <CountryConfig.ParameterRow> parRows);

            string extensionID = (from e in ExtensionAndGroupManager.GetExtensions(cc) where e.Name == extensionName select e.ID).FirstOrDefault(); if (extensionID == null)
            {
                return;
            }
            bool baseOff = !on;

            foreach (CountryConfig.PolicyRow polRow in polRows)
            {
                if (!(from pe in countryConfig.Extension_Policy where pe.PolicyID == polRow.ID && pe.ExtensionID == extensionID && pe.BaseOff == baseOff select pe).Any())
                {
                    countryConfig.Extension_Policy.AddExtension_PolicyRow(extensionID, polRow, baseOff); // make sure to not add twice (and thus crash)
                    if (polRow.Switch == DefPar.Value.NA)
                    {
                        polRow.Switch = DefPar.Value.OFF;                                   // if set to n/a the xml-reader would ignore the policy, before extensions are taken into account
                    }
                }
            }
            foreach (CountryConfig.FunctionRow funRow in funRows)
            {
                if (!(from fe in countryConfig.Extension_Function where fe.FunctionID == funRow.ID && fe.ExtensionID == extensionID && fe.BaseOff == baseOff select fe).Any())
                {
                    countryConfig.Extension_Function.AddExtension_FunctionRow(extensionID, funRow, baseOff);
                    if (funRow.Switch == DefPar.Value.NA)
                    {
                        funRow.Switch = DefPar.Value.OFF;
                    }
                }
            }
            foreach (CountryConfig.ParameterRow parRow in parRows)
            {
                if (!(from pe in countryConfig.Extension_Parameter where pe.ParameterID == parRow.ID && pe.ExtensionID == extensionID && pe.BaseOff == baseOff select pe).Any())
                {
                    countryConfig.Extension_Parameter.AddExtension_ParameterRow(extensionID, parRow, baseOff);
                }
            }

            if (!on)
            {
                return;
            }

            // adapt switches in treelist directly, as a full update takes too long
            foreach (CountryConfig.PolicyRow polRow in polRows)
            {
                SetSwitch(polRow.ID, polRow.SystemID, false, DefPar.Value.SWITCH);
                // for functions, which are part of an extension-policy one still needs to show off and n/a instead of switch (see GetExtensionAdaptedSwitch)
                foreach (CountryConfig.FunctionRow funRow in polRow.GetFunctionRows())
                {
                    SetSwitch(funRow.ID, polRow.SystemID, true, ExtensionAndGroupManager.GetExtensionAdaptedSwitch(funRow));
                }
            }
            foreach (CountryConfig.FunctionRow funRow in funRows)
            {
                SetSwitch(funRow.ID, funRow.PolicyRow.SystemID, true, DefPar.Value.SWITCH);
            }

            void SetSwitch(string rowID, string sysID, bool isFun, string switchValue)
            {
                KeyValuePair <TreeListNode, TreeListColumn> cell = mainForm.GetTreeListBuilder().GetCellByDataRow(rowID, sysID, isFun);

                if (cell.Key != null && cell.Value != null)
                {
                    cell.Key.SetValue(cell.Value, switchValue);
                }
            }
        }
        private static Dictionary <string, Image> GetRelevantExtensionMenuItems(string cc, string menuItemName)
        {
            Dictionary <string, Image> relevantExtensions = new Dictionary <string, Image>();
            bool globalOnly = menuItemName == MENU_EXTENSION_PRIVATE_ALL || menuItemName == MENU_EXTENSION_NOT_PRIVATE_ALL;

            // (1) add to extension: only show extensions which still can be added, i.e. where not already all selected elements belong to
            if (menuItemName == MENU_EXTENSION_ADDON || menuItemName == MENU_EXTENSION_ADDOFF)
            {
                foreach (GlobLocExtensionRow extRow in globalOnly ? ExtensionAndGroupManager.GetGlobalExtensions() : ExtensionAndGroupManager.GetExtensions(cc))
                {
                    bool canBeAdded = false;
                    foreach (TreeListNode node in GetSelectedNodes(cc))
                    {
                        if (CountryAdministrator.IsAddOn(cc) || node.Tag == null || node.Tag as BaseTreeListTag == null)
                        {
                            continue;
                        }
                        BaseTreeListTag nodeTag = node.Tag as BaseTreeListTag;
                        if (nodeTag.GetDefaultParameterRow() != null) // means: if (isParameterRow)
                        {
                            if ((from ePar in GetCountryConfig(cc).Extension_Parameter
                                 where ePar.ExtensionID == extRow.ID && ePar.ParameterID == nodeTag.GetDefaultParameterRow().ID
                                 select ePar).Any())
                            {
                                continue;                      // node belongs to extension
                            }
                        }
                        if (nodeTag.GetDefaultFunctionRow() != null) // means: if (isFunctionRow || isParameterRow)
                        {
                            var ef = from eFun in GetCountryConfig(cc).Extension_Function
                                     where eFun.ExtensionID == extRow.ID && eFun.FunctionID == nodeTag.GetDefaultFunctionRow().ID
                                     select eFun;
                            if (ef.Any())
                            {
                                if (nodeTag.GetDefaultParameterRow() == null)
                                {
                                    continue;                                           // is actually function-node and belongs to extension
                                }
                                // a parameter-node can still be added as switch-off, if function-node is added as switch-on
                                if (ef.First().BaseOff || menuItemName == MENU_EXTENSION_ADDON)
                                {
                                    continue;
                                }
                            }
                        }
                        // means: if (isPolicyRow || isFunctionRow || isParameterRow)
                        var ep = from ePol in GetCountryConfig(cc).Extension_Policy
                                 where ePol.ExtensionID == extRow.ID && ePol.PolicyID == nodeTag.GetDefaultPolicyRow().ID
                                 select ePol;
                        if (ep.Any())
                        {
                            if (nodeTag.GetDefaultParameterRow() == null && nodeTag.GetDefaultFunctionRow() == null)
                            {
                                continue;                                                                                      // is actually policy-node and belongs to extension
                            }
                            // a parameter- or function-node can still be added as switch-off, if policy-node is added as switch-on
                            if (ep.First().BaseOff || menuItemName == MENU_EXTENSION_ADDON)
                            {
                                continue;
                            }
                        }
                        canBeAdded = true; break; // node, nor parent nodes, do belong to extension: can be added
                    }
                    if (!canBeAdded)
                    {
                        continue;
                    }
                    ExtensionOrGroup eg = new ExtensionOrGroup(extRow);
                    relevantExtensions.Add(eg.name, eg.look.GetMenuImage());
                }
            }
            // (2) remove from extension: only show extensions which can be removed, i.e. where any of the selected elements belongs to
            else if (menuItemName == MENU_EXTENSION_REMOVE)
            {
                List <string> extIds = new List <string>();
                foreach (TreeListNode node in GetSelectedNodes(cc))
                {
                    if (CountryAdministrator.IsAddOn(cc) || node.Tag == null || node.Tag as BaseTreeListTag == null)
                    {
                        continue;
                    }
                    BaseTreeListTag nodeTag = node.Tag as BaseTreeListTag;
                    // "belongs to" means, that the function/parameter itself has to belong to the extension, not only the parent
                    if (nodeTag.GetDefaultParameterRow() != null) // means: if (isParameterRow)
                    {
                        extIds.AddRange(from ePar in GetCountryConfig(cc).Extension_Parameter where ePar.ParameterID == nodeTag.GetDefaultParameterRow().ID select ePar.ExtensionID);
                    }
                    else if (nodeTag.GetDefaultFunctionRow() != null) // means: if (isFunctionRow)
                    {
                        extIds.AddRange(from eFun in GetCountryConfig(cc).Extension_Function where eFun.FunctionID == nodeTag.GetDefaultFunctionRow().ID select eFun.ExtensionID);
                    }
                    else // means: if (isPolicyRow)
                    {
                        extIds.AddRange(from ePol in GetCountryConfig(cc).Extension_Policy where ePol.PolicyID == nodeTag.GetDefaultPolicyRow().ID select ePol.ExtensionID);
                    }
                }
                foreach (GlobLocExtensionRow gleRow in from e in globalOnly ? ExtensionAndGroupManager.GetGlobalExtensions() : ExtensionAndGroupManager.GetExtensions(cc)
                         where extIds.Contains(e.ID) select e)
                {
                    ExtensionOrGroup eg = new ExtensionOrGroup(gleRow);
                    relevantExtensions.Add(eg.name, eg.look.GetMenuImage());
                }
            }
            // (3) all other menu items (Expand,etc.): show all extensions
            else
            {
                foreach (GlobLocExtensionRow extRow in globalOnly ? ExtensionAndGroupManager.GetGlobalExtensions() : ExtensionAndGroupManager.GetExtensions(cc))
                {
                    ExtensionOrGroup eg = new ExtensionOrGroup(extRow);
                    relevantExtensions.Add(eg.name, eg.look.GetMenuImage());
                }
            }
            return(relevantExtensions.Any() ? relevantExtensions : new Dictionary <string, Image>()
            {
                { NO_ITEMS_DEFINED, null }
            });
        }