Пример #1
0
        private void btnApply_Click(object sender, EventArgs e)
        {
            try
            {
                foreach (var csc in m_ctlList)
                {
                    csc.Apply();
                }
                if (m_workBus.FindDevice <IUlaDevice>() == null)
                {
                    Locator.Resolve <IUserMessage>()
                    .Error("Bad configuration!\n\nPease add ULA device!");
                    return;
                }
                if (m_workBus.FindDevice <IMemoryDevice>() == null)
                {
                    Locator.Resolve <IUserMessage>()
                    .Error("Bad configuration!\n\nPease add Memory device!");
                    return;
                }

                if (!m_workBus.Connect())
                {
                    Locator.Resolve <IUserMessage>()
                    .Error("Apply failed!\n\nThere is a problem in your machine configuration!\nSee logs for details");
                    m_workBus.Disconnect();
                    return;
                }

                XmlDocument xml  = new XmlDocument();
                XmlNode     root = xml.AppendChild(xml.CreateElement("Bus"));
                m_workBus.SaveConfigXml(root);

                bool running = m_vm.IsRunning;
                m_vm.DoStop();


                var bmgr = m_vm.Bus;

                // workaround to save border color + Reset in case when memory changed
                var ula       = bmgr.FindDevice <IUlaDevice>();
                var oldMemory = bmgr.FindDevice <IMemoryDevice>();
                int portFE    = ula != null ? ula.PortFE : 0x00;
                bmgr.LoadConfigXml(root);
                ula        = bmgr.FindDevice <IUlaDevice>();
                ula.PortFE = (byte)portFE;
                var memory = bmgr.FindDevice <IMemoryDevice>();
                if (memory != oldMemory)
                {
                    m_vm.DoReset();
                }

                m_vm.SaveConfig();
                if (running)
                {
                    m_vm.DoRun();
                }
                GC.Collect();
                Close();
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                m_workBus.Disconnect();
                Locator.Resolve <IUserMessage>()
                .Error("Apply failed!\n\n{0}", ex.Message);
            }
        }