Пример #1
0
 public void UpdateDataFromUI()
 {
     config.LogDebug = cbLogDebug.Checked;
     config.LogError = cbLogError.Checked;
     config.LogInfo  = cbLogInfo.Checked;
     config.LogWarn  = cbLogWarn.Checked;
     config.EmailServerSettings.FromEmail         = txtFromEmail.Text.Trim();
     config.EmailServerSettings.ToEmail           = txtToEmail.Text.Trim();
     config.EmailServerSettings.Server            = txtEmailServerName.Text.Trim();
     config.EmailServerSettings.Port              = SafeUtils.Int(txtEmailPort.Text.Trim());
     config.EmailServerSettings.UserName          = txtEmailUsername.Text.Trim();
     config.EmailServerSettings.Password          = txtEmailPassword.Text.Trim();
     config.EmailServerSettings.UseSSL            = cbEmailUseSSL.Checked;
     config.EmailServerSettings.UseHtmlMail       = cbUseHtmlMessage.Checked;
     config.EmailTemplateSettings.DefaultSubject  = txtEmailTemplateSubject.Text;
     config.EmailTemplateSettings.DefaultTextBody = txtEmailTemplateBody.Text;
     config.EmailTemplateSettings.DefaultHtmlBody = txtEmailTemplateBody.Text;
 }
Пример #2
0
        private void btSendTestEmail_Click(object sender, EventArgs e)
        {
            try
            {
                EmailUtils.SendMail(txtFromEmail.Text.Trim(),
                                    txtToEmail.Text.Trim(),
                                    "Test email from MonitorR",
                                    cbUseHtmlMessage.Checked,
                                    cbUseHtmlMessage.Checked ? "<html><b>Test html email from MonitorR</b></html>" : "Test email from MonitorR",
                                    txtEmailServerName.Text.Trim(),
                                    SafeUtils.Int(txtEmailPort.Text.Trim()),
                                    txtEmailUsername.Text.Trim(),
                                    txtEmailPassword.Text.Trim(),
                                    cbEmailUseSSL.Checked,
                                    10);

                MessageBox.Show($"Successfully sent the mail to {txtToEmail.Text}");
            }
            catch (Exception ex)
            {
                log.Error(ex, $"Unable to send email to - {txtToEmail.Text}");
                MessageBox.Show($"Unable to send email to - {txtToEmail.Text} \n\n Exception : \n" + ex.RecursivelyGetExceptionMessage());
            }
        }
Пример #3
0
        static AppLog GetAppLogFromLine(string fileName, string line, string extractionPattern, string extractionPatternForFileName)
        {
            AppLog log = new AppLog();
            Match  match;

            if (String.IsNullOrEmpty(extractionPattern))
            {
                match = defaultLogExpression.Match(line);
            }
            else
            {
                Regex expression = new Regex(extractionPattern);
                match = expression.Match(line);
            }

            if (match.Success)
            {
                if (match.Groups["longdatetime"].Value.IsTrimmedStringNotNullOrEmpty())
                {
                    log.Longdate = SafeUtils.DateTime(match.Groups["longdatetime"].Value);
                }
                else if (match.Groups["shorttime"].Value.IsTrimmedStringNotNullOrEmpty())
                {
                    log.Longdate = SafeUtils.DateTime(match.Groups["shorttime"].Value);

                    if (match.Groups["shortdate"].Value.IsTrimmedStringNotNullOrEmpty())
                    {
                        var shortDate = DateTime.UtcNow;
                        shortDate    = SafeUtils.DateTime(match.Groups["shortdate"].Value);
                        log.Longdate = log.Longdate.UpdateDatePart(shortDate.Date);
                    }
                    else
                    {
                        var shortFilename = Path.GetFileName(fileName);
                        var expression    = new Regex(extractionPatternForFileName);
                        var fileNameMatch = expression.Match(shortFilename ?? "");

                        if ((fileNameMatch.Groups["year"].Value.IsTrimmedStringNotNullOrEmpty()) &&
                            (fileNameMatch.Groups["month"].Value.IsTrimmedStringNotNullOrEmpty()) &&
                            (fileNameMatch.Groups["day"].Value.IsTrimmedStringNotNullOrEmpty()))
                        {
                            log.Longdate = log.Longdate.UpdateDatePart(SafeUtils.Int(fileNameMatch.Groups["year"].Value), SafeUtils.Int(fileNameMatch.Groups["month"].Value), SafeUtils.Int(fileNameMatch.Groups["day"].Value));
                        }
                        else
                        {
                            Console.WriteLine("Unable to get the Log Date for Line - " + line);
                        }
                    }
                }
                else
                {
                    log.Longdate = DateTime.UtcNow;
                }

                if (match.Groups["loglevel"].Value.IsTrimmedStringNotNullOrEmpty())
                {
                    log.Severity = match.Groups["loglevel"].Value;
                }


                if (match.Groups["machine"].Value.IsTrimmedStringNotNullOrEmpty())
                {
                    log.MachineName = match.Groups["machine"].Value;
                }
                else
                {
                    log.MachineName = Environment.MachineName;
                }

                if (SafeUtils.Int(match.Groups["processid"].Value) != 0)
                {
                    log.ProcessId = SafeUtils.Int(match.Groups["processid"].Value);
                }

                if (SafeUtils.Int(match.Groups["threadid"].Value) != 0)
                {
                    log.ThreadId = SafeUtils.Int(match.Groups["threadid"].Value);
                }

                if (match.Groups["function"].Value.IsTrimmedStringNotNullOrEmpty())
                {
                    log.CurrentFunction = match.Groups["function"].Value;
                }

                if (match.Groups["filename"].Value.IsTrimmedStringNotNullOrEmpty())
                {
                    log.CurrentSourceFilename = match.Groups["filename"].Value;
                }

                if (SafeUtils.Int(match.Groups["linenumber"].Value) != 0)
                {
                    log.CurrentSourceLineNumber = SafeUtils.Int(match.Groups["linenumber"].Value);
                }

                if (match.Groups["tag"].Value.IsTrimmedStringNotNullOrEmpty())
                {
                    log.CurrentTag = match.Groups["tag"].Value;
                }

                if (match.Groups["user"].Value.IsTrimmedStringNotNullOrEmpty())
                {
                    log.UserIdentity = match.Groups["user"].Value;
                }

                if (match.Groups["ip"].Value.IsTrimmedStringNotNullOrEmpty())
                {
                    log.RemoteAddress = match.Groups["ip"].Value;
                }

                if (match.Groups["result"].Value.IsTrimmedStringNotNullOrEmpty())
                {
                    log.Result = match.Groups["result"].Value;
                }

                if (match.Groups["loglevel"].Value.IsTrimmedStringNotNullOrEmpty())
                {
                    log.ElapsedTime = SafeUtils.Double(match.Groups["elapsedtime"].Value);
                }

                if (match.Groups["message"].Value.IsTrimmedStringNotNullOrEmpty())
                {
                    log.Message = match.Groups["message"].Value;
                }

                if (match.Groups["log-id"].Value.IsTrimmedStringNotNullOrEmpty())
                {
                    log.LogId = SafeUtils.Guid(match.Groups["log-id"].Value);
                }

                if (match.Groups["log-type"].Value.IsTrimmedStringNotNullOrEmpty())
                {
                    log.LogType = SafeUtils.Int(match.Groups["LogType"].Value);
                }

                if (match.Groups["application-Id"].Value.IsTrimmedStringNotNullOrEmpty())
                {
                    log.ApplicationId = match.Groups["application-Id"].Value;
                }

                if (match.Groups["corelation-id"].Value.IsTrimmedStringNotNullOrEmpty())
                {
                    log.CorelationId = match.Groups["corelation-id"].Value;
                }

                if (match.Groups["receivedDateAsTicks"].Value.IsTrimmedStringNotNullOrEmpty())
                {
                    log.ReceivedDateAsTicks = SafeUtils.Long(match.Groups["receivedDateAsTicks"].Value);
                }

                if (match.Groups["longdate-as-ticks"].Value.IsTrimmedStringNotNullOrEmpty())
                {
                    log.LongdateAsTicks = SafeUtils.Long(match.Groups["longdate-as-ticks"].Value);
                }

                if (match.Groups["app"].Value.IsTrimmedStringNotNullOrEmpty())
                {
                    log.App = match.Groups["app"].Value;
                }

                if (match.Groups["module"].Value.IsTrimmedStringNotNullOrEmpty())
                {
                    log.Module = match.Groups["module"].Value;
                }

                if (match.Groups["result-code"].Value.IsTrimmedStringNotNullOrEmpty())
                {
                    log.ResultCode = SafeUtils.Int(match.Groups["result-code"].Value);
                }

                if (match.Groups["function-name"].Value.IsTrimmedStringNotNullOrEmpty())
                {
                    log.FunctionName = match.Groups["function-name"].Value;
                }

                if (match.Groups["start-time"].Value.IsTrimmedStringNotNullOrEmpty())
                {
                    log.StartTime = SafeUtils.DateTime(match.Groups["start-time"].Value);
                }

                if (match.Groups["result"].Value.IsTrimmedStringNotNullOrEmpty())
                {
                    log.Result = match.Groups["result"].Value;
                }

                if (match.Groups["request"].Value.IsTrimmedStringNotNullOrEmpty())
                {
                    log.Request = match.Groups["request"].Value;
                }

                if (match.Groups["response"].Value.IsTrimmedStringNotNullOrEmpty())
                {
                    log.Response = match.Groups["response"].Value;
                }
            }
            return(log);
        }
Пример #4
0
        protected void PopulateFromConfigFile()
        {
            var configLocation = GetConfigFileLocation();

            if (configLocation == null || configLocation.Trim() == string.Empty)
            {
                throw new Exception("Unable to find the Config location");
            }

            var builder = new ConfigurationBuilder()
                          .SetBasePath(Path.GetDirectoryName(configLocation))
                          .AddJsonFile(Path.GetFileName(configLocation), optional: false, reloadOnChange: true);

            var config = builder.Build();

            var appSettings          = config.GetSection("configuration:appSettings");
            var frameworkLogSettings = config.GetSection("Logging");

            PopulateFromConfigFile(appSettings, frameworkLogSettings, configLocation);

            if (DbSettings.MigrationNamespace.IsTrimmedStringNullOrEmpty())
            {
                throw new Exception(ErrorConstants.MigrationNamespaceIsEmpty);
            }

            ServerPort       = SafeUtils.Int(appSettings[Strings.Config.ServerPort], ServerPort);
            AppName          = Path.GetFileNameWithoutExtension(this.GetType().GetTypeInfo().Assembly.Location);
            BatchSizeToIndex = SafeUtils.Int(appSettings[StringConstants.Config.BatchSizeToIndex], BatchSizeToIndex);

            EnablePushToMasterIndexServer = SafeUtils.Bool(appSettings[StringConstants.Config.EnablePushToMasterIndexServer], false);
            if (EnablePushToMasterIndexServer)
            {
                var masterIndexServerSettings = appSettings.GetSection(StringConstants.Config.MasterIndexStoreSettings);
                MasterIndexStoreSettings = new MasterIndexStoreSettings(masterIndexServerSettings);
            }

            this.IndexStoreType = SafeUtils.Enum <IndexStoreType>(appSettings[StringConstants.Config.IndexStoreType], IndexStoreType.None);

            if (IndexStoreType == IndexStoreType.Lucene)
            {
                var luceneSettings = appSettings.GetSection(StringConstants.Config.LuceneIndexStoreSettings);
                LuceneIndexStoreSettings = new LuceneIndexStoreSettings(luceneSettings, (str) =>
                {
                    if (str.IsTrimmedStringNotNullOrEmpty() && str.Contains(Strings.Config.ConfigPath))
                    {
                        str = str.Replace(Strings.Config.ConfigPath, FileUtils.GetFileDirectory(configLocation));
                        str = Path.GetFullPath(new Uri(str).LocalPath);
                    }
                    return(str);
                });

                if (Directory.Exists(LuceneIndexStoreSettings.AppLogIndexFolder) == false)
                {
                    Directory.CreateDirectory(LuceneIndexStoreSettings.AppLogIndexFolder);
                }

                if (Directory.Exists(LuceneIndexStoreSettings.PerformanceLogIndexFolder) == false)
                {
                    Directory.CreateDirectory(LuceneIndexStoreSettings.PerformanceLogIndexFolder);
                }
            }
            else if (IndexStoreType == IndexStoreType.Sqlite3 || IndexStoreType == IndexStoreType.SqlServer || IndexStoreType == IndexStoreType.Postgresql || IndexStoreType == IndexStoreType.MySql)
            {
                var configSettings = appSettings.GetSection(StringConstants.Config.SqlIndexStoreSettings);
                this.SqlIndexStoreSettings = new DbSettings(configSettings, (str) =>
                {
                    if (str.IsTrimmedStringNotNullOrEmpty() && str.Contains(Strings.Config.ConfigPath))
                    {
                        str = str.Replace(Strings.Config.ConfigPath, FileUtils.GetFileDirectory(configLocation));
                        str = Path.GetFullPath(new Uri(str).LocalPath);
                    }
                    return(str);
                });
            }
            else if (IndexStoreType == IndexStoreType.ElasticSearch)
            {
                var configSettings = appSettings.GetSection(StringConstants.Config.EmbbededElasticSearchIndexStoreSettings);
                this.ElasticSearchIndexStoreSettings = new ElasticSearchIndexStoreSettings(configSettings);
            }

            //else if (IndexStoreType == IndexStoreType.EmbbededElasticSearch)
            //{
            //    var configSettings = appSettings.GetSection("embeddedElasticSearchIndexStoreSettings");
            //    this.EmbeddedElasticSearchIndexStoreSettings = new EmbeddedElasticSearchIndexStoreSettings(configSettings, (str) =>
            //    {
            //        if (str.IsTrimmedStringNotNullOrEmpty() && str.Contains(Strings.Config.ConfigPath))
            //        {
            //            str = str.Replace(Strings.Config.ConfigPath, FileUtils.GetFileDirectory(configLocation));
            //            str = Path.GetFullPath(new Uri(str).LocalPath);
            //        }
            //        return str;
            //    });
            //}
            else if (IndexStoreType == IndexStoreType.RaptorDB)
            {
                var configSettings = appSettings.GetSection(StringConstants.Config.RaptorDBIndexStoreSettings);
                this.RaptorDBIndexStoreSettings = new RaptorDBIndexStoreSettings(configSettings, (str) =>
                {
                    if (str.IsTrimmedStringNotNullOrEmpty() && str.Contains(Strings.Config.ConfigPath))
                    {
                        str = str.Replace(Strings.Config.ConfigPath, FileUtils.GetFileDirectory(configLocation));
                        str = Path.GetFullPath(new Uri(str).LocalPath);
                    }
                    return(str);
                });
            }
            else if (IndexStoreType == IndexStoreType.MongoDB)
            {
                var configSettings = appSettings.GetSection("mongoDBIndexStoreSettings");
                this.MongoDBIndexStoreSettings = new MongoDBIndexStoreSettings(configSettings);
            }
            else
            {
                throw new Exception("Index Store Type is not configured");
            }
        }
Пример #5
0
        private bool IsValid()
        {
            if (txtFromEmail.Text.IsTrimmedStringNullOrEmpty())
            {
                MessageBox.Show("From Email should not be empty");
                return(false);
            }

            if (!ValidationUtils.IsEmailValid(txtFromEmail.Text.Trim()))
            {
                MessageBox.Show("From Email is not valid");
                return(false);
            }

            if (txtToEmail.Text.IsTrimmedStringNullOrEmpty())
            {
                MessageBox.Show("To Email should not be empty");
                return(false);
            }

            if (!ValidationUtils.IsEmailValid(txtToEmail.Text.Trim()))
            {
                MessageBox.Show("To Email is not valid");
                return(false);
            }

            if (txtEmailServerName.Text.IsTrimmedStringNullOrEmpty())
            {
                MessageBox.Show("Email Server should not be empty");
                return(false);
            }

            if (SafeUtils.Int(txtEmailPort.Text) == 0)
            {
                MessageBox.Show("Email Port should be  greater than Zero");
                return(false);
            }

            if (txtEmailUsername.Text.IsTrimmedStringNullOrEmpty())
            {
                MessageBox.Show("Email Usename should not be empty");
                return(false);
            }

            if (txtEmailPassword.Text.IsTrimmedStringNullOrEmpty())
            {
                MessageBox.Show("Email Password should not be empty");
                return(false);
            }

            if (txtEmailTemplateSubject.Text.IsTrimmedStringNullOrEmpty())
            {
                MessageBox.Show("Email Template Subject should not be empty");
                return(false);
            }

            if (txtEmailTemplateBody.Text.IsTrimmedStringNullOrEmpty())
            {
                MessageBox.Show("Email Template Body should not be empty");
                return(false);
            }

            return(true);
        }