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 );
			}
		}
Example #4
0
        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);
        }
Example #7
0
        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());
            }
        }