void IPgConnectionStash.PersistConnections(IConfigurationItem node, eConfigurationSource configurationSource)
        {
            foreach (IPgConnection dbCon in _DbSettings.Values)
            {
                if (dbCon.Persist)
                {
                    log.Debug("Persist database connection: " + dbCon.ToString());

                    IConfigurationItem item = new IConfigurationItemImpl("item" + Convert.ToString(node.ConfigurationItems.Count + 1), "", configurationSource);
                    node.AddConfigurationItem(item);

                    item.AddConfigurationItem(new IConfigurationItemImpl("name", dbCon.Name, configurationSource));
                    item.AddConfigurationItem(new IConfigurationItemImpl("server", dbCon.Server, configurationSource));
                    item.AddConfigurationItem(new IConfigurationItemImpl("port", dbCon.Port, configurationSource));
                    item.AddConfigurationItem(new IConfigurationItemImpl("database", dbCon.Database, configurationSource));
                    item.AddConfigurationItem(new IConfigurationItemImpl("user", dbCon.User, configurationSource));

                    IConfigurationItem keyIt = new IConfigurationItemImpl("password", "", configurationSource);
                    keyIt.StorageKey    = "system";
                    keyIt.Configuration = node.Configuration;
                    keyIt.SetValue(dbCon.Password);
                    item.AddConfigurationItem(keyIt);
                }
            }
        }
示例#2
0
        string IConfigurationSource.GetURIPath(eConfigurationSource source)
        {
            string result = "";

            switch (source)
            {
            case eConfigurationSource.AppConfig:
                result = Application.ExecutablePath;
                result = result.Substring(0, result.LastIndexOf(Path.DirectorySeparatorChar) + 1);
                break;

            case eConfigurationSource.UserAppData:
                result = GetURIPath(Environment.SpecialFolder.LocalApplicationData);
                break;

            case eConfigurationSource.AllUsersAppData:
                result = GetURIPath(Environment.SpecialFolder.CommonApplicationData);
                break;

            case eConfigurationSource.User:
                result = GetURIPath(Environment.SpecialFolder.UserProfile);
                break;
            }
            return(result);
        }
示例#3
0
        public IConfigurationItemImpl(string name, string newValue,
                                      eConfigurationSource target)
        {
            _Name         = name;
            InternalValue = newValue;
            _Target       = target;

            _Source = eConfigurationSource.Construction;
        }
示例#4
0
        public static IConfigurationItem FromXml(XmlNode Node, eConfigurationSource target)
        {
            IConfigurationItem result = new IConfigurationItemImpl("", Node.InnerText, target);

            result.StorageKey = Node.Attributes[tag_key_attribute] != null ? Node.Attributes[tag_key_attribute].InnerText : "";
            result.Type       = Node.Attributes[tag_type_attribute] != null ? Node.Attributes[tag_type_attribute].InnerText : "";

            return(result);
        }
示例#5
0
 public IConfigurationItemImpl(string name, string newValue,
                               eConfigurationSource target,
                               eConfigurationSource sourceAllowed = eConfigurationSource.AllAllowed)
 {
     _Name          = name;
     InternalValue  = newValue;
     _Target        = target;
     _Source        = eConfigurationSource.Construction;
     _SourceAllowed = sourceAllowed;
 }
示例#6
0
        protected bool IsSourceAllowed(eConfigurationSource source)
        {
            bool result = false;

            if (_Source == eConfigurationSource.Undefined || Convert.ToInt16(source) <= Convert.ToInt16(_Source))
            {
                result = (_SourceAllowed & source) != eConfigurationSource.Undefined;
            }

            return(result);
        }
示例#7
0
        public IConfigurationSourceImpl(eConfigurationSource source)
        {
            _Source = source;

            switch (source)
            {
            case eConfigurationSource.AppConfig:
                _Name = "AppConfig";
                _URI  = Application.ExecutablePath + ".config";
                _ConfigurationSourceType = eConfigurationSourceTypes.AppConfig;
                _ReadOnly = true;
                break;

            case eConfigurationSource.UserAppData:
                _Name = "UserAppDataPath";
                _URI  = GetURIPath(Environment.SpecialFolder.ApplicationData) + "config.xml";

                _ConfigurationSourceType = eConfigurationSourceTypes.Xml;
                _ReadOnly = false;
                break;

            case eConfigurationSource.AllUsersAppData:
                _Name = "CommonAppDataPath";
                _URI  = GetURIPath(Environment.SpecialFolder.CommonApplicationData) + "config.xml";

                _ConfigurationSourceType = eConfigurationSourceTypes.Xml;
                _ReadOnly = false;
                break;

            case eConfigurationSource.User:
                _Name = "UserLocal";
                _URI  = GetURIPath(Environment.SpecialFolder.LocalApplicationData) + "config.xml";

                _ConfigurationSourceType = eConfigurationSourceTypes.Xml;
                _ReadOnly = false;
                break;
            }

            string folder = _URI.Substring(0, _URI.LastIndexOf(Path.DirectorySeparatorChar) + 1);

            ConfigurationRepository.IConfiguration.AddConfigurationItem(
                new IConfigurationItemImpl(
                    SourceMapping[_Source.ToString()],
                    folder,
                    eConfigurationSource.NonPersistent)
                );

            if (!Load(null))
            {
                _Configuration          = new XmlDocument();
                _Configuration.InnerXml = _OrgConfiguration;
            } //if (!Load())
        }
示例#8
0
        } //void IConfiguration.AddConfigurationSource( ...

        IConfigurationSource IConfiguration.GetConfigurationSource(eConfigurationSource source)
        {
            foreach (IConfigurationSource src in _ConfigurationSources)
            {
                if (src.Source == source)
                {
                    return(src);
                }
            }

            return(null);
        }
示例#9
0
        public IConfigurationSourceImpl(string name, eConfigurationSource source, string uri,
                                        eConfigurationSourceTypes sourceType = eConfigurationSourceTypes.Xml, bool readOnly = false)
        {
            _Name   = name;
            _Source = source;
            _URI    = uri;
            _ConfigurationSourceType = sourceType;
            _ReadOnly = readOnly;

            if (!Load(null))
            {
                _Configuration          = new XmlDocument();
                _Configuration.InnerXml = _OrgConfiguration;
            } //if (!Load())
        }     //public IConfigurationSourceImpl( ...
示例#10
0
        bool IConfigurationItem.SetValue(string newValue, eConfigurationSource source)
        {
            if (IsSourceAllowed(source))
            {
                if (source == eConfigurationSource.User && _OrgValue == "" && InternalValue != newValue)
                {
                    _OrgValue = InternalValue;
                }

                InternalValue = newValue;
                _Source       = source;

                return(true);
            } //if (_Source == eConfigurationSource.Undefined ...

            return(false);
        } //bool IConfigurationItem.SetValue(
示例#11
0
        } //bool IConfiguration.Save()

        bool IConfiguration.SaveTo(XmlDocument doc, eConfigurationSource target)
        {
            if (doc.InnerXml == "")
            {
                doc.InnerXml = "<?xml version=\"1.0\" encoding=\"utf-8\"?><configuration></configuration>";
            }

            foreach (IConfigurationItem item in _RootConfigurationItem.ConfigurationItems)
            {
                foreach (IConfigurationSource source in _ConfigurationSources)
                {
                    item.SaveTo(doc, target);
                }
            }

            return(true);
        } //bool IConfiguration.Save()
示例#12
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            IConfigurationItem size = conf.GetConfigurationItem(UI_Constants.ConfigurationFormSize);

            (size as IConfigurationItemObject <Size>).SetValue(this.Size);

            IConfigurationItem location = conf.GetConfigurationItem(UI_Constants.ConfigurationFormLocation);

            (location as IConfigurationItemObject <Point>).SetValue(this.Location);

            conf.SetConfigurationValue(UI_Constants.SakwaModelPath, tbxModelFolder.Text);
            conf.SetConfigurationValue(UI_Constants.SakwaTemplatePath, tbxTemplateFolder.Text);
            conf.SetConfigurationValue(UI_Constants.SakwaModelOnStart, chxOpenOnStart.Checked.ToString());

            conf.SetConfigurationValue(UI_Constants.FullHelpPath, tbxHelpFile.Text);

            modelGUIConfig.Save();

            IConfigurationItem stockMethods = conf.GetConfigurationItem(UI_Constants.StockMethods);

            if (stockMethods != null)
            {
                eConfigurationSource src = stockMethods.Source;
                stockMethods.Clear();
                stockMethods.Source = src;

                foreach (string mthd in lbMethods.Items)
                {
                    string name = string.Format("item-{0}", stockMethods.ConfigurationItems.Count + 1);
                    stockMethods.AddConfigurationItem(new IConfigurationItemImpl(name, mthd, UI_Constants.ConfigurationSource));
                }
            }

            string json = (tpgInferenceConfig.Controls[0] as ucPropertyEditor).PropertiesAsJson;

            conf.SetConfigurationValue(UI_Constants.GlobalConnectionProperties, json);

            conf.Save();
        }
示例#13
0
        } //bool IConfigurationItem.SetValue(

        bool IConfigurationItem.SetValue(XmlNode newValue, eConfigurationSource source)
        {
            if (newValue != null && IsSourceAllowed(source))
            {
                if (newValue.Attributes[tag_definition_attribute] != null)
                {
                    _ConfigurationItemValueType = (eConfigurationItemValueType)Enum.Parse(typeof(eConfigurationItemValueType), newValue.Attributes[tag_definition_attribute].InnerText, true);

                    bool result = false;

                    switch (_ConfigurationItemValueType)
                    {
                    case eConfigurationItemValueType.plain:
                        if (newValue.ChildNodes.Count >= 1 && newValue.ChildNodes[0].GetType() == typeof(XmlElement))
                        {
                            (this as IConfigurationItem).Clear();
                            foreach (XmlNode node in newValue)
                            {
                                IConfigurationItem item = new IConfigurationItemImpl(node.Name);
                                if (node.Attributes[tag_key_attribute] != null)
                                {
                                    item.StorageKey = node.Attributes[tag_key_attribute].InnerText;
                                }

                                item.SetValue(node, source);
                                item.Source = source;
                                item.Target = _Target;

                                _Source = source;
                                _ConfigurationItems.Add(item);
                            } //foreach (XmlNode node in newValue)
                        }     //if (newValue.ChildNodes.Count > 1)
                        else
                        {
                            _Value = GetNodeValue(newValue);
                        }

                        result = true;

                        break;

                    case eConfigurationItemValueType.xml:
                        _Value = GetNodeValue(newValue);

                        result = true;
                        break;

                    case eConfigurationItemValueType.list:
                        (this as IConfigurationItem).Clear();
                        foreach (XmlNode node in newValue)
                        {
                            IConfigurationItem item = new IConfigurationItemImpl("item" + Convert.ToString(_ConfigurationItems.Count + 1));
                            item.SetValue(node, source);
                            item.Source = source;
                            item.Target = _Target;

                            _Source = source;
                            _ConfigurationItems.Add(item);
                        }     //foreach (XmlNode node in newValue)

                        result = true;

                        break;
                    } //switch (_ConfigurationItemValueType)

                    return(result);
                } //if (newValue.Attributes[tag_definition_attribute] != null)

                switch (newValue.ChildNodes.Count)
                {
                case 0:
                case 1:
                    if (_IsCollection)
                    {
                        (this as IConfigurationItem).Clear();
                        foreach (XmlNode node in newValue)
                        {
                            IConfigurationItem item = new IConfigurationItemImpl(node.Name);
                            item.SetValue(node, source);
                            _Source = source;
                            _ConfigurationItems.Add(item);
                        } //foreach (XmlNode node in newValue)
                    }     //if (_IsCollection)
                    else
                    {
                        InternalValue = GetNodeValue(newValue);
                    }

                    break;

                default:
                    (this as IConfigurationItem).Clear();
                    foreach (XmlNode node in newValue)
                    {
                        IConfigurationItem item = new IConfigurationItemImpl(node.Name);
                        item.SetValue(node, source);
                        _ConfigurationItems.Add(item);
                    }     //foreach (XmlNode node in newValue)

                    break;
                } //switch(newValue.ChildNodes.Count)

                _Source = source;

                return(true);
            } //if (newValue != null && (_Source ...

            return(false);
        } //bool IConfigurationItem.SetValue(
示例#14
0
        } //string IConfigurationItem.ToString( ...

        /*
         * public enum eConfigurationSource {
         * Undefined, User = 1,
         * CmdLine = 2,
         * UserAppData = 4,
         * AllUsersAppData = 8,
         * UserServerSide = 16,
         * GroupServerSide = 32,
         * ServerSide = 64,
         * AppConfig = 128,
         * NonPersistent = 256,
         * AllAllowed = 1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 + 256,
         * Construction = 512}
         *
         * */
        private string eCSToString(eConfigurationSource source)
        {
            string result = "";

            //if ((source & eConfigurationSource.AllAllowed) == eConfigurationSource.AllAllowed)
            //    return "AllAllowed";

            if (source == eConfigurationSource.Undefined)
            {
                return("Undefined");
            }

            if ((source & eConfigurationSource.User) == eConfigurationSource.User)
            {
                result += result != "" ? ", User" : "User";
            }

            if ((source & eConfigurationSource.CmdLine) == eConfigurationSource.CmdLine)
            {
                result += result != "" ? ", CmdLine" : "CmdLine";
            }

            if ((source & eConfigurationSource.AllUsersAppData) == eConfigurationSource.AllUsersAppData)
            {
                result += result != "" ? ", AllUsersAppData" : "AllUsersAppData";
            }

            if ((source & eConfigurationSource.UserAppData) == eConfigurationSource.UserAppData)
            {
                result += result != "" ? ", UserAppData" : "UserAppData";
            }

            if ((source & eConfigurationSource.ServerSide) == eConfigurationSource.ServerSide)
            {
                result += result != "" ? ", ServerSide" : "ServerSide";
            }

            if ((source & eConfigurationSource.UserServerSide) == eConfigurationSource.UserServerSide)
            {
                result += result != "" ? ", UserServerSide" : "UserServerSide";
            }

            if ((source & eConfigurationSource.GroupServerSide) == eConfigurationSource.GroupServerSide)
            {
                result += result != "" ? ", GroupServerSide" : "GroupServerSide";
            }

            if ((source & eConfigurationSource.AppConfig) == eConfigurationSource.AppConfig)
            {
                result += result != "" ? ", AppConfig" : "AppConfig";
            }

            if ((source & eConfigurationSource.NonPersistent) == eConfigurationSource.NonPersistent)
            {
                result += result != "" ? ", NonPersistent" : "NonPersistent";
            }

            if ((source & eConfigurationSource.Construction) == eConfigurationSource.Construction)
            {
                result += result != "" ? ", Construction" : "Construction";
            }

            return(result);
        } //private string eCSToString(eConfigurationSource source)
示例#15
0
        } //string IConfigurationItem.ToString()

        string IConfigurationItem.ToString(eConfigurationSource SourecOrTarget)
        {
            return(eCSToString(SourecOrTarget));
        } //string IConfigurationItem.ToString( ...
 public ConfigurationItemObject(string name, T newValue, eConfigurationSource target)
     : base(name, StreamPersist(newValue), target)
 {
     _Type = typeof(T).Name;
 }
 public ConfigurationItemObject(string name, T newValue, eConfigurationSource target,
                                eConfigurationSource sourceAllowed = eConfigurationSource.AllAllowed)
     : base(name, StreamPersist(newValue), target, sourceAllowed)
 {
     _Type = typeof(T).Name;
 }
示例#18
0
        } //bool IConfigurationItem.SaveToTarget( ...

        bool IConfigurationItem.SaveTo(XmlDocument doc, eConfigurationSource target)
        {
            bool result = false;

            if (doc != null && (this as IConfigurationItem).SaveToTarget(target))
            {
                if (doc.InnerXml == "")
                {
                    doc.InnerXml = "<?xml version=\"1.0\" encoding=\"utf-8\"?><configuration></configuration>";
                }

                #region ServerSide, CommonAppData and UserAppData
                if ((target &
                     (eConfigurationSource.ServerSide |
                      eConfigurationSource.GroupServerSide |
                      eConfigurationSource.UserServerSide |
                      eConfigurationSource.AllUsersAppData |
                      eConfigurationSource.UserAppData)) != eConfigurationSource.Undefined)
                {
                    XmlNode Node = doc.DocumentElement[_Name];
                    if (Node == null)
                    {
                        Node = GetXmlNode(doc, Node);
                        doc.DocumentElement.AppendChild(Node);
                    } //if (Node == null)
                    else
                    {
                        Node.RemoveAll();
                        Node = GetXmlNode(doc, Node); //Update the definition attribute
                    } //else, if (Node == null)

                    switch (_ConfigurationItemValueType)
                    {
                    case eConfigurationItemValueType.plain:
                        if (_ConfigurationItems.Count > 0)
                        {
                            foreach (IConfigurationItem item in _ConfigurationItems)
                            {
                                AddSubNode(item, Node);
                            } //foreach(IConfigurationItem item in _ConfigurationItems)
                        }     //if(_ConfigurationItems.Count > 0)
                        else
                        {
                            Node.InnerText = _Value;
                        }

                        break;

                    case eConfigurationItemValueType.xml:
                        Node.InnerText = _Value;
                        break;

                    case eConfigurationItemValueType.list:
                        foreach (IConfigurationItem item in _ConfigurationItems)
                        {
                            AddSubNode(item, Node);
                            //XmlNode childNode = item.GetXmlNode(doc);
                            //Node.AppendChild(childNode);
                            //childNode.InnerText = item.Value;
                        }     //foreach(IConfigurationItem item in _ConfigurationItems)
                        break;
                    }

                    //if (_ConfigurationItems.Count > 0)
                    //{
                    //    foreach (IConfigurationItem item in _ConfigurationItems)
                    //    {
                    //        XmlNode childNode = item.GetXmlNode(doc);
                    //        Node.AppendChild(childNode);
                    //        childNode.InnerText = item.Value;

                    //    } //foreach(IConfigurationItem item in _ConfigurationItems)
                    //} //if(_ConfigurationItems.Count > 0)
                    //else
                    //    Node.InnerText = InternalValue;

                    result = true;
                } //if((target & ...
                #endregion
                else
                #region app.config
                if ((target & eConfigurationSource.AppConfig) != eConfigurationSource.Undefined)
                {
                    XmlNode root = doc.DocumentElement[tag_appSettings];
                    if (root == null)
                    {
                        root = doc.CreateNode(XmlNodeType.Element, tag_appSettings, "");
                        doc.DocumentElement.AppendChild(root);
                    }
                    XmlNode Node = null;
                    foreach (XmlNode node in root)
                    {
                        if (node.Attributes[tag_key] != null && node.Attributes[tag_key].InnerText == _Name)
                        {
                            Node = node;
                            break;
                        }     //if (node.Attributes["key"] != null && node.Attributes["key"].InnerText = _Name)
                    }
                    if (Node == null)
                    {
                        Node = doc.CreateNode(XmlNodeType.Element, tag_addNode, "");
                        Node.Attributes.Append(doc.CreateAttribute(tag_key));
                        Node.Attributes.Append(doc.CreateAttribute(tag_value));
                        Node.Attributes[tag_key].InnerText = _Name;

                        root.AppendChild(Node);
                    }     //if (Node == null)

                    Node.Attributes[tag_value].InnerText = _Value;
                }     //if ((target & eConfigurationSource.AppConfig) != eConfigurationSource.Undefined)
                #endregion
            } //if (doc != null && (this as IConfigurationItem).SaveToTarget(target))

            return(result);
        } //bool IConfigurationItem.SaveTo( ...
示例#19
0
        } //bool IConfigurationItem.SetValue(

        bool IConfigurationItem.SaveToTarget(eConfigurationSource target)
        {
            return(_Source != eConfigurationSource.Undefined || _IsCollection
                ? (_Target & target) != eConfigurationSource.Undefined
                : false);
        } //bool IConfigurationItem.SaveToTarget( ...