示例#1
0
        private void AddPackage(HostAndPort host, BasePackage package)
        {
            HostReceive receive;

            if (hostQueue.TryGetValue(host.Host + host.Port, out receive))
            {
                if (receive.IsShut)
                {
                    hostQueue.TryRemove(host.Host + host.Port, out receive);
                    AddPackage(host, package);
                    return;
                }
                receive.Add(package);
                receive.LastUseTime = receive.CountTime;
            }
            else
            {
                receive = new HostReceive(senderSession)
                {
                    Host = host
                };
                receive.dataNotify += ReceiveData;
                receive.Add(package);
                hostQueue[host.Host + host.Port] = receive;
                receive.LastUseTime = receive.CountTime;//记录使用
            }
        }
示例#2
0
        public static BaseObject Link(NamespaceMapping aPckg, TypeMapping aType)
        {
            if (!aType.HasClassifier())
            {
                return(null);
            }
            string    aKey = aType.FullName; //aPckg.FullName + "::" + aType.FullName;
            ProperRef ref2 = (ProperRef)_tabRefs[aKey];

            if (ref2 != null)
            {
                return(ref2._obj);
            }
            Classifier  anObj      = aType.Classifier;
            BasePackage newPackage = aPckg.Package;
            BasePackage package    = (BasePackage)anObj.Package;

            if (newPackage.ObjectID == package.ObjectID)
            {
                ref2 = new ProperRef(aKey, anObj);
                return(anObj);
            }
            BaseObject obj2 = anObj.CreateShortcut(newPackage, "");

            ref2 = new ProperRef(aKey, obj2);
            return(obj2);
        }
示例#3
0
        public void OnUpdateAction(BasePackage package, UpdateAction[] acts)
        {
            foreach (var act in acts)
            {
                switch (act.Type)
                {
                case UpdateAction.ActionType.Init:
                    Init();
                    break;

                case UpdateAction.ActionType.Add:
                    UpdateItem(act.Index, package.GetItemAt <ItemData>(act.Index));
                    break;

                case UpdateAction.ActionType.Remove:
                    UpdateItem(act.Index, package.GetItemAt <ItemData>(act.Index));
                    break;

                case UpdateAction.ActionType.UpdateCount:
                    UpdateItem(act.Index, package.GetItemAt <ItemData>(act.Index));
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
        }
示例#4
0
        /// <summary>
        /// Enqueue the package in the message queue to send this to the server.
        /// </summary>
        /// <param name="package">Package to send (must inherit <see cref="BasePackage"/>).</param>
        public void EnqueueDataForWrite(BasePackage package)
        {
            if (!TcpClient.Connected)
            {
                throw new InvalidOperationException("You're not connected!");
            }

            var packageBytes = BasePackage.Serialize(package);

            var length      = packageBytes.Length;
            var lengthBytes = BitConverter.GetBytes(length);

            PendingDataToWrite.Enqueue(lengthBytes);
            PendingDataToWrite.Enqueue(packageBytes);

            lock (PendingDataToWrite)
            {
                if (SendingData)
                {
                    return;
                }

                SendingData = true;
            }

            WriteData();
        }
示例#5
0
        /// <summary>
        /// Loads all Available Description Files in the Package
        /// </summary>
        protected void LoadDescriptions()
        {
            bysimid    = new Hashtable();
            byinstance = new Hashtable();
            bool didwarndoubleguid = false;

            if (BasePackage == null)
            {
                return;
            }

            IPackedFileDescriptor[] files = BasePackage.FindFiles(Data.MetaData.SIM_DESCRIPTION_FILE);

            foreach (IPackedFileDescriptor pfd in files)
            {
                //SDesc sdesc = new SDesc(this.names, this.famnames, this);
                LinkedSDesc sdesc = new LinkedSDesc();
                sdesc.ProcessData(pfd, BasePackage);

                if (bysimid.ContainsKey((uint)sdesc.SimId) || byinstance.ContainsKey((ushort)sdesc.Instance))
                {
                    if (!didwarndoubleguid)
                    {
                        Helper.ExceptionMessage(new Warning("A Sim was found Twice!", "The Sim with GUID 0x" + Helper.HexString(sdesc.SimId) + " (inst=0x" + Helper.HexString(sdesc.Instance) + ") exists more than once. This could result in  Problems during the Gameplay!"));
                        didwarndoubleguid = true;
                    }
                }

                bysimid[(uint)sdesc.SimId]         = sdesc;
                byinstance[(ushort)sdesc.Instance] = sdesc;
            }
        }
示例#6
0
 public override List<BaseResponse> Decode(BasePackage bp, OriginalBytes obytes)
 {
     Cabinet cabinet = SpringHelper.GetObject<Cabinet>("cabinet");
     if (bp.AppData.Length == 48)//应用数据(48)
     {
         List<BaseResponse> list = new List<BaseResponse>();
         for (byte rackNo = 2; rackNo <= 5; rackNo++)//除系统机笼
         {
             for (byte slotNo = 3; slotNo <= 14; slotNo++)
             {
                 BoardStatusResponse boardStatusResponse = new BoardStatusResponse();
                 boardStatusResponse.CommunicatinBoard = cabinet.GetCommunicationBoard(bp.RemoteIpEndPoint);
                 boardStatusResponse.DtTime = DateTime.Now;
                 boardStatusResponse.OriginalBytes = obytes;
                 byte[] eqid = new byte[] { 0x05, rackNo, slotNo, 0xFF, 0xFF };
                 Board b = cabinet.FindEq(eqid) as Board;
                 if (b != null)
                 {
                     boardStatusResponse.Board = b;
                     boardStatusResponse.ErrorCode = bp.AppData[(rackNo - 2) * 12 + (slotNo - 3)];
                     list.Add(boardStatusResponse);
                 }
             }
         }
         return list;
     }
     return null;
 }
示例#7
0
 private NamespaceMapping(string aName, BasePackage aPckg)
 {
     this._pdPckg = aPckg;
     this._name   = aName;
     _tabNmsp.Add(aName, this);
     _idxNmsp.Add(aPckg, this);
 }
 private NamespaceMapping(string aName, BasePackage aPckg)
 {
     this._pdPckg = aPckg;
     this._name = aName;
     _tabNmsp.Add(aName, this);
     _idxNmsp.Add(aPckg, this);
 }
 public Task SaveModelAsync(IStorageFile modelFile)
 {
     if (BasePackage == null)
     {
         throw new InvalidOperationException($"{nameof(BasePackage)} is null");
     }
     return(BasePackage.SaveModelAsync(modelFile));
 }
 public Task RemoveTagAsync(Guid tagId)
 {
     if (BasePackage == null)
     {
         throw new InvalidOperationException($"{nameof(BasePackage)} is null");
     }
     return(BasePackage.RemoveTagAsync(tagId));
 }
 public Task <IDictionary <string, float> > EvaluateAsync(IList <InkStroke> strokes, float threshold = 0)
 {
     if (BasePackage == null)
     {
         throw new InvalidOperationException($"{nameof(BasePackage)} is null");
     }
     return(BasePackage.EvaluateAsync(strokes, threshold));
 }
示例#12
0
 public static NamespaceMapping Retrieve(BasePackage aPckg)
 {
     if (aPckg == null)
     {
         _idxNmsp.Count.ToString();
     }
     return (NamespaceMapping) _idxNmsp[aPckg];
 }
示例#13
0
 public static NamespaceMapping Retrieve(BasePackage aPckg)
 {
     if (aPckg == null)
     {
         _idxNmsp.Count.ToString();
     }
     return((NamespaceMapping)_idxNmsp[aPckg]);
 }
示例#14
0
        /// <summary>
        /// 发送关闭信息
        /// </summary>
        /// <param name="package"></param>
        internal void SendShut(BasePackage package)
        {
            ShutDownPackage shut = new ShutDownPackage()
            {
                DestHost = package.DestHost, DestPort = package.DestPort, PackID = package.PackID, direction = 1
            };

            this.SocketStream.Write(shut.DestHost, shut.DestPort, shut.GetBuffer());
        }
示例#15
0
 public virtual BasePackage Encode()
 {
     BasePackage bp = new BasePackage();
     bp.RemoteIpEndPoint = Board.CommunicationIP;
     bp.ProtocolVersion = 0x01;
     bp.CycleNo = GetNextSequence(Board);
     bp.ErrorStatus = 0x00;
     return bp;
 }
        public Task AddTagAsync(Guid tagId, string tagName)
        {
            if (BasePackage == null)
            {
                throw new InvalidOperationException($"{nameof(BasePackage)} is null");
            }

            return(BasePackage.AddTagAsync(tagId, tagName));
        }
        public Task SaveAsync()
        {
            if (BasePackage == null)
            {
                throw new InvalidOperationException($"{nameof(BasePackage)} is null");
            }

            return(BasePackage.SaveAsync());
        }
示例#18
0
 public PackageTests()
 {
     _basePackage = new BasePackage(AppDomain.CurrentDomain.BaseDirectory.TrimEnd('\\'));
     _basePackage.AddPackage("std", null);
     _basePackage.AddPackage("base2", null);
     _basePackage.AddPackage("std.vector", "lib\\vector.lll");
     _basePackage.AddPackage("std.fixedarray", "lib\\fixedarray.lll");
     _basePackage.AddPackage("std.test", "lib\\test.lll");
     _basePackage.AddPackage("base2.pkg", "lib\\base2\\bas2.lll");
 }
示例#19
0
 //解码工厂
 public void DecodeInternal()
 {
     List<Original> list = rxQueue.PopAll();
     foreach (var o in list)
     {
         if (o is OriginalBytes)
         {
             OriginalBytes obytes = o as OriginalBytes;
             FrameProtocol fp = frameProtocol.DePackage(obytes.Data);
             byte[] data = fp.Body;
             if (data.Length > 10)
             {
                 BasePackage bp = new BasePackage();
                 bp.RemoteIpEndPoint = obytes.RemoteIpEndPoint;
                 bp.ProtocolVersion = data[0];
                 bp.CycleNo = Util.B2LInt32(new byte[] { data[1], data[2], data[3], data[4] });
                 bp.Type = data[5];
                 bp.SubType = data[6];
                 bp.ErrorStatus = data[7];
                 bp.DataLen = Util.B2LInt16(new byte[]{data[8],data[9]});
                 bp.AppData = new byte[data.Length - 10];
                 Array.Copy(data,10,bp.AppData,0,data.Length - 10);
                 //if (data.Length == bp.DataLen + 10)
                 {
                     if (Decoders.ContainsKey(bp.Type))
                     {
                         List<BaseResponse> responseList = Decoders[bp.Type].Decode(bp, obytes);
                         if (responseList != null)
                         {
                             rxFctMsgQueue.Push(responseList);
                             rxGeneralMsgQueue.Push(responseList);
                             rxSelfMsgQueue.Push(responseList);
                         }
                         else
                         {
                             LogHelper.GetLogger<ProtocolFactory>().Error(string.Format("解码错误:{0}",
                                 Summer.System.Util.ByteHelper.Byte2ReadalbeXstring(obytes.Data)));
                         }
                     }
                     else
                     {
                         LogHelper.GetLogger<ProtocolFactory>().Error(string.Format("没有解码器可以解码:{0}",
                                 Summer.System.Util.ByteHelper.Byte2ReadalbeXstring(obytes.Data)));
                     }
                 }
                 //else
                 //{
                 //    LogHelper.GetLogger<ProtocolFactory>().Error(string.Format("数据不完整,丢弃:0x{0}",
                 //                Summer.System.Util.ByteHelper.Byte2Xstring(obytes.Data)));
                 //}
             }
         }
     }
 }
示例#20
0
        /// <summary>
        /// 转入包
        /// </summary>
        /// <param name="package"></param>
        /// <returns></returns>
        public bool Add(BasePackage package)
        {
            SendQueue sessionQueue = null;

            if (queue.TryGetValue(package.PackID, out sessionQueue))
            {
                if (sessionQueue.IsShut)
                {
                    queue.TryRemove(package.PackID, out sessionQueue);
                    return(false);
                }
                if (package is DATAPackage)
                {
                    sessionQueue.AddData((DATAPackage)package);
                }
                else if (package is FINPackage)
                {
                    sessionQueue.AddFin((FINPackage)package);
                    //删除
                    queue.TryRemove(package.PackID, out sessionQueue);
                }
                else if (package is ACKPackage)
                {
                    sessionQueue.AddAck((ACKPackage)package);
                    if (sessionQueue.IsEmpty)
                    {
                        //接收完成
                        queue.TryRemove(package.PackID, out sessionQueue);
                    }
                }
                else if (package is LostPackage)
                {
                    sessionQueue.AddLost((LostPackage)package);
                }
            }
            else
            {
                if (package is LostPackage)
                {
                    //如果是接收端发送的丢失包没有找到,则发送一次关闭
                    SendShut(package);
                    return(true);
                }
                int len = (int)(package.Length / package.PackSize) + 1;
                sessionQueue = new SendQueue(SocketStream, len);
                sessionQueue.AddData((DATAPackage)package);
                queue[package.PackID] = sessionQueue;
            }
            //
            return(true);
        }
示例#21
0
        public VsxToolWindow() :
            base(null)
        {
            var attr = GetType().AttributesOfType <VsxToolWindowCaptionAttribute>().FirstOrDefault();

            if (attr != null)
            {
                Caption          = BasePackage.GetPackageResourceString(attr.Caption, GetType().Assembly);
                BitmapResourceID = attr.BitmapResourseID;
                BitmapIndex      = attr.BitmapIndex;
            }

            base.Content = new T();
        }
示例#22
0
        /// <summary>
        /// Distributes a Package to a Wildcard or a specific UID.
        /// </summary>
        /// <param name="package">Package to distribute</param>
        /// <param name="senderTcpClient">TcpClient-Object of the sender</param>
        /// <param name="excludedClients">Array of clients, where the package is not distributed</param>
        public void DistributePackage(BasePackage package, TcpClient senderTcpClient, string[] excludedClients = null)
        {
            if (excludedClients == null)
            {
                excludedClients = new string[] { }
            }
            ;

            switch (package.DestinationUid)
            {
            case ServerWildcard:
                _serverInstance.HandleIncommingData(package, senderTcpClient);
                break;

            case AllAuthenticatedWildCard:
                foreach (BaseClientData client in _serverInstance.Clients)
                {
                    if (client.Authenticated && !IsInArray(client.Uid, excludedClients))
                    {
                        client.EnqueueDataForWrite(package);
                    }
                }
                break;

            case AllNotAutheticatedWildCard:
                foreach (BaseClientData client in _serverInstance.Clients)
                {
                    if (!client.Authenticated && !IsInArray(client.Uid, excludedClients))
                    {
                        client.EnqueueDataForWrite(package);
                    }
                }
                break;

            case AllWildCard:
                foreach (BaseClientData client in _serverInstance.Clients)
                {
                    if (!IsInArray(client.Uid, excludedClients))
                    {
                        client.EnqueueDataForWrite(package);
                    }
                }
                break;

            default:
                //Send to package to DestinationUID
                _serverInstance.GetClientFromClientList(package.DestinationUid)?.EnqueueDataForWrite(package);
                break;
            }
        }
示例#23
0
        public byte[] GetBigBytes(BasePackage bp)
        {
            bp.DataLen = (ushort)bp.AppData.Length;

            byte[] data = new byte[bp.AppData.Length + 10];
            data[0] = bp.ProtocolVersion;
            Array.Copy(Util.L2BInt32(bp.CycleNo), 0, data, 1, 4);
            data[5] = bp.Type;
            data[6] = bp.SubType;
            data[7] = bp.ErrorStatus;
            Array.Copy(Util.L2BInt16(bp.DataLen), 0, data, 8, 2);
            Array.Copy(bp.AppData, 0, data, 10, bp.AppData.Length);

            return data;
        }
示例#24
0
        public void UploadBasePackageTest()
        {
            _esSession.Open();
            BasePackage basePackage = new BasePackage();

            basePackage.BasepackageName        = "basepackage1";
            basePackage.BasepackageDescription = "This is a basepackage.";
            basePackage.BasepackageType        = ConstMgr.HWBasePackage.PACKAGE_TYPE_FIRMWARE;
            basePackage.FileList     = "iBMC.zip,iBMC.zip.asc";
            basePackage.SftpserverIP = "188.10.18.188";
            basePackage.SftpUserName = "******";
            basePackage.SftpPassword = "******";
            string taskName = _esSession.BasePackageWorker.UploadBasePackage(basePackage);

            Console.WriteLine(taskName);
            Assert.IsTrue(!string.IsNullOrEmpty(taskName));
        }
示例#25
0
文件: Docx.cs 项目: FredCof/Codex
        public Docx()
        {
            string ofDocx = "I am a constructor of Docx";

            // ReSharper disable once CA1303
            Console.WriteLine(ofDocx);
            Unit a = new Unit(10, SUnit.Centi);
            Unit b = Unit.Add(a, a);

            Console.WriteLine(b);
            Paragraph codexP = new Paragraph();

            string srcFolder  = @"";
            string targetFile = @"";

            // BasePackage.PackageFolder(srcFolder, targetFile, true);
            BasePackage.Compress(srcFolder, targetFile);
        }
示例#26
0
        /// <summary>
        /// Loads String Resource from the Package
        /// </summary>
        /// <param name="list">The List where you want to store the Resource</param>
        /// <param name="instance">The Instance of the TextFile</param>
        /// <param name="lang">The Language Number</param>
        public void LoadData(ref ArrayList list, ushort instance, ushort lang)
        {
            list = new ArrayList();
            if (BasePackage == null)
            {
                return;
            }

            IPackedFileDescriptor pfd = BasePackage.FindFile(Data.MetaData.STRING_FILE, 0x00000000, 0x7FE59FD0, instance);

            SimPe.PackedFiles.Wrapper.Str str = new SimPe.PackedFiles.Wrapper.Str();
            str.ProcessData(pfd, BasePackage);
            SimPe.PackedFiles.Wrapper.StrItemList sis = str.FallbackedLanguageItems((SimPe.Data.MetaData.Languages)lang);
            for (ushort i = 0; i < sis.Length; i++)
            {
                list.Add(sis[i].Title);
            }                   //for
        }
示例#27
0
        internal void DataIn(object clientData)
        {
            BaseClientData client       = (BaseClientData)clientData;
            var            clientStream = client.ClientStream;

            try
            {
                while (true)
                {
                    byte[] buffer;                 //Daten
                    byte[] dataSize = new byte[4]; //Länge

                    int readBytes = clientStream.Read(dataSize, 0, 4);

                    while (readBytes != 4)
                    {
                        readBytes += clientStream.Read(dataSize, readBytes, 4 - readBytes);
                    }
                    var contentLength = BitConverter.ToInt32(dataSize, 0);

                    buffer    = new byte[contentLength];
                    readBytes = 0;
                    while (readBytes != buffer.Length)
                    {
                        readBytes += clientStream.Read(buffer, readBytes, buffer.Length - readBytes);
                    }

                    //Daten sind im Buffer-Array
                    Router.DistributePackage(BasePackage.Deserialize <BasePackage>(buffer), client.TcpClient);
                }
            }
            catch (IOException e)
            {
                Log.Debug(e.ToString());
                BaseClientData disconnectedClient = GetClientFromClientList(client.TcpClient);
                Log.Info("Client disconnected with Uid: " + disconnectedClient.Uid);
                Clients.Remove(disconnectedClient);
                Log.Info("Client removed from list.");

                OnClientDisconnected(new ClientDisconnectedEventArgs(disconnectedClient.Uid));
            }
        }
        /// <summary>
        /// 上传固件任务。
        /// </summary>
        /// <param name="basePackage"></param>
        /// <returns></returns>
        public string UploadBasePackage(BasePackage basePackage)
        {
            StringBuilder sb      = new StringBuilder(ConstMgr.HWESightHost.URL_UPLOADE_BASEPACKAGE);
            int           retCode = 0;
            JObject       jResult = ESSession.HCPost(sb.ToString(), basePackage);

            CheckAndThrowException(jResult);
            HWESightTask eSightTask = HWESightTaskDal.Instance.FindTaskByBasepackageName(this.ESSession.HWESightHost.ID, basePackage.BasepackageName);

            if (eSightTask == null)
            {
                eSightTask = new HWESightTask();
            }
            else
            {
                LogUtil.HWLogger.API.WarnFormat("Find same package name in the database, the data will be overwrite=[{0}]", basePackage.BasepackageName);
            }
            string taskName = "";
            QueryObjectResult <JObject> queryObjectResult = jResult.ToObject <QueryObjectResult <JObject> >();

            if (queryObjectResult.Code == 0)
            {
                taskName = JsonUtil.GetJObjectPropVal <string>(queryObjectResult.Data, "taskName");
                //Save to database.
                eSightTask.HWESightHostID     = this.ESSession.HWESightHost.ID;
                eSightTask.TaskName           = taskName;
                eSightTask.SoftWareSourceName = basePackage.BasepackageName;
                eSightTask.ReservedStr1       = basePackage.BasepackageType;
                eSightTask.TaskStatus         = ConstMgr.HWESightTask.TASK_STATUS_RUNNING;//初始化。
                eSightTask.TaskProgress       = 0;
                eSightTask.TaskResult         = "";
                eSightTask.ErrorDetail        = "";
                eSightTask.SyncStatus         = ConstMgr.HWESightTask.SYNC_STATUS_CREATED;
                eSightTask.TaskType           = ConstMgr.HWESightTask.TASK_TYPE_FIRMWARE;
                eSightTask.LastModifyTime     = System.DateTime.Now;
                eSightTask.CreateTime         = System.DateTime.Now;
                int taskId = HWESightTaskDal.Instance.InsertEntity(eSightTask);
                LogUtil.HWLogger.API.InfoFormat("add task:{0}", taskId);
            }
            return(taskName);
        }
示例#29
0
        /// <summary>
        /// Enqueue the packet in the message queue to send this to the client.
        /// </summary>
        /// <param name="package">Package to send (must inherit <see cref="BasePackage"/>).</param>
        public void EnqueueDataForWrite(BasePackage package)
        {
            var packageBytes = BasePackage.Serialize(package);

            var length      = packageBytes.Length;
            var lengthBytes = BitConverter.GetBytes(length);

            _pendingDataToWrite.Enqueue(lengthBytes);
            _pendingDataToWrite.Enqueue(packageBytes);

            lock (_pendingDataToWrite)
            {
                if (_sendingData)
                {
                    return;
                }

                _sendingData = true;
            }

            WriteData();
        }
示例#30
0
        public static NamespaceMapping RetrieveFromName(string aName)
        {
            NamespaceMapping mapping = (NamespaceMapping)_tabNmsp[aName];

            if (mapping != null)
            {
                return(mapping);
            }
            if (_mdl == null)
            {
                return(null);
            }
            ArrayList list  = new ArrayList(aName.Split(new char[] { '.' }));
            string    str   = (string)list[list.Count - 1];
            Array     array = Array.CreateInstance(typeof(string), (int)(list.Count - 1));

            list.CopyTo(0, array, 0, array.Length);
            BasePackage aPckg = (BasePackage)RetrieveFromName(string.Join(".", (string[])array))._pdPckg.CreateObject(0x18112061, "", -1, true);

            aPckg.Name = aPckg.Code = str;
            return(new NamespaceMapping(aName, aPckg));
        }
示例#31
0
        public void UploadBasePackageJsonTest()
        {
            _esSession.Open();
            BasePackage basePackage = new BasePackage();

            basePackage.BasepackageName        = "basepackage1";
            basePackage.BasepackageDescription = "This is a basepackage.";
            basePackage.BasepackageType        = ConstMgr.HWBasePackage.PACKAGE_TYPE_FIRMWARE;
            basePackage.FileList     = "iBMC.zip,iBMC.zip.asc";
            basePackage.SftpserverIP = "188.10.18.188";
            basePackage.SftpUserName = "******";
            basePackage.SftpPassword = "******";
            WebMutilESightsParam <BasePackage> postESightParam = new WebMutilESightsParam <BasePackage>();

            postESightParam.ESights = new List <string>()
            {
                "127.0.0.1"
            };
            postESightParam.Data = basePackage;

            LogUtil.HWLogger.API.Info("UploadBasePackageJsonTest Params:" + JsonUtil.SerializeObject(postESightParam));

            string taskName = _esSession.BasePackageWorker.UploadBasePackage(basePackage);


            JObject taskObject = new JObject();

            taskObject.Add("taskName", taskName);
            WebReturnResult <JObject> taskResult = new WebReturnResult <JObject>();

            taskResult.Data        = taskObject;
            taskResult.Description = "";
            LogUtil.HWLogger.API.Info("UploadBasePackageJsonTest Result:" + JsonUtil.SerializeObject(taskResult));


            Assert.IsTrue(!string.IsNullOrEmpty(taskName));
        }
示例#32
0
        /// <summary>
        /// Reads the incomming data from the <see cref="NetworkStream"/>.
        /// </summary>
        private void HandleIncommingData()
        {
            try
            {
                while (true)
                {
                    byte[] buffer;                 //Daten
                    byte[] dataSize = new byte[4]; //Länge

                    int readBytes = ClientStream.Read(dataSize, 0, 4);

                    while (readBytes != 4)
                    {
                        readBytes += ClientStream.Read(dataSize, readBytes, 4 - readBytes);
                    }
                    var contentLength = BitConverter.ToInt32(dataSize, 0);

                    buffer    = new byte[contentLength];
                    readBytes = 0;
                    while (readBytes != buffer.Length)
                    {
                        readBytes += ClientStream.Read(buffer, readBytes, buffer.Length - readBytes);
                    }

                    //Daten sind im Buffer-Array gespeichert
                    PackageReceived?.Invoke(this,
                                            new PackageReceivedEventArgs(BasePackage.Deserialize(buffer), TcpClient));
                }
            }
            catch (IOException ex)
            {
                Log.Info(ex.Message);
                Log.Info("Server connection lost!");
                ConnectionLost?.Invoke(this, EventArgs.Empty);
            }
        }
示例#33
0
        /// <summary>
        /// 从接收session接收数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="data"></param>
        /// <param name="host"></param>
        private void Stream_DataCall(object sender, byte[] data, HostAndPort host)
        {
            //创建类型
            BasePackage package = new BasePackage(data);

            //所有接收信息都经过
            switch (package.PackType)
            {
            case PackageControl.Data:
                package = new DATAPackage(data);
                break;

            case PackageControl.Ack:
                package = new ACKPackage(data);
                break;

            case PackageControl.Fin:
                package = new  FINPackage(data);
                break;

            case PackageControl.Lost:
                package = new LostPackage(data);
                break;

            case PackageControl.ShutDown:
                package = new ShutDownPackage(data);
                break;

            case PackageControl.Syn:
                package = new SYNPackage(data);
                break;
            }
            package.DestHost = host.Host;
            package.DestPort = host.Port;
            AddPackage(host, package);
        }
示例#34
0
 /// <summary>
 /// 自己生成的,下位机不会送达,所以没有解码方法
 /// </summary>
 /// <param name="bp"></param>
 /// <returns></returns>
 public override List<BaseResponse> Decode(BasePackage bp, OriginalBytes obytes)
 {
     return null;
 }
示例#35
0
 //--------------------------------------
 // INITIALIZE
 //--------------------------------------
 //--------------------------------------
 //  PUBLIC METHODS
 //--------------------------------------
 public static void send(BasePackage pack)
 {
     GameCenterMultiplayer.instance.SendDataToAll (pack.getBytes(), GameCenterDataSendType.RELIABLE);
 }
示例#36
0
 /// <summary>
 /// Handles packets who are sent to the server.
 /// </summary>
 /// <param name="package"></param>
 /// <param name="senderTcpClient"></param>
 public void HandleIncommingData(BasePackage package, TcpClient senderTcpClient)
 {
     OnPackageReceived(senderTcpClient, new PackageReceivedEventArgs(package, senderTcpClient));
 }
示例#37
0
 public override List<BaseResponse> Decode(BasePackage bp, OriginalBytes obytes)
 {
     Cabinet cabinet = SpringHelper.GetObject<Cabinet>("cabinet");
     Board b = cabinet.GetCommunicationBoard(bp.RemoteIpEndPoint);
     if (b != null)
     {
         ShakeResponse sr = new ShakeResponse();
         sr.CommunicatinBoard = b;
         sr.DtTime = DateTime.Now;
         sr.OriginalBytes = obytes;
         return CreateOneList(sr);
     }
     return null;
 }
示例#38
0
        /// <inheritdoc />
        protected override int Execute(IInput input, IOutput output)
        {
            string[] packages = input.GetArgument("packages");
            packages = Arr.Map(packages, (package) => package.ToLower());

            var file     = Factory.GetBucketFile();
            var filePath = Path.Combine(Environment.CurrentDirectory, file);

            var jsonFile     = new JsonFile(filePath);
            var configBucket = jsonFile.Read <ConfigBucket>();
            var backup       = File.ReadAllText(filePath);

            var source = new JsonConfigSource(jsonFile);
            var io     = GetIO();

            var requireKey            = input.GetOption("dev") ? LinkType.RequireDev : LinkType.Require;
            var alternativeRequireKey = input.GetOption("dev") ? LinkType.Require : LinkType.RequireDev;

            var requireMapping            = new Dictionary <string, string>();
            var alternativeRequireMapping = new Dictionary <string, string>();

            void EstablishCaseMapping(IDictionary <string, string> mapping, LinkType type)
            {
                var collection = type == LinkType.Require ? configBucket.Requires : configBucket.RequiresDev;

                if (collection == null)
                {
                    return;
                }

                foreach (var item in collection)
                {
                    mapping[item.Key.ToLower()] = item.Key;
                }
            }

            EstablishCaseMapping(requireMapping, requireKey);
            EstablishCaseMapping(alternativeRequireMapping, alternativeRequireKey);

            bool TryGetMatchPackages(IDictionary <string, string> mapping, string package, out IEnumerable <string> matches)
            {
                var result       = new List <string>();
                var regexPackage = BasePackage.PackageNameToRegexPattern(package);

                foreach (var item in mapping)
                {
                    if (Regex.IsMatch(item.Key, regexPackage, RegexOptions.IgnoreCase))
                    {
                        result.Add(item.Value);
                    }
                }

                matches = result;
                return(result.Count > 0);
            }

            foreach (var package in packages)
            {
                if (requireMapping.TryGetValue(package, out string originalName))
                {
                    source.RemoveLink(requireKey, originalName);
                }
                else if (alternativeRequireMapping.TryGetValue(package, out originalName))
                {
                    io.WriteError($"<warning>{originalName} could not be found in {Str.LowerDashes(requireKey.ToString())} but it is present in {Str.LowerDashes(alternativeRequireKey.ToString())}</warning>");
                    if (io.IsInteractive && io.AskConfirmation($"Do you want to remove it from {Str.LowerDashes(alternativeRequireKey.ToString())} [<comment>yes</comment>]? ", true))
                    {
                        source.RemoveLink(alternativeRequireKey, originalName);
                    }
                }
                else if (TryGetMatchPackages(requireMapping, package, out IEnumerable <string> matches))
                {
                    foreach (var match in matches)
                    {
                        source.RemoveLink(requireKey, match);
                    }
                }
                else if (TryGetMatchPackages(alternativeRequireMapping, package, out matches))
                {
                    foreach (var match in matches)
                    {
                        io.WriteError($"<warning>{match} could not be found in {Str.LowerDashes(requireKey.ToString())} but it is present in {Str.LowerDashes(alternativeRequireKey.ToString())}</warning>");
                        if (io.IsInteractive && io.AskConfirmation($"Do you want to remove it from {Str.LowerDashes(alternativeRequireKey.ToString())} [<comment>yes</comment>]? ", true))
                        {
                            source.RemoveLink(alternativeRequireKey, match);
                        }
                    }
                }
                else
                {
                    io.WriteError($"<warning>{package} is not required in your bucket.json and has not been removed</warning>");
                }
            }

            if (input.GetOption("no-update"))
            {
                return(ExitCodes.Normal);
            }

            // todo: implement installer uninstall.
            ResetBucket();

            var bucket = GetBucket(true, input.GetOption("no-plugins"));

            // todo: set no-progress.
            var commandEvent = new CommandEventArgs(PluginEvents.Command, "remove", input, output);

            bucket.GetEventDispatcher().Dispatch(this, commandEvent);

            ISet <string> GetRemoveWhitlist()
            {
                Guard.Requires <UnexpectedException>(packages.Length > 0);
                return(new HashSet <string>(packages));
            }

            var installer = new BucketInstaller(io, bucket);
            var status    = installer
                            .SetVerbose(input.GetOption("verbose"))
                            .SetDevMode(!input.GetOption("update-no-dev"))
                            .SetRunScripts(!input.GetOption("no-scripts"))
                            .SetUpdate(true)
                            .SetUpdateWhitelist(GetRemoveWhitlist())
                            .SetWhitelistTransitiveDependencies(!input.GetOption("no-update-with-dependencies"))
                            .SetIgnorePlatformRequirements(input.GetOption("ignore-platform-reqs"))
                            .Run();

            if (status != 0)
            {
                io.WriteError($"{Environment.NewLine}<error>Removal failed, reverting {file} to its original content.</error>");
                File.WriteAllText(filePath, backup);
            }

            return(status);
        }
示例#39
0
 /// <summary>
 /// [EquipId(BOARD)(5)+errorCode(1)]
 /// </summary>
 /// <param name="bp"></param>
 /// <param name="obytes"></param>
 /// <returns></returns>
 public override List<BaseResponse> Decode(BasePackage bp, OriginalBytes obytes)
 {
     Cabinet cabinet = SpringHelper.GetObject<Cabinet>("cabinet");
     if (bp.AppData.Length >= 6)
     {
         VPSErrorInfoResponse tr = new VPSErrorInfoResponse();
         tr.CommunicatinBoard = cabinet.GetCommunicationBoard(bp.RemoteIpEndPoint);
         tr.DtTime = DateTime.Now;
         tr.OriginalBytes = obytes;
         byte[] eqid = new byte[] { bp.AppData[0], bp.AppData[1], bp.AppData[2], bp.AppData[3], bp.AppData[4] };
         tr.ErrorBoard = cabinet.FindEq(eqid) as Board;
         tr.ErrorCode = bp.AppData[5];
         return CreateOneList(tr);
     }
     return null;
 }
示例#40
0
	//--------------------------------------
	// INITIALIZE
	//--------------------------------------



	//--------------------------------------
	//  PUBLIC METHODS
	//--------------------------------------

	public static void send(BasePackage pack) {
		GameCenter_RTM.instance.SendDataToAll (pack.getBytes(), GK_MatchSendDataMode.RELIABLE);
	}
示例#41
0
 /// <summary>
 /// 立即发送一个包
 /// </summary>
 /// <param name="pack"></param>
 private void SendData(BasePackage pack)
 {
     stream.Write(pack.DestHost, pack.DestPort, pack.GetBuffer());
 }
示例#42
0
 public override List<BaseResponse> Decode(BasePackage bp, OriginalBytes obytes)
 {
     base.Decode(bp, obytes);
     Cabinet cabinet = SpringHelper.GetObject<Cabinet>("cabinet");
     List<BaseResponse> list = new List<BaseResponse>();
     //应用区数据格式:[EquipId(COMPONENT)(5)+testtimes(4)+误码次数(4)+丢包次数(4)+通信终端次数(4)]*
     if (bp.AppData.Length % 21 == 0)
     {
         for (int i = 0; i < bp.AppData.Length / 21; i++)
         {
             byte[] eqid = new byte[] { bp.AppData[i * 21 + 0], bp.AppData[i * 21 + 1], bp.AppData[i * 21 + 2], bp.AppData[i * 21 + 3], bp.AppData[i * 21 + 4] };
             int allTimes = (int)Util.B2LInt32(new byte[] { bp.AppData[i * 21 + 5], bp.AppData[i * 21 + 6], bp.AppData[i * 21 + 7], bp.AppData[i * 21 + 8] });
             int errorPackageTimes = (int)Util.B2LInt32(new byte[] { bp.AppData[i * 21 + 9], bp.AppData[i * 21 + 10], bp.AppData[i * 21 + 11], bp.AppData[i * 21 + 12] });
             int lostPackageTimes = (int)Util.B2LInt32(new byte[] { bp.AppData[i * 21 + 13], bp.AppData[i * 21 + 14], bp.AppData[i * 21 + 15], bp.AppData[i * 21 + 16] });
             int interruptTimes = (int)Util.B2LInt32(new byte[] { bp.AppData[i * 21 + 17], bp.AppData[i * 21 + 18], bp.AppData[i * 21 + 19], bp.AppData[i * 21 + 20] });
             AbstractEq eq = cabinet.FindEq(eqid);
             if (eq != null && eq is Component)
             {
                 ComponentTestResponse cr = new ComponentTestResponse();
                 cr.CommunicatinBoard = cabinet.GetCommunicationBoard(bp.RemoteIpEndPoint);
                 cr.DtTime = DateTime.Now;
                 cr.OriginalBytes = obytes;
                 cr.Component = eq as Component;
                 cr.Component.AllTestTimes = allTimes;
                 cr.Component.ErrorPackageTimes = errorPackageTimes;
                 cr.Component.LostPackageTimes = lostPackageTimes;
                 cr.Component.InterruptTimes = interruptTimes;
                 list.Add(cr);
             }
         }
     }
     return list;
 }
示例#43
0
 public virtual List<BaseResponse> Decode(BasePackage bp, OriginalBytes obytes)
 {
     CycleNo = bp.CycleNo;
     return null;
 }
示例#44
0
 public override List<BaseResponse> Decode(BasePackage bp, OriginalBytes obytes)
 {
     Cabinet cabinet = SpringHelper.GetObject<Cabinet>("cabinet");
     //应用区数据格式:[EquipId(COMPONENT)(5)]*
     StopFctTestResponse sr = new StopFctTestResponse();
     sr.Components = new List<Component>();
     if (bp.AppData.Length % 5 == 0)
     {
         for (int i = 0; i < bp.AppData.Length / 5; i++)
         {
             byte[] eqid = new byte[] { bp.AppData[i * 5 + 0], bp.AppData[i * 5 + 1], bp.AppData[i * 5 + 2], bp.AppData[i * 5 + 3], bp.AppData[i * 5 + 4] };
             AbstractEq eq = cabinet.FindEq(eqid);
             if (eq is Component)
             {
                 sr.CommunicatinBoard = cabinet.GetCommunicationBoard(bp.RemoteIpEndPoint);
                 sr.DtTime = DateTime.Now;
                 sr.OriginalBytes = obytes;
                 sr.Components.Add(eq as Component);
             }
         }
     }
     return CreateOneList(sr);
 }
示例#45
0
        public int smallCycleBoard; //小周期号

        #endregion Fields

        #region Methods

        public override List<BaseResponse> Decode(BasePackage bp, OriginalBytes obytes)
        {
            base.Decode(bp, obytes);
            Cabinet cabinet = SpringHelper.GetObject<Cabinet>("cabinet");
            List<BaseResponse> list = new List<BaseResponse>();
            Board communicatinBoard = cabinet.GetCommunicationBoard(bp.RemoteIpEndPoint);
            //应用区数据格式:rack(1)+slot(1)+boardtype(1)+smallcycle(1)+lightport(2) +[采集到的码字(4)*16] +[错误次数(4)*16]
            if (bp.AppData.Length == 6 + 4 * 16 + 4 * 16)
            {
                byte rackNo = bp.AppData[0];
                byte slotNo = bp.AppData[1];
                byte boardType = bp.AppData[2];
                byte smallCycle = bp.AppData[3];
                UInt32[] realCodes = new UInt32[16];
                Int32[] errorTimes = new Int32[16];
                for (int i = 0; i < 16; i++)
                {
                    realCodes[i] = System.BitConverter.ToUInt32(bp.AppData, 6 + i * 4);
                    errorTimes[i] = System.BitConverter.ToInt32(bp.AppData, 6 + 64 + i * 4);
                }

                int a = (int)(((bp.AppData[4] << 8) & 0xFF00) | (bp.AppData[5] & 0x00FF));
                byte[] eqId = new byte[] { 0x05, rackNo, slotNo, 0xFF, 0xFF };
                //byte[] eqId = GetEqId(rackNo, slotNo);
                for (int i = 0; i < 16; ++i)
                {
                    if (((a >> i) & 0x01) == 0x01)//error
                    {
                        //例如 02 04 02 05 01 00
                        //表示 1 机笼 4槽道 VOB16板卡 01 00 ->0000 0001 0000 0000 : 第9个灯位有问题
                        int posk = (rackNo - 2) * 12 * 16 + (slotNo - 2) * 16 + i;
                        if (boardType == 0x01)//VIB
                        {
                            VIBTestResponse vibR = new VIBTestResponse();
                            vibR.CommunicatinBoard = communicatinBoard;
                            vibR.DtTime = DateTime.Now;
                            vibR.OriginalBytes = obytes;
                            vibR.Board = cabinet.FindEq(eqId) as Board;
                            vibR.Board.BoardType = "VIB";
                            vibR.LightPos = i + 1;
                            vibR.ExpectedCode = Util.vib_true[posk];
                            vibR.RealCode = realCodes[i];
                            vibR.ErrorTimes = errorTimes[i];
                            int readableSmallCycle = (int)smallCycle + 1;
                            vibR.smallCycleBoard = readableSmallCycle;
                            list.Add(vibR);
                        }
                        else if (boardType == 0x02)//VOB
                        {
                            VOBTestResponse vobR = new VOBTestResponse();
                            vobR.CommunicatinBoard = communicatinBoard;
                            vobR.DtTime = DateTime.Now;
                            vobR.OriginalBytes = obytes;
                            vobR.Board = cabinet.FindEq(eqId) as Board;
                            vobR.Board.BoardType = "VOB";
                            vobR.LightPos = i + 1;
                            vobR.RealCode = realCodes[i];
                            vobR.ErrorTimes = errorTimes[i];

                            byte[] cycleNo = new byte[2];
                            Array.Copy(obytes.Data, 3, cycleNo, 0, 2);//帧协议中周期号四个字节中的低两位作为是否有输出
                            uint value = (uint)(((cycleNo[0] << 8) & 0xFF00) | (cycleNo[1] & 0x00FF));
                            int readableSmallCycle = (int)smallCycle;
                            vobR.smallCycleBoard = readableSmallCycle;
                            if (((value >> i) & 0x01) == 0x01)//有输出
                            {
                                //VOB板卡第i个灯位错误,且当前灯位亮的状态(有输出)
                                vobR.OutPut = true;
                                vobR.ErrorCode = false;
                                if (readableSmallCycle == 2)
                                {
                                    vobR.ExpectedCode = Util.vob_ock_even[posk];
                                    vobR.OCK = true;
                                }
                                else if (readableSmallCycle == 0 || readableSmallCycle == 4 ||
                                    readableSmallCycle == 6 || readableSmallCycle == 8)
                                {
                                    vobR.ExpectedCode = Util.vob_true_even;
                                    vobR.OCK = false;
                                }
                                else if (readableSmallCycle == 1)
                                {
                                    vobR.ExpectedCode = Util.vob_ock_odd[posk];
                                    vobR.OCK = true;
                                }
                                else if (readableSmallCycle == 3 || readableSmallCycle == 5 ||
                                    readableSmallCycle == 7 || readableSmallCycle == 9)
                                {
                                    vobR.ExpectedCode = Util.vob_true_odd;
                                    vobR.OCK = false;
                                }
                            }
                            else
                            {
                                //当前的灯位灭的状态(无输出)
                                vobR.OutPut = false;
                                vobR.ErrorCode = true;
                                if (readableSmallCycle == 0 || readableSmallCycle == 2 ||
                                    readableSmallCycle == 4 || readableSmallCycle == 6 ||
                                    readableSmallCycle == 8)
                                {
                                    vobR.ExpectedCode = Util.vob_ckWord_even[posk];
                                }
                                else if (readableSmallCycle == 1 || readableSmallCycle == 3 ||
                                    readableSmallCycle == 5 || readableSmallCycle == 7 ||
                                    readableSmallCycle == 9)
                                {
                                    vobR.ExpectedCode = Util.vob_ckWord_odd[posk];
                                }
                            }
                            list.Add(vobR);
                        }
                    }
                }
            }
            return list;
        }