Ejemplo n.º 1
0
        /// <summary>
        /// Initializes the environment variables for the current user of
        /// the local machine.
        /// </summary>
        /// <param name="target">
        /// One of the <see cref="System.EnvironmentVariableTarget" /> values.
        /// </param>
        private void InitializeVariables(EnvironmentVariableTarget target)
        {
            Variable.VariableType type;

            switch (target)
            {
                case EnvironmentVariableTarget.Machine:
                    type = Variable.VariableType.System;
                    break;
                case EnvironmentVariableTarget.User:
                    type = Variable.VariableType.User;
                    break;
                default:
                    throw new ArgumentException("Invalid environment variable target", "target");
            }

            IDictionary<string, string> variables = Proxy.GetEnvironmentVariables(target);

            foreach (string name in variables.Keys)
            {
                Variable variable = new Variable();
                variable.Name = name;
                variable.State = true;
                variable.Type = type;

                foreach (string content in variables[name].Split(';'))
                {
                    Value value = new Value();
                    value.Content = content;
                    value.State = true;

                    variable.Values.Add(value);
                }

                Manager.Variables.Add(variable);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Generates an object from its XML representation.
        /// </summary>
        /// <param name="reader">
        /// The <see cref="System.Xml.XmlReader" /> stream from which the object is
        /// deserialized.
        /// </param>
        public void ReadXml(XmlReader reader)
        {
            if (!reader.IsStartElement("Manager"))
            {
                throw new XmlException("Expected <Manager> element");
            }

            bool isEmptyElement = reader.IsEmptyElement;
            reader.ReadStartElement("Manager");

            if (!isEmptyElement)
            {
                if (!reader.IsStartElement("Variables"))
                {
                    throw new XmlException("Expected <Variables> subelement in <Manager> element");
                }

                isEmptyElement = reader.IsEmptyElement;
                reader.ReadStartElement("Variables");

                if (!isEmptyElement)
                {
                    while (reader.IsStartElement("Variable"))
                    {
                        Variable variable = new Variable();
                        variable.ReadXml(reader);
                        this.Variables.Add(variable);
                    }

                    reader.ReadEndElement(); // Variables
                }

                reader.ReadEndElement(); // Manager
            }
        }