/// <summary>
        ///     Makes a clone of a source filestorage, and re-allocates the data identifiers in the destination filestorage (the first
        ///     data identifier will get 0001, the next one 0002, etc. Next to outputting a new target filestorage with new indexes,
        ///     the method also produces a sql file that should be used to update your DAL logic, since the references need to be
        ///     updated too ofcourse.
        /// </summary>
        public static void Upgrade(string sourceFileStorageName, string destinationFileStorageName, FileStorageHandler.ExposeProgressDelegate exposeProgressDelegateA, FileStorageHandler.ExposeProgressDelegate exposeProgressDelegateB)
        {
            Create(destinationFileStorageName, CreateFileStorageBehaviour.ThrowExceptionWhenExists);

            FileStorageHandler sourceFileStorageHandler      = FileStorageHandler.Open(sourceFileStorageName, VersionBehaviour.BypassVersionCheck);
            FileStorageHandler destinationFileStorageHandler = FileStorageHandler.Open(destinationFileStorageName);

            List <Guid> dataIdentifiers = sourceFileStorageHandler.GetAllDataIdentifiersBasedUponFileStorageIndexFile(StreamStateBehaviour.OpenNewStreamForReading, exposeProgressDelegateA);

            for (int currentDataIdentifierIndex = 0; currentDataIdentifierIndex < dataIdentifiers.Count; currentDataIdentifierIndex++)
            {
                Guid   currentSourceDataIdentifier = dataIdentifiers[currentDataIdentifierIndex];
                byte[] theBytes = sourceFileStorageHandler.GetFileByteData(currentSourceDataIdentifier, StreamStateBehaviour.OpenNewStreamForReading, StreamStateBehaviour.OpenNewStreamForReading);

                ICustomMetaData customMetaData = sourceFileStorageHandler.SupportsFeature(FileStorageFeatureEnum.StoreMetaData)
                                                     ? sourceFileStorageHandler.GetMetaDataContainer(currentSourceDataIdentifier, StreamStateBehaviour.OpenNewStreamForReading, StreamStateBehaviour.OpenNewStreamForReading).CustomMetaData
                                                     : new EmptyCustomMetaData();

                Guid currentDestinationDataIdentifier = currentSourceDataIdentifier;

                //
                // store item in destination
                //
                destinationFileStorageHandler.StoreBytes(currentDestinationDataIdentifier, theBytes, customMetaData, AddFileBehaviour.ThrowExceptionWhenAlreadyExists, StreamStateBehaviour.OpenNewStreamForReadingAndWriting, StreamStateBehaviour.OpenNewStreamForReadingAndWriting);

                if (exposeProgressDelegateB != null)
                {
                    exposeProgressDelegateB.Invoke(currentDestinationDataIdentifier);
                }
            }
        }
        public IActionResult Upload(IList <IFormFile> files)
        {
            foreach (var file in files)
            {
                ContentDispositionHeaderValue header = ContentDispositionHeaderValue.Parse(file.ContentDisposition);
                string fileName = header.FileName;
                fileName = fileName.Trim('"');
                fileName = Path.GetFileName(fileName);

                MemoryStream ms = new MemoryStream();
                Stream       s  = file.OpenReadStream();
                s.CopyTo(ms);
                byte[] data = ms.ToArray();
                s.Dispose();
                ms.Dispose();
                string fileContent = System.Text.ASCIIEncoding.ASCII.GetString(data);

                FileFormatHandler  handler1 = new FileFormatHandler();
                FileStorageHandler handler2 = new FileStorageHandler();
                DataImportHandler  handler3 = new DataImportHandler();

                handler1.NextHandler = handler2;
                handler2.NextHandler = handler3;
                handler3.NextHandler = null;

                handler1.Process(fileName, fileContent);
            }
            ViewBag.Message = files.Count + " file(s) imported successfully!";
            return(View("Index"));
        }
예제 #3
0
        public static void ExportToOtherFileStorage(string sourcefileStorageName, Guid dataIdentifier, AddFileBehaviour addFileBehaviour, string targetfileStorageName)
        {
            var sourceFileStorageHandler = FileStorageHandler.Open(sourcefileStorageName);
            var targetFileStorageHandler = FileStorageHandler.Open(targetfileStorageName);

            sourceFileStorageHandler.ExportToOtherFileStorage(dataIdentifier, targetFileStorageHandler, addFileBehaviour, StreamStateBehaviour.OpenNewStreamForReading, StreamStateBehaviour.OpenNewStreamForReading, StreamStateBehaviour.OpenNewStreamForReadingAndWriting, StreamStateBehaviour.OpenNewStreamForReadingAndWriting);
        }
        /// <summary>
        ///     Makes a clone of a source filestorage, and re-allocates the data identifiers in the destination filestorage (the first
        ///     data identifier will get 0001, the next one 0002, etc. Next to outputting a new target filestorage with new indexes,
        ///     the method also produces a sql file that should be used to update your DAL logic, since the references need to be
        ///     updated too ofcourse.
        /// </summary>
        public static void DefragDataIdentifiers(string sourceFileStorageName, string destinationFileStorageName, string sqlTable, string sqlColumn, FileStorageHandler.ExposeProgressDelegate exposeProgressDelegateA, FileStorageHandler.ExposeProgressDelegate exposeProgressDelegateB)
        {
            Create(destinationFileStorageName, CreateFileStorageBehaviour.ThrowExceptionWhenExists);

            string sqlOutputFileName = destinationFileStorageName + ".FileStorage.index.fc.sql";

            if (File.Exists(sqlOutputFileName))
            {
                throw new Exception(string.Format("File {0} already exists", sqlOutputFileName));
            }

            FileStorageHandler sourceFileStorageHandler      = FileStorageHandler.Open(sourceFileStorageName);
            FileStorageHandler destinationFileStorageHandler = FileStorageHandler.Open(destinationFileStorageName);

            using (StreamWriter sw = File.CreateText(sqlOutputFileName))
            {
                sw.WriteLine("-- SQL Patch script to adjust the dataidentifiers");

                List <Guid> dataIdentifiers = sourceFileStorageHandler.GetAllDataIdentifiersBasedUponFileStorageIndexFile(StreamStateBehaviour.OpenNewStreamForReading, exposeProgressDelegateA);

                for (int currentDataIdentifierIndex = 0; currentDataIdentifierIndex < dataIdentifiers.Count; currentDataIdentifierIndex++)
                {
                    Guid   currentSourceDataIdentifier = dataIdentifiers[currentDataIdentifierIndex];
                    byte[] theBytes = sourceFileStorageHandler.GetFileByteData(currentSourceDataIdentifier, StreamStateBehaviour.OpenNewStreamForReading, StreamStateBehaviour.OpenNewStreamForReading);

                    ICustomMetaData customMetaData = sourceFileStorageHandler.SupportsFeature(FileStorageFeatureEnum.StoreMetaData)
                                                         ? sourceFileStorageHandler.GetMetaDataContainer(currentSourceDataIdentifier, StreamStateBehaviour.OpenNewStreamForReading, StreamStateBehaviour.OpenNewStreamForReading).CustomMetaData
                                                         : new EmptyCustomMetaData();

                    //
                    // determine the new identifier
                    //
                    int b1AsInt = (currentDataIdentifierIndex >> 24) & 255;
                    var b1      = (byte)b1AsInt;
                    int b2AsInt = (currentDataIdentifierIndex >> 16) & 255;
                    var b2      = (byte)b2AsInt;
                    int b3AsInt = (currentDataIdentifierIndex >> 8) & 255;
                    var b3      = (byte)b3AsInt;
                    int b4AsInt = (currentDataIdentifierIndex >> 0) & 255;
                    var b4      = (byte)b4AsInt;
                    var currentDestinationDataIdentifier = new Guid(0, 0, 0, 0, 0, 0, 0, b1, b2, b3, b4);

                    string line = String.Format("update {0} set {1}='{2}' where {1}='{3}'", sqlTable, sqlColumn, currentSourceDataIdentifier, currentDestinationDataIdentifier);
                    sw.WriteLine(line);

                    //
                    // store item in destination
                    //
                    destinationFileStorageHandler.StoreBytes(currentDestinationDataIdentifier, theBytes, customMetaData, AddFileBehaviour.ThrowExceptionWhenAlreadyExists, StreamStateBehaviour.OpenNewStreamForReadingAndWriting, StreamStateBehaviour.OpenNewStreamForReadingAndWriting);

                    if (exposeProgressDelegateB != null)
                    {
                        exposeProgressDelegateB.Invoke(currentDestinationDataIdentifier);
                    }
                }

                sw.WriteLine("-- EOF");
            }
        }
 public void DisconnectFromStorage()
 {
     connectedStorage = null;
     connected        = false;
     if (openedStorage == OpenedStorage.CONNECTED_STORAGE)
     {
         ReturnToChoosingStorage();
     }
 }
예제 #6
0
        public void UploadFiletoAzure(string fileToUpload, string filePath)
        {
            FileStorageHandler azureBlob = new FileStorageHandler();

            string timestamp = DateTime.Now.ToString("yyyyMMddHHmmssfff");

            string inputFileName  = fileToUpload;
            string uploadFileName = Path.GetFileNameWithoutExtension(inputFileName) + "_" + timestamp + Path.GetExtension(inputFileName);

            azureBlob.upload_ToBlob(filePath + uploadFileName, "forecastbillingcontainer");
            //azureBlob.download_FromBlob(uploadFileName, "forecastbillingcontainer");
        }
예제 #7
0
        public static string GetInfo(string fileStorageName)
        {
            var fileStorageHandler = FileStorageHandler.Open(fileStorageName);

            var stringBuilder = new StringBuilder();

            stringBuilder.AppendLine(String.Format("------"));
            stringBuilder.AppendLine(String.Format("Index file {0} ", fileStorageHandler.indexFilename));
            stringBuilder.AppendLine(String.Format("Data file {0} ", fileStorageHandler.dataFilename));
            stringBuilder.AppendLine(String.Format("Contains {0} unique files (index entries)", FileCountBasedUponFileStorageIndexFile(fileStorageName)));
            stringBuilder.AppendLine(String.Format("Contains {0} data files (data entries)", FileCountBasedUponFileStorageDataFile(fileStorageName)));
            stringBuilder.AppendLine(String.Format("------"));
            return(stringBuilder.ToString());
        }
예제 #8
0
        public static void DeleteDataIdentifier(string fileStorageName, Guid dataIdentifier, DeleteFileBehaviour deleteFileBehaviour)
        {
            var fileStorageHandler = FileStorageHandler.Open(fileStorageName);

            fileStorageHandler.DeleteDataIdentifier(dataIdentifier, deleteFileBehaviour, StreamStateBehaviour.OpenNewStreamForReadingAndWriting);
        }
예제 #9
0
        public static List <Guid> GetAllDataIdentifiersBasedUponFileStorageIndexFile(string fileStorageName, FileStorageHandler.ExposeProgressDelegate notificationDelegate)
        {
            var fileStorageHandler = FileStorageHandler.Open(fileStorageName);

            return(fileStorageHandler.GetAllDataIdentifiersBasedUponFileStorageIndexFile(StreamStateBehaviour.OpenNewStreamForReading, notificationDelegate));
        }
예제 #10
0
 public static void RestoreIndexFile(string fileStorageName, AddFileBehaviour addFileBehaviour, FileStorageHandler.ExposeProgressDelegate exposeProgressDelegate)
 {
     FileStorageHandler.RestoreIndexFile(fileStorageName, addFileBehaviour, exposeProgressDelegate);
 }
예제 #11
0
 public void TestInit()
 {
     fileStorageService = new Mock <IFileStorageService>();
     fileStorageHandler = new FileStorageHandler(fileStorageService.Object);
 }
예제 #12
0
        public static void StoreObject(string fileStorageName, Guid dataIdentifier, IDynamiteXml objectToStore, ICustomMetaData customMetaData, AddFileBehaviour addFileBehaviour)
        {
            var fileStorageHandler = FileStorageHandler.Open(fileStorageName);

            fileStorageHandler.StoreObject(dataIdentifier, objectToStore, customMetaData, addFileBehaviour, StreamStateBehaviour.OpenNewStreamForReadingAndWriting, StreamStateBehaviour.OpenNewStreamForReadingAndWriting);
        }
예제 #13
0
        public static void StoreString(string fileStorageName, Guid dataIdentifier, Encoding encoding, string stringToStore, ICustomMetaData customMetaData, AddFileBehaviour addFileBehaviour)
        {
            var fileStorageHandler = FileStorageHandler.Open(fileStorageName);

            fileStorageHandler.StoreString(dataIdentifier, encoding, stringToStore, customMetaData, addFileBehaviour, StreamStateBehaviour.OpenNewStreamForReadingAndWriting, StreamStateBehaviour.OpenNewStreamForReadingAndWriting);
        }
예제 #14
0
        public static void StoreBytes(string fileStorageName, Guid dataIdentifier, byte[] fileData, ICustomMetaData customMetaData, AddFileBehaviour addFileBehaviour)
        {
            var fileStorageHandler = FileStorageHandler.Open(fileStorageName);

            fileStorageHandler.StoreBytes(dataIdentifier, fileData, customMetaData, addFileBehaviour, StreamStateBehaviour.OpenNewStreamForReadingAndWriting, StreamStateBehaviour.OpenNewStreamForReadingAndWriting);
        }
예제 #15
0
        public static IDynamiteXml GetObjectData(string fileStorageName, Guid dataIdentifier)
        {
            var fileStorageHandler = FileStorageHandler.Open(fileStorageName);

            return(fileStorageHandler.GetObjectData(dataIdentifier, StreamStateBehaviour.OpenNewStreamForReading, StreamStateBehaviour.OpenNewStreamForReading));
        }
 void Start()
 {
     personalDeviceStorage = gameObject.GetComponent <FileStorageHandler>();
 }
 public void ConnectToStorage(FileStorageHandler externalStorage)
 {
     connectedStorage = externalStorage;
     connected        = true;
 }
예제 #18
0
        public static void Dir
        (
            [Required] string fileStorageName,
            [Required] string quickOrVerbose
        )
        {
            bool verbose = quickOrVerbose.ToLower().Equals("verbose");

            var sourceFileStorageHandler = FileStorageHandler.Open(fileStorageName);
            var features = FileStorageFeatureFactory.CreateFileStorageFeatureList(sourceFileStorageHandler.DataFileHeaderStruct.fileStorageFeatures);

            if (verbose && !sourceFileStorageHandler.SupportsFeature(FileStorageFeatureEnum.StoreMetaData))
            {
                Console.WriteLine();
                Console.WriteLine("The datastore does not support metadata feature and thus the verbose output is not available.");
                Console.WriteLine("Hint: Use the replicate option to promote this FileStorage to one that does support this feature.");
                Console.WriteLine("Press a key to continue outputting quick dir");
                Console.ReadKey();
                verbose = false;
            }
            else
            {
                Console.WriteLine(sourceFileStorageHandler.DataFileHeaderStruct.fileStorageFeatures);
            }

            Int64 totalSize = 0;

            try
            {
                ProgressNotifier progressNotifier = new ProgressNotifier("Dir");
                var         count           = 0;
                DateTime    startDateTime   = DateTime.Now;
                List <Guid> dataIdentifiers = FileStorageFacade.GetAllDataIdentifiersBasedUponFileStorageIndexFile(fileStorageName, new FileStorageHandler.ExposeProgressDelegate(progressNotifier.ShowProgress));

                if (verbose)
                {
                    Console.WriteLine("Data identifier                      | Text identifier  | Creation date     | Size ");
                    Console.WriteLine("-------------------------------------+------------------+-------------------+-----------------");
                }
                else
                {
                    Console.WriteLine("Data identifier                      | Text identifier   ");
                    Console.WriteLine("-------------------------------------+-------------------");
                }


                foreach (Guid currentDataIdentifier in dataIdentifiers)
                {
                    string interpretedString = currentDataIdentifier.ToNFileStorageOrigFileName();

                    if (verbose)
                    {
                        var   metaDataContainer = FileStorageFacade.GetMetaData(fileStorageName, currentDataIdentifier);
                        Int64 binarySizeInBytes = metaDataContainer.BinarySizeInBytes;
                        totalSize += binarySizeInBytes;
                        DateTime creationDate = metaDataContainer.CreationDateUTC;
                        Console.WriteLine(string.Format("{0} | {1} | {2} | {3:0,0,0,0}", currentDataIdentifier, interpretedString, creationDate.ToString("yyyyMMdd hh:mm:ss"), binarySizeInBytes));
                    }
                    else
                    {
                        Console.WriteLine(string.Format("{0} | {1} | ", currentDataIdentifier, interpretedString));
                    }

                    count++;
                }

                if (verbose)
                {
                    Console.WriteLine(string.Format("{0} files found ({1:0,0,0,0} bytes)", count, (int)totalSize));
                }
                else
                {
                    Console.WriteLine(string.Format("{0} files found", count));
                }

                TimeSpan timeSpan = DateTime.Now - startDateTime;
                Console.WriteLine(string.Format("This operation took {0} msecs", (Int64)timeSpan.TotalMilliseconds));
            }
            catch (Exception e)
            {
                Console.WriteLine(string.Format("An error occured; {0}", e.Message));
                Console.WriteLine(string.Format("An error occured; {0}", e.StackTrace));
            }
        }
예제 #19
0
        public static string GetStringData(string fileStorageName, Guid dataIdentifier, Encoding encoding)
        {
            var fileStorageHandler = FileStorageHandler.Open(fileStorageName);

            return(fileStorageHandler.GetStringData(dataIdentifier, encoding, StreamStateBehaviour.OpenNewStreamForReading, StreamStateBehaviour.OpenNewStreamForReading));
        }
예제 #20
0
        public static bool Exists(string fileStorageName, Guid dataIdentifier)
        {
            var fileStorageHandler = FileStorageHandler.Open(fileStorageName);

            return(fileStorageHandler.Exists(dataIdentifier, StreamStateBehaviour.OpenNewStreamForReading));
        }
예제 #21
0
        public static void Replicate(string sourcefileStorageName, string targetfileStorageName, ReplicateBehaviour replicateBehaviour, AddFileBehaviour addFileBehaviour, FileStorageHandler.ExposeProgressDelegate exposeProgressDelegatePhase1, FileStorageHandler.ExposeProgressDelegate exposeProgressDelegatePhase2)
        {
            var sourceFileStorageHandler = FileStorageHandler.Open(sourcefileStorageName);

            switch (replicateBehaviour)
            {
            case ReplicateBehaviour.AddToExistingStorage:
                //
                // nothing to check here
                //

                break;

            case ReplicateBehaviour.ReplicateToNewStorage:

                //
                // ensure target does not yet exist
                //
                Create(targetfileStorageName, CreateFileStorageBehaviour.ThrowExceptionWhenExists);

                break;

            default:
                throw new NotSupportedException(string.Format("Unsupported replicate behaviour {0}", replicateBehaviour));
            }

            var targetFileStorageHandler = FileStorageHandler.Open(targetfileStorageName);

            //
            // open source streams
            //
            using (sourceFileStorageHandler.indexStream = FileStreamFactory.CreateFileStream(sourceFileStorageHandler.indexFilename, StreamStateBehaviour.OpenNewStreamForReading))
            {
                using (sourceFileStorageHandler.dataStream = FileStreamFactory.CreateFileStream(sourceFileStorageHandler.dataFilename, StreamStateBehaviour.OpenNewStreamForReading))
                {
                    //
                    // open target streams
                    //
                    using (targetFileStorageHandler.indexStream = FileStreamFactory.CreateFileStream(targetFileStorageHandler.indexFilename, StreamStateBehaviour.OpenNewStreamForReadingAndWriting))
                    {
                        using (targetFileStorageHandler.dataStream = FileStreamFactory.CreateFileStream(targetFileStorageHandler.dataFilename, StreamStateBehaviour.OpenNewStreamForReadingAndWriting))
                        {
                            var allIdentifiers = sourceFileStorageHandler.GetAllDataIdentifiersBasedUponFileStorageIndexFile(StreamStateBehaviour.UseExistingStream, exposeProgressDelegatePhase1);

                            //
                            // start replicate process
                            //
                            foreach (var dataIdentifier in allIdentifiers)
                            {
                                sourceFileStorageHandler.ExportToOtherFileStorage(dataIdentifier, targetFileStorageHandler, addFileBehaviour, StreamStateBehaviour.UseExistingStream, StreamStateBehaviour.UseExistingStream, StreamStateBehaviour.UseExistingStream, StreamStateBehaviour.UseExistingStream);
                                if (exposeProgressDelegatePhase2 != null)
                                {
                                    exposeProgressDelegatePhase2.Invoke(dataIdentifier);
                                }
                            }
                            if (exposeProgressDelegatePhase2 != null)
                            {
                                exposeProgressDelegatePhase2.Invoke(true);
                            }
                        }
                    }
                }
            }
        }
예제 #22
0
 public static void Create(string fileStorageName, CreateFileStorageBehaviour createFileStorageBehaviour)
 {
     FileStorageHandler.Create(fileStorageName, FileStorageFeatureFactory.GetDefaultFeatures(), createFileStorageBehaviour);
 }
예제 #23
0
        public static void StoreStream(string fileStorageName, Guid dataIdentifier, Stream streamToStore, int numberOfBytes, ICustomMetaData customMetaData, AddFileBehaviour addFileBehaviour)
        {
            var fileStorageHandler = FileStorageHandler.Open(fileStorageName);

            fileStorageHandler.StoreStream(dataIdentifier, streamToStore, numberOfBytes, customMetaData, addFileBehaviour, StreamStateBehaviour.OpenNewStreamForReadingAndWriting, StreamStateBehaviour.OpenNewStreamForReadingAndWriting);
        }
예제 #24
0
        public static void ExportToFile(string fileStorageName, Guid dataIdentifier, string outputFile, ExportFileBehaviour exportFileBehaviour)
        {
            var fileStorageHandler = FileStorageHandler.Open(fileStorageName);

            fileStorageHandler.ExportToFile(dataIdentifier, outputFile, exportFileBehaviour);
        }
예제 #25
0
        public static void StoreHttpRequest(string fileStorageName, Guid dataIdentifier, string url, ICustomMetaData customMetaData, AddFileBehaviour addFileBehaviour, string userAgent)
        {
            var fileStorageHandler = FileStorageHandler.Open(fileStorageName);

            fileStorageHandler.StoreHttpRequest(dataIdentifier, url, customMetaData, addFileBehaviour, userAgent, StreamStateBehaviour.OpenNewStreamForReadingAndWriting, StreamStateBehaviour.OpenNewStreamForReadingAndWriting);
        }
예제 #26
0
        public static IEnumerable GetAllDataIdentifierEnumerableBasedUponFileStorageDataFile(string fileStorageName)
        {
            var fileStorageHandler = FileStorageHandler.Open(fileStorageName);

            return(fileStorageHandler.GetAllDataIdentifierEnumerableBasedUponFileStorageDataFile());
        }
예제 #27
0
        public static MetaDataContainer GetMetaData(string fileStorageName, Guid dataIdentifier)
        {
            var fileStorageHandler = FileStorageHandler.Open(fileStorageName);

            return(fileStorageHandler.GetMetaDataContainer(dataIdentifier, StreamStateBehaviour.OpenNewStreamForReading, StreamStateBehaviour.OpenNewStreamForReading));
        }
예제 #28
0
        public static byte[] GetFileByteData(string fileStorageName, Guid dataIdentifier)
        {
            var fileStorageHandler = FileStorageHandler.Open(fileStorageName);

            return(fileStorageHandler.GetFileByteData(dataIdentifier, StreamStateBehaviour.OpenNewStreamForReading, StreamStateBehaviour.OpenNewStreamForReading));
        }