Ejemplo n.º 1
0
        public static List <POCO.O365.EOMessageEntity> GetMessages(DataConfig providerConfig, List <Filter> filters, string thisPageId, int rowLimit, out string nextPageId)
        {
            nextPageId = string.Empty;

            List <POCO.O365.EOMessageEntity> files = new List <POCO.O365.EOMessageEntity>();

            switch (providerConfig.ProviderType)
            {
            case "azure.tableservice":
            {
                string combinedFilter = Utils.GenerateAzureFilter(filters);
                TableContinuationToken thisPageToken = null;
                if (thisPageId != null && thisPageId != string.Empty)
                {
                    thisPageToken = Newtonsoft.Json.JsonConvert.DeserializeObject <TableContinuationToken>(thisPageId);
                }
                TableContinuationToken      nextPageToken        = null;
                List <AzureEOMessageEntity> azdata               = new List <AzureEOMessageEntity>();
                AzureTableAdaptor <AzureEOMessageEntity> adaptor = new AzureTableAdaptor <AzureEOMessageEntity>();
                azdata = adaptor.ReadTableDataWithToken(providerConfig, AzureTableNames.EOMessage, combinedFilter, rowLimit, thisPageToken, out nextPageToken);

                foreach (var doc in azdata)
                {
                    files.Add(doc.Value);
                }

                // Check if there is a next page token available
                if (nextPageToken != null)
                {
                    nextPageId = Newtonsoft.Json.JsonConvert.SerializeObject(nextPageToken);
                }

                break;
            }

            case "internal.mongodb":
            {
                var lastId     = "";
                var collection = Utils.GetMongoCollection <MongoEOMessageEntity>(providerConfig, MongoTableNames.EOMessage);

                // Add an _id filter if a page has been requested
                if (thisPageId != null && thisPageId != string.Empty)
                {
                    filters.Insert(0, new Filter("_id", thisPageId, "gt"));
                }


                FilterDefinition <MongoEOMessageEntity> filter = Utils.GenerateMongoFilter <MongoEOMessageEntity>(filters);

                var documents = collection.Find(filter).Sort("{\"_id\":1}").Limit(rowLimit).ToList();

                foreach (var file in documents)
                {
                    files.Add(file);
                    lastId = file._id.ToString();
                }

                // Check if there are more pages of data
                if (files.Count == rowLimit)
                {
                    // Return the _id of the last row
                    nextPageId = lastId;
                }

                break;
            }

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

            return(files);
        }
Ejemplo n.º 2
0
        public static List <POCO.NTFSFile> GetFiles(DataConfig providerConfig, List <Filter> filters, string thisPageId, int rowLimit, out string nextPageId)
        {
            nextPageId = string.Empty;
            List <POCO.NTFSFile> files = new List <POCO.NTFSFile>();

            switch (providerConfig.ProviderType)
            {
            case "azure.tableservice":


                string combinedFilter = Utils.GenerateAzureFilter(filters);
                TableContinuationToken thisPageToken = null;
                if (thisPageId != null && thisPageId != string.Empty)
                {
                    thisPageToken = Newtonsoft.Json.JsonConvert.DeserializeObject <TableContinuationToken>(thisPageId);
                }
                TableContinuationToken            nextPageToken = null;
                List <AzureNTFSFile>              azdata        = new List <AzureNTFSFile>();
                AzureTableAdaptor <AzureNTFSFile> adaptor       = new AzureTableAdaptor <AzureNTFSFile>();
                azdata = adaptor.ReadTableDataWithToken(providerConfig, NTFS.AzureTableNames.NTFSFiles, combinedFilter, rowLimit, thisPageToken, out nextPageToken);

                foreach (var doc in azdata)
                {
                    files.Add(doc.Value);
                }

                // Check if there is a next page token available
                if (nextPageToken != null)
                {
                    nextPageId = Newtonsoft.Json.JsonConvert.SerializeObject(nextPageToken);
                }

                break;

                //throw new NotImplementedException();

                //string combinedFilter = Utils.GenerateAzureFilter(filters);

                //List<AzureNTFSFile> azdata = new List<AzureNTFSFile>();
                //AzureTableAdaptor<AzureNTFSFile> adaptor = new AzureTableAdaptor<AzureNTFSFile>();
                //azdata = adaptor.ReadTableData(providerConfig, NTFS.AzureTableNames.NTFSFiles, combinedFilter);

                //foreach (var doc in azdata)
                //{
                //    files.Add(doc.Value);
                //}

                break;

            case "internal.mongodb":
                var collection = Utils.GetMongoCollection <MongoNTFSFile>(providerConfig, NTFS.MongoTableNames.NTFSFiles);

                // Add an _id filter if a page has been requested
                if (thisPageId != null && thisPageId != string.Empty)
                {
                    filters.Insert(0, new Filter("_id", thisPageId, "gt"));
                }

                FilterDefinition <MongoNTFSFile> filter = Utils.GenerateMongoFilter <MongoNTFSFile>(filters);

                //DEBUG output the filter values
                //foreach (Castlepoint.DataFactory.Filter debugFilter in filters)
                //{
                //    // Output the filter field names and values
                //    Console.WriteLine("DEBUG filter: " + debugFilter.FieldName + " : " + debugFilter.FieldValue);
                //}
                var documents = collection.Find(filter).Sort("{\"_id\":1}").Limit(rowLimit).ToList();


                foreach (var NTFSFile in documents)
                {
                    files.Add(NTFSFile);
                }

                // Get the next page id
                if (documents.Count == rowLimit)
                {
                    // Set the next page id
                    nextPageId = documents[documents.Count - 1]._id.ToString();
                }


                break;

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

            return(files);
        }