示例#1
0
        //Called by the WCF to apply the configuration settings (the property above) to the binding element
        public override void ApplyConfiguration(BindingElement bindingElement)
        {
            GZipMessageEncodingBindingElement binding      = (GZipMessageEncodingBindingElement)bindingElement;
            PropertyInformationCollection     propertyInfo = this.ElementInformation.Properties;

            if (propertyInfo["innerMessageEncoding"].ValueOrigin != PropertyValueOrigin.Default)
            {
                switch (this.InnerMessageEncoding)
                {
                case "textMessageEncoding":
                    binding.InnerMessageEncodingBindingElement = new TextMessageEncodingBindingElement();
                    break;

                case "binaryMessageEncoding":
                    binding.InnerMessageEncodingBindingElement = new BinaryMessageEncodingBindingElement();
                    break;
                }
            }
            if (this.ReaderQuotas.ElementInformation.IsPresent)
            {
                XmlDictionaryReaderQuotasElement elementQuotas = this.ReaderQuotas;
                XmlDictionaryReaderQuotas        bindingQuotas = binding.ReaderQuotas;
                if (elementQuotas.MaxArrayLength != 0)
                {
                    bindingQuotas.MaxArrayLength = elementQuotas.MaxArrayLength;
                }
                if (elementQuotas.MaxBytesPerRead != 0)
                {
                    bindingQuotas.MaxBytesPerRead = elementQuotas.MaxBytesPerRead;
                }
                if (elementQuotas.MaxDepth != 0)
                {
                    bindingQuotas.MaxDepth = elementQuotas.MaxDepth;
                }
                if (elementQuotas.MaxNameTableCharCount != 0)
                {
                    bindingQuotas.MaxNameTableCharCount = elementQuotas.MaxNameTableCharCount;
                }
                if (elementQuotas.MaxStringContentLength != 0)
                {
                    bindingQuotas.MaxStringContentLength = elementQuotas.MaxStringContentLength;
                }
            }
        }
示例#2
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;            
        }