diff --git a/Ginger/Ginger/Activities/ActivityDetailsPage.xaml.cs b/Ginger/Ginger/Activities/ActivityDetailsPage.xaml.cs index ec335a39e2..b9e945a5fe 100644 --- a/Ginger/Ginger/Activities/ActivityDetailsPage.xaml.cs +++ b/Ginger/Ginger/Activities/ActivityDetailsPage.xaml.cs @@ -170,8 +170,13 @@ private void BindControls() xTargetApplicationComboBox.ItemsSource = WorkSpace.Instance.Solution.GetSolutionTargetApplications(); - - + + if (WorkSpace.Instance!=null && WorkSpace.Instance.Solution!=null && WorkSpace.Instance.Solution.ApplicationPlatforms!=null) + { + WorkSpace.Instance.Solution.ApplicationPlatforms.CollectionChanged -= OnApplicationPlatformChanged; + WorkSpace.Instance.Solution.ApplicationPlatforms.CollectionChanged += OnApplicationPlatformChanged; + } + xTargetApplicationlbl.Content = $"{GingerDicser.GetTermResValue(eTermResKey.TargetApplication)}:"; xTargetApplicationComboBox.SelectedValuePath = nameof(TargetApplication.AppName); xTargetApplicationComboBox.DisplayMemberPath = nameof(TargetApplication.AppName); @@ -216,6 +221,31 @@ private void BindControls() mActivity.DirtyTracking = Amdocs.Ginger.Common.Enums.eDirtyTracking.Started; } + private void OnApplicationPlatformChanged(object? sender, NotifyCollectionChangedEventArgs e) + { + xTargetApplicationComboBox.ItemsSource = WorkSpace.Instance.Solution.GetSolutionTargetApplications(); + + if(xTargetApplicationComboBox.Items == null || mActivity == null || mActivity.TargetApplication == null) + { + return; + } + + int pointer = 0; + + foreach(TargetApplication targetApplication in xTargetApplicationComboBox.Items) + { + + if (targetApplication.AppName.Equals(mActivity.TargetApplication)) + { + xTargetApplicationComboBox.SelectedIndex = pointer; + } + + pointer++; + } + + TargetAppSelectedComboBox(); + } + private void UserProfile_PropertyChanged(object? sender, PropertyChangedEventArgs e) { if(string.Equals(e.PropertyName, nameof(UserProfile.ShowEnterpriseFeatures))) diff --git a/Ginger/Ginger/SolutionWindows/AddApplicationPage.xaml.cs b/Ginger/Ginger/SolutionWindows/AddApplicationPage.xaml.cs index 6e07a0b568..84c549ac42 100644 --- a/Ginger/Ginger/SolutionWindows/AddApplicationPage.xaml.cs +++ b/Ginger/Ginger/SolutionWindows/AddApplicationPage.xaml.cs @@ -171,6 +171,7 @@ private void OKButton_Click(object sender, RoutedEventArgs e) mSolution.ApplicationPlatforms.Add(selectedApp); + if (!msgSelection.Equals(eUserMsgSelection.Yes)) { this.NewlyAddedApplicationPlatform = selectedApp; diff --git a/Ginger/GingerCoreNET/Database/NoSqlBase/GingerCassandra.cs b/Ginger/GingerCoreNET/Database/NoSqlBase/GingerCassandra.cs index 0d9c522dd5..c50b5dd112 100644 --- a/Ginger/GingerCoreNET/Database/NoSqlBase/GingerCassandra.cs +++ b/Ginger/GingerCoreNET/Database/NoSqlBase/GingerCassandra.cs @@ -17,13 +17,18 @@ limitations under the License. #endregion using Amdocs.Ginger.Common; +using Amdocs.Ginger.CoreNET.RunLib.CLILib; using Cassandra; using GingerCore.Actions; using GingerCore.NoSqlBase.DataAccess; +using HBaseNet.Const; +using Microsoft.Graph; +using Microsoft.Graph.SecurityNamespace; using System; using System.Collections.Generic; using System.Linq; using System.Reflection; +using System.Security.Authentication; using System.Text.RegularExpressions; using System.Threading.Tasks; @@ -37,32 +42,72 @@ public class GingerCassandra : NoSqlBase dynamic myclass = null; string mUDTName = null; - - public override bool Connect() { try { - string queryTimeoutString = "querytimeout="; + const string queryTimeoutString = "querytimeout="; + const string sslString = "ssl="; int queryTimeout = 20000;//default timeout (20 seconds). - if (Db.DatabaseOperations.TNSCalculated.ToLower().Contains(queryTimeoutString.ToLower())) + string[] queryArray = Db.DatabaseOperations.TNSCalculated.ToLower().Split(';'); + SSLOptions sslOptions = null; + for (int i = 1; i < queryArray.Length; i++) { - string queryTimeoutValue = Db.DatabaseOperations.TNSCalculated.Substring(Db.DatabaseOperations.TNSCalculated.ToLower().IndexOf(queryTimeoutString.ToLower()) + queryTimeoutString.Length); - queryTimeout = Convert.ToInt32(queryTimeoutValue) * 1000; + switch (queryArray[i]) + { + case var str when str.Contains(queryTimeoutString): + string queryTimeoutValue = str.Substring(str.IndexOf(queryTimeoutString) + queryTimeoutString.Length); + if (!int.TryParse(queryTimeoutValue, out int timeout)) + { + throw new ArgumentException("Query timeout value is not a valid integer."); + } + queryTimeout = Convert.ToInt32(queryTimeoutValue) * 1000; + break; + + case var str when str.Contains(sslString): + string sslValue = str.Substring(str.IndexOf(sslString) + sslString.Length); + sslOptions = SetupSslOptions(sslValue); + break; + default: + throw new ArgumentException("Please check connection string."); + } } - - string[] HostKeySpace = Db.DatabaseOperations.TNSCalculated.Split('/'); + string[] HostKeySpace = queryArray[0].ToLower().Replace("http://", "").Replace("https://", "").Split('/'); string[] HostPort = HostKeySpace[0].Split(':'); if (HostPort.Length == 2) { if (string.IsNullOrEmpty(Db.Pass) && string.IsNullOrEmpty(Db.User)) { - cluster = Cluster.Builder().AddContactPoint(HostPort[0]).WithPort(Int32.Parse(HostPort[1])).WithQueryTimeout(queryTimeout).Build(); + if (sslOptions ==null) + { + cluster = Cluster.Builder().AddContactPoint(HostPort[0]).WithPort(Int32.Parse(HostPort[1])).WithQueryTimeout(queryTimeout).Build(); + } + else + { + cluster = Cluster.Builder() + .AddContactPoint(HostPort[0]) + .WithPort(Int32.Parse(HostPort[1])) + .WithSSL(sslOptions) + .WithQueryTimeout(queryTimeout) + .Build(); + } } else { - cluster = Cluster.Builder().WithCredentials(Db.User.ToString(), Db.Pass.ToString()).AddContactPoint(HostPort[0]).WithPort(Int32.Parse(HostPort[1])).WithQueryTimeout(queryTimeout).Build(); + if (sslOptions == null) { + cluster = Cluster.Builder().WithCredentials(Db.User.ToString(), Db.Pass.ToString()).AddContactPoint(HostPort[0]).WithPort(Int32.Parse(HostPort[1])).WithQueryTimeout(queryTimeout).Build(); + } + else + { + cluster = Cluster.Builder() + .AddContactPoint(HostPort[0]) + .WithPort(Int32.Parse(HostPort[1])) + .WithAuthProvider(new PlainTextAuthProvider(Db.User, Db.Pass)) + .WithSSL(sslOptions) + .WithQueryTimeout(queryTimeout) + .Build(); + } } } else @@ -85,8 +130,8 @@ public override bool Connect() } catch (Exception e) { - Reporter.ToLog(eLogLevel.ERROR, "Failed to connect to Cassandra DB", e); - throw (e); + Reporter.ToLog(eLogLevel.ERROR, "Failed to connect to Cassandra DB. Please check Connection String", e); + throw; } } @@ -94,7 +139,7 @@ public override bool MakeSureConnectionIsOpen() { try { - if (session != null) + if (session != null && !session.IsDisposed) { Metadata m = cluster.Metadata; ICollection Keyspaces = m.GetKeyspaces(); @@ -182,8 +227,15 @@ public override Task> GetColumnList(string tablename) private void Disconnect() { - session.Dispose(); - cluster.Dispose(); + try + { + session.Dispose(); + cluster.Dispose(); + } + finally + { + session = null; + } } public Type TypeConverter(RowSet RS, string Type1) @@ -789,5 +841,20 @@ void UpdateOutValues(RowSet RS, Type t = null) i++; } } + + public static SSLOptions SetupSslOptions(string sslParamValue) + { + try + { + var sslProtocol = Enum.Parse(sslParamValue, ignoreCase: true); + return new SSLOptions(sslProtocol, false, (_, _, _, _) => true); + } + catch (ArgumentException e) + { + Reporter.ToLog(eLogLevel.ERROR, "SSL value not correct. Please enter SSL value like Default, None, Ssl2, Ssl3, Tls, Tls11, Tls12, Tls13", e); + Reporter.ToLog(eLogLevel.ERROR, "Note - Also try removing ssl= parameter from connection string", e); + throw new ArgumentException("SSL value not correct. Please enter SSL value like Default, None, Ssl2, Ssl3, Tls, Tls11, Tls12, Tls13."); + } + } } } diff --git a/Ginger/GingerCoreNET/Database/NoSqlBase/GingerCouchbase.cs b/Ginger/GingerCoreNET/Database/NoSqlBase/GingerCouchbase.cs index 4e5c7b0329..85db194f38 100644 --- a/Ginger/GingerCoreNET/Database/NoSqlBase/GingerCouchbase.cs +++ b/Ginger/GingerCoreNET/Database/NoSqlBase/GingerCouchbase.cs @@ -154,6 +154,8 @@ private string GetBucketName(string inputSQL) { string bucketName = string.Empty; string[] bucketNameArray; + const string strUpdate = "update "; + const string strFrom = " from "; if (Action == ActDBValidation.eDBValidationType.RecordCount) { bucketName = inputSQL.Replace("`", ""); @@ -164,11 +166,11 @@ private string GetBucketName(string inputSQL) { if (Action == ActDBValidation.eDBValidationType.UpdateDB) { - bucketName = inputSQL.Substring(inputSQL.ToLower().IndexOf("Update ") + 7); + bucketName = inputSQL.Substring(inputSQL.IndexOf(strUpdate, StringComparison.OrdinalIgnoreCase) + strUpdate.Length); } else { - bucketName = inputSQL.Substring(inputSQL.ToLower().IndexOf(" from ") + 6); + bucketName = inputSQL.Substring(inputSQL.IndexOf(strFrom, StringComparison.OrdinalIgnoreCase) + strFrom.Length); } bucketNameArray = bucketName.Split('.'); bucketName = bucketNameArray[0].Trim();