示例#1
0
    public UDefaultValue GetDefaultValue(string strField)
    {
        TConfigSection       tConfigSection = new TConfigSection();
        ConfigurationElement configElement  = tConfigSection as ConfigurationElement;

        if (configElement == null)
        {
            // not a config section
            System.Diagnostics.Debug.Assert(false);
            return(default(UDefaultValue));
        }
        ElementInformation elementInfo = configElement.ElementInformation;
        var varTest = elementInfo.Properties;

        foreach (var item in varTest)
        {
            PropertyInformation propertyInformation = item as PropertyInformation;
            if (propertyInformation == null || propertyInformation.Name != strField)
            {
                continue;
            }
            try
            {
                UDefaultValue defaultValue = (UDefaultValue)propertyInformation.DefaultValue;
                return(defaultValue);
            }
            catch (Exception ex)
            {
                // default value of the wrong type
                System.Diagnostics.Debug.Assert(false);
                return(default(UDefaultValue));
            }
        }
        return(default(UDefaultValue));
    }
示例#2
0
        static void ValidateProperty(SettingsProperty settingsProperty, ElementInformation elementInfo)
        {
            string exceptionMessage = string.Empty;

            if (!AnonymousIdentificationModule.Enabled &&
                (bool)settingsProperty.Attributes ["AllowAnonymous"])
            {
                exceptionMessage = "Profile property '{0}' allows anonymous users to store data. " +
                                   "This requires that the AnonymousIdentification feature be enabled.";
            }

            if (settingsProperty.PropertyType == null)
            {
                exceptionMessage = "The type specified for a profile property '{0}' could not be found.";
            }

            if (settingsProperty.SerializeAs == SettingsSerializeAs.Binary &&
                !settingsProperty.PropertyType.IsSerializable)
            {
                exceptionMessage = "The type for the property '{0}' cannot be serialized " +
                                   "using the binary serializer, since the type is not marked as serializable.";
            }

            if (exceptionMessage.Length > 0)
            {
                throw new ConfigurationErrorsException(string.Format(exceptionMessage, settingsProperty.Name),
                                                       elementInfo.Source, elementInfo.LineNumber);
            }
        }
示例#3
0
 public void LogWarning(string message, ElementInformation info)
 {
     #if !NET_3_5
     _buildEngine.LogWarningEvent(new BuildWarningEventArgs("Semiodesk.Trinity", "", info.Source, info.LineNumber, 0, info.LineNumber, 0, message, "Semiodesk", "OntologyGenerator", DateTime.Now));
     #else
     _buildEngine.LogWarningEvent(new BuildWarningEventArgs("Semiodesk.Trinity", "", info.Source, info.LineNumber, 0, info.LineNumber, 0, message, "Semiodesk", "OntologyGenerator"));
     #endif
 }
        public static ListenerElement Create(ElementInformation eI)
        {
            string name           = eI.Properties["name"].Value as string;
            string type           = eI.Properties["type"].Value as string;
            string initializeData = eI.Properties["initializeData"].Value as string;

            return(new ListenerElement(name, type, initializeData));
        }
示例#5
0
        public void ElementInformation_validator()
        {
            /* pick a Configuration class that doesn't
             * specify an ElementInformation override */
            DefaultSection     sect = new DefaultSection();
            ElementInformation info = sect.ElementInformation;

            Assert.AreEqual(typeof(DefaultValidator), info.Validator.GetType(), "A1");
        }
示例#6
0
        public int Run()
        {
            if (_settings == null)
            {
                throw new Exception("Trinity config file (app.config or web.config) not initialized.");
            }

            _sourceDir = new FileInfo(_configPath).Directory;

            if (!string.IsNullOrEmpty(_generatePath))
            {
                FileInfo fileInfo = new FileInfo(_generatePath);

                using (OntologyGenerator generator = new OntologyGenerator(_settings.Namespace))
                {
                    generator.Logger = Logger;

                    if (_settings.Ontologies != null)
                    {
                        foreach (var ontology in _settings.Ontologies)
                        {
                            UriRef t = GetPathFromSource(ontology.FileSource);

                            if (!generator.ImportOntology(ontology.Uri, t))
                            {
                                FileInfo ontologyFile = new FileInfo(t.LocalPath);

                                ElementInformation info = ontology.ElementInformation;

                                Logger.LogWarning(string.Format("Could not read ontology <{0}> from path {1}.", ontology.Uri, ontologyFile.FullName), info);
                            }

                            if (!generator.AddOntology(ontology.Uri, ontology.MetadataUri, ontology.Prefix))
                            {
                                Logger.LogMessage("Ontology with uri <{0}> or uri <{1}> could not be found in store.", ontology.Uri, ontology.MetadataUri);
                            }
                        }

                        generator.GenerateFile(fileInfo);
                    }
                    else
                    {
                        Logger.LogMessage("No ontologies configured in TrinitySettings section in app.config or web.config.");
                    }
                }

                return(0);
            }
            else
            {
                return(-1);
            }
        }
示例#7
0
        private static IList <ListenerPrefix> LoadListenerPrefixSettings()
        {
            string setting = System.Configuration.ConfigurationManager.AppSettings[_ListenerPrefixesAppSettingsKey];

            if (string.IsNullOrWhiteSpace(setting))
            {
                setting = _DefaultListenerPrefix;
            }

            string[] urls = setting.Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries);

            if (urls.Length == 0)
            {
                ElementInformation listenerPrefixesElement = GetAppSettingElementInformation(_ListenerPrefixesAppSettingsKey);
                throw new ConfigurationErrorsException("The specified listener prefix setting contains invalid data.", listenerPrefixesElement.Source, listenerPrefixesElement.LineNumber);
            }

            var listenerPrefixesList = new List <ListenerPrefix>();

            foreach (string url in urls)
            {
                ListenerPrefix prefix = null;

                if (ListenerPrefix.TryCreate(url.Trim(), out prefix))
                {
                    if (!prefix.Scheme.Equals(Uri.UriSchemeHttp) && !prefix.Scheme.Equals(Uri.UriSchemeHttps))
                    {
                        ElementInformation listenerPrefixesElement = GetAppSettingElementInformation(_ListenerPrefixesAppSettingsKey);
                        throw new ConfigurationErrorsException(string.Format("The specified listener prefix, '{0}', must start with either {1} or {2}.", url.Trim(), Uri.UriSchemeHttp, Uri.UriSchemeHttps),
                                                               listenerPrefixesElement.Source,
                                                               listenerPrefixesElement.LineNumber);
                    }

                    listenerPrefixesList.Add(prefix);
                }
                else
                {
                    ElementInformation listenerPrefixesElement = GetAppSettingElementInformation(_ListenerPrefixesAppSettingsKey);
                    throw new ConfigurationErrorsException(string.Format("The specified listener prefix, '{0}', is not valid.", url.Trim()),
                                                           listenerPrefixesElement.Source,
                                                           listenerPrefixesElement.LineNumber);
                }
            }

            return(listenerPrefixesList);
        }
        public void RemoveAt(int index)
        {
            ConfigurationElement elem = BaseGet(index);

            if (elem != null)
            {
                ElementInformation elemInfo = elem.ElementInformation;
                if (elemInfo.IsPresent)
                {
                    BaseRemoveAt(index);
                }
                else
                {
                    throw new ConfigurationErrorsException(SR.GetString(SR.Config_base_cannot_remove_inherited_items));
                }
            }
        }
示例#9
0
        private static IList <TimeSpan> LoadRetryIntervalSettings()
        {
            string setting = System.Configuration.ConfigurationManager.AppSettings[_RetryIntervalsAppSettingsKey];

            if (string.IsNullOrWhiteSpace(setting))
            {
                setting = _DefaultRetryIntervals;
            }

            string[] intervals = setting.Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries);

            if (intervals.Length == 0)
            {
                ElementInformation retryIntervalsElement = GetAppSettingElementInformation(_RetryIntervalsAppSettingsKey);
                throw new ConfigurationErrorsException("The specified retry intervals setting contains invalid data.", retryIntervalsElement.Source, retryIntervalsElement.LineNumber);
            }

            var retryIntervalsList = new List <TimeSpan>();

            foreach (string interval in intervals)
            {
                try
                {
                    TimeSpan retryInterval = XmlConvert.ToTimeSpan(interval.Trim());

                    if (retryInterval < TimeSpan.Zero)
                    {
                        ElementInformation retryIntervalsElement = GetAppSettingElementInformation(_RetryIntervalsAppSettingsKey);
                        throw new ConfigurationErrorsException("A specified retry interval cannot be negative.", retryIntervalsElement.Source, retryIntervalsElement.LineNumber);
                    }

                    retryIntervalsList.Add(retryInterval);
                }
                catch (FormatException fex)
                {
                    ElementInformation retryIntervalsElement = GetAppSettingElementInformation(_RetryIntervalsAppSettingsKey);
                    throw new ConfigurationErrorsException(string.Format("The specified retry interval, '{0}', is not a valid XML duration.", interval.Trim()),
                                                           fex,
                                                           retryIntervalsElement.Source,
                                                           retryIntervalsElement.LineNumber);
                }
            }

            return(retryIntervalsList);
        }
示例#10
0
        GetElementInformation()
        {
            // Get the current configuration file.
            System.Configuration.Configuration config =
                ConfigurationManager.OpenExeConfiguration(
                    ConfigurationUserLevel.None);

            // Get the section.
            UrlsSection section =
                (UrlsSection)config.GetSection("MyUrls");

            // Get the element.
            UrlConfigElement url = section.Simple;

            ElementInformation eInfo =
                url.ElementInformation;

            return(eInfo);
        }
        public void Clear()
        {
            int index = Count - 1;

            bModified = true;

            for (int i = index; i >= 0; i--)
            {
                ConfigurationElement elem = BaseGet(i);
                if (elem != null)
                {
                    ElementInformation elemInfo = elem.ElementInformation;
                    if (elemInfo.IsPresent)
                    {
                        BaseRemoveAt(i);
                    }
                }
            }
        }
示例#12
0
 private static bool ConfigurationElementHasKeyProperties(ElementInformation elementInformation)
 {
     return(elementInformation.Properties.Cast <PropertyInformation>().Any(x => x.IsKey));
 }
 public ConfigurationElement()
 {
     ElementInformation = new ElementInformation(isPresent: true);
 }
 public void SetLocation(ElementInformation location) => Location    = new ConfigurationLocation(location.Source, location.LineNumber);
        static void Main(string[] args)
        {
            try
            {
                // Set the path of the config file.
                string configPath = "";

                // Get the Web application configuration object.
                Configuration config =
                    WebConfigurationManager.OpenWebConfiguration(configPath);

                // Get the section related object.
                AnonymousIdentificationSection configSection =
                    (AnonymousIdentificationSection)config.GetSection
                        ("system.web/anonymousIdentification");

                // Display title.
                Console.WriteLine("Configuration PropertyInformation");
                Console.WriteLine("Section: anonymousIdentification");

                // Instantiate a new PropertyInformationCollection object.
                PropertyInformationCollection propCollection =
                    configSection.ElementInformation.Properties;

                // Display Collection Count.
                Console.WriteLine("Collection Count: {0}",
                                  propCollection.Count);

                // Display properties of elements
                // of the PropertyInformationCollection.
                foreach (PropertyInformation propertyItem in propCollection)
                {
                    Console.WriteLine();
                    Console.WriteLine("Property Details:");

                    // <Snippet8>
                    // Display the Name property.
                    Console.WriteLine("Name: {0}", propertyItem.Name);
                    // </Snippet8>

                    // <Snippet12>
                    // Display the Value property.
                    Console.WriteLine("Value: {0}", propertyItem.Value);
                    // </Snippet12>

                    // <Snippet2>
                    // Display the DefaultValue property.
                    Console.WriteLine("DefaultValue: {0}",
                                      propertyItem.DefaultValue);
                    // </Snippet2>

                    // <Snippet10>
                    // Display the Type property.
                    Console.WriteLine("Type: {0}", propertyItem.Type);
                    // </Snippet10>

                    // <Snippet3>
                    // Display the IsKey property.
                    Console.WriteLine("IsKey: {0}", propertyItem.IsKey);
                    // </Snippet3>

                    // <Snippet4>
                    // Display the IsLocked property.
                    Console.WriteLine("IsLocked: {0}", propertyItem.IsLocked);
                    // </Snippet4>

                    // <Snippet5>
                    // Display the IsModified property.
                    Console.WriteLine("IsModified: {0}", propertyItem.IsModified);
                    // </Snippet5>

                    // <Snippet6>
                    // Display the IsRequired property.
                    Console.WriteLine("IsRequired: {0}", propertyItem.IsRequired);
                    // </Snippet6>

                    // <Snippet7>
                    // Display the LineNumber property.
                    Console.WriteLine("LineNumber: {0}", propertyItem.LineNumber);
                    // </Snippet7>

                    // <Snippet9>
                    // Display the Source property.
                    Console.WriteLine("Source: {0}", propertyItem.Source);
                    // </Snippet9>

                    // <Snippet11>
                    // Display the Validator property.
                    Console.WriteLine("Validator: {0}", propertyItem.Validator);
                    // </Snippet11>

                    // <Snippet13>
                    // Display the ValueOrigin property.
                    Console.WriteLine("ValueOrigin: {0}", propertyItem.ValueOrigin);
                    // </Snippet13>
                }

                Console.WriteLine("");
                Console.WriteLine("Configuration - Accessing an Attribute");
                // <Snippet14>
                // Create EllementInformation object.
                ElementInformation elementInfo =
                    configSection.ElementInformation;
                // Create a PropertyInformationCollection object.
                PropertyInformationCollection propertyInfoCollection =
                    elementInfo.Properties;
                // Create a PropertyInformation object.
                PropertyInformation myPropertyInfo =
                    propertyInfoCollection["enabled"];
                // Display the property value.
                Console.WriteLine
                    ("anonymousIdentification Section - Enabled: {0}",
                    myPropertyInfo.Value);
                // </Snippet14>
            }

            catch (Exception e)
            {
                // Error.
                Console.WriteLine(e.ToString());
            }

            // Display and wait.
            Console.ReadLine();
        }
示例#16
0
        /// <summary>
        ///  Initialize History Logger configuration from the web.config.
        /// </summary>
        /// <returns> if error return true else false </returns>
        private void Initialize()
        {
            _valid = false;
            _used = false;

            bool error = false;

            try
            {

				bool isLoadingFromWebApplication = AppDomain.CurrentDomain.GetData("DataDirectory") != null;

                if (ConfigurationManager.AppSettings[DATABASECONFIGPATH] != null)
                {
                    _used = true;
                    try
                    {
                        try
                        {
                            _dataBaseConfigPath = ConfigurationManager.AppSettings[DATABASECONFIGPATH];
                            _dataBaseConfigPath = _dataBaseConfigPath.Replace("|DataDirectory|", ServiceConfiguration.AppDataPath);

                            ReadDBConfigFile();
                        }
                        catch (Exception)
                        {
                            LogManager.WriteLog(TraceType.ERROR, PIS.Ground.Core.Properties.Resources.LogDataBaseConfigFile, "PIS.Ground.Core.LogMgmt.HistoryLoggerConfiguration.Initialize", null, EventIdEnum.GroundCore);
                            error = true;
                        }
                    }
                    catch
                    {
                        LogManager.WriteLog(TraceType.ERROR, PIS.Ground.Core.Properties.Resources.LogDataBaseConfigFile, "PIS.Ground.Core.LogMgmt.HistoryLoggerConfiguration.Initialize", null, EventIdEnum.GroundCore);
                        error = true;
                    }
                }

                if (ConfigurationManager.AppSettings[LOGBACKUPPATH] != null)
                {
                    try
                    {
                        try
                        {
                            _logBackupPath = ConfigurationManager.AppSettings[LOGBACKUPPATH];
                            _logBackupPath = _logBackupPath.Replace("|DataDirectory|", ServiceConfiguration.AppDataPath);
                        }
                        catch (Exception)
                        {
                            LogManager.WriteLog(TraceType.ERROR, "LogBackUpPath in web.config not valid", "PIS.Ground.Core.LogMgmt.HistoryLoggerConfiguration.Initialize", null, EventIdEnum.GroundCore);
                            error = true;
                        }
                    }
                    catch
                    {
                        LogManager.WriteLog(TraceType.ERROR, PIS.Ground.Core.Properties.Resources.LogDataBaseConfigFile, "PIS.Ground.Core.LogMgmt.HistoryLoggerConfiguration.Initialize", null, EventIdEnum.GroundCore);
                        error = true;
                    }
                }

                if (ConfigurationManager.AppSettings[CREATETABLESCRIPTPATH] != null)
                {
                    try
                    {
                        try
                        {
                            _createTableScriptPath = ConfigurationManager.AppSettings[CREATETABLESCRIPTPATH];
                            _createTableScriptPath = _createTableScriptPath.Replace("|DataDirectory|", ServiceConfiguration.AppDataPath);
                        }
                        catch (Exception)
                        {
                            LogManager.WriteLog(TraceType.ERROR, "CreateTableScript in web.config not valid", "PIS.Ground.Core.LogMgmt.HistoryLoggerConfiguration.Initialize", null, EventIdEnum.GroundCore);
                            error = true;
                        }
                    }
                    catch
                    {
                        LogManager.WriteLog(TraceType.ERROR, PIS.Ground.Core.Properties.Resources.LogDataBaseConfigFile, "PIS.Ground.Core.LogMgmt.HistoryLoggerConfiguration.Initialize", null, EventIdEnum.GroundCore);
                        error = true;
                    }
                }

                if (ConfigurationManager.ConnectionStrings[SQLCONNECTIONSTRING] != null)
                {
                    try
                    {
                        _connectionString = ConfigurationManager.ConnectionStrings[SQLCONNECTIONSTRING].ConnectionString;
                        SqlConnectionStringBuilder stringBuiilder = new SqlConnectionStringBuilder(ConfigurationManager.ConnectionStrings["SqlServerDataDirectory"].ConnectionString);
                        if (stringBuiilder != null && stringBuiilder.AttachDBFilename != null && stringBuiilder.AttachDBFilename.Contains("|DataDirectory|"))
                        {
                            string configConvertedPath = stringBuiilder.AttachDBFilename.Replace("|DataDirectory|", ServiceConfiguration.AppDataPath);
                            //if (File.Exists(configConvertedPath))
                            try
                            {
                                FileInfo file = new FileInfo(configConvertedPath);
                                stringBuiilder.AttachDBFilename = file.FullName;
                                _connectionString = stringBuiilder.ConnectionString;
                            }
                            catch
                            {
                            }
                        }
                    }
                    catch
                    {
                        LogManager.WriteLog(TraceType.ERROR, PIS.Ground.Core.Properties.Resources.LogSqlServerDataDirectoryError, "PIS.Ground.Core.LogMgmt.HistoryLoggerConfiguration.Initialize", null, EventIdEnum.GroundCore);
                        error = true;
                    }
                }

                if (ConfigurationManager.ConnectionStrings[SQLCREATEDBCONNECTIONSTRING] != null)
                {
                    try
                    {
                        _createDbConnectionString = ConfigurationManager.ConnectionStrings[SQLCREATEDBCONNECTIONSTRING].ConnectionString;

                    }
                    catch
                    {
                        LogManager.WriteLog(TraceType.ERROR, "Error in connection string " + SQLCREATEDBCONNECTIONSTRING, "PIS.Ground.Core.LogMgmt.HistoryLoggerConfiguration.Initialize", null, EventIdEnum.GroundCore);
                        error = true;
                    }
                }

                try
                {
					ServiceModelSectionGroup section;
					if (isLoadingFromWebApplication)
					{
						Configuration config = WebConfigurationManager.OpenWebConfiguration("~");
						section = config.GetSectionGroup("system.serviceModel") as ServiceModelSectionGroup;
					}
					else
					{
						section = ConfigurationManager.GetSection("system.serviceModel") as ServiceModelSectionGroup;
					}

					if (section != null)
					{
						CustomBindingElementCollection customBindingElements = section.Bindings.CustomBinding.Bindings;
						for (int customElements = 0; customElements < customBindingElements.Count; customElements++)
						{
							CustomBindingElement customBindingElement = customBindingElements[customElements];
							if (customBindingElement.Name == "MaintenanceBinding")
							{
								ElementInformation txtMessageEncodingElementInfo = customBindingElement.ElementInformation;
								TextMessageEncodingElement txtMessageEncodingElement = (TextMessageEncodingElement)txtMessageEncodingElementInfo.Properties["textMessageEncoding"].Value;
								ElementInformation readerQuotasElementInfo = txtMessageEncodingElement.ElementInformation;
								XmlDictionaryReaderQuotasElement readerQuotasElement = (XmlDictionaryReaderQuotasElement)readerQuotasElementInfo.Properties["readerQuotas"].Value;
								_maxStringContentLength = readerQuotasElement.MaxStringContentLength;
								break;
							}
						}
					}
                }
                catch
                {
                    LogManager.WriteLog(TraceType.ERROR, "Error in retrieving max String Content Length", "PIS.Ground.Core.LogMgmt.HistoryLoggerConfiguration.Initialize", null, EventIdEnum.GroundCore);
                    error = true;
                }

                if (!error)
                {
                    string message = "Initialize success:"
                        + " DataBaseConfigPath=" + DataBaseConfigPath
                        + " LogDataBaseStructureVersion=" + LogDataBaseStructureVersion
                        + " PercentageToCleanUpInLogDatabase=" + PercentageToCleanUpInLogDatabase
                        + " MaximumLogMessageSize=" + MaximumLogMessageSize
                        + " MaximumLogMessageCount=" + MaximumLogMessageCount
                        + " SqlConnectionString=" + SqlConnectionString
                        + " SqlCreateDbConnectionString=" + SqlCreateDbConnectionString
                        + " LogBackupPath=" + LogBackupPath
                        + " CreateTableScriptPath=" + CreateTableScriptPath;

                    LogManager.WriteLog(TraceType.INFO, message, "PIS.Ground.Core.LogMgmt.HistoryLoggerConfiguration.Initialize", null, EventIdEnum.GroundCore);
                }
            }
            catch
            {
                LogManager.WriteLog(TraceType.ERROR, "Error Initializing HistoryLoggerConfiguration", "PIS.Ground.Core.LogMgmt.HistoryLoggerConfiguration.Initialize", null, EventIdEnum.GroundCore);
            }
            
            _valid = !error;            
        }       
示例#17
0
 /// <summary>
 /// 返回配置系统错误的异常。
 /// </summary>
 /// <param name="message">异常的信息。</param>
 /// <param name="innerException">导致当前异常的异常。</param>
 /// <param name="info">配置元素的信息。</param>
 /// <returns><see cref="ConfigurationErrorsException"/> 对象。</returns>
 private static ConfigurationErrorsException GetConfigurationErrorsException(string message,
                                                                             Exception innerException, ElementInformation info)
 {
     Contract.Requires(message != null && innerException != null && info != null);
     return(new ConfigurationErrorsException(message, innerException, info.Source, info.LineNumber));
 }