示例#1
0
        public IReceiveResult EndReceive(IAsyncResult asyncResult)
        {
            if (!asyncResult.IsCompleted)
            {
                return(null);
            }
            else
            {
                FileReceiveResult result = asyncResults[asyncResult];
                // Delete this file
                if (!keepFiles)
                {
                    try
                    {
                        System.IO.File.Delete(result.FileName);
                    }
                    catch (Exception)
                    {
                    }
                }

                lock (asyncResults) { asyncResults.Remove(asyncResult); }
                return(result);
            }
        }
示例#2
0
            public void Work(object state)
            {
                // Prepare stream
                Stream            s      = null;
                FileReceiveResult result = new FileReceiveResult();

                result.FileName = state.ToString(); // reference filename
                IFormatterParseResult pResult = null;

                // parse the object
                try
                {
                    s = new FileStream(state.ToString(), FileMode.Open, FileAccess.Read, FileShare.Write);

                    // Parse the object
                    pResult          = Formatter.Parse(s);
                    result.Structure = pResult.Structure;
                    result.Details   = pResult.Details;
                    result.Code      = ResultCode.Accepted;
                    if (result.Details.FirstOrDefault(o => o.Type == ResultDetailType.Error) != null)
                    {
                        result.Code = ResultCode.AcceptedNonConformant;
                    }
                    else if (result.Structure == null)
                    {
                        result.Code = ResultCode.TypeNotAvailable;
                    }
                }
                catch (MessageValidationException e)
                {
                    result.Code = ResultCode.Rejected;
                    List <IResultDetail> dtl = new List <IResultDetail>(new IResultDetail[] { new FileResultDetail(ResultDetailType.Error, e.Message, state.ToString(), e) });
                    dtl.AddRange(pResult.Details ?? new IResultDetail[0]);
                    result.Details = dtl.ToArray();
                }
                catch (FormatException e)
                {
                    result.Code    = ResultCode.Rejected;
                    result.Details = new IResultDetail[] { new FileResultDetail(ResultDetailType.Error, e.Message, state.ToString(), e) };
                }
                catch (DirectoryNotFoundException e)
                {
                    result.Code    = ResultCode.NotAvailable;
                    result.Details = new IResultDetail[] { new FileResultDetail(ResultDetailType.Error, e.Message, state.ToString(), e) };
                }
                catch (IOException)
                {
                    retryCount++;
                    if (retryCount < MAX_RETRY_COUNT)
                    {
                        Work(state);
                    }
                    return;
                }
                catch (Exception e)
                {
                    result.Code    = ResultCode.Error;
                    result.Details = new IResultDetail[] { new FileResultDetail(ResultDetailType.Error, e.Message, state.ToString(), e) };
                }
                finally
                {
                    if (s != null)
                    {
                        s.Close();
                    }
                }

                // Set the result
                this.Result = result;

                // Fire completed event
                if (Completed != null)
                {
                    Completed(this);
                }
            }
示例#3
0
            public void Work(object state)
            {
                // Prepare stream
                Stream s = null;
                FileReceiveResult result = new FileReceiveResult();
                result.FileName = state.ToString(); // reference filename
                IFormatterParseResult pResult = null;

                // parse the object
                try
                {
                    s = new FileStream(state.ToString(), FileMode.Open, FileAccess.Read, FileShare.Write);

                    // Parse the object
                    pResult = Formatter.Parse(s);
                    result.Structure = pResult.Structure;
                    result.Details = pResult.Details;
                    result.Code = ResultCode.Accepted;
                    if (result.Details.FirstOrDefault(o => o.Type == ResultDetailType.Error) != null)
                        result.Code = ResultCode.AcceptedNonConformant;
                    else if (result.Structure == null)
                        result.Code = ResultCode.TypeNotAvailable;
                }
                catch (MessageValidationException e)
                {
                    result.Code = ResultCode.Rejected;
                    List<IResultDetail> dtl = new List<IResultDetail>(new IResultDetail[] { new FileResultDetail(ResultDetailType.Error, e.Message, state.ToString(), e) });
                    dtl.AddRange(pResult.Details ?? new IResultDetail[0]);
                    result.Details = dtl.ToArray();
                }
                catch (FormatException e)
                {
                    result.Code = ResultCode.Rejected;
                    result.Details = new IResultDetail[] { new FileResultDetail(ResultDetailType.Error, e.Message, state.ToString(), e) };
                }
                catch (DirectoryNotFoundException e)
                {
                    result.Code = ResultCode.NotAvailable;
                    result.Details = new IResultDetail[] { new FileResultDetail(ResultDetailType.Error, e.Message, state.ToString(), e) };
                }
                catch (IOException)
                {
                    retryCount++;
                    if(retryCount < MAX_RETRY_COUNT)
                        Work(state);
                    return;
                }
                catch (Exception e)
                {
                    result.Code = ResultCode.Error;
                    result.Details = new IResultDetail[] { new FileResultDetail(ResultDetailType.Error, e.Message, state.ToString(), e) };
                }
                finally
                {
                    if (s != null) s.Close();
                }

                // Set the result
                this.Result = result;

                // Fire completed event
                if (Completed != null) Completed(this);

            }