public async Task HandshakeAsync(long agentId) { _compId = agentId; using (var entities = new CrmEntitiesEntities()) { var query = from comp in entities.Computers where comp.Id == agentId select comp; var context = OperationContext.Current; var comps = await entities.GetEntitiesAsync(query); var cmp = comps.FirstOrDefault(); if (cmp == null) { throw new FaultException("comp not found"); } context.Channel.Closed += (sender, args) => { Server.UnRegisterAgent(agentId); }; Server.RegisterAgent(agentId); _rnd = new Random(GetHashCode()); } }
public async Task HandshakeAsync( long agentId ) { _compId = agentId; using( var entities = new CrmEntitiesEntities() ) { var query = from comp in entities.Computers where comp.Id == agentId select comp; var context = OperationContext.Current; var comps = await entities.GetEntitiesAsync( query ); var cmp = comps.FirstOrDefault(); if( cmp == null ) { throw new FaultException( "comp not found" ); } context.Channel.Closed += ( sender, args ) => { Server.UnRegisterAgent( agentId ); }; Server.RegisterAgent( agentId ); _rnd = new Random( GetHashCode() ); } }
public async Task RegisterAsync() { _callback = OperationContext.Current.GetCallbackChannel<IAgentControlCallback>(); using( var entities = new CrmEntitiesEntities() ) { var idsquery = from comp in entities.Computers orderby comp.Id select comp.Id; var context = OperationContext.Current; var ids = await entities.GetEntitiesAsync( idsquery ); Server.RegisterAgentControl( _callback ); context.Channel.Closed += ( sender, args ) => { Server.UnregisterAgentControl( _callback ); }; _callback.Initialize( ids ); _callback.SetConnectionsCount( Server.ExpectedConnectionsCount ); } }
public async Task RegisterAsync() { _callback = OperationContext.Current.GetCallbackChannel <IAgentControlCallback>(); using (var entities = new CrmEntitiesEntities()) { var idsquery = from comp in entities.Computers orderby comp.Id select comp.Id; var context = OperationContext.Current; var ids = await entities.GetEntitiesAsync(idsquery); Server.RegisterAgentControl(_callback); context.Channel.Closed += (sender, args) => { Server.UnregisterAgentControl(_callback); }; _callback.Initialize(ids); _callback.SetConnectionsCount(Server.ExpectedConnectionsCount); } }
public async Task DoOperationAsync() { using( var entities = new CrmEntitiesEntities() ) { var query = from comp in entities.Computers where comp.Id == _compId select comp; Computer[] comps; if( Server.IsAsync ) { comps = await entities.GetEntitiesAsync( query ); } else { comps = entities.GetEntitiesSync( query ); } if( Server.AgentSavesComputer ) { var cmp = comps.First(); int val = _rnd.Next(); cmp.AgentPackageName = val.ToString(); if( Server.IsAsync ) { await entities.SaveComputerAsync( cmp ); } else { entities.SaveComputerSync( cmp ); } } } Interlocked.Increment( ref _doOperationCalls ); }
public async Task DoOperationAsync() { using (var entities = new CrmEntitiesEntities()) { var query = from comp in entities.Computers where comp.Id == _compId select comp; Computer[] comps; if (Server.IsAsync) { comps = await entities.GetEntitiesAsync(query); } else { comps = entities.GetEntitiesSync(query); } if (Server.AgentSavesComputer) { var cmp = comps.First(); int val = _rnd.Next(); cmp.AgentPackageName = val.ToString(); if (Server.IsAsync) { await entities.SaveComputerAsync(cmp); } else { entities.SaveComputerSync(cmp); } } } Interlocked.Increment(ref _doOperationCalls); }
public IAsyncResult BeginGetComputers(AsyncCallback callback, object state) { var entities = new CrmEntitiesEntities(); var query = (from comp in entities.Computers where comp.Id > 10 && comp.Id < 100 orderby comp.Id select comp).Skip(10).Take(25); var result = new MyAsyncResult <Computer[]> { AsyncState = state }; entities.BeginGetEntities(query, entitiesAsyncResult => { IEnumerable <Computer> computers = entities.EndGetEntities <Computer>(entitiesAsyncResult); result.Data = computers.ToArray(); entities.Dispose(); result.Complete(false); callback(result); }, null); return(result); #region TPL Improvements var task = Task.Factory.FromAsync <IQueryable <Computer>, IEnumerable <Computer> >( entities.BeginGetEntities, entities.EndGetEntities <Computer>, query, state); return(task.ContinueWith(res => { entities.Dispose(); callback(task); })); #endregion }
public async Task <IEnumerable <Computer> > GetComputersAsync() { using (var entities = new CrmEntitiesEntities()) { lock ( _sync ) { if (_rand == null) { _rand = new Random(); _computersCount = entities.Computers.Count(); } } int start = _rand.Next(_computersCount - _take); var query = (from comp in entities.Computers orderby comp.Id select comp).Skip(start).Take(_take); var result = await entities.GetEntitiesAsync(query); return(result.ToArray()); } }