public override object Resolve(ResolutionInfo resolutionInfo) { if (this.resolverDelegate != null) return this.resolverDelegate(resolutionInfo); lock (this.syncObject) { if (this.resolverDelegate != null) return this.resolverDelegate(resolutionInfo); var parameter = Expression.Parameter(typeof(ResolutionInfo)); this.resolverDelegate = Expression.Lambda<ResolverDelegate>(this.GetExpression(resolutionInfo, parameter), parameter).Compile(); } return this.resolverDelegate(resolutionInfo); }
static AutomationElement ResolveWithTimeout(ResolverDelegate resolver, IntPtr context, int timeoutMS) { // resolve with timeout DateTime methodCalledTime = DateTime.Now; while (true) { // try to get the element AutomationElement target = resolver(context); if (target != null) { return(target); } // timeout? TimeSpan ellapsed = DateTime.Now - methodCalledTime; if (ellapsed.TotalMilliseconds > timeoutMS) { // timeout return(null); } } }
/// <summary> /// Returns resolver from the _delegates as REsolverDelegate, ready to use or if it is not present there it furst searches for it and creates it /// from one of the registered ParameterResolverSet-s. /// </summary> /// <param name="name">The alias of the method or the full name under which it is egistered - see the class notes for details on naming.</param> /// <returns></returns> public ResolverDelegate <ParameterResolverValue, IParameterResolverContext> GetResolver(string name) { if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentException("name cannot be empty or null, It is expected to have the form: [<prefix>.]<resolvername>"); } if (_delegates.ContainsKey(name)) { return(_delegates[name]); } // We have to find it string[] parts = name.Split('.'); string prefix = null; string setname = null; string alias = null; if (parts.Length == 1) { alias = parts[0].Trim(); } else if (parts.Length == 2) { prefix = parts[0].Trim(); alias = parts[1].Trim(); } else if (parts.Length == 3) { if (!FullChainNaming) { // TODO: Error reporting - this cannot be correct // If the manager had this set previously all resolved names under fullName policy will be in the cache. return(null); } prefix = parts[0].Trim(); setname = parts[1].Trim(); alias = parts[2].Trim(); } else { // TODO: Error reporting - this cannot be correct return(null); } ResolverDelegate <ParameterResolverValue, IParameterResolverContext> resolver = null; if (parts.Length == 1) { // This can happen only for specially configured methods or sets - fullNames are ignored, prefixes are also ignored for them // So, any resolver will have at least 2 part name if it or its set (library) is not marked appropriately var libs = _Sets.Where(s => s.Library.Configuration != null) .Select(s => s.Library) .Where(l => (l.Configuration.GlobalNames && l.Configuration.Resolvers.Any(r => r.Alias == alias)) || (l.Configuration.Resolvers.Any(r => r.GlobalName && r.Alias == alias)) ).ToList(); if (libs.Count == 0) { return(null); // Not found } if (libs.Count > 1) { throw new Exception("Ambiguous name exception - more than one library is configured to register resolver with that name."); } resolver = libs[0].GetResolver(alias); lock (this.registerDelegateLocker) { if (!_delegates.ContainsKey(name)) { _delegates[name] = resolver; } } return(resolver); } else if (parts.Length == 2) { // LibName.Alias - We can have 2 parts only when the name of the set and the name of the resolver are both used // but fullChainNaming is off if (!FullChainNaming) { var libs = _Sets.Where(s => s.Name == setname).Select(s => s.Library).Where(l => l.Configuration != null && !l.Configuration.GlobalNames).ToList(); if (libs.Count == 0) { return(null); // Not found - there is no library that can possibly give us this one } libs = libs.Where(l => l.Configuration.Resolvers.Any(r => !r.GlobalName && r.Alias == alias)).ToList(); if (libs.Count == 0) { return(null); // Not found } if (libs.Count > 1) { throw new Exception("Ambiguous name - more than one resolver are found for this name."); } resolver = libs[0].GetResolver(alias); lock (this.registerDelegateLocker) { if (!_delegates.ContainsKey(name)) { _delegates[name] = resolver; } } return(resolver); } } else if (parts.Length == 3) { // Full names - if we are here it is permitted, but lets check it for better readability // This is much like case 2, but with FullChanin mode on if (FullChainNaming) { var libs = _Sets.Where(s => s.Name == setname && s.Prefix == prefix).Select(s => s.Library).Where(l => l.Configuration != null && !l.Configuration.GlobalNames).ToList(); if (libs.Count == 0) { return(null); // Not found - there is no library that can possibly give us this one } libs = libs.Where(l => l.Configuration.Resolvers.Any(r => !r.GlobalName && r.Alias == alias)).ToList(); if (libs.Count == 0) { return(null); // Not found } if (libs.Count > 1) { throw new Exception("Ambiguous name - more than one resolver are found for this name."); } resolver = libs[0].GetResolver(alias); lock (this.registerDelegateLocker) { if (!_delegates.ContainsKey(name)) { _delegates[name] = resolver; } } return(resolver); } } return(null); }
public void ConnectAsync() { // Resolve Host OnHostResolved += new ResolverDelegate(ConnectAsync_OnHostResolved); ResolveHostAsync(); }
public void ConnectAsync() { // Resolve Host OnHostResolved += new ResolverDelegate(ConnectAsync_OnHostResolved); ResolveHostAsync(); }