Example #1
0
        public void GetTaskBegin(AsyncCallback fCallback, object oParam)
        {
            m_GetTask = new TransportClass(fCallback, oParam);
            try
            {
                DateTime oDateTimeNow = DateTime.UtcNow;
                DateTime oDateTimeNowMinusConvertTime = oDateTimeNow.AddSeconds(-1 * m_dMaxConvertTimeInSeconds);
                string   strDateTimeNow = oDateTimeNow.ToString(Constants.mc_sDateTimeFormat);
                string   strDateTimeNowMinusConvertTime = oDateTimeNowMinusConvertTime.ToString(Constants.mc_sDateTimeFormat);

                string strSelectSQL = GetSelectString();

                m_GetTask.m_oSqlCon = GetDbConnection();
                m_GetTask.m_oSqlCon.Open();
                IDbCommand oSelCommand = m_GetTask.m_oSqlCon.CreateCommand();
                oSelCommand.CommandText    = strSelectSQL;
                m_GetTask.m_oCommand       = oSelCommand;
                m_GetTask.m_delegateReader = new ExecuteReader(oSelCommand.ExecuteReader);
                m_GetTask.m_delegateReader.BeginInvoke(GetTaskCallback, null);
            }
            catch
            {
                m_GetTask.DisposeAndCallback();
            }
        }
Example #2
0
        private void WriteFileCallback(IAsyncResult result)
        {
            TransportClass oTransportClass = result.AsyncState as TransportClass;

            try
            {
                int        nWriteBytes;
                ErrorTypes eError = oTransportClass.m_oStorage.WriteFileEnd(result, out nWriteBytes);
                if (ErrorTypes.NoError == eError)
                {
                    string sSiteUrl = UrlBuilder.UrlWithoutPath(oTransportClass.m_oContext.Request);
                    string sFileUrl = sSiteUrl + Constants.mc_sResourceServiceUrlRel + HttpUtility.UrlEncode(oTransportClass.m_sPath) + "&nocache=true" + "&deletepath=" + HttpUtility.UrlEncode(oTransportClass.m_sDeletePath) + "&filename=" + HttpUtility.UrlEncode(oTransportClass.m_sFilename);
                    writeXml(oTransportClass.m_oContext, sFileUrl, "100", true, null);
                }
                else
                {
                    writeXml(oTransportClass.m_oContext, null, null, null, eError);
                }
                oTransportClass.m_oCallback(new AsyncOperationData(oTransportClass));
            }
            catch
            {
                writeXml(oTransportClass.m_oContext, null, null, null, ErrorTypes.StorageWrite);
                oTransportClass.m_oCallback(new AsyncOperationData(oTransportClass));
            }
        }
Example #3
0
        private void DeletePath(IAsyncResult result)
        {
            TransportClass oTransportClass = result.AsyncState as TransportClass;

            try
            {
                if (null != oTransportClass.m_sDeletePath && false == string.IsNullOrEmpty(oTransportClass.m_sDeletePath))
                {
                    ITaskResultInterface oTaskResult = oTransportClass.m_oTaskResult;

                    string sKey = oTransportClass.m_sDeletePath;

                    oTaskResult.RemoveBegin(sKey, RemoveTaskCallback, oTransportClass);
                }
                else
                {
                    oTransportClass.m_oCallback(new AsyncOperationData(oTransportClass));
                }
            }
            catch (Exception e)
            {
                _log.Error("Exception catched in DeletePath:", e);

                oTransportClass.m_oCallback(new AsyncOperationData(oTransportClass));
            }
        }
Example #4
0
        public void GetOrCreateBegin(string sKey, TaskResultData oDataToAdd, AsyncCallback fCallback, object oParam)
        {
            m_oGetOrCreate           = new TransportClass(fCallback, oParam);
            m_oGetOrCreate.m_oTast   = oDataToAdd;
            m_oGetOrCreate.m_bCreate = true;
            try
            {
                m_oGetOrCreate.m_oSqlCon = GetDbConnection();
                m_oGetOrCreate.m_oSqlCon.Open();

                if (Constants.mc_sPostgreProvider == Utils.GetDbConnectionProviderName(m_sConnectionString))
                {
                    IDbCommand oInsCommand = m_oGetOrCreate.m_oSqlCon.CreateCommand();
                    oInsCommand.CommandText           = GetINSERTString(m_oGetOrCreate.m_oTast);
                    m_oGetOrCreate.m_oCommand         = oInsCommand;
                    m_oGetOrCreate.m_delegateNonQuery = new ExecuteNonQuery(oInsCommand.ExecuteNonQuery);
                    m_oGetOrCreate.m_delegateNonQuery.BeginInvoke(GetOrCreateCallback, null);
                }
                else
                {
                    IDbCommand oSelCommand = m_oGetOrCreate.m_oSqlCon.CreateCommand();
                    oSelCommand.CommandText           = GetUPSERTString(m_oGetOrCreate.m_oTast);
                    m_oGetOrCreate.m_oCommand         = oSelCommand;
                    m_oGetOrCreate.m_delegateNonQuery = new ExecuteNonQuery(oSelCommand.ExecuteNonQuery);
                    m_oGetOrCreate.m_delegateNonQuery.BeginInvoke(GetOrCreateCallback2, null);
                }
            }
            catch
            {
                m_oGetOrCreate.DisposeAndCallback();
            }
        }
Example #5
0
 private void FireCallback(TransportClass oTransportClass)
 {
     if (null != oTransportClass.m_fAsyncCallback)
     {
         oTransportClass.m_fAsyncCallback.Invoke(new AsyncOperationData(oTransportClass.m_oParam));
     }
 }
Example #6
0
        private void GetResponseCallback(IAsyncResult ar)
        {
            TransportClass oTransportClass = ar.AsyncState as TransportClass;

            try
            {
                HttpWebResponse response      = (HttpWebResponse)oTransportClass.m_oWebRequest.EndGetResponse(ar);
                Int64           ContentLength = 0;
                if (!Int64.TryParse(response.Headers.Get("Content-Length"), out ContentLength))
                {
                    ContentLength = 0;
                }
                if (m_nMaxSize > 0 && ContentLength > m_nMaxSize)
                {
                    _log.ErrorFormat("Downloaded object size {0} exceed max {1}", ContentLength, m_nMaxSize);
                    oTransportClass.m_eError = ErrorTypes.WebRequest;
                    ClearAndCallback(oTransportClass);
                }
                else
                {
                    Stream streamResponse = response.GetResponseStream();
                    AsyncContextReadOperation oAsyncContextReadOperation = new AsyncContextReadOperation(m_nMaxSize);
                    oTransportClass.m_oHttpWebResponse           = response;
                    oTransportClass.m_oStream                    = streamResponse;
                    oTransportClass.m_oAsyncContextReadOperation = oAsyncContextReadOperation;
                    oAsyncContextReadOperation.ReadContextBegin(streamResponse, ReadContextCallback, oTransportClass);
                }
            }
            catch (Exception e)
            {
                _log.Error("Exception catched in GetRequestStreamCallback:", e);
                oTransportClass.m_eError = ErrorTypes.WebRequest;
                ClearAndCallback(oTransportClass, true);
            }
        }
Example #7
0
        private void RemoveTaskCallback(IAsyncResult result)
        {
            TransportClass oTransportClass = result.AsyncState as TransportClass;

            try
            {
                ITaskResultInterface oTaskResult = oTransportClass.m_oTaskResult;

                if (null != oTaskResult)
                {
                    oTaskResult.RemoveEnd(result);
                }

                Storage oStorage = oTransportClass.m_oStorage;

                if (null != oStorage)
                {
                    oStorage.RemovePathBegin(oTransportClass.m_sDeletePath, RemoveFileCallback, oTransportClass);
                }
            }
            catch (Exception e)
            {
                _log.Error("Exception catched in RemoveTaskCallback:", e);

                oTransportClass.m_oCallback(new AsyncOperationData(oTransportClass));
            }
        }
 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();
     }
 }
Example #9
0
        private void GetRequestStreamCallback(IAsyncResult ar)
        {
            TransportClass oTransportClass = ar.AsyncState as TransportClass;

            try
            {
                Stream postStream = oTransportClass.m_oWebRequest.EndGetRequestStream(ar);
                if (null != oTransportClass.m_aInput)
                {
                    postStream.Write(oTransportClass.m_aInput, 0, oTransportClass.m_aInput.Length);
                }
                postStream.Close();
                oTransportClass.m_oWebRequest.BeginGetResponse(GetResponseCallback, oTransportClass);
            }
            catch (WebException e)
            {
                _log.Error("WebException catched in GetResponseCallback:", e);
                _log.ErrorFormat("The Uri requested is {0}", oTransportClass.m_oWebRequest.RequestUri);
                oTransportClass.m_eError = ErrorTypes.WebRequest;
                ClearAndCallback(oTransportClass, true);
            }
            catch (Exception e)
            {
                _log.Error("Exception catched in GetResponseCallback:", e);
                oTransportClass.m_eError = ErrorTypes.WebRequest;
                ClearAndCallback(oTransportClass, true);
            }
        }
        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();
            }
        }
        public void WriteFileBegin(string strPath, System.IO.Stream oStream, AsyncCallback fCallback, object oParam)
        {
            m_oWriteFile = new TransportClass(fCallback, ErrorTypes.StorageWrite, oParam);
            try
            {
                string   strFilepath = GetFilePath(strPath);
                FileInfo oFileInfo   = new FileInfo(strFilepath);
                if (false == oFileInfo.Directory.Exists)
                {
                    oFileInfo.Directory.Create();
                }
                int nStreamLength = (int)oStream.Length;

                if (0 == nStreamLength)
                {
                    nStreamLength = 1;
                }
                FileStream oFileStreamOutput = new FileStream(strFilepath, FileMode.Create, FileAccess.Write, FileShare.Write, nStreamLength, true);
                byte[]     aBuffer           = new byte[oStream.Length];

                m_oWriteFile.m_oInput         = oStream;
                m_oWriteFile.m_aBuffer        = aBuffer;
                m_oWriteFile.m_oOutput        = oFileStreamOutput;
                m_oWriteFile.m_bDisposeOutput = true;
                m_oWriteFile.m_oInput.BeginRead(aBuffer, 0, aBuffer.Length, EndCallbackRead, m_oWriteFile);
            }
            catch
            {
                m_oWriteFile.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();
                }
            }
        }
        /// <summary>
        /// Создает новый Тип транспорта и Триггер передачи данных по задаваемому значению Байта.
        /// </summary>
        /// <param name="value">Байт содержащий сгруппированные биты полностью содержащие значения данного класса.</param>
        public TransportTypeAndTrigger(byte value)
        {
            //X------- = 0= Client; 1= Server
            //-XXX---- = Production Trigger, 0 = Cyclic, 1 = CoS, 2 = Application Object
            //----XXXX = Transport class, 0 = Class 0, 1 = Class 1, 2 = Class 2, 3 = Class 3

            this.AsServer = (value & 0x80) != 0;

            byte productionTriggerValue = (byte)((value & 0x30) >> 4);

            foreach (ProductionTrigger trigger in Enum.GetValues(typeof(ProductionTrigger)))
            {
                if ((byte)trigger == productionTriggerValue)
                {
                    this.ProductionTrigger = trigger;
                    break;
                }
            }

            byte productionTransportClass = (byte)(value & 0x03);

            foreach (TransportClass transportClass in Enum.GetValues(typeof(TransportClass)))
            {
                if ((byte)transportClass == productionTransportClass)
                {
                    this.TransportClass = transportClass;
                    break;
                }
            }
        }
Example #15
0
        public IAsyncResult RequestBegin(string sUrl, string sMethod, string sContentType, byte[] aData, AsyncCallback fCallback, object oParam)
        {
            TransportClass     oTransportClass     = new TransportClass(fCallback, oParam, sUrl, sMethod, sContentType, aData, m_nAttemptCount, m_nAttemptDelay);
            AsyncOperationData oAsyncOperationData = new AsyncOperationData(oTransportClass);

            RequestBeginExec(oTransportClass);
            return(oAsyncOperationData);
        }
Example #16
0
        private void WaitEndTimerCallback(Object stateInfo)
        {
            TransportClass oTransportClass1 = stateInfo as TransportClass;

            if (null != oTransportClass1.m_oTimer)
            {
                oTransportClass1.m_oTimer.Dispose();
            }
            RequestBeginExec(oTransportClass1);
        }
Example #17
0
 private void Clear(TransportClass oTransportClass)
 {
     if (null != oTransportClass.m_oStream)
     {
         oTransportClass.m_oStream.Close();
     }
     if (null != oTransportClass.m_oHttpWebResponse)
     {
         oTransportClass.m_oHttpWebResponse.Close();
     }
 }
Example #18
0
        public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
        {
            bool       bStartAsync = false;
            ErrorTypes eError      = ErrorTypes.Unknown;

            try
            {
                _log.Info("Starting process request...");
                _log.Info(context.Request.QueryString.ToString());

                string vKey = context.Request.QueryString["vkey"];
                string sKey = context.Request.QueryString["key"];

                if (null != sKey && false == string.IsNullOrEmpty(sKey))
                {
                    eError = ErrorTypes.NoError;

                    if (ErrorTypes.NoError == eError)
                    {
                        bStartAsync = true;
                        Storage oStorage  = new Storage();
                        string  sTempKey  = "temp_" + sKey;
                        string  sFilename = sKey + ".tmp";
                        string  sPath     = sTempKey + "/" + sFilename;
                        AsyncContextReadOperation asynch          = new AsyncContextReadOperation();
                        TransportClass            oTransportClass = new TransportClass(context, cb, oStorage, asynch, sPath, sTempKey, sFilename);
                        asynch.ReadContextBegin(context.Request.InputStream, ReadContextCallback, oTransportClass);
                    }
                }
            }
            catch (Exception e)
            {
                eError = ErrorTypes.Unknown;

                _log.Error(context.Request.QueryString.ToString());
                _log.Error("Exeption: ", e);
            }
            finally
            {
                if (ErrorTypes.NoError != eError)
                {
                    writeXml(context, null, null, null, eError);
                }
            }

            TransportClass oTempTransportClass = new TransportClass(context, cb, null, null, null, null, null);

            if (false == bStartAsync)
            {
                cb(new AsyncOperationData(oTempTransportClass));
            }
            return(new AsyncOperationData(oTempTransportClass));
        }
 public void GetTaskBegin(AsyncCallback fCallback, object oParam)
 {
     m_oGetTask = new TransportClass(fCallback, oParam);
     try
     {
         m_oGetTask.m_delegateGetter = GetTask;
         m_oGetTask.m_delegateGetter.BeginInvoke(m_oGetTask.m_fCallback, m_oGetTask.m_oParam);
     }
     catch
     {
         m_oGetTask.DisposeAndCallback();
     }
 }
 public void RemoveTaskBegin(object key, AsyncCallback fCallback, object oParam)
 {
     m_oRemoveTask = new TransportClass(fCallback, oParam);
     try
     {
         m_oRemoveTask.m_delegateRemover = RemoveTask;
         m_oRemoveTask.m_delegateRemover.BeginInvoke(key, fCallback, oParam);
     }
     catch
     {
         m_oRemoveTask.DisposeAndCallback();
     }
 }
        private void EndCallbackRead(IAsyncResult ar)
        {
            TransportClass oTransportClass = ar.AsyncState as TransportClass;

            try
            {
                oTransportClass.m_oInput.EndRead(ar);
                oTransportClass.m_oOutput.BeginWrite(oTransportClass.m_aBuffer, 0, (int)oTransportClass.m_aBuffer.Length, oTransportClass.m_fCallback, oTransportClass.m_oParam);
            }
            catch
            {
                oTransportClass.DisposeAndCallback();
            }
        }
 public void AddTaskBegin(TaskQueueData oTask, Priority oPriority, AsyncCallback fCallback, object oParam)
 {
     m_oAddTask = new TransportClass(fCallback, oParam);
     try
     {
         m_oAddTask.m_delegateAdder = AddTask;
         m_oAddTask.m_delegateAdder.BeginInvoke(oTask, oPriority, m_oAddTask.m_fCallback, m_oAddTask.m_oParam);
     }
     catch
     {
         m_oAddTask.DisposeAndCallback();
     }
     return;
 }
 public void GetBegin(string sKey, AsyncCallback fCallback, object oParam)
 {
     m_oGet = new TransportClass(fCallback, oParam);
     try
     {
         m_oGet.m_sKey        = sKey;
         m_oGet.m_delegateGet = new DelegateGet(GetFromMC);
         m_oGet.m_delegateGet.BeginInvoke(sKey, out m_oGet.m_oTast, GetCallback, null);
     }
     catch
     {
         m_oGet.DisposeAndCallback();
     }
 }
Example #24
0
 public void WriteMediaXmlBegin(string sPath, Dictionary <string, string> aMediaXmlMapHash, AsyncCallback fAsyncCallback, object oParam)
 {
     m_oWriteMediaXml = new TransportClass(fAsyncCallback, oParam);
     try
     {
         byte[]       aBuffer = GetMediaXmlBytes(aMediaXmlMapHash);
         MemoryStream ms      = new MemoryStream(aBuffer);
         m_oWriteMediaXml.m_oStorage = new Storage();
         m_oWriteMediaXml.m_oStorage.WriteFileBegin(sPath, ms, fAsyncCallback, oParam);
     }
     catch
     {
         m_oWriteMediaXml.DisposeAndCallback();
     }
 }
Example #25
0
        private void ReadContextCallback(IAsyncResult result)
        {
            TransportClass oTransportClass = result.AsyncState as TransportClass;

            try
            {
                oTransportClass.m_oAsyncContextRead.ReadContextEnd(result);
                oTransportClass.m_oAsyncContextRead.m_aOutput.Position = 0;
                oTransportClass.m_oStorage.WriteFileBegin(oTransportClass.m_sPath, oTransportClass.m_oAsyncContextRead.m_aOutput, WriteFileCallback, oTransportClass);
            }
            catch
            {
                writeXml(oTransportClass.m_oContext, null, null, null, ErrorTypes.StorageWrite);
                oTransportClass.m_oCallback(new AsyncOperationData(oTransportClass));
            }
        }
Example #26
0
 private void ClearAndCallback(TransportClass oTransportClass, bool bRepeatIfCan)
 {
     oTransportClass.m_nAttemptCount--;
     Clear(oTransportClass);
     if (!bRepeatIfCan || oTransportClass.m_nAttemptCount <= 0)
     {
         FireCallback(oTransportClass);
     }
     else
     {
         oTransportClass.m_eError = ErrorTypes.NoError;
         Timer oTimer = new Timer(WaitEndTimerCallback, oTransportClass, TimeSpan.FromMilliseconds(-1), TimeSpan.FromMilliseconds(-1));
         oTransportClass.m_oTimer = oTimer;
         oTimer.Change(TimeSpan.FromMilliseconds(oTransportClass.m_nAttemptDelay), TimeSpan.FromMilliseconds(-1));
     }
 }
    public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
    {
        bool bStartAsync = false;
        ErrorTypes eError = ErrorTypes.Unknown;       
        try
        {
            _log.Info("Starting process request...");
            _log.Info(context.Request.QueryString.ToString());
                      
            string vKey = context.Request.QueryString["vkey"];
            string sKey = context.Request.QueryString["key"];

            if (null != sKey && false == string.IsNullOrEmpty(sKey))
            {
                eError = ErrorTypes.NoError;

                if (ErrorTypes.NoError == eError)
                {
                    bStartAsync = true;
                    Storage oStorage = new Storage();
                    string sTempKey = "temp_" + sKey;
                    string sFilename = sKey + ".tmp";
                    string sPath = sTempKey + "/" + sFilename;
                    AsyncContextReadOperation asynch = new AsyncContextReadOperation();
                    TransportClass oTransportClass = new TransportClass(context, cb, oStorage, asynch, sPath, sTempKey, sFilename);
                    asynch.ReadContextBegin(context.Request.InputStream, ReadContextCallback, oTransportClass);
                }
            }
        }
        catch(Exception e)
        {
            eError = ErrorTypes.Unknown;
            
            _log.Error(context.Request.QueryString.ToString());
            _log.Error("Exeption: ", e);
        }
        finally
        {
            if (ErrorTypes.NoError != eError)
                writeXml(context, null, null, null, eError);
        }
        
        TransportClass oTempTransportClass = new TransportClass(context, cb, null, null, null, null, null);
        if (false == bStartAsync)
            cb(new AsyncOperationData(oTempTransportClass));
        return new AsyncOperationData(oTempTransportClass);
    }
 public void GetOrCreateBegin(string sKey, TaskResultData oDataToAdd, AsyncCallback fCallback, object oParam)
 {
     m_oGetOrCreate           = new TransportClass(fCallback, oParam);
     m_oGetOrCreate.m_oTast   = oDataToAdd;
     m_oGetOrCreate.m_bCreate = true;
     m_oGetOrCreate.m_sKey    = sKey;
     try
     {
         TaskResultData oTast = null;
         m_oGetOrCreate.m_delegateGet = new DelegateGet(GetFromMC);
         m_oGetOrCreate.m_delegateGet.BeginInvoke(sKey, out oTast, GetOrCreateCallback, null);
     }
     catch
     {
         m_oGetOrCreate.DisposeAndCallback();
     }
 }
Example #29
0
        private void ReadFileCallback(IAsyncResult result)
        {
            TransportClass oTransportClass = result.AsyncState as TransportClass;
            HttpContext    context         = oTransportClass.m_oContext;

            try
            {
                FileStream oFileStreamInput = oTransportClass.m_oFileStreamInput;
                oTransportClass.nReadWriteBytes = oFileStreamInput.EndRead(result);
                oFileStreamInput.Dispose();
                if (oTransportClass.nReadWriteBytes <= 0)
                {
                    context.Response.StatusCode = (int)HttpStatusCode.BadRequest;
                    oTransportClass.m_oCallback(new AsyncOperationData(oTransportClass));
                }
                else
                {
                    byte[] aOutput = null;
                    if (gc_sJsExtention == Path.GetExtension(oTransportClass.m_sFontNameDecoded))
                    {
                        aOutput = GetJsContent(oTransportClass.m_aBuffer, oTransportClass.m_sFontNameDecoded.Substring(0, oTransportClass.m_sFontNameDecoded.Length - gc_sJsExtention.Length));
                        oTransportClass.nReadWriteBytes = aOutput.Length;
                    }
                    else
                    {
                        aOutput = oTransportClass.m_aBuffer;
                        byte[] guidOdttf = { 0xA0, 0x66, 0xD6, 0x20, 0x14, 0x96, 0x47, 0xfa, 0x95, 0x69, 0xB8, 0x50, 0xB0, 0x41, 0x49, 0x48 };

                        int nMaxLen = Math.Min(32, aOutput.Length);
                        for (int i = 0; i < nMaxLen; ++i)
                        {
                            aOutput[i] ^= guidOdttf[i % 16];
                        }
                    }
                    context.Response.OutputStream.BeginWrite(aOutput, 0, aOutput.Length, WriteBufferCallback, oTransportClass);
                }
            }
            catch (Exception e)
            {
                context.Response.StatusCode = (int)HttpStatusCode.BadRequest;
                oTransportClass.m_oCallback(new AsyncOperationData(oTransportClass));

                _log.Error("Exception catched in ReadFileCallback:", e);
            }
        }
        private void ReadFileCallback(IAsyncResult result)
        {
            TransportClass oTransportClass = result.AsyncState as TransportClass;
            HttpContext    context         = oTransportClass.m_oContext;

            try
            {
                Storage oStorage = oTransportClass.m_oStorage;
                if (null != oStorage)
                {
                    int        nReadWriteBytes = 0;
                    ErrorTypes eResult         = oStorage.ReadFileEnd(result, out nReadWriteBytes);
                    if (ErrorTypes.NoError != eResult)
                    {
                        context.Response.StatusCode = (int)HttpStatusCode.BadRequest;
                    }
                    else
                    {
                        context.Response.AddHeader("Content-Length", nReadWriteBytes.ToString());
                        context.Response.StatusCode = (int)HttpStatusCode.OK;
                    }
                    context.Response.Flush();
                    context.Response.End();
                }
                if (null != oTransportClass.m_sDeletePath && false == string.IsNullOrEmpty(oTransportClass.m_sDeletePath))
                {
                    TaskResult oTaskResult = oTransportClass.m_oTaskResult;

                    string sKey = oTransportClass.m_sDeletePath;

                    oTaskResult.RemoveBegin(sKey, RemoveTaskCallback, oTransportClass);
                }
                else
                {
                    oTransportClass.m_oCallback(new AsyncOperationData(oTransportClass));
                }
            }
            catch (Exception e)
            {
                context.Response.StatusCode = (int)HttpStatusCode.BadRequest;
                oTransportClass.m_oCallback(new AsyncOperationData(oTransportClass));

                _log.Error("Exception catched in ReadFileCallback:", e);
            }
        }
Example #31
0
        public ErrorTypes RequestEnd(IAsyncResult ar, out byte[] aOutput)
        {
            aOutput = null;
            ErrorTypes eError = ErrorTypes.WebRequest;

            try
            {
                TransportClass oTransportClass = ar.AsyncState as TransportClass;
                aOutput = oTransportClass.m_aOutput;
                eError  = oTransportClass.m_eError;
            }
            catch (Exception e)
            {
                _log.Error("Exception catched in RequestEnd:", e);
                eError = ErrorTypes.WebRequest;
            }
            return(eError);
        }
        public void ReadFileBegin(string strPath, System.IO.Stream oStream, AsyncCallback cb, object oParam)
        {
            try
            {
                m_oReadFile = new TransportClass(cb, oParam);
                m_oReadFile.m_oS3Client = Amazon.AWSClientFactory.CreateAmazonS3Client(m_oRegion);

                string strFileKey = GetFilePath(strPath);
                Amazon.S3.Model.GetObjectRequest oRequest = new Amazon.S3.Model.GetObjectRequest()
                      .WithBucketName(m_strBucketName).WithKey(strFileKey);

                m_oReadFile.m_oStreamOutput = oStream;
                m_oReadFile.m_oS3Client.BeginGetObject(oRequest, EndCallbackGetObject, m_oReadFile);
            }
            catch
            {
                m_oReadFile.m_eError = ErrorTypes.StorageRead;
                m_oReadFile.DisposeAndCallback();
            }
        }
        public void WriteFileBegin(string strPath, System.IO.Stream oStream, AsyncCallback fCallback, object oParam)
        {
            m_oWriteFile = new TransportClass(fCallback, ErrorTypes.StorageWrite, oParam);
            try
            {
                string strFilepath = GetFilePath(strPath);
                FileInfo oFileInfo = new FileInfo(strFilepath);
                if (false == oFileInfo.Directory.Exists)
                    oFileInfo.Directory.Create();
                int nStreamLength = (int)oStream.Length;

                if(0 == nStreamLength)
                    nStreamLength = 1;
                FileStream oFileStreamOutput = new FileStream(strFilepath, FileMode.Create, FileAccess.Write, FileShare.Write, nStreamLength, true);
                byte[] aBuffer = new byte[oStream.Length];

                m_oWriteFile.m_oInput = oStream;
                m_oWriteFile.m_aBuffer = aBuffer;
                m_oWriteFile.m_oOutput = oFileStreamOutput;
                m_oWriteFile.m_bDisposeOutput = true;
                m_oWriteFile.m_oInput.BeginRead(aBuffer, 0, aBuffer.Length, EndCallbackRead, m_oWriteFile);
            }
            catch
            {
                m_oWriteFile.DisposeAndCallback();
            }
        }
Example #34
0
        public void GetTaskBegin(AsyncCallback fCallback, object oParam)
        {
            m_GetTask = new TransportClass(fCallback, oParam);
            try
            {
                
                string strSelectSQL = GetSelectString();

                m_GetTask.m_oSqlCon = GetDbConnection();
                m_GetTask.m_oSqlCon.Open();
                IDbCommand oSelCommand = m_GetTask.m_oSqlCon.CreateCommand();
                oSelCommand.CommandText = strSelectSQL;
                m_GetTask.m_oCommand = oSelCommand;
                m_GetTask.m_delegateReader = new ExecuteReader(oSelCommand.ExecuteReader);
                m_GetTask.m_delegateReader.BeginInvoke(GetTaskCallback, null);
            }
            catch(Exception e)
            {
                _log.Error("Exception cathed in GetTaskBegin:", e);
                m_GetTask.DisposeAndCallback();
            }
        }
    public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
    {
        bool bStartAsync = false;
        try
        {
            _log.Info("Starting process request...");
            _log.Info("fontname: " + m_sFontName);

            string sNameToDecode;
            if (m_sFontName.Length > gc_sJsExtention.Length && gc_sJsExtention == m_sFontName.Substring(m_sFontName.Length - gc_sJsExtention.Length))
                sNameToDecode = m_sFontName.Substring(0, m_sFontName.Length - gc_sJsExtention.Length);
            else
                sNameToDecode = m_sFontName;
            byte[] data_decode = Odtff_fonts.ZBase32Encoder.Decode(sNameToDecode);
            string sFontNameDecoded = System.Text.Encoding.UTF8.GetString(data_decode);
            _log.Info("fontnameDecoded: " + sFontNameDecoded);

            context.Response.Clear();
            context.Response.Cache.SetExpires(DateTime.Now.AddMinutes(double.Parse(ConfigurationManager.AppSettings["resource.expires"], Constants.mc_oCultureInfo)));
            context.Response.Cache.SetSlidingExpiration(false);
            context.Response.Cache.SetCacheability(HttpCacheability.Public);
            context.Response.ContentType = Utils.GetMimeType(sFontNameDecoded);
            string contentDisposition = Utils.GetContentDisposition(context.Request.UserAgent, context.Request.Browser.Browser, context.Request.Browser.Version, m_sFontName);
            context.Response.AppendHeader("Content-Disposition", contentDisposition);

            string sRealFontName = sFontNameDecoded;
            if (gc_sJsExtention == Path.GetExtension(sRealFontName))
                sRealFontName = sRealFontName.Substring(0, sRealFontName.Length - gc_sJsExtention.Length);

            string strFilepath;
            m_mapFontNameToFullPath.TryGetValue(sRealFontName.ToUpper(), out strFilepath);

            FileInfo oFileInfo = new FileInfo(strFilepath);
            if (oFileInfo.Exists)
            {
                DateTime oLastModified = oFileInfo.LastWriteTimeUtc;
                string sETag = oLastModified.Ticks.ToString("x");

                DateTime oDateTimeUtcNow = DateTime.UtcNow;

                if (oLastModified.CompareTo(oDateTimeUtcNow) > 0)
                {
                    _log.DebugFormat("LastModifiedTimeStamp changed from {0} to {1}", oLastModified, oDateTimeUtcNow);
                    oLastModified = oDateTimeUtcNow;
                }

                string sRequestIfModifiedSince = context.Request.Headers["If-Modified-Since"];
                string sRequestETag = context.Request.Headers["If-None-Match"];
                bool bNoModify = false;
                if (false == string.IsNullOrEmpty(sRequestETag) || false == string.IsNullOrEmpty(sRequestIfModifiedSince))
                {
                    bool bRequestETag = true;
                    if (false == string.IsNullOrEmpty(sRequestETag) && sRequestETag != sETag)
                        bRequestETag = false;
                    bool bRequestIfModifiedSince = true;
                    if (false == string.IsNullOrEmpty(sRequestIfModifiedSince))
                    {
                        try
                        {
                            DateTime oRequestIfModifiedSince = DateTime.ParseExact(sRequestIfModifiedSince, "R", System.Globalization.CultureInfo.InvariantCulture);
                            if ((oRequestIfModifiedSince - oLastModified).TotalSeconds > 1)
                                bRequestIfModifiedSince = false;
                        }
                        catch 
                        {
                            bRequestIfModifiedSince = false;
                        }
                    }
                    if (bRequestETag && bRequestIfModifiedSince)
                    {
                        context.Response.StatusCode = (int)HttpStatusCode.NotModified;
                        bNoModify = true;
                    }
                }
                if (false == bNoModify)
                {
                    context.Response.Cache.SetETag(sETag);

                    context.Response.Cache.SetLastModified(oLastModified.ToLocalTime());
                    
                    FileStream oFileStreamInput = new FileStream(strFilepath, FileMode.Open, FileAccess.Read, FileShare.Read, (int)oFileInfo.Length, true);
                    byte[] aBuffer = new byte[oFileStreamInput.Length];
                    TransportClass oTransportClass = new TransportClass(context, cb, oFileStreamInput, aBuffer, sFontNameDecoded);
                    oFileStreamInput.BeginRead(aBuffer, 0, aBuffer.Length, ReadFileCallback, oTransportClass);
                    bStartAsync = true;
                }
            }
            else
                context.Response.StatusCode = (int)HttpStatusCode.BadRequest;
        }
        catch(Exception e)
        {
            context.Response.StatusCode = (int)HttpStatusCode.BadRequest;
            
            _log.Error(context.Request.QueryString.ToString());
            _log.Error("Exeption catched in BeginProcessRequest:", e);
        }
        TransportClass oTempTransportClass = new TransportClass(context, cb, null, null, null);
        if (false == bStartAsync)
            cb(new AsyncOperationData(oTempTransportClass));
        return new AsyncOperationData(oTempTransportClass);
    }
 public void GetBegin(string sKey, AsyncCallback fCallback, object oParam)
 {
     m_oGet = new TransportClass(fCallback, oParam);
     try
     {
         m_oGet.m_sKey = sKey;
         m_oGet.m_delegateGet = new DelegateGet(GetFromMC);
         m_oGet.m_delegateGet.BeginInvoke(sKey, out m_oGet.m_oTast, GetCallback, null);
     }
     catch 
     {
         m_oGet.DisposeAndCallback();
     }
 }
 public void AddRandomKeyBegin(string sKey, TaskResultData oTastToAdd, AsyncCallback fCallback, object oParam)
 {
     m_oAddRandomKey = new TransportClass(fCallback, oParam);
     m_oAddRandomKey.m_oTast = oTastToAdd.Clone();
     try
     {
         m_oAddRandomKey.m_oSqlCon = GetDbConnection();
         m_oAddRandomKey.m_oSqlCon.Open();
         string sNewKey = 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);
     }
     catch
     {
         m_oAddRandomKey.DisposeAndCallback();
     }
 }
 private void Clear(TransportClass oTransportClass)
 {
     if (null != oTransportClass.m_oStream)
         oTransportClass.m_oStream.Close();
     if (null != oTransportClass.m_oHttpWebResponse)
         oTransportClass.m_oHttpWebResponse.Close();
 }
 private void FireCallback(TransportClass oTransportClass)
 {
     if (null != oTransportClass.m_fAsyncCallback)
         oTransportClass.m_fAsyncCallback.Invoke(new AsyncOperationData(oTransportClass.m_oParam));
 }
 private void ClearAndCallback(TransportClass oTransportClass)
 {
     ClearAndCallback(oTransportClass, false);
 }
        private void RequestBeginExec(TransportClass oTransportClass)
        {
            try
            {

                ServicePointManager.ServerCertificateValidationCallback = (s, c, h, p) => true;

                HttpWebRequest oWebRequest = (HttpWebRequest)HttpWebRequest.Create(oTransportClass.m_sUrl);
                oWebRequest.UserAgent = Constants.mc_sWebClientUserAgent;
                oTransportClass.m_oWebRequest = oWebRequest;
                if (!string.IsNullOrEmpty(oTransportClass.m_sMethod))
                    oWebRequest.Method = oTransportClass.m_sMethod;
                if ("GET" == oWebRequest.Method)
                {
                    oWebRequest.BeginGetResponse(GetResponseCallback, oTransportClass);
                }
                else
                {
                    if (!string.IsNullOrEmpty(oTransportClass.m_sContentType))
                        oWebRequest.ContentType = oTransportClass.m_sContentType;
                    else
                        oWebRequest.ContentType = "text/plain";
                    if (null != oTransportClass.m_aInput)
                        oWebRequest.ContentLength = oTransportClass.m_aInput.Length;
                    oWebRequest.BeginGetRequestStream(GetRequestStreamCallback, oTransportClass);
                }
            }
            catch (Exception e)
            {
                _log.Error("Exception catched in RequestBeginExec:", e);
                oTransportClass.m_eError = ErrorTypes.WebRequest;
                ClearAndCallback(oTransportClass, true);
            }
        }
        public void WriteFileBegin(string strPath, System.IO.Stream oStream, AsyncCallback cb, object oParam)
        {
            try
            {
                m_oWriteFile = new TransportClass(cb, oParam);
                m_oWriteFile.m_nReadWriteBytes = (int)oStream.Length;
                m_oWriteFile.m_oS3Client = Amazon.AWSClientFactory.CreateAmazonS3Client(m_oRegion);

                string strFileKey = GetFilePath(strPath);
                Amazon.S3.Model.PutObjectRequest oRequest = new Amazon.S3.Model.PutObjectRequest()
                    .WithBucketName(m_strBucketName).WithKey(strFileKey);
                oRequest.WithInputStream(oStream);

                m_oWriteFile.m_oS3Client.BeginPutObject(oRequest, m_oWriteFile.m_fCallback, m_oWriteFile.m_oParam);
            }
            catch
            {
                m_oWriteFile.m_eError = ErrorTypes.StorageWrite;
                m_oWriteFile.DisposeAndCallback();
            }
        }
 public IAsyncResult RequestBegin(string sUrl, string sMethod, string sContentType, byte[] aData, AsyncCallback fCallback, object oParam)
 {
     TransportClass oTransportClass = new TransportClass(fCallback, oParam, sUrl, sMethod, sContentType, aData, m_nAttemptCount, m_nAttemptDelay);
     AsyncOperationData oAsyncOperationData = new AsyncOperationData(oTransportClass);
     RequestBeginExec(oTransportClass);
     return oAsyncOperationData;
 }
 public void GetOrCreateBegin(string sKey, TaskResultData oDataToAdd, AsyncCallback fCallback, object oParam)
 {
     m_oGetOrCreate = new TransportClass(fCallback, oParam);
     m_oGetOrCreate.m_oTast = oDataToAdd;
     m_oGetOrCreate.m_bCreate = true;
     try
     {
         m_oGetOrCreate.m_oSqlCon = GetDbConnection();
         m_oGetOrCreate.m_oSqlCon.Open();
         IDbCommand oSelCommand = m_oGetOrCreate.m_oSqlCon.CreateCommand();
         oSelCommand.CommandText = GetSELECTString(sKey);
         m_oGetOrCreate.m_oCommand = oSelCommand;
         m_oGetOrCreate.m_delegateReader = new ExecuteReader(oSelCommand.ExecuteReader);
         m_oGetOrCreate.m_delegateReader.BeginInvoke(GetOrCreateCallback, null);
     }
     catch
     {
         m_oGetOrCreate.DisposeAndCallback();
     }
 }
Example #45
0
        public void GetOrCreateBegin(string sKey, TaskResultData oDataToAdd, AsyncCallback fCallback, object oParam)
        {
            m_oGetOrCreate = new TransportClass(fCallback, oParam);
            m_oGetOrCreate.m_oTast = oDataToAdd;
            m_oGetOrCreate.m_bCreate = true;
            try
            {
                m_oGetOrCreate.m_oSqlCon = GetDbConnection();
                m_oGetOrCreate.m_oSqlCon.Open();

                if (Constants.mc_sPostgreProvider == Utils.GetDbConnectionProviderName(m_sConnectionString))
                {
                    IDbCommand oInsCommand = m_oGetOrCreate.m_oSqlCon.CreateCommand();
                    oInsCommand.CommandText = GetINSERTString(m_oGetOrCreate.m_oTast);
                    m_oGetOrCreate.m_oCommand = oInsCommand;
                    m_oGetOrCreate.m_delegateNonQuery = new ExecuteNonQuery(oInsCommand.ExecuteNonQuery);
                    m_oGetOrCreate.m_delegateNonQuery.BeginInvoke(GetOrCreateCallback, null);
                }
                else
                {

                    IDbCommand oSelCommand = m_oGetOrCreate.m_oSqlCon.CreateCommand();
                    oSelCommand.CommandText = GetUPSERTString(m_oGetOrCreate.m_oTast);
                    m_oGetOrCreate.m_oCommand = oSelCommand;
                    m_oGetOrCreate.m_delegateNonQuery = new ExecuteNonQuery(oSelCommand.ExecuteNonQuery);
                    m_oGetOrCreate.m_delegateNonQuery.BeginInvoke(GetOrCreateCallback2, null);
                }
            }
            catch
            {
                m_oGetOrCreate.DisposeAndCallback();
            }
        }
        public void GetMediaXmlBegin(string sPath, AsyncCallback fAsyncCallback, object oParam)
        {
            m_oGetMediaXml = new TransportClass(fAsyncCallback, oParam);
            m_oGetMediaXml.m_sPath = sPath;
            m_oGetMediaXml.m_aMediaXmlMapFilename = new Dictionary<string, string>();
            m_oGetMediaXml.m_aMediaXmlMapHash = new Dictionary<string, string>();

            StorageFileInfo oStorageFileInfo;
            ErrorTypes eFileExist = m_oGetMediaXml.m_oStorage.GetFileInfo(sPath, out oStorageFileInfo);
            if (ErrorTypes.NoError == eFileExist && null != oStorageFileInfo)
            {

                m_oGetMediaXml.m_oStorage.ReadFileBegin(sPath, m_oGetMediaXml.m_oMemoryStream, ReadMediaXmlCallback, null);
            }
            else
            {

                m_oGetMediaXml.m_oStorage.GetTreeNodeBegin(Path.GetDirectoryName(sPath), GetTreeNodeCallback, null);
            }
        }
 public void GetOrCreateBegin(string sKey, TaskResultData oDataToAdd, AsyncCallback fCallback, object oParam)
 {
     m_oGetOrCreate = new TransportClass(fCallback, oParam);
     m_oGetOrCreate.m_oTast = oDataToAdd;
     m_oGetOrCreate.m_bCreate = true;
     m_oGetOrCreate.m_sKey = sKey;
     try
     {
         TaskResultData oTast = null;
         m_oGetOrCreate.m_delegateGet = new DelegateGet(GetFromMC);
         m_oGetOrCreate.m_delegateGet.BeginInvoke(sKey, out oTast, GetOrCreateCallback, null);
     }
     catch
     {
         m_oGetOrCreate.DisposeAndCallback();
     }
 }
        public void WriteMediaXmlBegin(string sPath, Dictionary<string, string> aMediaXmlMapHash, AsyncCallback fAsyncCallback, object oParam)
        {
            m_oWriteMediaXml = new TransportClass(fAsyncCallback, oParam);
            try
            {

                StringBuilder sb = new StringBuilder();
                sb.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
                sb.Append("<images>");
                foreach (KeyValuePair<string, string> kvp in aMediaXmlMapHash)
                    sb.AppendFormat("<image md5=\"{0}\" filename=\"{1}\"/>", kvp.Key, kvp.Value);
                sb.Append("</images>");
                byte[] aBuffer = Encoding.UTF8.GetBytes(sb.ToString());
                MemoryStream ms = new MemoryStream(aBuffer);
                m_oWriteMediaXml.m_oStorage = new Storage();
                m_oWriteMediaXml.m_oStorage.WriteFileBegin(sPath, ms, fAsyncCallback, oParam);
            }
            catch
            {
                m_oWriteMediaXml.DisposeAndCallback();
            }
        }
    public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
    {
        bool bStartAsync = false;
        try
        {
            _log.Info("Starting process request...");
            _log.Info("fontname: " + m_sFontName);

            context.Response.Clear();
            context.Response.Cache.SetExpires(DateTime.Now);
            context.Response.Cache.SetCacheability(HttpCacheability.Public);
            context.Response.ContentType = Utils.GetMimeType(m_sFontName);
            if (context.Request.ServerVariables.Get("HTTP_USER_AGENT").Contains("MSIE"))
                context.Response.AppendHeader("Content-Disposition", "attachment; filename=\"" + context.Server.UrlEncode(m_sFontName) + "\"");
            else
                context.Response.AppendHeader("Content-Disposition", "attachment; filename=\"" + m_sFontName + "\"");

            string sConfigFontDir = ConfigurationManager.AppSettings["utils.common.fontdir"];
            string strFilepath;
            if (null != sConfigFontDir && string.Empty != sConfigFontDir)
                strFilepath = Path.Combine(Environment.ExpandEnvironmentVariables(sConfigFontDir), m_sFontName);
            else
                m_mapFontNameToFullPath.TryGetValue(m_sFontName.ToUpper(), out strFilepath);
            if (".js" == Path.GetExtension(m_sFontName))
            {
                string[] aFontExts = {".ttf", ".ttc", ".otf"};
                for(int i = 0; i < aFontExts.Length; i++)
                {
                    strFilepath = Path.ChangeExtension(strFilepath, aFontExts[i]);
                    if (File.Exists(strFilepath))
                        break;
                }
            }
            FileInfo oFileInfo = new FileInfo(strFilepath);
            if (oFileInfo.Exists)
            {
                DateTime oLastModified = oFileInfo.LastWriteTimeUtc;
                string sETag = oLastModified.Ticks.ToString("x");

                DateTime oDateTimeUtcNow = DateTime.UtcNow;

                if (oLastModified.CompareTo(oDateTimeUtcNow) > 0)
                {
                    _log.DebugFormat("LastModifiedTimeStamp changed from {0} to {1}", oLastModified, oDateTimeUtcNow);
                    oLastModified = oDateTimeUtcNow;
                }

                string sRequestIfModifiedSince = context.Request.Headers["If-Modified-Since"];
                string sRequestETag = context.Request.Headers["If-None-Match"];
                bool bNoModify = false;
                if (false == string.IsNullOrEmpty(sRequestETag) || false == string.IsNullOrEmpty(sRequestIfModifiedSince))
                {
                    bool bRequestETag = true;
                    if (false == string.IsNullOrEmpty(sRequestETag) && sRequestETag != sETag)
                        bRequestETag = false;
                    bool bRequestIfModifiedSince = true;
                    if (false == string.IsNullOrEmpty(sRequestIfModifiedSince))
                    {
                        try
                        {
                            DateTime oRequestIfModifiedSince = DateTime.ParseExact(sRequestIfModifiedSince, "R", System.Globalization.CultureInfo.InvariantCulture);
                            if ((oRequestIfModifiedSince - oLastModified).TotalSeconds > 1)
                                bRequestIfModifiedSince = false;
                        }
                        catch
                        {
                            bRequestIfModifiedSince = false;
                        }
                    }
                    if (bRequestETag && bRequestIfModifiedSince)
                    {
                        context.Response.StatusCode = (int)HttpStatusCode.NotModified;
                        bNoModify = true;
                    }
                }
                if (false == bNoModify)
                {
                    context.Response.Cache.SetETag(sETag);
                    context.Response.Cache.SetLastModified(oLastModified);

                    FileStream oFileStreamInput = new FileStream(strFilepath, FileMode.Open, FileAccess.Read, FileShare.Read, (int)oFileInfo.Length, true);
                    byte[] aBuffer = new byte[oFileStreamInput.Length];
                    TransportClass oTransportClass = new TransportClass(context, cb, oFileStreamInput, aBuffer);
                    oFileStreamInput.BeginRead(aBuffer, 0, aBuffer.Length, ReadFileCallback, oTransportClass);
                    bStartAsync = true;
                }
            }
            else
                context.Response.StatusCode = (int)HttpStatusCode.BadRequest;
        }
        catch(Exception e)
        {
            context.Response.StatusCode = (int)HttpStatusCode.BadRequest;

            _log.Error(context.Request.Params.ToString());
            _log.Error("Exeption catched in BeginProcessRequest:", e);
        }
        TransportClass oTempTransportClass = new TransportClass(context, cb, null, null);
        if (false == bStartAsync)
            cb(new AsyncOperationData(oTempTransportClass));
        return new AsyncOperationData(oTempTransportClass);
    }
 public void AddTaskBegin(TaskQueueData oTask, Priority oPriority, AsyncCallback fCallback, object oParam)
 {
     m_oAddTask = new TransportClass(fCallback, oParam);
     try
     {
         m_oAddTask.m_delegateAdder = AddTask;
         m_oAddTask.m_delegateAdder.BeginInvoke(oTask, oPriority, m_oAddTask.m_fCallback, m_oAddTask.m_oParam);
     }
     catch
     {
         m_oAddTask.DisposeAndCallback();
     }
     return;
 }
    public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
    {
        bool bStartAsync = false;
        try
        {
            _log.Info("Starting process request...");
            _log.Info(context.Request.QueryString.ToString());
            
            Storage oStorage = new Storage();
            ITaskResultInterface oTaskResult = TaskResult.NewTaskResult();
            string sPathOriginal = context.Request.QueryString["path"];
            string sPath = null;
            if (null != sPathOriginal)
            {
                sPath = sPathOriginal.Replace("../", "").Replace("..\\", "");
                if (sPathOriginal != sPath)
                {
                    _log.Error("Possible XSS attack:" + sPathOriginal);
                }
            }

            string sOutputFilename = context.Request.QueryString["filename"];

            string sDeletePathOriginal = context.Request.QueryString["deletepath"];
            string sDeletePath = null;
            if (null != sDeletePathOriginal)
            {
                sDeletePath = sDeletePathOriginal.Replace("../", "").Replace("..\\", "");
                if (sDeletePathOriginal != sDeletePath)
                {
                    _log.Error("Possible XSS attack:" + sDeletePathOriginal);
                }
            }

            string sNoCache = context.Request.QueryString["nocache"];
            if (string.IsNullOrEmpty(sOutputFilename))
            {
                if (null != sPath)
                {
                    int nIndex1 = sPath.LastIndexOf('/');
                    int nIndex2 = sPath.LastIndexOf('\\');
                    if (-1 != nIndex1 || -1 != nIndex2)
                    {
                        int nIndex = Math.Max(nIndex1, nIndex2);
                        sOutputFilename = sPath.Substring(nIndex + 1);
                    }
                    else
                        sOutputFilename = "resource";
                }
            }
               
            context.Response.Clear();

            context.Response.Cache.SetCacheability(HttpCacheability.Public);
            context.Response.ContentType = Utils.GetMimeType(sOutputFilename);
            string contentDisposition = Utils.GetContentDisposition(context.Request.UserAgent, context.Request.Browser.Browser, context.Request.Browser.Version, sOutputFilename);
            context.Response.AppendHeader("Content-Disposition", contentDisposition);
            if (null != sPath)
            {
                TransportClass oTransportClass = new TransportClass(context, cb, oStorage, oTaskResult, sPath, sDeletePath);
                oStorage.GetFileInfoBegin(sPath, GetFileInfoCallback, oTransportClass);
                bStartAsync = true;
            }
            else
                context.Response.StatusCode = (int)HttpStatusCode.NotFound;
                
        }
        catch(Exception e)
        {
            context.Response.StatusCode = (int)HttpStatusCode.BadRequest;
            
            _log.Error(context.Request.QueryString.ToString());
            _log.Error("Exeption catched in BeginProcessRequest:", e);
        }
        TransportClass oTempTransportClass = new TransportClass(context, cb, null, null, null, null);
        if (false == bStartAsync)
            cb(new AsyncOperationData(oTempTransportClass));
        return new AsyncOperationData(oTempTransportClass);
    }
 public void GetTaskBegin(AsyncCallback fCallback, object oParam)
 {
     m_oGetTask = new TransportClass(fCallback, oParam);
     try
     {
         m_oGetTask.m_delegateGetter = GetTask;
         m_oGetTask.m_delegateGetter.BeginInvoke(m_oGetTask.m_fCallback, m_oGetTask.m_oParam);
     }
     catch
     {
         m_oGetTask.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 RemoveTaskBegin(object key, AsyncCallback fCallback, object oParam)
 {
     m_oRemoveTask = new TransportClass(fCallback, oParam);
     try
     {
         m_oRemoveTask.m_delegateRemover = RemoveTask;
         m_oRemoveTask.m_delegateRemover.BeginInvoke(key, fCallback, oParam);
     }
     catch
     {
         m_oRemoveTask.DisposeAndCallback();
     }
 }
        public void GetTreeNodeBegin(string strPath, AsyncCallback cb, object oParam)
        {
            try
            {
                m_oGetTreeNode = new TransportClass(cb, oParam);
                m_oGetTreeNode.m_oS3Client = Amazon.AWSClientFactory.CreateAmazonS3Client(m_oRegion);
                m_oGetTreeNode.m_strPrefix = GetDirPath(strPath);
                Amazon.S3.Model.ListObjectsRequest oRequest = new Amazon.S3.Model.ListObjectsRequest();
                oRequest.WithBucketName(m_strBucketName).WithPrefix(m_oGetTreeNode.m_strPrefix);

                m_oGetTreeNode.m_oS3Client.BeginListObjects(oRequest, m_oGetTreeNode.m_fCallback, m_oGetTreeNode.m_oParam);
            }
            catch
            {
                m_oGetTreeNode.m_eError = ErrorTypes.StorageGetInfo;
                m_oGetTreeNode.DisposeAndCallback();
            }
        }
        public void GetTaskBegin(AsyncCallback fCallback, object oParam)
        {
            m_GetTask = new TransportClass(fCallback, oParam);
            try
            {
                DateTime oDateTimeNow = DateTime.UtcNow;
                DateTime oDateTimeNowMinusConvertTime = oDateTimeNow.AddSeconds(-1 * m_dMaxConvertTimeInSeconds);
                string strDateTimeNow = oDateTimeNow.ToString(Constants.mc_sDateTimeFormat);
                string strDateTimeNowMinusConvertTime = oDateTimeNowMinusConvertTime.ToString(Constants.mc_sDateTimeFormat);

                string strSelectSQL = GetSelectString();

                m_GetTask.m_oSqlCon = GetDbConnection();
                m_GetTask.m_oSqlCon.Open();
                IDbCommand oSelCommand = m_GetTask.m_oSqlCon.CreateCommand();
                oSelCommand.CommandText = strSelectSQL;
                m_GetTask.m_oCommand = oSelCommand;
                m_GetTask.m_delegateReader = new ExecuteReader(oSelCommand.ExecuteReader);
                m_GetTask.m_delegateReader.BeginInvoke(GetTaskCallback, null);
            }
            catch
            {
                m_GetTask.DisposeAndCallback();
            }
        }
        public void RemovePathBegin(string strPath, AsyncCallback cb, object oParam)
        {
            try
            {
                m_oRemoveDirectory = new TransportClass(cb, oParam);
                m_oRemoveDirectory.m_oS3Client = Amazon.AWSClientFactory.CreateAmazonS3Client(m_oRegion);

                string strDirKey = GetDirPath(strPath);
                Amazon.S3.Model.ListObjectsRequest oListObjectsRequest = new Amazon.S3.Model.ListObjectsRequest()
                    .WithBucketName(m_strBucketName).WithPrefix(strDirKey);

                m_oRemoveDirectory.m_oS3Client.BeginListObjects(oListObjectsRequest, EndCallbackGetListObjects, m_oRemoveDirectory);
            }
            catch
            {
                m_oRemoveDirectory.m_eError = ErrorTypes.StorageRemoveDir;
                m_oRemoveDirectory.DisposeAndCallback();
            }
        }
 public void WriteMediaXmlBegin(string sPath, Dictionary<string, string> aMediaXmlMapHash, AsyncCallback fAsyncCallback, object oParam)
 {
     m_oWriteMediaXml = new TransportClass(fAsyncCallback, oParam);
     try
     {
         
         byte[] aBuffer = GetMediaXmlBytes(aMediaXmlMapHash);
         MemoryStream ms = new MemoryStream(aBuffer);
         m_oWriteMediaXml.m_oStorage = new Storage();
         m_oWriteMediaXml.m_oStorage.WriteFileBegin(sPath, ms, fAsyncCallback, oParam);
     }
     catch
     {
         m_oWriteMediaXml.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 ClearAndCallback(TransportClass oTransportClass, bool bRepeatIfCan)
 {
     oTransportClass.m_nAttemptCount--;
     Clear(oTransportClass);
     if (!bRepeatIfCan || oTransportClass.m_nAttemptCount <= 0)
     {
         FireCallback(oTransportClass);
     }
     else
     {
         oTransportClass.m_eError = ErrorTypes.NoError;
         Timer oTimer = new Timer(WaitEndTimerCallback, oTransportClass, TimeSpan.FromMilliseconds(-1), TimeSpan.FromMilliseconds(-1));
         oTransportClass.m_oTimer = oTimer;
         oTimer.Change(TimeSpan.FromMilliseconds(oTransportClass.m_nAttemptDelay), TimeSpan.FromMilliseconds(-1));
     }
 }