예제 #1
0
 public OutgoingMessageQueue()
 {
     _unackedQueue = new();
     Tail          = 0;
     Head          = 0;
     _preSyncHead  = 0;
 }
예제 #2
0
        public void GetDtuList(int uID, string sID, string cmds, string gprsNum, bool isset)
        {
            try
            {
                DownRequest request = new DownRequest {
                    StationId = sID, Cmds = cmds, GprsNum = gprsNum, IsSet = isset
                };

                DownConf info = grpcClient.GetDownConf(request);

                downConfList = new CDictionary <int, DownConf>();

                if (info != null)
                {
                    if (downConfList.ContainsKey(uID))
                    {
                        downConfList[uID] = info;
                    }
                    else
                    {
                        downConfList.Add(uID, info);
                    }
                }
            }
            catch (Exception exp)
            {
                Debug.WriteLine("RPC failed" + exp);
                throw;
            }
        }
예제 #3
0
        private void ReadSDXml()
        {
            m_mapStationData     = new CDictionary <string, CEntityStation>();
            m_mapStationbeidouID = new CDictionary <string, string>();
            m_mapStationgprsID   = new CDictionary <string, string>();
            // 读取XML,初始化站点数据表
            List <CEntityStation> listSD = Deserialize();

            if (null == listSD)
            {
                return;
            }
            for (int i = 0; i < listSD.Count; ++i)
            {
                try
                {
                    if (!m_mapStationData.ContainsKey(listSD[i].StationID))
                    {
                        // 通知界面
                        m_mapStationData.Add(listSD[i].StationID, listSD[i]);
                        m_mapStationbeidouID.Add(listSD[i].StationID, listSD[i].BDSatellite);
                        m_mapStationgprsID.Add(listSD[i].StationID, listSD[i].GPRS);
                    }
                    else
                    {
                        // 位置站点,读取站点数据文件不匹配
                        System.Diagnostics.Debug.WriteLine(string.Format("站点数据中站点\"{0}\"已存在", listSD[i].StationID));
                    }
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine(string.Format("站点数据异常" + e));
                }
            }
        }
예제 #4
0
        public void GetOLStatus(int uID, string subcenterId)
        {
            try
            {
                Subcenter sub = new Subcenter {
                    SubcenterdId = subcenterId
                };

                DtuList list = grpcClient.GetDtuList(sub);

                dtuList = new CDictionary <int, DtuList>();

                if (list != null)
                {
                    if (dtuList.ContainsKey(uID))
                    {
                        dtuList[uID] = list;
                    }
                    else
                    {
                        dtuList.Add(uID, list);
                    }
                }
            }
            catch (Exception exp)
            {
                Debug.WriteLine("RPC failed" + exp);
                throw;
            }
        }
예제 #5
0
 internal void TraceApiError(string appKey, string apiName, string url, CDictionary parameters, double latency, string errorMessage)
 {
     if (!disableTrace)
     {
         this.logger.ErrorFormat(appKey, apiName, url, parameters, latency, errorMessage);
     }
 }
예제 #6
0
        public DynamicRangeChunkVolume(GraphicsDevice device, GameDataProvider provider)
        {
            chunkWishList = new HashSet<WorldPosition>();
            this.provider = provider;
            volume = new Chunk[16, 16, 16];
            vertexBuffers = new CDictionary<Chunk, VBuffer7>();
            this.device = device;
            this.effect = Static.Effect;
            MiniMap = new Texture2D(Static.Device, 64, 64);
            MiniMapBuffer = new Color[64 * 64];
            MiniMapLayer = new Layer(MiniMap, 1, 0.7f, LayerDock.Far, LayerDock.Far,
                () =>
                {
                    return true;
                }
                );
            MiniMapLayer.Push(new LayerCell
            {
                SourceTexture = new Rectangle(0, 0, 64, 64),
                DestinationScreen = new Rectangle(-270, -270, 256, 256)
            });

            redrawWorker = new Timer(doRedraw);
            redrawWorker.Change(50, 50);

            hoverBoxMesh = HelpfulStuff.getCube(0.51f, GraphicsHelper.TextureCoord(36));
        }
예제 #7
0
 private static bool smethod_2(Keys keys_0)
 {
     if (cdictionary_1.ContainsKey(keys_0))
     {
         return(cdictionary_1[keys_0]());
     }
     return(true);
 }
예제 #8
0
 public MainWindow()
 {
     InitializeComponent();
     service = new Service(this);
     clientList = new CDictionary<NetworkClient, UserData>();
     listener = new TcpListener(IPAddress.Any, 8080);//0xBEAF);
     physics = new PhysicsManager(this);
 }
예제 #9
0
 public DynamicRangeChunkVolume(GraphicsDevice device, GameDataProvider provider)
 {
     chunkWishList = new HashSet<WorldPosition>();
     this.provider = provider;
     volume = new Chunk[16, 16, 16];
     vertexBuffers = new CDictionary<Chunk, VertexBuffer[]>();
     this.device = device;
     this.effect = Static.Effect;
 }
예제 #10
0
 private static bool OnKeyUp(Keys key)
 {
     if (handledKeysUp.ContainsKey(key))
     {
         return(handledKeysUp[key]());
     }
     else
     {
         return(true);
     }
 }
예제 #11
0
        public void AddAndRemovedEntriesFromDictionary()
        {
            var storage = new InMemoryStorageEngine();
            var os      = ObjectStore2.New(storage);
            var d       = new CDictionary <string, Person>();

            os.Roots.Entangle(d);

            d["101020"] = new Person {
                Name = "Peter"
            };
            d["311209"] = new Person {
                Name = "Ole", Relationship = d["101020"]
            };

            os.Persist();

            os = ObjectStore2.Load(storage);
            d  = os.Roots.Find <CDictionary <string, Person> >();

            d.Count.ShouldBe(2);
            d["101020"].Name.ShouldBe("Peter");
            d["101020"].Relationship.ShouldBeNull();

            d["311209"].Name.ShouldBe("Ole");
            d["311209"].Relationship.Name.ShouldBe("Peter");

            d.Remove("311209");

            os.Persist();
            os = ObjectStore2.Load(storage);
            d  = os.Roots.Find <CDictionary <string, Person> >();

            d.Count.ShouldBe(1);
            d["101020"].Name.ShouldBe("Peter");
            d["101020"].Relationship.ShouldBeNull();
            d["311209"] = d["101020"];

            os.Persist();
            os = ObjectStore2.Load(storage);
            d  = os.Roots.Find <CDictionary <string, Person> >();

            d.Count.ShouldBe(2);
            d["101020"].ShouldBe(d["311209"]);

            d.Remove("101020");
            d.Remove("311209");

            os.Persist();
            os = ObjectStore2.Load(storage);
            d  = os.Roots.Find <CDictionary <string, Person> >();

            d.Count.ShouldBe(0);
        }
예제 #12
0
 private static bool smethod_1(Keys keys_0)
 {
     if (KeyDown != null)
     {
         return(KeyDown(keys_0));
     }
     if (cdictionary_0.ContainsKey(keys_0))
     {
         return(cdictionary_0[keys_0]());
     }
     return(true);
 }
예제 #13
0
        /// <summary>
        /// 获取所有的Key-Value形式的文本请求参数字典。
        /// </summary>
        /// <returns></returns>
        public virtual CDictionary GetParameters()
        {
            if (_parameters != null)
            {
                return(_parameters);
            }
            var properties = this.GetType().GetProperties().Where(m => m != null);
            //_parameters = properties.ToDictionary(m => m.Name, n => (object)HttpUtility.UrlEncode(n.GetValue(this, null).ToString()));
            IDictionary <string, string> paras = properties.ToDictionary(m => m.Name, n => Convert.ToString(n.GetValue(this, null)));

            _parameters = _parameters ?? new CDictionary();
            _parameters.AddAll(paras);
            return(_parameters);
        }
예제 #14
0
        public IncomingCoordinator(
            string hostName, int port, Action <ImmutableByteArray> messageHandler,
            CDictionary <Guid, IncomingMessageDeliverer> connectionInfos = null)
        {
            _hostName       = hostName;
            _port           = port;
            _messageHandler = messageHandler;
            _scheduler      = Engine.Current;

            _messageDeliverers = connectionInfos ?? new CDictionary <Guid, IncomingMessageDeliverer>();

            //connectionListener = new ConnectionListener(IPEndPoint.Parse($"{hostName}:{port}"), HandleNewConnection, _scheduler);
            _scheduler.Schedule(_connectionListener.StartServing);
        }
예제 #15
0
 private static bool OnKeyDown(Keys key)
 {
     if (KeyDown != null)
     {
         return(KeyDown(key));
     }
     if (handledKeysDown.ContainsKey(key))
     {
         return(handledKeysDown[key]());
     }
     else
     {
         return(true);
     }
 }
예제 #16
0
 public DynamicRangeChunkVolume(GraphicsDevice device, GameDataProvider provider)
 {
     chunkWishList = new HashSet<WorldPosition>();
     this.provider = provider;
     volume = new Chunk[16, 16, 16];
     vertexBuffers = new CDictionary<Chunk, VBuffer7>();
     this.device = device;
     this.effect = Static.Effect;
     MiniMap = new Texture2D(Static.Device, 64, 64);
     MiniMapBuffer = new Color[64 * 64];
     MiniMapLayer = new Layer(MiniMap, 1, 0.7f, LayerDock.Far, LayerDock.Far, () => true);
     MiniMapLayer.Push(new LayerCell
     {
         SourceTexture = new Rectangle(0, 0, 64, 64),
         DestinationScreen = new Rectangle(-270, -270, 256, 256)
     });
 }
        public void InsertElementsPersistAndReceivedThemAgain()
        {
            var d = new CDictionary <int, string>
            {
                [5] = "Hello", [10] = "World"
            };


            AttachAndPersist(d);

            d = Load();
            d.Count.ShouldBe(2);
            d[5].ShouldBe("Hello");
            d[10].ShouldBe("World");

            d.Remove(5);
            Persist();

            d = Load();
            d.Count.ShouldBe(1);
            d[10].ShouldBe("World");

            d[10] = "WORLD";

            Persist();

            d = Load();

            d[10].ShouldBe("WORLD");

            d.Set(10, "worlds");
            d.Remove(10);

            Persist();

            d = Load();
            d.Count.ShouldBe(0);
        }
예제 #18
0
        /// <summary>
        /// 启动检查,检查1、数据交换服务器IP设置,2、WMS服务器IP设置,3、PDA设置,4、3台PLC设置是否都正确。
        /// </summary>
        private void SetupCheck()
        {
            bool checkResult = true; string strStaus = string.Empty;
            CDictionary <string, string> checkIPList = new CDictionary <string, string>();

            checkIPList = AppConfig.Instance().GetAppSettingsByPreKeyIsIP();
            if (checkIPList != null && checkIPList.Count > 0)
            {
                foreach (var item in checkIPList)
                {
                    Splasher.Status = strStaus = $">> 检查{item.Key}网络是否正常.";
                    Application.DoEvents();
                    txtMsg.AppendText(strStaus + Environment.NewLine);
                    if (NetworkUtil.TestNetConnectity(item.Value))
                    {
                        Splasher.Status = strStaus = $">> {item.Key}({item.Value})网络正常.";
                        Application.DoEvents();
                        txtMsg.AppendText(strStaus + Environment.NewLine);
                    }
                    else
                    {
                        checkResult     = false;
                        Splasher.Status = strStaus = $">> {item.Key}({item.Value})网络异常,请检查.";
                        Application.DoEvents();
                        txtMsg.AppendRichText(strStaus + Environment.NewLine, new Font("微软雅黑", 9), Color.Crimson);
                        return;
                    }
                }
            }

            if (checkResult)
            {
                Thread.Sleep(50);
                btnTCPStart_Click(null, null);
                Splasher.Status = ">> 启动数据交换服务器MES.SocketService";
                Application.DoEvents();
            }
        }
 public Remover(int index, CDictionary <int, ImmutableByteArray> queue)
 {
     Index = index;
     Queue = queue;
 }
 private static void PopupForm(CTreeType treeType, object obj)
 {
     PopupFormMap[treeType](obj);
 }
예제 #21
0
 public void StopGrpcClient()
 {
     dtuList    = null;
     grpcClient = null;
 }
예제 #22
0
 public void Dispose()
 {
     m_Pos  = -1;
     m_This = null;
 }
예제 #23
0
 static DynamicManager()
 {
     objects = new CDictionary<string, DynamicBase>();
     HelpfulStuff.RunPeriodic(update, 5000);
 }
예제 #24
0
 public VEntities(CDictionary <Key, Value> aThis)
 {
     m_Pos  = -1;
     m_This = aThis;
 }
예제 #25
0
 public VValues(CDictionary <Key, Value> aThis)
 {
     m_This = aThis;
     m_Pos  = -1;
 }
예제 #26
0
 public abstract CDictionary InitParameters(CDictionary parameters);
예제 #27
0
        public ReadDatas GetReadDatas(ReadRequest request)
        {
            readDataDic = new CDictionary <string, string>();
            ReadDatas readDatas = new ReadDatas();

            m_timer_1.Start();

            if (request.RType == ReadRequest.Types.readType.ReadStoredWater)
            {
                CProtocolEventManager.DownForData += ReadForData_EventHandler_1;
                foreach (var id in request.SList.Ids)
                {
                    CEntityStation station = CDBDataMgr.Instance.GetStationById(id);
                    CPortDataMgr.Instance.GroupStorageWaterFirst(station);
                }
            }
            else if (request.RType == ReadRequest.Types.readType.ReadRealWater)
            {
                CProtocolEventManager.DownForData += ReadForData_EventHandler_2;
                foreach (var id in request.SList.Ids)
                {
                    CEntityStation station = CDBDataMgr.Instance.GetStationById(id);
                    CPortDataMgr.Instance.GroupRealityWater(station);
                }
            }
            else if (request.RType == ReadRequest.Types.readType.ReadRain)
            {
                CProtocolEventManager.DownForData += ReadForData_EventHandler_3;
                foreach (var id in request.SList.Ids)
                {
                    CEntityStation station = CDBDataMgr.Instance.GetStationById(id);
                    CPortDataMgr.Instance.GroupRainWater(station);
                }
            }
            //else if (request.RType == ReadRequest.Types.readType.ReadSoil)
            //{
            //    foreach (var id in request.SList.Ids)
            //    {
            //        CEntityStation station = CDBDataMgr.Instance.GetStationById(id);
            //        CPortDataMgr.Instance.GroupSoilWater(station);
            //    }
            //}

            //等待读取完成
            while (true)
            {
                // 等待
                if (timeDown_1)
                {
                    foreach (var id in request.SList.Ids)
                    {
                        if (readDataDic.ContainsKey(id))
                        {
                            readDatas.RData.Add(new ReadData()
                            {
                                StationId = id, Data = readDataDic[id]
                            });
                        }
                        else
                        {
                            readDatas.RData.Add(new ReadData()
                            {
                                StationId = id, Data = ""
                            });
                        }
                    }
                    break;
                }
            }

            m_timer_1.Stop();

            CProtocolEventManager.DownForData -= ReadForData_EventHandler_1;
            CProtocolEventManager.DownForData -= ReadForData_EventHandler_2;
            CProtocolEventManager.DownForData -= ReadForData_EventHandler_3;
            return(readDatas);
        }
예제 #28
0
        private T DoExecute <T>(IRequest <T> request, string session, DateTime timestamp) where T : ResponseBase
        {
            long start = DateTime.Now.Ticks;

            // 提前检查业务参数
            try
            {
                request.Validate();
            }
            catch (CException e)
            {
                return(CreateErrorResponse <T>(e.ErrorCode, e.ErrorMsg));
            }

            CDictionary txtParams = new CDictionary(request.GetParameters());

            txtParams.Add(Constants.METHOD, request.GetApiName);
            InitParameters(txtParams);


            // 添加协议级请求参数
            //ACDictionary txtParams = new ACDictionary(request.GetParameters());
            //txtParams.Add(Constants.METHOD, request.GetApiName());
            //txtParams.Add(Constants.VERSION, "1.0");
            ////txtParams.Add(Constants.SIGN_METHOD, Constants.SIGN_METHOD_MD5);
            //txtParams.Add(Constants.APP_KEY, appKey);
            //txtParams.Add(Constants.FORMAT, format);
            //txtParams.Add(Constants.TIMESTAMP, timestamp);
            //txtParams.AddAll(this.systemParameters);


            //// 添加签名参数
            //txtParams.Add(Constants.SIGN, SignHelper.SignACRequest(txtParams, appSecret, Constants.SIGN_METHOD_MD5));

            // 添加头部参数
            if (this.useGzipEncoding)
            {
                request.GetHeaderParameters()[Constants.ACCEPT_ENCODING] = Constants.CONTENT_ENCODING_GZIP;
            }

            string realServerUrl = GetServerUrl(this.serverUrl, request.GetApiName, session);
            string reqUrl        = WebUtils.BuildRequestUrl(realServerUrl, txtParams);

            try
            {
                string body;
                if (request is IUploadRequest <T> ) // 是否需要上传文件
                {
                    IUploadRequest <T>             uRequest   = (IUploadRequest <T>)request;
                    IDictionary <string, FileItem> fileParams = SignHelper.CleanupDictionary(uRequest.GetFileParameters());
                    body = webUtils.DoPost(realServerUrl, txtParams, fileParams, request.GetHeaderParameters());
                }
                else
                {
                    body = webUtils.DoPost(realServerUrl, txtParams, request.GetHeaderParameters());
                }

                // 解释响应结果
                T rsp;
                if (disableParser)
                {
                    rsp = Activator.CreateInstance <T>();
                    rsp.ResponseBody = body;
                }
                else
                {
                    if (Constants.FORMAT_XML.Equals(format))
                    {
                        IParser <T> tp = new XmlParser <T>();
                        rsp = tp.Parse(body);
                    }
                    else
                    {
                        IParser <T> tp;
                        if (useSimplifyJson)
                        {
                            tp = new AcSimplifyJsonParser <T>();
                        }
                        else
                        {
                            tp = new JsonParser <T>();
                        }
                        rsp = tp.Parse(body);
                    }
                }

                // 追踪错误的请求
                if (!rsp.HaveError)
                {
                    TimeSpan latency = new TimeSpan(DateTime.Now.Ticks - start);
                    TraceApiError(AppKey, request.GetApiName, serverUrl, txtParams, latency.TotalMilliseconds, rsp.ResponseBody);
                }
                return(rsp);
            }
            catch (Exception e)
            {
                TimeSpan latency = new TimeSpan(DateTime.Now.Ticks - start);
                TraceApiError(AppKey, request.GetApiName, serverUrl, txtParams, latency.TotalMilliseconds, e.GetType() + ": " + e.Message);
                throw e;
            }
        }
예제 #29
0
 public void StopGrpcClient()
 {
     downConfList = null;
     grpcClient   = null;
 }
예제 #30
0
        private static void ConcurrentCollectionsExample()
        {
            CDictionary stock = new CDictionary();
            int         stockValue;

            //Try add
            var result = stock.TryAdd("Simpsons", 5);

            Console.WriteLine($"Tried to add 5 Simpsons tshirts with result:{result}");
            Console.WriteLine($"Add the same tshirt again");
            result = stock.TryAdd("Simpsons", 2);
            Console.WriteLine($"Tried to add 2 Simpsons tshirts with result:{result}");

            //Try Update
            result = stock.TryUpdate("Simpsons", 5, 6);
            Console.WriteLine($"Tried to update Simpsons tshirts (5 of stock), with a new value of 6 with result {result}");
            result = stock.TryUpdate("Simpsons", 7, 6);
            Console.WriteLine($"Tried to update Simpsons tshirts (5 of stock) sending 7 instead, with a new value of 6 with result {result}");

            //TryGet

            result = stock.TryGet("Simpsons", out stockValue);
            Console.WriteLine($"Get value for simpsons occured with result {result} and the value is {stockValue}");

            //Add or Update -> try to update the value, if key it's not present add it
            var updatedStock = stock.AddOrUpdate("Simpsons", 3);

            Console.WriteLine($"Tried to increment Simpsons tshirts (5 of stock) with a new value of {updatedStock}");
            updatedStock = stock.AddOrUpdate("Family Guy", 10);
            Console.WriteLine($"Tried to increment Simpsons tshirts (5 of stock) with a new value of {updatedStock}");

            //Get or Add -> try and get the value. if key not present add it

            stockValue = stock.GetOrAdd("Family Guy", 0);
            Console.WriteLine($"Get the value of {stockValue} for tshirt Family Guy");
            //Try Remove
            result = stock.TryRemove("Simpsons", out stockValue);
            Console.WriteLine($"Tried to remove remove Simpsons tshirts wich had {stockValue} of stock with result {result}");

            result = stock.TryRemove("Simpsons", out stockValue);
            Console.WriteLine($"Tried to remove remove Simpsons tshirts wich had {stockValue} of stock with result {result}");


            //Concurrent Queue
            CQueue queue = new CQueue();

            queue.Enqueue("Simpsons");
            queue.Enqueue("FamilyGuy");
            queue.Enqueue("StarWars");

            string shirt;

            result = queue.TryPeek(out shirt);
            if (result)
            {
                Console.WriteLine($"The item at the front of the queue is {shirt}");
            }
            else
            {
                Console.WriteLine($"Error peeking. Pervert?");
            }

            result = queue.TryDequeue(out shirt);

            if (result)
            {
                Console.WriteLine($"The item dequeued is {shirt}");
            }
            else
            {
                Console.WriteLine($"Error peeking. Pervert?");
            }

            result = queue.TryPeek(out shirt);
            if (result)
            {
                Console.WriteLine($"The item at the front of the queue (after dequeue) is {shirt}");
            }
            else
            {
                Console.WriteLine($"Error peeking. Pervert?");
            }


            //Concurrent Stack

            CStack stack = new CStack();

            stack.Push("Simpsons");
            stack.Push("FamilyGuy");
            stack.Push("StarWars");


            result = stack.TryPeek(out shirt);
            if (result)
            {
                Console.WriteLine($"The item at the Top of the stack is {shirt}");
            }
            else
            {
                Console.WriteLine($"Error peeking. Pervert?");
            }

            result = stack.TryPop(out shirt);

            if (result)
            {
                Console.WriteLine($"The item poped is {shirt}");
            }
            else
            {
                Console.WriteLine($"Error peeking. Pervert?");
            }

            result = stack.TryPeek(out shirt);
            if (result)
            {
                Console.WriteLine($"The item at the Top of the stack (after Pop) is {shirt}");
            }
            else
            {
                Console.WriteLine($"Error peeking. Pervert?");
            }


            //ConcurrentBag No garanties for the order of put and take. In single thread it tends to have the same beahaviour of stack. It is
            //used if the same thread does multiple add and remove. in that case it is more efficient.
            CBag bag = new CBag();

            bag.Push("Simpsons");
            bag.Push("FamilyGuy");
            bag.Push("StarWars");


            result = bag.TryPeek(out shirt);
            if (result)
            {
                Console.WriteLine($"The item peeked is {shirt}");
            }
            else
            {
                Console.WriteLine($"Error peeking. Pervert?");
            }

            result = bag.TryPop(out shirt);

            if (result)
            {
                Console.WriteLine($"The item poped is {shirt}");
            }
            else
            {
                Console.WriteLine($"Error peeking. Pervert?");
            }

            result = bag.TryPeek(out shirt);
            if (result)
            {
                Console.WriteLine($"The item at the Top of the stack (after Pop) is {shirt}");
            }
            else
            {
                Console.WriteLine($"Error peeking. Pervert?");
            }
        }