/// <summary> /// Return an AbstractConnection to the pool /// </summary> /// <param name="cxn">The connection to return to the pool</param> /// <returns></returns> public override object checkIn(AbstractResource cxn) { AbstractConnection theCxn = (AbstractConnection)cxn; // first get a new reference if (!theCxn.IsConnected || !theCxn.isAlive()) // don't add disconnected connections to the pool { this.TotalResources--; return(null); } theCxn.LastUsed = DateTime.Now; if (cxn is VistaPoolConnection) { if (this.PoolSource.Credentials == null) // if not an authenticated connection { ((VistaPoolConnection)theCxn).resetRaw(); // reset the symbol table so we're always receiving fresh from pool ((VistaAccount)((VistaConnection)theCxn).Account).setContext(new MenuOption("XUS SIGNON")); } _pooledCxns.Add(theCxn); } else if (cxn is VistaConnection) { if (this.PoolSource.Credentials == null) // if not an authenticated connection { ((VistaAccount)((VistaConnection)theCxn).Account).setContext(new MenuOption("XUS SIGNON")); } _pooledCxns.Add(theCxn); } else { _pooledCxns.Add(theCxn); } //System.Console.WriteLine("A connection was returned to the pool. {0} available", _pooledCxns.Count); return(null); }
/// <summary> /// Check out an object from the pool and call isAlive to guarantee state. Decrement resource count /// on pool if object is not alive and discard it by removing references /// </summary> /// <param name="obj"></param> /// <returns>AbstractResource</returns> public override AbstractResource checkOutAlive(object obj) { AbstractResource resource = checkOut(obj); while (!resource.isAlive()) { //LogUtils.getInstance().Log("Found disconnected/timed out connection... Fetching another: " + ((ConnectionPoolSource)this.PoolSource).CxnSource.SiteId.Id); this.decrementResourceCount(); //this.TotalResources--; resource = checkOut(obj); } if (resource is VistaPoolConnection && this.PoolSource.RecycleCount > 0) // only need to step in here if the recycle count was actually set { VistaPoolConnection cxn = (VistaPoolConnection)resource; if (cxn.QueryCount >= this.PoolSource.RecycleCount) // if we've used cxn more times than specified before recycle, we should disconnect this connection and return another { //LogUtils.getInstance().Log("Max number of queries exceeded for connection - disconnecting and discarding: " + ((ConnectionPoolSource)this.PoolSource).CxnSource.SiteId.Id); new System.Threading.Tasks.Task(() => cxn.disconnect()).Start(); this.decrementResourceCount(); //this.TotalResources--; return(this.checkOutAlive(obj)); } } return(resource); }
/// <summary> /// Return an AbstractConnection to the pool /// </summary> /// <param name="cxn">The connection to return to the pool</param> /// <returns></returns> public override object checkIn(AbstractResource cxn) { AbstractConnection theCxn = (AbstractConnection)cxn; // first get a new reference if (!theCxn.IsConnected || !theCxn.isAlive()) // don't add disconnected connections to the pool { this.TotalResources--; return null; } theCxn.LastUsed = DateTime.Now; if (cxn is VistaPoolConnection) { if (this.PoolSource.Credentials == null) // if not an authenticated connection { ((VistaPoolConnection)theCxn).resetRaw(); // reset the symbol table so we're always receiving fresh from pool ((VistaAccount)((VistaConnection)theCxn).Account).setContext(new MenuOption("XUS SIGNON")); } _pooledCxns.Add(theCxn); } else if (cxn is VistaConnection) { if (this.PoolSource.Credentials == null) // if not an authenticated connection { ((VistaAccount)((VistaConnection)theCxn).Account).setContext(new MenuOption("XUS SIGNON")); } _pooledCxns.Add(theCxn); } else { _pooledCxns.Add(theCxn); } //System.Console.WriteLine("A connection was returned to the pool. {0} available", _pooledCxns.Count); return null; }
private object SanitizeValue(AbstractResource resource, string propertyName, object rawValue) { var asEmbedded = rawValue as IEmbeddedProperty; if (asEmbedded != null) { return(new { href = asEmbedded.Href }); } var asEnumeration = rawValue as StringEnumeration; if (asEnumeration != null) { return(asEnumeration.Value.ToLower()); } var asEmbeddedResource = rawValue as AbstractResource; if (asEmbeddedResource != null) { return(this.AsInterface.ToMap(asEmbeddedResource)); } // Already a primitive-like type, no need to sanitize return(rawValue); }
public CodecContainer(RestClient client) { this.Codec = new CodecResource <CodecConfig>(client, ApiUrls.CodecConfig); this.H264 = new AbstractResource <H264VideoConfiguration>(client, ApiUrls.CodecConfigH264); this.H265 = new AbstractResource <H265VideoConfiguration>(client, ApiUrls.CodecConfigH265); this.VP9 = new AbstractResource <VP9VideoConfiguration>(client, ApiUrls.CodecConfigVP9); this.Aac = new AbstractResource <AACAudioConfiguration>(client, ApiUrls.CodecConfigAac); }
public bool isMoreThanOrEqual(AbstractResource otherResource) { if (sameResourceType(otherResource)) { IntResource other = otherResource as IntResource; return value >= other.value; } return false; }
public ResourceWPF(Point position, AbstractResource resource) : base(position, resource.Description) { this.resPuts = new List <ResConnectionWPF>(); this.ResourceModel = resource; Foreground = Brushes.Black; MakeIMG(); // установить ZIndex //SetZIngex(); }
private bool sameResourceType(AbstractResource otherResource) { if (otherResource is IntResource) { IntResource other = otherResource as IntResource; if (other.id == id) { return true; } } return false; }
public override AbstractResource checkOutAlive(object obj) { AbstractResource resource = checkOut(obj); while (!resource.isAlive()) { // System.Console.WriteLine("Found a disconnected resource from ConnectionPools"); LogUtils.getInstance().Log("Found a disconnected resource from ConnectionPools... decrementing resource count and checking out another"); _pools[(String)obj].decrementResourceCount(); // we decrement resource count for this pool here because checkOut doesn't do it //_pools[(String)obj].TotalResources--; resource = checkOut(obj); } return(resource); }
Map IResourceConverter.ToMap(AbstractResource resource) { var propertyNames = resource.GetUpdatedPropertyNames(); var resultMap = propertyNames.Select(name => { var rawValue = resource.GetProperty(name); var value = this.SanitizeValue(resource, name, rawValue); return new { name, value }; }).ToDictionary( map => map.name, map => map.value); return resultMap; }
Map IResourceConverter.ToMap(AbstractResource resource) { var propertyNames = resource.GetUpdatedPropertyNames(); var resultMap = propertyNames.Select(name => { var rawValue = resource.GetProperty(name); var value = this.SanitizeValue(resource, name, rawValue); return(new { name, value }); }).ToDictionary( map => map.name, map => map.value); return(resultMap); }
/// <summary> /// Check a connection in to the pool /// </summary> /// <param name="objToReturn">The AbstractConnection to check in</param> /// <returns>null</returns> public override object checkIn(AbstractResource objToReturn) { if (objToReturn == null || !(objToReturn is AbstractConnection)) { throw new ArgumentException("Invalid object for checkin"); } AbstractConnection theCxn = (AbstractConnection)objToReturn; if (theCxn.DataSource == null || theCxn.DataSource.SiteId == null || String.IsNullOrEmpty(theCxn.DataSource.SiteId.Id)) { throw new ArgumentException("The connection source is incomplete"); } if (!_pools.ContainsKey(theCxn.DataSource.SiteId.Id)) { throw new ArgumentException("No pool found for that connection"); } _pools[theCxn.DataSource.SiteId.Id].checkIn(theCxn); return null; }
/// <summary> /// Check a connection in to the pool /// </summary> /// <param name="objToReturn">The AbstractConnection to check in</param> /// <returns>null</returns> public override object checkIn(AbstractResource objToReturn) { if (objToReturn == null || !(objToReturn is AbstractConnection)) { throw new ArgumentException("Invalid object for checkin"); } AbstractConnection theCxn = (AbstractConnection)objToReturn; if (theCxn.DataSource == null || theCxn.DataSource.SiteId == null || String.IsNullOrEmpty(theCxn.DataSource.SiteId.Id)) { throw new ArgumentException("The connection source is incomplete"); } if (!_pools.ContainsKey(theCxn.DataSource.SiteId.Id)) { throw new ArgumentException("No pool found for that connection"); } _pools[theCxn.DataSource.SiteId.Id].checkIn(theCxn); return(null); }
private object SanitizeValue(AbstractResource resource, string propertyName, object rawValue) { var asEmbedded = rawValue as IEmbeddedProperty; if (asEmbedded != null) { return new { href = asEmbedded.Href }; } var asEnumeration = rawValue as StringEnumeration; if (asEnumeration != null) { return asEnumeration.Value.ToLower(); } var asEmbeddedResource = rawValue as AbstractResource; if (asEmbeddedResource != null) { return this.AsInterface.ToMap(asEmbeddedResource); } // Already a primitive-like type, no need to sanitize return rawValue; }
public void addResourceConstraint(AbstractResource resource) { constraints.Add(resource); }
public void addResource(AbstractResource resource) { resources.Add(resource); }