예제 #1
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Sets the value for specific setting defined by parent node and setting's key.
        /// </summary>
        /// <param name="appSettingsNode">
        /// defines the <b>XmlNode</b> that contains the setting nodes.
        /// </param>
        /// <param name="nodeName">
        /// the value of <i>key</i> attribute of setting node
        /// </param>
        /// <param name="value">
        /// the string that should be assigned to the <i>value</i> attribute of setting node
        /// </param>
        /// <returns>
        /// Returns <b>True</b> if setting node was modified and <b>False</b> in other case
        /// </returns>
        /// <remarks>
        /// This method is used to set the values of setting nodes with predefined node parameters: <br/>
        /// <i>add</i> - the tag name of setting node
        /// <b>key</b> - the attribute that defines the unique node identifier
        /// <b>value</b> - the attribute that defines the setting value <br/>
        /// If requested setting is absent the new setting node is added to the parent <b>XmlNode</b>
        /// </remarks>
        /// <history>
        ///     [Mike]	23.03.2006	Created
        /// </history>
        /// -----------------------------------------------------------------------------
        private bool SetAttributeValue(XmlNode appSettingsNode, string nodeName, string value)
        {
            XmlNode node = FindNodeByAttribute(appSettingsNode, "add", "key", nodeName);

            if (node == null && appSettingsNode != null && appSettingsNode.OwnerDocument != null)
            {
                node = appSettingsNode.OwnerDocument.CreateElement("add");
                node.Attributes.Append(appSettingsNode.OwnerDocument.CreateAttribute("key"));
                node.Attributes["key"].InnerText = nodeName;
                node.Attributes.Append(appSettingsNode.OwnerDocument.CreateAttribute("value"));
                node.Attributes["value"].InnerText = value;
                appSettingsNode.AppendChild(node);
                Dbg.ConditionalDebug(DebugDetalizationLevel.High, "attribute value {0} for node {1} is added  ", value,
                                     nodeName);
                return(true);
            }
            if (node.Attributes["value"].InnerText != value)
            {
                Dbg.ConditionalDebug(DebugDetalizationLevel.High,
                                     "attribute value for node {0} was changed from {1} to {2}  ", nodeName,
                                     node.Attributes["value"].InnerText, value);
                node.Attributes["value"].InnerText = value;
                return(true);
            }
            Dbg.ConditionalDebug(DebugDetalizationLevel.High, "attribute value for node {0} was changed not changed",
                                 nodeName);
            return(false);
        }
예제 #2
0
        private void CreateClientEvent(EventType eventType, object objectId)
        {
            Dbg.ConditionalDebug(DebugDetalizationLevel.Low,
                                 "replication client raise replication event for object at {0}", DateTime.Now);

            using (DbManagerProxy manager = GetDbManager())
            {
                try
                {
                    manager.SetSpCommand("dbo.spEventLog_CreateNewEvent",
                                         manager.Parameter("@idfsEventTypeID", Convert.ToInt64(eventType)),
                                         manager.Parameter("@idfObjectID", objectId),
                                         manager.Parameter("@strInformationString", DBNull.Value),
                                         manager.Parameter("@strNote", DBNull.Value),
                                         manager.Parameter("@ClientID", m_ClientID),
                                         manager.Parameter("@datEventDatatime", DateTime.Now),
                                         manager.Parameter("@intProcessed", 0),
                                         manager.Parameter("@idfUserID", m_UserID),
                                         manager.Parameter(ParameterDirection.InputOutput, "@EventID", DBNull.Value, DbType.Int64),
                                         manager.Parameter("@idfsSite", m_SiteID),
                                         manager.Parameter("@idfsDiagnosis", DBNull.Value)
                                         ).ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    Dbg.Debug("event creation fail: {0}", ex);
                }
            }
        }
예제 #3
0
 private void StartReplication(object state)
 {
     lock (m_SyncObject)
     {
         m_DelayedReplicationTimer.Change(Timeout.Infinite, Timeout.Infinite);
         Dbg.ConditionalDebug(DebugDetalizationLevel.Low, "delayed replication event occured");
         if (m_StdReplicationRequested)
         {
             CreateClientEvent(EventType.ReplicationRequestedByUser, -1);
             if (!IsNotificationService && EidssSiteContext.Instance.RealSiteType != SiteType.CDR)
             {
                 CheckNotificationService();
             }
         }
         m_StdReplicationRequested = false;
     }
 }
예제 #4
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Searches the <b>XmlNode</b> with specific name and specific attribute value in descendant nodes of parent node and sets values for the set of node attributes.
        /// </summary>
        /// <param name="appSettingsNode">
        /// parent <b>XmlNode</b> node. The node that should be modified will be searched among the children of this node.
        /// </param>
        /// <param name="nodeName">
        /// the tag name of xml node that should be modified
        /// </param>
        /// <param name="attr">
        /// the array of <i>NodeAttribute</i> objects that defines the name/value pairs for modified attributes
        /// </param>
        /// <returns>
        /// Returns <b>True</b> if any of the passed attributes values was modified or new node was created and <b>False</b> in other case.
        /// </returns>
        /// <remarks>
        /// Call this method if you need to modify several attributes of <i>XmlNode</i> with custom node name.
        /// </remarks>
        /// <history>
        ///     [Mike]	23.03.2006	Created
        /// </history>
        /// -----------------------------------------------------------------------------
        private bool SetAttributeValue(XmlNode appSettingsNode, string nodeName, NodeAttribute[] attr)
        {
            if (attr.Length == 0)
            {
                return(false);
            }
            XmlNode node = FindNodeByAttribute(appSettingsNode, nodeName, attr[0].Name, attr[0].Value);

            if (node == null && appSettingsNode != null && appSettingsNode.OwnerDocument != null)
            {
                node = appSettingsNode.OwnerDocument.CreateElement(nodeName);
                for (int i = 0; i <= attr.Length - 1; i++)
                {
                    node.Attributes.Append(appSettingsNode.OwnerDocument.CreateAttribute(attr[i].Name));
                    node.Attributes[attr[i].Name].InnerText = attr[i].Value;
                    Dbg.ConditionalDebug(DebugDetalizationLevel.High, "attribute value {0} for node {1} is added  ",
                                         attr[i].Value, attr[i].Name);
                }
                appSettingsNode.AppendChild(node);
                m_Modified = true;
                return(true);
            }
            for (int i = 1; i <= attr.Length - 1; i++)
            {
                if (node.Attributes[attr[i].Name] == null)
                {
                    node.Attributes.Append(appSettingsNode.OwnerDocument.CreateAttribute(attr[i].Name));
                    Dbg.ConditionalDebug(DebugDetalizationLevel.High, "attribute value {0} for node {1} is added  ",
                                         attr[i].Value, attr[i].Name);
                    m_Modified = true;
                }
                if (node.Attributes[attr[i].Name].InnerText != attr[i].Value)
                {
                    Dbg.ConditionalDebug(DebugDetalizationLevel.High,
                                         "attribute value for node {0} was changed from {1} to {2}  ", attr[i].Name,
                                         node.Attributes[attr[i].Name].InnerText, attr[i].Value);
                    node.Attributes[attr[i].Name].InnerText = attr[i].Value;
                    m_Modified = true;
                }
            }
            return(m_Modified);
        }
예제 #5
0
 public bool StartReplication()
 {
     if (EidssSiteContext.Instance.RealSiteType == SiteType.CDR)
     {
         return(true);
     }
     if (RoutineJobName == null && Utils.IsEmpty(Config.GetSetting("RoutineJobName")))
     {
         return(true);
     }
     lock (m_SyncObject)
     {
         if (!m_StdReplicationRequested)
         {
             m_StdReplicationRequested = true;
             Dbg.ConditionalDebug(DebugDetalizationLevel.Low,
                                  "replication client put replication request to buffer for object at {0}",
                                  DateTime.Now);
             m_DelayedReplicationTimer.Change(1000, 1000);
         }
     }
     return(true);
 }
예제 #6
0
        public void SaveToFile(string configFile)
        {
            if (!BaseSettings.UpdateConnectionInfo)
            {
                return;
            }
            if (configFile != null)
            {
                if (System.IO.File.Exists(configFile))
                {
                    m_Config.Read(configFile);
                }
            }
            Dbg.ConditionalDebug(DebugDetalizationLevel.High, "Saving connection to file {0}", m_Config.FileName);
            m_Config.SetItem(GetKey("ConnectionString"), m_SQLConnectionString);

            m_Config.SetItem(GetKey("Database"), Utils.Str(m_SQLDatabase));
            m_Config.SetItem(GetKey("Server"), Utils.Str(m_SQLServer));
            if (Utils.IsEmpty(m_SQLUser))
            {
                m_Config.SetItem(GetKey("User"), "");
            }
            else
            {
                m_Config.SetItem(GetKey("User"), Cryptor.Encrypt(m_SQLUser));
            }
            if (Utils.IsEmpty(m_SQLPassword))
            {
                m_Config.SetItem(GetKey("Password"), "");
            }
            else
            {
                m_Config.SetItem(GetKey("Password"), Cryptor.Encrypt(m_SQLPassword, Utils.Str(m_SQLUser)));
            }
            m_Config.Save();
            Config.ReloadSettings();
        }
예제 #7
0
 public void Trace(string title, string message, params object[] args)
 {
     Dbg.ConditionalDebug(DebugDetalizationLevel.High, title + Environment.NewLine + message, args);
 }
예제 #8
0
 public void TraceError(Exception e)
 {
     Dbg.ConditionalDebug(DebugDetalizationLevel.High, e.ToString());
 }
예제 #9
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Saves the configuration file previously read using <i>Read</i> method.
        /// </summary>
        /// <returns>
        /// Returns <b>False</b> if error occur during saving or <b>True</b> in other case.
        /// </returns>
        /// <remarks>
        /// When the application is run from VS IDE the changes for default application configuration
        /// file are saved not only to configuration file in the <b>bin</b> folder but to the original
        /// <b>app.config</b> file too. If error occurs during saving the error is written to
        /// the application log but no error reported to end user
        /// </remarks>
        /// <history>
        ///     [Mike]	23.03.2006	Created
        /// </history>
        /// -----------------------------------------------------------------------------
        public bool Save(bool forceSaving = false, bool throwExeption = false)
        {
            if (!m_Modified && !forceSaving)
            {
                Dbg.ConditionalDebug(DebugDetalizationLevel.High,
                                     "configuration file {0} is not saved, there is no changes", m_FileName);
                return(true);
            }
            //!!We should never update web.config from code. Only manual changes are allowed
            var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(m_FileName);

            if (fileNameWithoutExtension != null && fileNameWithoutExtension.ToLowerInvariant() == "web")
            {
                return(true);
            }
            bool ret = true;

            try
            {
                if (!File.Exists(FileName))
                {
                    Utils.ForceDirectories(Path.GetDirectoryName(FileName));
                    FileStream fs = File.Create(FileName);
                    fs.Close();
                }
                FileAttributes attr = File.GetAttributes(FileName);
                if ((attr & FileAttributes.ReadOnly) != 0)
                {
                    attr = attr & (~FileAttributes.ReadOnly);
                    File.SetAttributes(FileName, attr);
                }
                m_AppConfig.Save(m_FileName);
                m_Modified = false;
            }
            catch (Exception ex)
            {
                ret = false;
                Dbg.Debug("the changes to configuration file {0} was not written, {1}",
                          m_FileName, ex.Message);
                if (throwExeption)
                {
                    throw;
                }
            }
            string appConfigFileName = "";

            try
            {
                if (m_FileName == m_DefaultConfigFileName)
                {
                    appConfigFileName = Utils.GetExecutingPath() + "\\..\\app.config";
                    if (File.Exists(appConfigFileName))
                    {
                        m_AppConfig.Save(appConfigFileName);
                    }
                }
            }
            catch (Exception ex)
            {
                ret = false;
                Dbg.Debug("the changes to configuration file {0} was not written, {1}",
                          appConfigFileName, ex.Message);
                if (throwExeption)
                {
                    throw;
                }
            }
            //Config.ReloadSettings();
            //Instance.Read(null);
            return(ret);
        }