private void ReadMediaXmlCallback(IAsyncResult ar) { try { int nReadWriteBytes; m_oGetMediaXml.m_eError = m_oGetMediaXml.m_oStorage.ReadFileEnd(ar, out nReadWriteBytes); if (ErrorTypes.NoError == m_oGetMediaXml.m_eError || ErrorTypes.StorageFileNoFound == m_oGetMediaXml.m_eError) { MemoryStream oMemoryStream = m_oGetMediaXml.m_oMemoryStream; if (nReadWriteBytes > 0) { string sXml = Encoding.UTF8.GetString(oMemoryStream.GetBuffer(), 0, (int)oMemoryStream.Position); using (XmlTextReader reader = new XmlTextReader(new StringReader(sXml))) { while (reader.Read()) { if ("image" == reader.Name) { string sHash = null; string sFilename = null; while (reader.MoveToNextAttribute()) { if ("md5" == reader.Name) { sHash = reader.Value; } else if ("filename" == reader.Name) { sFilename = reader.Value; } } if (null != sHash && null != sFilename) { m_oGetMediaXml.m_aMediaXmlMapHash[sHash] = sFilename; m_oGetMediaXml.m_aMediaXmlMapFilename[sFilename] = sHash; } } } } } } m_oGetMediaXml.FireCallback(); } catch { m_oGetMediaXml.DisposeAndCallback(); } }
private void GetOrCreateCallback(IAsyncResult ar) { try { TaskResultData oTaskResult = null; m_oGetOrCreate.m_delegateGet.EndInvoke(out oTaskResult, ar); m_oGetOrCreate.m_delegateGet = null; if (oTaskResult != null) { m_oGetOrCreate.m_bCreate = false; m_oGetOrCreate.m_oTast = oTaskResult; m_oGetOrCreate.FireCallback(); } else { m_oGetOrCreate.m_bReadFromDB = true; m_oTaskResultDB.GetOrCreateBegin(m_oGetOrCreate.m_sKey, m_oGetOrCreate.m_oTast, m_oGetOrCreate.m_fCallback, m_oGetOrCreate.m_oParam); } } catch { m_oGetOrCreate.DisposeAndCallback(); } }
public void RemovePathBegin(string strPath, AsyncCallback fCallback, object oParam) { m_oRemovePath = new TransportClass(fCallback, ErrorTypes.StorageRemoveDir, oParam); try { string strDirpath = GetFilePath(strPath); if (Directory.Exists(strDirpath)) { m_oRemovePath.m_delegateDirectoryDelete = Directory.Delete; m_oRemovePath.m_delegateDirectoryDelete.BeginInvoke(strDirpath, true, m_oRemovePath.m_fCallback, m_oRemovePath.m_oParam); } else if (File.Exists(strDirpath)) { m_oRemovePath.m_delegateFileDelete = File.Delete; m_oRemovePath.m_delegateFileDelete.BeginInvoke(strDirpath, m_oRemovePath.m_fCallback, m_oRemovePath.m_oParam); } else { m_oRemovePath.FireCallback(); } } catch { m_oRemovePath.DisposeAndCallback(); } }
public void ReadFileBegin(string strPath, System.IO.Stream oStream, AsyncCallback fCallback, object oParam) { m_oReadFile = new TransportClass(fCallback, ErrorTypes.StorageRead, oParam); try { string strFilepath = GetFilePath(strPath); FileInfo oFileInfo = new FileInfo(strFilepath); if (oFileInfo.Exists) { FileStream oFileStreamInput = new FileStream(strFilepath, FileMode.Open, FileAccess.Read, FileShare.Read, (int)oFileInfo.Length, true); byte[] aBuffer = new byte[oFileStreamInput.Length]; m_oReadFile.m_oInput = oFileStreamInput; m_oReadFile.m_aBuffer = aBuffer; m_oReadFile.m_oOutput = oStream; m_oReadFile.m_bDisposeInput = true; m_oReadFile.m_oInput.BeginRead(aBuffer, 0, aBuffer.Length, EndCallbackRead, m_oReadFile); } else { m_oReadFile.m_eError = ErrorTypes.StorageFileNoFound; m_oReadFile.FireCallback(); } } catch { m_oReadFile.DisposeAndCallback(); } }
private void EndCallbackGetListObjects(IAsyncResult ar) { TransportClass oObject = null; try { oObject = ar.AsyncState as TransportClass; oObject.m_oListObjectsResponse = oObject.m_oS3Client.EndListObjects(ar); if (oObject.m_oListObjectsResponse.S3Objects.Count > 0) { Amazon.S3.Model.DeleteObjectsRequest oDeleteObjectsRequest = new Amazon.S3.Model.DeleteObjectsRequest(); oDeleteObjectsRequest.WithBucketName(m_strBucketName); foreach (Amazon.S3.Model.S3Object oS3Obj in oObject.m_oListObjectsResponse.S3Objects) { oDeleteObjectsRequest.AddKey(oS3Obj.Key); } oObject.m_oS3Client.BeginDeleteObjects(oDeleteObjectsRequest, m_oRemoveDirectory.m_fCallback, m_oRemoveDirectory.m_oParam); } else { oObject.FireCallback(); } } catch { m_oRemoveDirectory.m_eError = ErrorTypes.StorageRemoveDir; m_oRemoveDirectory.DisposeAndCallback(); } }
private void EndCallbackReadStream(IAsyncResult ar) { TransportClass oObject = null; try { oObject = ar.AsyncState as TransportClass; oObject.m_nReadWriteBytes = oObject.m_oGetObjectResponse.ResponseStream.EndRead(ar); if (oObject.m_nReadWriteBytes > 0) { oObject.m_nTotalReadWriteBytes += oObject.m_nReadWriteBytes; oObject.m_oStreamOutput.BeginWrite(oObject.m_aBuffer, 0, oObject.m_nReadWriteBytes, EndCallbackWriteStream, oObject); } else { oObject.FireCallback(); } } catch { if (null != oObject) { oObject.DisposeAndCallback(); } } }
private void GetOrCreateCallback(IAsyncResult ar) { try { bool bEmptyRead = false; using (IDataReader oReader = m_oGetOrCreate.m_delegateReader.EndInvoke(ar)) { if (true == oReader.Read()) { m_oGetOrCreate.m_oTast = new TaskResultData(); TaskResultFromReader(m_oGetOrCreate.m_oTast, oReader); } else { bEmptyRead = true; } } if (null != m_oGetOrCreate.m_oCommand) { m_oGetOrCreate.m_oCommand.Dispose(); m_oGetOrCreate.m_oCommand = null; } if (bEmptyRead) { IDbCommand oSelCommand = m_oGetOrCreate.m_oSqlCon.CreateCommand(); oSelCommand.CommandText = GetINSERTString(m_oGetOrCreate.m_oTast); m_oGetOrCreate.m_oCommand = oSelCommand; m_oGetOrCreate.m_delegateNonQuery = new ExecuteNonQuery(oSelCommand.ExecuteNonQuery); m_oGetOrCreate.m_delegateNonQuery.BeginInvoke(GetOrCreateCallback2, null); } else { m_oGetOrCreate.m_bCreate = false; m_oGetOrCreate.m_delegateReader = null; m_oGetOrCreate.FireCallback(); } } catch { m_oGetOrCreate.DisposeAndCallback(); } }
private void GetOrCreateCallback(IAsyncResult ar) { try { bool bExist = false; try { m_oGetOrCreate.m_delegateNonQuery.EndInvoke(ar); } catch { bExist = true; } if (bExist) { m_oGetOrCreate.m_bCreate = false; if (null != m_oGetOrCreate.m_oCommand) { m_oGetOrCreate.m_oCommand.Dispose(); m_oGetOrCreate.m_oCommand = null; } IDbCommand oSelCommand = m_oGetOrCreate.m_oSqlCon.CreateCommand(); TaskResultDataToUpdate oToUpdate = new TaskResultDataToUpdate(); oToUpdate.oLastOpenDate = DateTime.UtcNow; oSelCommand.CommandText = GetUPDATEString(m_oGetOrCreate.m_oTast.sKey, oToUpdate) + GetSELECTString(m_oGetOrCreate.m_oTast.sKey); m_oGetOrCreate.m_oCommand = oSelCommand; m_oGetOrCreate.m_delegateReader = new ExecuteReader(oSelCommand.ExecuteReader); m_oGetOrCreate.m_delegateReader.BeginInvoke(m_oGetOrCreate.m_fCallback, m_oGetOrCreate.m_oParam); } else { m_oGetOrCreate.m_bCreate = true; m_oGetOrCreate.m_delegateReader = null; m_oGetOrCreate.FireCallback(); } } catch { m_oGetOrCreate.DisposeAndCallback(); } }
private void GetTaskCallback(IAsyncResult ar) { try { uint ncq_id = 0; DateTime oTaskUpdateTime = DateTime.UtcNow; bool bIsExist = false; using (IDataReader oReader = m_GetTask.m_delegateReader.EndInvoke(ar)) { if (true == oReader.Read()) { ncq_id = Convert.ToUInt32(oReader["cq_id"]); oTaskUpdateTime = Convert.ToDateTime(oReader["cq_update_time"]); m_GetTask.m_oTaskQueueData = TaskQueueData.DeserializeFromXml(Convert.ToString(oReader["cq_data"])); m_GetTask.m_oTaskQueueData.m_oDataKey = ncq_id; bIsExist = true; } } if (null != m_GetTask.m_oCommand) { m_GetTask.m_oCommand.Dispose(); m_GetTask.m_oCommand = null; } m_GetTask.Close(); if (bIsExist) { IDbCommand oUpdateCommand = m_GetTask.m_oSqlCon.CreateCommand(); oUpdateCommand.CommandText = GetUpdateString(ncq_id, oTaskUpdateTime); m_GetTask.m_oCommand = oUpdateCommand; m_GetTask.m_delegateNonQuery = new ExecuteNonQuery(oUpdateCommand.ExecuteNonQuery); m_GetTask.m_delegateNonQuery.BeginInvoke(m_GetTask.m_fCallback, m_GetTask.m_oParam); } else { m_GetTask.m_delegateNonQuery = null; m_GetTask.FireCallback(); } } catch (Exception e) { _log.Error("Exception cathed in GetTaskCallback:", e); m_GetTask.DisposeAndCallback(); } }
private void AddRandomKeyCallback(IAsyncResult ar) { try { bool bExist = false; try { m_oAddRandomKey.m_delegateNonQuery.EndInvoke(ar); if (null != m_oAddRandomKey.m_oCommand) { m_oAddRandomKey.m_oCommand.Dispose(); m_oAddRandomKey.m_oCommand = null; } } catch { bExist = true; } if (bExist) { string sNewKey = m_oAddRandomKey.m_oTast.sKey + "_" + m_oRandom.Next(mc_nRandomMaxNumber); m_oAddRandomKey.m_oTast.sKey = sNewKey; IDbCommand oSelCommand = m_oAddRandomKey.m_oSqlCon.CreateCommand(); m_oAddRandomKey.m_oCommand = oSelCommand; oSelCommand.CommandText = GetINSERTString(m_oAddRandomKey.m_oTast); m_oAddRandomKey.m_delegateNonQuery = new ExecuteNonQuery(oSelCommand.ExecuteNonQuery); m_oAddRandomKey.m_delegateNonQuery.BeginInvoke(AddRandomKeyCallback, null); } else { m_oAddRandomKey.Close(); m_oAddRandomKey.FireCallback(); } } catch { m_oAddRandomKey.DisposeAndCallback(); } }
public void ReadFileBegin(string strPath, System.IO.Stream oStream, AsyncCallback fCallback, object oParam) { m_oReadFile = new TransportClass(fCallback, ErrorTypes.StorageRead ,oParam); try { string strFilepath = GetFilePath(strPath); FileInfo oFileInfo = new FileInfo(strFilepath); if (oFileInfo.Exists) { FileStream oFileStreamInput = new FileStream(strFilepath, FileMode.Open, FileAccess.Read, FileShare.Read, (int)oFileInfo.Length, true); byte[] aBuffer = new byte[oFileStreamInput.Length]; m_oReadFile.m_oInput = oFileStreamInput; m_oReadFile.m_aBuffer = aBuffer; m_oReadFile.m_oOutput = oStream; m_oReadFile.m_bDisposeInput = true; m_oReadFile.m_oInput.BeginRead(aBuffer, 0, aBuffer.Length, EndCallbackRead, m_oReadFile); } else { m_oReadFile.m_eError = ErrorTypes.StorageFileNoFound; m_oReadFile.FireCallback(); } } catch { m_oReadFile.DisposeAndCallback(); } }