Ejemplo n.º 1
0
        public static string AddFolder(DataConfig providerConfig, POCO.SakaiFolder ntfsFolder)
        {
            switch (providerConfig.ProviderType)
            {
            case "azure.tableservice":

                AzureSakaiFolder az = new AzureSakaiFolder(ntfsFolder);

                CloudTable     table     = Utils.GetCloudTable(providerConfig, SakaiResource.AzureTableNames.SakaiFolders);
                TableOperation operation = TableOperation.InsertOrMerge(az);
                Task           tUpdate   = table.ExecuteAsync(operation);
                tUpdate.Wait();

                break;

            case "internal.mongodb":
                IMongoCollection <MongoSakaiFolder> collection = Utils.GetMongoCollection <MongoSakaiFolder>(providerConfig, SakaiResource.MongoTableNames.SakaiFolders);
                MongoSakaiFolder mongoObject = Utils.ConvertType <MongoSakaiFolder>(ntfsFolder);
                collection.InsertOne(mongoObject);
                return(string.Empty);

            default:
                throw new ApplicationException("Data provider not recognised: " + providerConfig.ProviderType);
            }

            //TODO return id of new object if supported
            return(string.Empty);
        }
Ejemplo n.º 2
0
        public static void UpdateFolder(DataConfig providerConfig, POCO.SakaiFolder ntfsFolder)
        {
            switch (providerConfig.ProviderType)
            {
            case "azure.tableservice":

                AzureSakaiFolder az = new AzureSakaiFolder(ntfsFolder);

                CloudTable     table     = Utils.GetCloudTable(providerConfig, SakaiResource.AzureTableNames.SakaiFolders);
                TableOperation operation = TableOperation.InsertOrMerge(az);
                Task           tUpdate   = table.ExecuteAsync(operation);
                tUpdate.Wait();

                break;

            case "internal.mongodb":
                IMongoCollection <MongoSakaiFolderUpsert> collection = Utils.GetMongoCollection <MongoSakaiFolderUpsert>(providerConfig, SakaiResource.MongoTableNames.SakaiFolders);
                MongoSakaiFolderUpsert mongoObject = Utils.ConvertType <MongoSakaiFolderUpsert>(ntfsFolder);

                // Create the upsert filter
                List <DataFactory.Filter> filters  = new List <DataFactory.Filter>();
                DataFactory.Filter        pkFilter = new DataFactory.Filter("PartitionKey", Utils.CleanTableKey(mongoObject.PartitionKey), "eq");
                DataFactory.Filter        rkFilter = new DataFactory.Filter("RowKey", Utils.CleanTableKey(mongoObject.RowKey), "eq");
                filters.Add(pkFilter);
                filters.Add(rkFilter);
                FilterDefinition <MongoSakaiFolderUpsert> filter = Utils.GenerateMongoFilter <MongoSakaiFolderUpsert>(filters);

                // Create the upsert options
                MongoDB.Driver.ReplaceOptions options = new ReplaceOptions();
                options.IsUpsert = true;

                // Upsert
                collection.ReplaceOne(filter, mongoObject, options);

                return;

            default:
                throw new ApplicationException("Data provider not recognised: " + providerConfig.ProviderType);
            }

            //TODO return id of new object if supported
            return;
        }