Ejemplo n.º 1
0
        private Stream UploadDataAsync(Common.Solution solution, Stream messageBody, bool checkExisting)
        {
            try
            {
                String contentEncoding = WebOperationContext.Current.IncomingRequest.Headers[HttpRequestHeader.ContentEncoding];
                Guid   sessionGuid     = Guid.NewGuid();

                //save file
                string filepath = Path.Combine(System.IO.Path.GetTempPath(), sessionGuid.ToString());
                using (FileStream fs = System.IO.File.OpenWrite(filepath))
                {
                    messageBody.CopyTo(fs);
                    fs.Flush();
                }

                try
                {
                    //try to create session
                    CreateAyncUploadRecord(solution, sessionGuid);
                }
                catch
                {
                    try
                    {
                        System.IO.File.Delete(filepath);
                    }
                    catch
                    {
                    }
                    throw;
                }

                AsyncUploadThread t = new AsyncUploadThread(this, sessionGuid, solution, null, checkExisting, !String.IsNullOrEmpty(contentEncoding), contentEncoding, filepath);
                t.Start();
                if (t.IsStarted())
                {
                    return(Common.Utils.MakeTextAnswer(String.Format("{0}", sessionGuid.ToString())));
                }
                else
                {
                    //t.Terminate();
                    return(Common.Utils.MakeTextAnswer("Unable to start async upload session"));
                }
            }
            catch (Exception e)
            {
                return(Common.Utils.MakeExceptionAnswer(e, solution.Name));
            }
        }
Ejemplo n.º 2
0
        private Stream UploadDataAsync(Common.Solution solution, Stream messageBody, bool checkExisting)
        {
            try
            {
                String contentEncoding = WebOperationContext.Current.IncomingRequest.Headers[HttpRequestHeader.ContentEncoding];
                Guid sessionGuid = Guid.NewGuid();

                //save file
                string filepath = Path.Combine(System.IO.Path.GetTempPath(), sessionGuid.ToString());
                using (FileStream fs = System.IO.File.OpenWrite(filepath))
                {
                    messageBody.CopyTo(fs);
                    fs.Flush();
                }

                try
                {
                    //try to create session
                    CreateAyncUploadRecord(solution, sessionGuid);
                }
                catch
                {
                    try
                    {
                        System.IO.File.Delete(filepath);
                    }
                    catch
                    {
                    }
                    throw;
                }

                AsyncUploadThread t = new AsyncUploadThread(this,sessionGuid,solution,null,checkExisting, !String.IsNullOrEmpty(contentEncoding), contentEncoding, filepath);
                t.Start();
                if (t.IsStarted())
                    return Common.Utils.MakeTextAnswer(String.Format("{0}", sessionGuid.ToString()));
                else
                {
                    //t.Terminate();
                    return Common.Utils.MakeTextAnswer("Unable to start async upload session");
                }
            }
            catch (Exception e)
            {
                return Common.Utils.MakeExceptionAnswer(e, solution.Name);
            }
        }