/// <summary> /// Fetches the version from the database if it is not already known. /// </summary> /// <param name="conn">The connection to fetch the version for</param> /// <param name="async">Whether to fetch the version asynchronously</param> /// <returns>A promise to return the version of the Aras installation.</returns> public static IPromise <Version> FetchVersion(this IAsyncConnection conn, bool async) { if (!(conn is Connection.IArasConnection arasConn)) { return(Promises.Resolved(default(Version))); } var version = arasConn.Version; if (version != default(Version)) { return(Promises.Resolved(version)); } return(conn.ApplyAsync(@"<Item type='Variable' action='get' select='name,value'> <name condition='like'>Version*</name> </Item>", async, false) .Convert(res => { var dict = res.Items() .GroupBy(i => i.Property("name").AsString("")) .ToDictionary(g => g.Key, g => g.First().Property("value").Value); var major = 0; var minor = 0; var servicePack = 0; var build = 0; // int.TryParse will default to 0 on a failure // Always set a version with the pieces even if the version doesn't make sense so that we don't repeat retrieval var _ = dict.TryGetValue("VersionMajor", out string majorStr) && int.TryParse(majorStr, out major); _ = dict.TryGetValue("VersionMinor", out string minorStr) && int.TryParse(minorStr, out minor); _ = dict.TryGetValue("VersionServicePack", out string servicePackStr) && int.TryParse(servicePackStr.TrimStart('S', 'P'), out servicePack); _ = dict.TryGetValue("VersionBuild", out string buildStr) && int.TryParse(buildStr, out build); version = new Version(major, minor, servicePack, build); arasConn.Version = version; return version; })); }
public override IPromise <Stream> Rollback(bool async) { if (Status == UploadStatus.RolledBack) { return(_lastPromise); } Status = UploadStatus.RolledBack; _lastPromise = Promises.All(Files .Where(f => f.UploadPromise != null) .Select(f => f.UploadPromise.Continue(s => { var result = _conn.AmlContext.FromXml(s); if (result.Exception != null) { return(Promises.Resolved((Stream) new MemoryStream())); } return(_conn.Process(new Command("<Item type='File' action='delete' id='@0' />", f.Id), async)); })).ToArray()) .Convert(l => l.OfType <Stream>().FirstOrDefault() ?? new MemoryStream()); return(_lastPromise); }
private IPromise <TokenCredentials> ValidCredentials(bool async) { if (_tokenCreds == null) { _tokenCreds = GetCredentials(async); return(_tokenCreds); } else { return(_tokenCreds.Continue(c => { if (c.Expires <= DateTime.UtcNow) { _tokenCreds = GetCredentials(async); return _tokenCreds; } else { return Promises.Resolved(c); } })); } }
public IPromise <ExplicitHashCredentials> HashCredentials(ICredentials credentials, bool async) { return(Promises.Resolved(HashCredentials(credentials))); }
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); }
/// <summary> /// Hashes the credentials for use with logging in or workflow voting /// </summary> /// <param name="credentials">The credentials.</param> /// <param name="async">Whether to perform this action asynchronously</param> /// <returns> /// A promise to return hashed credentials /// </returns> public IPromise <ExplicitHashCredentials> HashCredentials(ICredentials credentials, bool async) { var explicitCred = credentials as ExplicitCredentials; var hashCred = credentials as ExplicitHashCredentials; var winCred = credentials as WindowsCredentials; if (explicitCred != null) { return(Promises.Resolved(new ExplicitHashCredentials(explicitCred.Database, explicitCred.Username, _hashFunc(explicitCred.Password)))); } else if (hashCred != null) { return(Promises.Resolved(hashCred)); } else if (winCred != null) { var waLoginUrl = new Uri(this._innovatorClientBin, "../scripts/IOMLogin.aspx"); var handler = new SyncClientHandler() { Credentials = winCred.Credentials, PreAuthenticate = true }; var http = new SyncHttpClient(handler); var req = new HttpRequest() { Content = new SimpleContent("<?xml version=\"1.0\" encoding=\"utf-8\" ?><Item />", "text/xml") }; var context = ElementFactory.Local.LocalizationContext; req.SetHeader("DATABASE", winCred.Database); req.SetHeader("LOCALE", context.Locale); req.SetHeader("TIMEZONE_NAME", context.TimeZone); return(http.PostPromise(waLoginUrl, async, req, new LogData(4 , "Innovator: Execute query" , Factory.LogListener) { { "database", winCred.Database }, { "url", waLoginUrl }, }).Convert(r => { var res = r.AsXml().DescendantsAndSelf("Result").FirstOrDefault(); var username = res.Element("user").Value; var pwd = res.Element("password").Value; if (pwd.IsNullOrWhiteSpace()) { throw new ArgumentException("Failed to authenticate with Innovator server '" + _innovatorClientBin, "credentials"); } var needHash = res.Element("hash").Value; var password = default(string); if (string.Equals(needHash.Trim(), "false", StringComparison.OrdinalIgnoreCase)) { password = pwd; } else { password = _hashFunc(pwd); } return new ExplicitHashCredentials(winCred.Database, username, password); })); } else { throw new NotSupportedException("This connection implementation does not support the specified credential type"); } }