public string GetConnectionString() { string connStr = null; bool res; res = false; if (String.IsNullOrEmpty(ConnectionStringCalculated)) { connStr = CreateConnectionString(); } connStr = ConnectionStringCalculated.Replace("{USER}", UserCalculated); String deCryptValue = EncryptionHandler.DecryptwithKey(PassCalculated); if (!string.IsNullOrEmpty(deCryptValue)) { connStr = connStr.Replace("{PASS}", deCryptValue); } else { connStr = connStr.Replace("{PASS}", PassCalculated); } return(connStr); }
public override bool MakeSureConnectionIsOpen() { string password = string.Empty; string pass = EncryptionHandler.DecryptwithKey(Db.DatabaseOperations.PassCalculated.ToString()); if (!string.IsNullOrEmpty(pass)) { password = pass; } else { password = Db.DatabaseOperations.PassCalculated; } try { if (clusterCB != null) { var clusterManager = clusterCB.CreateManager(Db.DatabaseOperations.UserCalculated, password); var buckets = clusterManager.ListBuckets().Value; if (buckets != null) { return(true); } else { return(Connect()); } } return(Connect()); } catch (Exception ex) { return(Connect()); } }
internal void PasswordEncrypted(string value) { Reporter.ToLog(eLogLevel.DEBUG, "PasswordEncrypted: '" + value + "'"); string pswd = WorkSpace.Instance.UserProfile.SourceControlPass; if (value == "Y") { try { pswd = EncryptionHandler.DecryptwithKey(WorkSpace.Instance.UserProfile.SourceControlPass); } catch (Exception ex) { string mess = ex.Message; //To avoid warning of ex not used Reporter.ToLog(eLogLevel.ERROR, "Failed to decrypt the source control password"); //not showing ex details for not showing the password by mistake in log } } if (WorkSpace.Instance.UserProfile.SourceControlType == SourceControlBase.eSourceControlType.GIT && pswd == "") { pswd = "Test"; } WorkSpace.Instance.UserProfile.SourceControlPass = pswd; sourceControlPass = pswd; }
public override bool Connect() { try { clusterCB = new Couchbase.Cluster(new ClientConfiguration { ViewRequestTimeout = 45000, Servers = new List <Uri> { new Uri(Db.DatabaseOperations.TNSCalculated.ToString()) }, }); //TODO: need to decrypt the password in the Database->PassCalculated String deCryptValue = EncryptionHandler.DecryptwithKey(Db.DatabaseOperations.PassCalculated.ToString()); if (!string.IsNullOrEmpty(deCryptValue)) { clusterCB.Authenticate(Db.DatabaseOperations.UserCalculated.ToString(), deCryptValue); } else { clusterCB.Authenticate(Db.DatabaseOperations.UserCalculated.ToString(), Db.DatabaseOperations.PassCalculated.ToString()); } return(true); } catch (Exception e) { Reporter.ToLog(eLogLevel.ERROR, "Failed to connect to Couchbase DB", e); return(false); } }
public void GetBusinessFlowDependacies() { //Arrange string filePath = TestResources.GetTestResourcesFile(@"Solutions" + Path.DirectorySeparatorChar + "GlobalCrossSolution" + Path.DirectorySeparatorChar + "BusinessFlows" + Path.DirectorySeparatorChar + "Flow 1.Ginger.BusinessFlow.xml"); //Act GlobalSolutionItem item = new GlobalSolutionItem(GlobalSolution.eImportItemType.Environments, filePath, GlobalSolutionUtils.Instance.ConvertToRelativePath(filePath), true, GlobalSolutionUtils.Instance.GetRepositoryItemName(filePath), ""); GlobalSolutionUtils.Instance.AddDependaciesForBusinessFlows(item, ref SelectedItemsListToImport, ref VariableListToImport, ref EnvAppListToImport); //Assert Assert.AreEqual(SelectedItemsListToImport.Count, 12); Assert.IsNotNull(SelectedItemsListToImport.Where(x => x.ItemExtraInfo == "~\\\\Applications Models\\POM Models\\SeleniumDemoValid.Ginger.ApplicationPOMModel.xml")); Assert.IsNotNull(SelectedItemsListToImport.Where(x => x.ItemExtraInfo == "~\\\\SharedRepository\\Actions\\Browser Action.Ginger.Action.xml")); Assert.IsNotNull(SelectedItemsListToImport.Where(x => x.ItemExtraInfo == "~\\\\SharedRepository\\Actions\\UIElement Action.Ginger.Action.xml")); Assert.IsNotNull(SelectedItemsListToImport.Where(x => x.ItemExtraInfo == "~\\\\SharedRepository\\Activities\\Activity 2.Ginger.Activity.xml")); Assert.IsNotNull(SelectedItemsListToImport.Where(x => x.ItemExtraInfo == "~\\\\DataSources\\AccessDS.Ginger.DataSource.xml")); Assert.IsNotNull(SelectedItemsListToImport.Where(x => x.ItemExtraInfo == "~\\\\Documents\\bankCode3.xml")); Assert.IsNotNull(SelectedItemsListToImport.Where(x => x.ItemExtraInfo == "~\\\\Documents\\Multiple Values.xlsx")); Assert.IsNotNull(SelectedItemsListToImport.Where(x => x.ItemExtraInfo == "~\\\\Environments\\Test.Ginger.Environment.xml")); Assert.IsNotNull(SelectedItemsListToImport.Where(x => x.ItemExtraInfo == "NewVarString")); Assert.IsNotNull(SelectedItemsListToImport.Where(x => x.ItemExtraInfo == "MyWebApp")); Assert.IsNotNull(SelectedItemsListToImport.Where(x => x.ItemExtraInfo == "MyWebServicesApp")); Assert.IsNotNull(SelectedItemsListToImport.Where(x => x.ItemExtraInfo == "MyWindowsApp")); Assert.AreEqual(VariableListToImport.Count, 2); Assert.IsNotNull(VariableListToImport.Where(x => x.Name == "NewVarString")); Assert.IsNotNull(VariableListToImport.Where(x => x.Name == "NewVarPasswordString")); string strValuetoPass = EncryptionHandler.DecryptwithKey(VariableListToImport.Where(x => x.Name == "NewVarPasswordString").FirstOrDefault().Value, EncryptionHandler.GetDefaultKey()); Assert.AreEqual(strValuetoPass, "ABCD"); Assert.AreEqual(EnvAppListToImport.Count, 1); Assert.IsNotNull(EnvAppListToImport.Where(x => x.Name == "MyWebApp")); }
public void DecryptString() { //Arrange string decryptedString = string.Empty; bool result = false; //Act decryptedString = EncryptionHandler.DecryptwithKey("mDL33JRKM3Zv1FdtGQMNZg=="); //Assert Assert.AreEqual("ginger", decryptedString); }
public void GetDependaciesForEnvParamUsingRegex() { //Arrange string filePath = TestResources.GetTestResourcesFile(@"Solutions" + Path.DirectorySeparatorChar + "GlobalCrossSolution" + Path.DirectorySeparatorChar + "BusinessFlows" + Path.DirectorySeparatorChar + "Flow 1.Ginger.BusinessFlow.xml"); //Act GlobalSolutionUtils.Instance.AddDependaciesForEnvParam(filePath, ref SelectedItemsListToImport, ref VariableListToImport, ref EnvAppListToImport); //Assert Assert.AreEqual(EnvAppListToImport.Count, 1); Assert.IsNotNull(EnvAppListToImport.Where(x => x.Name == "MyWebApp")); string strValuetoPass = EncryptionHandler.DecryptwithKey(EnvAppListToImport[0].GeneralParams.Where(x => x.Name == "Password").FirstOrDefault().Value, EncryptionHandler.GetDefaultKey()); Assert.AreEqual(strValuetoPass, "ABCD"); }
/// <summary> /// For encrypting password variables /// </summary> public bool ValidateKey(string encryptionKey = null) { try { bool isDecrypted = EncryptionHandler.DecryptwithKey(Solution.EncryptedValidationString, encryptionKey ?? Solution.EncryptionKey).Equals("valid"); if (isDecrypted) { Solution.EncryptionKey = encryptionKey ?? (Solution.EncryptionKey ?? EncryptionHandler.GetDefaultKey()); } return(isDecrypted); } catch (Exception ex) { Reporter.ToLog(eLogLevel.DEBUG, ex.Message); } return(false); }
public UserProfile LoadPasswords(UserProfile userProfile) { //Get sourcecontrol password if (!string.IsNullOrEmpty(userProfile.EncryptedSourceControlPass)) { userProfile.SourceControlPass = EncryptionHandler.DecryptwithKey(userProfile.EncryptedSourceControlPass); } else { userProfile.SourceControlPass = WinCredentialUtil.GetCredential("Ginger_SourceControl_" + userProfile.SourceControlType); } if (!string.IsNullOrEmpty(userProfile.EncryptedSolutionSourceControlPass)) { userProfile.SolutionSourceControlPass = EncryptionHandler.DecryptwithKey(userProfile.EncryptedSolutionSourceControlPass); } else { userProfile.SolutionSourceControlPass = WinCredentialUtil.GetCredential("Ginger_SolutionSourceControl"); } //Get ALM passwords foreach (GingerCoreNET.ALMLib.ALMUserConfig almConfig in userProfile.ALMUserConfigs) { if (!string.IsNullOrEmpty(almConfig.EncryptedALMPassword)) { almConfig.ALMPassword = EncryptionHandler.DecryptwithKey(almConfig.EncryptedALMPassword); } else { almConfig.ALMPassword = WinCredentialUtil.GetCredential("Ginger_ALM_" + almConfig.AlmType); } } return(userProfile); }
public bool ProcessCommandLineArgs(string[] lines) { string scURL = null; string scUser = null; string scPswd = null; foreach (string arg in lines) { int i = arg.IndexOf('='); string param = arg.Substring(0, i).Trim(); string value = arg.Substring(i + 1).Trim(); switch (param) { case "SourceControlType": Reporter.ToLog(eLogLevel.DEBUG, "Selected SourceControlType: '" + value + "'"); if (value.Equals("GIT")) { WorkSpace.UserProfile.SourceControlType = SourceControlBase.eSourceControlType.GIT; } else if (value.Equals("SVN")) { WorkSpace.UserProfile.SourceControlType = SourceControlBase.eSourceControlType.SVN; } else { WorkSpace.UserProfile.SourceControlType = SourceControlBase.eSourceControlType.None; } break; case "SourceControlUrl": Reporter.ToLog(eLogLevel.DEBUG, "Selected SourceControlUrl: '" + value + "'"); if (WorkSpace.UserProfile.SourceControlType == SourceControlBase.eSourceControlType.SVN) { if (!value.ToUpper().Contains("/SVN") && !value.ToUpper().Contains("/SVN/")) { value = value + "svn/"; } if (!value.ToUpper().EndsWith("/")) { value = value + "/"; } } WorkSpace.UserProfile.SourceControlURL = value; scURL = value; break; case "SourceControlUser": Reporter.ToLog(eLogLevel.DEBUG, "Selected SourceControlUser: '******'"); if (WorkSpace.UserProfile.SourceControlType == SourceControlBase.eSourceControlType.GIT && value == "") { value = "Test"; } WorkSpace.UserProfile.SourceControlUser = value; scUser = value; break; case "SourceControlPassword": Reporter.ToLog(eLogLevel.DEBUG, "Selected SourceControlPassword: '******'"); WorkSpace.UserProfile.SourceControlPass = value; scPswd = value; break; case "PasswordEncrypted": Reporter.ToLog(eLogLevel.DEBUG, "PasswordEncrypted: '" + value + "'"); string pswd = WorkSpace.UserProfile.SourceControlPass; if (value == "Y") { pswd = EncryptionHandler.DecryptwithKey(WorkSpace.UserProfile.SourceControlPass, App.ENCRYPTION_KEY); } if (WorkSpace.UserProfile.SourceControlType == SourceControlBase.eSourceControlType.GIT && pswd == "") { pswd = "Test"; } WorkSpace.UserProfile.SourceControlPass = pswd; break; case "SourceControlProxyServer": Reporter.ToLog(eLogLevel.DEBUG, "Selected SourceControlProxyServer: '" + value + "'"); if (value == "") { WorkSpace.UserProfile.SolutionSourceControlConfigureProxy = false; } else { WorkSpace.UserProfile.SolutionSourceControlConfigureProxy = true; } if (value != "" && !value.ToUpper().StartsWith("HTTP://")) { value = "http://" + value; } WorkSpace.UserProfile.SolutionSourceControlProxyAddress = value; break; case "SourceControlProxyPort": if (value == "") { WorkSpace.UserProfile.SolutionSourceControlConfigureProxy = false; } else { WorkSpace.UserProfile.SolutionSourceControlConfigureProxy = true; } Reporter.ToLog(eLogLevel.INFO, "Selected SourceControlProxyPort: '" + value + "'"); WorkSpace.UserProfile.SolutionSourceControlProxyPort = value; break; case "Solution": if (scURL != null && scUser != "" && scPswd != null) { Reporter.ToLog(eLogLevel.DEBUG, "Downloading Solution from source control"); if (value.IndexOf(".git") != -1) { App.DownloadSolution(value.Substring(0, value.IndexOf(".git") + 4)); } else { App.DownloadSolution(value); } } Reporter.ToLog(eLogLevel.DEBUG, "Loading the Solution: '" + value + "'"); try { if (App.SetSolution(value) == false) { Reporter.ToLog(eLogLevel.ERROR, "Failed to load the Solution"); return(false); } } catch (Exception ex) { Reporter.ToLog(eLogLevel.ERROR, "Failed to load the Solution"); Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex); return(false); } break; case "Env": Reporter.ToLog(eLogLevel.DEBUG, "Selected Environment: '" + value + "'"); ProjEnvironment env = WorkSpace.Instance.SolutionRepository.GetAllRepositoryItems <ProjEnvironment>().Where(x => x.Name.ToLower().Trim() == value.ToLower().Trim()).FirstOrDefault(); if (env != null) { App.RunsetExecutor.RunsetExecutionEnvironment = env; } else { Reporter.ToLog(eLogLevel.ERROR, "Failed to find matching Environment in the Solution"); return(false); } break; case "RunSet": Reporter.ToLog(eLogLevel.DEBUG, string.Format("Selected {0}: '{1}'", GingerDicser.GetTermResValue(eTermResKey.RunSet), value)); ObservableList <RunSetConfig> RunSets = WorkSpace.Instance.SolutionRepository.GetAllRepositoryItems <RunSetConfig>(); RunSetConfig runSetConfig = RunSets.Where(x => x.Name.ToLower().Trim() == value.ToLower().Trim()).FirstOrDefault(); if (runSetConfig != null) { WorkSpace.RunsetExecutor.RunSetConfig = runSetConfig; } else { Reporter.ToLog(eLogLevel.ERROR, string.Format("Failed to find matching {0} in the Solution", GingerDicser.GetTermResValue(eTermResKey.RunSet))); return(false); } break; default: Reporter.ToLog(eLogLevel.ERROR, "Un Known argument: '" + param + "'"); return(false); } } return(true); }
private bool ProcessCommandLineArgs() { // New option with one arg to config file // resole spaces and quotes mess in commnd arg + more user friednly to edit // We expect only AutoRun --> File location try { string[] Args = Environment.GetCommandLineArgs(); // We xpect Autorun as arg[1] string[] arg1 = Args[1].Split('='); if (arg1[0] != "ConfigFile") { Reporter.ToLog(eLogLevel.ERROR, "'ConfigFile' argument was not found."); return(false); } string AutoRunFileName = arg1[1]; Reporter.ToLog(eLogLevel.INFO, "Reading all arguments from the Config file placed at: '" + AutoRunFileName + "'"); string[] lines = System.IO.File.ReadAllLines(AutoRunFileName); string scURL = null; string scUser = null; string scPswd = null; foreach (string arg in lines) { int i = arg.IndexOf('='); string param = arg.Substring(0, i).Trim(); string value = arg.Substring(i + 1).Trim(); switch (param) { case "SourceControlType": Reporter.ToLogAndConsole(eLogLevel.INFO, "Selected SourceControlType: '" + value + "'"); if (value.Equals("GIT")) { App.UserProfile.SourceControlType = SourceControlBase.eSourceControlType.GIT; } else if (value.Equals("SVN")) { App.UserProfile.SourceControlType = SourceControlBase.eSourceControlType.SVN; } else { App.UserProfile.SourceControlType = SourceControlBase.eSourceControlType.None; } break; case "SourceControlUrl": Reporter.ToLogAndConsole(eLogLevel.INFO, "Selected SourceControlUrl: '" + value + "'"); if (App.UserProfile.SourceControlType == SourceControlBase.eSourceControlType.SVN) { if (!value.ToUpper().Contains("/SVN") && !value.ToUpper().Contains("/SVN/")) { value = value + "svn/"; } if (!value.ToUpper().EndsWith("/")) { value = value + "/"; } } App.UserProfile.SourceControlURL = value; scURL = value; break; case "SourceControlUser": Reporter.ToLogAndConsole(eLogLevel.INFO, "Selected SourceControlUser: '******'"); if (App.UserProfile.SourceControlType == SourceControlBase.eSourceControlType.GIT && value == "") { value = "Test"; } App.UserProfile.SourceControlUser = value; scUser = value; break; case "SourceControlPassword": Reporter.ToLogAndConsole(eLogLevel.INFO, "Selected SourceControlPassword: '******'"); App.UserProfile.SourceControlPass = value; scPswd = value; break; case "PasswordEncrypted": Reporter.ToLogAndConsole(eLogLevel.INFO, "PasswordEncrypted: '" + value + "'"); string pswd = App.UserProfile.SourceControlPass; if (value == "Y") { pswd = EncryptionHandler.DecryptwithKey(App.UserProfile.SourceControlPass, App.ENCRYPTION_KEY); } if (App.UserProfile.SourceControlType == SourceControlBase.eSourceControlType.GIT && pswd == "") { pswd = "Test"; } App.UserProfile.SourceControlPass = pswd; break; case "SourceControlProxyServer": Reporter.ToLogAndConsole(eLogLevel.INFO, "Selected SourceControlProxyServer: '" + value + "'"); if (value == "") { App.UserProfile.SolutionSourceControlConfigureProxy = false; } else { App.UserProfile.SolutionSourceControlConfigureProxy = true; } if (value != "" && !value.ToUpper().StartsWith("HTTP://")) { value = "http://" + value; } App.UserProfile.SolutionSourceControlProxyAddress = value; break; case "SourceControlProxyPort": if (value == "") { App.UserProfile.SolutionSourceControlConfigureProxy = false; } else { App.UserProfile.SolutionSourceControlConfigureProxy = true; } Reporter.ToLogAndConsole(eLogLevel.INFO, "Selected SourceControlProxyPort: '" + value + "'"); App.UserProfile.SolutionSourceControlProxyPort = value; break; case "Solution": if (scURL != null && scUser != "" && scPswd != null) { Reporter.ToLogAndConsole(eLogLevel.INFO, "Downloading Solution from source control"); if (value.IndexOf(".git") != -1) { App.DownloadSolution(value.Substring(0, value.IndexOf(".git") + 4)); } else { App.DownloadSolution(value); } } Reporter.ToLog(eLogLevel.INFO, "Loading the Solution: '" + value + "'"); try { if (App.SetSolution(value) == false) { Reporter.ToLog(eLogLevel.ERROR, "Failed to load the Solution"); return(false); } } catch (Exception ex) { Reporter.ToLog(eLogLevel.ERROR, "Failed to load the Solution"); Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}"); return(false); } break; case "Env": Reporter.ToLog(eLogLevel.INFO, "Selected Environment: '" + value + "'"); ProjEnvironment env = WorkSpace.Instance.SolutionRepository.GetAllRepositoryItems <ProjEnvironment>().Where(x => x.Name.ToLower().Trim() == value.ToLower().Trim()).FirstOrDefault(); if (env != null) { RunsetExecutionEnvironment = env; } else { Reporter.ToLog(eLogLevel.ERROR, "Failed to find matching Environment in the Solution"); return(false); } break; case "RunSet": Reporter.ToLog(eLogLevel.INFO, string.Format("Selected {0}: '{1}'", GingerDicser.GetTermResValue(eTermResKey.RunSet), value)); ObservableList <RunSetConfig> RunSets = WorkSpace.Instance.SolutionRepository.GetAllRepositoryItems <RunSetConfig>(); RunSetConfig runSetConfig = RunSets.Where(x => x.Name.ToLower().Trim() == value.ToLower().Trim()).FirstOrDefault(); if (runSetConfig != null) { App.RunsetExecutor.RunSetConfig = runSetConfig; } else { Reporter.ToLog(eLogLevel.ERROR, string.Format("Failed to find matching {0} in the Solution", GingerDicser.GetTermResValue(eTermResKey.RunSet))); return(false); } break; default: Reporter.ToLog(eLogLevel.ERROR, "Un Known argument: '" + param + "'"); return(false); } } if (RunSetConfig != null && RunsetExecutionEnvironment != null) { return(true); } else { Reporter.ToLog(eLogLevel.ERROR, "Missing key arguments which required for execution"); return(false); } } catch (Exception ex) { Reporter.ToLog(eLogLevel.ERROR, "Exception occurred during command line arguments processing", ex); return(false); } }
private void LoadALMDetailsFromJSON(GingerExecConfig gingerExecConfig) { foreach (AlmDetails almDetails in gingerExecConfig.AlmsDetails) { ALMIntegration.eALMType almTypeToConfigure; if (Enum.TryParse <ALMIntegration.eALMType>(almDetails.ALMType, out almTypeToConfigure)) { try { ALMConfig solutionAlmConfig = WorkSpace.Instance.Solution.ALMConfigs.FirstOrDefault(x => x.AlmType == almTypeToConfigure); if (solutionAlmConfig == null) { //ADD solutionAlmConfig = new ALMConfig() { AlmType = almTypeToConfigure }; WorkSpace.Instance.Solution.ALMConfigs.Add(solutionAlmConfig); } ALMUserConfig userProfileAlmConfig = WorkSpace.Instance.UserProfile.ALMUserConfigs.FirstOrDefault(x => x.AlmType == almTypeToConfigure); if (userProfileAlmConfig == null) { //ADD userProfileAlmConfig = new ALMUserConfig() { AlmType = almTypeToConfigure }; WorkSpace.Instance.UserProfile.ALMUserConfigs.Add(userProfileAlmConfig); } if (almDetails.ALMSubType != null) { solutionAlmConfig.JiraTestingALM = (ALMIntegration.eTestingALMType)Enum.Parse(typeof(ALMIntegration.eTestingALMType), almDetails.ALMSubType); } if (almDetails.ServerURL != null) { solutionAlmConfig.ALMServerURL = almDetails.ServerURL; userProfileAlmConfig.ALMServerURL = almDetails.ServerURL; } if (almDetails.User != null) { solutionAlmConfig.ALMUserName = almDetails.User; userProfileAlmConfig.ALMUserName = almDetails.User; } if (almDetails.Password != null) { if (almDetails.PasswordEncrypted) { string pass = EncryptionHandler.DecryptwithKey(almDetails.Password); solutionAlmConfig.ALMPassword = pass; userProfileAlmConfig.ALMPassword = pass; } else { solutionAlmConfig.ALMPassword = almDetails.Password; userProfileAlmConfig.ALMPassword = almDetails.Password; } } if (almDetails.Domain != null) { solutionAlmConfig.ALMDomain = almDetails.Domain; } if (almDetails.Project != null) { solutionAlmConfig.ALMProjectName = almDetails.Project; } if (almDetails.ProjectKey != null) { solutionAlmConfig.ALMProjectKey = almDetails.ProjectKey; } if (almDetails.ConfigPackageFolderPath != null) { solutionAlmConfig.ALMConfigPackageFolderPath = almDetails.ConfigPackageFolderPath; userProfileAlmConfig.ALMConfigPackageFolderPath = almDetails.ConfigPackageFolderPath; } if (almDetails.UseRest != null) { solutionAlmConfig.UseRest = (bool)almDetails.UseRest; } if (almDetails.IsDefault != null) { if (almDetails.IsDefault == true) { //clear previous default ALMConfig currentDefAlm = WorkSpace.Instance.Solution.ALMConfigs.Where(x => x.DefaultAlm == true).FirstOrDefault(); currentDefAlm.DefaultAlm = false; } solutionAlmConfig.DefaultAlm = (bool)almDetails.IsDefault; } } catch (Exception ex) { throw new Exception(string.Format("Failed to load the ALM type: '{0}' details, due to error: '{1}'", almDetails.ALMType, ex.Message), ex); } } else { throw new Exception(string.Format("Failed to find the ALM type: '{0}'", almDetails.ALMType)); } } }
public bool Send_SMTP() { try { if (string.IsNullOrEmpty(Email.MailFrom)) { Email.Event = "Failed: Please provide FROM email address."; return(false); } if (string.IsNullOrEmpty(Email.MailTo)) { Email.Event = "Failed: Please provide TO email address."; return(false); } if (string.IsNullOrEmpty(Email.Subject)) { Email.Event = "Failed: Please provide email subject."; return(false); } if (string.IsNullOrEmpty(Email.SMTPMailHost)) { Email.Event = "Failed: Please provide Mail Host"; return(false); } mVE.Value = Email.MailFrom; var fromAddress = new MailAddress(mVE.ValueCalculated, Email.MailFromDisplayName); mVE.Value = Email.SMTPMailHost; string mailHost = mVE.ValueCalculated; if (Email.SMTPPort == 0 || Email.SMTPPort == null) { Email.SMTPPort = 25; } var smtp = new SmtpClient() { Host = mailHost, // amdocs config Port = (int)Email.SMTPPort, EnableSsl = Email.EnableSSL, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = !Email.ConfigureCredential }; if (Email.ConfigureCredential) { string DecryptPass = EncryptionHandler.DecryptwithKey(Email.SMTPPass); if (!string.IsNullOrEmpty(DecryptPass)) { smtp.Credentials = new NetworkCredential(Email.SMTPUser, DecryptPass); } else { smtp.Credentials = new NetworkCredential(Email.SMTPUser, Email.SMTPPass); } } mVE.Value = Email.MailTo; string emails = mVE.ValueCalculated; Array arrEmails = emails.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); System.Net.Mail.MailMessage myMail = new System.Net.Mail.MailMessage(); foreach (string email in arrEmails) { myMail.To.Add(email); } //Add CC if (!String.IsNullOrEmpty(Email.MailCC)) { Array arrCCEmails = Email.MailCC.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); foreach (string MailCC1 in arrCCEmails) { myMail.CC.Add(MailCC1); } } mVE.Value = Email.Subject; string subject = mVE.ValueCalculated; mVE.Value = Email.Body; string body = mVE.ValueCalculated; myMail.From = fromAddress; myMail.IsBodyHtml = IsBodyHTML; myMail.Subject = subject.Replace('\r', ' ').Replace('\n', ' '); myMail.Body = body; foreach (string AttachmentFileName in Email.Attachments) { if (String.IsNullOrEmpty(AttachmentFileName) == false) { Attachment a = new Attachment(WorkSpace.Instance.OSHelper.AdjustFilePath(AttachmentFileName)); myMail.Attachments.Add(a); } } if (alternateView != null) { myMail.AlternateViews.Add(alternateView); } smtp.Send(myMail); //clear and dispose attachments if (myMail.Attachments != null) { foreach (Attachment attachment in myMail.Attachments) { attachment.Dispose(); } myMail.Attachments.Clear(); myMail.Attachments.Dispose(); } myMail.Dispose(); return(true); } catch (Exception ex) { if (ex.Message.Contains("Mailbox unavailable")) { Email.Event = "Failed: Please provide correct FROM email address"; } else if (ex.StackTrace.Contains("System.Runtime.InteropServices.Marshal.GetActiveObject")) { Email.Event = "Please make sure ginger/outlook opened in same security context (Run as administrator or normal user)"; } else if (ex.StackTrace.Contains("System.Security.Authentication.AuthenticationException") || ex.StackTrace.Contains("System.Net.Sockets.SocketException")) { Email.Event = "Please check SSL configuration"; } else { Email.Event = "Failed: " + ex.Message; } Reporter.ToLog(eLogLevel.ERROR, "Failed to send mail", ex); return(false); } }
public override bool Connect() { try { /// /// ConnectionString format /// "mongodb://*****:*****@localhost/DB" /// if (Db.ConnectionString != null && !string.IsNullOrEmpty(Db.ConnectionString)) { var connectionString = Db.DatabaseOperations.ConnectionStringCalculated.ToString(); DbName = MongoUrl.Create(Db.DatabaseOperations.ConnectionStringCalculated.ToString()).DatabaseName; if (DbName == null) { return(false); } mMongoClient = new MongoClient(connectionString); } else { /// /// Host format /// "mongodb://HostOrIP:27017/DBName" /// string[] HostPortDB = Db.DatabaseOperations.TNSCalculated.Split('/'); string[] HostPort = HostPortDB[0].Split(':'); //need to get db name MongoCredential mongoCredential = null; MongoClientSettings mongoClientSettings = null; if (HostPort.Length == 2 && HostPortDB.Length == 2) { if (string.IsNullOrEmpty(HostPortDB[HostPortDB.Length - 1])) { Reporter.ToLog(eLogLevel.ERROR, "Database is not mentioned in the TNS/Host."); return(false); } if (string.IsNullOrEmpty(Db.Pass) && string.IsNullOrEmpty(Db.User)) { mongoClientSettings = new MongoClientSettings { Server = new MongoServerAddress(HostPort[0], Convert.ToInt32(HostPort[1])) }; } else { String deCryptValue = EncryptionHandler.DecryptwithKey(Db.DatabaseOperations.PassCalculated.ToString()); if (!string.IsNullOrEmpty(deCryptValue)) { mongoCredential = MongoCredential.CreateCredential(HostPortDB[HostPortDB.Length - 1], Db.DatabaseOperations.UserCalculated, deCryptValue); } else { mongoCredential = MongoCredential.CreateCredential(HostPortDB[HostPortDB.Length - 1], Db.DatabaseOperations.UserCalculated, Db.DatabaseOperations.PassCalculated.ToString()); } mongoClientSettings = new MongoClientSettings { Server = new MongoServerAddress(HostPort[0], Convert.ToInt32(HostPort[1])), //UseSsl = true, Credentials = new[] { mongoCredential } }; } DbName = HostPortDB[HostPortDB.Length - 1]; mMongoClient = new MongoClient(mongoClientSettings); } else { return(false); } } //check dbname is present in the dblist if (GetDatabaseList().Contains(DbName)) { return(true); } else { return(false); } } catch (Exception e) { Reporter.ToLog(eLogLevel.ERROR, "Failed to connect to Mongo DB", e); return(false); } }