Exemple #1
0
        /// <summary>
        /// Writes error to error log file.
        /// </summary>
        /// <param name="virtualServer">Virtual server name.</param>
        /// <param name="errorText">Error text to dump.</param>
        public static void DumpError(string virtualServer, string errorText)
        {
            try{
                DataSet ds = new DataSet("dsEvents");
                ds.Tables.Add("Events");
                ds.Tables["Events"].Columns.Add("ID");
                ds.Tables["Events"].Columns.Add("VirtualServer");
                ds.Tables["Events"].Columns.Add("CreateDate", typeof(DateTime));
                ds.Tables["Events"].Columns.Add("Type");
                ds.Tables["Events"].Columns.Add("Text");

                if (File.Exists(SCore.PathFix(m_Path + "Settings\\Events.xml")))
                {
                    ds.ReadXml(SCore.PathFix(m_Path + "Settings\\Events.xml"));
                }

                DataRow dr = ds.Tables["Events"].NewRow();
                dr["ID"]            = Guid.NewGuid().ToString();
                dr["VirtualServer"] = virtualServer;
                dr["CreateDate"]    = DateTime.Now;
                dr["Type"]          = 0;
                dr["Text"]          = errorText;
                ds.Tables["Events"].Rows.Add(dr);

                ds.WriteXml(SCore.PathFix(m_Path + "Settings\\Events.xml"));
            }
            catch {
            }
        }
Exemple #2
0
        /// <summary>
        /// Loads specified virtual server API.
        /// </summary>
        /// <param name="assembly">API assembly name.</param>
        /// <param name="type">API type name.</param>
        /// <param name="initString">API init string</param>
        /// <returns></returns>
        internal IMailServerApi LoadApi(string assembly, string type, string initString)
        {
            string apiAssemblyPath = "";

            if (File.Exists(SCore.PathFix(m_StartupPath + "\\" + assembly)))
            {
                apiAssemblyPath = SCore.PathFix(m_StartupPath + "\\" + assembly);
            }
            else
            {
                apiAssemblyPath = SCore.PathFix(assembly);
            }

            Assembly ass = Assembly.LoadFile(apiAssemblyPath);

            return((IMailServerApi)Activator.CreateInstance(ass.GetType(type), new object[] { initString }));
        }
Exemple #3
0
        /// <summary>
        /// Writes specified text to log file.
        /// </summary>
        /// <param name="fileName">Log file name.</param>
        /// <param name="text">Log text.</param>
        public static void WriteLog(string fileName, string text)
        {
            try{
                fileName = SCore.PathFix(fileName);

                // If there isn't such directory, create it.
                if (!Directory.Exists(Path.GetDirectoryName(fileName)))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(fileName));
                }

                using (FileStream fs = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write)){
                    StreamWriter w = new StreamWriter(fs); // create a Char writer
                    w.BaseStream.Seek(0, SeekOrigin.End);  // set the file pointer to the end
                    w.Write(text + "\r\n");
                    w.Flush();                             // update underlying file
                }
            }
            catch {
            }
        }
Exemple #4
0
        /// <summary>
        /// Loads virtual server from xml file.
        /// </summary>
        internal void LoadVirtualServers()
        {
            try{
                if (!File.Exists(SCore.PathFix(m_StartupPath + "Settings\\localServers.xml")))
                {
                    return;
                }

                DateTime dateServers = File.GetLastWriteTime(SCore.PathFix(m_StartupPath + "Settings\\localServers.xml"));

                if (DateTime.Compare(dateServers, m_ServersFileDate) != 0)
                {
                    m_ServersFileDate = dateServers;

                    DataSet ds = new DataSet();
                    ds.Tables.Add("Servers");
                    ds.Tables["Servers"].Columns.Add("ID");
                    ds.Tables["Servers"].Columns.Add("Enabled");
                    ds.Tables["Servers"].Columns.Add("Name");
                    ds.Tables["Servers"].Columns.Add("API_assembly");
                    ds.Tables["Servers"].Columns.Add("API_class");
                    ds.Tables["Servers"].Columns.Add("API_initstring");
                    ds.ReadXml(SCore.PathFix(m_StartupPath + "Settings\\localServers.xml"));

                    if (ds.Tables.Contains("Servers"))
                    {
                        // Delete running virtual servers what has deleted.
                        for (int i = 0; i < m_pVirtualServers.Count; i++)
                        {
                            VirtualServer server = m_pVirtualServers[i];
                            bool          exists = false;
                            foreach (DataRow dr in ds.Tables["Servers"].Rows)
                            {
                                if (server.ID == dr["ID"].ToString())
                                {
                                    exists = true;
                                    break;
                                }
                            }
                            if (!exists)
                            {
                                server.Stop();
                                m_pVirtualServers.Remove(server);
                                i--;
                            }
                        }

                        // Add new added virtual servers what aren't running already.
                        foreach (DataRow dr in ds.Tables["Servers"].Rows)
                        {
                            //--- See if specified server already running, if so, skip it. --//
                            bool exists = false;
                            foreach (VirtualServer server in m_pVirtualServers)
                            {
                                if (server.ID == dr["ID"].ToString())
                                {
                                    exists         = true;
                                    server.Enabled = ConvertEx.ToBoolean(dr["Enabled"], true);
                                    break;
                                }
                            }
                            if (exists)
                            {
                                continue;
                            }
                            //--------------------------------------------------------------//

                            string id       = dr["ID"].ToString();
                            string name     = dr["Name"].ToString();
                            string assembly = dr["API_assembly"].ToString();
                            string apiClass = dr["API_class"].ToString();
                            string intiStr  = dr["API_initstring"].ToString();

                            IMailServerApi api           = LoadApi(assembly, apiClass, intiStr);
                            VirtualServer  virtualServer = new VirtualServer(this, id, name, intiStr, api);
                            m_pVirtualServers.Add(virtualServer);
                            virtualServer.Enabled = ConvertEx.ToBoolean(dr["Enabled"], true);
                        }
                    }
                }
            }
            catch (Exception x) {
                Error.DumpError(x, new System.Diagnostics.StackTrace());
            }
        }