示例#1
0
        private bool TryReturnFile(HttpListenerResponse response, string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                return(false);
            }

            if (string.IsNullOrEmpty(_rootFileDirectory))
            {
                return(false);
            }

            var filePath = path.Remove(0, 1).Replace('/', '\\');
            var fullPath = Path.Combine(_rootFileDirectory, filePath);

            if (!File.Exists(fullPath))
            {
                return(false);
            }

            response.ContentType = GetContentType(fullPath);

            using (Stream instream = File.OpenRead(fullPath))
            {
                StreamUtil.CopyStream(instream, response.OutputStream);
            }

            return(true);
        }
示例#2
0
 public override void Save(FilePath filePath)
 {
     using (var stream = new FileStream(filePath.FullPath, FileMode.CreateNew, FileAccess.Write, FileShare.None))
     {
         _stream.Position = 0;
         StreamUtil.CopyStream(_stream, stream);
     }
 }
示例#3
0
        private static void Save(TestResume resume)
        {
            var data     = resume.GetData();
            var filePath = FileSystem.GetAbsolutePath(@"Test\Data\Resumes\" + resume.FileName, RuntimeEnvironment.GetSourceFolder());

            using (var stream = new MemoryStream(data))
            {
                stream.Position = 0;
                using (var fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None))
                {
                    StreamUtil.CopyStream(stream, fileStream);
                }
            }
        }
示例#4
0
        private static void BounceEmail(string fileName)
        {
            var request = (HttpWebRequest)WebRequest.Create(EmailStatusUrl);

            request.Method      = "POST";
            request.UserAgent   = "Mozilla/4.0 (compatible; MSIE 6.0)";
            request.ContentType = "text/plain";

            using (var fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read))
            {
                using (var requestStream = request.GetRequestStream())
                {
                    StreamUtil.CopyStream(fileStream, requestStream);
                }
            }

            request.GetResponse();
        }
示例#5
0
        private static HttpStatusCode PostFile(string fileName)
        {
            var request = (HttpWebRequest)WebRequest.Create(BaseUrl);

            request.Method      = "POST";
            request.UserAgent   = "Mozilla/4.0 (compatible; MSIE 6.0)";
            request.ContentType = "text/plain";

            using (var fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read))
            {
                using (var requestStream = request.GetRequestStream())
                {
                    StreamUtil.CopyStream(fileStream, requestStream);
                }
            }

            var response = (HttpWebResponse)request.GetResponse();

            return(response.StatusCode);
        }
示例#6
0
        public void CopyOutputStreamTo(Stream toSteam)
        {
            var fromStream = new MemoryStream(_outputStream.ToArray());

            StreamUtil.CopyStream(fromStream, toSteam);
        }
示例#7
0
        public void OnEnteredStateImpl()
        {
            FileStream stream           = new FileStream(this.extractMe, FileMode.Open, FileAccess.Read, FileShare.Read);
            FileStream underlyingStream = null;

            try
            {
                using (ZipArchive archive = new ZipArchive(stream, ZipArchiveMode.Read, true))
                {
                    ZipArchiveEntry entry = archive.Entries.FirstOrDefault <ZipArchiveEntry>(ze => string.Compare(".exe", Path.GetExtension(ze.Name), true, CultureInfo.InvariantCulture) == 0);
                    if (entry == null)
                    {
                        this.exception = new FileNotFoundException();
                        base.StateMachine.QueueInput(PrivateInput.GoToError);
                    }
                    else
                    {
                        int maxBytes   = (int)entry.Length;
                        int bytesSoFar = 0;
                        this.installerPath = Path.Combine(Path.GetDirectoryName(this.extractMe), entry.Name);
                        underlyingStream   = new FileStream(this.installerPath, FileMode.Create, FileAccess.Write, FileShare.Read);
                        SiphonStream output = new SiphonStream(underlyingStream, 0x1000);
                        this.abortMeStream = output;
                        IOEventHandler handler = delegate(object sender, IOEventArgs e) {
                            bytesSoFar += e.Count;
                            double percent = 100.0 * (((double)bytesSoFar) / ((double)maxBytes));
                            this.OnProgress(percent);
                        };
                        base.OnProgress(0.0);
                        if (maxBytes > 0)
                        {
                            output.IOFinished += handler;
                        }
                        using (Stream stream4 = entry.Open())
                        {
                            StreamUtil.CopyStream(stream4, output);
                        }
                        if (maxBytes > 0)
                        {
                            output.IOFinished -= handler;
                        }
                        this.abortMeStream = null;
                        output             = null;
                        underlyingStream.Close();
                        underlyingStream = null;
                        base.StateMachine.QueueInput(PrivateInput.GoToReadyToInstall);
                    }
                }
            }
            catch (Exception exception)
            {
                if (base.AbortRequested)
                {
                    base.StateMachine.QueueInput(PrivateInput.GoToAborted);
                }
                else
                {
                    this.exception = exception;
                    base.StateMachine.QueueInput(PrivateInput.GoToError);
                }
            }
            finally
            {
                if (underlyingStream != null)
                {
                    underlyingStream.Close();
                    underlyingStream = null;
                }
                if (stream != null)
                {
                    stream.Close();
                    stream = null;
                }
                if (((this.exception != null) || base.AbortRequested) && (this.installerPath != null))
                {
                    bool flag = FileSystem.TryDeleteFile(this.installerPath);
                }
                if (this.extractMe != null)
                {
                    bool flag2 = FileSystem.TryDeleteFile(this.extractMe);
                }
            }
        }
示例#8
0
        void IEmailStatusService.AddNotification(Stream httpStream)
        {
            const string method = "AddNotification";

            try
            {
                SetHttpStatusCode(HttpStatusCode.NoContent);

                // Parse top-level message.

                var memoryStream = new MemoryStream();
                StreamUtil.CopyStream(httpStream, memoryStream); // CDO will need random access to the stream

                var rootMessage = new MessageClass();
                rootMessage.OpenObject(new ReadOnlyIStream(memoryStream), "IStream");
                if (rootMessage.ContentMediaType == "test/octet-stream")
                {
                    SetHttpStatusCode(HttpStatusCode.Accepted); // just testing
                    return;
                }

                var deliveryStatusPart = GetDeliveryStatusPart(rootMessage);
                if (deliveryStatusPart == null)
                {
                    return;
                }

                // Analyze message/delivery-status.

                var mtaMessage       = GetInnerMessage(deliveryStatusPart);
                var recipientMessage = GetInnerMessage(mtaMessage);
                var recipientField   = (string)recipientMessage.Fields["urn:schemas:mailheader:final-recipient"].Value;
                if (recipientField == null)
                {
                    #region Log
                    Log(Event.Warning, method, "Final-Recipient field is missing. Notofication ignored.", null, rootMessage);
                    #endregion
                    return;
                }

                var emailAddress = GetEmailAddress(recipientField);
                if (string.IsNullOrEmpty(emailAddress))
                {
                    #region Log
                    Log(Event.Warning, method, "Final-Recipient is invalid. Notification ignored.", null, rootMessage, Event.Arg("Final-Recipient", recipientField));
                    #endregion
                    return;
                }

                var statusField = (string)recipientMessage.Fields["urn:schemas:mailheader:status"].Value;
                if (statusField == null)
                {
                    #region Log
                    Log(Event.Warning, method, "Status field is missing. Notification ignored.", null, rootMessage);
                    #endregion
                    return;
                }

                if (GetStatusClass(statusField) != "5")
                {
                    #region Log
                    Log(Event.Trace, method, "Not a permanent error. Notification ignored.", null, rootMessage, Event.Arg("Status", statusField));
                    #endregion
                    return;
                }

                var diagnosticField = (string)recipientMessage.Fields["urn:schemas:mailheader:diagnostic-code"].Value;
                if (diagnosticField == null)
                {
                    #region Log
                    Log(Event.Information, method, "Diagnostic-Code field is missing. Notification will be processed.", null, rootMessage);
                    #endregion
                }
                else
                {
                    var replyCode = GetReplyCode(diagnosticField);
                    if (replyCode == null)
                    {
                        #region Log
                        Log(Event.Warning, method, "Unable to interpret the Diagnostic-Code field. Notification will be processed.", null, rootMessage, Event.Arg("Diagnostic-Code", diagnosticField));
                        #endregion
                    }
                    else if (TransientReplyCodes.Contains(replyCode.Value))
                    {
                        // Yahoo uses transient codes for permanent errors
                        if (!emailAddress.Contains(Yahoo))
                        {
                            #region Log
                            Log(Event.Information, method, "Reply code indicates transient condition. Notification ignored.", null, rootMessage, Event.Arg("Diagnostic-Code", diagnosticField));
                            #endregion

                            return;
                        }
                    }
                }

                // Update member record.

                #region Log
                Log(Event.Information, method, "Setting EmailBounced flag for the user.", null, rootMessage,
                    Event.Arg("emailAddress", emailAddress), Event.Arg("diagnosticField", diagnosticField));
                #endregion

                _emailVerificationsCommand.UnverifyEmailAddress(emailAddress, diagnosticField);
            }
            catch (Exception e)
            {
                Logger.Raise(Event.Error, method, "Unexpected exception.", e, new StandardErrorHandler());
                throw;
            }
        }