Example #1
0
        public void OnStartCasting(IChampion owner, ISpell spell, IAttackableUnit target)
        {
            _owningSpell = spell;

            spell.AddProjectileTarget("KatarinaQ", target);

            if (!_listenerAdded)
            {
                ApiEventManager.OnHitUnit.AddListener(this, _owningChampion, OnProc);
                _listenerAdded = true;
            }

            foreach (var enemyTarget in GetUnitsInRange(target, 625, true))
            {
                if (enemyTarget != null && enemyTarget.Team == CustomConvert.GetEnemyTeam(owner.Team) && enemyTarget != target && enemyTarget != owner && target.GetDistanceTo(enemyTarget) < 100 && !UnitIsTurret((AttackableUnit)enemyTarget))
                {
                    CreateTimer(3.0f, () => {
                        if (!(enemyTarget.IsDead))
                        {
                            AddParticle(owner, "katarina_bouncingBlades_mis.troy", enemyTarget.X, enemyTarget.Y);
                        }
                        spell.AddProjectileTarget("KatarinaQMark", enemyTarget);
                    });
                }
            }

            //WE NEED A TIMER ON THE Q TO BE FIXED
        }
Example #2
0
        /// <summary>
        /// 解包过程
        /// </summary>
        public virtual void Unpackage()
        {
            if (package.Length < 3)
            {
                throw new MissingMemberException("Not enough members.");
            }
            index = 0;
            ProtocolRevisionNumber = package[index];
            index += 1;

            var temp = new byte[2];

            Buffer.BlockCopy(package, index, temp, 0, 2);
            temp = CustomConvert.reserve(temp);
            OverallMessageLength = BitConverter.ToUInt16(temp, 0);
            index += 2;

            if (package.Length < OverallMessageLength + HEADER_SIZE)
            {
                throw new MissingFieldException("Not enough fields.");
            }

            content = new byte[OverallMessageLength];
            Buffer.BlockCopy(package, index, content, 0, OverallMessageLength);
            index += OverallMessageLength;
        }
Example #3
0
        /// <summary>
        /// 手动发送一条铱星数据
        /// </summary>
        private void IridiumManualSend()
        {
            //if (_iridium.ShowPackageInformation)
            {
                ShowHistory(Environment.NewLine + Now + "MT operation begin, try to connect Iridium server...", false);
            }
            tsbtSend.Enabled = false;
            SendIMEI         = tscbIMEI.Text.Trim();
            if (string.IsNullOrEmpty(tstbData.Text.Trim()))
            {
                SendContent = null;
            }
            else
            {
                SendContent = CustomConvert.GetBytes(tstbData.Text.Trim());
            }
            SendMTMSN = mtmsn++;
            performSend();
            Task task = new Task(() =>
            {
                Thread.Sleep(5000);
                BeginInvoke((MyInvoker) delegate
                {
                    tsbtSend.Enabled = true;
                });
            });

            task.Start();
        }
Example #4
0
        public void notifySpawn(Unit u)
        {
            var m = u as Minion;

            if (m != null)
            {
                notifyMinionSpawned(m, CustomConvert.getEnemyTeam(m.getTeam()));
            }

            var c = u as Champion;

            if (c != null)
            {
                notifyChampionSpawned(c, CustomConvert.getEnemyTeam(c.getTeam()));
            }

            var monster = u as Monster;

            if (monster != null)
            {
                notifyMonsterSpawned(monster);
            }

            notifySetHealth(u);
        }
Example #5
0
        public override void Execute(Peer peer, bool hasReceivedArguments, string arguments = "")
        {
            var split = arguments.ToLower().Split(' ');

            if (split.Length < 2)
            {
                ChatCommandManager.SendDebugMsgFormatted(DebugMsgType.SYNTAXERROR);
                ShowSyntax();
                return;
            }
            int team;

            if (!int.TryParse(split[1], out team))
            {
                return;
            }

            var units = _game.ObjectManager.GetObjects()
                        .Where(xx => xx.Value.Team == CustomConvert.ToTeamId(team))
                        .Where(xx => xx.Value is Minion || xx.Value is Monster);

            foreach (var unit in units)
            {
                var ping     = new AttentionPingRequest(unit.Value.X, unit.Value.Y, 0, Pings.Ping_Danger);
                var client   = _playerManager.GetPeerInfo(peer);
                var response = new AttentionPingResponse(client, ping);
                _game.PacketHandlerManager.broadcastPacketTeam(client.Team, response, Channel.CHL_S2C);
            }
        }
Example #6
0
        protected void updateProfile_Click(object sender, EventArgs e)
        {
            User = UserService.Get(CustomConvert.ToInt32(RouteData.Values["userId"]));

            if (SecurityContext.User.Id == User.Id)
            {
                try
                {
                    if (this.profileImageUpload.HasFile)
                    {
                        var profileImage = Image.FromStream(this.profileImageUpload.FileContent);
                        UserService.SetProfilePicture(User, profileImage);
                    }

                    User.UpdateProfile(this.firstName.Text, this.lastName.Text);

                    UserService.Update(User);
                    UserService.CommitChanges();
                    Response.RedirectToRoute("Profile", new { userId = User.Id });
                }
                catch (Exception exception)
                {
                    //handle exception
                    this.message.InnerText = GenericErrorMessage;
                    this.message.Visible   = true;
                }
            }
            else
            {
                Response.RedirectToRoute("NotFound", null);
            }
        }
        public void OnFinishCasting(IObjAiBase owner, ISpell spell, IAttackableUnit target)
        {
            IGameObject m             = AddParticle(owner, "Karthus_Base_Q_Explosion.troy", spell.X, spell.Y);
            var         affectedUnits = GetUnitsInRange(m, 150, true);
            var         ap            = owner.Stats.AbilityPower.Total;
            var         damage        = 20f + spell.Level * 20f + ap * 0.3f;

            if (affectedUnits.Count == 0)
            {
                AddParticle(owner, "Karthus_Base_Q_Hit_Miss.troy", spell.X, spell.Y);
            }
            foreach (var unit in affectedUnits
                     .Where(x => x.Team == CustomConvert.GetEnemyTeam(owner.Team)))
            {
                if (unit is IChampion || unit is IMinion)
                {
                    if (affectedUnits.Count == 1)
                    {
                        damage *= 2;
                        AddParticle(owner, "Karthus_Base_Q_Hit_Single.troy", spell.X, spell.Y);
                        unit.TakeDamage(owner, damage, DamageType.DAMAGE_TYPE_MAGICAL, DamageSource.DAMAGE_SOURCE_SPELL, true);
                    }
                    if (affectedUnits.Count > 1)
                    {
                        AddParticle(owner, "Karthus_Base_Q_Hit_Many.troy", spell.X, spell.Y);
                        unit.TakeDamage(owner, damage, DamageType.DAMAGE_TYPE_MAGICAL, DamageSource.DAMAGE_SOURCE_SPELL, false);
                    }
                }
            }
            m.SetToRemove();
            AddParticle(owner, "Karthus_Base_Q_Explosion_Sound.troy", spell.X, spell.Y);
        }
Example #8
0
        public void OnFinishCasting(IObjAiBase owner, ISpell spell, IAttackableUnit target)
        {
            var armor  = owner.Stats.Armor.Total;
            var damage = spell.Level * 40 + armor * 0.2f;
            var reduce = spell.Level * 5 + armor * 0.05f;

            AddParticleTarget(owner, "Shatter_nova.troy", owner, 1);

            foreach (var enemy in GetUnitsInRange(owner, 375, true)
                     .Where(x => x.Team == CustomConvert.GetEnemyTeam(owner.Team)))
            {
                var hasbuff = HasBuff((IObjAiBase)enemy, "TaricWDis");
                if (enemy is IObjAiBase)
                {
                    enemy.TakeDamage(owner, damage, DamageType.DAMAGE_TYPE_MAGICAL, DamageSource.DAMAGE_SOURCE_SPELL, false);
                    var p2 = AddParticleTarget(owner, "Shatter_tar.troy", enemy, 1);
                    AddBuff("TaricWDis", 4.0f, 1, spell, (IObjAiBase)enemy, owner);

                    if (hasbuff == true)
                    {
                        return;
                    }
                    if (hasbuff == false)
                    {
                        enemy.Stats.Armor.FlatBonus -= reduce;
                    }

                    CreateTimer(4f, () =>
                    {
                        enemy.Stats.Armor.FlatBonus += reduce;
                        RemoveParticle(p2);
                    });
                }
            }
        }
Example #9
0
        /// <summary>
        /// 解析通信申请数据包
        /// </summary>
        public override void Unpackage()
        {
            base.Unpackage();
            var index = 0;

            if (null == _type)
            {
                _type = new TXSQ_Type();
            }
            _type.Type = Data[index];
            index     += 1;

            //_target = new byte[UserAddressSize];
            Buffer.BlockCopy(Data, index, _target, 0, UserAddressSize);
            index += UserAddressSize;

            var data = new byte[2];

            Buffer.BlockCopy(Data, index, data, 0, 2);
            data        = CustomConvert.reserve(data);
            MessageSize = BitConverter.ToUInt16(data, 0);
            index      += Marshal.SizeOf(MessageSize);

            Reply  = Data[index];
            index += 1;

            var len = MessageSize / 8;

            _message = new byte[len];
            Buffer.BlockCopy(Data, index, _message, 0, len);
            index += len;
        }
Example #10
0
        /// <summary>
        /// 解析数据包
        /// </summary>
        public virtual void Unpackage()
        {
            if (null == _content)
            {
                throw new Exception("Cannot unpackage null data.");
            }
            var len = _content.Length;

            if (len < (CommandSize + UserAddressSize + Marshal.SizeOf(TotalSize)))
            {
                throw new Exception("Data length is to short.");
            }
            var index = 0;

            Command = ASCIIEncoding.ASCII.GetString(_content, index, CommandSize);
            index  += CommandSize;

            var data = new byte[2];

            Buffer.BlockCopy(_content, index, data, 0, 2);
            data      = CustomConvert.reserve(data);
            TotalSize = BitConverter.ToUInt16(data, 0);
            index    += Marshal.SizeOf(TotalSize);

            _origin = new byte[UserAddressSize];
            Buffer.BlockCopy(_content, index, _origin, 0, UserAddressSize);
            index += UserAddressSize;

            // 数据长度=总长度-命令字长度-总长度size-用户地址长度-校验和长度
            _data = new byte[TotalSize - CommandSize - Marshal.SizeOf(TotalSize) - UserAddressSize - 1];
            Buffer.BlockCopy(_content, index, _data, 0, _data.Length);
            index += _data.Length;

            Xor = _content[index];
        }
Example #11
0
        /// <summary>
        /// 打包数据长度
        /// </summary>
        /// <param name="len"></param>
        protected void PackageTotalSize(ushort len)
        {
            var data = BitConverter.GetBytes(len);

            data = CustomConvert.reserve(data);
            Buffer.BlockCopy(data, 0, Content, 5, 2);
        }
Example #12
0
        /// <summary>
        /// 解包定位信息
        /// </summary>
        public void Unpackate()
        {
            var nsew = CustomConvert.IntToDigit(latlng[0], CustomConvert.BIN, 8);

            //nsew = CustomConvert.reserve(nsew);
            report = (byte)(nsew[7] == '1' ? 1 : 0);
            eng    = (byte)(nsew[6] == '1' ? 1 : 0);
            NSI    = nsew[1] == '1' ? 'S' : 'N';
            EWI    = nsew[0] == '1' ? 'W' : 'E';

            Latitude = latlng[1];
            byte[] tmp = new byte[2];
            Buffer.BlockCopy(latlng, 2, tmp, 0, 2);
            //tmp = CustomConvert.reserve(tmp);

            var    u16 = BitConverter.ToUInt16(tmp, 0);
            double mm  = u16 / Math.Pow(10, u16.ToString().Length);

            // 将ddmmmm转换成dd.dddd
            //mm = Wbs.Protocol.TX300.Analyse.GPSInfo.DDMM2DDDD(mm);
            Latitude += mm;

            Longitude = latlng[4];
            Buffer.BlockCopy(latlng, 5, tmp, 0, 2);
            //tmp = CustomConvert.reserve(tmp);
            u16 = BitConverter.ToUInt16(tmp, 0);
            mm  = u16 / Math.Pow(10, u16.ToString().Length);
            // 将ddmmmm转换成dd.dddd
            //mm = Wbs.Protocol.TX300.Analyse.GPSInfo.DDMM2DDDD(mm);
            Longitude += mm;
        }
Example #13
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                var navigation = new List <Tuple <string, string> >();
                int topicId    = CustomConvert.ToInt32(RouteData.Values["topicId"]);
                var topic      = TopicService.Get(topicId);

                if (topic == null)
                {
                    Response.RedirectToRoute("NotFound", null);
                }
                else
                {
                    navigation.Add(Tuple.Create(GetRouteUrl("Default", null), "Acasa"));
                    navigation.Add(Tuple.Create(GetRouteUrl("SubjectTopics", new { subjectId = topic.Subject.Id }), topic.Subject.Name));
                    navigation.Add(Tuple.Create(GetRouteUrl("TopicPosts", new { topicId = topic.Id }), topic.Name));
                    Session["Navigation"] = navigation;

                    this.topicId.Value = topicId.ToString();
                    this.sortByDropDownList.DataSource = new List <object>
                    {
                        new { Value = "0", Text = "Data descrescator" },
                        new { Value = "1", Text = "Data crescator" },
                        new { Value = "2", Text = "Autor descrescator" },
                        new { Value = "3", Text = "Autor crescator" }
                    };
                    this.sortByDropDownList.DataValueField = "Value";
                    this.sortByDropDownList.DataTextField  = "Text";
                    this.sortByDropDownList.DataBind();
                    DataBind();
                }
            }
        }
        protected void usersGridView_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            var userId       = this.usersGridView.DataKeys[e.RowIndex].Value;
            var user         = UserService.Get(CustomConvert.ToInt32(userId));
            var roleDropDown = this.usersGridView.Rows[e.RowIndex].FindControl("roleDropDown") as DropDownList;

            if (!SecurityContext.IsAdmin)
            {
                throw new NotAuthorizedException();
            }

            if (user != null)
            {
                try
                {
                    this.usersGridView.EditIndex = -1;
                    user.SetRole((Role)int.Parse(roleDropDown.SelectedValue));
                    UserService.Update(user);
                    UserService.CommitChanges();
                    DataBind();
                }
                catch (Exception execption)
                {
                    //handle exception
                    this.message.InnerText = GenericErrorMessage;
                    this.message.Visible   = true;
                }
            }
        }
Example #15
0
        /// <summary>
        /// 文字列を <see cref="HardwareInput"/> クラスのインスタンスに変換する
        /// 変換できない場合はNULLを返却する
        /// </summary>
        /// <param name="value">
        /// <see cref="HardwareInput"/> クラスのインスタンスに変換する文字列
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// 引数の <paramref name="value"/> がNULLの場合に発生
        /// </exception>
        /// <returns>
        /// 文字列から生成した<see cref="HardwareInput"/> クラスのインスタンス
        /// 変換できない場合はNULLを返却する
        /// </returns>
        public HardwareInput ConvertFromString(string value)
        {
            // 引数の型チェック
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            // カンマ区切りをSplitして各パラメータを取得する
            string[] param = value.Split(',');

            // Splitした結果、要素数3未満の配列の場合は過不足があり変換ができないためNULLを返却する
            if (param.Length < 3)
            {
                return(null);
            }

            // 変換処理を行う、変換に失敗した場合はNULLを返却
            if (!CustomConvert.TryHexStringToInt(param[0], out int message) ||
                !CustomConvert.TryHexStringToShort(param[1], out short lowlParam) ||
                !CustomConvert.TryHexStringToShort(param[2], out short highlParam))
            {
                return(null);
            }

            // HardwareInputクラスのインスタンスを生成し返却
            return(new HardwareInput(message, lowlParam, highlParam));
        }
        private void Handle0x7030(TX300 obj, TB_Tracker tracker)
        {
            _0x7030 x7030 = new _0x7030();

            x7030.Content = obj.MsgContent;
            x7030.Unpackage();
            string provider = "gps";
            var    bin      = "0000000000000000";

            if (obj.TerminalType == TerminalTypes.TX10GAPP)
            {
                bin = CustomConvert.IntToDigit(obj.PackageID, CustomConvert.BIN, 8) +
                      CustomConvert.IntToDigit(obj.TotalPackage, CustomConvert.BIN, 8);
            }
            int cnt = 0;

            foreach (var pos in x7030.Positions)
            {
                if (pos.Available)
                {
                    provider = GetTrackerProvider(bin[cnt]);//bin[cnt] == '0' ? "gps" : "network";
                    SaveTrackerPosition(obj.TerminalID, (null == tracker ? "" : tracker.CarNumber),
                                        (null == tracker ? -1 : tracker.id), provider, pos, "Tracking", tracker.LastActionAt.Value);
                }
                cnt++;
            }
        }
        protected void usersGridView_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {
                e.Row.TableSection = TableRowSection.TableHeader;
            }

            if (e.Row.RowType == DataControlRowType.DataRow &&
                (e.Row.RowState & DataControlRowState.Edit) == DataControlRowState.Edit)
            {
                var userId        = this.usersGridView.DataKeys[e.Row.RowIndex].Value;
                var user          = UserService.Get(CustomConvert.ToInt32(userId));
                var roleDropDrown = e.Row.FindControl("roleDropDown") as DropDownList;

                roleDropDrown.DataSource = new List <object>
                {
                    new { Value = (int)Role.Normal, Text = Role.Normal.ToString() },
                    new { Value = (int)Role.Manager, Text = Role.Manager.ToString() },
                    new { Value = (int)Role.Admin, Text = Role.Admin.ToString() }
                };

                roleDropDrown.DataValueField = "Value";
                roleDropDrown.DataTextField  = "Text";
                roleDropDrown.DataBind();
                roleDropDrown.SelectedIndex = (int)user.Role;
            }
        }
Example #18
0
        /// <summary>
        /// See interface docs.
        /// </summary>
        /// <param name="icao24"></param>
        /// <returns></returns>
        public CodeBlock FindCodeBlock(string icao24)
        {
            CodeBlock result = null;

            if (!String.IsNullOrEmpty(icao24))
            {
                int icaoValue = CustomConvert.Icao24(icao24);
                if (icaoValue != -1)
                {
                    List <CodeBlockBitMask> codeBlockCache;
                    lock (_CodeBlockCacheLock) {
                        codeBlockCache = _CodeBlockCache;
                    }

                    foreach (var entry in codeBlockCache)
                    {
                        if (entry.CodeMatches(icaoValue))
                        {
                            result = entry.CodeBlock;
                            break;
                        }
                    }
                    if (result == null && _FilesValid)
                    {
                        result = new CodeBlock();
                    }
                }
            }

            return(result);
        }
Example #19
0
        private void PreviousAircraftFromPostBody(AircraftListJsonBuilderArgs args)
        {
            var bodyStream = PipelineContext.Request.Body;

            if (bodyStream != null && bodyStream != Stream.Null)
            {
                using (var reader = new StreamReader(bodyStream)) {
                    var content = reader.ReadToEnd()?.Trim();
                    if (!String.IsNullOrEmpty(content))
                    {
                        var icaosIdx = content.IndexOf("icaos=", StringComparison.OrdinalIgnoreCase);
                        var icaos    = icaosIdx == -1 ? "" : content.Substring(icaosIdx + 6).Trim();

                        if (!String.IsNullOrEmpty(icaos))
                        {
                            foreach (var icao in icaos.Split('-'))
                            {
                                var id = CustomConvert.Icao24(icao);
                                if (id != -1)
                                {
                                    args.PreviousAircraft.Add(id);
                                }
                            }
                        }
                    }
                }
            }
        }
Example #20
0
        protected object GetTopics()
        {
            try
            {
                var result = SubjectService.Get(CustomConvert.ToInt32(this.subjectId.Value), x => x.Topics.Select(y => y.CreatedBy))?.Topics
                             .OrderByDescending(x => x.CreatedAt)
                             .Select(x => (object)new
                {
                    Id            = x.Id,
                    CreatedAt     = x.CreatedAt,
                    CreatedBy     = x.CreatedBy,
                    Name          = x.Name,
                    NumberOfPosts = x.Posts.Count,
                    PostsUrl      = GetRouteUrl("TopicPosts", new { topicId = x.Id }),
                    CanEdit       = SecurityContext.IsAuthenticated && (x.CreatedBy == SecurityContext.User || SecurityContext.IsManager),
                    CanDelete     = SecurityContext.IsManager || SecurityContext.IsAdmin
                }).ToList();

                return(result);
            }
            catch (Exception exception)
            {
                //handle exception
                return(null);
            }
        }
Example #21
0
        protected void topicsListView_ItemInserting(object sender, ListViewInsertEventArgs e)
        {
            var topicNameTextBox = this.topicsListView.InsertItem.FindControl("name") as TextBox;

            if (!SecurityContext.IsAuthenticated)
            {
                throw new NotAuthorizedException();
            }

            try
            {
                var subject = SubjectService.Get(CustomConvert.ToInt32(this.subjectId.Value));
                var topic   = new Topic(topicNameTextBox.Text, subject, SecurityContext.User);

                TopicService.Create(topic);
                TopicService.CommitChanges();
                Response.RedirectToRoute("SubjectTopics", new { subjectId = this.subjectId.Value });
            }
            catch
            {
                //handle exception
                this.message.InnerText = GenericErrorMessage;
                this.message.Visible   = true;
            }
        }
Example #22
0
        public void NotifyGameEnd(Nexus nexus)
        {
            var losingTeam = nexus.Team;

            foreach (var p in _playerManager.GetPlayers())
            {
                var coords = _game.Map.GetEndGameCameraPosition(losingTeam);
                var cam    = new MoveCamera(p.Item2.Champion, coords[0], coords[1], coords[2], 2);
                _game.PacketHandlerManager.sendPacket(p.Item2.Peer, cam, Channel.CHL_S2C);
                _game.PacketHandlerManager.sendPacket(p.Item2.Peer, new HideUi(), Channel.CHL_S2C);
            }
            _game.PacketHandlerManager.broadcastPacket(new ExplodeNexus(nexus), Channel.CHL_S2C);

            var timer = new System.Timers.Timer(5000);

            timer.AutoReset = false;
            timer.Elapsed  += (a, b) =>
            {
                var win = new GameEnd(true);
                _game.PacketHandlerManager.broadcastPacketTeam(CustomConvert.getEnemyTeam(losingTeam), win, Channel.CHL_S2C);
                var lose = new GameEnd(false);
                _game.PacketHandlerManager.broadcastPacketTeam(losingTeam, lose, Channel.CHL_S2C);
            };
            timer.Start();
        }
Example #23
0
        /// <summary>
        /// 组包
        /// </summary>
        /// <param name="args"></param>
        public void ResizeData(SocketAsyncEventArgs args)
        {
            var len = audb_buffer.Length;

            audb_buffer = CustomConvert.expand(audb_buffer, len + args.BytesTransferred);
            System.Buffer.BlockCopy(args.Buffer, args.Offset, audb_buffer, len, args.BytesTransferred);
        }
Example #24
0
        /// <summary>
        /// 扩展组包收到的UDP数据
        /// </summary>
        /// <param name="buffer"></param>
        /// <param name="len"></param>
        public void ResizeData(byte[] buffer, int len)
        {
            var old = audb_buffer.Length;

            audb_buffer = CustomConvert.expand(audb_buffer, old + len);
            System.Buffer.BlockCopy(buffer, 0, audb_buffer, old, len);
        }
Example #25
0
 public void CustomConvert_Icao24_Is_Case_Insensitive()
 {
     Assert.AreEqual(1223476, CustomConvert.Icao24("12AB34"));
     Assert.AreEqual(1223476, CustomConvert.Icao24("12ab34"));
     Assert.AreEqual(1223476, CustomConvert.Icao24("12Ab34"));
     Assert.AreEqual(1223476, CustomConvert.Icao24("12aB34"));
 }
Example #26
0
 public void CustomConvert_Icao24_Six_Digit_Hex_Codes_Are_Valid()
 {
     Assert.AreEqual(0, CustomConvert.Icao24("000000"));
     Assert.AreEqual(1193046, CustomConvert.Icao24("123456"));
     Assert.AreEqual(11259375, CustomConvert.Icao24("ABCDEF"));
     Assert.AreEqual(16777215, CustomConvert.Icao24("FFFFFF"));
 }
Example #27
0
        protected void postsView_ItemUpdating(object sender, ListViewUpdateEventArgs e)
        {
            var postTextBox = this.postsListView.EditItem.FindControl("Text") as TextBox;
            var postIdField = this.postsListView.EditItem.FindControl("Id") as HiddenField;
            var post        = PostService.Get(CustomConvert.ToInt32(postIdField.Value));

            if (post.CreatedBy != SecurityContext.User)
            {
                throw new NotAuthorizedException();
            }

            try
            {
                post.Edit(postTextBox.Text);
                PostService.Update(post);
                PostService.CommitChanges();
                Response.RedirectToRoute("TopicPosts", new { topicId = this.topicId.Value });
            }
            catch
            {
                //handle exception
                this.message.InnerText = GenericErrorMessage;
                this.message.Visible   = true;
            }
        }
Example #28
0
        private void Handle0x3000(TX300 obj, TB_Equipment equipment, TB_Terminal terminal)
        {
            _0x3000 x3000 = new _0x3000();

            x3000.Content = obj.MsgContent;
            x3000.Unpackage();
            if (null != equipment)
            {
                using (var bll = new EquipmentBLL())
                {
                    bll.Update(f => f.id == equipment.id, act =>
                    {
                        act.LockStatus = CustomConvert.GetHex(x3000.Type);
                        // 存储锁车状态
                        act.LockEffected = (byte)((x3000.Type == 0x40 || x3000.Type == 0x0F || x3000.Type == 0xFF) ? 1 : 0);
                        if (x3000.GPSInfo.Available)
                        {
                            act.Latitude   = x3000.GPSInfo.Latitude;
                            act.Longitude  = x3000.GPSInfo.Longitude;
                            act.GpsUpdated = false;
                        }
                    });
                }
            }
            if (x3000.GPSInfo.Available)
            {
                SaveGpsInfo(x3000.GPSInfo, equipment, obj.TerminalID, ("Security: " + x3000.Flag + GetPackageType(obj.ProtocolType)));
            }
        }
Example #29
0
        /// <summary>
        /// 处理收到的数据
        /// </summary>
        /// <param name="data"></param>
        public void HandleData(AsyncUserDataBuffer data)
        {
            try
            {
                //if (data.PackageType == AsyncDataPackageType.UDP)
                {
                    IP   = data.IP;
                    Port = data.Port;
                }
                bool handled = false;
                switch (data.DataType)
                {
                case AsyncUserDataType.ClientConnected: break;

                case AsyncUserDataType.ClientDisconnected:
                    // 处理客户端断开连接的情况
                    HandleClientDisconnect(data.SocketHandle);
                    break;

                case AsyncUserDataType.ReceivedData:
                    var len = data.Buffer.Length;
                    // 如果收到的数据长度小于TX300的包头则不用处理数据了
                    if (len >= Protocol.TX300.TX300Items.header_length && Protocol.ProtocolTypes.IsTX300(data.Buffer[2]) && Protocol.TerminalTypes.IsTX300(data.Buffer[3]))
                    {
                        handled = true;
                        if (data.Buffer[0] != len)
                        {
                            HandleException("Data length(package length: " + data.Buffer[0] + ", buffer length: " + len + ") error.", CustomConvert.GetHex(data.Buffer));
                        }
                        else
                        {
                            HandleReceivedData(data);
                        }
                    }
                    else
                    {
                        // 增加未能处理的数据保存   2015/09/02 15:09
                        HandleException("Data is not TX protocol.", CustomConvert.GetHex(data.Buffer));
                    }
                    break;
                }
                if (data.PackageType == AsyncDataPackageType.SAT)
                {
                    if (!handled)
                    {
                    }
                    data.Dispose();
                    data = null;
                }
            }
            catch (Exception e)
            {
                ShowUnhandledMessage(Now + e.Message + Environment.NewLine +
                                     e.StackTrace + Environment.NewLine + CustomConvert.GetHex(data.Buffer));
                HandleException(e.Message + Environment.NewLine + e.StackTrace, CustomConvert.GetHex(data.Buffer));
            }
            IP   = "";
            Port = 0;
        }
Example #30
0
        private void spPort_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
        {
            if (sender.GetType() != typeof(System.IO.Ports.SerialPort))
            {
                return;
            }

            if (hasClosed)
            {
                return;
            }

            byte[]     bReceived = null;
            SerialPort comp      = (System.IO.Ports.SerialPort)sender;

            try
            {
                comp.ReceivedBytesThreshold = comp.ReadBufferSize;
                while (true)
                {
                    int len = comp.BytesToRead;
                    if (len > 0)
                    {
                        byte[] b = new byte[len];
                        comp.Read(b, 0, len);

                        if (bReceived == null)
                        {
                            bReceived = new byte[len];
                        }
                        else
                        {
                            bReceived = CustomConvert.expand(bReceived, bReceived.Length + len);
                        }
                        Buffer.BlockCopy(b, 0, bReceived, bReceived.Length - len, len);

                        Win32.TimeDelay(50);
                    }
                    else
                    {
                        break;
                    }
                }
            }
            catch (Exception readError)
            {
                ShowHistory("Cannot read data from \"" + comp.PortName + "\": " + readError.Message);
            }
            finally
            {
                comp.ReceivedBytesThreshold = 1;
            }
            if (bReceived == null)
            {
                return;
            }

            HandleReceivedData(bReceived);
        }