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

                AzureNTFSFolder az = new AzureNTFSFolder(ntfsFolder);

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

                break;

            case "internal.mongodb":
                IMongoCollection <MongoNTFSFolder> collection = Utils.GetMongoCollection <MongoNTFSFolder>(providerConfig, MongoTableNames.NTFSFolders);
                MongoNTFSFolder mongoObject = Utils.ConvertType <MongoNTFSFolder>(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);
        }
Esempio n. 2
0
        public static void UpdateFolder(DataConfig providerConfig, POCO.NTFSFolder ntfsFolder)
        {
            switch (providerConfig.ProviderType)
            {
            case "azure.tableservice":

                AzureNTFSFolder az = new AzureNTFSFolder(ntfsFolder);

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

                break;

            case "internal.mongodb":
                IMongoCollection <MongoNTFSFolderUpsert> collection = Utils.GetMongoCollection <MongoNTFSFolderUpsert>(providerConfig, NTFS.MongoTableNames.NTFSFolders);
                MongoNTFSFolderUpsert mongoObject = Utils.ConvertType <MongoNTFSFolderUpsert>(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 <MongoNTFSFolderUpsert> filter = Utils.GenerateMongoFilter <MongoNTFSFolderUpsert>(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;
        }