public async Task <IActionResult> UploadEquipmentMediaAsync(DetailsViewModel model)
        {
            foreach (IFormFile file in model.UploadMedia.MediaFiles)
            {
                string blobName = $"{Guid.NewGuid()}_{file.FileName}";
                string uri      = await __BlobService.UploadFormFile(file, blobName);

                if (!string.IsNullOrWhiteSpace(uri))
                {
                    BlobResponse _BlobResponse = await __BlobManager.CreateAsync(new CreateBlobRequest
                    {
                        Name = blobName,
                        Path = uri
                    });

                    await __EquipmentBlobManager.CreateAsync(new CreateEquipmentBlobRequest
                    {
                        EquipmentUID = model.UploadMedia.EquipmentUID,
                        BlobUID      = _BlobResponse.UID
                    });
                }
            }

            return(Redirect(Request.Headers["Referer"].ToString()));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the page ranges impl.
        /// </summary>
        /// <param name="options">An object that specifies any additional options for the request.</param>
        /// <param name="setResult">The set result.</param>
        /// <returns>A <see cref="TaskSequence"/> for getting the page ranges.</returns>
        private TaskSequence GetPageRangesImpl(BlobRequestOptions options, Action <IEnumerable <PageRange> > setResult)
        {
            CommonUtils.AssertNotNull("options", options);

            var webRequest = ProtocolHelper.GetWebRequest(this.ServiceClient, options, (timeout) => BlobRequest.GetPageRanges(this.TransformedAddress, timeout, this.SnapshotTime, null));

            BlobRequest.AddMetadata(webRequest, this.Metadata);
            this.ServiceClient.Credentials.SignRequest(webRequest);
            var task = webRequest.GetResponseAsyncWithTimeout(this.ServiceClient, options.Timeout);

            yield return(task);

            using (var webResponse = task.Result as HttpWebResponse)
            {
                var getPageRangesResponse   = BlobResponse.GetPageRanges(webResponse);
                List <PageRange> pageRanges = new List <PageRange>();

                // materialize response as we need to close the webResponse
                pageRanges.AddRange(getPageRangesResponse.PageRanges.ToList());

                setResult(pageRanges);

                this.ParseSizeAndLastModified(webResponse);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Sets the content stream of the given Document instance ID
        /// </summary>
        /// <param name="blob">Information about the given blob</param>
        /// <returns>the newly created Blob instance</returns>
        public BlobResponse SetBlobStream(BlobMessage blob)
        {
            using (Logging.Facade.DebugTraceMethodCall("SetBlobStream"))
            {
                if (blob == null)
                {
                    throw new ArgumentNullException("blob");
                }
                try
                {
                    DebugLogIdentity();

                    using (IZetboxContext ctx = _ctxFactory())
                    {
                        var result = _sohFactory
                                     .GetServerDocumentHandler()
                                     .SetBlobStream(blob.Version, ctx, blob.Stream, blob.FileName, blob.MimeType);
                        BlobResponse resp = new BlobResponse();
                        resp.ID           = result.ID;
                        resp.BlobInstance = SendObjects(new IDataObject[] { result }, true);
                        return(resp);
                    }
                }
                catch (Exception ex)
                {
                    Helper.ThrowFaultException(ex);
                    // Never called, Handle errors throws an Exception
                    return(null);
                }
            }
        }
Ejemplo n.º 4
0
        public Zetbox.App.Base.Blob SetBlobStream(IZetboxContext ctx, Stream stream, string filename, string mimetype)
        {
            Zetbox.App.Base.Blob result   = null;
            BlobResponse         response = null;
            BlobMessage          msg      = new BlobMessage()
            {
                Version = ZetboxGeneratedVersionAttribute.Current, FileName = filename, MimeType = mimetype, Stream = stream
            };

            MakeRequest(() =>
            {
                // Rewind stream to ensure complete files, e.g. after a fault
                if (msg.Stream.Position != 0)
                {
                    msg.Stream.Seek(0, SeekOrigin.Begin);
                }
                response = _service.SetBlobStream(msg);
            });

            using (var sr = _readerFactory(new BinaryReader(response.BlobInstance)))
            {
                // ignore auxObjects for blobs, which should not have them
                result = ReceiveObjectList(ctx, sr).Cast <Zetbox.App.Base.Blob>().Single();
            }
            return(result);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Set the event handler.
        /// </summary>
        /// <param name="req">The request.</param>
        /// <param name="webResponse">The web response.</param>
        /// <param name="eventHandler">The event handler.</param>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The exception.</param>
        private static void OnResponseReceived(
            WebRequest req,
            WebResponse webResponse,
            EventHandler <ResponseReceivedEventArgs> eventHandler,
            object sender,
            Exception e)
        {
            // Get a Thread safe refence. May be not necessary given that its a function argument.
            EventHandler <ResponseReceivedEventArgs> temp = eventHandler;

            if (temp != null)
            {
                if (webResponse != null)
                {
                    HttpWebResponse response = webResponse as HttpWebResponse;

                    if (response != null)
                    {
                        string requestId = BlobResponse.GetRequestId(response);
                        var    eventArgs = new ResponseReceivedEventArgs()
                        {
                            RequestId         = requestId,
                            RequestHeaders    = req.Headers,
                            RequestUri        = req.RequestUri,
                            ResponseHeaders   = response.Headers,
                            StatusCode        = response.StatusCode,
                            StatusDescription = response.StatusDescription,
                            Exception         = e
                        };

                        temp(sender, eventArgs);
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public Zetbox.App.Base.Blob SetBlobStream(IZetboxContext ctx, Stream stream, string filename, string mimetype)
        {
            Zetbox.App.Base.Blob result = null;
            var handler    = _memoryFactory.GetServerDocumentHandler();
            var serverBlob = handler.SetBlobStream(ZetboxGeneratedVersionAttribute.Current, _backingStore, stream, filename, mimetype);

            BlobResponse resp = new BlobResponse();

            resp.ID           = serverBlob.ID;
            resp.BlobInstance = SendObjects(new IDataObject[] { serverBlob }, true);

            using (var sr = new ZetboxStreamReader(_map, new BinaryReader(resp.BlobInstance)))
            {
                result = ReceiveObjectList(ctx, sr).Cast <Zetbox.App.Base.Blob>().Single();
            }
            return(result);
        }
Ejemplo n.º 7
0
        private async Task UploadEquipmentMediaAsync(IFormFile file, Guid equipmentUID)
        {
            string blobName = $"{Guid.NewGuid()}_{file.FileName}";
            string uri      = await __BlobService.UploadFormFile(file, blobName);

            if (!string.IsNullOrWhiteSpace(uri))
            {
                BlobResponse _BlobResponse = await __BlobManager.CreateAsync(new CreateBlobRequest
                {
                    Name = blobName,
                    Path = uri
                });

                await __EquipmentBlobManager.CreateAsync(new CreateEquipmentBlobRequest
                {
                    EquipmentUID = equipmentUID,
                    BlobUID      = _BlobResponse.UID
                });
            }
        }