/// <summary> /// 异步循环扫描命令队列并添加到任务池中 /// </summary> private static void ScanCommandAndExecuteAsync() { while (true) { if (!importCts.Token.CanBeCanceled)//true为已取消 { onInitTaskPool("----------------------------------" + DateTime.Now + ":准备接受命令并运行消息循环开始...-----------------------------------"); System.Threading.Thread.Sleep(1000); try { ScanCommandAndExecute(); } catch (Exception ex) { onInitTaskPool("系统级不可恢复严重错误", ex); } onInitTaskPool("----------------------------------" + DateTime.Now + ":消息循环结束...-----------------------------------"); LogProxy.AddNodeLog(strLog.ToString(), LogType.RefreshCommandQueueLog); strLog.Clear(); System.Threading.Thread.Sleep(3000); } else { importCts.Dispose(); //task.Dispose(); importCts = null; task = null; break; } } }
internal static void SROLogging(SRO[] objs) { try { List <SRO> list = new List <SRO>(); SROLog log; foreach (SRO obj in objs) { if (obj == null || obj.SaveMode == SROSaveMode.Init || obj.SaveMode == SROSaveMode.NoChange || !(obj is INeedFullLogging)) { continue; } log = new SROLog(); log.ObjectId = obj.Id; log.ObjectType = obj.GetType().FullName; log.ObjectJson = JsonConvert.SerializeObject(obj); log.HostName = Tools.GetHostName(); list.Add(log); } if (list.Count > 0) { PersisterService.SaveObject(list.ToArray()); } } catch (Exception ex) { LogProxy.Error(ex, false); } }
protected override void OnStart(string[] args) { LogProxy.Info("同步服务端启动开始"); Scree.Core.IoC.ServiceRoot.Init(); LogProxy.Info("同步服务端启动结束"); // TODO: 在此处添加代码以启动服务。 }
public static void FReceiveLobbyPacket(IGamerEntity gamer, Dictionary <byte, object> packet) { if (!Enum.TryParse(packet[0].ToString(), out EServerLobbyCode code)) { LogProxy.WriteError($"Parse ServerLobbyCode fail, Value:{packet[0]}"); return; } switch (code) { case EServerLobbyCode.Rooms: onGetRoomList(); break; case EServerLobbyCode.AllPeers: onGetAllRoommates(); break; case EServerLobbyCode.RoomReady: onRoommateReady(); break; } void onGetRoomList() { var webRoomPacket = (RoomPacket[])packet[1]; int waitingRoomCount = int.Parse(packet[2].ToString()); int battleRoomCount = int.Parse(packet[3].ToString()); gamer.input.SetLevel(); } void onGetAllRoommates() { var playerPackets = (PlayerPacket[])packet[1]; int comeDown = int.Parse(packet[2].ToString()); var roomID = packet[3].ToString(); gamer.mPlayerNameList.Clear(); for (int i = 0; i < playerPackets.Length; i++) { if (playerPackets[i].SlotID == -1) { continue; } gamer.mPlayerNameList.Add(playerPackets[i].SlotID, playerPackets[i].Name); if (playerPackets[i].Name == gamer.account.Info.Name) { gamer.input.SlotID = playerPackets[i].SlotID; } } gamer.input.TrySetNextLevel(GamerInput.Level.WaitingPeers); } void onRoommateReady() { //當 有玩家按 Ready 時觸發 } }
internal Task <bool> SendTracer(LogProxy log = null) { var msg = GetTracerMessage(false); msg = LoggingMessage.Create(log, msg); return(WriteDirectAsync(msg, ResultProcessor.Tracer)); }
private static void Register() { Serilog.ILogger serilog = new LoggerConfiguration() .Enrich.FromLogProxy() .Destructure.UsingAttributes() .WriteTo.Seq(EnvVars.SeqAddress()) .CreateLogger(); Log.Logger = serilog; var builder = new ContainerBuilder(); // SSL gRPC var caCrt = File.ReadAllText(EnvVars.CaCrtPath()); var sslCredentials = new SslCredentials(caCrt); var registrationEngineGrpcChannel = new Channel( EnvVars.Target(@"RegistrationEngineHost", @"RegistrationEnginePort"), sslCredentials); // Create MagicOnion dynamic client proxy var registrationEngineGrpcClient = TrackingProxy.Create <IRegistrationEngineGrpc>(registrationEngineGrpcChannel); var registrationEngine = LogProxy.Create <IRegistrationEngine>(new RegistrationEngineClient(registrationEngineGrpcClient), serilog, LogType.All); builder.RegisterInstance <Serilog.ILogger>(serilog); builder.RegisterInstance <IRegistrationEngine>(registrationEngine); builder.RegisterType <MembershipManager>().As <IMembershipManager>(); IContainer container = builder.Build(); // Set up the service locator ServiceLocator.SetLocatorProvider(() => new AutofacServiceLocator(container)); GrpcEnvironment.SetLogger(new ConsoleLogger()); }
protected void UpdatePosition() { if (CurrentLocation.Value.HasValue && Director.TryGetEntity(CurrentLocation.Value.Value, out var currentLocationEntity)) { CurrentLocationEntity = currentLocationEntity; var nodeBehaviour = CurrentLocationEntity.EntityBehaviour as NodeBehaviour; if (nodeBehaviour == null) { LogProxy.Error($"EntityBehaviour for entity {Entity.Id} is not NodeBehaviour"); } if (transform.parent != CurrentLocationEntity.GameObject) { transform.SetParent(CurrentLocationEntity.GameObject.transform, true); } if (nodeBehaviour != null) { var visitorVectors = nodeBehaviour.GetVisitorPosition(VisitorPosition.Position); _rectTransform.anchoredPosition = new Vector3(visitorVectors.Position.x, visitorVectors.Position.y, transform.position.z); _rectTransform.eulerAngles = new Vector3(0, 0, visitorVectors.Rotation.z); } } else { LogProxy.Error($"Failed to load actor component(s) for UpdatePosition on entity {Entity.Id}"); } }
internal void Bestrow() { if (OriginalValue != null && OriginalValue.Count > 0) { return; } try { IMyPropertyInfo[] myPropertys = PropertyInfoProxy.GetProperties(this.GetType()); foreach (IMyPropertyInfo property in myPropertys) { if (property.IsLoad == false && property.IsSave == false) {//判断是否加载 continue; } object value = property.GetValue(this); OriginalValue[property.Name] = value; } } catch (Exception ex) { LogProxy.Error(ex, false); } }
internal void Reset() { if (OriginalValue == null || OriginalValue.Count == 0) { return; } try { IMyPropertyInfo[] myPropertys = PropertyInfoProxy.GetProperties(this.GetType()); foreach (IMyPropertyInfo property in myPropertys) { if (property.IsLoad == false) {//判断是否加载 continue; } object value = OriginalValue.ContainsKey(property.Name) ? OriginalValue[property.Name] : null; property.SetValue(this, value); } } catch (Exception ex) { LogProxy.Error(ex, false); } }
private static void PostCallbackThreadMethod(object obj) { ISynData[] objs = obj as ISynData[]; if (objs == null || objs.Length == 0) { return; } int cnt = 0; int interval = PostTryInterval; L: try { SynServerService.Add(objs); } catch (Exception ex) { LogProxy.Error(ex, false, string.Format(POSTFAIL, objs.Length)); if (cnt < PostTrys) { Thread.Sleep(interval); cnt++; interval *= PostTryMultiple; goto L; } } }
private static void Log(string message) { if (DebugLog) { LogProxy.Info(message); } }
protected override void onCompleteConnect(IAsyncResult iar) { bool connectResult = false; UdpClient tcpc; try { tcpc = (UdpClient)iar.AsyncState; IPEndPoint iPEndPoint = null; byte[] receiveBytes = tcpc.EndReceive(iar, ref iPEndPoint); if (receiveBytes[0].Equals(1)) { udpClient.BeginReceive(onCompleteReadFromServerStream, udpClient); connectResult = true; } MaintainConnecting_Start(); fireCompleteConnect(); } catch (Exception ex) { connectResult = false; LogProxy.WriteError(ex.StackTrace); fireCompleteDisconnect(); } }
public static DeleteNewsOutDTO DeleteNews(DeleteNewsInDTO inDto) { DeleteNewsOutDTO outDto = new DeleteNewsOutDTO(); try { if (inDto == null || string.IsNullOrEmpty(inDto.Id)) { outDto.ErrorMsg = "参数错误"; return(outDto); } News news = NewsService.GetNews(inDto.Id, LoadType.DataBaseDirect); if (news == null) { outDto.ErrorMsg = "新闻不存在"; return(outDto); } news.IsDeleted = true; string remark = "删除新闻"; SystemLog systemLog = LogService.CreateSystemLog(SystemLogType.DeleteNews, typeof(News), news.Id, remark); PersisterService.SaveObject(new SRO[] { news, systemLog }); outDto.IsSucceed = true; } catch (Exception ex) { outDto.ErrorMsg = ex.Message; LogProxy.Error(ex, false); } return(outDto); }
public void Test() { var proxy = new LogProxy(BaseAddress); proxy.Add(Token, AppId, new LogModel { Type = 1, Message = "test" }).Wait(); // падает при оппытке удаления пользователя }
private static void LoadSingleTypeCacheConfig(IEnumerable <XElement> types) { SingleTypeCacheConfig config; foreach (XElement el in types) { try { string name = el.Attribute("name").Value; if (string.IsNullOrEmpty(name)) { LogProxy.Warn(CACHETYPENAMEISNULL); continue; } bool isFix = false; if (el.Attribute("isfix") != null) { bool.TryParse(el.Attribute("isfix").Value.Trim(), out isFix); if (isFix) { config = new SingleTypeCacheConfig(name, true, 0, 0); MyCacheConfig[name] = config; continue; } } int second = 0; if (el.Attribute("second") != null) { int.TryParse(el.Attribute("second").Value.Trim(), out second); if (second < 0) { second = 0; } } int size = 0; if (el.Attribute("size") != null) { int.TryParse(el.Attribute("size").Value.Trim(), out size); if (size < 0) { size = 0; } } config = new SingleTypeCacheConfig(name, false, second, size); MyCacheConfig[name] = config; } catch (Exception ex) { LogProxy.Error(ex, false); } } }
public override void Connect(IPAddress address, int port) { tcpClient = new TcpClient(AddressFamily.InterNetworkV6); tcpClient.Client.DualMode = true; if (!IPTool.IOSCheck(address, out address)) { address = address.MapToIPv6(); } try { tcpClient.Connect(address, port); if (tcpClient.Connected) { fireCompleteConnect(); StartReceiveAsync(tcpClient); } else { fireCompleteDisconnect(); } } catch (SocketException e) { switch (e.ErrorCode) { case (int)SocketError.ConnectionRefused: fireCompleteDisconnect(); LogProxy.WriteLine(e.Message); break; } } }
private async Task StartReceiveAsync(TcpClient tcpc) { Task.Run(async() => { while (true) { try { byte[] buff = new byte[BufferSize]; int count = await tcpClient.GetStream().ReadAsync(buff, 0, buff.Length); Array.Resize(ref buff, count); if (count.Equals(0)) { LogProxy.WriteLine("Get Packet Length = 0"); DisConnect(); break; } Task.Run(() => { try { fireCompleteReadFromServerStream(buff); } catch (Exception e) { LogProxy.WriteError(e.Message); } }); } catch (Exception e) { if (!callForTcpClientClose) { DisConnect(); } callForTcpClientClose = false; LogProxy.WriteLine(e.Message); break; } } }); }
public override void BeginSend(byte[] datagram, int bytes) { if (udpClient != null) { udpClient.BeginSend(datagram, bytes, serverIPEndPoint, iar => { try { UdpClient tcpc; tcpc = (UdpClient)iar.AsyncState; tcpc.EndSend(iar); } catch (SocketException socketException) { if (!socketException.Message.Contains(SocketErrorMsgs3)) { LogProxy.WriteLine("Begin Send Socket Error : " + socketException.Message); } else { DisConnect(); } } fireCompleteSend(); }, udpClient); } }
private static void LoadSynClientConfig(IEnumerable <XElement> excludedTypes, IEnumerable <XElement> synTypes) { SynClientConfig config; foreach (XElement el in excludedTypes) { try { string name = el.Attribute("name").Value; if (string.IsNullOrEmpty(name)) { LogProxy.Warn(SYNCLIENTTYPENAMEISNULL); continue; } if (MySynClientConfig.ContainsKey(name)) { continue; } config = new SynClientConfig(name, true, false); MySynClientConfig[name] = config; } catch (Exception ex) { LogProxy.Error(ex, false); } } foreach (XElement el in synTypes) { try { string name = el.Attribute("name").Value; if (string.IsNullOrEmpty(name)) { LogProxy.Warn(SYNCLIENTTYPENAMEISNULL); continue; } if (MySynClientConfig.ContainsKey(name)) { continue; } bool isLazy = false; if (el.Attribute("islazy") != null) { bool.TryParse(el.Attribute("islazy").Value.Trim(), out isLazy); } config = new SynClientConfig(name, false, isLazy); MySynClientConfig[name] = config; } catch (Exception ex) { LogProxy.Error(ex, false); } } }
static int logWarning(IntPtr L) { try { int count = LuaDLL.lua_gettop(L); if (TypeChecker.CheckTypes <UnityEngine.Object, object>(L, 1) && TypeChecker.CheckParamsType <object>(L, 3, count - 2)) { UnityEngine.Object arg0 = (UnityEngine.Object)ToLua.ToObject(L, 1); object arg1 = ToLua.ToVarObject(L, 2); object[] arg2 = ToLua.ToParamsObject(L, 3, count - 2); LogProxy.logWarning(arg0, arg1, arg2); return(0); } else if (TypeChecker.CheckTypes <object>(L, 1) && TypeChecker.CheckParamsType <object>(L, 2, count - 1)) { object arg0 = ToLua.ToVarObject(L, 1); object[] arg1 = ToLua.ToParamsObject(L, 2, count - 1); LogProxy.logWarning(arg0, arg1); return(0); } else { return(LuaDLL.luaL_throw(L, "invalid arguments to method: LogProxy.logWarning")); } } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
private static async void RunTask(int count) { IList <Task> tasks = new List <Task>(); for (int i = 0; i < count; i++) { var task = Task.Run(() => { for (int index = 0; index < 100; index++) { LogProxy.Error(string.Format("{0}_{1}", "Exception : ", index), "Snake.DemoConsole", new Random().Next(1, 5), new List <string>() { "Block", "Red" }); LogProxy.Debug(string.Format("{0}_{1}", "Debug : ", index), "Snake.DemoConsole", tags: new List <string>() { "Blue", "Red" }); Console.WriteLine("Log{0} published", index); } }); tasks.Add(task); } await Task.WhenAll(tasks.ToArray()); Console.WriteLine("Completed..."); }
public MembershipManagerGrpc() { var serilog = ServiceLocator.Current.GetInstance <ILogger>(); var membershipManager = ServiceLocator.Current.GetInstance <IMembershipManager>(); _Impl = LogProxy.Create <IMembershipManager>(membershipManager, serilog, LogType.All); }
static int logChannel(IntPtr L) { try { int count = LuaDLL.lua_gettop(L); if (TypeChecker.CheckTypes <UnityEngine.Object, string, string>(L, 1) && TypeChecker.CheckParamsType <object>(L, 4, count - 3)) { UnityEngine.Object arg0 = (UnityEngine.Object)ToLua.ToObject(L, 1); string arg1 = ToLua.ToString(L, 2); string arg2 = ToLua.ToString(L, 3); object[] arg3 = ToLua.ToParamsObject(L, 4, count - 3); LogProxy.logChannel(arg0, arg1, arg2, arg3); return(0); } else if (TypeChecker.CheckTypes <string, string>(L, 1) && TypeChecker.CheckParamsType <object>(L, 3, count - 2)) { string arg0 = ToLua.ToString(L, 1); string arg1 = ToLua.ToString(L, 2); object[] arg2 = ToLua.ToParamsObject(L, 3, count - 2); LogProxy.logChannel(arg0, arg1, arg2); return(0); } else { return(LuaDLL.luaL_throw(L, "invalid arguments to method: LogProxy.logChannel")); } } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
private static void Clear() { LogProxy.InfoFormat(BEGINCLEAR, Data.Count); DateTime clearTime = DateTime.Now.AddMinutes(-TimeLimit); if (LockDicObj.TryEnterWriteLock(WriteLockTimeout)) { try { var keys = (from o in Data where o.Value.SynTime < clearTime select o.Key).ToArray(); foreach (var key in keys) { Data.Remove(key); } } catch (Exception ex) { LogProxy.Error(ex, false); } finally { LockDicObj.ExitWriteLock(); } } LogProxy.InfoFormat(ENDCLEAR, Data.Count); }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { foreach (NewsType item in Enum.GetValues(typeof(NewsType))) { drpType.Items.Add(new ListItem(item.ToString(), ((int)item).ToString())); } GetNewsInDTO inDto = new GetNewsInDTO(); inDto.Id = Request.QueryString["id"]; var outDto = NewsService.GetNews(inDto); if (!outDto.IsSucceed) { LogProxy.Error(outDto.ErrorMsg); Response.Redirect("/index.aspx"); } drpType.SelectedValue = ((int)outDto.Type).ToString(); txtTitle.Text = outDto.Title; txtAuthor.Text = outDto.Author; txtContext.Text = outDto.Context; } }
private static void LoadStorageContexts(IEnumerable <XElement> storageContexts) { StorageContext storageContext; bool isFirst = true; foreach (XElement el in storageContexts) { storageContext = BuilderStorageContext(el); if (string.IsNullOrEmpty(storageContext.Name)) { LogProxy.Warn(STORAGECONTEXTNAMEISNULL); continue; } StorageContexts[storageContext.Name] = storageContext; if (isFirst) { DefaultStorageContext = storageContext; isFirst = false; } else if (string.Equals(storageContext.Name, DEFAULTSTORAGECONTEXT, StringComparison.OrdinalIgnoreCase)) { DefaultStorageContext = storageContext; } } }
public static ReadingNewsOutDTO ReadingNews(DeleteNewsInDTO inDto) { ReadingNewsOutDTO outDto = new ReadingNewsOutDTO(); try { if (inDto == null || string.IsNullOrEmpty(inDto.Id)) { outDto.ErrorMsg = "参数错误"; return(outDto); } News news = NewsService.GetNews(inDto.Id, LoadType.DataBaseDirect); if (news == null) { outDto.ErrorMsg = "新闻不存在"; return(outDto); } news.ReadingQuantity++; PersisterService.SaveObject(news); outDto.IsSucceed = true; outDto.ReadingQuantity = news.ReadingQuantity; } catch (Exception ex) { outDto.ErrorMsg = ex.Message; LogProxy.Error(ex, false); } return(outDto); }
public RUdp() : base(NetworkProtocol.RUDP) { listener = new EventBasedNetListener(); client = new NetManager(listener) { DisconnectTimeout = 20 * 1000 }; client.UpdateTime = 15; listener.PeerConnectedEvent += (NetPeer peer) => { LogProxy.WriteLine("Connect Success : " + peer.EndPoint); this.peer = peer; fireCompleteConnect(); }; listener.PeerDisconnectedEvent += (NetPeer peer, DisconnectInfo disconnectInfo) => { client.Flush(); client.Stop(); fireCompleteDisconnect(); }; listener.NetworkReceiveEvent += (fromPeer, dataReader, deliveryMethod) => { byte[] packet = new byte[dataReader.AvailableBytes]; dataReader.GetBytes(packet, dataReader.AvailableBytes); fireCompleteReadFromServerStream(packet); dataReader.Recycle(); }; }
protected override void onCompleteReadFromServerStream(IAsyncResult iar) { UdpClient tcpc; try { tcpc = (UdpClient)iar.AsyncState; //取得這次傳入資料的長度 IPEndPoint iPEndPoint = null; byte[] receiveBytes = tcpc.EndReceive(iar, ref iPEndPoint); udpMaintainConnecting = true; fireCompleteReadFromServerStream(receiveBytes); } catch (Exception exc) { if (!exc.Message.Contains(SocketErrorMsgs) && !exc.Message.Contains(SocketErrorMsgs2)) { LogProxy.WriteLine(exc.Message); } } finally { if (udpClient != null && udpClient.Client.Connected) { udpClient.BeginReceive(onCompleteReadFromServerStream, udpClient); } } }
void OnEnable( ) { // instantiate a new instance of log proxy for use by viewer logProxy = new LogProxy( ); logProxy.Init(); // setup initial filter parms and their previous values if (levelColours == null) { category = (Log.Category) 0xFFFFFF; prevCategory = category; level = Log.Level.Trivial; prevLevel = level; logLevel = 0; pauseFrame = null; keyword = ""; Log.SetListener(OnLogChange); scrollPosition = 0f; activeMessage = null; stylesInitialized = false; logSize = Log.Instance.Count; isDirty = true; levelColours = new Dictionary <Log.Level, StateColour>( ); LoadSettings( ); } // assign application hook to register callbacks for console output and log them if needed Application.RegisterLogCallback(HandleLog); }
static SynServerService() { try { LogProxy.InfoFormat(CURRENTAPPID, AppId); ApplicationName = SynServerConfig.ApplicationName; if (SynServerConfig.Port > 0) { Port = SynServerConfig.Port; } if (SynServerConfig.ClearInterval > 0) { ClearInterval = SynServerConfig.ClearInterval * 1000; } if (SynServerConfig.TimeLimit > 0) { TimeLimit = SynServerConfig.TimeLimit; } } catch (Exception ex) { LogProxy.Fatal(ex, true); } }
private static void Main(string[] args) { var proxy = new MailLogProxy(); proxy.Send(); var dynamicProxy = new LogProxy<IMail>(new Mail()); var mail = dynamicProxy.GetTransparentProxy() as IMail; if (mail != null) { mail.Send(); } Console.ReadKey(); }