Пример #1
0
        public override IPromise <Stream> Commit(bool async)
        {
            if (Status != UploadStatus.Pending)
            {
                return(_lastPromise);
            }

            Status = UploadStatus.Committed;
            // No transaction has been started
            if (_transactionId == null && !Files.Any(f => f.UploadPromise != null))
            {
                _lastPromise = UploadAndApply(async);
            }
            else
            {
                var transactionId = default(string);
                _lastPromise = BeginTransaction(async)
                               .Continue(t =>
                {
                    transactionId = t;
                    return(Promises.All(Files
                                        .Select(f => f.UploadPromise ?? UploadFile(f, async))
                                        .ToArray()));
                })
                               .Continue(l =>
                {
                    var aml     = this.ToNormalizedAml(_conn.AmlContext.LocalizationContext);
                    var content = new FormContent
                    {
                        {
                            "XMLData",
                            "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:i18n=\"http://www.aras.com/I18N\"><SOAP-ENV:Body><ApplyItem>"
                            + aml
                            + "</ApplyItem></SOAP-ENV:Body></SOAP-ENV:Envelope>"
                        }
                    };

                    var req = new HttpRequest()
                    {
                        Content = content
                    };
                    _conn.SetDefaultHeaders(req.SetHeader);
                    foreach (var ac in _conn.DefaultSettings)
                    {
                        ac.Invoke(req);
                    }
                    Settings?.Invoke(req);
                    req.SetHeader("SOAPAction", "CommitTransaction");
                    req.SetHeader("VAULTID", Vault.Id);
                    req.SetHeader("transactionid", transactionId);

                    var trace = new LogData(4
                                            , "Innovator: Execute vault query"
                                            , LogListener ?? Factory.LogListener
                                            , Parameters)
                    {
                        { "aras_url", _conn.MapClientUrl("../../Server") },
                        { "database", _conn.Database },
                        { "query", aml },
                        { "soap_action", "CommitTransaction" },
                        { "url", Vault.Url },
                        { "user_id", _conn.UserId },
                        { "vault_id", Vault.Id },
                        { "version", _conn.Version }
                    };
                    return(Vault.HttpClient.PostPromise(new Uri(Vault.Url), async, req, trace).Always(trace.Dispose));
                })
                               .Convert(r => r.AsStream);
            }
            return(_lastPromise);
        }
Пример #2
0
        /// <summary>
        /// Uploads the files and applies the AML in a single transaction
        /// </summary>
        /// <param name="async">Whether to perform this action asynchronously</param>
        /// <returns>A promise to return an XML SOAP response as a <see cref="System.IO.Stream"/></returns>
        internal IPromise <Stream> UploadAndApply(string soapAction, string aml, IEnumerable <CommandFile> files, bool async)
        {
            return(_conn.FetchVersion(async).Continue(v =>
            {
                return Vault.TransformUrl(_conn, async).Continue(u =>
                {
                    // Compile the headers and AML query into the appropriate content
                    HttpRequest req;
                    var content = new FormContent
                    {
                        {
                            "XMLdata",
                            "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:i18n=\"http://www.aras.com/I18N\"><SOAP-ENV:Body><ApplyItem>" +
                            aml +
                            "</ApplyItem></SOAP-ENV:Body></SOAP-ENV:Envelope>"
                        }
                    };
                    foreach (var file in files)
                    {
                        content.Add(file.AsContent(this, _conn.AmlContext.LocalizationContext, true).Single());
                    }
                    content.Compression = _conn.Compression;
                    if (_conn.Version >= new Version(12, 0, 9))
                    {
                        req = GetUploadRequest12sp09(content, soapAction);
                    }
                    else
                    {
                        req = GetUploadRequestLegacy(content, soapAction);
                    }
                    foreach (var ac in _conn.DefaultSettings)
                    {
                        ac.Invoke(req);
                    }
                    Settings?.Invoke(req);

                    req.Headers.TransferEncodingChunked = true;

                    var trace = new LogData(4
                                            , "Innovator: Execute query"
                                            , LogListener ?? Factory.LogListener
                                            , Parameters)
                    {
                        { "aras_url", _conn.MapClientUrl("../../Server") },
                        { "database", _conn.Database },
                        { "query", aml },
                        { "soap_action", soapAction },
                        { "url", Vault.Url },
                        { "user_id", _conn.UserId },
                        { "vault_id", Vault.Id },
                        { "version", _conn.Version }
                    };
                    _conn.SetDefaultHeaders((name, value) =>
                    {
                        if (string.Equals(name, "LOCALE", StringComparison.OrdinalIgnoreCase) ||
                            string.Equals(name, "TIMEZONE_NAME", StringComparison.OrdinalIgnoreCase))
                        {
                            trace.Add(name.ToLowerInvariant(), value);
                        }
                    });
                    return Vault.HttpClient
                    .PostPromise(new Uri(Vault.Url), async, req, trace)
                    .Always(trace.Dispose)
                    .Always(req.Dispose);
                }).Convert(r => r.AsStream);
            }));
        }