Example #1
0
        static async Task Main(string[] args)
        {
            var jsonSerializer        = new Serializers.JsonSerializer(new JsonSerializerSettings());
            var fileStorageProvider   = new LocalStorageProvider(@".\");
            var memoryStorageProvider = new MemoryStorageProvider();

            var rawFileStorage   = new RawStorageClient(fileStorageProvider);
            var rawMemoryStorage = new RawStorageClient(memoryStorageProvider);

            var fileStorage   = new ObjectStorageClient(rawFileStorage, jsonSerializer);
            var memoryStorage = new ObjectStorageClient(rawMemoryStorage, jsonSerializer);

            Console.WriteLine("object memory storage");
            await TryStorage("test", memoryStorage);

            Console.WriteLine("object file storage");
            await TryStorage("test", fileStorage);

            Console.WriteLine("raw file storage");
            await TryRawStorage("test", rawFileStorage);

            Console.WriteLine("raw memory storage");
            await TryRawStorage("test", rawMemoryStorage);

            Console.WriteLine("Concurrent writes and reads");

            var tasks = Enumerable.Repeat(Enumerable.Range(1, 3).ToList(), 3)
                        .SelectMany(x => x)
                        .Select(x => TryRawStorage(x.ToString(), rawMemoryStorage));

            await Task.WhenAll(tasks);
        }
Example #2
0
        public async Task InsertMultipleEntityIntoDatabase()
        {
            var database = new LocalStorageProvider();
            await database.InitializeDatabaseAsync();

            await database.AddAccountsAsync(GenerateBatchTestData());
        }
Example #3
0
        private async void LoadDutyGroups()
        {
            LocalStorageProvider storage = new LocalStorageProvider();

            var directory = Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Iterations", "Common"));

            StorageResult = await storage.LoadGroups(directory.FullName);

            if (StorageResult.Result != null)
            {
                string json = (string)StorageResult.Result;

                List <DutyGroup> lst = JsonConvert.DeserializeObject <List <DutyGroup> >(json);
                if (lst != null && lst.Count > 0)
                {
                    AvailableGroups = new ObservableCollection <DutyGroup>(lst);
                }
                else
                {
                    InitDummyGroups();
                }
            }
            else
            {
                InitDummyGroups();
            }
        }
Example #4
0
        public void Initialize()
        {
            //日志函数
            void LogAction(string tag, string message)
            {
                if (tag.Equals("error", StringComparison.CurrentCultureIgnoreCase))
                {
                    Logger.Error(message);
                }
                else
                {
                    Logger.Debug(message);
                }
            }

            #region 配置存储程序
            switch (AppConfiguration["StorageProvider:Type"])
            {
            case "LocalStorageProvider":
            {
                var config = GetConfigFromConfigOrSettingsByKey <LocalStorageConfig>("LocalStorageProvider").Result;

                if (config != null)
                {
                    if (!config.RootPath.Contains(":"))
                    {
                        var hostingEnvironment = IocManager.Resolve <IWebHostEnvironment>();
                        config.RootPath = Path.Combine(hostingEnvironment.WebRootPath, config.RootPath);
                    }
                }
                if (!Directory.Exists(config.RootPath))
                {
                    Directory.CreateDirectory(config.RootPath);
                }

                StorageProvider = new LocalStorageProvider(config);
                break;
            }

            case "AliyunOssStorageProvider":
            {
                var aliyunOssConfig = GetConfigFromConfigOrSettingsByKey <AliyunOssConfig>("AliyunOssStorageProvider").Result;;
                StorageProvider = new AliyunOssStorageProvider(aliyunOssConfig);
                break;
            }

            case "TencentCosStorageProvider":
            {
                var config = GetConfigFromConfigOrSettingsByKey <TencentCosConfig>("TencentCosStorageProvider").Result;;
                StorageProvider = new TencentStorageProvider(config);
                break;
            }

            default:
                break;
            }
            #endregion
        }
Example #5
0
        public async Task ResetDatabase()
        {
            var database = new LocalStorageProvider();
            await database.InitializeDatabaseAsync();

            await InsertMultipleEntityIntoDatabase();

            await database.ResetDatabaseAsync();
        }
Example #6
0
        private async void SyncDutyGroups()
        {
            var directory = Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Iterations", "Common"));

            //TODO: add proper factory infrastructure
            LocalStorageProvider storage = new LocalStorageProvider();

            StorageResult = await storage.StoreGroups(AvailableGroups.ToList(), directory.FullName);
        }
Example #7
0
        private async void StoreTempIteration()
        {
            var directory = Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Iterations", "Common"));

            LocalStorageProvider provider = new LocalStorageProvider();

            string json = JsonConvert.SerializeObject(Provider.Iteration);

            StorageResult result = await provider.StoreTempIteration(json, directory.FullName);
        }
Example #8
0
        public async Task QueryDatabase()
        {
            var database = new LocalStorageProvider();
            await database.InitializeDatabaseAsync();

            await database.AddAccountsAsync(GenerateBatchTestData());

            await database.GetAllAccountsAsync();

            // No assert needed.
        }
        public LocalStorageTests()
        {
            rootPath = Path.Combine(Directory.GetCurrentDirectory(), "Files");
            if (!Directory.Exists(rootPath))
            {
                Directory.CreateDirectory(rootPath);
            }

            rootUrl         = "/";
            StorageProvider = new LocalStorageProvider(rootPath, rootUrl);
        }
        public async void LoadIterations(string directory)
        {
            LocalStorageProvider provider = new LocalStorageProvider();

            StorageResult result = await provider.LoadStoredIterationsAsync(directory);

            if ((result.Status == StorageStatus.Success || result.Status == StorageStatus.Warning) && result.Result != null)
            {
                BrowsedIterations = new ObservableCollection <BrowsedIteration>((List <BrowsedIteration>)result.Result);
            }
        }
Example #11
0
        public async Task InsertSingleEntityIntoDatabase()
        {
            var database = new LocalStorageProvider();
            await database.InitializeDatabaseAsync();

            await database.AddAccountAsync(new Account
            {
                AccountName      = "LightStudio:[email protected]",
                AccountKeyBase32 = "sertcew43d5432wfe5yklv==/ewed",
                AccountIcon      = "ms-appx:///Assets/Services/MicrosoftAccount.png",
            });
        }
Example #12
0
        public IAsyncAction DeleteAccountInRoamingStorageAsync(Account account)
        {
            return(Task.Run(async() =>
            {
                if (!_isInitialized)
                {
                    await InitializeStorageAsync();
                }

                var dbDriver = new LocalStorageProvider();
                await dbDriver.InitializeDatabaseAsync();
                await DeleteAccountInRoamingStorageAsync(await dbDriver.GetRoamingGuidFromAccountNameAsync(account.AccountName));
            }).AsAsyncAction());
        }
Example #13
0
        public async void LoadIterations(string directory)
        {
            LocalStorageProvider provider = new LocalStorageProvider();

            StorageResult result = await provider.LoadStoredIterationsAsync(directory, CheckSubFolder);


            if (result.Status == StorageStatus.Success || result.Status == StorageStatus.Warning)
            {
                BrowsedIterations = new ObservableCollection <BrowsedIteration>((List <BrowsedIteration>)result.Result);

                // Generate statistics
                GenerateBasicStatistics();
            }
        }
Example #14
0
        public async Task DeleteSingleEntity()
        {
            var database = new LocalStorageProvider();
            await database.InitializeDatabaseAsync();

            var account = new Account
            {
                AccountName      = "LightStudio:[email protected]",
                AccountKeyBase32 = "sertcew43d5432wfe5yklv==/ewed",
                AccountIcon      = "ms-appx:///Assets/Services/MicrosoftAccount.png",
            };
            var guid = Guid.NewGuid();
            await database.AddAccountAsync(account, guid);

            await database.DeleteAccountAsync(account, guid);
        }
Example #15
0
        public void Project()
        {
            var storage = new LocalStorageProvider();

            // Create some basic information about the model.
            var address = Model.CreateAddress(storage, "Office", "12345 Sesame Street", "Gotham", null, "New York", "10005", "USA");
            var user    = Model.CreateUser(storage, "ikeough", "Ian", "Keough", "*****@*****.**", IfcRoleEnum.ARCHITECT);
            var org     = Model.CreateOrganization("Test", "A test organization for model creation.", address);

            // Create the model.
            var m = new Model(storage, "Test Project", "A test project for the Elements API.", address, user, org);

            // Write the model to STEP.
            var stepPath = Path.Combine(BASELINES, "project.ifc");
            var step     = m.ToSTEP(stepPath);

            File.WriteAllText(stepPath, step);
        }
Example #16
0
        public async Task GetRoamingGuid()
        {
            var database = new LocalStorageProvider();
            await database.InitializeDatabaseAsync();

            var account = new Account
            {
                AccountName      = "LightStudio:[email protected]",
                AccountKeyBase32 = "sertcew43d5432wfe5yklv==/eweddiff",
                AccountIcon      = "ms-appx:///Assets/Services/MicrosoftAccount.png",
            };
            var guid = Guid.NewGuid();
            await database.AddAccountAsync(account, guid);

            var resultguid = await database.GetRoamingGuidFromAccountNameAsync(account.AccountName);

            Assert.AreEqual(guid, resultguid);
        }
Example #17
0
        public IAsyncAction ModifyAccountToRoamingStorageAsync(Account oldAccount, Account newAccount)
        {
            return(Task.Run(async() =>
            {
                if (!_isInitialized)
                {
                    await InitializeStorageAsync();
                }

                var dbDriver = new LocalStorageProvider();
                await dbDriver.InitializeDatabaseAsync();
                var guid = await dbDriver.GetRoamingGuidFromAccountNameAsync(oldAccount.AccountName);

                // Delete
                await DeleteAccountInRoamingStorageAsync(guid);

                // Create new
                await AddAccountToRoamingStorageAsync(newAccount, guid);
            }).AsAsyncAction());
        }
Example #18
0
        private async void FinishIterationAndStoreIt()
        {
            _Provider.EndIteration();

            SetPrettyIterationPrint();

            var directory = Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Iterations"));

            //TODO: add proper factory infrastructure
            LocalStorageProvider storage = new LocalStorageProvider();

            StorageResult = await storage.StoreIteration(_Provider.Iteration, directory.FullName);

            _Provider.StartNewIteration();

            NotifyPropertyChanged(() => CurrentDuty);
            NotifyPropertyChanged(() => CurrentDutyGroup);
            ResetAndStopTimer();

            var directoryTemp = Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Iterations", "Common"));
            await storage.DeleteTempIteration(directoryTemp.FullName);
        }
Example #19
0
        private async void LoadKeywords()
        {
            LocalStorageProvider storage = new LocalStorageProvider();

            var directory = Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Iterations", "Common"));

            StorageResult = await storage.LoadKeywords(directory.FullName);

            if (StorageResult.Result != null)
            {
                string val = StorageResult.Result.ToString();
                ObservableCollection <string> col = new ObservableCollection <string>();
                string[] tmp = val.Split(',');

                foreach (string kword in tmp)
                {
                    col.Add(kword.Trim());
                }

                AvailableKeywords = col;
            }
        }
Example #20
0
        private async void LoadTempIteration()
        {
            var directory = Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Iterations", "Common"));

            LocalStorageProvider provider = new LocalStorageProvider();
            StorageResult        result   = await provider.LoadTempIteration(directory.FullName);

            if (result.Result != null)
            {
                Iteration iteration = JsonConvert.DeserializeObject <Iteration>((string)result.Result);

                if (iteration != null && iteration.Duties != null && iteration.Duties.Count > 0)
                {
                    Provider.SetIteration(iteration);
                    NotifyPropertyChanged(() => CurrentDuty);
                    NotifyPropertyChanged(() => CurrentDutyGroup);

                    _LoadedFromTemp = true;

                    SetAndStartTimer();
                }
            }
        }
 public BlobTestBase(StorageFixture fixture)
 {
     BasePath  = StorageFixture.BasePath;
     _provider = new LocalStorageProvider(StorageFixture.BasePath);
 }
 /// <summary>
 /// The standard constructor to instantiate a new CaldavConnector. No settings set-up so far.
 /// </summary>
 public CaldavConnector()
 {
     //Deactivate certificate validation
     System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); };
     _localStorage = new LocalStorageProvider();
 }
Example #23
0
 public async Task InitializeDatabase()
 {
     var database = new LocalStorageProvider();
     await database.InitializeDatabaseAsync();
 }