Beispiel #1
0
        // Create data and category files
        private async Task <bool> Initialize()
        {
            string assemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            var dataController  = new StorageController <DataModel>(Path.Combine(assemblyPath, SecureManager.DataFileName));
            var dataInitializer = new StorageInitializer <DataModel>(new DataGenerator(), new Cryptographer(SecureManager.Key));

            try
            {
                List <DataModel> dataList = await dataInitializer.GetDataAsync();

                await dataController.CreateStorageAsync(dataList);
            }
            catch (InvalidOperationException ex)
            {
                MessageBox.Show($"Can't write data to {ex.Source}");
                return(false);
            }

            var categoriesController = new StorageController <CategoryModel>(Path.Combine(assemblyPath, SecureManager.CategoriesFileName));

            try
            {
                await categoriesController.CreateStorageAsync(new List <CategoryModel>());
            }
            catch (InvalidOperationException ex)
            {
                MessageBox.Show($"Can't write data to {ex.Source}");
                return(false);
            }

            return(true);
        }