Esempio n. 1
0
        public void CanComputeDistance(string sourceId, string targetId, int expectedDistance)
        {
            var source = AgentId.Parse(sourceId);
            var target = AgentId.Parse(targetId);

            Assert.Equal(expectedDistance, source - target);
        }
Esempio n. 2
0
 public void MergeFrom(SubscribeRequest other)
 {
     if (other == null)
     {
         return;
     }
     if (other.agentId_ != null)
     {
         if (agentId_ == null)
         {
             agentId_ = new global::Bgs.Protocol.EntityId();
         }
         AgentId.MergeFrom(other.AgentId);
     }
     if (other.entityId_ != null)
     {
         if (entityId_ == null)
         {
             entityId_ = new global::Bgs.Protocol.EntityId();
         }
         EntityId.MergeFrom(other.EntityId);
     }
     if (other.ObjectId != 0UL)
     {
         ObjectId = other.ObjectId;
     }
     program_.Add(other.program_);
     if (other.FlagPublic != false)
     {
         FlagPublic = other.FlagPublic;
     }
 }
Esempio n. 3
0
        public override bool Equals(Object o)
        {
            if (this == o)
            {
                return(true);
            }
            if (o == null || GetType() != o.GetType())
            {
                return(false);
            }

            TransactionId that = (TransactionId)o;

            if (AgentStartTime != that.AgentStartTime)
            {
                return(false);
            }
            if (TransactionSequence != that.TransactionSequence)
            {
                return(false);
            }
            if (!AgentId.Equals(that.AgentId))
            {
                return(false);
            }

            return(true);
        }
Esempio n. 4
0
 public void MergeFrom(SubmitReportRequest other)
 {
     if (other == null)
     {
         return;
     }
     if (other.HasAgentId)
     {
         if (!HasAgentId)
         {
             AgentId = new global::Bgs.Protocol.Account.V1.GameAccountHandle();
         }
         AgentId.MergeFrom(other.AgentId);
     }
     if (other.HasReportType)
     {
         if (!HasReportType)
         {
             ReportType = new global::Bgs.Protocol.Report.V1.ReportType();
         }
         ReportType.MergeFrom(other.ReportType);
     }
     if (other.HasProgram)
     {
         Program = other.Program;
     }
     _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
 }
Esempio n. 5
0
        public void CanCreateIdFromId(string representation, byte rootId, params int[] parts)
        {
            var root       = new AgentId(rootId);
            var descendant = ToBytes(parts).Aggregate(root, (id, p) => id + p);

            Assert.Equal(representation, descendant.ToString());
        }
Esempio n. 6
0
 public void MergeFrom(UnsubscribeRequest other)
 {
     if (other == null)
     {
         return;
     }
     if (other.agentId_ != null)
     {
         if (agentId_ == null)
         {
             agentId_ = new global::Bgs.Protocol.EntityId();
         }
         AgentId.MergeFrom(other.AgentId);
     }
     if (other.entityId_ != null)
     {
         if (entityId_ == null)
         {
             entityId_ = new global::Bgs.Protocol.EntityId();
         }
         EntityId.MergeFrom(other.EntityId);
     }
     if (other.ObjectId != 0UL)
     {
         ObjectId = other.ObjectId;
     }
 }
Esempio n. 7
0
        public Weight GetRelationWeight(AgentId subjectId, AgentId objectId)
        {
            var subject  = GetPeer(subjectId);
            var relation = subject.GetRelation(objectId);

            return(relation.Strength);
        }
Esempio n. 8
0
 public ScheduledJob(AgentId agentId, AgentAction action, string conversationId)
 {
     this.AgentId        = agentId;
     this.Action         = action;
     this.JobStatus      = Status.Requested;
     this.ConversationId = conversationId;
 }
Esempio n. 9
0
        private Agent GetAgent(LogEventInfo logEventInfo)
        {
            var agentId      = AgentId?.Render(logEventInfo);
            var agentName    = AgentName?.Render(logEventInfo);
            var agentType    = AgentType?.Render(logEventInfo);
            var agentVersion = AgentVersion?.Render(logEventInfo);

            if (string.IsNullOrEmpty(agentId) &&
                string.IsNullOrEmpty(agentName) &&
                string.IsNullOrEmpty(agentType) &&
                string.IsNullOrEmpty(agentVersion))
            {
                return(null);
            }

            var agent = new Agent
            {
                Id      = agentId,
                Name    = agentName,
                Type    = agentType,
                Version = agentVersion
            };

            return(agent);
        }
Esempio n. 10
0
        public static string GenerateToken(AgentId agentId, byte[] keyBytes)
        {
            var claims = new List <Claim>
            {
                new(ClaimTypes.NameIdentifier, agentId.Value),
                new(ClaimTypes.Name, agentId.Value),
                new("milou_agent", agentId.Value),
                new("unique_name", agentId.Value),
            };

            var handler         = new JwtSecurityTokenHandler();
            var securityKey     = new SymmetricSecurityKey(keyBytes);
            var tokenDescriptor = new SecurityTokenDescriptor
            {
                Subject            = new ClaimsIdentity(claims),
                Expires            = new DateTime(DateTime.Today.Year + 2, 12, 31, 0, 0, 0, 0),
                SigningCredentials = new SigningCredentials(securityKey,
                                                            SecurityAlgorithms.HmacSha256Signature)
            };

            IdentityModelEventSource.ShowPII = true;

            JwtSecurityToken securityToken = handler.CreateJwtSecurityToken(tokenDescriptor);
            string           jwt           = handler.WriteToken(securityToken);

            return(jwt);
        }
Esempio n. 11
0
 public RemoteDeploymentPackageAgent(IHubContext <AgentHub> agentHub, AgentsData agentsData, AgentId agentId, ILogger logger)
 {
     _agentHub   = agentHub;
     _agentsData = agentsData;
     AgentId     = agentId;
     _logger     = logger;
 }
Esempio n. 12
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (HasAgentId)
            {
                hash ^= AgentId.GetHashCode();
            }
            if (HasUserDescription)
            {
                hash ^= UserDescription.GetHashCode();
            }
            if (HasProgram)
            {
                hash ^= Program.GetHashCode();
            }
            if (HasUserOptions)
            {
                hash ^= UserOptions.GetHashCode();
            }
            if (HasClubOptions)
            {
                hash ^= ClubOptions.GetHashCode();
            }
            hash ^= (int)typeCase_;
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Esempio n. 13
0
 public AgentInfo(AgentId id, DateTimeOffset?connectedAt = null, string?connectionId = null, string?currentDeploymentTaskId = null, DeploymentTargetId?currentDeploymentTargetId = null)
 {
     Id                        = id;
     ConnectedAt               = connectedAt;
     ConnectionId              = connectionId;
     CurrentDeploymentTaskId   = currentDeploymentTaskId;
     CurrentDeploymentTargetId = currentDeploymentTargetId;
 }
Esempio n. 14
0
 private Account(ICryptography cryptography, string name, AgentId id)
 {
     _cryptography = cryptography;
     Name          = name;
     Id            = id;
     Self          = CreateSelf();
     SetRelationWeight(Id, Id, Weight.Max);
 }
Esempio n. 15
0
        public override int GetHashCode()
        {
            int result = AgentId.GetHashCode();

            result = 31 * result + (int)(AgentStartTime ^ (AgentStartTime >> 32));
            result = 31 * result + (int)(TransactionSequence ^ (TransactionSequence >> 32));
            return(result);
        }
Esempio n. 16
0
        public AgentId GetFromFile()
        {
            var agentId = File.Exists(_agentIdFilePath)
                ? new AgentId(File.ReadAllText(_agentIdFilePath))
                : new AgentId(null);

            _current = agentId;
            return(agentId);
        }
Esempio n. 17
0
 private void AccountArtefactTransfer(Artefact[] artefacts, AgentId receiverId)
 {
     foreach (var artefact in artefacts)
     {
         _actor.Account.MoveArtefact(
             artefact,
             _actor.ProducePeer(receiverId).Id);
     }
 }
Esempio n. 18
0
        public void HasBeenCancelledBy()
        {
            var agentId = new AgentId(1, 1);

            _task.Assigned = agentId;
            Assert.IsFalse(_task.IsCancelledBy(agentId));
            _task.Cancel();
            Assert.IsTrue(_task.IsCancelledBy(agentId));
        }
Esempio n. 19
0
    override protected void Action()
    {
        MaterialConcept materialConcept = new MaterialConcept(materialType);
        AgentAction     action          = new GetMaterialAction(materialConcept, amount);
        AgentMessage    message         = new AgentMessage(AgentMessage.PerformativeType.INFORM);

        message.Receiver = AgentId.ParseGlobalId(receiver);
        message.Content  = action;
        Agent.Send(message);
    }
Esempio n. 20
0
        public void Save(string agentId)
        {
            if (agentId is "")
            {
                File.Delete(_agentIdFilePath);
            }

            _current = new AgentId(agentId);
            File.WriteAllText(_agentIdFilePath, agentId);
        }
Esempio n. 21
0
        private IHolder RequestPeerAssessment(AgentId id, params AgentId[] asking)
        {
            var money = RequestPeerAssessment(GetNearestFriends(id, asking).ToArray(), id, asking);

            return(money.HasValue
                ? new Holder {
                Id = id, Money = money.Value
            }
                : null);
        }
Esempio n. 22
0
        public void ExistAndStartedAgentTests()
        {
            var agentId = new AgentId(1, ClassName1);

            Assert.IsFalse(Environment.AgentNetwork.ExistsAndStarted(agentId));
            _agent = TestReactiveAgent.CreateInstance(Environment);
            _agent.Start();
            Environment.AgentNetwork.WaitingForStart(_agent.AgentId);
            Assert.IsTrue(Environment.AgentNetwork.ExistsAndStarted(_agent.AgentId));
        }
Esempio n. 23
0
        public void AddArtefact(Artefact artefact, AgentId ownerId)
        {
            if (!IsConnectedTo(ownerId))
            {
                return;
            }
            var newArtefact = new Artefact(artefact, ownerId);

            GetPeer(ownerId).AddArtefact(newArtefact);
            RememberArtefact(newArtefact);
        }
Esempio n. 24
0
        public void Initialize()
        {
            var agentId = new AgentId(1, 1);

            _belief0      = new Belief(Network, 0, Model, BeliefWeightLevel.RandomWeight);
            _belief1      = new Belief(Network, 1, Model, BeliefWeightLevel.RandomWeight);
            _belief2      = new Belief(Network, 2, Model, BeliefWeightLevel.RandomWeight);
            _actorBelief0 = new ActorBelief(agentId, _belief0.EntityId, BeliefLevel.NeitherAgreeNorDisagree);
            _actorBelief1 = new ActorBelief(agentId, _belief1.EntityId, BeliefLevel.NeitherAgreeNorDisagree);
            _actorBelief2 = new ActorBelief(agentId, _belief2.EntityId, BeliefLevel.NeitherAgreeNorDisagree);
        }
Esempio n. 25
0
        public void SetRelationWeight(AgentId subjectId, AgentId objectId, Weight value)
        {
            if (subjectId == objectId)
            {
                value = Weight.Max;
            }
            var subject  = GetPeer(subjectId);
            var relation = subject.GetRelation(objectId);

            relation.Strength = value;
        }
Esempio n. 26
0
        private Money?RequestPeerAssessment(IPeer[] asked, AgentId about, params AgentId[] asking)
        {
            if (!asked.Any())
            {
                return(null);
            }
            var assessments = GetIndirectPeerAssessments(asked, about, asking);

            return(assessments.Any()
                ? ComputeMeanAssessment(assessments)
                : (Money?)null);
        }
Esempio n. 27
0
 public CustomHttpClient(IHttpClientFactory httpClientFactory,
                         string deploymentTaskId,
                         DeploymentTargetId deploymentTargetId,
                         AgentId agentId,
                         ILogger logger)
 {
     _httpClientFactory  = httpClientFactory;
     _deploymentTaskId   = deploymentTaskId;
     _deploymentTargetId = deploymentTargetId;
     _agentId            = agentId;
     _logger             = logger;
 }
Esempio n. 28
0
        public bool Update(AgentId subjectId, SignedAction signedAction)
        {
            if (!_actor.Account.IsConnectedTo(subjectId))
            {
                return(false);
            }
            var peer = _actor.Account.GetPeer(subjectId);

            _actor.Account.VerifySignature(signedAction, peer);
            UpdatePeer(peer, signedAction.Action);
            return(true);
        }
Esempio n. 29
0
        public void Initialize()
        {
            var agentId = new AgentId(1, 1);

            _knowledge        = new Knowledge(Network, MainOrganization.Models, "0", 10);
            _knowledge1       = new Knowledge(Network, MainOrganization.Models, "1", 10);
            _knowledge2       = new Knowledge(Network, MainOrganization.Models, "2", 10);
            _actorKnowledge0  = new ActorKnowledge(agentId, _knowledge.EntityId, _knowledge0Bits, 0, -1);
            _actorKnowledge1  = new ActorKnowledge(agentId, _knowledge1.EntityId, _knowledge1Bits, 0, -1);
            _actorKnowledge01 = new ActorKnowledge(agentId, _knowledge2.EntityId, _knowledge01Bits, 0, -1);
            _actorKnowledge   = new ActorKnowledge(agentId, _knowledge.EntityId, KnowledgeLevel.BasicKnowledge, 0, -1);
        }
Esempio n. 30
0
        public GameObject GetAgent(AgentId agentId)
        {
            foreach (var gameObj in _itemsInPresceneZone)
            {
                var ttag = gameObj.GetComponent <Tag>();
                if (ttag.Type == TagType.Device && ttag.AgentId == agentId)
                {
                    return(gameObj);
                }
            }

            return(null);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="EntityConfiguration"/> class
        /// with the specified values.
        /// </summary>
        /// <param name="label">The name for the entity. If this value is <see langword="null"/>, the underlying property will be omitted from the JSON representation of the object.</param>
        /// <param name="agentId">The agent which this entity is bound to. If this value is <see langword="null"/>, the underlying property will be omitted from the JSON representation of the object.</param>
        /// <param name="ipAddresses">The IP addresses which can be referenced by checks on this entity. If this value is <see langword="null"/>, the underlying property will be omitted from the JSON representation of the object.</param>
        /// <param name="metadata">A collection of metadata to associate with the entity. If this value is <see langword="null"/>, the underlying property will be omitted from the JSON representation of the object.</param>
        /// <exception cref="ArgumentException">
        /// If <paramref name="label"/> is empty.
        /// <para>-or-</para>
        /// <para>If <paramref name="ipAddresses"/> contains any empty keys.</para>
        /// <para>-or-</para>
        /// <para>If <paramref name="metadata"/> contains any empty keys.</para>
        /// </exception>
        protected EntityConfiguration(string label, AgentId agentId, IDictionary<string, IPAddress> ipAddresses, IDictionary<string, string> metadata)
        {
            if (label == string.Empty)
                throw new ArgumentException("label cannot be empty");

            _label = label;
            _agentId = agentId;
            _ipAddresses = ipAddresses;
            if (_ipAddresses != null)
            {
                if (_ipAddresses.ContainsKey(string.Empty))
                    throw new ArgumentException("ipAddresses cannot contain any empty keys", "ipAddresses");
            }

            _metadata = metadata;
            if (_metadata != null)
            {
                if (_metadata.ContainsKey(string.Empty))
                    throw new ArgumentException("metadata cannot contain any empty keys", "metadata");
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="UpdateEntityConfiguration"/> class
 /// with the specified values.
 /// </summary>
 /// <param name="label">The name for the entity. If this parameter is <see langword="null"/>, the name for the entity is not changed.</param>
 /// <param name="agentId">The agent which this entity is bound to. If this parameter is <see langword="null"/>, the agent for the entity is not changed.</param>
 /// <param name="ipAddresses">The IP addresses which can be referenced by checks on this entity. If this parameter is <see langword="null"/>, the IP addresses for the entity are not changed.</param>
 /// <param name="metadata">A collection of metadata to associate with the entity. If this parameter is <see langword="null"/>, the metadata for the entity is not changed.</param>
 /// <exception cref="ArgumentException">
 /// If <paramref name="label"/> is empty.
 /// <para>-or-</para>
 /// <para>If <paramref name="ipAddresses"/> contains any empty keys, or any <see langword="null"/> values.</para>
 /// <para>-or-</para>
 /// <para>If <paramref name="metadata"/> contains any empty keys, or any <see langword="null"/> values.</para>
 /// </exception>
 public UpdateEntityConfiguration(string label = null, AgentId agentId = null, IDictionary<string, IPAddress> ipAddresses = null, IDictionary<string, string> metadata = null)
     : base(label, agentId, ipAddresses, metadata)
 {
 }
Esempio n. 33
0
 public AgentStatus()
 {
     Capabilities = new List<string>();
     Id = new AgentId(Guid.Empty);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="NewEntityConfiguration"/> class
 /// with the specified values.
 /// </summary>
 /// <param name="label">The name for the entity.</param>
 /// <param name="agentId">The agent which this entity is bound to. If this parameter is <see langword="null"/>, <placeholder>placeholder</placeholder>.</param>
 /// <param name="ipAddresses">The IP addresses which can be referenced by checks on this entity. If this parameter is <see langword="null"/>, <placeholder>placeholder</placeholder>.</param>
 /// <param name="metadata">A collection of metadata to associate with the entity. If this parameter is <see langword="null"/>, the entity is created without any custom metadata.</param>
 /// <exception cref="ArgumentNullException">If <paramref name="label"/> is <see langword="null"/>.</exception>
 /// <exception cref="ArgumentException">
 /// If <paramref name="label"/> is empty.
 /// <para>-or-</para>
 /// <para>If <paramref name="ipAddresses"/> contains any empty keys.</para>
 /// <para>-or-</para>
 /// <para>If <paramref name="metadata"/> contains any empty keys.</para>
 /// </exception>
 public NewEntityConfiguration(string label, AgentId agentId, IDictionary<string, IPAddress> ipAddresses, IDictionary<string, string> metadata)
     : base(label, agentId, ipAddresses, metadata)
 {
     if (label == null)
         throw new ArgumentNullException("label");
 }
        /// <summary>
        /// Gets login information reported by a monitoring agent.
        /// </summary>
        /// <param name="service">The monitoring service instance.</param>
        /// <param name="agentId">The agent ID. This is obtained from <see cref="Agent.Id">Agent.Id</see>.</param>
        /// <returns>A <see cref="HostInformation{T}"/> object containing the host information.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="service"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentNullException">If <paramref name="agentId"/> is <see langword="null"/>.</exception>
        /// <exception cref="WebException">If the REST request does not return successfully.</exception>
        /// <seealso href="http://docs.rackspace.com/cm/api/v1.0/cm-devguide/content/service-agent-host_info.html#service-agent-host_info-who">Get Logged-in User Information (Rackspace Cloud Monitoring Developer Guide - API v1.0)</seealso>
        public static HostInformation<ReadOnlyCollection<LoginInformation>> GetLoginInformation(this IMonitoringService service, AgentId agentId)
        {
            if (service == null)
                throw new ArgumentNullException("service");

            try
            {
                return service.GetLoginInformationAsync(agentId, CancellationToken.None).Result;
            }
            catch (AggregateException ex)
            {
                ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions;
                if (innerExceptions.Count == 1)
                    throw innerExceptions[0];

                throw;
            }
        }
        /// <summary>
        /// Gets a collection of monitoring agent connections.
        /// </summary>
        /// <param name="service">The monitoring service instance.</param>
        /// <param name="agentId">The agent ID. This is obtained from <see cref="Agent.Id">Agent.Id</see>.</param>
        /// <param name="marker">A marker identifying the next page of results. This parameter is used for <see href="http://docs.rackspace.com/cm/api/v1.0/cm-devguide/content/api-paginated-collections.html">pagination</see>, and is obtained from <see cref="ReadOnlyCollectionPage{T, TMarker}.NextMarker"/>. If the value is <see langword="null"/>, the list starts at the beginning.</param>
        /// <param name="limit">The maximum number of items to include in a single page of results. This parameter is used for <see href="http://docs.rackspace.com/cm/api/v1.0/cm-devguide/content/api-paginated-collections.html">pagination</see>. If the value is <see langword="null"/>, a provider-specific default value is used.</param>
        /// <returns>
        /// A <see cref="ReadOnlyCollectionPage{T, TMarker}"/> object containing the page
        /// of results and its associated pagination metadata.
        /// </returns>
        /// <exception cref="ArgumentNullException">If <paramref name="service"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentNullException">If <paramref name="agentId"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentOutOfRangeException">If <paramref name="limit"/> is less than or equal to 0.</exception>
        /// <exception cref="WebException">If the REST request does not return successfully.</exception>
        /// <seealso href="http://docs.rackspace.com/cm/api/v1.0/cm-devguide/content/service-agent.html#service-agent-list-agent-connections">List Agent Connections (Rackspace Cloud Monitoring Developer Guide - API v1.0)</seealso>
        /// <seealso href="http://docs.rackspace.com/cm/api/v1.0/cm-devguide/content/api-paginated-collections.html">Paginated Collections (Rackspace Cloud Monitoring Developer Guide - API v1.0)</seealso>
        public static ReadOnlyCollectionPage<AgentConnection, AgentConnectionId> ListAgentConnections(this IMonitoringService service, AgentId agentId, AgentConnectionId marker, int? limit)
        {
            if (service == null)
                throw new ArgumentNullException("service");

            try
            {
                return service.ListAgentConnectionsAsync(agentId, marker, limit, CancellationToken.None).Result;
            }
            catch (AggregateException ex)
            {
                ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions;
                if (innerExceptions.Count == 1)
                    throw innerExceptions[0];

                throw;
            }
        }