Esempio n. 1
0
        private void BinarySearchButton_Click(object sender, EventArgs e)
        {
            if (!File.Exists(_binaryFile))
            {
                ShowMessage("Vyhledávání není možné provést!\nBinární soubor není inicializován!\n\nPrvnì ho inicializujte!", MessageBoxIcon.Warning, "Chyba");
                return;
            }

            BinaryStorage <VertexData> bs     = new BinaryStorage <VertexData>(_binaryFile);
            BinaryFindRemoveDialog     dialog = new BinaryFindRemoveDialog();

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    VertexData item = bs.Find(dialog.Key, dialog.Method);
                    if (item != null)
                    {
                        ShowMessage("Prvek s klíèem '" + dialog.Key + "' byl Nalezen!\nSouøadnice: [" + item.X + ", " + item.Y + "]", MessageBoxIcon.Information, "Vyhledání");
                    }
                    else
                    {
                        ShowMessage("Prvek s klíèem '" + dialog.Key + "' nebylo možné odstranit!\nJe možné že již byl odstranìn!", MessageBoxIcon.Warning, "Vyhledání");
                    }
                }
                catch (Exception ex)
                {
                    ShowMessage(ex.Message, MessageBoxIcon.Error, "Chyba");
                }
            }
        }
Esempio n. 2
0
        public Main()
        {
            _settingsStorage = new PluginJsonStorage <Settings>();
            _settings        = _settingsStorage.Load();

            Stopwatch.Normal("|Microsoft.Plugin.Program.Main|Preload programs cost", () =>
            {
                _win32Storage = new BinaryStorage <Programs.Win32[]>("Win32");
                _win32s       = _win32Storage.TryLoad(new Programs.Win32[] { });

                _packageRepository.Load();
            });
            Log.Info($"|Microsoft.Plugin.Program.Main|Number of preload win32 programs <{_win32s.Length}>");

            var a = Task.Run(() =>
            {
                if (IsStartupIndexProgramsRequired || !_win32s.Any())
                {
                    Stopwatch.Normal("|Microsoft.Plugin.Program.Main|Win32Program index cost", IndexWin32Programs);
                }
            });

            var b = Task.Run(() =>
            {
                if (IsStartupIndexProgramsRequired || !_packageRepository.Any())
                {
                    Stopwatch.Normal("|Microsoft.Plugin.Program.Main|Win32Program index cost", _packageRepository.IndexPrograms);
                }
            });


            Task.WaitAll(a, b);

            _settings.LastIndexTime = DateTime.Today;
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            int         cnt  = 1;
            List <Item> data = Random(cnt);

            BinaryStorage <Item> bw = new BinaryStorage <Item>("./data.bin");

            bw.WriteBinaryFile(data);

            bw.Find("K_1");

            bool res = bw.RemoveItem("K_1");

            bw.Find("K_1");


            List <Item> output = bw.ReadBinaryFile();

            foreach (var i in output)
            {
                Console.WriteLine(i.Key);
            }

            /*for(int i = 1; i <= cnt; i++)
             * {
             *  string search = "K_" + i;
             *  Item val = bw.Find(search, SearchMethod.Interpolation);
             *  if(val == null || val.Key != search)
             *  {
             *      break;
             *  }
             * }*/

            Console.ReadLine();
        }
        public void TestDeserialize1()
        {
            string code = "a=1;";
            Dictionary <int, List <VariableLine> > unboundIdentifiers = null;
            List <ProtoCore.AST.Node> astNodes = null;

            GraphUtilities.ParseCodeBlockNodeStatements(code, unboundIdentifiers, out astNodes);

            Ui.Statement statement = new Ui.Statement(astNodes[0]);

            IStorage storage = new BinaryStorage();

            statement.Serialize(storage);
            Ui.Statement newStatement = new Ui.Statement(storage);
            storage.Seek(0, SeekOrigin.Begin);
            newStatement.Deserialize(storage);

            VariableSlotInfo outputExpression = new VariableSlotInfo("a", 1, uint.MaxValue);

            Assert.AreEqual("a", statement.DefinedVariable);
            Assert.AreEqual(outputExpression, statement.OutputExpression);
            Assert.AreEqual(0, statement.References.Count);
            Assert.AreEqual(0, statement.Children.Count);
            Assert.AreEqual(false, statement.IsSwappable);
            Assert.AreEqual(false, statement.IsComplex);
        }
Esempio n. 5
0
        public static void Initialize()
        {
            _storage       = new BinaryStorage <Dictionary <string, int> >("Image");
            _hashGenerator = new ImageHashGenerator();

            var usage = LoadStorageToConcurrentDictionary();

            foreach (var icon in new[] { Constant.DefaultIcon, Constant.MissingImgIcon })
            {
                ImageSource img = new BitmapImage(new Uri(icon));
                img.Freeze();
                ImageCache[icon] = img;
            }

            Task.Run(() =>
            {
                Stopwatch.Normal("|ImageLoader.Initialize|Preload images cost", () =>
                {
                    ImageCache.Data.AsParallel().ForAll(x =>
                    {
                        Load(x.Key);
                    });
                });
                Log.Info($"|ImageLoader.Initialize|Number of preload images is <{ImageCache.CacheSize()}>, Images Number: {ImageCache.CacheSize()}, Unique Items {ImageCache.UniqueImagesInCache()}");
            });
        }
Esempio n. 6
0
        public void TestBank()
        {
            Console.WriteLine("*****Test Account Service*****");
            Console.WriteLine("Create service!");
            BankAccount        jo        = new BankAccount(1, "Jo", "Pinkman", 100m, Status.Gold);
            BinaryStorage      storage   = new BinaryStorage();
            BallExchenger      exchenger = new BallExchenger();
            BankAccountService service   = new BankAccountService(jo, storage, exchenger);

            Console.WriteLine("Add more money!");
            Console.WriteLine($"{jo.Cash} - money have Jo!");
            Console.WriteLine($"{jo.BonusBalls} - bonus balls have Jo!");
            service.PutMoneyIntoTheAccount(1000m);
            Console.WriteLine($"{jo.Cash} - money have Jo now!");
            Console.WriteLine($"{jo.BonusBalls} - bonus balls have Jo now!");
            Console.WriteLine("Withdraw money!");
            service.WithdrawFromTheAccount(500m);
            Console.WriteLine($"{jo.Cash} - money have Jo now!");
            Console.WriteLine($"{jo.BonusBalls} - bonus balls have Jo now!");
            Console.WriteLine("Withdraw more money!");
            service.WithdrawFromTheAccount(1000m);
            Console.WriteLine($"{jo.Cash} - money have Jo now!");
            Console.WriteLine($"{jo.BonusBalls} - bonus balls have Jo now!");
            Console.WriteLine($"Lets try to freeze Jo!");
            service.FreezeTheAccount();
            Console.WriteLine("*****End of test Bank's Service*****");
        }
Esempio n. 7
0
File: Main.cs Progetto: danisein/Wox
 public Main()
 {
     _settingsStorage = new PluginJsonStorage<Settings>();
     _settings = _settingsStorage.Load();
     _cacheStorage = new BinaryStorage<ProgramIndexCache>();
     _cache = _cacheStorage.Load();
 }
Esempio n. 8
0
        public static void Initialize(Theme theme)
        {
            _storage       = new BinaryStorage <Dictionary <string, int> >("Image");
            _hashGenerator = new ImageHashGenerator();
            ImageCache.SetUsageAsDictionary(_storage.TryLoad(new Dictionary <string, int>()));

            foreach (var icon in new[] { Constant.DefaultIcon, Constant.ErrorIcon, Constant.LightThemedDefaultIcon, Constant.LightThemedErrorIcon })
            {
                ImageSource img = new BitmapImage(new Uri(icon));
                img.Freeze();
                ImageCache[icon] = img;
            }

            UpdateIconPath(theme);
            Task.Run(() =>
            {
                Stopwatch.Normal("|ImageLoader.Initialize|Preload images cost", () =>
                {
                    ImageCache.Usage.AsParallel().ForAll(x =>
                    {
                        Load(x.Key);
                    });
                });
                Log.Info($"|ImageLoader.Initialize|Number of preload images is <{ImageCache.Usage.Count}>, Images Number: {ImageCache.CacheSize()}, Unique Items {ImageCache.UniqueImagesInCache()}");
            });
        }
Esempio n. 9
0
        public void BuildAndRead_ZeroItem_Test()
        {
            List <DataItem>          data = Random(0);
            BinaryStorage <DataItem> bw   = new BinaryStorage <DataItem>(_testFile);

            Assert.ThrowsException <NoDataException>(() => bw.WriteBinaryFile(data));
        }
Esempio n. 10
0
        public ActionResult UploadImage(HttpPostedFileBase uploadFile, QuestionAnswer answer)
        {
            if (ModelState.IsValid)
            {
                if (uploadFile != null)
                {
                    // Das Frageobjekt aus der Datenbank holen
                    var a = db.Answers.Find(answer.Id);

                    if (a != null)
                    {
                        // die BinaryStorage für die Datenbank anlegen
                        var image = new BinaryStorage()
                        {
                            ImageFileType = uploadFile.ContentType,
                            ImageData     = new byte[uploadFile.ContentLength],
                        };

                        // Die Datei in die Binary Storage einlesen
                        uploadFile.InputStream.Read(image.ImageData, 0, uploadFile.ContentLength);

                        db.BinaryStorages.Add(image);
                        a.Image = image;

                        db.SaveChanges();

                        return(RedirectToAction("Index", new { id = a.Question.Id }));
                    }
                }
            }

            return(View());
        }
Esempio n. 11
0
File: Main.cs Progetto: znatz/Wox
 public Main()
 {
     _settingsStorage = new PluginJsonStorage <Settings>();
     _settings        = _settingsStorage.Load();
     _cacheStorage    = new BinaryStorage <ProgramIndexCache>();
     _cache           = _cacheStorage.Load();
 }
Esempio n. 12
0
        public Main()
        {
            _settingsStorage = new PluginJsonStorage <Settings>();
            _settings        = _settingsStorage.Load();

            Stopwatch.Normal("|Flow.Launcher.Plugin.Program.Main|Preload programs cost", () =>
            {
                _win32Storage = new BinaryStorage <Win32[]>("Win32");
                _win32s       = _win32Storage.TryLoad(new Win32[] { });
                _uwpStorage   = new BinaryStorage <UWP.Application[]>("UWP");
                _uwps         = _uwpStorage.TryLoad(new UWP.Application[] { });
            });
            Log.Info($"|Flow.Launcher.Plugin.Program.Main|Number of preload win32 programs <{_win32s.Length}>");
            Log.Info($"|Flow.Launcher.Plugin.Program.Main|Number of preload uwps <{_uwps.Length}>");

            var a = Task.Run(() =>
            {
                if (IsStartupIndexProgramsRequired || !_win32s.Any())
                {
                    Stopwatch.Normal("|Flow.Launcher.Plugin.Program.Main|Win32Program index cost", IndexWin32Programs);
                }
            });

            var b = Task.Run(() =>
            {
                if (IsStartupIndexProgramsRequired || !_uwps.Any())
                {
                    Stopwatch.Normal("|Flow.Launcher.Plugin.Program.Main|Win32Program index cost", IndexUWPPrograms);
                }
            });

            Task.WaitAll(a, b);

            _settings.LastIndexTime = DateTime.Today;
        }
Esempio n. 13
0
        private void BinaryRemoveButton_Click(object sender, EventArgs e)
        {
            if (!File.Exists(_binaryFile))
            {
                ShowMessage("Odstranìní není možné provést!\nBinární soubor není inicializován!\n\nPrvnì ho inicializujte!", MessageBoxIcon.Warning, "Chyba");
                return;
            }

            BinaryStorage <VertexData> bs     = new BinaryStorage <VertexData>(_binaryFile);
            BinaryFindRemoveDialog     dialog = new BinaryFindRemoveDialog(false);

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if (bs.RemoveItem(dialog.Key, dialog.Method))
                    {
                        ShowMessage("Prvek s klíèem '" + dialog.Key + "' byl odstranìn!", MessageBoxIcon.Information, "Odstranìní");
                    }
                    else
                    {
                        ShowMessage("Prvek s klíèem '" + dialog.Key + "' nebylo možné odstranit!\nJe možné že již byl odstranìn!", MessageBoxIcon.Warning, "Odstranìní");
                    }
                }
                catch (Exception ex)
                {
                    ShowMessage(ex.Message, MessageBoxIcon.Error, "Chyba");
                }
            }
        }
Esempio n. 14
0
        public void ShouldContain()
        {
            // Arrange
            string shouldContainFolder = "ShouldGet";
            string inputFolderPath     = Path.Combine(this.inputBasePath, shouldContainFolder);
            string assertFolderPath    = Path.Combine(this.assertBasePath, shouldContainFolder);

            // Act
            using (var storage = new BinaryStorage(new StorageConfiguration()
            {
                WorkingFolder = inputFolderPath
            }))
            {
                Directory.EnumerateFiles(assertFolderPath, "*", SearchOption.AllDirectories)
                .AsParallel().WithDegreeOfParallelism(degreeOfParallelism).ForAll(s =>
                {
                    string fileName = Path.GetFileName(s);
                    if (!storage.Contains(fileName))
                    {
                        Assert.Fail();
                    }
                });
            }
            // Assert
            Assert.IsTrue(true);
        }
Esempio n. 15
0
        public static void Initialize()
        {
            _storage         = new BinaryStorage <ConcurrentDictionary <string, int> > ("Image");
            ImageCache.Usage = _storage.TryLoad(new ConcurrentDictionary <string, int>());

            foreach (var icon in new[] { Constant.DefaultIcon, Constant.ErrorIcon })
            {
                ImageSource img = new BitmapImage(new Uri(icon));
                img.Freeze();
                ImageCache[icon] = img;
            }
            Task.Run(() =>
            {
                Stopwatch.Normal("|ImageLoader.Initialize|Preload images cost", () =>
                {
                    ImageCache.Usage.AsParallel().Where(i => !ImageCache.ContainsKey(i.Key)).ForAll(i =>
                    {
                        var img = Load(i.Key);
                        if (img != null)
                        {
                            ImageCache[i.Key] = img;
                        }
                    });
                });
                Log.Info($"|ImageLoader.Initialize|Number of preload images is <{ImageCache.Usage.Count}>");
            });
        }
Esempio n. 16
0
        public void ShouldGet()
        {
            // Arrange
            string inputFolder      = "ShouldGet";
            string inputFolderPath  = Path.Combine(this.inputBasePath, inputFolder);
            string assertFolderPath = Path.Combine(this.assertBasePath, inputFolder);

            // Act
            using (var storage = new BinaryStorage(new StorageConfiguration()
            {
                WorkingFolder = inputFolderPath
            }))
            {
                Directory.EnumerateFiles(assertFolderPath, "*", SearchOption.AllDirectories)
                .AsParallel().WithDegreeOfParallelism(degreeOfParallelism).ForAll(s =>
                {
                    string fileName = Path.GetFileName(s);
                    using (var resultStream = storage.Get(fileName))
                    {
                        using (var sourceStream = new FileStream(s, FileMode.Open, FileAccess.Read))
                        {
                            if (!AreStreamsEqual(s, sourceStream, resultStream))
                            {
                                // Assert
                                Assert.IsTrue(false);
                            }
                        }
                    }
                });
            }
            // Assert
            Assert.IsTrue(true);
        }
Esempio n. 17
0
 private static void WithStorage(Action <IBinaryStorage> code)
 {
     using (var storage = new BinaryStorage(new StorageConfiguration {
         WorkingFolder = DIRECTORY
     }))
         code.Invoke(storage);
 }
Esempio n. 18
0
 private void SendBackBinaryData(int time)
 {
     try
     {
         IReView_Feed proxy = RPC_Manager.Instance.Get_Client_Proxy <RPC_Client_Proxy_IReView_Feed>();
         if (proxy != null && BinaryStorage != null)
         {
             // Collect all data entries and create a package to send
             List <BinaryData> dataEntries = BinaryStorage.GetData(time);
             List <long>       idList      = new List <long>();
             List <int>        timeList    = new List <int>();
             List <byte[]>     dataList    = new List <byte[]>();
             foreach (BinaryData data in dataEntries)
             {
                 idList.Add(data.Id);
                 timeList.Add(data.Time);
                 dataList.Add(data.Data);
             }
             proxy.SendBackBinaryData(idList.ToArray(), timeList.ToArray(), dataList.ToArray());
         }
     }
     catch (Exception e)
     {
         RPC_Manager.Instance.Close();
     }
 }
Esempio n. 19
0
        public void TestCreate00()
        {
            IStorage       storage        = new BinaryStorage();
            EdgeController edgeController = null;

            Assert.Throws <ArgumentNullException>(() =>
            {
                IVisualEdge edge = VisualEdge.Create(edgeController, storage);
            });
        }
Esempio n. 20
0
        public void TestCreate00()
        {
            IGraphController graphController = null;
            IStorage         storage         = new BinaryStorage();

            Assert.Throws <ArgumentNullException>(() =>
            {
                ISlot slot = Slot.Create(graphController, storage);
            });
        }
Esempio n. 21
0
        public Main()
        {
            _settingsStorage = new PluginJsonStorage <Settings>();
            _settings        = _settingsStorage.Load();

            Stopwatch.Normal("|Wox.Plugin.Program.Main|Preload programs cost", () => {
                _win32Storage = new BinaryStorage <Win32[]>("Win32");
                _win32s       = _win32Storage.TryLoad(new Win32[] { });
            });
            Log.Info($"|Wox.Plugin.Program.Main|Number of preload win32 programs <{_win32s.Length}>");
        }
Esempio n. 22
0
        public void BuildAndRead_OneItem_Test()
        {
            List <DataItem>          data = Random(1);
            BinaryStorage <DataItem> bw   = new BinaryStorage <DataItem>(_testFile, 100);

            bw.WriteBinaryFile(data);

            List <DataItem> readed = bw.ReadBinaryFile();

            ListContainSameValues(data, readed);
        }
        public void Implement_Interface_IFormattable_Class_Book(string format, string result)
        {
            var storage = new BinaryStorage();

            var service = new BookListService(logger);

            service.ReadList(storage);

            var assert1 = service.ListBooks[0].ToString(format, CultureInfo.GetCultureInfo("en-IN"));

            Assert.AreEqual(result, assert1);
        }
Esempio n. 24
0
        public void BuildAndRead_OneThousandItem_Test()
        {
            List <DataItem>          data = Random(1000);
            BinaryStorage <DataItem> bw   = new BinaryStorage <DataItem>(_testFile, 100);

            bw.WriteBinaryFile(data);

            List <DataItem> readed = bw.ReadBinaryFile();

            ListContainSameValues(data, readed);
            Assert.AreEqual(data.Count, readed.Count);
        }
Esempio n. 25
0
 private static void PreLoadPrograms()
 {
     Logger.StopWatchNormal("Preload programs cost", () =>
     {
         _win32Storage = new BinaryStorage <Win32[]>("Win32");
         _win32s       = _win32Storage.TryLoad(new Win32[] { });
         _uwpStorage   = new BinaryStorage <UWP.Application[]>("UWP");
         _uwps         = _uwpStorage.TryLoad(new UWP.Application[] { });
     });
     Logger.WoxInfo($"Number of preload win32 programs <{_win32s.Length}>");
     Logger.WoxInfo($"Number of preload uwps <{_uwps.Length}>");
 }
        public void Extension_Class_Book_Expected_FormatException_If_Format_Is_Not_Support(string format, string result)
        {
            var storage = new BinaryStorage();

            var service = new BookListService(logger);

            service.ReadList(storage);

            var customFormat = new BookFormatProvider(logger);

            Assert.Throws <FormatException>(() => String.Format(customFormat, format, service.ListBooks[0]));
        }
Esempio n. 27
0
        internal static void Main(string[] args)
        {
            if (args.Length < 2 ||
                !Directory.Exists(args[0]) ||
                !Directory.Exists(args[1]))
            {
                Console.WriteLine("Usage: Lab.Interview.BinStorage.TestApp.exe InputFolder StorageFolder");
                return;
            }

            // Create storage and add data
            Console.WriteLine("Creating storage from " + args[0]);
            var stopwatch = Stopwatch.StartNew();

            using (var storage = new BinaryStorage(new StorageConfiguration()
            {
                WorkingFolder = args[1]
            })) {
                Directory.EnumerateFiles(args[0], "*", SearchOption.AllDirectories)
                .AsParallel().WithDegreeOfParallelism(4).ForAll(s => {
                    AddFile(storage, s);
                });
            }
            Console.WriteLine("Time to create: " + stopwatch.Elapsed);

            // Open storage and read data
            Console.WriteLine("Verifying data");
            stopwatch = Stopwatch.StartNew();
            using (var storage = new BinaryStorage(new StorageConfiguration()
            {
                WorkingFolder = args[1]
            })) {
                Directory.EnumerateFiles(args[0], "*", SearchOption.AllDirectories)
                .AsParallel().WithDegreeOfParallelism(4).ForAll(s => {
                    using (var ms1 = new MemoryStream()) {
                        storage.Get(s).CopyTo(ms1);
                        using (var ms2 = new MemoryStream()) {
                            using (var file = new FileStream(s, FileMode.Open)) {
                                {
                                    file.CopyTo(ms2);
                                    if (ms2.Length != ms1.Length)
                                    {
                                        throw new Exception();
                                    }
                                }
                            }
                        }
                    }
                });
            }
            Console.WriteLine("Time to verify: " + stopwatch.Elapsed);
        }
Esempio n. 28
0
        public static void Initialize()
        {
            Format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);

            Stopwatch.Normal("|Wox.Infrastructure.Alphabet.Initialize|Preload pinyin cache", () => {
                _pinyinStorage = new BinaryStorage <ConcurrentDictionary <string, string> >("Pinyin");
                PinyinCache    = _pinyinStorage.TryLoad(new ConcurrentDictionary <string, string>());
                // force pinyin library static constructor initialize
                PinyinHelper.toHanyuPinyinStringArray('T', Format);
            });
            Log.Info(
                $"|Wox.Infrastructure.Alphabet.Init ialize|Number of preload pinyin combination<{PinyinCache.Count}>");
        }
Esempio n. 29
0
        private void InitializePinyinHelpers()
        {
            _pinyinFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);

            Stopwatch.Normal("|Wox.Infrastructure.Alphabet.Initialize|Preload pinyin cache", () =>
            {
                _pinyinStorage = new BinaryStorage <Dictionary <string, string[][]> >("Pinyin");
                SetPinyinCacheAsDictionary(_pinyinStorage.TryLoad(new Dictionary <string, string[][]>()));

                // force pinyin library static constructor initialize
                PinyinHelper.toHanyuPinyinStringArray('T', _pinyinFormat);
            });
            Log.Info($"Number of preload pinyin combination<{_pinyinCache.Count}>", GetType());
        }
Esempio n. 30
0
        private void InitializePinyinHelpers()
        {
            Format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);

            Logger.StopWatchNormal("Preload pinyin cache", () =>
            {
                _pinyinStorage = new BinaryStorage <ConcurrentDictionary <string, string[][]> >("Pinyin");
                PinyinCache    = _pinyinStorage.TryLoad(new ConcurrentDictionary <string, string[][]>());

                // force pinyin library static constructor initialize
                PinyinHelper.toHanyuPinyinStringArray('T', Format);
            });
            Logger.WoxInfo($"Number of preload pinyin combination<{PinyinCache.Count}>");
        }
Esempio n. 31
0
        public void TestDeserilaizeOperationException()
        {
            IGraphController graphController = new GraphController(null);
            IStorage         storage         = new BinaryStorage();
            DataHeader       header          = new DataHeader();

            storage.WriteUnsignedInteger(FieldCode.DataHeaderSignature, 21);
            storage.Seek(0, SeekOrigin.Begin);

            Assert.Throws <InvalidOperationException>(() =>
            {
                header.Deserialize(storage);
            });
        }
Esempio n. 32
0
        public Main()
        {
            _settingsStorage = new PluginJsonStorage<Settings>();
            _settings = _settingsStorage.Load();

            Stopwatch.Debug("Preload programs", () =>
            {
                _cacheStorage = new BinaryStorage<ProgramIndexCache>();
                _cache = _cacheStorage.Load();
                _win32s = _cache.Programs;
            });
            Log.Info($"Preload {_win32s.Length} programs from cache");
            Stopwatch.Debug("Program Index", IndexPrograms);
        }
Esempio n. 33
0
        internal static void Main(string[] args)
        {
            if (args.Length < 2
                || !Directory.Exists(args[0])
                || !Directory.Exists(args[1])) {
                Console.WriteLine("Usage: Lab.Interview.BinStorage.TestApp.exe InputFolder StorageFolder");
                return;
            }

            // Create storage and add data
            Console.WriteLine("Creating storage from " + args[0]);
            var stopwatch = Stopwatch.StartNew();
            using (var storage = new BinaryStorage(new StorageConfiguration() { WorkingFolder = args[1] })) {
                Directory.EnumerateFiles(args[0], "*", SearchOption.AllDirectories)
                    .AsParallel().WithDegreeOfParallelism(4).ForAll(s => {
                        AddFile(storage, s);
                    });

            }
            Console.WriteLine("Time to create: " + stopwatch.Elapsed);

            // Open storage and read data
            Console.WriteLine("Verifying data");
            stopwatch = Stopwatch.StartNew();
            using (var storage = new BinaryStorage(new StorageConfiguration() { WorkingFolder = args[1] })) {
                Directory.EnumerateFiles(args[0], "*", SearchOption.AllDirectories)
                    .AsParallel().WithDegreeOfParallelism(4).ForAll(s => {
                        using (var ms1 = new MemoryStream()) {
                            storage.Get(s).CopyTo(ms1);
                            using (var ms2 = new MemoryStream()) {
                                using (var file = new FileStream(s, FileMode.Open)) {
                                    {
                                        file.CopyTo(ms2);
                                        if (ms2.Length != ms1.Length)
                                            throw new Exception();
                                    }
                                }
                            }
                        }
                    });
            }
            Console.WriteLine("Time to verify: " + stopwatch.Elapsed);
        }
Esempio n. 34
0
        public Main()
        {
            _settingsStorage = new PluginJsonStorage<Settings>();
            _settings = _settingsStorage.Load();

            Stopwatch.Normal("Preload programs", () =>
            {
                _win32Storage = new BinaryStorage<Win32[]>("Win32Cache");
                _win32s = _win32Storage.TryLoad(new Win32[] { });
                _uwpStorage = new BinaryStorage<UWP.Application[]>("UWPCache");
                _uwps = _uwpStorage.TryLoad(new UWP.Application[] { });

            });
            Log.Info($"Preload {_win32s.Length} win32 programs from cache");
            Log.Info($"Preload {_uwps.Length} uwps from cache");
            Task.Run(() =>
            {
                Stopwatch.Normal("Program Index", IndexPrograms);
            });
        }
Esempio n. 35
0
 static ImageLoader()
 {
     _storage = new BinaryStorage<ImageCache>();
     _cache = _storage.Load();
 }
Esempio n. 36
0
 static ImageLoader()
 {
     Storage = new BinaryStorage<ConcurrentDictionary<string, int>> ("ImageCache");
     ImageCache.Usage = Storage.TryLoad(new ConcurrentDictionary<string, int>());
 }