Exemple #1
0
        private async Task <string> getOneDriveDocumentUrl(string token)
        {
            long myUri = this.Database.CurrentUser.Uri;

            if (!_oneDriveDocuemntUrls.ContainsKey(myUri))
            {
                var driveDetails = await ODataHelper.GetItem <OneDriveDrive>(GraphApiHelper.GetMyOneDriveUrl(), token, null);

                _oneDriveDocuemntUrls.Add(myUri, driveDetails.WebUrl);
            }

            return(_oneDriveDocuemntUrls[myUri]);
        }
Exemple #2
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);
        }