Ejemplo n.º 1
0
        public void ConvertorFactory_CreateConvertor_Test(TargetFormatType targetFormat, Type expectedType)
        {
            ConvertorFactory factory = new ConvertorFactory();

            var convertor = factory.CreateObjectConvertor(targetFormat);

            Assert.NotNull(convertor);
            Assert.IsAssignableFrom(expectedType, convertor);
        }
Ejemplo n.º 2
0
        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ý");
            }
        }
Ejemplo n.º 3
0
        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 ConvertedResult GetConvertedResult(DocToConvert docToConvert)
        {
            TargetFormatType requiredFormat = docToConvert.TargetFormat;

            Document document = this.deserializerFromXml.DeserializeFromXml(docToConvert.XmlContent);

            IObjectConvertor convertor = this.convertorFactory.CreateObjectConvertor(requiredFormat);

            string convertedContent = convertor.SerializeObject(document);


            return(new ConvertedResult()
            {
                TargetFormat = requiredFormat,
                Content = convertedContent
            });
        }
Ejemplo n.º 5
0
        public IObjectConvertor CreateObjectConvertor(TargetFormatType targetFormat)
        {
            switch (targetFormat)
            {
            case TargetFormatType.Json:
                return(new ToJsonConvertor());

            case TargetFormatType.Protobuf:
                return(new ToProtobufConvertor());

            // další formáty se jen přidají další konvertory
            //case TargetFormatType.XY:
            //    return new ToXYConvertor();

            default:
                throw new Exception($"Neimplementovay format {targetFormat}");
            }
        }
Ejemplo n.º 6
0
        string BuildOutputFile(MultimediaData multimediaData, TargetFormatType targetFormat)
        {
            //Format the target file like <output directory>\<source filename>_<source file extension>_<Guid>.<new extension>
            string ext = Path.GetExtension(multimediaData.SourceFile);

            if (!string.IsNullOrEmpty(ext))
            {
                ext = ext.Replace(".", "");
            }

            if (!string.IsNullOrEmpty(ext))
            {
                ext = "_" + ext;
            }
            else
            {
                ext = string.Empty;
            }

            string name = Path.GetFileNameWithoutExtension(multimediaData.SourceFile);

            name = string.Format(
                "{0}{1}_{2}.{3}",
                name, ext, Guid.NewGuid(), GetExtension(targetFormat));

            string fullPath = string.Empty;

            // If the TargetFile is a file, this is a full path (from a previous conversion). In this case need, we to get the directory name and append the new file name.
            // We cannot check the file itself because it may no longer exist so we use the extension in the path to indicate if it is a file
            if (String.IsNullOrEmpty(Path.GetExtension(multimediaData.TargetFile)))
            {
                fullPath = multimediaData.TargetFile; //path is a directory
            }
            else
            {
                fullPath = Path.GetDirectoryName(multimediaData.TargetFile);//This is a file
            }
            if (!Directory.Exists(fullPath))
            {
                Directory.CreateDirectory(fullPath);
            }

            return(Path.Combine(fullPath, name));
        }
Ejemplo n.º 7
0
        private string GetExtension(TargetFormatType targetFormat)
        {
            switch (targetFormat)
            {
            case TargetFormatType.MPEG2DICOM:
            case TargetFormatType.DICOM:
                return("dcm");

            case TargetFormatType.ASF:
            case TargetFormatType.ASFMux:
            case TargetFormatType.WMVMux:
                return("wmv");

            case TargetFormatType.DVSD:
                return("dvsd");

            case TargetFormatType.MKV:
                return("mkv");

            case TargetFormatType.MXF:
                return("mxf");

            case TargetFormatType.DVSDAVI:
                return("avi");

            case TargetFormatType.DVSDMXF:
                return("mxf");

            case TargetFormatType.DVSDOGG:
                return("ogg");

            case TargetFormatType.FLVH264:
            case TargetFormatType.FLVH263:
            case TargetFormatType.FLV:
                return("flv");

            case TargetFormatType.ISO:
                return("mp4");

            case TargetFormatType.MP3LEAD:
            case TargetFormatType.MP3LAME:
            case TargetFormatType.MP3Default:
            case TargetFormatType.MP3:
                return("mp3");

            case TargetFormatType.MPEG2Program:
            case TargetFormatType.MPEG1Audio:
            case TargetFormatType.MPEG1System:
                return("mpg");

            case TargetFormatType.MPEG2Transport:
                return("m2ts");

            case TargetFormatType.OGG:
                return("ogg");

            case TargetFormatType.WAVE:
                return("wav");

            default:
            case TargetFormatType.AVI:
                return("avi");
            }
        }