Exemple #1
0
 public void PerformUpdate()
 {
     SettingsNode.Descendants("Major").First().SetValue(Version.Major);
     SettingsNode.Descendants("Minor").First().SetValue(Version.Minor);
     SettingsNode.Descendants("Build").First().SetValue(Version.Build);
     SettingsNode.Descendants("Revision").First().SetValue(Version.Revision);
     SettingsDocument.Save(ConfigFilePath);
 }
Exemple #2
0
 private void buttonSave_Click(object sender, EventArgs e)
 {
     if (_filePathUsers != null)
     {
         SettingsDocument doc = SettingsConverter.ConvertObjectToDocument(_settingsObject, _filePathUsers);
         doc.Save(_filePathUsers, SettingsFileOption.Encrypted);
         UpdateUsersSettings.SafeInvoke(this._settingsObject, e);
     }
 }
Exemple #3
0
 private void buttonSave_Click(object sender, EventArgs e)
 {
     if (_filePathUsers != null)
     {
         SettingsDocument doc = SettingsConverter.ConvertObjectToDocument(_settingsObject, _filePathUsers);
         doc.Save(_filePathUsers, SettingsFileOption.Encrypted);
         UpdateUsersSettings.SafeInvoke(this._settingsObject, e);
         Notify.PopUp("Configuration File Saved", "Updated settings have been saved to disk", "", "OK");
     }
 }
Exemple #4
0
        protected override void Commit()
        {
            /*XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
             * xmlOptions.SaveSyntheticDocumentElement=(new QName(CTSettings.type.Name.NamespaceURI, "settings"));
             * Dictionary<String, String> map = new Dictionary<String, String>();
             * map.Put("http://schemas.openxmlformats.org/wordprocessingml/2006/main", "w");
             * xmlOptions.SaveSuggestedPrefixes=(map);*/
            XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces(new[] {
                new XmlQualifiedName("w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main")
            });
            PackagePart      part = GetPackagePart();
            Stream           out1 = part.GetOutputStream();
            SettingsDocument sd   = new SettingsDocument(ctSettings);

            sd.Save(out1, namespaces);
            out1.Close();
        }
        /// <summary>
        /// Saves settings using settings document.
        /// </summary>
        protected virtual void OnSave()
        {
            if (SettingsDocument != null)
            {
                SettingsFileOption fileOption = SettingsFileOption.Default;

                string extension = Path.GetExtension(FilePath);
                if (String.Equals(extension, ".stpe", StringComparison.InvariantCultureIgnoreCase))
                {
                    fileOption = SettingsFileOption.Encrypted;
                }
                else if (String.Equals(extension, ".stpc", StringComparison.InvariantCultureIgnoreCase))
                {
                    fileOption = SettingsFileOption.Compressed;
                }

                SettingsDocument.Save(FilePath, fileOption);
            }
        }
Exemple #6
0
        protected internal override void Commit()
        {
            if (ctSettings == null)
            {
                throw new InvalidOperationException("Unable to write out settings that were never read in!");
            }

            /*XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
             * xmlOptions.SaveSyntheticDocumentElement=(new QName(CTSettings.type.Name.NamespaceURI, "settings"));
             * Dictionary<String, String> map = new Dictionary<String, String>();
             * map.Put("http://schemas.openxmlformats.org/wordprocessingml/2006/main", "w");
             * xmlOptions.SaveSuggestedPrefixes=(map);*/
            //XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces(new XmlQualifiedName[] {
            //    new XmlQualifiedName("w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main")});
            PackagePart part = GetPackagePart();

            using (Stream out1 = part.GetOutputStream())
            {
                SettingsDocument sd = new SettingsDocument(ctSettings);
                sd.Save(out1);
            }
        }
Exemple #7
0
        /// <summary>
        /// Initializes the specified configuration files.
        /// </summary>
        /// <param name="configFiles">The configuration files.</param>
        public virtual void Initialize(params string[] configFiles)
        {
            SetupLogging();

            Log.Info(this, "Starting {0} hardware configuration...", Name);

            List <SettingsNode> settingsDocs = new List <SettingsNode>();

            foreach (string file in configFiles)
            {
                if (!File.Exists(file))
                {
                    Log.Error(this, "Settings file '{0}' does not exist. Skipping devices and parts listed in file.", file);
                    continue;
                }

                SettingsDocument doc = new SettingsDocument(file);
                settingsDocs.Add(doc);
            }

            if (settingsDocs.Count == 0)
            {
                Log.Error(this, "No valid settings files. Generating a default settings file template...");

                SettingsDocument simDoc = GenerateSettingsTemplate();
                simDoc.Save(ConfigFilePath);

                settingsDocs.Add(simDoc);
            }

            Dictionary <IDevice, SettingsNode> devSettings = new Dictionary <IDevice, SettingsNode>();

            // Create devices
            foreach (SettingsNode doc in settingsDocs)
            {
                IList <SettingsNode> devSettingNodes;
                IList <IDevice>      devices = _devMgr.FindOrCreateDevices(doc, out devSettingNodes);

                IList <TDevice> myDevices = devices.Where(d => d is TDevice)
                                            .Select(d => (TDevice)d)
                                            .ToList();

                _devices.AddRange(myDevices);

                for (int i = 0; i < devices.Count; i++)
                {
                    devSettings.Add(devices[i], devSettingNodes[i]);
                }
            }

            // Connect to all devices
            foreach (TDevice device in _devices)
            {
                try
                {
                    if (!device.Connected)
                    {
                        device.Open();
                    }
                }
                catch (Exception ex)
                {
                    Log.Error(this, "Unable to open a connect to {0} device '{1}' on port {2}. {3}", device.GetType().Name, device.Name, device.Port, ex);
                }
            }

            // Configure all devices
            foreach (KeyValuePair <IDevice, SettingsNode> kvp in devSettings)
            {
                if (!(kvp.Key is TDevice))
                {
                    continue;
                }

                TDevice myDevice = (TDevice)kvp.Key;

                try
                {
                    myDevice.Configure(kvp.Value);
                }
                catch (Exception ex)
                {
                    Log.Error(this, "Unable to configure {0} device '{1}' from . {2}", myDevice.GetType().Name, myDevice.Name, ex);
                }
            }

            // Create parts
            List <string> forcedParts = new List <string>();

            foreach (SettingsNode partsDoc in settingsDocs)
            {
                IList <TPart>  parts;
                IList <string> forced = CreateParts(partsDoc, out parts);

                // This handles the old initialization files

                if (parts.Count == 0)
                {
                    string partsDocName   = Path.GetFileName(partsDoc.Name);
                    string configFileName = Path.GetFileName(ConfigFilePath);

                    if (String.Equals(partsDocName, configFileName, StringComparison.CurrentCultureIgnoreCase))
                    {
                        forced = TrySpecificInit(partsDoc, out parts);
                    }
                }

                _parts.AddRange(parts);
                forcedParts.AddRange(forced);
            }

            Log.Info(this, "{0} parts defined as follows:", Name);

            List <IDevice> partDevices = new List <IDevice>();

            foreach (TPart part in _parts)
            {
                Log.Info(this, "{0}: {1} @ {2}", part.Name, part.Device.Name, part.Device.Port);

                if (!partDevices.Contains(part.Device))
                {
                    partDevices.Add(part.Device);
                }
            }

            RegisterParts(_parts);

            foreach (IDevice device in partDevices)
            {
                if (!_devices.Contains(device.Name))
                {
                    _devices.Add((TDevice)device);
                }

                try
                {
                    device.Initialize();
                }
                catch (Exception ex)
                {
                    Log.Error(this, "Failed to initialize {0} device. {1}", device.Name, ex.Message);
                }
            }

            if (forcedParts.Count > 0)
            {
                string message = String.Format("The following parts were forced into simulation mode:{0}{1}{0}Please see the log for more details.",
                                               Environment.NewLine,
                                               String.Join(Environment.NewLine, forcedParts));

                Notify.PopUpError(Name + " Forcing Simulation...", message);
            }

            Log.Info(this, "Completed {0} hardware configuration", Name);
        }
Exemple #8
0
 public static void SaveSettings()
 {
     SettingsDocument.Save(File.Create("settings"));
 }