Hello Im recieving an "}" expected error, im trying to end my main method after the public class starter. Why am i receiving this error?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Diagnostics;
using System.Data.SqlClient;
namespace MainPDF
{
static class Program
{
static void Main()
{
public class starter
{
private System.Timers.Timer withEventsField_tmrCheckMailOdd = new System.Timers.Timer();
public System.Timers.Timer tmrCheckMailOdd
{
get { return withEventsField_tmrCheckMailOdd; }
set
{
if (withEventsField_tmrCheckMailOdd != null)
{
withEventsField_tmrCheckMailOdd.Elapsed -= tmrCheckMailOdd_Elapsed;
}
withEventsField_tmrCheckMailOdd = value;
if (withEventsField_tmrCheckMailOdd != null)
{
withEventsField_tmrCheckMailOdd.Elapsed += tmrCheckMailOdd_Elapsed;
}
}
}
private System.Timers.Timer withEventsField_tmrCheckMailEven = new System.Timers.Timer();
public System.Timers.Timer tmrCheckMailEven
{
get { return withEventsField_tmrCheckMailEven; }
set
{
if (withEventsField_tmrCheckMailEven != null)
{
withEventsField_tmrCheckMailEven.Elapsed -= tmrCheckMailEven_Elapsed;
}
withEventsField_tmrCheckMailEven = value;
if (withEventsField_tmrCheckMailEven != null)
{
withEventsField_tmrCheckMailEven.Elapsed += tmrCheckMailEven_Elapsed;
}
}
}
Dictionary<string, string> EmailMerchants = new Dictionary<string, string>();
int EmailMerchantRefreshMaxIndex = 120;
int EmailMerchantRefreshIndex = 0;
SqlDataAdapter daAdapter = new SqlDataAdapter();
System.DateTime gServiceStartDate;
System.DateTime gLastStatusReportDate;
string strRootUploadedImagePath = "";
System.DateTime gLastUserNotifcationDate = DateTime.Now.AddDays(-1);
int intThumbnailHeight = 200;
int intThumbnailWidth = 200;
string MailHost = "";
string ReplyEmail = "";
string SMTPUserName = "";
string SMTPPassword = "";
int SMTPPort = 25;
bool bUseSSL = false;
private string GetMachineName()
{
return System.Environment.MachineName;
}
protected void OnStart(string[] args)
{
try
{
System.Threading.Thread.Sleep(20000);
gServiceStartDate = DateTime.Now;
gLastStatusReportDate = DateTime.Now;
using (SqlConnection scMail = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["myDigiStuff"].ConnectionString))
for (int x = 1; x <= 5; x++)
{
try
{
Console.Write("Attempting to open database connection to " + scMail.Database, TraceEventType.Information);
if (scMail.State != ConnectionState.Open)
{
scMail.Open();
Console.Write("Connection established to [" + scMail.Database + "]", TraceEventType.Information);
}
break;
}
catch (Exception ex)
{
if (x < 5)
{
Console.Write("Failed connecting to [" + scMail.Database + "] on attempt [" + x + "]. Will retry in 5 seconds..." + System.Environment.NewLine + ex.Message, TraceEventType.Warning);
System.Threading.Thread.Sleep(5000);
}
else
{
Console.Write("Failed connecting to [" + scMail.Database + "] on final attempt. Service is shutting down..." + System.Environment.NewLine + ex.Message, TraceEventType.Error);
return;
}
}
}
Console.Write("Getting global variables for configuration", TraceEventType.Information);
DataTable dtGlobalSettings = GetGlobalVariables("AdminEmails, EmailPollTimerIntervalInSeconds, MailHosts, ReplyEmail, SMTPUserName, SMTPPassword, SMTPPort, SMTPUseSSL,dbo.NextIntervalTimertoAPN(getdate()) APNTimerIntervalInSeconds ");
tmrCheckMailOdd.Interval = (double)dtGlobalSettings.Rows[0]["EmailPollTimerIntervalInSeconds"] * 1000;
tmrCheckMailEven.Interval = (double)dtGlobalSettings.Rows[0]["EmailPollTimerIntervalInSeconds"] * 1000;
MailHost = dtGlobalSettings.Rows[0]["MailHosts"].ToString();
ReplyEmail = dtGlobalSettings.Rows[0]["ReplyEmail"].ToString();
SMTPUserName = dtGlobalSettings.Rows[0]["SMTPUserName"].ToString();
SMTPPassword = dtGlobalSettings.Rows[0]["SMTPPassword"].ToString();
SMTPPort = (int)dtGlobalSettings.Rows[0]["SMTPPort"];
bUseSSL = (bool)dtGlobalSettings.Rows[0]["SMTPUseSSL"];
Console.Write("Email polling timer set to poll every [" + dtGlobalSettings.Rows[0]["EmailPollTimerIntervalInSeconds"] + "] seconds based on GlobalConfig setting", TraceEventType.Information);
tmrCheckMailOdd.Enabled = true;
tmrCheckMailOdd.Start();
tmrCheckMailEven.Enabled = true;
tmrCheckMailEven.Start();
Console.Write("Application" + " started successfully!", TraceEventType.Information);
Console.Write("Email merchants loaded [" + EmailMerchants.Count().ToString() + "].", TraceEventType.Information);
string strUserEmails = dtGlobalSettings.Rows[0]["AdminEmails"].ToString();
CSUtilities objCSUtilities = new CSUtilities();
}
catch (Exception ex)
{
Console.Write(ex.ToString(), TraceEventType.Error, "There was an error trying to start the service. " + GetErrorInfo(ex));
}
}
protected void OnStop()
{
DataTable dtGlobalSettings = null;
dtGlobalSettings = GetGlobalVariables("AdminEmails,EmailPollTimerIntervalInSeconds, MailHosts, ReplyEmail, SMTPUserName, SMTPPassword, SMTPPort, SMTPUseSSL,APNTimerIntervalInSeconds");
string strUserEmails = dtGlobalSettings.Rows[0]["AdminEmails"].ToString();
Console.Write("Application" + " stopping.", TraceEventType.Information);
Console.Write("Stopping Timer.", TraceEventType.Information);
try
{
tmrCheckMailOdd.Stop();
tmrCheckMailOdd.Enabled = false;
Console.Write("Odd Timer Stopped.", TraceEventType.Information);
tmrCheckMailEven.Stop();
tmrCheckMailEven.Enabled = false;
Console.Write("Even Timer Stopped.", TraceEventType.Information);
}
catch (Exception ex)
{
Console.Write(ex.ToString(), TraceEventType.Warning, "Timer could not be stopped gracefully. " + GetErrorInfo(ex));
}
}
public void tmrCheckMailOdd_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
try
{
tmrCheckMailOdd.Stop();
DataTable dtGlobalSettings = GetGlobalVariables("EmailPollTimerIntervalInSeconds, MailHosts, ReplyEmail, SMTPUserName, SMTPPassword, SMTPPort, SMTPUseSSL");
tmrCheckMailOdd.Interval = (double)dtGlobalSettings.Rows[0]["EmailPollTimerIntervalInSeconds"] * 1000;
using (SqlConnection scMail = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["myDigiStuff"].ConnectionString))
{
scMail.Open();
CSUtilities objCSUtilities = new CSUtilities();
RefreshEmailMerchants();
objCSUtilities.CheckEmail(scMail, dtGlobalSettings.Rows[0], true, ("WinnovativePrototype"), EmailMerchants);
if (scMail.State != ConnectionState.Closed)
{
scMail.Close();
}
}
}
catch (Exception ex)
{
Console.Write(ex.ToString(), TraceEventType.Error, "Error Processing Emails: " + GetErrorInfo(ex));
}
finally
{
tmrCheckMailOdd.Start();
}
}
public void tmrCheckMailEven_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
try
{
tmrCheckMailEven.Stop();
DataTable dtGlobalSettings = GetGlobalVariables("EmailPollTimerIntervalInSeconds, MailHosts, ReplyEmail, SMTPUserName, SMTPPassword, SMTPPort, SMTPUseSSL");
tmrCheckMailEven.Interval = (double)dtGlobalSettings.Rows[0]["EmailPollTimerIntervalInSeconds"] * 1000;
using (SqlConnection scMail = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["myDigiStuff"].ConnectionString))
{
scMail.Open();
CSUtilities objCSUtilities = new CSUtilities();
RefreshEmailMerchants();
string folderz = "WinnovativeTesting";
objCSUtilities.CheckEmail(scMail, dtGlobalSettings.Rows[0], false, ("WinnovativePrototype"), EmailMerchants);
if (scMail.State != ConnectionState.Closed)
{
scMail.Close();
}
}
}
catch (Exception ex)
{
Console.Write(ex.ToString(), TraceEventType.Error, "Error Processing Emails: " + GetErrorInfo(ex));
}
finally
{
tmrCheckMailEven.Start();
}
}
private string GetErrorInfo(Exception ex)
{
string strReturn = "";
try
{
strReturn += System.Environment.NewLine + "Error: [" + ex.Message + "]";
if ((ex.StackTrace != null))
{
strReturn += System.Environment.NewLine + "Stack Trace:" + System.Environment.NewLine + ex.StackTrace + "]";
}
foreach (string objItem in ex.Data.Keys)
{
strReturn += System.Environment.NewLine + objItem + ": [" + ex.Data[objItem].ToString() + "]";
}
if (strReturn.Length >= 30000)
{
strReturn = "The additional info needed to be truncated!" + System.Environment.NewLine + System.Environment.NewLine + strReturn.Substring(0, 30000);
}
}
catch (Exception ex2)
{
Console.Write(ex2.ToString(), TraceEventType.Error, "There was an unhandled exception when building the ErrorInfo string. GetErrorInfo(); " + System.Environment.NewLine + ex2.Message);
}
return strReturn;
}
public DataTable GetGlobalVariables(string strVariableList)
{
DataTable functionReturnValue = default(DataTable);
try
{
using (SqlConnection scMail = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["myDigiStuff"].ConnectionString))
{
scMail.Open();
string strSQL = "";
SqlDataAdapter sda = new SqlDataAdapter(strSQL, scMail);
DataTable dtReturnValues = new DataTable();
strSQL = "SELECT " + strVariableList + " FROM GlobalConfig";
sda.SelectCommand.CommandText = strSQL;
sda.Fill(dtReturnValues);
functionReturnValue = dtReturnValues;
}
}
catch (Exception ex)
{
functionReturnValue = null;
throw ex;
}
finally
{
}
return functionReturnValue;
}
private void RefreshEmailMerchants()
{
EmailMerchantRefreshIndex = EmailMerchantRefreshIndex + 1;
if (EmailMerchantRefreshIndex > EmailMerchantRefreshMaxIndex)
{
EmailMerchants = GetEmailMerchantDomains();
EmailMerchantRefreshIndex = 0;
}
}
private Dictionary<string, string> GetEmailMerchantDomains()
{
Dictionary<string, string> retVal = new Dictionary<string, string>();
try
{
using (SqlConnection scMail = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["myDigiStuff"].ConnectionString))
{
scMail.Open();
string strSQL = "";
SqlDataAdapter sda = new SqlDataAdapter(strSQL, scMail);
DataTable dtReturnValues = new DataTable();
strSQL = "SELECT MerchantDomain, MerchantName FROM lkupReturnPathMerchantDomains WITH(NOLOCK) WHERE IsActive = 1;";
sda.SelectCommand.CommandText = strSQL;
sda.Fill(dtReturnValues);
dtReturnValues.AsEnumerable().ToList().ForEach(obj => { retVal.Add(obj[0].ToString(), obj[1].ToString()); });
}
}
catch (Exception ex)
{
throw ex;
}
return retVal;
}
}
}
}
}
What I have tried:
I've check multiple time to make sure its in the correct placement.
Rebuilt project
Clean Build
Pulled hair out :) lol