/// <summary>
        /// Add a file to the upload request
        /// </summary>
        /// <param name="id">Aras ID of the file</param>
        /// <param name="path">Path (or pseudo path) of the file</param>
        /// <param name="data">Stream of data representing the file</param>
        /// <param name="isNew">Is this a new file being added to the database for the first time?</param>
        /// <param name="calcChecksum">Whether to buffer the stream for the purposes of calculating a checksum</param>
        /// <returns>AML file string useful for building a larger AML statement</returns>
        public string AddFile(string id, string path, Stream data, bool isNew = true, bool calcChecksum = true)
        {
            var file = new CommandFile(id, path, data, Vault.Id, isNew, calcChecksum);

            _files.Add(file);
            return(file.Aml);
        }
Example #2
0
        public override IPromise <string> UploadFile(string id, string path, Stream data, bool async)
        {
            var file = new CommandFile(id, path, data, Vault.Id);

            Files.Add(file);
            file.UploadPromise = UploadFile(file, async);
            return(file.UploadPromise.Convert(s => file.Aml));
        }
        private IPromise <Stream> UploadFile(CommandFile file, bool async)
        {
            return(BeginTransaction(async)
                   .Continue(t =>
            {
                var chain = Promises.Resolved(default(IHttpResponse));

                foreach (var content in file.AsContent(this, _conn.AmlContext.LocalizationContext, false))
                {
                    chain = chain.Continue(_ => {
                        var req = new HttpRequest()
                        {
                            Content = content
                        };
                        req.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/octet-stream");
                        _conn.SetDefaultHeaders(req.SetHeader);

                        foreach (var a in _conn.DefaultSettings)
                        {
                            a.Invoke(req);
                        }
                        Settings?.Invoke(req);
                        req.SetHeader("SOAPAction", "UploadFile");
                        req.SetHeader("VAULTID", Vault.Id);
                        req.SetHeader("transactionid", t);

                        var trace = new LogData(4
                                                , "Innovator: Upload File"
                                                , LogListener ?? Factory.LogListener)
                        {
                            { "aras_url", _conn.MapClientUrl("../../Server") },
                            { "database", _conn.Database },
                            { "soap_action", "UploadFile" },
                            { "url", Vault.Url },
                            { "user_id", _conn.UserId },
                            { "vault_id", Vault.Id },
                            { "version", _conn.Version }
                        };
                        var uri = new Uri(Vault.Url + "?fileId=" + file.Id);
                        return Vault.HttpClient
                        .PostPromise(uri, async, req, trace)
                        .Always(trace.Dispose)
                        .Always(req.Dispose);
                    });
                }

                return chain;
            })
                   .Convert(r => r.AsStream));
        }
Example #4
0
 /// <summary>
 /// Add a file to the upload request
 /// </summary>
 /// <param name="id">Aras ID of the file</param>
 /// <param name="path">Path (or pseudo path) of the file</param>
 /// <param name="data">Stream of data representing the file</param>
 /// <param name="isNew">Is this a new file being added to the database for the first time?</param>
 /// <returns>AML file string useful for building a larger AML statement</returns>
 public string AddFile(string id, string path, Stream data, bool isNew = true)
 {
   var file = new CommandFile(id, path, data, _vault.Id, isNew);
   _files.Add(file);
   return file.Aml;
 }