예제 #1
0
 public ActionResult EditPowerpoint(long id) //701
 {
     return(View("WopiFrame", new EditDocumentModel()
     {
         AccessToken = FB.GetAccessToken(id),
         AccessTokenExpires = GetTokenExpires(),
         ActionUrl = GetEditPowerpointUrl(id)
     }));
 }
예제 #2
0
        public ActionResult Index(long id)
        {
            // discovery xml:
            // https://onenote.officeapps-df.live.com/hosting/discovery
            // action url for Edit Docx:
            //var actionUrl = "https://word-edit.officeapps-df.live.com/we/wordeditorframe.aspx?<ui=UI_LLCC&><rs=DC_LLCC&><dchat=DISABLE_CHAT&><hid=HOST_SESSION_ID&><showpagestats=PERFSTATS&><IsLicensedUser=BUSINESS_USER&>";

            var tokenExpires = Convert.ToInt64(DateTime.UtcNow.AddDays(1).ToUniversalTime().Subtract(
                                                   new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)
                                                   ).TotalMilliseconds);

            return(View("WopiFrame", new EditDocumentModel()
            {
                AccessToken = FB.GetAccessToken(id),
                AccessTokenExpires = tokenExpires,
                ActionUrl = GetValidatorUrl(id)
            }));
        }
예제 #3
0
        public WopiJsonResponse Handle()
        {
            var requestData = WopiRequest.ParseRequest(_request);

            var responseData = new PutRelativeResponse();

            var documentId      = Convert.ToInt64(requestData.Id);
            var relativeTarget  = _request.Headers[WopiHeaders.RelativeTarget];
            var suggestedTarget = _request.Headers[WopiHeaders.SuggestedTarget];

            // make sure we don't have both headers present:
            if (!string.IsNullOrEmpty(relativeTarget) && !string.IsNullOrEmpty(suggestedTarget))
            {
                return(new WopiJsonResponse()
                {
                    StatusCode = 501,
                    Json = new PutRelativeResponse()
                });
            }

            var    overwriteRelative = _request.Headers[WopiHeaders.OverwriteRelativeTarget];
            string extension;

            if (!string.IsNullOrEmpty(relativeTarget))
            {
                // check if we have a file matching the target name
                // and if so, return 409 conflict w/ lock response
                extension         = relativeTarget.Substring(relativeTarget.LastIndexOf(".") + 1);
                responseData.Name = IOHelper.Utf7Encode(relativeTarget); // extension should already be here, we just need to get it for below

                var overwriteExisting = !string.IsNullOrEmpty(overwriteRelative) && overwriteRelative.ToLower().Equals("true");
                var relativeDocument  = FB.GetDocumentByNameAndExtension(responseData.Name, extension, documentId);

                // does this document already exist?
                if (relativeDocument != null)
                {
                    // lock check - make sure the existing document isn't locked:
                    var currentLock = "";
                    if (LockHelper.IsLockMismatch(_request, relativeDocument, out currentLock))
                    {
                        return(new WopiJsonResponse()
                        {
                            StatusCode = 409, Json = responseData
                        });
                    }

                    // not locked - but the document exists, so make sure the overwrite existing header is set:
                    if (!overwriteExisting)
                    {
                        return(new WopiJsonResponse()
                        {
                            StatusCode = 409,
                            Json = responseData
                        });
                    }
                }
            }
            else
            {
                // suggested mode:
                // save the file with whatever name we want, and return that name:
                extension         = suggestedTarget.Substring(suggestedTarget.LastIndexOf(".") + 1);
                responseData.Name = "wopitest_putrelative." + extension;
            }

            var binary        = IOHelper.StreamToBytes(_request.InputStream);
            var newDocumentId = FB.SaveNewDocument(binary, extension, responseData.Name, documentId);
            var newToken      = FB.GetAccessToken(newDocumentId);

            responseData.Url = $"{Constants.WopiApiUrl}wopi/files/{newDocumentId}?access_token={newToken}";

            return(new WopiJsonResponse()
            {
                StatusCode = 200,
                Json = responseData
            });
        }