/// <summary> /// Import a product using given parameters /// </summary> protected override Task <ProductImporterResult> Import(ProductImportContext context, SpecializedWatchImportParameters parameters) { var product = new WatchType { Name = parameters.Name, Identity = new ProductIdentity(parameters.Identifier, parameters.Revision), Watchface = new ProductPartLink <WatchfaceTypeBase> { Product = (WatchfaceType)Storage.LoadType(new ProductIdentity(parameters.WatchfaceIdentifier, ProductIdentity.LatestRevision)) }, Needles = new List <NeedlePartLink> { new NeedlePartLink { Role = NeedleRole.Minutes, Product = (NeedleType)Storage.LoadType(new ProductIdentity(parameters.MinuteNeedleIdentifier, ProductIdentity.LatestRevision)) } } }; return(Task.FromResult(new ProductImporterResult { ImportedTypes = new ProductType[] { product } })); }
/// <inheritdoc /> protected override Task <ProductImporterResult> Import(ProductImportContext context, DefaultImporterParameters parameters) { // TODO: Use type wrapper var type = ReflectionTool.GetPublicClasses <ProductType>(p => p.Name == parameters.ProductType) .First(); var productType = (ProductType)Activator.CreateInstance(type); productType.Identity = new ProductIdentity(parameters.Identifier, parameters.Revision); productType.Name = parameters.Name; return(Task.FromResult(new ProductImporterResult { ImportedTypes = new[] { productType } })); }
/// <summary> /// Import a product using given parameters /// </summary> protected override Task <ProductImporterResult> Import(ProductImportContext context, FileImportParameters parameters) { using (var stream = parameters.ReadFile()) { var textReader = new StreamReader(stream); var identifier = textReader.ReadLine(); var revision = short.Parse(textReader.ReadLine() ?? "0"); var name = textReader.ReadLine(); return(Task.FromResult(new ProductImporterResult { ImportedTypes = new ProductType[] { new NeedleType { Name = name, Identity = new ProductIdentity(identifier, revision) } } })); } }