Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/ginger analytics config page b #3895

Merged
merged 14 commits into from
Sep 16, 2024
1 change: 1 addition & 0 deletions Ginger/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ csharp_style_prefer_extended_property_pattern = true:suggestion
csharp_style_var_for_built_in_types = true:none
csharp_style_var_when_type_is_apparent = true:none
csharp_style_var_elsewhere = true:none
csharp_indent_braces = false

[*.vb]
#### Naming styles ####
Expand Down
5 changes: 4 additions & 1 deletion Ginger/Ginger/Environments/AppsListPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:Ginger="clr-namespace:Ginger" x:Class="Ginger.Environments.AppsListPage"
xmlns:UserControlsLib="clr-namespace:Ginger.UserControlsLib"
xmlns:usercontrols2="clr-namespace:Amdocs.Ginger.UserControls"
mc:Ignorable="d"
xmlns:h="clr-namespace:Ginger.Help"
xmlns:usercontrols="clr-namespace:Ginger.UserControlsLib" h:GingerHelpProvider.HelpString="Environment"
Expand All @@ -29,7 +30,9 @@
<StackPanel>
<DockPanel>
<Label Style="{StaticResource $LabelStyle}" Content="Release:"/>
<ComboBox x:Name="xReleaseCombobox" Style="{StaticResource $FlatEditInputComboBoxStyle}" MinWidth="300px" HorizontalAlignment="Left"></ComboBox>
<ComboBox x:Name="xReleaseCombobox" IsEnabled="True" Style="{StaticResource $FlatEditInputComboBoxStyle}" MinWidth="300px" HorizontalAlignment="Left"></ComboBox>
<usercontrols2:ImageMakerControl x:Name="xProcessingImage" ImageType="Processing" Margin="640,0,0,0" HorizontalAlignment="Left" Height="30" Width="20" Visibility="Hidden"></usercontrols2:ImageMakerControl>
<Button x:Name="xGASyncBtn" IsEnabled="True" Style="{StaticResource $InputButtonStyle}" Visibility="Collapsed" Margin="0,0,10,0" HorizontalAlignment="Right" Click="xGASyncBtn_Click" FontWeight="Bold" Content="Sync with Ginger Analytics"/>
</DockPanel>

<CheckBox x:Name="xPublishcheckbox" Content="Publish" ToolTip="Publish to third party applications" DockPanel.Dock="Top" HorizontalAlignment="Left" Margin="0,5,0,0" Style="{StaticResource $CeckBoxStyle}"/>
Expand Down
170 changes: 169 additions & 1 deletion Ginger/Ginger/Environments/AppsListPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,24 @@ limitations under the License.
using Amdocs.Ginger.Common;
using Amdocs.Ginger.CoreNET.Run.SolutionCategory;
using Amdocs.Ginger.Repository;
using Ginger.Environments.GingerAnalyticsEnvWizardLib;
using Ginger.ExternalConfigurations;
using Ginger.SolutionWindows.TreeViewItems.EnvironmentsTreeItems;
using Ginger.UserControls;
using Ginger.UserControlsLib;
using GingerCore.Environments;
using GingerCore.GeneralLib;
using GingerCoreNET.SolutionRepositoryLib.RepositoryObjectsLib.PlatformsLib;
using GingerTest.WizardLib;
using Microsoft.Graph;
using Microsoft.Identity.Client.Kerberos;
using Microsoft.VisualStudio.Services.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using static Ginger.Environments.GingerAnalyticsEnvWizardLib.GingerAnalyticsAPIResponseInfo;

namespace Ginger.Environments
{
Expand All @@ -40,6 +47,8 @@ namespace Ginger.Environments
public partial class AppsListPage : GingerUIPage
{
public ProjEnvironment AppEnvironment { get; set; }
public AddGingerAnalyticsEnvPage AddGingerAnalyticsEnvPage;
public GingerAnalyticsAPI GingerAnalyticsAPI;
public AppsListPage(ProjEnvironment env)
{
InitializeComponent();
Expand All @@ -50,12 +59,23 @@ public AppsListPage(ProjEnvironment env)
SetGridView();
SetGridData();

if (AppEnvironment.GAFlag)
{
EnvNameTextBox.IsEnabled = false;
xGASyncBtn.Visibility = Visibility.Visible;
}
else
{
EnvNameTextBox.IsEnabled = true;
xGASyncBtn.Visibility = Visibility.Collapsed;
InitReleaseComboBox();
}

BindingHandler.ObjFieldBinding(EnvNameTextBox, TextBox.TextProperty, env, ProjEnvironment.Fields.Name);
EnvNameTextBox.AddValidationRule(new EnvironemntNameValidationRule());
xShowIDUC.Init(AppEnvironment);
BindingHandler.ObjFieldBinding(xPublishcheckbox, CheckBox.IsCheckedProperty, AppEnvironment, nameof(RepositoryItemBase.Publish));

InitReleaseComboBox();

grdApps.btnAdd.AddHandler(Button.ClickEvent, new RoutedEventHandler(AddApp));
grdApps.AddToolbarTool("@Share_16x16.png", "Add Selected Applications to All Environments", new RoutedEventHandler(AddAppsToOtherEnvironments));
Expand Down Expand Up @@ -158,5 +178,153 @@ private void EnvNameTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
grdApps.Title = $"'{EnvNameTextBox.Text}' Environment Applications";
}

private async void xGASyncBtn_Click(object sender, RoutedEventArgs e)
{
try
{
xGASyncBtn.IsEnabled = false;
ShowLoader();
AddGingerAnalyticsEnvPage = new();
GingerAnalyticsAPI = new();
AddGingerAnalyticsEnvPage.environmentListGA = await GingerAnalyticsAPI.FetchApplicationDataFromGA(AppEnvironment.GingerAnalyticsEnvId.ToString(), AddGingerAnalyticsEnvPage.environmentListGA);

foreach (var appEnv in AddGingerAnalyticsEnvPage.environmentListGA)
{
var appListEnv = appEnv.Value.GingerAnalyticsApplications;
foreach (var item in appListEnv)
{
var existingApp = AppEnvironment.Applications.FirstOrDefault(k => k.GAId == item.Id);
if (existingApp != null)
{
UpdateExistingApplication(existingApp, item);
}
else
{
AddNewApplication(item);
}
}
}
}
catch (Exception ex)
{
Reporter.ToLog(eLogLevel.ERROR, "Failed to Sync with Ginger Analytics", ex);
}
finally
{
HideLoader();
xGASyncBtn.IsEnabled = true;
}
}

private void UpdateExistingApplication(EnvApplication existingApp, GingerAnalyticsApplication item)
{
if (!existingApp.Equals(item))
{
existingApp.Name = item.Name;
existingApp.Platform = MapToPlatformType(item.GAApplicationParameters.FirstOrDefault(k => k.Name == "Application Type")?.Value);
existingApp.Url = item.GAApplicationParameters.FirstOrDefault(k => k.Name == "Application URL")?.Value;

// Add all other parameters to GeneralParams
foreach (var param in item.GAApplicationParameters)
{
if (param.Name != "Application Type" && param.Name != "Application URL")
{
existingApp.GeneralParams.Add(new GeneralParam { Name = param.Name, Value = param.Value });
}
}

UpdateApplicationPlatform(existingApp, item);
}
}

private void AddNewApplication(GingerAnalyticsApplication item)
{
if (!string.IsNullOrEmpty(item.Name) && !string.IsNullOrEmpty(item.Id))
{
var platformType = MapToPlatformType(item.GAApplicationParameters.FirstOrDefault(k => k.Name == "Application Type")?.Value);
var appUrl = item.GAApplicationParameters.FirstOrDefault(k => k.Name == "Application URL")?.Value;

EnvApplication newEnvApp = new() { Name = item.Name, Platform = platformType, GAId = item.Id, Active = true, Url = appUrl, GeneralParams = new ObservableList<GeneralParam>() };

// Add all other parameters to GeneralParams
foreach (var param in item.GAApplicationParameters)
{
if (param.Name != "Application Type" && param.Name != "Application URL")
{
newEnvApp.GeneralParams.Add(new GeneralParam { Name = param.Name, Value = param.Value });
}
}

AppEnvironment.Applications.Add(newEnvApp);

UpdateApplicationPlatform(newEnvApp, item);
}
}

private void UpdateApplicationPlatform(EnvApplication app, GingerAnalyticsApplication item)
{
var existingPlatform = WorkSpace.Instance.Solution.ApplicationPlatforms.FirstOrDefault(k => k.GAId == item.Id);
if (existingPlatform == null)
{
AddApplicationPlatform(app, item);
}
else
{
existingPlatform.AppName = WorkSpace.Instance.Solution.ApplicationPlatforms.FirstOrDefault(k => k.AppName == item.Name) == null
? item.Name : item.Name + "_GingerAnalytics";
existingPlatform.Platform = app.Platform;
}
}

private void AddApplicationPlatform(EnvApplication app, GingerAnalyticsApplication item)
{
var selectedApp = new ApplicationPlatform
{
AppName = WorkSpace.Instance.Solution.ApplicationPlatforms.FirstOrDefault(k => k.AppName == item.Name) != null
? item.Name + "_GingerAnalytics" : item.Name,
Platform = app.Platform,
GAId = item.Id
};

WorkSpace.Instance.Solution.ApplicationPlatforms.Add(selectedApp);
}

private ePlatformType MapToPlatformType(string applicationType)
{
return applicationType switch
{
"Web" => ePlatformType.Web,
"Mobile" => ePlatformType.Mobile,
"Unix" => ePlatformType.Unix,
"ASCF" => ePlatformType.ASCF,
"DOS" => ePlatformType.DOS,
"VBScript" => ePlatformType.VBScript,
"WebServices" => ePlatformType.WebServices,
"PowerBuilder" => ePlatformType.PowerBuilder,
"Java" => ePlatformType.Java,
"MainFrame" => ePlatformType.MainFrame,
"Service" => ePlatformType.Service,
"Windows" => ePlatformType.Windows,
"NA" => ePlatformType.NA,
_ => throw new ArgumentException($"Unknown platform type: {applicationType}")
};
}

private void HideLoader()
{
this.Dispatcher.Invoke(() =>
{
xProcessingImage.Visibility = Visibility.Hidden;
});
}

private void ShowLoader()
{
this.Dispatcher.Invoke(() =>
{
xProcessingImage.Visibility = Visibility.Visible;
});
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<Page x:Class="Ginger.Environments.GingerAnalyticsEnvWizardLib.AddGingerAnalyticsEnvPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Ginger.Environments.GingerAnalyticsEnvWizardLib"
xmlns:usercontrols2="clr-namespace:Amdocs.Ginger.UserControls"
xmlns:UserControlsLib="clr-namespace:Ginger.UserControlsLib"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
Title="AddGingerAnalyticsEnvPage">

<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="40"/>
<RowDefinition Height="40"/>
<RowDefinition Height="40"/>
<RowDefinition Height="40"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="90"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>

<!-- Project Label and ComboBox -->
<Label x:Name="xProject" Grid.Column="0" Grid.Row="0" Content="Project :" Margin="0,10,0,0" Style="{StaticResource $LabelStyle}"/>
<ComboBox x:Name="xProjectComboBox" Grid.Column="1" Margin="0,0,0,0" Style="{StaticResource $FlatInputComboBoxStyle}" HorizontalAlignment="Left" SelectionChanged="xProjectComboBox_SelectionChanged" ToolTip="Select Ginger Analytics Project" Width="180"/>


<!-- Architecture Label and ComboBox -->
<Label x:Name="xArchitecture" Grid.Row="1" Grid.Column="0" Content="Architecture :" Margin="0,10,0,0" Style="{StaticResource $LabelStyle}"/>
<ComboBox x:Name="xArchitectureComboBox" Grid.Row="1" Grid.Column="1" Margin="0,0,0,0" Style="{StaticResource $FlatInputComboBoxStyle}" HorizontalAlignment="Left" SelectionChanged="xArchitectureComboBox_SelectionChanged" ToolTip="Select Ginger Analytics Architecture" Width="180"/>


<!-- Environment Label and ComboBox -->
<Label x:Name="xEnvironment" Grid.Row="2" Grid.Column="0" Content="Environment :" Margin="0,10,0,0" Style="{StaticResource $LabelStyle}"/>
<UserControlsLib:MultiSelectComboBox x:Name="xEnvironmentComboBox" Grid.Row="2" Grid.Column="1" Margin="0,0,0,0" HorizontalAlignment="Left" ToolTip="Select Ginger Analytics Environment" Width="180"/>

</Grid>
</Page>
Loading
Loading