private void SendFileRequest(OutputSfc oOutputSfc, TransportClassSaveChanges2 oTransportClassSaveChanges2) { string sJson = new JavaScriptSerializer().Serialize(oOutputSfc); uint attempcount = uint.Parse(ConfigurationSettings.AppSettings["sfc.webrequest.attempcount"] ?? "1"); uint attempdelay = uint.Parse(ConfigurationSettings.AppSettings["sfc.webrequest.attempdelay"] ?? "0"); AsyncWebRequestOperation oAsyncWebRequestOperation = new AsyncWebRequestOperation(attempcount, attempdelay); oTransportClassSaveChanges2.m_oAsyncWebRequestOperation = oAsyncWebRequestOperation; _log.DebugFormat("TaskResultRemoveCallback4 url:{0}", oTransportClassSaveChanges2.m_sCallbackUrl); oTransportClassSaveChanges2.m_oAsyncWebRequestOperationResult = oAsyncWebRequestOperation.RequestBegin(oTransportClassSaveChanges2.m_sCallbackUrl, "POST", "application/json", Encoding.UTF8.GetBytes(sJson), RequestCallback2, oTransportClassSaveChanges2); }
private void ReadFileCallback(IAsyncResult ar) { TransportClassStorage3 oTransportClassStorage3 = ar.AsyncState as TransportClassStorage3; TransportClassSaveChanges2 oTransportClassSaveChanges2 = oTransportClassStorage3.m_oSaveChanges2; try { Storage oStorage = oTransportClassStorage3.m_oStorage; if (null == oStorage) { throw new NullReferenceException(); } TaskResultData oTaskResultData = oTransportClassSaveChanges2.m_oTaskResultData; int nReadWriteBytes = 0; ErrorTypes eResult = oStorage.ReadFileEnd(ar, out nReadWriteBytes); OutputSfc oOutputSfc = new OutputSfc(); oOutputSfc.key = oTransportClassSaveChanges2.m_oInputCommand.id; if (ErrorTypes.NoError == eResult) { byte[] buffer = new byte[nReadWriteBytes]; oTransportClassStorage3.m_oStream.Seek(0, SeekOrigin.Begin); oTransportClassStorage3.m_oStream.Read(buffer, 0, nReadWriteBytes); oTransportClassStorage3.m_oStream.Dispose(); string strSiteUrl = UrlBuilder.UrlWithoutPath(oTransportClassSaveChanges2.m_oHttpContext.Request); oOutputSfc.url = GetResultUrl(strSiteUrl, oTaskResultData.sKey, oTaskResultData.sTitle, oTaskResultData.sTitle, false); oOutputSfc.changesurl = GetResultUrl(strSiteUrl, oTaskResultData.sKey, "changes.zip", oTaskResultData.sTitle, false); oOutputSfc.changeshistory = Encoding.UTF8.GetString(buffer); } _log.DebugFormat("saved file url:{0}", oOutputSfc.url); if (!string.IsNullOrEmpty(oTransportClassSaveChanges2.m_oInputCommand.userid)) oOutputSfc.users.Add(oTransportClassSaveChanges2.m_oInputCommand.userid); FileStatusOut eFileStatusOut = FileStatusOut.NotFound; if (!string.IsNullOrEmpty(oOutputSfc.url) && oOutputSfc.users.Count > 0) eFileStatusOut = FileStatusOut.MustSave; else eFileStatusOut = FileStatusOut.Corrupted; oOutputSfc.status = (int)eFileStatusOut; SendFileRequest(oOutputSfc, oTransportClassSaveChanges2); } catch (Exception e) { _log.Error("Exception catched in ReadFileCallback:", e); RemoveFromCoAuthoringHandler(oTransportClassSaveChanges2); } }
private void DocsCallbacksRemoveCallback(IAsyncResult ar) { TransportClassSaveChanges2 oTransportClassSaveChanges2 = ar.AsyncState as TransportClassSaveChanges2; try { InputCommand cmd = oTransportClassSaveChanges2.m_oInputCommand; _log.DebugFormat("Enter DocsCallbacksRemoveCallback(id={0})", cmd.id); ErrorTypes eError = oTransportClassSaveChanges2.m_oDocsCallbacks.RemoveEnd(ar); if (ErrorTypes.NoError == eError) { TaskResultData oTaskResultData = oTransportClassSaveChanges2.m_oTaskResultData; if (FileStatus.Ok != oTaskResultData.eStatus && (FileStatus.Err != oTaskResultData.eStatus || (int)ErrorTypes.ConvertCorrupted != oTaskResultData.nStatusInfo)) { OutputSfc oOutputSfc = new OutputSfc(); oOutputSfc.status = (int)FileStatusOut.Corrupted; SendFileRequest(oOutputSfc, oTransportClassSaveChanges2); } else { Storage oStorage = new Storage(); MemoryStream oStream = new MemoryStream(); TransportClassStorage3 oTransportClassStorage3 = new TransportClassStorage3(oTransportClassSaveChanges2, cmd, oStorage, oStream, oTaskResultData.sKey, oTransportClassSaveChanges2); oStorage.ReadFileBegin(Path.Combine(oTaskResultData.sKey, "changesHistory.json"), oStream, ReadFileCallback, oTransportClassStorage3); } } else { RemoveFromCoAuthoringHandler(oTransportClassSaveChanges2); } } catch (Exception e) { _log.Error("Exception catched in DocsCallbacksRemoveCallback:", e); RemoveFromCoAuthoringHandler(oTransportClassSaveChanges2); } }