static void Main(string[] args) { Console.WriteLine("Hello World!"); // vstupy od někud StorageType storageType = StorageType.FileSystem; string sourceFileName = "url nebo filePath Document1.xml"; string targetFileName = "url na cil, nebo filePath"; TargetFormatType targetFormat = TargetFormatType.Json; // v reálu přes nějaké DI ProxyClientAPIFormatConvertor proxyClient = new ProxyClientAPIFormatConvertor(); // podle typu storage var factory = new BlobStorageFactory(); ISourceBlobStorage sourceStorage = factory.CreateBlobStorage(storageType); IPersistBlobStorage persistBlobStorage = factory.CreatePersistBlobStorage(storageType); // podle ciloveho typu persist storage ISerializedResultStorage serializedResultStorage = new SerializedResultStorageFactory().CreateSerializedResultStorage(targetFormat, sourceStorage, persistBlobStorage); string input; try { input = sourceStorage.ReadAsString(sourceFileName); DocToConvert docToConvert = new DocToConvert { TargetFormat = targetFormat, XmlContent = input, }; // API provede konverzi string convertedResult = proxyClient.GetConvertedContent(docToConvert); serializedResultStorage.SaveConvertedContent(convertedResult, targetFileName); } catch (Exception ex) { // TODO ILogger logger // zalogovat včetně StackTrace // logger.LogException(ex); // výše poslat jen stručné info throw new Exception("Něco se nepovedlo"); } }
public ResultStorageProtobuf(ISourceBlobStorage storage, IPersistBlobStorage persistBlobStorage) : base(storage, persistBlobStorage) { }
public ISerializedResultStorage CreateSerializedResultStorage(TargetFormatType targetFormat, ISourceBlobStorage storage, IPersistBlobStorage persistBlobStorage) { switch (targetFormat) { case TargetFormatType.Json: return(new ResultStorageText(storage, persistBlobStorage)); case TargetFormatType.Protobuf: return(new ResultStorageProtobuf(storage, persistBlobStorage)); default: throw new Exception("Neznámý"); } }
public BaseResultStorage(ISourceBlobStorage storage, IPersistBlobStorage persistBlobStorage) { this.storage = storage; this.persistBlobStorage = persistBlobStorage; }
public ResultStorageText(ISourceBlobStorage storage, IPersistBlobStorage persistBlobStorage) : base(storage, persistBlobStorage) { }