Beispiel #1
0
        public async Task <object> Post(DriveFileOperation request)
        {
            string token = await getToken();


            RegisterFileResponse response = new RegisterFileResponse();

            Record record = new Record(this.Database, request.Uri);

            string driveId = record.ExternalReference;

            var registeredFile = new RegisterdFileResponse()
            {
                Id = driveId
            };


            request.Action = request.Action ?? "";

            if (request.Action.IndexOf("AddToFavorites", StringComparison.InvariantCultureIgnoreCase) > -1)
            {
                record.AddToFavorites();
            }

            if (request.Action.IndexOf("RemoveFromFavorites", StringComparison.InvariantCultureIgnoreCase) > -1)
            {
                record.RemoveFromFavorites();
            }


            if (request.Action.IndexOf("checkin", StringComparison.InvariantCultureIgnoreCase) > -1)
            {
                var driveDetails = await ODataHelper.GetItem <string>(GraphApiHelper.GetOneDriveItemContentIdUrl(driveId), token);

                record.SetDocument(new InputDocument(driveDetails), true, false, "checkin from Word Online");
            }

            if (request.Action.IndexOf("delete", StringComparison.InvariantCultureIgnoreCase) > -1)
            {
                await ODataHelper.DeleteWithToken(GraphApiHelper.GetOneDriveItemIdUrl(driveId), token);

                record.ExternalReference = "";
            }

            if (request.Action.IndexOf("finalize", StringComparison.InvariantCultureIgnoreCase) > -1)
            {
                record.SetAsFinal(false);
            }

            record.Save();

            updateFromRecord(registeredFile, record);

            response.Results = new List <RegisterdFileResponse>()
            {
                registeredFile
            };
            return(response);
        }
        public async Task <object> Post(DriveFileOperation request)
        {
            try
            {
                RegisterFileResponse response = new RegisterFileResponse();

                Record record = new Record(this.Database, request.Uri);
                record.Refresh();

                string driveId = record.SpURL;

                var registeredFile = new RegisterdFileResponse()
                {
                    Id = driveId
                };


                request.Action = request.Action ?? "";

                if (request.Action.IndexOf("AddToFavorites", StringComparison.InvariantCultureIgnoreCase) > -1)
                {
                    record.AddToFavorites();
                }

                if (request.Action.IndexOf("RemoveFromFavorites", StringComparison.InvariantCultureIgnoreCase) > -1)
                {
                    record.RemoveFromFavorites();
                }


                if (request.Action.IndexOf("checkin", StringComparison.InvariantCultureIgnoreCase) > -1)
                {
                    string token = await getToken();

                    if (!string.IsNullOrWhiteSpace(request.FileName))
                    {
                        //	filePath = Path.Combine(TrimApplication.WebServerWorkPath, record.SuggestedFileName);


                        //using (var stream = new FileStream(filePath, FileMode.Append))
                        //{
                        //	stream.Write(request.Data, 0, request.Data.Length);
                        //}

                        //if (request.LastDataSlice == true)
                        //{
                        //	record.SetDocument(new InputDocument(filePath), true, false, "checkin from Word Online");
                        //} else
                        //{
                        //	response.Results = new List<RegisterdFileResponse>() { registeredFile };
                        //	return response;
                        //}
                        //	var driveDetails = await ODataHelper.GetItem<string>(GraphApiHelper.GetOneDriveItemContentIdUrl(driveId), token, filePath);

                        var inputDocument = new InputDocument(request.FileName);


                        inputDocument.CheckinAs = request.WebUrl;
                        record.SetDocument(inputDocument, true, false, "checkin from Word Online");
                    }
                }

                if (request.Action.IndexOf("delete", StringComparison.InvariantCultureIgnoreCase) > -1)
                {
                    string token = await getToken();

                    await ODataHelper.DeleteWithToken(GraphApiHelper.GetOneDriveItemIdUrl(driveId), token);

                    record.SpURL = "";
                }

                if (request.Action.IndexOf("finalize", StringComparison.InvariantCultureIgnoreCase) > -1)
                {
                    record.SetAsFinal(false);
                }

                record.Save();

                updateFromRecord(registeredFile, record);

                response.Results = new List <RegisterdFileResponse>()
                {
                    registeredFile
                };
                return(response);
            }
            finally
            {
                if (!string.IsNullOrWhiteSpace(request.FileName))
                {
                    File.Delete(request.FileName);
                }
            }
        }
Beispiel #3
0
        public async Task <object> Post(DriveFileOperation request)
        {
            string fileName = request.FileName;

            try
            {
                RegisterFileResponse response = new RegisterFileResponse();

                Record record = new Record(this.Database, request.Uri);
                record.Refresh();

                string driveId = record.GetDriveId();

                var registeredFile = new RegisterdFileResponse()
                {
                    Id = driveId
                };


                request.Action = request.Action ?? "";

                if (request.Action.IndexOf("AddToFavorites", StringComparison.InvariantCultureIgnoreCase) > -1)
                {
                    record.AddToFavorites();
                }

                if (request.Action.IndexOf("RemoveFromFavorites", StringComparison.InvariantCultureIgnoreCase) > -1)
                {
                    record.RemoveFromFavorites();
                }

                if (request.Action.IndexOf("checkin", StringComparison.InvariantCultureIgnoreCase) > -1 &&
                    request.Action.IndexOf("checkin-requst-del", StringComparison.InvariantCultureIgnoreCase) < 1)
                {
                    string token = await getToken();

                    if (!string.IsNullOrWhiteSpace(request.FileName))
                    {
                        if (!Path.IsPathRooted(request.FileName))
                        {
                            fileName = Path.Combine(this.ServiceDefaults.UploadBasePath, request.FileName);
                        }

                        var inputDocument = new InputDocument(fileName);

                        inputDocument.CheckinAs = request.WebUrl;
                        record.SetDocument(inputDocument, true, false, "checkin from Word Online");
                    }
                    else
                    {
                        string downloadUrl = GraphApiHelper.GetOneDriveItemContentIdUrl(driveId);

                        var fileResult = await ODataHelper.GetItem <OneDriveItem>(GraphApiHelper.GetOneDriveItemIdUrl(driveId), token, null);

                        string filePath = Path.Combine(TrimApplication.WebServerWorkPath, fileResult.Name);


                        await ODataHelper.GetItem <string>(downloadUrl, token, filePath);



                        var inputDocument = new InputDocument(filePath);


                        inputDocument.CheckinAs = record.SuggestedFileName;
                        record.SetDocument(inputDocument, true, false, "checkin from Word Online");
                    }
                }

                if (request.Action.IndexOf("request-del", StringComparison.InvariantCultureIgnoreCase) > -1)
                {
                    record.SetDeleteNow(!record.GetDeleteNow());
                }

                if (request.Action.IndexOf("delete", StringComparison.InvariantCultureIgnoreCase) > -1)
                {
                    string token = await getToken();

                    await ODataHelper.DeleteWithToken(GraphApiHelper.GetOneDriveItemIdUrlForDelete(driveId), token);

                    record.SetDriveId("");
                }

                if (request.Action.IndexOf("finalize", StringComparison.InvariantCultureIgnoreCase) > -1)
                {
                    record.SetAsFinal(false);
                }

                record.Save();

                updateFromRecord(registeredFile, record);

                response.Results = new List <RegisterdFileResponse>()
                {
                    registeredFile
                };
                return(response);
            }
            finally
            {
                if (!string.IsNullOrWhiteSpace(fileName))
                {
                    File.Delete(fileName);
                }
            }
        }