New change request abstractions.

This commit is contained in:
Burak Kaan Köse
2024-11-26 20:03:10 +01:00
parent e81b7e2e61
commit a9fffd44d2
38 changed files with 769 additions and 1051 deletions

View File

@@ -12,6 +12,10 @@
AlwaysMoveTo,
MoveToFocused,
Archive,
}
public enum FolderSynchronizerOperation
{
RenameFolder,
EmptyFolder,
MarkFolderRead,

View File

@@ -1,5 +1,4 @@
using System.Collections.Generic;
using Wino.Core.Domain.Entities.Mail;
using Wino.Core.Domain.Entities.Mail;
using Wino.Core.Domain.Enums;
namespace Wino.Core.Domain.Interfaces
@@ -10,7 +9,7 @@ namespace Wino.Core.Domain.Interfaces
public interface IRequestBundle
{
string BundleId { get; set; }
IRequestBase Request { get; }
IUIChangeRequest UIChangeRequest { get; }
}
/// <summary>
@@ -20,15 +19,25 @@ namespace Wino.Core.Domain.Interfaces
public interface IRequestBundle<TRequest> : IRequestBundle
{
TRequest NativeRequest { get; }
IRequestBase Request { get; }
}
public interface IRequestBase : IClientMessage
public interface IRequestBase : IClientMessage, IUIChangeRequest
{
/// <summary>
/// Synchronizer option to perform.
/// Whether synchronizations should be delayed after executing this request.
/// Specially Outlook sometimes don't report changes back immidiately after sending the API request.
/// This results following synchronization to miss the changes.
/// We add small delay for the following synchronization after executing current requests to overcome this issue.
/// Default is false.
/// </summary>
MailSynchronizerOperation Operation { get; }
int ResynchronizationDelay { get; }
object GroupingKey();
}
public interface IUIChangeRequest
{
/// <summary>
/// UI changes to apply to the item before sending the request to the server.
/// Changes here only affect the UI, not the item itself.
@@ -40,30 +49,18 @@ namespace Wino.Core.Domain.Interfaces
/// Reverts the UI changes applied by <see cref="ApplyUIChanges"/> if the request fails.
/// </summary>
void RevertUIChanges();
/// <summary>
/// Whether synchronizations should be delayed after executing this request.
/// Specially Outlook sometimes don't report changes back immidiately after sending the API request.
/// This results following synchronization to miss the changes.
/// We add small delay for the following synchronization after executing current requests to overcome this issue.
/// Default is false.
/// </summary>
int ResynchronizationDelay { get; }
}
public interface IRequest : IRequestBase
public interface IMailActionRequest : IRequestBase
{
MailCopy Item { get; }
IBatchChangeRequest CreateBatch(IEnumerable<IRequest> requests);
MailSynchronizerOperation Operation { get; }
}
public interface IFolderRequest : IRequestBase
public interface IFolderActionRequest : IRequestBase
{
MailItemFolder Folder { get; }
}
public interface IBatchChangeRequest : IRequestBase
{
IEnumerable<IRequest> Items { get; }
FolderSynchronizerOperation Operation { get; }
}
}

View File

@@ -12,7 +12,7 @@ namespace Wino.Core.Domain.Interfaces
/// </summary>
/// <param name="request"></param>
/// <returns>Base request that synchronizer can execute.</returns>
Task<IRequestBase> PrepareFolderRequestAsync(FolderOperationPreperationRequest request);
Task<IFolderActionRequest> PrepareFolderRequestAsync(FolderOperationPreperationRequest request);
/// <summary>
/// Prepares proper Wino requests for synchronizers to execute categorized by AccountId and FolderId.
@@ -21,6 +21,6 @@ namespace Wino.Core.Domain.Interfaces
/// <param name="mailCopyIds">Selected mails.</param>
/// <exception cref="UnavailableSpecialFolderException">When required folder target is not available for account.</exception>
/// <returns>Base request that synchronizer can execute.</returns>
Task<List<IRequest>> PrepareRequestsAsync(MailOperationPreperationRequest request);
Task<List<IMailActionRequest>> PrepareRequestsAsync(MailOperationPreperationRequest request);
}
}

View File

@@ -2,7 +2,7 @@
using Wino.Core.Domain.Enums;
using Wino.Core.Domain.Models.Calendar;
namespace Wino.Calendar.Models.CalendarTypeStrategies
namespace Wino.Core.Domain.Models.Calendar.CalendarTypeStrategies
{
public abstract class BaseCalendarTypeDrawingStrategy
{

View File

@@ -2,7 +2,7 @@
using Wino.Core.Domain.Enums;
using Wino.Core.Domain.Models.Calendar;
namespace Wino.Calendar.Models.CalendarTypeStrategies
namespace Wino.Core.Domain.Models.Calendar.CalendarTypeStrategies
{
public class DayCalendarDrawingStrategy : BaseCalendarTypeDrawingStrategy
{

View File

@@ -1,11 +1,11 @@
using System;
using Wino.Core.Domain.Models.Calendar;
namespace Wino.Calendar.Models.CalendarTypeStrategies
namespace Wino.Core.Domain.Models.Calendar.CalendarTypeStrategies
{
public class WeekCalendarDrawingStrategy : BaseCalendarTypeDrawingStrategy
{
public WeekCalendarDrawingStrategy(CalendarSettings settings) : base(settings, Core.Domain.Enums.CalendarDisplayType.Week) { }
public WeekCalendarDrawingStrategy(CalendarSettings settings) : base(settings, Enums.CalendarDisplayType.Week) { }
public override DateRange GetNextDateRange(DateRange CurrentDateRange, int DayDisplayCount)
=> new DateRange(CurrentDateRange.EndDate, CurrentDateRange.EndDate.AddDays(7 * 2));

View File

@@ -1,34 +1,40 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using Wino.Core.Domain.Entities.Mail;
using Wino.Core.Domain.Enums;
using Wino.Core.Domain.Interfaces;
namespace Wino.Core.Domain.Models.Requests
{
public abstract record RequestBase<TBatchRequestType>(MailCopy Item, MailSynchronizerOperation Operation) : IRequest
where TBatchRequestType : IBatchChangeRequest
public abstract record RequestBase<TOperation> where TOperation : Enum
{
public abstract IBatchChangeRequest CreateBatch(IEnumerable<IRequest> requests);
public abstract void ApplyUIChanges();
public abstract void RevertUIChanges();
public virtual void ApplyUIChanges() { }
public virtual void RevertUIChanges() { }
public virtual int ResynchronizationDelay => 0;
public abstract TOperation Operation { get; }
public virtual object GroupingKey() { return Operation; }
}
public abstract record FolderRequestBase(MailItemFolder Folder, MailSynchronizerOperation Operation) : IFolderRequest
public abstract record MailRequestBase(MailCopy Item) : RequestBase<MailSynchronizerOperation>, IMailActionRequest
{
public abstract void ApplyUIChanges();
public abstract void RevertUIChanges();
public virtual int ResynchronizationDelay => 0;
}
public abstract record BatchRequestBase(IEnumerable<IRequest> Items, MailSynchronizerOperation Operation) : IBatchChangeRequest
public abstract record FolderRequestBase(MailItemFolder Folder, FolderSynchronizerOperation Operation) : IFolderActionRequest
{
public abstract void ApplyUIChanges();
public abstract void RevertUIChanges();
public virtual int ResynchronizationDelay => 0;
public virtual bool ExecuteSerialBatch => false;
public virtual object GroupingKey() { return Operation; }
}
public class BatchCollection<TRequestType> : List<TRequestType>, IUIChangeRequest where TRequestType : IUIChangeRequest
{
public BatchCollection(IEnumerable<TRequestType> collection) : base(collection)
{
}
public void ApplyUIChanges() => ForEach(x => x.ApplyUIChanges());
public void RevertUIChanges() => ForEach(x => x.RevertUIChanges());
}
}