Exemplo n.º 1
0
        public State RegisterHost(Host host)
        {
            //bool exist = false;

            HostRepository hostRepo = new HostRepository();
            //var hosts = hostRepo.GetAll();

            //foreach(var h in hosts)
            //{
            //    if (h.Ip == host.Ip && h.Port == host.Port)
            //    {
            //        exist = true;
            //    }
            //}

            //if (exist)
            //{
            //    return new State() {IsError = true, Message = "Host is already registred!" };
            //}

            //string id = Guid.NewGuid().ToString();
            HostEntity entity = new HostEntity {
                HostId = host.Id, Ip = host.Ip, Port = host.Port, IsBusy = host.IsBusy
            };

            hostRepo.Create(entity);
            //hostRepo.Save();

            return(new State()
            {
                IsError = false, Message = "id"
            });
        }
Exemplo n.º 2
0
        public override void ApplyOnMember(EntityModelBuilder builder)
        {
            var namesArr = StringHelper.SplitNames(this.MemberNames);

            foreach (var name in namesArr)
            {
                var targetMember = HostEntity.GetMember(name);
                if (targetMember == null)
                {
                    builder.Log.Error("Member {0} referenced in DependsOn attribute on member {1}.{2} not found.", name,
                                      HostEntity.Name, HostMember.MemberName);
                    return;
                }
                //add this member to DependentMembers array of targetMember
                if (targetMember.DependentMembers == null)
                {
                    targetMember.DependentMembers = new EntityMemberInfo[] { HostMember }
                }
                ;
                else
                {
                    var mList = targetMember.DependentMembers.ToList();
                    mList.Add(HostMember);
                    targetMember.DependentMembers = mList.ToArray();
                }
            } //foreach name
        }     // method
Exemplo n.º 3
0
 public override void ApplyOnMember(EntityModelBuilder builder)
 {
     if (HostMember.DataType != typeof(int))
     {
         builder.Log.Error("HashFor attribute can be used only on int properties. Entity/property: {0}.{1}.",
                           HostEntity.Name, HostMember.MemberName);
         return;
     }
     _hashedMember = HostEntity.GetMember(this.PropertyName);
     if (_hashedMember == null)
     {
         builder.Log.Error("Property {0} referenced in HashFor attribute on property {1} not found on entity {2}.",
                           this.PropertyName, HostMember.MemberName, HostEntity.Name);
         return;
     }
     if (_hashedMember.DataType != typeof(string))
     {
         builder.Log.Error("HashFor attribute on property {0}.{1}: target property must be of string type.",
                           HostEntity.Name, HostMember.MemberName);
         return;
     }
     _oldSetter = _hashedMember.SetValueRef;
     _hashedMember.SetValueRef = OnSettingValue;
     _hashingService           = builder.Model.App.GetService <IHashingService>();
 }
Exemplo n.º 4
0
 public virtual void CreateKey(IActivationLog log)
 {
     if (this.Key != null) //protect against multiple processing
     {
         return;
     }
     // we initially assign temp names
     this.Key = new EntityKeyInfo(HostEntity, KeyType, HostMember, this.Alias);
     // add members
     if (HostMember != null)
     {
         Key.KeyMembers.Add(new EntityKeyMemberInfo(HostMember, false));
     }
     else
     {
         // it will add errors if it fails
         HostEntity.TryParseKeySpec(this.MemberNames, log, out Key.KeyMembers, ordered: true);
     }
     // construct name
     Key.ExplicitDbKeyName = this.DbKeyName;
     // PK
     if (KeyType.IsSet(KeyType.PrimaryKey))
     {
         if (HostEntity.PrimaryKey == null)
         {
             HostEntity.PrimaryKey = Key;
             Key.KeyMembers.Each(km => km.Member.Flags |= EntityMemberFlags.PrimaryKey);
         }
         else
         {
             log.Error("Entity {0} has more than one Primary Key specified.", GetHostRef());
         }
     }
 }
Exemplo n.º 5
0
 public static Host ToDomain(this HostEntity host)
 {
     return(new Host()
     {
         Id = host.Id,
         Server = host.Server,
         Port = host.Port
     });
 }
Exemplo n.º 6
0
 public override void OnUpdate()
 {
     if ((HostEntity.CollisionLeft() == ColliderType.Land) || (HostEntity.Location.X <= 0))
     {
         HostEntity.Velocity.X = _speed;
         HostEntity.SetAnime(_rightAnimeStartIndex, _rightAnimeEndIndex, 8);
     }
     if ((HostEntity.CollisionRight() == ColliderType.Land) || (HostEntity.Location.X >= Core.I.CurrentMap.Size.X * 16 - 1))
     {
         HostEntity.Velocity.X = -_speed;
         HostEntity.SetAnime(_leftAnimeStartIndex, _leftAnimeEndIndex, 8);
     }
 }
Exemplo n.º 7
0
 public override void OnInit()
 {
     if (HostEntity.Parent.MainEntity.Location.X < HostEntity.Location.X)
     {
         HostEntity.Velocity.X = -_speed;
         HostEntity.SetAnime(_leftAnimeStartIndex, _leftAnimeEndIndex, 8);
     }
     else
     {
         HostEntity.Velocity.X = _speed;
         HostEntity.SetAnime(_rightAnimeStartIndex, _rightAnimeEndIndex, 8);
     }
     base.OnInit();
 }
Exemplo n.º 8
0
 public override void OnUpdate()
 {
     if ((HostEntity.CollisionLeft() == ColliderType.Land) || (HostEntity.Location.X <= 0))
     {
         HostEntity.Velocity.X = _speed;
         HostEntity.SetAnime(_rightAnimeStartIndex, _rightAnimeEndIndex, 8);
     }
     if ((HostEntity.CollisionRight() == ColliderType.Land) || (HostEntity.Location.X >= Core.I.CurrentMap.Size.X * 16 - 1))
     {
         HostEntity.Velocity.X = -_speed;
         HostEntity.SetAnime(_leftAnimeStartIndex, _leftAnimeEndIndex, 8);
     }
     HostEntity.Velocity.Y = (float)Math.Sin(_deg / 180.0 * Math.PI) * (HostEntity.Direction == Direction.Left ? -1 : 1);
     _deg = (_deg + 5) % 360;
 }
Exemplo n.º 9
0
        public static HostModel ToModel(this HostEntity entity)
        {
            if (entity == null)
            {
                return(null);
            }

            return(new HostModel
            {
                Id = entity.Id,
                Hostname = entity.Hostname,
                IpAddress = entity.IpAddress,
                MacAddress = entity.MacAddress,
                Netmask = entity.Netmask
            });
        }
Exemplo n.º 10
0
 private HostVulnerabilityEntity CreateHostVulnerability(
     int engagementId,
     int phaseId,
     HostEntity hostEntity,
     VulnerabilityEntity vulnerabilityEntity,
     ImportEntity importEntity)
 {
     return(new HostVulnerabilityEntity
     {
         EngagementId = engagementId,
         PhaseId = phaseId,
         Host = hostEntity,
         Vulnerability = vulnerabilityEntity,
         Import = importEntity
     });
 }
Exemplo n.º 11
0
        public override void ApplyOnMember(EntityModelBuilder builder)
        {
            var names = StringHelper.SplitNames(this.GroupNames);

            foreach (var name in names)
            {
                if (string.IsNullOrWhiteSpace(name))
                {
                    continue;
                }
                var grp = HostEntity.GetPropertyGroup(name, create: true);
                if (!grp.Members.Contains(HostMember))
                {
                    grp.Members.Add(HostMember);
                }
            } //foreach
        }
Exemplo n.º 12
0
        public override void ApplyOnEntity(EntityModelBuilder builder)
        {
            var names = StringHelper.SplitNames(this.MemberNames);

            foreach (var name in names)
            {
                var member = HostEntity.GetMember(name);
                if (member == null)
                {
                    builder.Log.Error("PropertyGroup '{0}', entity {1}: member {2} not found.", this.GroupName, HostEntity.Name, name);
                    return;
                }
                var grp = HostEntity.GetPropertyGroup(this.GroupName, create: true);
                if (!grp.Members.Contains(member))
                {
                    grp.Members.Add(member);
                }
            } //foreach
        }
Exemplo n.º 13
0
        /// <summary>
        /// Add a host
        /// </summary>
        /// <param name="Hostname"></param>
        /// <param name="IPAddress"></param>
        public void AddHost(string Hostname, string IPAddress)
        {
            // Create a host entity
            HostEntity host = new HostEntity();

            host.PartitionKey = IPAddress;
            host.RowKey       = Hostname;

            // Create the TableOperation object that inserts the host entity.
            TableOperation insertOperation = TableOperation.Insert(host);

            // Check if the host is already added.
            if (ExistsHost(IPAddress))
            {
                throw new Exception("Host already exists.");
            }

            // Execute the insert operation.
            var result = HostTable.ExecuteAsync(insertOperation).Result;
        }
Exemplo n.º 14
0
 public override void ApplyOnEntity(EntityModelBuilder builder)
 {
     if (this.MethodClass != null && this.MethodName != null)
     {
         _customMethodInfo = this.MethodClass.GetMethod(MethodName);
         if (_customMethodInfo == null)
         {
             builder.Log.Error("Method {0} specified as Display method for entity {1} not found in type {2}",
                               MethodName, HostEntity.EntityType, this.MethodClass);
             return;
         }
         HostEntity.DisplayMethod = InvokeCustomDisplay;
         return;
     }
     //Check if Format provided
     if (string.IsNullOrEmpty(this.Format))
     {
         builder.Log.Error("Invalid Display attribute on entity {0}. You must provide method reference or non-empty Format value.",
                           HostEntity.EntityType);
         return;
     }
     //Parse Format value, build argIndexes from referenced property names
     StringHelper.TryParseTemplate(this.Format, out _adjustedFormat, out _propNames);
     //verify and build arg indexes
     foreach (var prop in _propNames)
     {
         //it might be dotted sequence of props; we check only first property
         var propSeq = prop.SplitNames('.');
         var member  = HostEntity.GetMember(propSeq[0]);
         if (member == null)
         {
             builder.Log.Error("Invalid Format expression in Display attribute on entity {0}. Property {1} not found.",
                               HostEntity.EntityType, propSeq[0]);
             return;
         }
     }//foreach
     HostEntity.DisplayMethod = GetDisplayString;
 }
Exemplo n.º 15
0
        public override void OnUpdate()
        {
            if (((_nowstatus != 2) && (_nowstatus != 0) && (_tick == 15)) || (_tick == 30))
            {
                if (_nowstatus == 2 && Core.I.CurrentMap != null)
                {
                    DESound.Play(Sounds.ShootArrow);

                    var speed = HostEntity.Direction == Direction.Right ? Core.GetRand(4) + 1 : -Core.GetRand(4) - 1;
                    HostEntity.Parent.Add(Core.I.EntityRegistry.CreateEntity("Arrow",
                                                                             new Vector(HostEntity.Location.X + (HostEntity.Direction == Direction.Left ? 0 : HostEntity.Size.Width),
                                                                                        HostEntity.Location.Y + HostEntity.Size.Height / 2), Core.I.Tiles, Core.I.CurrentMap.Chips, HostEntity.Parent,
                                                                             DynamicJson.Parse("{\"Speed\": " + speed + " }")));
                }
                _tick      = -1;
                _nowstatus = (_nowstatus + 1) % 4;
            }
            if (HostEntity.Parent.MainEntity.Location.X < HostEntity.Location.X)
            {
                HostEntity.SetGraphic(_nowstatus + (HostEntity.Direction == Direction.Right ? 4 : 0));
            }
            _tick++;
        }
Exemplo n.º 16
0
        public override void OnUpdate()
        {
            _tick++;

            if (_tick > 60)
            {
                var atan =
                    (float)
                    Math.Atan2(HostEntity.Parent.MainEntity.Location.Y - HostEntity.Location.Y,
                               HostEntity.Parent.MainEntity.Location.X - HostEntity.Location.X);
                HostEntity.Velocity.X = (float)Math.Cos(atan);
                HostEntity.Velocity.Y = (float)Math.Sin(atan);
                _tick = 0;
            }
            if (HostEntity.Direction == Direction.Left)
            {
                HostEntity.SetAnime(_leftAnimeStartIndex, _leftAnimeEndIndex, 8);
            }
            else
            {
                HostEntity.SetAnime(_rightAnimeStartIndex, _rightAnimeEndIndex, 8);
            }
        }
Exemplo n.º 17
0
 public override void Init()
 {
     _attrAgent = HostEntity.GetComponent <AttrComponent>();
 }