Last active
November 10, 2017 18:19
-
-
Save jweyrich/ccd44a0461ca9ca0cee58ae5b7a86105 to your computer and use it in GitHub Desktop.
Cannot implicitly convert type 'Demo.RestoreOperation' to 'Demo.IBaseOperation<Demo.IBaseOperationReport>'. An explicit conversion exists (are you missing a cast?)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
namespace Demo | |
{ | |
public interface IBaseOperationReport | |
{ | |
List<string> ErrorMessages { get; } | |
bool HasErrorMessages { get; } | |
void Reset(); | |
void AggregateResults(); | |
} | |
public abstract class BaseOperationReport : IBaseOperationReport | |
{ | |
// ... | |
public List<string> ErrorMessages { get; protected set; } | |
public virtual bool HasErrorMessages | |
{ | |
get { return ErrorMessages.Count > 0; } | |
} | |
public BaseOperationReport() | |
{ | |
ErrorMessages = new List<string>(); | |
} | |
public virtual void Reset() | |
{ | |
// ... | |
} | |
public virtual void AggregateResults() | |
{ | |
// ... | |
} | |
} | |
public abstract class TransferOperationReport : BaseOperationReport | |
{ | |
public override void Reset() | |
{ | |
base.Reset(); | |
// ... | |
} | |
public override void AggregateResults() | |
{ | |
base.AggregateResults(); | |
// ... | |
} | |
} | |
public sealed class BackupOperationReport : TransferOperationReport | |
{ | |
} | |
public sealed class RestoreOperationReport : TransferOperationReport | |
{ | |
} | |
public interface IBaseOperation<TReport> : IDisposable where TReport : IBaseOperationReport | |
{ | |
TReport Report { get; } | |
bool IsRunning { get; } | |
void Start(); | |
void SendReport(); | |
void DoEvents(); | |
void Cancel(); | |
} | |
public abstract class BaseOperation<TReport> : IBaseOperation<TReport> where TReport : BaseOperationReport, new() | |
{ | |
public TReport Report { get; protected set; } | |
protected BaseOperation() | |
{ | |
Report = new TReport(); | |
// ... | |
} | |
public abstract void Start(); | |
public abstract void SendReport(); | |
public virtual void DoEvents() | |
{ | |
// ... | |
} | |
public virtual void Cancel() | |
{ | |
// ... | |
} | |
public bool IsRunning | |
{ | |
get { throw new NotImplementedException(); } | |
} | |
public void Dispose() | |
{ | |
throw new NotImplementedException(); | |
} | |
} | |
public abstract class BackupOperation : BaseOperation<BackupOperationReport> | |
{ | |
// ... | |
} | |
public class NewBackupOperation : BackupOperation | |
{ | |
// ... | |
public override void Start() | |
{ | |
throw new NotImplementedException(); | |
} | |
public override void SendReport() | |
{ | |
throw new NotImplementedException(); | |
} | |
} | |
public abstract class RestoreOperation : BaseOperation<RestoreOperationReport> | |
{ | |
// ... | |
} | |
public class NewRestoreOperation : RestoreOperation | |
{ | |
// ... | |
public override void Start() | |
{ | |
throw new NotImplementedException(); | |
} | |
public override void SendReport() | |
{ | |
throw new NotImplementedException(); | |
} | |
} | |
public class PlanExecutor | |
{ | |
static void Main(string[] args) | |
{ | |
PlanExecutor executor = new PlanExecutor(); | |
executor.Run(); | |
} | |
private void Run() | |
{ | |
var RunningOperation = CreateOperation(0); | |
RunningOperation.Start(); | |
while (true) | |
{ | |
// ... | |
RunningOperation.DoEvents(); | |
} | |
} | |
private IBaseOperation<IBaseOperationReport> CreateOperation(int type) | |
{ | |
IBaseOperation<IBaseOperationReport> result = null; | |
switch (type) | |
{ | |
case 0: | |
result = CreateBackupOperation(); | |
break; | |
case 1: | |
result = CreateRestoreOperation(); | |
break; | |
} | |
return result; | |
} | |
private BackupOperation CreateBackupOperation() | |
{ | |
return new NewBackupOperation(); // For testing purposes | |
} | |
private RestoreOperation CreateRestoreOperation() | |
{ | |
return new NewRestoreOperation(); // For testing purposes | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment