我想處理文件,因爲它們保存在四個目錄中,它們都以非常不同的方式處理。無法將源接口類型轉換爲目標接口類型
我有一個在調度計時器上運行的公共處理器IFileQueueService,加載所有文件名併爲每個文件調用自定義處理器IExecutionProcessor。這可能是一個簡單的問題,但我擁有比標準IExecutionProvider更多屬性的處理器,我不知道如何調用這些定製處理器。
//Basic processor interface
public interface IExecutionProvider
{
void ProcessFile(string file);
}
//Simplified version of one of the custom processor interfaces
public interface IKyoExecutionProcessor
{
string DestinationPath { get; set; }
}
public class KyoExecutionProcessor : IExecutionProvider, IKyoExecutionProcessor
{
//This processor moves a file to the DestinationPath.
}
public interface IFileQueueService
{
string SourcePath { get; set; }
IExecutionProvider ExecutionProvider { get; set; }
void Start();
void Stop();
}
public class FileProcessor : IFileQueueService
{
...
public virtual void ProcessFileQueue()
{
IEnumerable<string> filesToProcess = GetFilesReadyToProcess();
foreach (string file in filesToProcess.ToList())
{
ExecutionProvider.ProcessFile(file);
}
}
}
public class KYOFileSysWatcher : ServiceBase
{
private IFileQueueService Processor { get; set; }
private IKyoExecutionProcessor KyoCustomProcessor { get; set; }
public KYOFileSysWatcher()
{
Processor = ObjectFactory.GetInstance<IFileQueueService>();
KyoCustomProcessor = ObjectFactory.GetInstance<IKyoExecutionProcessor>();
//This doesn't work, cannot convert source type to target type, but it implements the IExecutionProvider interface??? How do I do this?
Processor.ExecutionProvider = KyoCustomProcessor;
Processor.Start(); //Sets up dispatch timer
}
}
如何'KyoCustomProcessor'執行'IExecutionProvider'?它明確是一個'IKyoExecutionProcessor'。 – 2012-03-14 14:29:55