Esempio n. 1
0
 public static void GetStreamMIMEType(SessionHandler oSessionHndlr, Byte[] buffer, bool isRequest)
 {
     if (buffer.Length > 0)
     {
         if (isRequest)
         {
             oSessionHndlr.UploadStream.MIME_DLL       = MIMEIdentifier.FileMIME.GetMimeFromBytes(buffer);
             oSessionHndlr.UploadStream.MIME_Signature = MIMEIdentifier.FileMIMESignature.GetMimeType(buffer);
         }
         else
         {
             byte[] tempBuffer = buffer;
             if (oSessionHndlr.ResponseLines.ContainsKey("CONTENT-ENCODING"))
             {
                 switch (oSessionHndlr.ResponseLines["CONTENT-ENCODING"])
                 {
                 case "gzip":
                     tempBuffer = Decompressor.DecompressGzip(new MemoryStream(tempBuffer), Encoding.Default);
                     break;
                 }
             }
             oSessionHndlr.DownloadStream.MIME_DLL       = MIMEIdentifier.FileMIME.GetMimeFromBytes(buffer);
             oSessionHndlr.DownloadStream.MIME_Signature = MIMEIdentifier.FileMIMESignature.GetMimeType(buffer);
         }
     }
 }
Esempio n. 2
0
        public static void WriteToFile(SessionHandler oSessionHndlr, Byte[] buffer, bool isUpload)
        {
            byte[] tempBuffer = buffer;
            if (!isUpload)
            {
                if (oSessionHndlr.ResponseLines.ContainsKey("CONTENT-ENCODING"))
                {
                    switch (oSessionHndlr.ResponseLines["CONTENT-ENCODING"])
                    {
                    case "gzip":
                        tempBuffer = Decompressor.DecompressGzip(new MemoryStream(tempBuffer), Encoding.Default);
                        break;
                    }
                }
            }

            if (oSessionHndlr.FileName != null)
            {
                try
                {
                    FileStream tempFilsStream = new FileStream(oSessionHndlr.FileName, FileMode.Create);
                    tempFilsStream.Write(tempBuffer, 0, tempBuffer.Length);
                    tempFilsStream.Close();
                }
                catch (Exception ex)
                {
                    Debug.Write(ex.Message + " " + ex.StackTrace);
                }
            }

            if (oSessionHndlr.FileName == null || oSessionHndlr.FileName == string.Empty)
            {
                return;
            }

            string tempData = Convert.ToBase64String(tempBuffer);
            // if (LazyAnalyser.DataPacketsDB != null)
            {
                //if (isUpload)
                //{
                //    DBAnalyser.DataPacketsDB.InsertInUploads(oSessionHndlr.StartedDateTime.ToString(ConstantVariables.DATETIMEFORMAT),
                //                            oSessionHndlr.RequestURL,
                //                            0,
                //                             oSessionHndlr.FileMIMETypeDLL,
                //                            oSessionHndlr.RequestRawData.Length,
                //                            tempData,
                //                             string.Empty,
                //                            oSessionHndlr.ClientID,
                //                            oSessionHndlr.ClientName,
                //                            string.Empty);
                //}
                //else
                //{
                //    DBAnalyser.DataPacketsDB.InsertInDowloads(oSessionHndlr.StartedDateTime.ToString(ConstantVariables.DATETIMEFORMAT),
                //                                            oSessionHndlr.RequestURL,
                //                                            0,
                //                                            oSessionHndlr.FileMIMETypeDLL,
                //                                            oSessionHndlr.ResponseRawData.Length,
                //                                           tempData,
                //                                             string.Empty,
                //                                            oSessionHndlr.ClientID,
                //                                            oSessionHndlr.ClientName,
                //                                            string.Empty);
                //}
            }
        }