Beispiel #1
0
        public static List <POCO.Files.CPFile> GetFiles(DataConfig dataConfig, POCO.System system, List <Filter> filters, string thisPageId, int maxRows, out string nextPageId)
        {
            List <POCO.Files.CPFile> filesToProcess = new List <POCO.Files.CPFile>();

            // Default next page id to "no more data" (empty string)
            nextPageId = string.Empty;

            // Check the system type
            switch (system.Type)
            {
            case POCO.SystemType.SharePoint2010:
            {
                List <POCO.SharePoint.SPFile> spfiles = DataFactory.SharePoint.GetFiles(dataConfig, filters, thisPageId, maxRows, out nextPageId);

                // Convert to ICPFile format
                foreach (POCO.SharePoint.SPFile fileToConvert in spfiles)
                {
                    // Convert to ICPFile compatible object
                    POCO.Files.SPFile file = JsonConvert.DeserializeObject <POCO.Files.SPFile>(JsonConvert.SerializeObject(fileToConvert));
                    filesToProcess.Add(file);
                }

                break;
            }

            case POCO.SystemType.SharePoint2013:
            {
                List <POCO.SharePoint.SPFile> spfiles = DataFactory.SharePoint.GetFiles(dataConfig, filters, thisPageId, maxRows, out nextPageId);

                // Convert to ICPFile format
                foreach (POCO.SharePoint.SPFile fileToConvert in spfiles)
                {
                    // Convert to ICPFile compatible object
                    POCO.Files.SPFile file = JsonConvert.DeserializeObject <POCO.Files.SPFile>(JsonConvert.SerializeObject(fileToConvert));
                    filesToProcess.Add(file);
                }

                break;
            }

            case POCO.SystemType.SharePointOneDrive:
            case POCO.SystemType.SharePointTeam:
            case POCO.SystemType.SharePointOnline:
            {
                List <POCO.SPFile> spfiles = DataFactory.SharePointOnline.GetFiles(dataConfig, filters, thisPageId, maxRows, out nextPageId);

                // Convert to ICPFile format
                foreach (POCO.SPFile fileToConvert in spfiles)
                {
                    // Convert to ICPFile compatible object
                    POCO.Files.SPFile file = JsonConvert.DeserializeObject <POCO.Files.SPFile>(JsonConvert.SerializeObject(fileToConvert));
                    filesToProcess.Add(file);
                }

                break;
            }

            case POCO.SystemType.GoogleDrive:
            {
                List <POCO.Files.GoogleFile> googlefiles = DataFactory.Google.GetFiles(dataConfig, filters);

                // Convert to ICPFile format
                foreach (POCO.Files.GoogleFile fileToConvert in googlefiles)
                {
                    // Convert to ICPFile compatible object
                    POCO.Files.GoogleFile file = JsonConvert.DeserializeObject <POCO.Files.GoogleFile>(JsonConvert.SerializeObject(fileToConvert));
                    filesToProcess.Add(file);
                }

                break;
            }

            case POCO.SystemType.NTFSShare:

                List <POCO.NTFSFile> ntfsFiles = DataFactory.NTFS.GetFiles(dataConfig, filters);

                // Convert to ICPFile format
                foreach (POCO.NTFSFile fileToConvert in ntfsFiles)
                {
                    // Convert to ICPFile compatible object
                    POCO.Files.NTFSFile ntfsfile = JsonConvert.DeserializeObject <POCO.Files.NTFSFile>(JsonConvert.SerializeObject(fileToConvert));
                    filesToProcess.Add(ntfsfile);
                }

                break;

            case POCO.SystemType.SakaiAlliance:

                List <POCO.SakaiFile> sakaiFiles = DataFactory.SakaiResource.GetFiles(dataConfig, filters);

                // Convert to ICPFile format
                foreach (POCO.SakaiFile fileToConvert in sakaiFiles)
                {
                    // Convert to ICPFile compatible object
                    POCO.Files.SakaiFile sakaifile = JsonConvert.DeserializeObject <POCO.Files.SakaiFile>(JsonConvert.SerializeObject(fileToConvert));
                    filesToProcess.Add(sakaifile);
                }

                break;

            case POCO.SystemType.Basecamp:
                // Get the Basecamp files

                throw new NotImplementedException("GetFiles: system type not implemented=" + system.Type);

                // URL format of the basecamp project is:  https://<basecamp api>/<account number>/projects/<project id>.json
                // all data for a project is in "buckets": https://<basecamp api>/<account number>/buckets/<project id>/<type of bucket>/<id>.json
                // any data matching should use the buckets/<project id>>
                //string basecampFilesUri = record.RecordUri.Replace("projects", "buckets");
                //if (basecampFilesUri.ToLower().EndsWith(".json")) { basecampFilesUri = basecampFilesUri.Substring(0, basecampFilesUri.Length - 5); }
                //if (!basecampFilesUri.EndsWith("|")) { basecampFilesUri += "|"; }

                //List<DataFactory.Filter> basecampFilters = new List<DataFactory.Filter>();

                //string pk = Utils.CleanTableKey(basecampFilesUri);
                //DataFactory.Filter basecampPK = new DataFactory.Filter("PartitionKey", pk, "eq");
                //basecampFilters.Add(basecampPK);

                ////DataFactory.Filter basecampPKLT = new DataFactory.Filter("PartitionKey", Utils.GetLessThanFilter(pk), "lt");
                ////basecampFilters.Add(basecampPKGE);
                ////basecampFilters.Add(basecampPKLT);

                //DataFactory.DataConfig basecampDataConfig = dataConfig;
                //List<POCO.BasecampDocumentEntity> basecampFiles = DataFactory.BasecampProject.GetFiles(basecampDataConfig, basecampFilters);

                //// Convert to ICPFile format
                //foreach (POCO.BasecampDocumentEntity fileToConvert in basecampFiles)
                //{
                //    // Convert to ICPFile compatible object
                //    //BasecampFile basefile = JsonConvert.DeserializeObject<BasecampFile>(JsonConvert.SerializeObject(fileToConvert));

                //    POCO.Files.BasecampFile bf = new POCO.Files.BasecampFile();
                //    bf.BatchGuid = Guid.Empty;
                //    bf.BatchStatus = null;
                //    bf.CreationTime = fileToConvert.TimeCreated;
                //    bf.FolderUri = fileToConvert.PartitionKey;
                //    bf.ItemUri = fileToConvert.ServerRelativeUrl;
                //    bf.JsonFileProcessResult = null;
                //    bf.LastModifiedTime = fileToConvert.TimeLastModified;
                //    bf.Name = fileToConvert.Name;
                //    bf.OrganisationId = Guid.Empty;
                //    bf.PartitionKey = fileToConvert.PartitionKey;
                //    bf.RowKey = fileToConvert.RowKey;
                //    bf.SiteUrl = fileToConvert.ServerRelativeUrl;
                //    bf.SourceFileName = fileToConvert.Name;
                //    bf.SourceRelativeUrl = fileToConvert.ServerRelativeUrl;
                //    bf.Title = fileToConvert.Title;
                //    bf.UniqueId = fileToConvert.UniqueId;

                //    filesToProcess.Add(bf);
                //}

                break;

            default:
            {
                throw new NotImplementedException("GetFiles: unknown system type: " + system.Type);
            }
            }

            return(filesToProcess);
        }
Beispiel #2
0
        internal static List <POCO.Files.CPFile> GetFilesAssociatedToRecordForBatchProcessing(DataConfig dataConfig, POCO.System system, POCO.Record record)
        {
            List <POCO.Files.CPFile> filesToProcess = new List <POCO.Files.CPFile>();

            // Create the filter
            string recordUri = record.RowKey;

            if (!recordUri.EndsWith("|"))
            {
                recordUri += "|";
            }                                                   // Standardise the url to end in a pipe '|' to help match files via partial Uri

            List <DataFactory.Filter> filters = new List <DataFactory.Filter>();

            DataFactory.Filter pkGTEFilter = new DataFactory.Filter("PartitionKey", recordUri, "ge");
            DataFactory.Filter pkLTFilter  = new DataFactory.Filter("PartitionKey", Utils.GetLessThanFilter(recordUri), "lt");
            filters.Add(pkGTEFilter);
            filters.Add(pkLTFilter);

            // Check the system type
            string thisPageId = string.Empty;
            string nextPageId = string.Empty;

            switch (system.Type)
            {
            case POCO.SystemType.SharePointOnline:
            case POCO.SystemType.SharePointTeam:
            case POCO.SystemType.SharePointOneDrive:
            {
                do
                {
                    List <POCO.SPFile> spfiles = DataFactory.SharePointOnline.GetFiles(dataConfig, filters, thisPageId, 1000, out nextPageId);

                    // Convert to ICPFile format
                    foreach (POCO.SPFile fileToConvert in spfiles)
                    {
                        // Convert to ICPFile compatible object
                        POCO.Files.SPFile file = JsonConvert.DeserializeObject <POCO.Files.SPFile>(JsonConvert.SerializeObject(fileToConvert));
                        filesToProcess.Add(file);
                    }

                    thisPageId = nextPageId;
                }while (nextPageId != string.Empty);


                break;
            }

            case POCO.SystemType.GoogleDrive:
            {
                List <POCO.Files.GoogleFile> googlefiles = DataFactory.Google.GetFiles(dataConfig, filters);

                // Convert to ICPFile format
                foreach (POCO.Files.GoogleFile fileToConvert in googlefiles)
                {
                    // Convert to ICPFile compatible object
                    POCO.Files.GoogleFile file = JsonConvert.DeserializeObject <POCO.Files.GoogleFile>(JsonConvert.SerializeObject(fileToConvert));
                    filesToProcess.Add(file);
                }

                break;
            }

            case POCO.SystemType.NTFSShare:

                List <POCO.NTFSFile> ntfsFiles = DataFactory.NTFS.GetFiles(dataConfig, filters);

                // Convert to ICPFile format
                foreach (POCO.NTFSFile fileToConvert in ntfsFiles)
                {
                    // Convert to ICPFile compatible object
                    POCO.Files.NTFSFile ntfsfile = JsonConvert.DeserializeObject <POCO.Files.NTFSFile>(JsonConvert.SerializeObject(fileToConvert));
                    filesToProcess.Add(ntfsfile);
                }

                break;

            case POCO.SystemType.Basecamp:
                // Get the Basecamp files

                // URL format of the basecamp project is:  https://<basecamp api>/<account number>/projects/<project id>.json
                // all data for a project is in "buckets": https://<basecamp api>/<account number>/buckets/<project id>/<type of bucket>/<id>.json
                // any data matching should use the buckets/<project id>>
                string basecampFilesUri = record.RecordUri.Replace("projects", "buckets");
                if (basecampFilesUri.ToLower().EndsWith(".json"))
                {
                    basecampFilesUri = basecampFilesUri.Substring(0, basecampFilesUri.Length - 5);
                }
                if (!basecampFilesUri.EndsWith("|"))
                {
                    basecampFilesUri += "|";
                }

                List <DataFactory.Filter> basecampFilters = new List <DataFactory.Filter>();

                string             pk         = Utils.CleanTableKey(basecampFilesUri);
                DataFactory.Filter basecampPK = new DataFactory.Filter("PartitionKey", pk, "eq");
                basecampFilters.Add(basecampPK);

                //DataFactory.Filter basecampPKLT = new DataFactory.Filter("PartitionKey", Utils.GetLessThanFilter(pk), "lt");
                //basecampFilters.Add(basecampPKGE);
                //basecampFilters.Add(basecampPKLT);

                DataFactory.DataConfig             basecampDataConfig = dataConfig;
                List <POCO.BasecampDocumentEntity> basecampFiles      = DataFactory.BasecampProject.GetFiles(basecampDataConfig, basecampFilters);

                // Convert to ICPFile format
                foreach (POCO.BasecampDocumentEntity fileToConvert in basecampFiles)
                {
                    // Convert to ICPFile compatible object
                    //BasecampFile basefile = JsonConvert.DeserializeObject<BasecampFile>(JsonConvert.SerializeObject(fileToConvert));

                    POCO.Files.BasecampFile bf = new POCO.Files.BasecampFile();
                    bf.BatchGuid             = Guid.Empty;
                    bf.BatchStatus           = null;
                    bf.CreationTime          = fileToConvert.TimeCreated;
                    bf.FolderUri             = fileToConvert.PartitionKey;
                    bf.ItemUri               = fileToConvert.ServerRelativeUrl;
                    bf.JsonFileProcessResult = null;
                    bf.LastModifiedTime      = fileToConvert.TimeLastModified;
                    bf.Name              = fileToConvert.Name;
                    bf.OrganisationId    = Guid.Empty;
                    bf.PartitionKey      = fileToConvert.PartitionKey;
                    bf.RowKey            = fileToConvert.RowKey;
                    bf.SiteUrl           = fileToConvert.ServerRelativeUrl;
                    bf.SourceFileName    = fileToConvert.Name;
                    bf.SourceRelativeUrl = fileToConvert.ServerRelativeUrl;
                    bf.Title             = fileToConvert.Title;
                    bf.UniqueId          = fileToConvert.UniqueId;

                    filesToProcess.Add(bf);
                }

                break;

            default:
            {
                throw new NotImplementedException("Unknown system type: " + system.Type);
            }
            }

            return(filesToProcess);
        }