Exemplo n.º 1
0
        public async Task <MultipleDocumentResult> GetActivityStates(Iri activityId, Agent agent, Guid?registration, DateTimeOffset?since = null, CancellationToken cancellationToken = default)
        {
            AgentEntity savedAgent = await mediator.Send(GetAgentQuery.Create(agent), cancellationToken);

            if (savedAgent == null)
            {
                return(MultipleDocumentResult.Empty());
            }

            var states = await mediator.Send(new GetActivityStatesQuery()
            {
                ActivityId   = activityId,
                AgentId      = savedAgent.AgentId,
                Registration = registration,
                Since        = since
            }, cancellationToken);

            if (!states.Any())
            {
                return(MultipleDocumentResult.Empty());
            }

            var keys         = states.Select(x => x.Key).ToHashSet();
            var lastModified = states.OrderByDescending(x => x.UpdatedAt)
                               .Select(x => x.UpdatedAt)
                               .FirstOrDefault();

            return(MultipleDocumentResult.Success(keys, lastModified));
        }
Exemplo n.º 2
0
        public static List <IAgent> GetAgent(SearchCriteria searchCriteria, int ID)
        {
            string        strExecution = "[exp].[prcGetAgentList]";
            List <IAgent> lstAgent     = new List <IAgent>();

            using (DbQuery oDq = new DbQuery(strExecution))
            {
                oDq.AddIntegerParam("@AgentID", ID);
                oDq.AddVarcharParam("@SchAgentName", 100, searchCriteria.AgentName);
                oDq.AddVarcharParam("@SchLineName", 100, searchCriteria.LineName);
                oDq.AddVarcharParam("@SchFPOD", 100, searchCriteria.POD);
                oDq.AddVarcharParam("@SortExpression", 50, searchCriteria.SortExpression);
                oDq.AddVarcharParam("@SortDirection", 4, searchCriteria.SortDirection);
                DataTableReader reader = oDq.GetTableReader();


                while (reader.Read())
                {
                    IAgent oIH = new AgentEntity(reader);
                    lstAgent.Add(oIH);
                }
                reader.Close();
            }
            return(lstAgent);
        }
Exemplo n.º 3
0
        public int delete(int id)
        {
            AbstractCommonData entity   = new AgentEntity();
            string             delQuery = "DELETE FROM " + entity.TableName + " where " + entity.IndexFieldName + "=" + provider.getSQLString(id);

            return(provider.delete(delQuery));
        }
Exemplo n.º 4
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!BeforSave())
            {
                return;
            }
            AgentEntity entity = new AgentEntity();
            DataRow     dr     = entity.Tables[entity.TableName].NewRow();

            if (_id > 0)
            {
                dr[AgentEntity.FIELD_ID] = _id;
            }

            dr[AgentEntity.FIELD_Agent_NAME] = txtAgentName.Text;
            dr[AgentEntity.FIELD_AGENTCODE]  = txtAgentCode.Text;
            dr[AgentEntity.FIELD_TELEPHONE]  = txtTelephone.Text;
            dr[AgentEntity.FIELD_MOBILE]     = txtMobile.Text;
            dr[AgentEntity.FIELD_FAX]        = txtFax.Text;
            dr[AgentEntity.FIELD_ADDRESS]    = txtAddress.Text;
            dr[AgentEntity.FIELD_ACTIVE]     = (cmbActive.SelectedIndex == 1 ? false : true);
            entity.Tables[entity.TableName].Rows.Add(dr);

            if (_id < 0)
            {
                _id         = _AgentBL.add(entity);
                lblMsg.Text = "دخیره شده ";
            }
            else
            {
                _AgentBL.update(entity);
                lblMsg.Text = "به روز رسانی گردید.";
            }
            this.Close();
        }
Exemplo n.º 5
0
        /// <summary>
        /// 修改用户
        /// </summary>
        public bool EditUser(AgentEntity user)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update tbAgent set ");
            strSql.Append("agent_AN=@AccountName,agent_mp=@MobilePhone,agent_email=@Email,status_id=@StatusID");
            strSql.Append(" where id=@Id");

            SqlParameter[] paras =
            {
                new SqlParameter("@UserAcountName",  user.AgentAccountName),
                new SqlParameter("@UserMobliePhone", user.MobliePhone),
                new SqlParameter("@Email",           user.Email),
                new SqlParameter("@StatusID",        user.StatusID),
                new SqlParameter("@Id",              user.AgentID),
            };
            object obj = SqlHelper.ExecuteNonQuery(SqlHelper.connStr, CommandType.Text, strSql.ToString(), paras);

            if (Convert.ToInt32(obj) > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 6
0
        /// <inheritdoc />
        /// <summary>
        /// Removes the specified agent from the repository.
        /// </summary>
        /// <param name="id">The id of the agent to remove.</param>
        /// <returns><see cref="Task" />.</returns>
        public async Task Remove(string id)
        {
            AgentEntity entity = await _context.Agents.FirstAsync(x => x.Id.Equals(id));

            _context.Agents.Remove(entity);
            await _context.SaveChangesAsync();
        }
Exemplo n.º 7
0
 public static AgentUpdated Create(AgentEntity agent)
 {
     return(new AgentUpdated()
     {
         Agent = agent
     });
 }
Exemplo n.º 8
0
        public async Task HandleObject(StatementBase statement, IStatementBaseEntity newStatement, CancellationToken cancellationToken)
        {
            var objType = statement.Object.ObjectType;

            if (objType == ObjectType.Activity)
            {
                var activity = await _mediator.Send(UpsertActivityCommand.Create((Activity)statement.Object), cancellationToken);

                newStatement.ObjectType = EntityObjectType.Activity;
                newStatement.ObjectId   = activity.ActivityId;
            }
            else if (objType == ObjectType.Agent || objType == ObjectType.Group)
            {
                AgentEntity agent = await _mediator.Send(UpsertActorCommand.Create((Agent)statement.Object), cancellationToken);;
                newStatement.ObjectType = EntityObjectType.Agent;
                newStatement.ObjectId   = agent.AgentId;
            }
            else if (objType == ObjectType.SubStatement)
            {
                SubStatementEntity subStatement = await _mediator.Send(CreateSubStatementCommand.Create((SubStatement)statement.Object), cancellationToken);

                newStatement.ObjectType = EntityObjectType.SubStatement;
                newStatement.ObjectId   = subStatement.SubStatementId;
            }
            else if (objType == ObjectType.StatementRef)
            {
                StatementRef statementRef = (StatementRef)statement.Object;
                newStatement.ObjectType = EntityObjectType.StatementRef;
                newStatement.ObjectId   = statementRef.Id;
            }
        }
Exemplo n.º 9
0
 public void SetViewEntity(AgentEntity entity, AgentViewModel viewEntity)
 {
     viewEntity.F_Id               = entity.F_Id;
     viewEntity.c_name             = entity.c_name;
     viewEntity.c_mobile           = entity.c_mobile;
     viewEntity.c_login_pwd        = entity.c_login_pwd;
     viewEntity.c_safe_pwd         = entity.c_safe_pwd;
     viewEntity.c_bank_name        = entity.c_bank_name;
     viewEntity.c_bank_account     = entity.c_bank_account;
     viewEntity.c_address          = entity.c_address;
     viewEntity.c_state            = entity.c_state;
     viewEntity.c_score            = entity.c_score;
     viewEntity.c_levle            = entity.c_levle;
     viewEntity.c_agent_level      = entity.c_agent_level;
     viewEntity.c_had_reward       = entity.c_had_reward;
     viewEntity.c_agnet_type       = entity.c_agnet_type;
     viewEntity.c_exp_state        = entity.c_exp_state;
     viewEntity.c_rec_person       = entity.c_rec_person;
     viewEntity.c_rec_mobile       = entity.c_rec_mobile;
     viewEntity.c_bank_person      = entity.c_bank_person;
     viewEntity.c_voucher_path     = entity.c_voucher_path;
     viewEntity.c_create_date      = entity.c_create_date;
     viewEntity.F_CreatorUserId    = entity.F_CreatorUserId;
     viewEntity.F_LastModifyTime   = entity.F_LastModifyTime;
     viewEntity.F_CreatorTime      = entity.F_CreatorTime;
     viewEntity.F_LastModifyUserId = entity.F_LastModifyUserId;
     viewEntity.F_DeleteTime       = entity.F_DeleteTime;
     viewEntity.F_DeleteUserId     = entity.F_DeleteUserId;
     viewEntity.F_DeleteMark       = entity.F_DeleteMark;
 }
Exemplo n.º 10
0
    public void SpawnAgent(AgentEntity.EntityType type)
    {
        IncrementAgentType(type);
        switch (type)
        {
        case AgentEntity.EntityType.farmer:
            SpawnFarmer();
            break;

        case AgentEntity.EntityType.woodcutter:
            SpawnWoodcutter();
            break;

        case AgentEntity.EntityType.miner:
            SpawnMiner();
            break;

        case AgentEntity.EntityType.smelter:
            SpawnSmelter();
            break;

        case AgentEntity.EntityType.blacksmith:
            SpawnBlacksmith();
            break;
        }
        AgentEntity newAgent = Agents[Agents.Count - 1];

        AddAgentToGuild(newAgent);
    }
Exemplo n.º 11
0
            /// <summary>
            /// Creates or gets current agent
            /// </summary>
            /// <param name="actor"></param>
            /// <returns></returns>
            private async Task <AgentEntity> MergeActor(AgentEntity actor, CancellationToken cancellationToken)
            {
                // Get from db
                actor = await _context.Agents.FirstOrDefaultAsync(x =>
                                                                  x.ObjectType == actor.ObjectType &&
                                                                  x.Hash == actor.Hash,
                                                                  cancellationToken) ?? actor;

                if (actor is GroupEntity group)
                {
                    // Perform group update logic, add group member etc.
                    var remove       = new HashSet <AgentEntity>();
                    var groupMembers = new HashSet <AgentEntity>();

                    foreach (var member in group.Members)
                    {
                        var savedGrpActor = await MergeActor(member, cancellationToken);

                        if (savedGrpActor != null)
                        {
                            groupMembers.Add(savedGrpActor);
                        }
                        else
                        {
                            groupMembers.Add(member);
                        }
                    }
                    // Re-create the list of members
                    group.Members = new HashSet <AgentEntity>();
                    foreach (var member in groupMembers)
                    {
                        group.Members.Add(member);
                    }
                    //foreach (var member in group.Members)
                    //{
                    //    // Ensure Agent exist
                    //    var grpAgent = await MergeActor(member, cancellationToken);
                    //    if(grpAgent != null)
                    //    {
                    //        member = grpAgent;
                    //    }

                    //    // Check if the relation exist
                    //    var isMember = group.Members.Count(x => x.Hash == grpAgent.Hash) > 0;
                    //    if (!isMember)
                    //    {
                    //        group.Members.Add(grpAgent);
                    //    }
                    //}
                }

                if (actor.AgentId.Equals(Guid.Empty))
                {
                    actor.AgentId = Guid.NewGuid();
                    _context.Agents.Add(actor);
                }

                return(actor);
            }
Exemplo n.º 12
0
        public string getAgentName(int id)
        {
            AgentEntity entity = new AgentEntity();
            string      cond   = AgentEntity.FIELD_ID + "=" + provider.getSQLString(id);

            provider.loadToDataSet(entity, cond);
            return(entity.get(AgentEntity.FIELD_Agent_NAME).ToString());
        }
Exemplo n.º 13
0
        public AgentEntity get()
        {
            AgentEntity entity = new AgentEntity();
            string      cond   = "ID > 0";

            provider.loadToDataSet(entity, cond);
            return(entity);
        }
Exemplo n.º 14
0
        /// <inheritdoc />
        /// <summary>
        /// Adds the specified agent to the repository.
        /// </summary>
        /// <param name="entity">The entity to add.</param>
        /// <returns>
        ///   <see cref="AgentEntity" />.
        /// </returns>
        public async Task <AgentEntity> Add(AgentEntity entity)
        {
            await _context.Agents.AddAsync(entity);

            await _context.SaveChangesAsync();

            return(entity);
        }
Exemplo n.º 15
0
        public ActionResult expAgent(string keyValue)
        {
            AgentEntity entity = agentApp.GetForm(keyValue);

            entity.c_exp_state = 1;
            agentApp.UpdateForm(entity);
            return(Success("更改成功。"));
        }
Exemplo n.º 16
0
        public AgentEntity get(int id)
        {
            AgentEntity entity = new AgentEntity();
            string      cond   = AgentEntity.FIELD_ID + "=" + provider.getSQLString(id);

            provider.loadToDataSet(entity, cond);
            return(entity);
        }
Exemplo n.º 17
0
    public void AddMember(AgentEntity agent)
    {
        Members.Add(agent);

        if (Members.Count == 1)
        {
            Guildmaster = agent;
        }
    }
        public async Task <IActionResult> PostSingleState(
            [BindRequired, FromQuery] string stateId,
            [BindRequired, FromQuery] Iri activityId,
            [BindRequired, FromQuery] Agent agent,
            [BindRequired, FromBody] byte[] body,
            [BindRequired, FromHeader(Name = "Content-Type")] string contentType,
            [FromQuery] Guid?registration       = null,
            CancellationToken cancellationToken = default)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            AgentEntity storedAgent = await _mediator.Send(UpsertActorCommand.Create(agent));

            ActivityEntity activity = (ActivityEntity)await _mediator.Send(UpsertActivityCommand.Create(activityId), cancellationToken);

            ActivityStateDocument stateDocument = await _mediator.Send(new GetActivityStateQuery()
            {
                StateId      = stateId,
                ActivityId   = activityId,
                AgentId      = storedAgent.AgentId,
                Registration = registration
            }, cancellationToken);

            if (stateDocument != null)
            {
                stateDocument = await _mediator.Send(new UpdateStateDocumentCommand()
                {
                    StateId      = stateId,
                    ActivityId   = activityId,
                    AgentId      = storedAgent.AgentId,
                    Content      = body,
                    ContentType  = contentType,
                    Registration = registration
                }, cancellationToken);
            }
            else
            {
                stateDocument = await _mediator.Send(new CreateStateDocumentCommand()
                {
                    StateId      = stateId,
                    Activity     = activity,
                    Agent        = storedAgent,
                    Content      = body,
                    ContentType  = contentType,
                    Registration = registration
                }, cancellationToken);
            }

            Response.Headers.Add(HeaderNames.ETag, $"\"{stateDocument.Tag}\"");
            Response.Headers.Add(HeaderNames.LastModified, stateDocument.LastModified?.ToString("o"));

            return(NoContent());
        }
Exemplo n.º 19
0
        public static AgentEntity JamesCampbell()
        {
            var agent = new AgentEntity()
            {
                IFI_Key   = Ifi.Account,
                IFI_Value = "{ \"homePage\":\"http://www.bitflipping.net/agentId/1\", \"name\":\"Josephina\" }"
            };

            return(agent);
        }
Exemplo n.º 20
0
    private void SpawnWoodcutter()
    {
        AgentEntity woodcutter = new AgentEntity("Woodcutter" + String.Format("{0:D3}", AgentTypeCount[AgentEntity.EntityType.woodcutter]), AgentEntity.EntityType.woodcutter);

        woodcutter.Town = this;
        woodcutter.AddResource(ResourceUtil.Wood, InventoryItem.ActionType.sell, 10, 0);
        woodcutter.AddResource(ResourceUtil.Wheat, InventoryItem.ActionType.buy, 10, 4, 1);
        woodcutter.AddResource(ResourceUtil.Tools, InventoryItem.ActionType.buy, 10, 2, 1);

        Agents.Add(woodcutter);
    }
Exemplo n.º 21
0
    private void SpawnBlacksmith()
    {
        AgentEntity blacksmith = new AgentEntity("Blacksmith" + String.Format("{0:D3}", AgentTypeCount[AgentEntity.EntityType.blacksmith]), AgentEntity.EntityType.blacksmith);

        blacksmith.Town = this;
        blacksmith.AddResource(ResourceUtil.Tools, InventoryItem.ActionType.sell, 10, 0);
        blacksmith.AddResource(ResourceUtil.Wheat, InventoryItem.ActionType.buy, 10, 4, 2);
        blacksmith.AddResource(ResourceUtil.Metal, InventoryItem.ActionType.buy, 10, 4, 4);

        Agents.Add(blacksmith);
    }
Exemplo n.º 22
0
    private void SpawnFarmer()
    {
        AgentEntity farmer = new AgentEntity("Farmer" + String.Format("{0:D3}", AgentTypeCount[AgentEntity.EntityType.farmer]), AgentEntity.EntityType.farmer);

        farmer.Town = this;
        farmer.AddResource(ResourceUtil.Wheat, InventoryItem.ActionType.sell, 10, 0);
        farmer.AddResource(ResourceUtil.Wood, InventoryItem.ActionType.buy, 10, 5, 2);
        farmer.AddResource(ResourceUtil.Tools, InventoryItem.ActionType.buy, 10, 2, 1);

        Agents.Add(farmer);
    }
Exemplo n.º 23
0
    public void RemoveAgent(AgentEntity agent)
    {
        Console.WriteLine(String.Format("Town: {0}; Agent: {1}", Name, agent.Name));
        List <Market> agentMarkets = agent.Markets.Values.ToList();

        foreach (Market market in agentMarkets)
        {
            market.RemoveAgent(agent);
        }
        Guilds[agent.Type].RemoveMember(agent);
        Agents.Remove(agent);
    }
Exemplo n.º 24
0
 public void SubmitForm(AgentEntity userEntity, UserLogOnEntity userLogOnEntity, string keyValue)
 {
     if (!string.IsNullOrEmpty(keyValue))
     {
         userEntity.Modify(keyValue);
     }
     else
     {
         userEntity.Create();
     }
     service.SubmitForm(userEntity, userLogOnEntity, keyValue);
 }
Exemplo n.º 25
0
        public AgentEntity get(string cond)
        {
            AgentEntity entity = new AgentEntity();

            if (cond.Length > 0)
            {
                cond += " AND ";
            }
            cond += "ID > 0";
            provider.loadToDataSet(entity, cond);
            return(entity);
        }
Exemplo n.º 26
0
    private void SpawnSmelter()
    {
        AgentEntity smelter = new AgentEntity("Smelter" + String.Format("{0:D3}", AgentTypeCount[AgentEntity.EntityType.smelter]), AgentEntity.EntityType.smelter);

        smelter.Town = this;
        smelter.AddResource(ResourceUtil.Metal, InventoryItem.ActionType.sell, 10, 0);
        smelter.AddResource(ResourceUtil.Ore, InventoryItem.ActionType.buy, 10, 4, 4);
        smelter.AddResource(ResourceUtil.Wheat, InventoryItem.ActionType.buy, 10, 4, 2);
        smelter.AddResource(ResourceUtil.Tools, InventoryItem.ActionType.buy, 10, 2, 1);

        Agents.Add(smelter);
    }
        public async Task <IActionResult> GetSingleState(
            [BindRequired, FromQuery] Iri activityId,
            [BindRequired, FromQuery] Agent agent,
            [FromQuery] string stateId          = null,
            [FromQuery] DateTime?since          = null,
            [FromQuery] Guid?registration       = null,
            CancellationToken cancellationToken = default)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            AgentEntity agentEntity = await _mediator.Send(UpsertActorCommand.Create(agent));

            if (string.IsNullOrEmpty(stateId))
            {
                return(await GetMutipleStates(
                           activityId,
                           agentEntity.AgentId,
                           registration,
                           since,
                           cancellationToken
                           ));
            }

            ActivityStateDocument stateDocument = await _mediator.Send(new GetActivityStateQuery()
            {
                StateId      = stateId,
                ActivityId   = activityId,
                AgentId      = agentEntity.AgentId,
                Registration = registration
            }, cancellationToken);

            if (stateDocument == null)
            {
                return(NotFound());
            }

            if (Request.TryConcurrencyCheck(stateDocument.Tag, stateDocument.LastModified, out int statusCode))
            {
                return(StatusCode(statusCode));
            }

            var content = new FileContentResult(stateDocument.Content, stateDocument.ContentType.ToString())
            {
                LastModified = stateDocument.LastModified,
                EntityTag    = new EntityTagHeaderValue($"\"{stateDocument.Tag}\"")
            };

            return(content);
        }
Exemplo n.º 28
0
        public AgentEntity getOnlyActives(string cond)
        {
            AgentEntity entity = new AgentEntity();

            if (cond.Length > 0)
            {
                cond += " AND ";
            }
            cond += "(" + AgentEntity.FIELD_ACTIVE + "=1 OR " + AgentEntity.FIELD_ACTIVE + " IS NULL)";
            cond += " AND ID > 0";
            provider.loadToDataSet(entity, cond);
            return(entity);
        }
Exemplo n.º 29
0
        public AgentListDTO ToAgent(AgentEntity Agent)
        {
            AgentListDTO AgentList = new AgentListDTO();

            AgentList.AgentCode  = Agent.AgentCode;
            AgentList.AgentType  = Agent.AgentType;
            AgentList.CreateTime = Agent.CreateTime;
            AgentList.Flag       = Agent.Flag;
            AgentList.UserID     = Agent.UserID;


            return(AgentList);
        }
Exemplo n.º 30
0
        public static AgentEntity JamesCampbell()
        {
            var agent = new AgentEntity()
            {
                Account = new Domain.Entities.Account
                {
                    HomePage = "http://www.example.com/agentId/1",
                    Name     = "James Campbell"
                }
            };

            return(agent);
        }
Exemplo n.º 31
0
 /// <summary>
 /// The start.
 /// </summary>
 private void Start()
 {
     agent = new AgentEntity(ThePathfinder.AgentBelief as HVertexBased);
     RandomStrategy = GetComponent<IPortalsRandomStrategy>();
     StartCoroutine(MetaLoop());
 }