Пример #1
0
 /// <summary>
 /// serialisation constructor
 /// </summary>
 /// <param name="info"></param>
 /// <param name="ctxt"></param>
 public PConfigContent(SerializationInfo info, StreamingContext ctxt)
 {
     this.Name        = this.getDeCryptStringContent("Name", info);
     this.FlatContent = this.getDeCryptStringContent("FlatContent", info);
     this.Content     = (List <PConfigContent>)info.GetValue("Childs", typeof(List <PConfigContent>));
     this.parentNode  = (PConfigContent)info.GetValue("parent", typeof(PConfigContent));
 }
Пример #2
0
        public bool importFromXml(string filename)
        {
            StorageXmlLoader xmlLoader = new StorageXmlLoader();

            if (xmlLoader.load(filename))
            {
                PConfigContent loadedConfig = xmlLoader.tryToReadConfig();
                if (loadedConfig != null)
                {
                    // a couple of checks
                    if (loadedConfig.getName() == "Unamed")
                    {
                        return(false);
                    }

                    if (loadedConfig.getChildByName(PConfig.KEY_MAIN) == null)
                    {
                        return(false);
                    }

                    PConfig.Configuration = loadedConfig;
                    return(true);
                }
            }
            return(false);
        }
Пример #3
0
        /// <summary>
        /// save Config Object Binary serialized
        /// </summary>
        /// <param name="filename"></param>
        /// <param name="objectToSerialize"></param>
        public void SerializeObject(string filename, PConfigContent objectToSerialize)
        {
            Stream          stream     = File.Open(filename, FileMode.Create);
            BinaryFormatter bFormatter = new BinaryFormatter();

            bFormatter.Serialize(stream, objectToSerialize);
            stream.Close();
        }
Пример #4
0
        /// <summary>
        /// gets the group by name or add en empty group
        /// if not exists
        /// </summary>
        /// <param name="Name"></param>
        /// <returns>the existing or new created Group</returns>
        public PConfigContent addOrGetGroupChild(String Name)
        {
            PConfigContent addConfig = this.getChildByName(Name);

            if (addConfig == null)
            {
                return(this.addGroupChild(Name));
            }
            return(addConfig);
        }
Пример #5
0
        /// <summary>
        /// Updates an existing child just
        /// with an string value
        /// </summary>
        /// <param name="childName">the name of the existing child</param>
        /// <param name="value">the value as string</param>
        /// <returns>if false if the child not exists</returns>
        public Boolean UpdateFlatChild(string childName, string value)
        {
            PConfigContent content = this.getChildByName(childName);

            if (content != null)
            {
                content.Update(value);
                return(true);
            }
            return(false);
        }
Пример #6
0
        /// <summary>
        /// loads last stored runtime configuration
        /// from the default location, or initialize
        /// a new clear config, if file not exists
        /// </summary>
        public void loadRuntimeConfig()
        {
            if (System.IO.File.Exists(this.getDefaultFilename()))
            {
                PConfig.Configuration = fileHandle.DeSerializeObject(this.getDefaultFilename());
            }

            if (PConfig.Configuration == null)
            {
                this.initBaseConfig();
            }
            this.resetReader();
        }
Пример #7
0
        public void RemoveChild(string name, string childName, Boolean resetReader)
        {
            if (resetReader)
            {
                this.resetReader();
            }

            // add this node if not exists
            if (this.WalkingLive.getName() == name)
            {
                this.WalkingLive.RemoveChild(childName);
                return;
            }

            string[] keyChain  = name.Split('.');
            string   parentKey = keyChain[0];

            if (keyChain.Count() > 1)
            {
                if (parentKey == this.WalkingLive.getName())
                {
                    string nextStepKey = keyChain[1];
                    this.WalkingLive = this.WalkingLive.addOrGetGroupChild(nextStepKey);

                    string nextKey = "";

                    string add = "";
                    for (int i = 1; i < keyChain.Count(); i++)
                    {
                        nextKey += add + keyChain[i];
                        add      = ".";
                    }
                    this.RemoveChild(nextKey, childName, false);
                }
                else
                {
                    throw new Exception("There is no Setting named " + name);
                }
            }
            else
            {
                if (this.WalkingLive.getName() == name)
                {
                    this.WalkingLive.RemoveChild(childName);
                }
                else
                {
                    throw new Exception("There is no Setting named " + name);
                }
            }
        }
Пример #8
0
        public List <String> getListWidthDefault(string name, List <String> StoreValue, Boolean resetReader)
        {
            if (resetReader)
            {
                this.resetReader();
            }

            string[] keyChain  = name.Split('.');
            string   parentKey = keyChain[0];

            if (keyChain.Count() > 1)
            {
                if (parentKey == this.WalkingLive.getName())
                {
                    string nextStepKey = keyChain[1];
                    this.WalkingLive = this.WalkingLive.addOrGetGroupChild(nextStepKey);

                    string nextKey = "";
                    string add     = "";
                    for (int i = 1; i < keyChain.Count(); i++)
                    {
                        nextKey += add + keyChain[i];
                        add      = ".";
                    }
                    return(this.getListWidthDefault(nextKey, StoreValue, false));
                }
                else
                {
                    throw new Exception("There is no Setting named " + name);
                }
            }
            else
            {
                if (this.WalkingLive.getName() == name)
                {
                    List <string> upd = this.WalkingLive.getContentAsList();
                    if (upd == null || upd.Count() == 0)
                    {
                        this.WalkingLive.Update(StoreValue);
                        return(StoreValue);
                    }
                    return(upd);
                }
                else
                {
                    throw new Exception("There is no Setting named " + name);
                }
            }
        }
Пример #9
0
 /// <summary>
 /// adds an empty child group if this group not already exists.
 /// </summary>
 /// <param name="Name">the name of the childgroup</param>
 /// <returns>returns null if the group already exists</returns>
 public PConfigContent addGroupChild(String Name)
 {
     if (this.Content == null)
     {
         this.Content = new List <PConfigContent>();
     }
     if (this.getChildByName(Name) == null)
     {
         PConfigContent addConfig = new PConfigContent();
         addConfig.SetFlatConfig(Name, null);
         this.Content.Add(addConfig);
         return(addConfig);
     }
     return(null);
 }
Пример #10
0
        /// <summary>
        /// Loads binary file as config if exists
        ///
        /// </summary>
        /// <param name="filename">name of file that should be loaded</param>
        /// <returns>false if flie not exists</returns>
        public Boolean loadConfigFromFile(string filename)
        {
            if (System.IO.File.Exists(filename))
            {
                PConfig.Configuration = fileHandle.DeSerializeObject(filename);
                if (PConfig.Configuration == null)
                {
                    this.initBaseConfig();
                }
                this.resetReader();
                return(true);
            }

            return(false);
        }
Пример #11
0
 public void resetReader()
 {
     this.WalkingLive = PConfig.Configuration;
 }
Пример #12
0
 /// <summary>
 /// initialize basic configuration  objects
 /// </summary>
 private void initBaseConfig()
 {
     PConfig.Configuration = new PConfigContent();
     PConfig.Configuration.SetFlatConfig(this.NameSpace, null);
 }