Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
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 IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
    {
        TransportClassMainAshx oTransportClassMainAshx = new TransportClassMainAshx(context, cb);
        AsyncContextReadOperation asynch = new AsyncContextReadOperation();
        TransportClassContextRead oTransportClassContextRead = new TransportClassContextRead(oTransportClassMainAshx, asynch);
        try
        {
            asynch.ReadContextBegin(context.Request.InputStream, ReadContext, oTransportClassContextRead);
        }
        catch(Exception e)
        {
            OutputCommand oOutputCommand = new OutputCommand(ErrorTypes.Unknown);
            WriteOutputCommand(new TransportClassMainAshx(context, cb), oOutputCommand);

            _log.Error("Exception catched in BeginProcessRequest:", e);
        }
        return new AsyncOperationData(extraData);
    }
Exemplo n.º 4
0
            public TransportClass(AsyncCallback fCallback, object oParam, string sUrl, string sMethod, string sContentType, byte[] aData, uint nAttemptCount, uint nAttemptDelay)
            {
                m_fAsyncCallback = fCallback;
                m_oParam         = oParam;
                m_sUrl           = sUrl;
                m_sMethod        = sMethod;
                m_sContentType   = sContentType;
                m_aInput         = aData;

                m_oTimer                     = null;
                m_oWebRequest                = null;
                m_oHttpWebResponse           = null;
                m_oStream                    = null;
                m_oAsyncContextReadOperation = null;

                m_aOutput = null;
                m_eError  = ErrorTypes.NoError;

                m_nAttemptCount = nAttemptCount;
                m_nAttemptDelay = nAttemptDelay;
            }
 public TransportClass2(TransportClass1 oTransportClass1, Dictionary<string, string> oMediaXmlMapHash, Dictionary<string, string> oMediaXmlMapFilename, AsyncContextReadOperation oAsyncContextReadOperation)
     : base(oTransportClass1, oTransportClass1.m_oAsyncMediaXmlOperation, oTransportClass1.m_aInputParams, oTransportClass1.m_aUrls, oTransportClass1.m_sKey, oTransportClass1.m_sMediaXml, oTransportClass1.m_oFiles, oTransportClass1.m_oFilesEnumerator)
 {
     m_oMediaXmlMapHash = oMediaXmlMapHash;
     m_oMediaXmlMapFilename = oMediaXmlMapFilename;
     m_oAsyncContextReadOperation = oAsyncContextReadOperation;
 }
 private void GetMediaXmlCallbackProcess(TransportClass1 oTransportClass1, Dictionary<string, string> aMediaXmlMapHash, Dictionary<string, string> aMediaXmlMapFilename)
 {
     AsyncContextReadOperation oAsyncContextReadOperation = new AsyncContextReadOperation();
     TransportClass2 oTransportClass2 = new TransportClass2(oTransportClass1, aMediaXmlMapHash, aMediaXmlMapFilename, oAsyncContextReadOperation);
     HttpPostedFile oCurrentFile = (HttpPostedFile)oTransportClass1.m_oFiles[(string)oTransportClass1.m_oFilesEnumerator.Current];
     oCurrentFile.InputStream.Position = 0;
     oAsyncContextReadOperation.ReadContextBegin(oCurrentFile.InputStream, ReadContextCallback, oTransportClass2);
 }
Exemplo n.º 7
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);
     }
 }
Exemplo n.º 8
0
        public ErrorTypes Request(string sUrl, string sMethod, string sContentType, byte[] aData, out byte[] aOutput)
        {
            ErrorTypes eError = ErrorTypes.NoError;
            aOutput = null;
            try
            {

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

                WebResponse oWebResponse = null;
                int nAttemptCount = 0;
                bool bComplete = false;
                while (!bComplete && nAttemptCount < m_nAttemptCount)
                {
                    eError = ErrorTypes.NoError;
                    try
                    {
                        HttpWebRequest oWebRequest = (HttpWebRequest)HttpWebRequest.Create(sUrl);
                        oWebRequest.UserAgent = Constants.mc_sWebClientUserAgent;
                        if (!string.IsNullOrEmpty(sMethod))
                            oWebRequest.Method = sMethod;
                        if ("POST" == oWebRequest.Method)
                        {
                            if (!string.IsNullOrEmpty(sContentType))
                                oWebRequest.ContentType = sContentType;
                            else
                                oWebRequest.ContentType = "text/plain";
                            if (null != aData)
                                oWebRequest.ContentLength = aData.Length;
                            using (Stream postStream = oWebRequest.GetRequestStream())
                            {
                                if (null != aData)
                                    postStream.Write(aData, 0, aData.Length);
                            }
                        }
                        oWebResponse = oWebRequest.GetResponse();
                        bComplete = true;
                    }
                    catch (Exception e)
                    {
                        _log.Error("Exception catched in Request:", e);
                        eError = ErrorTypes.WebRequest;
                    }

                    nAttemptCount++;
                    if (!bComplete && nAttemptCount < m_nAttemptCount)
                        Thread.Sleep((int)m_nAttemptDelay);
                }
                if (null != oWebResponse)
                {
                    Int64 ContentLength = 0;
                    if (!Int64.TryParse(oWebResponse.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);
                        eError = ErrorTypes.WebRequest;
                    }
                    else
                    {
                        using (Stream oResponseStream = oWebResponse.GetResponseStream())
                        {
                            AsyncContextReadOperation oAsyncContextReadOperation = new AsyncContextReadOperation(m_nMaxSize);
                            if (ErrorTypes.NoError == oAsyncContextReadOperation.ReadContext(oResponseStream))
                                aOutput = oAsyncContextReadOperation.m_aOutput.ToArray();
                            else
                                eError = ErrorTypes.WebRequest;
                        }
                    }
                    oWebResponse.Close();
                }
            }
            catch (Exception e)
            {
                _log.Error("Exception catched in Request:", e);
                eError = ErrorTypes.WebRequest;
            }
            return eError;
        }
Exemplo n.º 9
0
            public TransportClass(AsyncCallback fCallback, object oParam, string sUrl, string sMethod, string sContentType, byte[] aData, uint nAttemptCount, uint nAttemptDelay) 
            {
                m_fAsyncCallback = fCallback;
                m_oParam = oParam;
                m_sUrl = sUrl;
                m_sMethod = sMethod;
                m_sContentType = sContentType;
                m_aInput = aData;

                m_oTimer = null;
                m_oWebRequest = null;
                m_oHttpWebResponse = null;
                m_oStream = null;
                m_oAsyncContextReadOperation = null;

                m_aOutput = null;
                m_eError = ErrorTypes.NoError;

                m_nAttemptCount = nAttemptCount;
                m_nAttemptDelay = nAttemptDelay;
            }
Exemplo n.º 10
0
 public TransportClassContextRead(TransportClassMainAshx m_oTransportClassMainAshx, AsyncContextReadOperation oAsyncContextReadOperation)
     : base(m_oTransportClassMainAshx.m_oHttpContext, m_oTransportClassMainAshx.m_oAsyncCallback)
 {
     m_oAsyncContextReadOperation = oAsyncContextReadOperation;
 }
Exemplo n.º 11
0
        public ErrorTypes Request(string sUrl, string sMethod, string sContentType, byte[] aData, out byte[] aOutput)
        {
            ErrorTypes eError = ErrorTypes.NoError;

            aOutput = null;
            try
            {
                ServicePointManager.ServerCertificateValidationCallback = (s, c, h, p) => true;

                WebResponse oWebResponse  = null;
                int         nAttemptCount = 0;
                bool        bComplete     = false;
                while (!bComplete && nAttemptCount < m_nAttemptCount)
                {
                    eError = ErrorTypes.NoError;
                    try
                    {
                        HttpWebRequest oWebRequest = (HttpWebRequest)HttpWebRequest.Create(sUrl);
                        oWebRequest.UserAgent = Constants.mc_sWebClientUserAgent;
                        if (!string.IsNullOrEmpty(sMethod))
                        {
                            oWebRequest.Method = sMethod;
                        }
                        if ("POST" == oWebRequest.Method)
                        {
                            if (!string.IsNullOrEmpty(sContentType))
                            {
                                oWebRequest.ContentType = sContentType;
                            }
                            else
                            {
                                oWebRequest.ContentType = "text/plain";
                            }
                            if (null != aData)
                            {
                                oWebRequest.ContentLength = aData.Length;
                            }
                            using (Stream postStream = oWebRequest.GetRequestStream())
                            {
                                if (null != aData)
                                {
                                    postStream.Write(aData, 0, aData.Length);
                                }
                            }
                        }
                        oWebResponse = oWebRequest.GetResponse();
                        bComplete    = true;
                    }
                    catch (Exception e)
                    {
                        _log.Error("Exception catched in Request:", e);
                        eError = ErrorTypes.WebRequest;
                    }

                    nAttemptCount++;
                    if (!bComplete && nAttemptCount < m_nAttemptCount)
                    {
                        Thread.Sleep((int)m_nAttemptDelay);
                    }
                }
                if (null != oWebResponse)
                {
                    Int64 ContentLength = 0;
                    if (!Int64.TryParse(oWebResponse.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);
                        eError = ErrorTypes.WebRequest;
                    }
                    else
                    {
                        using (Stream oResponseStream = oWebResponse.GetResponseStream())
                        {
                            AsyncContextReadOperation oAsyncContextReadOperation = new AsyncContextReadOperation(m_nMaxSize);
                            if (ErrorTypes.NoError == oAsyncContextReadOperation.ReadContext(oResponseStream))
                            {
                                aOutput = oAsyncContextReadOperation.m_aOutput.ToArray();
                            }
                            else
                            {
                                eError = ErrorTypes.WebRequest;
                            }
                        }
                    }
                    oWebResponse.Close();
                }
            }
            catch (Exception e)
            {
                _log.Error("Exception catched in Request:", e);
                eError = ErrorTypes.WebRequest;
            }
            return(eError);
        }
Exemplo n.º 12
0
 public TransportClassContextRead(TransportClassMainAshx m_oTransportClassMainAshx, AsyncContextReadOperation oAsyncContextReadOperation)
     : base(m_oTransportClassMainAshx.m_oHttpContext, m_oTransportClassMainAshx.m_oAsyncCallback)
 {
     m_oAsyncContextReadOperation = oAsyncContextReadOperation;
 }
Exemplo n.º 13
0
 public TransportClass(HttpContext oContext, AsyncCallback oCallback, Storage oStorage, AsyncContextReadOperation oAsyncContextRead, string sPath, string sDeletePath, string sFilename)
 {
     m_oContext = oContext;
     m_oCallback = oCallback;
     m_oStorage = oStorage;
     m_oAsyncContextRead = oAsyncContextRead;
     m_sPath = sPath;
     m_sDeletePath = sDeletePath;
     m_sFilename = sFilename;
 }