public LibraryBusinessService(ILibraryDataService libraryDataService)
        {
            this.libraryDataService = libraryDataService;


            //HttpContext.Current.Request.Files
        }
Ejemplo n.º 2
0
        private void RestoreAssetFromTxt(byte[] data, ILibraryDataService libraryDataService)
        {
            using (var stream = new MemoryStream(data))
            {
                var txtData = string.Empty;

                using (var reader = new StreamReader(stream))
                {
                    txtData = reader.ReadToEnd();
                }

                if (txtData.Substring(1, 4) != "List")
                {
                    var asset = RestoreFromTxt(txtData);

                    libraryDataService.AddAsset(asset);
                    libraryDataService.SaveChanges();

                    return;
                }

                var assets = RestoreAssetsListFromTxt(txtData);

                libraryDataService.AddAssetsRange(assets);
                libraryDataService.SaveChanges();
            }
        }
Ejemplo n.º 3
0
        private void RestoreAssetFromXml(byte[] data, ILibraryDataService libraryDataService)
        {
            using (var stream = new MemoryStream(data))
            {
                var xmlDocument = XDocument.Load(stream);
                if (xmlDocument.Elements().FirstOrDefault().Name == null)
                {
                    throw new Exception("Incorrect file format");
                }

                if (xmlDocument.Elements().FirstOrDefault().Name != "List")
                {
                    var asset = RestoreFromXml(xmlDocument.Elements().FirstOrDefault());

                    libraryDataService.AddAsset(asset);
                    libraryDataService.SaveChanges();
                    return;
                }

                var assets = RestoreAssetsListFromXml(xmlDocument);

                libraryDataService.AddAssetsRange(assets);
                libraryDataService.SaveChanges();
            }
        }
Ejemplo n.º 4
0
        public void RestoreDataFromFile(IFormFileCollection file, ILibraryDataService libraryDataService)
        {
            var fileExtension = Path.GetExtension(file[0].FileName);

            using (var stream = new MemoryStream())
            {
                file[0].CopyTo(stream);
                byte[] data = stream.ToArray();

                if (fileExtension == ".xml")
                {
                    RestoreAssetFromXml(data, libraryDataService);
                    return;
                }

                if (fileExtension == ".txt")
                {
                    RestoreAssetFromTxt(data, libraryDataService);
                    return;
                }

                throw new Exception("Incorrect file type");
            }
        }
 public AssetController(ILibraryDataService libraryDataService)
 {
     this._libraryDataService = libraryDataService;
 }
Ejemplo n.º 6
0
 public BaseAssetController(ILibraryDataService libraryDataService, IImageHandlerService imageService, IHostingEnvironment appEnvironment)
 {
     this._libraryDataService = libraryDataService;
     this._imageService       = imageService;
     this._appEnvironment     = appEnvironment;
 }
Ejemplo n.º 7
0
 public DataFileController(ILibraryDataService libraryDataService, IDataFileService dataFileService)
 {
     this._libraryDataService = libraryDataService;
     this._dataFileService    = dataFileService;
 }
 /// <summary>
 /// Constructor with Dependency Injection using Ninject
 /// </summary>
 /// <param name="dataService"></param>
 public LibraryApiController()
 {
     libraryDataService = new LibraryDataService();
 }
Ejemplo n.º 9
0
 public JournalController(ILibraryDataService libraryDataService, IImageHandlerService imageService, IHostingEnvironment appEnvironment)
     : base(libraryDataService, imageService, appEnvironment)
 {
 }