예제 #1
0
 public void StartReceiving()
 {
     Task.Run(async() =>
     {
         while (true)
         {
             try
             {
                 var udpReceiveResult = await _udpClient.ReceiveAsync();
                 MessageReceived?.Invoke(udpReceiveResult);
             }
             catch (SocketException ex)
             {
                 if (ex.SocketErrorCode != SocketError.ConnectionReset)
                 {
                     _logger.LogError(ex);
                     throw;
                 }
             }
             catch (Exception ex)
             {
                 _logger.LogError(ex);
                 throw;
             }
         }
     });
 }
예제 #2
0
        private void OnEditorPlayModeChanged()
        {
            if (Application.isPlaying == false)
            {
                MyLogger.Log("OnEditorPlayModeChanged()");
                UnityEditor.EditorApplication.playmodeStateChanged -= OnEditorPlayModeChanged;

                try
                {
                    a.Dispose();
                }
                catch (Exception e)
                {
                    MyLogger.LogError(LOG_TAG, "OnEditorPlayModeChanged() ", e.Message);
                }

                try
                {
                    b.Dispose();
                }
                catch (Exception e)
                {
                    MyLogger.LogError(LOG_TAG, "OnEditorPlayModeChanged()", e.Message);
                }
            }
        }
예제 #3
0
 public static void CopyDirectroy(string from, string to)
 {
     try
     {
         if ((to.Length - 1) != Path.DirectorySeparatorChar)
         {
             to += Path.DirectorySeparatorChar;
         }
         if (!Directory.Exists(to))
         {
             Directory.CreateDirectory(to);
         }
         string[] fileList = Directory.GetFileSystemEntries(from);
         foreach (string file in fileList)
         {
             if (Directory.Exists(file))
             {
                 CopyDirectroy(file, to + Path.GetFileName(file));
             }
             else
             {
                 File.Copy(file, to + Path.GetFileName(file), true);
             }
         }
     }
     catch (Exception ex)
     {
         MyLogger.LogError("Copy Directory Error" + ex.Message);
     }
 }
예제 #4
0
        //======================================================================


        public void CreateGame(GameParam param)
        {
            if (isRunning)
            {
                MyLogger.LogError(LOG_TAG, "Create()", "Game Is Runing Already!");
                return;
            }

            this.Log(LOG_TAG, "Create() param:{0}", param);

            //create game context to store global game status
            context                   = new GameContext();
            context.param             = param;
            context.random.Seed       = param.randSeed;
            context.currentFrameIndex = 0;


            //create map
            gameMap = new GameMap();
            gameMap.Load(param.mapData);
            context.mapSize = gameMap.Size;


            //initial entity factory
            EntityFactory.Init();
            ViewFactory.Init(gameMap.View.transform);

            //initial game camera
            GameCamera.Create();

            isRunning = true;
        }
 /// <summary>
 /// 更新里程信息按钮事件
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnUpdateMileInfo_Click(object sender, EventArgs e)
 {
     if (waveformMaker.WaveformDataList[0].MileageFix.FixData == null || waveformMaker.WaveformDataList[0].MileageFix.FixData.Count == 0)
     {
         MessageBox.Show("没有进行里程校正,不需要更新里程!");
         return;
     }
     if (waveformMaker.WaveformDataList[0].InvalidDataList.Count == 0)
     {
         return;
     }
     try
     {
         for (int i = 0; i < waveformMaker.WaveformDataList[0].InvalidDataList.Count; i++)
         {
             InvalidData data       = waveformMaker.WaveformDataList[0].InvalidDataList[i];
             float       iStartMile = waveformMaker.WaveformDataList[0].MileageFix.CalcPointMileStone(long.Parse(data.sStartPoint));
             float       iEndMile   = waveformMaker.WaveformDataList[0].MileageFix.CalcPointMileStone(long.Parse(data.sEndPoint));
             invalidManager.InvalidDataUpdate(idfFilePath, data.sStartPoint,
                                              data.sEndPoint, (iStartMile / 1000f).ToString(), (iEndMile / 1000f).ToString());
         }
     }
     catch (Exception ex)
     {
         MyLogger.LogError("更新无效数据时失败", ex);
     }
     MessageBox.Show("更新成功!");
     GetInvalidData();
 }
예제 #6
0
        public static string DecodeFromImage(Texture2D image)
        {
            MyLogger.Log(LOG_TAG, "DecodeFromImage() ");

            try
            {
                Color32LuminanceSource src = new Color32LuminanceSource(image.GetPixels32(), image.width, image.height);

                Binarizer    bin = new GlobalHistogramBinarizer(src);
                BinaryBitmap bmp = new BinaryBitmap(bin);

                MultiFormatReader mfr    = new MultiFormatReader();
                Result            result = mfr.decode(bmp);

                if (result != null)
                {
                    return(result.Text);
                }
                else
                {
                    MyLogger.LogError(LOG_TAG, "DecodeFromImage()", "Decode failed!");
                }
            }
            catch (Exception e)
            {
                MyLogger.LogError(LOG_TAG, "DecodeFromImage() ", e.Message);
            }

            return("");
        }
예제 #7
0
        /// <summary>
        /// 保存按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSave_Click(object sender, EventArgs e)
        {
            //删除
            _fixedTable = new UserFixedTable(waveformMaker.WaveformDataList[0].IndexOperator, waveformMaker.WaveformDataList[0].CitFile.iKmInc);
            _fixedTable.Clear();
            //重新保存索引库
            for (int i = 0; i < dgvMarkedPoints.Rows.Count; i++)
            {
                UserMarkedPoint markedPoint = new UserMarkedPoint();
                markedPoint.ID             = dgvMarkedPoints.Rows[i].Cells[0].Value.ToString();
                markedPoint.FilePointer    = long.Parse(dgvMarkedPoints.Rows[i].Cells[2].Value.ToString());
                markedPoint.UserSetMileage = float.Parse(dgvMarkedPoints.Rows[i].Cells[3].Value.ToString()) * 1000;
                _fixedTable.MarkedPoints.Add(markedPoint);
            }
            _fixedTable.Save();
            //创建计算后的索引库
            MilestoneFix fix = new MilestoneFix(waveformMaker.WaveformDataList[0].CitFilePath, waveformMaker.WaveformDataList[0].IndexOperator);

            try
            {
                fix.ClearMilestoneFixTable();
                fix.RunFixingAlgorithm();
                fix.SaveMilestoneFixTable();
                MessageBox.Show("保存成功!");
                btnLoad_Click(sender, e);
            }
            catch (Exception ex)
            {
                MyLogger.LogError("手动里程修正失败", ex);
                MessageBox.Show("错误:" + ex.Message);
            }
        }
        /// <summary>
        /// 另存配置
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SaveAsButton1_Click(object sender, EventArgs e)
        {
            try
            {
                SaveAsFileDialog1.FileName = "";
                DialogResult dr = SaveAsFileDialog1.ShowDialog();
                if (dr == DialogResult.OK)
                {
                    File.Copy(channelConfigPathCurrent, SaveAsFileDialog1.FileName, true);
                    //把所选层的配置文件设置为新的
                    channelConfigPathCurrent = SaveAsFileDialog1.FileName;
                    //保存配置到文件
                    SaveChannelSetToConfigFile(channelConfigPathCurrent);

                    //GetChannelsData(channelConfigPathCurrent, channelNames);
                    ConfigLabel.Text = Path.GetFileName(channelConfigPathCurrent);
                    MessageBox.Show("保存成功!");
                }
            }
            catch (Exception ex)
            {
                MyLogger.LogError("保存配置文件时出错", ex);
                MessageBox.Show(ex.Message);
            }
        }
예제 #9
0
 /// <summary>
 /// 加载数据
 /// </summary>
 public void LoadData()
 {
     try
     {
         dgvLayerInfo.Rows.Clear();
         for (int i = 0; i < _maker.WaveformDataList.Count; i++)
         {
             object[] cell = new object[7];
             cell[0] = (i + 1).ToString();
             cell[1] = _maker.WaveformDataList[i].CitFile.sTrackName + _maker.WaveformDataList[i].CitFile.iDir;
             cell[2] = _maker.WaveformDataList[i].CitFile.sDate;
             string dir = _maker.WaveformDataList[i].CitFile.iRunDir == 0 ? "正" : "反";
             cell[3] = dir;
             cell[4] = _maker.WaveformDataList[i].MileList.milestoneList[0].GetMeterString();
             string inc = _maker.WaveformDataList[i].CitFile.iKmInc == 0 ? "增" : "减";
             cell[5] = inc;
             cell[6] = _maker.WaveformDataList[i].CitFile.sTime;
             dgvLayerInfo.Rows.Add(cell);
         }
     }
     catch (Exception ex)
     {
         MyLogger.LogError("加载图层数据时出错", ex);
         MessageBox.Show("加载图层数据时出错:" + ex.Message);
     }
 }
예제 #10
0
 public static byte[] ReadFile(string fullpath)
 {
     byte[] buffer = null;
     if (File.Exists(fullpath))
     {
         FileStream fs = null;
         try
         {
             fs     = new FileStream(fullpath, FileMode.Open, FileAccess.Read);
             buffer = new byte[fs.Length];
             fs.Read(buffer, 0, buffer.Length);
         }
         catch (Exception e)
         {
             MyLogger.LogError(LOG_TAG, "ReadFile() Path:{0}, Error:{1}", fullpath, e.Message);
         }
         finally
         {
             if (fs != null)
             {
                 fs.Close();
             }
         }
     }
     else
     {
         MyLogger.LogError(LOG_TAG, "ReadFile() File is Not Exist: {0}", fullpath);
     }
     return(buffer);
 }
예제 #11
0
        private void LoadData()
        {
            try
            {
                lstallLineName.Items.Clear();
                //liyang: 这个form一定是在waveconvertform加载完毕后,才会出现,所以有些数据直接从waveconvertform拿即可,不用再从idf读。
                if (_convertForm.DtLineCodeAndName != null && _convertForm.DtLineCodeAndName.Rows.Count > 0)
                {
                    foreach (var row in _convertForm.DtLineCodeAndName.AsEnumerable())
                    {
                        lstallLineName.Items.Add(row["线路名"].ToString());
                    }
                }



                // 从自选线路代码表中填充: selectedLineNameListBox
                LoadUserSelectionTable();
            }
            catch (Exception ex)
            {
                MyLogger.LogError("加载线路出错", ex);
                MessageBox.Show(ex.Message);
            }
        }
예제 #12
0
        public async Task CreateMasterUser()
        {
            var user = await _userManager.FindByNameAsync("admin");

            if (user == null)
            {
                user = new ApplicationUser()
                {
                    Email    = "*****@*****.**",
                    UserName = "******"
                };

                IdentityResult result = await _userManager.CreateAsync(user, "Admin_01");

                if (!result.Succeeded)
                {
                    MyLogger.LogError("Could not create admin user.  Messages were: " + String.Join("; ", result.Errors.Select(x => x.Description)));
                    return;
                }
            }

            var claims = await _userManager.GetClaimsAsync(user);

            await AddClaim(user, claims, "ManageConfig");
            await AddClaim(user, claims, "ArmDisarm");

            MyLogger.LogInfo("Added the default roles to admin user with default password and roles");
        }
예제 #13
0
        /// <summary>
        /// status information to the smart things zone
        /// </summary>
        /// <param name="zoneInfo"></param>
        public static void UpdateZone(ZoneInfo zoneInfo)
        {
            try
            {
                OauthInfo authInfo = OauthRepository.Get();

                string url = authInfo.endpoints[0].uri + $"/UpdateZone";

                var client = new System.Net.Http.HttpClient();

                System.Net.Http.HttpRequestMessage msg = new System.Net.Http.HttpRequestMessage(System.Net.Http.HttpMethod.Post, url);
                msg.Headers.Add("Authorization", $"Bearer {authInfo.accessToken}");

                List <KeyValuePair <string, string> > parms = new List <KeyValuePair <string, string> >();
                parms.Add(new KeyValuePair <string, string>("Id", zoneInfo.Id.ToString()));
                parms.Add(new KeyValuePair <string, string>("Status", zoneInfo.Status));
                parms.Add(new KeyValuePair <string, string>("Name", zoneInfo.Name));
                msg.Content = new System.Net.Http.FormUrlEncodedContent(parms);
                var response = client.SendAsync(msg);
                response.Wait();

                if (response.Result.StatusCode != System.Net.HttpStatusCode.Created)
                {
                    MyLogger.LogError($"Error updating smart things zone {zoneInfo.Id} with status {zoneInfo.Status}");
                }
            }
            catch (Exception ex)
            {
                MyLogger.LogError($"Error updating smart things zone {zoneInfo.Id} with status {zoneInfo.Status}.  Exception was {MyLogger.ExMsg(ex)}");
            }
        }
예제 #14
0
        /// <summary>
        /// 修正按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnModify_Click(object sender, EventArgs e)
        {
            if (listBoxIICFile.Items.Count <= 0)
            {
                MessageBox.Show("没有IIC文件列表,请先添加文件!");
                return;
            }
            this.progressBar1.Visible = true;
            this.Enabled = false;
            try
            {
                Task t = new Task(new Action(() => Process()));
                t.ContinueWith((task) =>
                {
                    if (task.IsCompleted || task.Exception == null)
                    {
                        MessageBox.Show("修正成功!");
                        this.Invoke(new Action(() => { SetEnabledThis(true); }));
                    }
                    else
                    {
                        MessageBox.Show("错误:" + task.Exception.InnerException);
                    }
                });
                t.Start();
            }
            catch (Exception ex)
            {
                MyLogger.LogError("处理IIC修正时出现错误", ex);
                MessageBox.Show("处理IIC修正时出现错误:" + ex.Message);
            }

            //backgroundWorker1.RunWorkerAsync();
        }
        /// <summary>
        /// 导出里程修正索引到cit文件
        /// </summary>
        /// <param name="selectedPath"></param>
        /// <param name="exportPath"></param>
        /// <param name="count"></param>
        private void ExportCitAndIndex(string selectedPath, List <string> exportPath, int count)
        {
            btnExport.Enabled  = false;
            labLoading.Visible = true;
            for (int i = 0; i < dgvBoundary.Rows.Count; i++)
            {
                double startMile = double.Parse(dgvBoundary.Rows[i].Cells[1].Value.ToString());
                double endMile   = double.Parse(dgvBoundary.Rows[i].Cells[2].Value.ToString());
                try
                {
                    Task task = new Task(() =>
                    {
                        string path = _maker.WaveformDataList[0].ExportCITFileAndIndexData(selectedPath, startMile, endMile);

                        exportPath.Add(path);
                    });
                    task.ContinueWith((t) =>
                    {
                        if (t.IsFaulted || t.Exception != null)
                        {
                            MessageBox.Show("导出过程中出现错误:" + t.Exception.InnerException.Message);
                            exportPath.Add("");
                        }
                        if (exportPath.Count == count)
                        {
                            if (exportPath.Count > 0)
                            {
                                int success    = 0;
                                string allPath = "";
                                foreach (string path in exportPath)
                                {
                                    if (!string.IsNullOrEmpty(path))
                                    {
                                        allPath += "\n" + path;
                                        success++;
                                    }
                                }
                                MessageBox.Show("成功导出" + success + "条数据,导出路径为:" + allPath);
                            }
                            else
                            {
                                MessageBox.Show("任务完成,但没有数据导出,可能由于里程不处于管界范围内!");
                            }
                            this.Invoke(new Action(() =>
                            {
                                btnExport.Enabled  = true;
                                labLoading.Visible = false;
                            }));
                        }
                    });
                    task.Start();
                }
                catch (Exception ex)
                {
                    MyLogger.LogError("导出修正数据过程中出现错误", ex);
                    MessageBox.Show("导出过程中出现错误:" + ex.Message);
                }
            }
        }
예제 #16
0
        public async Task <PriceModel> GetPrice()
        {
            try
            {
                var market = _marketApis.First(m => m.Market == _configuration["Market"]);
                return(await market.RetrievePriceFromApi());
            }
            catch (InvalidOperationException ex)
            {
                _logger.LogError($"De opgegeven market wordt niet ondersteund: {_configuration["Market"]}.", ex);
            }
            catch (Exception ex)
            {
                _logger.LogError("Er is iets misgegaan bij het ophalen van een prijs.", ex);
            }

            return(null);
        }
예제 #17
0
        /// <summary>
        /// 选择geo文件
        /// </summary>
        /// <param name="sender">选择按钮</param>
        /// <param name="e">参数</param>
        private void btnSelectGeoFile_Click(object sender, EventArgs e)
        {
            openFileDialog.Filter = "GEO波形文件 | *.geo";
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    txtGeoPath.Text = openFileDialog.FileName;
                    _geoFilePath    = txtGeoPath.Text;
                    string[] sDHI          = Path.GetFileNameWithoutExtension(_geoFilePath).Split('-');
                    string   lineShortName = sDHI[0].ToUpper();
                    _geoHelper.QueryDataChannelInfoHead(_geoFilePath);
                    string mileageRange = _geoHelper.GetExportDataMileageRange(_geoFilePath);
                    mileageRange = mileageRange.Substring(2);
                    float startMileage = float.Parse(mileageRange.Substring(0, mileageRange.IndexOf("-")));
                    float endMileage   = float.Parse(mileageRange.Substring(mileageRange.IndexOf("-") + 1));
                    if (startMileage < endMileage)
                    {
                        cbxKmInc.SelectedIndex = 0;
                    }
                    else
                    {
                        cbxKmInc.SelectedIndex = 1;
                    }
                    txtStartPos.Text = startMileage.ToString();
                    txtEndPos.Text   = endMileage.ToString();
                    string time     = String.Format("{0}:{1}:{2}", sDHI[4].Substring(0, 2), sDHI[4].Substring(2, 2), sDHI[4].Substring(4, 2));
                    string date     = String.Format("{0}/{1}/{2}", sDHI[3].Substring(2, 2), sDHI[3].Substring(0, 2), sDHI[3].Substring(4, 4));
                    string lineCode = GetLineCodeByName(lineShortName);
                    if (!string.IsNullOrEmpty(lineCode))
                    {
                        var lineName = _dtLineCodeAndName.AsEnumerable().Where(p => p.Field <string>("自定义线路编号") == lineCode);
                        if (lineName != null)
                        {
                            cbxLineName.SelectedItem = lineName;
                        }
                    }
                    if (_dicDirAndDesc.ContainsKey(lineShortName.Substring(3, 1)))
                    {
                        cbxLineDir.SelectedItem = _dicDirAndDesc[lineShortName.Substring(3, 1)];
                    }
                    else
                    {
                        cbxLineDir.SelectedIndex = 0;
                    }
                    dateTimePickerDate.Value = DateTime.Parse(date);
                    dateTimePickerTime.Value = DateTime.Parse(time);

                    txtIICFilePath.Text = string.Empty;
                }
                catch (Exception ex)
                {
                    MyLogger.LogError("加载Geo文件时失败", ex);
                    MessageBox.Show(ex.Message);
                }
            }
        }
        /// <summary>
        /// Install or Update Devices in the SmartThings App
        /// </summary>
        public static void InstallDevices(string hostString)
        {
            try
            {
                string[] h         = hostString.Split(':');
                string   j64Server = h[0];
                int      j64Port   = 80;
                if (h.Length > 1)
                {
                    j64Port = Convert.ToInt32(h[1]);
                }

                var hostName = System.Net.Dns.GetHostEntryAsync(System.Net.Dns.GetHostName());
                hostName.Wait();
                foreach (var i in hostName.Result.AddressList)
                {
                    if (i.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                    {
                        j64Server = i.ToString();
                        break;
                    }
                }

                OauthInfo authInfo = OauthRepository.Get();

                if (authInfo == null | authInfo.endpoints == null || authInfo.endpoints.Count == 0)
                {
                    MyLogger.LogError("OAuth endpoints have not been created. Cannot update smart things at this time");
                    return;
                }
                string url = authInfo.endpoints[0].uri + $"/installDevices";

                var client = new System.Net.Http.HttpClient();

                System.Net.Http.HttpRequestMessage msg = new System.Net.Http.HttpRequestMessage(System.Net.Http.HttpMethod.Post, url);
                msg.Headers.Add("Authorization", $"Bearer {authInfo.accessToken}");

                List <KeyValuePair <string, string> > parms = new List <KeyValuePair <string, string> >();
                parms.Add(new KeyValuePair <string, string>("j64Server", j64Server));
                parms.Add(new KeyValuePair <string, string>("j64Port", j64Port.ToString()));
                parms.Add(new KeyValuePair <string, string>("j64UserName", "admin"));
                parms.Add(new KeyValuePair <string, string>("j64Password", "Admin_01"));
                msg.Content = new System.Net.Http.FormUrlEncodedContent(parms);
                var response = client.SendAsync(msg);
                response.Wait();

                if (response.Result.StatusCode != System.Net.HttpStatusCode.Created)
                {
                    MyLogger.LogError($"Error installing smart things devices.  StatusCode was {response.Result.StatusCode}");
                }
            }
            catch (Exception ex)
            {
                MyLogger.LogError($"Error installing smart things devices.  Exception was {MyLogger.ExMsg(ex)}");
            }
        }
예제 #19
0
 //=================================================================================
 //Receive
 #region message receive functions: ACK, SYN, Broadcast
 private void OnReceive(byte[] buffer, int size, IPEndPoint remotePoint)
 {
     try
     {
         var msg = PBSerializer.NDeserialize <RPCMessage>(buffer);
         HandleRPCMessage(msg, remotePoint);
     }
     catch (Exception e)
     {
         MyLogger.LogError(LOG_TAG, "OnReceive()", "->HandleMessage->Error:" + e.Message + "\n" + e.StackTrace);
     }
 }
예제 #20
0
        private bool TryHandleOneProtocol(NetBuffer stream, uint connId)
        {
            ProtocolHeader head = ProtocolHeader.Deserialize(stream);

            if (head == null)
            {
                return(false);
            }

            if (stream.Length < head.dataSize + ProtocolHeader.Length)
            {
                return(false);
            }

            if (m_recvBufferTemp.Capacity < head.dataSize)
            {
                MyLogger.LogError(TAG, "OnRecv() no enough buffer! connId:{0}, dataSize:{1}, RecvBuffCapacity:{2}",
                                  connId.ToString(), head.dataSize, m_recvBufferTemp.Capacity);

                return(false);
            }

            stream.ReadBytes(m_recvBufferTemp.GetBytes(), 0, head.dataSize);
            m_recvBufferTemp.AddLength(head.dataSize, 0);

            ushort sum = SGFEncoder.CheckSum(m_recvBufferTemp.GetBytes(), head.dataSize);

            if (sum != head.checksum)
            {
                MyLogger.LogError(TAG, "OnRecv() CheckSum failed! connId:{0}, dataSize:{1}, RecvBuffSize:{2}",
                                  connId.ToString(), head.dataSize, m_recvBufferTemp.Length);

                //reset conncetion
                stream.Clear();
                return(false);
            }

            object ptlObj = DeserializeProtocol(head.pid, m_recvBufferTemp.GetBytes(), m_recvBufferTemp.Length);

            if (ptlObj != null)
            {
                DispatchProtocol(head.pid, head.index, ptlObj);
            }
            else
            {
                m_recvBufferTemp.Position = 0;
                byte[] buffer = m_recvBufferTemp.ReadBytes(head.dataSize);
                DispatchProtocol(head.pid, head.index, buffer);
            }

            return(true);
        }
예제 #21
0
        public static void Create()
        {
            Camera c = GameObject.FindObjectOfType <Camera>();

            if (c != null)
            {
                GameObjectUtils.EnsureComponent <GameCamera>(c.gameObject);
            }
            else
            {
                MyLogger.LogError("GameCamera", "Create()", "Cannot Find Camera In Scene!");
            }
        }
예제 #22
0
        internal int Send(uint connId, byte[] buffer, int len)
        {
            IConnection conn = m_mapConnection[connId];

            if (conn != null)
            {
                return(conn.Send(buffer, len));
            }
            else
            {
                MyLogger.LogError(TAG, "Send() connId:{0} doesn't exist!", connId.ToString());
                return(-1);
            }
        }
예제 #23
0
        internal int Recv(uint connId, byte[] buffer, int offset)
        {
            IConnection conn = m_mapConnection[connId];

            if (conn != null)
            {
                return(conn.Recv(buffer, offset));
            }
            else
            {
                MyLogger.LogError(TAG, "Recv() connId:{0} doesn't exist!", connId.ToString());
                return(-1);
            }
        }
예제 #24
0
 void FixedUpdate()
 {
     if (FixedUpdateEvent != null)
     {
         try
         {
             FixedUpdateEvent();
         }
         catch (Exception e)
         {
             MyLogger.LogError("MonoHelper", "FixedUpdate() Error:{0}\n{1}", e.Message, e.StackTrace);
         }
     }
 }
예제 #25
0
 public void Invoke()
 {
     if (func != null)
     {
         try
         {
             func(args);
         }
         catch (Exception e)
         {
             MyLogger.LogError("DelayInvoker", "Invoke() Error:{0}\n{1}", e.Message, e.StackTrace);
         }
     }
 }
예제 #26
0
        //------------------------------------------------------------

        #region start server
        public bool Start(int port)
        {
            if (isRunning)
            {
                MyLogger.LogWarning(LOG_TAG_MAIN, "Start()", "cannot start duplicated Server!");
                return(false);
            }
            MyLogger.Log(LOG_TAG_MAIN, "Start()  port = {0}", port.ToString());

            DelAllSession();

            try
            {
                mLogicLastTicks   = DateTime.Now.Ticks;
                mRealTicksAtStart = mLogicLastTicks;

                //create Game Socket
                mGameSocket = new KCPSocket(0, 1);
                mGameSocket.AddReceiveListener(OnReceive);
                isRunning = true;

                //create game room
                mRoom = new FSPRoom();
                mRoom.Create();
                mRoomRPC = mRoom;

                //create  thread
                MyLogger.Log(LOG_TAG_MAIN, "Start()  create server thead");
                mThreadMain = new Thread(Thread_Main)
                {
                    IsBackground = true
                };
                mThreadMain.Start();
            }
            catch (Exception e)
            {
                MyLogger.LogError(LOG_TAG_MAIN, "Start() ", e.Message);
                Close();
                return(false);
            }

            //when user exit the game using stop button in UnityEditor, cannot release all resource in time
            //add listener here
#if UNITY_EDITOR
            UnityEditor.EditorApplication.playmodeStateChanged -= OnEditorPlayModeChanged;
            UnityEditor.EditorApplication.playmodeStateChanged += OnEditorPlayModeChanged;
#endif
            return(true);
        }
예제 #27
0
        public static void Main(string[] args)
        {
            //logger.Error("Only errors");

            //logger.Info("Login");

            LogThis("Message");

            MyLogger myLogger = new MyLogger("ProgramLogging");

            myLogger.LogError(DateTime.Now, "this error", "Arturo", "login");


            //logger.Fatal("100 fails ");
        }
예제 #28
0
 public static bool IseEmptyDirectory(string directoryPath)
 {
     try
     {
         string[] fileNames = GetFileNames(directoryPath);
         if (fileNames.Length > 0)
         {
             return(false);
         }
         return(true);
     }
     catch (Exception ex)
     {
         MyLogger.LogError("FileUtil:IsEmptyDirectory;Common", ex);
         return(true);
     }
 }
예제 #29
0
        private static IEnumerator DelayInvokerOnEndOfFrameWorker(DelayFunction func, params object[] args)
        {
            yield return(msWaitForEndOfFrame);

            //Profiler.BeginSample("DelayInvoker_DelayInvokerOnEndOfFrame");

            try
            {
                func(args);
            }
            catch (Exception e)
            {
                MyLogger.LogError("DelayInvoker", "DelayInvokerOnEndOfFrame() Error:{0}\n{1}", e.Message, e.StackTrace);
            }

            //Profiler.EndSample();
        }
예제 #30
0
        public static void CreateView(string resPath, string resDefaultPath, EntityObject entity, Transform parent = null)
        {
            ViewObject obj         = null;
            string     recycleType = resPath;
            bool       useRecycler = true;

            obj = objRecycler.Pop(recycleType) as ViewObject;
            if (obj == null)
            {
                useRecycler = false;
                obj         = InstanceViewFromPrefab(recycleType, resDefaultPath);
            }

            if (obj != null)
            {
                if (!obj.gameObject.activeSelf)
                {
                    obj.gameObject.SetActive(true);
                }

                if (parent != null)
                {
                    obj.transform.SetParent(parent, false);
                }
                else
                {
                    obj.transform.SetParent(viewRoot, false);
                }

                obj.CreateInFactory(entity, recycleType);

                if (EnableLog && MyLogger.EnableLog)
                {
                    MyLogger.Log(LOG_TAG, "CreateView() {0}:{1} -> {2}:{3}, UseRecycler:{4}",
                                 entity.GetType().Name, entity.GetHashCode(),
                                 obj.GetRecycleType(), obj.GetInstanceID(),
                                 useRecycler);
                }

                if (mapObjectList.ContainsKey(entity))
                {
                    MyLogger.LogError(LOG_TAG, "CreateView()", " Mapping already exist!");
                }
                mapObjectList[entity] = obj;
            }
        }