예제 #1
0
        public static TrimSearchClause GetDriveIdSearchClause(this string id, Database database)
        {
            TrimSearchClause clause = new TrimSearchClause(database, BaseObjectTypes.Record, new FieldDefinition(database, "DriveID"));

            clause.SetCriteriaFromString(id);

            return(clause);
        }
예제 #2
0
        public async Task <object> Get(RegisterFile request)
        {
            var log = LogManager.GetLogger(typeof(RegisterFileService));

            log.Debug("GET start");
            RegisterFileResponse response = new RegisterFileResponse();



            log.Debug("getToken");
            string token = await getToken();

            log.Debug("gotToken");

            string driveId = getDriveIdFromTrim(request);

            log.Debug("got Drive ID");
            OneDriveItem fileResult = null;

            try
            {
                if (!string.IsNullOrWhiteSpace(request.WebUrl) && new string[] { "https://", "http://" }
                    .Any(s => request.WebUrl.StartsWith(s, StringComparison.InvariantCultureIgnoreCase)))
                {
                    log.Debug("GetItem");
                    var fullOneDriveItemsUrl = GraphApiHelper.GetOneDriveShareUrl(request.WebUrl);
                    fileResult = await ODataHelper.GetItem <OneDriveItem>(fullOneDriveItemsUrl, token, null);

                    log.Debug("GotItem");
                }
                else if (!string.IsNullOrWhiteSpace(driveId))
                {
                    fileResult = await ODataHelper.GetItem <OneDriveItem>(GraphApiHelper.GetOneDriveItemIdUrl(driveId), token, null);
                }
            }
            catch
            {
                throw;
            }

            RegisterdFileResponse registeredFile = new RegisterdFileResponse();

            if (fileResult != null)
            {
                registeredFile.Id        = fileResult?.getDriveAndId();
                registeredFile.DriveItem = fileResult;

                TrimMainObjectSearch search = new TrimMainObjectSearch(this.Database, BaseObjectTypes.Record);
                TrimSearchClause     clause = new TrimSearchClause(this.Database, BaseObjectTypes.Record, SearchClauseIds.RecordSpURL);
                clause.SetCriteriaFromString(fileResult.getDriveAndId());

                search.AddSearchClause(clause);

                var uris = search.GetResultAsUriArray(2);

                if (uris.Count == 1)
                {
                    updateFromRecord(registeredFile, new Record(this.Database, uris[0]));
                }

                //if (request.Uri > 0)
                //{
                //	Record record = new Record(this.Database, request.Uri);
                //	response.RecordTitle = record.Title;
                //	response.Name = this.Database.CurrentUser.FormattedName;
                //}
            }

            response.Results = new List <RegisterdFileResponse>()
            {
                registeredFile
            };

            log.Debug("Finished");
            return(response);
        }
예제 #3
0
        public async Task <object> Get(RegisterFile request)
        {
            RegisterFileResponse response = new RegisterFileResponse();

            //string[] addinScopes = ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/scope").Value.Split(' ');

            string token = await getToken();


            string driveId = getDriveIdFromTrim(request);

            OneDriveItem fileResult = null;

            try
            {
                if (!string.IsNullOrWhiteSpace(request.WebUrl))
                {
                    var driveDetails = await ODataHelper.GetItem <OneDriveDrive>(GraphApiHelper.GetMyOneDriveUrl(), token);

                    string filePath = request.WebUrl.Substring(driveDetails.WebUrl.Length);

                    var fullOneDriveItemsUrl = GraphApiHelper.GetOneDriveItemPathsUrl(filePath);
                    fileResult = await ODataHelper.GetItem <OneDriveItem>(fullOneDriveItemsUrl, token);
                }
                else if (!string.IsNullOrWhiteSpace(driveId))
                {
                    fileResult = await ODataHelper.GetItem <OneDriveItem>(GraphApiHelper.GetOneDriveItemIdUrl(driveId), token);
                }
            }
            catch
            {
                throw;
            }


            var registeredFile = new RegisterdFileResponse()
            {
                Id = fileResult?.Id, DriveItem = fileResult
            };


            TrimMainObjectSearch search = new TrimMainObjectSearch(this.Database, BaseObjectTypes.Record);
            TrimSearchClause     clause = new TrimSearchClause(this.Database, BaseObjectTypes.Record, SearchClauseIds.RecordExternal);

            clause.SetCriteriaFromString(fileResult.Id);

            search.AddSearchClause(clause);

            var uris = search.GetResultAsUriArray(2);

            if (uris.Count == 1)
            {
                updateFromRecord(registeredFile, new Record(this.Database, uris[0]));
            }
            //if (request.Uri > 0)
            //{
            //	Record record = new Record(this.Database, request.Uri);
            //	response.RecordTitle = record.Title;
            //	response.Name = this.Database.CurrentUser.FormattedName;
            //}



            response.Results = new List <RegisterdFileResponse>()
            {
                registeredFile
            };
            return(response);
        }