Skip to content

Commit

Permalink
Fix storage methods
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperJMN committed Aug 16, 2023
1 parent 91b1492 commit e519483
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public ConfigViewModel(Maybe<ILogger> logger)

Save = ReactiveCommand.CreateFromTask(OnSave);
Load = ReactiveCommand.CreateFromTask(OnLoad);
Load.ThrownExceptions.Subscribe(exception => { });
Delete = ReactiveCommand.Create(() => profilesSource.RemoveKey(SelectedProfile!.Id), this.WhenAnyValue(x => x.SelectedProfile).NotNull());
AddOrUpdate.InvokeCommand(Save);
}
Expand Down
22 changes: 16 additions & 6 deletions src/AvaloniaSyncer/Plugins/SeaweedFS/Configuration/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,26 @@ public Task<Result<Config>> Load()

private static Result<Stream> OpenRead(string path)
{
var isolatedStorageScope = IsolatedStorageScope.User | IsolatedStorageScope.Domain | IsolatedStorageScope.Assembly;
return Result.Try(() => IsolatedStorageFile.GetStore(isolatedStorageScope, null, null))
.Map(file => (Stream)file.OpenFile(path, FileMode.Open));
return Result.Try(GetStore)
.Bind(store =>
{
return Result.Try(() =>
{
var isolatedStorageFileStream = new IsolatedStorageFileStream(path, FileMode.Open, store);
return (Stream) isolatedStorageFileStream;
});
});
}

private static Result<Stream> OpenWrite(string path)
{
var isolatedStorageScope = IsolatedStorageScope.User | IsolatedStorageScope.Domain | IsolatedStorageScope.Assembly;
return Result.Try(() => IsolatedStorageFile.GetStore(isolatedStorageScope, null, null))
.Map(file => (Stream)file.OpenFile(path, FileMode.Create));
return Result.Try(GetStore)
.Map(store => (Stream)new IsolatedStorageFileStream(path, FileMode.Create, store));
}

private static IsolatedStorageFile GetStore()
{
var isolatedStorageFile = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Domain | IsolatedStorageScope.Assembly, null, null);
return isolatedStorageFile;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public ConfigViewModel()

Save = ReactiveCommand.CreateFromTask(OnSave);
Load = ReactiveCommand.CreateFromTask(OnLoad);
Load.ThrownExceptions.Subscribe(exception => { });
Delete = ReactiveCommand.Create(() => profilesSource.RemoveKey(SelectedProfile!.Id), this.WhenAnyValue(x => x.SelectedProfile).NotNull());
AddOrUpdate.InvokeCommand(Save);
}
Expand Down
25 changes: 18 additions & 7 deletions src/AvaloniaSyncer/Plugins/Sftp/Configuration/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,32 @@ private static Task<Result<Config>> Load(Stream stream)

public Task<Result<Config>> Load()
{
return OpenRead("SFTP").Bind(stream => Load(stream));
var result = OpenRead("SFTP").Bind(stream => Load(stream));
return result;
}

private static Result<Stream> OpenRead(string path)
{
var isolatedStorageScope = IsolatedStorageScope.User | IsolatedStorageScope.Domain | IsolatedStorageScope.Assembly;
return Result.Try(() => IsolatedStorageFile.GetStore(isolatedStorageScope, null, null))
.Map(file => (Stream)file.OpenFile(path, FileMode.Open));
return Result.Try(GetStore)
.Bind(store =>
{
return Result.Try(() =>
{
var isolatedStorageFileStream = new IsolatedStorageFileStream(path, FileMode.Open, store);
return (Stream) isolatedStorageFileStream;
});
});
}

private static Result<Stream> OpenWrite(string path)
{
var isolatedStorageScope = IsolatedStorageScope.User | IsolatedStorageScope.Domain | IsolatedStorageScope.Assembly;
return Result.Try(() => IsolatedStorageFile.GetStore(isolatedStorageScope, null, null))
.Map(file => (Stream)file.OpenFile(path, FileMode.Create));
return Result.Try(GetStore)
.Map(store => (Stream)new IsolatedStorageFileStream(path, FileMode.Create, store));
}

private static IsolatedStorageFile GetStore()
{
var isolatedStorageFile = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Domain | IsolatedStorageScope.Assembly, null, null);
return isolatedStorageFile;
}
}
12 changes: 7 additions & 5 deletions src/AvaloniaSyncer/Views/CreateSyncSessionView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
xmlns:sftp="clr-namespace:AvaloniaSyncer.Plugins.Sftp"
xmlns:local="clr-namespace:AvaloniaSyncer.Plugins.Local"
xmlns:seaweedFs="clr-namespace:AvaloniaSyncer.Plugins.SeaweedFS"
mc:Ignorable="d"
mc:Ignorable="d"
x:Class="AvaloniaSyncer.Views.CreateSyncSessionView"
x:DataType="viewModels:CreateSyncSessionViewModel">

Expand All @@ -23,9 +23,11 @@
</DataTemplate>
</UserControl.DataTemplates>

<UniformGrid Rows="1" MinWidth="640" MinHeight="600">
<views:PluginSelectionView Margin="8" DataContext="{Binding SourcePluginViewModel}" />
<views:PluginSelectionView Margin="8" DataContext="{Binding DestinationPluginViewModel}" />
</UniformGrid>
<ScrollViewer>
<UniformGrid Rows="1" MinWidth="640" MinHeight="600">
<views:PluginSelectionView Margin="8" DataContext="{Binding SourcePluginViewModel}" />
<views:PluginSelectionView Margin="8" DataContext="{Binding DestinationPluginViewModel}" />
</UniformGrid>
</ScrollViewer>

</UserControl>

0 comments on commit e519483

Please sign in to comment.