Ejemplo n.º 1
0
        /// <summary>
        /// ExportMailTemplates method implementation
        /// </summary>
        public static bool ExportMailTemplates(MFAConfig config, int lcid, Dictionary <string, string> data)
        {
            bool done = false;

            try
            {
                WebAdminClient manager = new WebAdminClient();
                try
                {
                    manager.Initialize();
                    IWebAdminServices client = manager.Open();
                    try
                    {
                        done = client.ExportMailTemplates(GetServers(config), CFGReaderUtilities.GetCryptedConfig(config), lcid, data);
                    }
                    finally
                    {
                        manager.Close(client);
                    }
                }
                finally
                {
                    manager.UnInitialize();
                }

                if (done)
                {
                    char   sep      = Path.DirectorySeparatorChar;
                    string htmlpath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + sep + "MFA" + sep + "MailTemplates" + sep + lcid.ToString();

                    MailProvider mailprov = config.MailProvider;
                    if (!mailprov.MailOTPContent.Exists(c => c.LCID.Equals(lcid)))
                    {
                        mailprov.MailOTPContent.Add(new SendMailFileName(lcid, htmlpath + sep + "MailOTPContent.html"));
                    }
                    if (!mailprov.MailKeyContent.Exists(c => c.LCID.Equals(lcid)))
                    {
                        mailprov.MailKeyContent.Add(new SendMailFileName(lcid, htmlpath + sep + "MailKeyContent.html"));
                    }
                    if (!mailprov.MailAdminContent.Exists(c => c.LCID.Equals(lcid)))
                    {
                        mailprov.MailAdminContent.Add(new SendMailFileName(lcid, htmlpath + sep + "MailAdminContent.html"));
                    }
                    if (!mailprov.MailNotifications.Exists(c => c.LCID.Equals(lcid)))
                    {
                        mailprov.MailNotifications.Add(new SendMailFileName(lcid, htmlpath + sep + "MailNotifications.html"));
                    }
                }
                return(done);
            }
            catch
            {
                return(false);
            }
        }
        /// <summary>
        /// ExportMailTemplates method implementation
        /// </summary>
        internal bool ExportMailTemplates(Dictionary <string, bool> servers, byte[] config, int lcid, Dictionary <string, string> templates, bool dispatch = true)
        {
            char   sep      = Path.DirectorySeparatorChar;
            string htmlpath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + sep + "MFA" + sep + "MailTemplates" + sep + lcid.ToString();

            try
            {
                if (!Directory.Exists(htmlpath))
                {
                    Directory.CreateDirectory(htmlpath);
                }

                foreach (var item in templates)
                {
                    if (!File.Exists(htmlpath + sep + item.Key))
                    {
                        File.WriteAllText(htmlpath + sep + item.Key, item.Value, Encoding.UTF8);
                    }
                }

                if (dispatch)
                {
                    string        fqdn        = Dns.GetHostEntry("localhost").HostName;
                    List <string> servernames = (from server in servers
                                                 where (server.Key.ToLower() != fqdn.ToLower())
                                                 select server.Key.ToLower()).ToList <string>();

                    foreach (string srv in servernames)
                    {
                        WebAdminClient manager = new WebAdminClient();
                        manager.Initialize(srv);
                        try
                        {
                            IWebAdminServices client = manager.Open();
                            try
                            {
                                client.ExportMailTemplates(servers, config, lcid, templates, false);
                            }
                            catch (Exception e)
                            {
                                _log.WriteEntry(string.Format("Error on WebAdminService Service ExportMailTemplates method : {0} - {1} / {2}.", srv, lcid, e.Message), EventLogEntryType.Error, 2010);
                            }
                            finally
                            {
                                manager.Close(client);
                            }
                        }
                        catch (Exception e)
                        {
                            _log.WriteEntry(string.Format("Error on WebAdminService Service ExportMailTemplates method : {0} / {1}.", srv, e.Message), EventLogEntryType.Error, 2010);
                        }
                        finally
                        {
                            manager.UnInitialize();
                        }
                    }
                }
                return(true);
            }
            catch (Exception e)
            {
                _log.WriteEntry(string.Format("Error on WebAdminService Service ExportMailTemplates method : {0}.", e.Message), EventLogEntryType.Error, 2010);
                return(false);
            }
        }