internal static void UpdateCountryFiles(Dictionary <string, List <Tuple <string, string> > > changesCountryFiles, Form showWaitCursorForm = null)
        {
            try
            {
                if (showWaitCursorForm == null)
                {
                    showWaitCursorForm = EM_AppContext.Instance.GetActiveCountryMainForm();
                }
                showWaitCursorForm.Cursor = Cursors.WaitCursor;
                bool showOpenWarning = true;
                foreach (var ccChange in changesCountryFiles)
                {
                    string         country    = ccChange.Key;
                    EM_UI_MainForm ccMainForm = EM_AppContext.Instance.GetCountryMainForm(country);
                    if (ccMainForm != null)
                    {
                        if (showOpenWarning)
                        {
                            switch (UserInfoHandler.GetInfo(country.ToUpper() + " is open." + Environment.NewLine +
                                                            "Updating exchange rates requires a reset of the undo-functionality." + Environment.NewLine +
                                                            "That means you will not be able to undo any of your changes so far." + Environment.NewLine + Environment.NewLine +
                                                            "Do you still want to update exchange rates of " + country.ToUpper() + "?" + Environment.NewLine + Environment.NewLine +
                                                            "(Press Cancel to not be requested with respect to further open countries.)", MessageBoxButtons.YesNoCancel))
                            {
                            case DialogResult.No: continue;

                            case DialogResult.Cancel: showOpenWarning = false; break;
                            }
                        }
                        ccMainForm.GetUndoManager().Commit(); ccMainForm.GetUndoManager().Reset();
                    }
                    CountryConfigFacade ccf = CountryAdministrator.GetCountryConfigFacade(country);
                    foreach (var change in ccChange.Value)
                    {
                        ccf.GetSystemRowByName(change.Item1).ExchangeRateEuro = change.Item2;
                    }

                    if (ccMainForm != null)
                    {
                        ccMainForm.GetUndoManager().Commit(); ccMainForm.GetUndoManager().Reset(); ccMainForm.WriteXml();
                    }
                    else
                    {
                        CountryAdministrator.WriteXML(country);
                    }
                }
            }
            catch (Exception)
            {
            }
            finally { showWaitCursorForm.Cursor = Cursors.Default; }
        }
        internal static void SaveDirectXMLAction(EM_UI_MainForm mainForm)
        {
            string countryShortName = mainForm.GetCountryShortName();

            CountryAdministrator.GetCountryConfigFacade(countryShortName).GetCountryConfig().AcceptChanges();
            if (!CountryAdministrator.IsAddOn(countryShortName))
            {
                CountryAdministrator.GetDataConfigFacade(countryShortName).GetDataConfig().AcceptChanges();
            }
            mainForm.GetUndoManager().Reset();       //reset undo-manager with the drawback that actions up until now cannot be undone
            lock (EM_UI_MainForm._performActionLock) //to not get into conflict with auto-saving
            {
                CountryAdministrator.WriteXML(countryShortName);
            }
        }
Example #3
0
        internal static bool IsOldStyleExtensions(string cc, out bool openReadOnly)
        {
            openReadOnly = false; bool isOldStyle = false;
            // check for all policies with switch='switch' whether they are part of any extension ...
            foreach (CountryConfig.PolicyRow pol in from p in GetCountryConfig(cc).Policy where p.Switch == DefPar.Value.SWITCH select p)
            {
                if (!(from ep in GetCountryConfig(cc).Extension_Policy where ep.PolicyID == pol.ID && !ep.BaseOff select ep).Any())
                {
                    isOldStyle = true; break;
                }
            }
            if (!isOldStyle)
            {
                return(false);
            }

            // ... if not - suggest transformation to new style
            if (UserInfoHandler.GetInfo("The country needs to be updated to the new handling for Extensions (aka Switchable Policies)." + Environment.NewLine +
                                        "If you click Cancel the country will be opened in read-only mode.", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
            {
                openReadOnly = true; return(true);
            }

            // transform to new style: this assumes that the 'switch' settings in the spine are ok and just adds policies to extensions, which fulfill the name-pattern requirements
            CountryConfigFacade ccf = CountryAdministrator.GetCountryConfigFacade(cc);

            try
            {
                foreach (GlobLocExtensionRow ext in GetGlobalExtensions())
                {
                    foreach (CountryConfig.PolicyRow polRow in ccf.GetPolicyRowsOrderedAndDistinct())
                    {
                        string polName = string.IsNullOrEmpty(polRow.ReferencePolID) ? polRow.Name : ccf.GetPolicyRowByID(polRow.ReferencePolID).Name;
                        if (!EM_Helpers.DoesValueMatchPattern(ext.ShortName, polName))
                        {
                            continue;
                        }

                        foreach (CountryConfig.SystemRow sysRow in ccf.GetSystemRows())
                        {
                            CountryConfig.PolicyRow polSysRow = ccf.GetPolicyRowByOrder(polRow.Order, sysRow.ID);
                            if (!(from e in ccf.GetCountryConfig().Extension_Policy
                                  where e.ExtensionID == ext.ID & e.PolicyID == polSysRow.ID
                                  select e).Any()) // avoid double adding, which could actually only be caused by "playing"
                            {
                                ccf.GetCountryConfig().Extension_Policy.AddExtension_PolicyRow(ext.ID, polSysRow, false);
                            }
                        }
                    }
                }
                GetCountryConfig(cc).AcceptChanges();
                CountryAdministrator.WriteXML(cc);
            }
            catch (Exception exception)
            {
                UserInfoHandler.ShowException(exception, "Adapting Extensions failed.", false);
                ccf.GetCountryConfig().RejectChanges();
            }

            return(true);
        }
Example #4
0
        internal static void CheckForRemovedGlobalExtensions(string cc, out bool openReadOnly)
        {
            openReadOnly = false;
            List <string> existingExt = (from e in GetExtensions(cc) select e.ID).ToList();

            List <CountryConfig.Extension_PolicyRow>    delExtPol = new List <CountryConfig.Extension_PolicyRow>();
            List <CountryConfig.Extension_FunctionRow>  delExtFun = new List <CountryConfig.Extension_FunctionRow>();
            List <CountryConfig.Extension_ParameterRow> delExtPar = new List <CountryConfig.Extension_ParameterRow>();

            foreach (CountryConfig.Extension_PolicyRow ep in GetCountryConfig(cc).Extension_Policy)
            {
                if (!existingExt.Contains(ep.ExtensionID))
                {
                    delExtPol.Add(ep);
                }
            }
            foreach (CountryConfig.Extension_FunctionRow ef in GetCountryConfig(cc).Extension_Function)
            {
                if (!existingExt.Contains(ef.ExtensionID))
                {
                    delExtFun.Add(ef);
                }
            }
            foreach (CountryConfig.Extension_ParameterRow ep in GetCountryConfig(cc).Extension_Parameter)
            {
                if (!existingExt.Contains(ep.ExtensionID))
                {
                    delExtPar.Add(ep);
                }
            }

            if (!delExtPol.Any() && !delExtFun.Any() && !delExtPar.Any())
            {
                return;
            }
            if (UserInfoHandler.GetInfo("The country needs to be updated for removed Global Extensions." + Environment.NewLine +
                                        "If you click Cancel the country will be opened in read-only mode.", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
            {
                openReadOnly = true; return;
            }

            try
            {
                foreach (CountryConfig.Extension_PolicyRow dep in delExtPol)
                {
                    if (dep.PolicyRow.Switch == DefPar.Value.SWITCH)
                    {
                        dep.PolicyRow.Switch = DefPar.Value.TOGGLE;
                    }
                    dep.Delete();
                }
                foreach (CountryConfig.Extension_FunctionRow def in delExtFun)
                {
                    if (def.FunctionRow.Switch == DefPar.Value.SWITCH)
                    {
                        def.FunctionRow.Switch = DefPar.Value.TOGGLE;
                    }
                    def.Delete();
                }
                foreach (CountryConfig.Extension_ParameterRow dep in delExtPar)
                {
                    dep.Delete();
                }
                ExtensionDefaultSwitches_RemoveRelics(cc);

                GetCountryConfig(cc).AcceptChanges();
                CountryAdministrator.WriteXML(cc);
            }
            catch (Exception exception)
            {
                UserInfoHandler.ShowException(exception, "Adapting Extensions failed.", false);
                GetCountryConfig(cc).RejectChanges();
            }
        }
 internal override void PerformAction()
 {
     CountryAdministrator.WriteXML(_countryShortName, _alternativePath, _alternativeName);
 }