Skip to content

Commit

Permalink
Code cleaning and small bug fixes (#94)
Browse files Browse the repository at this point in the history
Fixed code that was giving warning on nullable types.
Updated the nuget packages to the latest version
Fixed Delete on SP, Trigger, UDF
  • Loading branch information
sachabruttin authored Dec 2, 2022
1 parent 6f4b37d commit d722b0d
Show file tree
Hide file tree
Showing 91 changed files with 906 additions and 855 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
public interface IFileService
{
T Read<T>(string folderPath, string fileName);
T? Read<T>(string folderPath, string fileName);

void Save<T>(string folderPath, string fileName, T content);

Expand Down
4 changes: 2 additions & 2 deletions src/CosmosDbExplorer.Core/CosmosDbExplorer.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.28.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.31.2" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
</ItemGroup>
</Project>
2 changes: 2 additions & 0 deletions src/CosmosDbExplorer.Core/Models/CosmosContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ public CosmosContainer(ContainerProperties properties)
GeospatialType = properties.GeospatialConfig.GeospatialType.ToLocalType();
}

#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
public CosmosContainer(string id, bool isLargePartition)
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
{
Id = id;
PartitionKeyDefVersion = isLargePartition
Expand Down
4 changes: 2 additions & 2 deletions src/CosmosDbExplorer.Core/Models/CosmosDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public CosmosDatabase(DatabaseProperties properties, int? throughput, bool isSer
}

public string Id { get; }
public string ETag { get; }
public string SelfLink { get; }
public string? ETag { get; }
public string? SelfLink { get; }
public int? Throughput { get; } // Null value indicates a container with no throughput provisioned.
public bool IsServerless { get; }
}
Expand Down
4 changes: 2 additions & 2 deletions src/CosmosDbExplorer.Core/Models/CosmosPermission.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public CosmosPermission()
public string? SelfLink { get; }
public CosmosPermissionMode PermissionMode { get; set; }
public string? PartitionKey;
public string ResourceUri { get; set; }
public string Token { get; }
public string? ResourceUri { get; set; }
public string? Token { get; }
public DateTime? LastModifed { get; }
}

Expand Down
2 changes: 1 addition & 1 deletion src/CosmosDbExplorer.Core/Models/CosmosQueryResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class CosmosResult

public class CosmosQueryResult<T> : CosmosResult
{
public T? Items { get; internal set; }
public T? Items { get; internal set; }
public Exception? Error { get; internal set; }
public string? ContinuationToken { get; internal set; }
public IEnumerable<string> Warnings { get; internal set; } = Array.Empty<string>();
Expand Down
5 changes: 4 additions & 1 deletion src/CosmosDbExplorer/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Toolkit.Mvvm.Messaging;
using CommunityToolkit.Mvvm.Messaging;

namespace CosmosDbExplorer
{
Expand Down Expand Up @@ -151,8 +151,11 @@ private void ConfigureServices(HostBuilderContext context, IServiceCollection se
services.AddTransient<PermissionEditViewModel>();

services.AddTransient<ViewModels.Assets.TriggerTabViewModel>();
services.AddTransient<ViewModels.DatabaseNodes.TriggerNodeViewModel>();
services.AddTransient<ViewModels.Assets.StoredProcedureTabViewModel>();
services.AddTransient<ViewModels.DatabaseNodes.StoredProcedureNodeViewModel>();
services.AddTransient<ViewModels.Assets.UserDefFuncTabViewModel>();
services.AddTransient<ViewModels.DatabaseNodes.UserDefFuncNodeViewModel>();

// Configuration
services.Configure<AppConfig>(context.Configuration.GetSection(nameof(AppConfig)));
Expand Down
2 changes: 1 addition & 1 deletion src/CosmosDbExplorer/AvalonEdit/AvalonCommands.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using ICSharpCode.AvalonEdit;
using Microsoft.Toolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.Input;

namespace CosmosDbExplorer.AvalonEdit
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace CosmosDbExplorer.Behaviors
{
public class BackstageTabNavigationBehavior : Behavior<BackstageTabControl>
{
private IPageService _pageService;
private IPageService? _pageService;

public BackstageTabNavigationBehavior()
{
Expand All @@ -39,6 +39,11 @@ protected override void OnDetaching()

private void OnSelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
if (_pageService is null)
{
throw new NullReferenceException("Please call method Initialize() on the BackstageTabNavigationBehavior instance!");
}

if (e.RemovedItems.Count > 0 && e.RemovedItems[0] is BackstageTabItem oldItem)
{
var content = oldItem.Content as Frame;
Expand All @@ -61,7 +66,7 @@ private void OnSelectionChanged(object sender, System.Windows.Controls.Selection

frame.Navigated += OnNavigated;
tabItem.Content = frame;
var page = _pageService.GetPage(tabItem.Tag as string);
var page = _pageService.GetPage((Type)tabItem.Tag);
frame.Navigate(page);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/CosmosDbExplorer/Behaviors/RibbonPageConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

using Fluent;

using Microsoft.Toolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.ComponentModel;

namespace CosmosDbExplorer.Behaviors
{
Expand Down
9 changes: 4 additions & 5 deletions src/CosmosDbExplorer/Behaviors/RibbonTabsBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,9 @@ public void Unsubscribe()
}
}

private void OnNavigated(object sender, string e)
private void OnNavigated(object? sender, string e)
{
var frame = sender as Frame;
if (frame != null && frame.Content is Page page)
if (sender is Frame frame && frame.Content is Page page)
{
UpdateTabs(page);
}
Expand All @@ -94,7 +93,7 @@ private void SetupHomeGroups(Collection<RibbonGroupBox> homeGroups)
return;
}

for (int i = homeTab.Groups.Count - 1; i >= 0; i--)
for (var i = homeTab.Groups.Count - 1; i >= 0; i--)
{
if (GetIsGroupFromPage(homeTab.Groups[i]))
{
Expand All @@ -113,7 +112,7 @@ private void SetupHomeGroups(Collection<RibbonGroupBox> homeGroups)

private void SetupTabs(Collection<RibbonTabItem> tabs)
{
for (int i = AssociatedObject.Tabs.Count - 1; i >= 0; i--)
for (var i = AssociatedObject.Tabs.Count - 1; i >= 0; i--)
{
if (GetIsTabFromPage(AssociatedObject.Tabs[i]))
{
Expand Down
2 changes: 1 addition & 1 deletion src/CosmosDbExplorer/Behaviors/SelectedTextBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected override void OnDetaching()
}
}

private void SelectionChanged(object sender, EventArgs e)
private void SelectionChanged(object? sender, EventArgs e)
{
if (sender is TextArea textarea)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ namespace CosmosDbExplorer.Contracts.Services
public interface IApplicationInfoService
{
Version GetVersion();
string GetTitle();
}
}
6 changes: 3 additions & 3 deletions src/CosmosDbExplorer/Contracts/Services/INavigationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ namespace CosmosDbExplorer.Contracts.Services
{
public interface INavigationService
{
event EventHandler<string> Navigated;
event EventHandler<string>? Navigated;

bool CanGoBack { get; }
bool? CanGoBack { get; }

void Initialize(Frame shellFrame);

bool NavigateTo(string pageKey, object? parameter = null, bool clearNavigation = false);
bool NavigateTo(Type pageKey, object? parameter = null, bool clearNavigation = false);

void GoBack();

Expand Down
6 changes: 4 additions & 2 deletions src/CosmosDbExplorer/Contracts/Services/IPageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ namespace CosmosDbExplorer.Contracts.Services
{
public interface IPageService
{
Type GetPageType(string key);
Type GetPageType(Type key);

Page GetPage(string key);
Page GetPage(Type key);

Page GetPage(Type key, object parameters);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public interface IRightPaneService

event EventHandler PaneClosed;

void OpenInRightPane(string pageKey, object? parameter = null);
void OpenInRightPane(Type pageKey, object parameter);

void Initialize(Frame rightPaneFrame, SplitView splitView);

Expand Down
2 changes: 1 addition & 1 deletion src/CosmosDbExplorer/Contracts/Services/ISystemService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
{
public interface ISystemService
{
void OpenInWebBrowser(string url);
void OpenInWebBrowser(string? url);
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
using System.Windows;
using System;
using System.Windows;

namespace CosmosDbExplorer.Contracts.Services
{
public interface IWindowManagerService
{
Window MainWindow { get; }

void OpenInNewWindow(string pageKey, object? parameter = null);
void OpenInNewWindow(Type pageKey, object? parameter = null);

bool? OpenInDialog(string pageKey, object? parameter = null);
bool? OpenInDialog(Type pageKey, object? parameter = null);

Window GetWindow(string pageKey);
Window? GetWindow(Type pageKey);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Windows.Input;
using Microsoft.Toolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.Input;

namespace CosmosDbExplorer.Contracts.ViewModels
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.Toolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.Input;

namespace CosmosDbExplorer.Contracts.ViewModels
{
Expand Down
2 changes: 1 addition & 1 deletion src/CosmosDbExplorer/Converters/EnumToBooleanConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace CosmosDbExplorer.Converters
{
public class EnumToBooleanConverter : IValueConverter
{
public Type? EnumType { get; set; }
public Type EnumType { get; set; } = typeof(object);

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
Expand Down
16 changes: 8 additions & 8 deletions src/CosmosDbExplorer/CosmosDbExplorer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@
<EmbeddedResource Include="AvalonEdit\JSON.xshd" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Autoupdater.NET.Official" Version="1.7.3" />
<PackageReference Include="Autoupdater.NET.Official" Version="1.7.6" />
<PackageReference Include="AvalonEdit" Version="6.1.3.50" />
<PackageReference Include="Dirkster.AvalonDock" Version="4.70.1" />
<PackageReference Include="Dirkster.AvalonDock.Themes.VS2013" Version="4.70.1" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.0.0" />
<PackageReference Include="Dirkster.AvalonDock" Version="4.70.3" />
<PackageReference Include="Dirkster.AvalonDock.Themes.VS2013" Version="4.70.3" />
<PackageReference Include="Fluent.Ribbon" Version="9.0.4" />
<PackageReference Include="FluentValidation" Version="10.4.0" />
<PackageReference Include="Fody" Version="6.6.2">
<PackageReference Include="FluentValidation" Version="11.4.0" />
<PackageReference Include="Fody" Version="6.6.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="gong-wpf-dragdrop" Version="3.1.1" />
<PackageReference Include="gong-wpf-dragdrop" Version="3.2.0" />
<PackageReference Include="MahApps.Metro" Version="2.4.9" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
<PackageReference Include="Microsoft.Toolkit.Mvvm" Version="7.1.2" />
<PackageReference Include="PropertyChanged.Fody" Version="3.4.1" />
<PackageReference Include="PropertyChanged.Fody" Version="4.1.0" />
<PackageReference Include="Validar.Fody" Version="1.9.0" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ namespace CosmosDbExplorer.Extensions
{
public static class NameValueCollectionExtensions
{
public static Dictionary<string, string> ToDictionary(this NameValueCollection source)
{
return source.AllKeys.ToDictionary(k => k, k => source[k]);
}
//public static Dictionary<string, string> ToDictionary(this NameValueCollection source)
//{
// return source.AllKeys.ToDictionary(k => k, k => source[k]);
//}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ protected override JsonProperty CreateProperty(MemberInfo member, MemberSerializ
{
prop.NullValueHandling = NullValueHandling.Ignore;
}
else if (systemResourceNames.Contains(prop.PropertyName))
else if (prop.PropertyName is not null && systemResourceNames.Contains(prop.PropertyName))
{
prop.Readable = false;
}
Expand Down
9 changes: 7 additions & 2 deletions src/CosmosDbExplorer/Helpers/OrderedDictionaryConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@ public override bool CanConvert(Type objectType)
return typeof(IDictionary<string, string>).IsAssignableFrom(objectType);
}

public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
public override object ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer)
{
throw new NotImplementedException();
}

public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer)
{
if (value is null)
{
return;
}

var dict = (IDictionary<string, string>)value;
var obj = new JObject();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ namespace CosmosDbExplorer.MarkupExtensions
{
public class EnumBindingSourceExtension : MarkupExtension
{
private Type _enumType;
public Type EnumType
private Type? _enumType;
public Type? EnumType
{
get { return _enumType; }
set
Expand Down Expand Up @@ -67,17 +67,22 @@ public EnumDescriptionTypeConverter(Type type)
{
}

public override object? ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
public override object? ConvertTo(ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, Type destinationType)
{
if (destinationType == typeof(string))
{
if (value != null)
if (value is not null)
{
var fi = value.GetType().GetField(value.ToString());
if (fi != null)
var fieldName = value.ToString();

if (fieldName is not null)
{
var attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
return ((attributes.Length > 0) && (!string.IsNullOrEmpty(attributes[0].Description))) ? attributes[0].Description : value.ToString();
var fi = value.GetType().GetField(fieldName);
if (fi is not null)
{
var attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
return ((attributes.Length > 0) && (!string.IsNullOrEmpty(attributes[0].Description))) ? attributes[0].Description : value.ToString();
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/CosmosDbExplorer/Messages/ActivePaneChangedMessage.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.Toolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.ComponentModel;

namespace CosmosDbExplorer.Messages
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public OpenScaleAndSettingsViewMessage(ScaleSettingsNodeViewModel? node, CosmosC

public class OpenDatabaseScaleViewMessage : OpenTabMessageBase<DatabaseScaleNodeViewModel>
{
public OpenDatabaseScaleViewMessage(DatabaseScaleNodeViewModel? node, CosmosConnection? connection, CosmosDatabase? database, CosmosContainer container)
public OpenDatabaseScaleViewMessage(DatabaseScaleNodeViewModel? node, CosmosConnection? connection, CosmosDatabase? database, CosmosContainer? container)
: base(node, connection, database, container)
{
}
Expand Down
Loading

0 comments on commit d722b0d

Please sign in to comment.