public UdpSession(UdpServer Server, Socket ServerSocket, IPEndPoint RemoteEndPoint, Func <ISessionContext, IBinaryTransformer, KeyValuePair <IServerImplementation, IStreamedVirtualTransportServer> > VirtualTransportServerFactory, Action <Action> QueueUserWorkItem) { this.Server = Server; this.ServerSocket = ServerSocket; this.RemoteEndPoint = RemoteEndPoint; this.LastActiveTimeValue = new LockedVariable <DateTime>(DateTime.UtcNow); ssm = new SessionStateMachine <StreamedVirtualTransportServerHandleResult, Unit>(ex => ex is SocketException, OnCriticalError, OnShutdownRead, OnShutdownWrite, OnWrite, OnExecute, OnStartRawRead, OnExit, QueueUserWorkItem); Context = Server.ServerContext.CreateSessionContext(); Context.Quit += ssm.NotifyExit; Context.Authenticated += () => Server.NotifySessionAuthenticated(this); var rpst = new Rc4PacketServerTransformer(); var Pair = VirtualTransportServerFactory(Context, rpst); si = Pair.Key; vts = Pair.Value; Context.SecureConnectionRequired += c => { rpst.SetSecureContext(c); NextSecureContext = c; }; vts.ServerEvent += () => ssm.NotifyWrite(new Unit()); vts.InputByteLengthReport += (CommandName, ByteLength) => Server.ServerContext.RaiseSessionLog(new SessionLogEntry { Token = Context.SessionTokenString, RemoteEndPoint = RemoteEndPoint, Time = DateTime.UtcNow, Type = "InBytes", Name = CommandName, Message = ByteLength.ToInvariantString() }); vts.OutputByteLengthReport += (CommandName, ByteLength) => Server.ServerContext.RaiseSessionLog(new SessionLogEntry { Token = Context.SessionTokenString, RemoteEndPoint = RemoteEndPoint, Time = DateTime.UtcNow, Type = "OutBytes", Name = CommandName, Message = ByteLength.ToInvariantString() }); }
internal void Redraw(LockedVariable source) { if (!mRedrawing && mFrame != null) { mRedrawing = true; UpdateUnknowns(mLock == LockedVariable.Nothing ? source : mLock); mRedrawing = false; } mProjectorPlugin.Redraw(); if (Change != null) { Change(); } }
public Projector(Frame frame, ProjectorPlugin projectorPlugin) { mProjectorPlugin = projectorPlugin; mFrame = frame; mTargetH = frame.Height; ProjectorConfig cfg = new ProjectorConfig(frame.Name); mOrientation = new Rotation(cfg.ProjectorPitch, cfg.ProjectorYaw); //Constants mThrowRatio = cfg.ThrowRatio; mUpsideDown = cfg.UpsideDown; mVOffset = cfg.VOffset; mNativeAspectRatio = cfg.NativeAspectRatio; SetAspectRatio(cfg.AspectRatio); CalculateAngles(); mLock = cfg.Lock; if (mLock == LockedVariable.Position /* || mLock == LockedVariable.Nothing*/) { mPosition = cfg.ProjectorPosition; mD = cfg.WallDistance; mFrame.Orientation.Yaw = mOrientation.Yaw; } else { mD = mLock == LockedVariable.Width ? CalculateDFromW() :CalculateDFromH(); mPosition = CalculatePositionFromH(); mOrientation.Yaw = mFrame.Orientation.Yaw; } mOldW = mFrame.Width; mOldH = mFrame.Height; mDraw = cfg.Draw; mDrawLabels = cfg.DrawLabels; mProjectorPlugin.RoomChanged += new Action(mProjectorPlugin_RoomChanged); mOrientation.Changed += new EventHandler(mOrientation_Changed); frame.Changed += new Action <Frame, EventArgs>(frame_Changed); }
public HttpSession(HttpServer Server, IPEndPoint RemoteEndPoint, Func <ISessionContext, KeyValuePair <IServerImplementation, IHttpVirtualTransportServer> > VirtualTransportServerFactory, Action <Action> QueueUserWorkItem) { this.Server = Server; this.RemoteEndPoint = RemoteEndPoint; this.LastActiveTimeValue = new LockedVariable <DateTime>(DateTime.UtcNow); ssm = new SessionStateMachine <HttpVirtualTransportServerHandleResult, Unit>(ex => false, OnCriticalError, OnShutdownRead, OnShutdownWrite, OnWrite, OnExecute, OnStartRawRead, OnExit, QueueUserWorkItem); Context = Server.ServerContext.CreateSessionContext(); Context.Quit += ssm.NotifyExit; Context.Authenticated += () => Server.NotifySessionAuthenticated(this); Context.SecureConnectionRequired += c => { throw new NotImplementedException(); }; var Pair = VirtualTransportServerFactory(Context); si = Pair.Key; vts = Pair.Value; }
private void UpdateUnknowns(LockedVariable l) { switch (l) { case LockedVariable.Width: mD = CalculateDFromW(); mFrame.Height = CalculateH(); mPosition = CalculatePositionFromH(); break; case LockedVariable.Height: mD = CalculateDFromH(); mFrame.Width = CalculateW(); mPosition = CalculatePositionFromH(); break; case LockedVariable.Position: mFrame.Width = CalculateW(); mFrame.Height = CalculateH(); mFrame.TopLeft = CalculateTopLeft(); break; } }
public SessionStateMachine(Func <Exception, Boolean> IsKnownException, Action <Exception, StackTrace> OnCriticalError, Action OnShutdownRead, Action OnShutdownWrite, Action <TWrite, Action, Action> OnWrite, Action <TRead, Action, Action> OnExecute, Action <Action <TRead[]>, Action> OnStartRawRead, Action OnExit, Action <Action> QueueUserWorkItem) { this.IsKnownException = IsKnownException; this.OnCriticalError = OnCriticalError; this.OnShutdownRead = OnShutdownRead; this.OnShutdownWrite = OnShutdownWrite; this.OnWrite = OnWrite; this.OnExecute = OnExecute; this.OnStartRawRead = OnStartRawRead; this.OnExit = OnExit; this.QueueUserWorkItem = QueueUserWorkItem; c = new LockedVariable <Context>(new Context { State = 0, IsReadEnabled = true, IsWriteEnabled = true, Reads = new Queue <TRead>(), Writes = new Queue <TWrite>(), IsInRawRead = false, IsReadShutDown = false, IsWriteShutDown = false }); }
public static void TestHttpForNumUser(String UrlPrefix, String ServiceVirtualPath, int NumUser, String Title, Action <int, int, ClientContext, IApplicationClient, Action> Test, Action <int, int, ClientContext, IApplicationClient, Action> InitializeClientContext = null, Action <ClientContext[]> FinalCheck = null) { Console.Write("{0}: ", Title); Console.Out.Flush(); var tl = new List <Task>(); var bcl = new List <Http.HttpClient>(); var ccl = new List <ClientContext>(); var vConnected = new LockedVariable <int>(0); var vCompleted = new LockedVariable <int>(0); var Check = new AutoResetEvent(false); var vError = new LockedVariable <int>(0); for (int k = 0; k < NumUser; k += 1) { var n = k; var Lockee = new Object(); var a = new JsonSerializationClientAdapter(); var ac = a.GetApplicationClient(); var vtc = new Http.JsonHttpPacketClient(a); var bc = new Http.HttpClient(UrlPrefix, ServiceVirtualPath, vtc); var cc = new ClientContext(); ac.Error += e => { var m = e.Message; Console.WriteLine(m); }; Action Completed; if (Test == TestQuit) { Completed = () => { vCompleted.Update(i => i + 1); Check.Set(); }; } else { Completed = () => { ac.Quit(new QuitRequest { }).ContinueWith(tt => { vCompleted.Update(i => i + 1); Check.Set(); }); }; } if (InitializeClientContext != null) { InitializeClientContext(NumUser, n, cc, ac, Completed); } try { ac.ServerTime(new ServerTimeRequest { }).ContinueWith(tt => { vConnected.Update(i => i + 1); Check.Set(); }); } catch (Exception ex) { Console.WriteLine(String.Format("{0}:{1}", n, ex.Message)); Completed(); } var t = new Task ( () => { try { Test(NumUser, n, cc, ac, Completed); } catch (Exception ex) { Console.WriteLine(String.Format("{0}:{1}", n, ex.Message)); Completed(); } } ); tl.Add(t); bcl.Add(bc); ccl.Add(cc); } while (vConnected.Check(i => i != NumUser)) { Check.WaitOne(); } var Time = Environment.TickCount; foreach (var t in tl) { t.Start(); } while (vCompleted.Check(i => i != NumUser)) { Check.WaitOne(); } var TimeDiff = Environment.TickCount - Time; Task.WaitAll(tl.ToArray()); foreach (var t in tl) { t.Dispose(); } foreach (var bc in bcl) { bc.Dispose(); } if (FinalCheck != null) { FinalCheck(ccl.ToArray()); } var NumError = vError.Check(v => v); if (NumError > 0) { Console.WriteLine("{0} Errors", NumError); } Console.WriteLine("{0} Users, {1} ms", NumUser, TimeDiff); }
public static void TestUdpForNumUser(IPEndPoint RemoteEndPoint, SerializationProtocolType ProtocolType, int NumUser, String Title, Action <int, int, ClientContext, IApplicationClient, Action> Test, Action <int, int, ClientContext, IApplicationClient, Action> InitializeClientContext = null, Action <ClientContext[]> FinalCheck = null) { Console.Write("{0}: ", Title); Console.Out.Flush(); var tl = new List <Task>(); var bcl = new List <UdpClient>(); var ccl = new List <ClientContext>(); var tmrl = new List <Timer>(); var vConnected = new LockedVariable <int>(0); var vCompleted = new LockedVariable <int>(0); var Check = new AutoResetEvent(false); var bAbondon = new LockedVariable <Boolean>(false); var vError = new LockedVariable <int>(0); for (int k = 0; k < NumUser; k += 1) { var n = k; var Lockee = new Object(); IApplicationClient ac; IStreamedVirtualTransportClient vtc; if (ProtocolType == SerializationProtocolType.Binary) { var a = new BinarySerializationClientAdapter(); ac = a.GetApplicationClient(); vtc = new BinaryCountPacketClient(a); } else if (ProtocolType == SerializationProtocolType.Json) { var a = new JsonSerializationClientAdapter(); ac = a.GetApplicationClient(); vtc = new JsonLinePacketClient(a); } else { throw new InvalidOperationException(); } var bc = new UdpClient(RemoteEndPoint, vtc, QueueUserWorkItem); var cc = new ClientContext(); var bCompleted = new LockedVariable <Boolean>(false); Action Completed; Action FaultedCompleted; if (Test == TestQuit) { Completed = () => { bCompleted.Update(b => true); vCompleted.Update(i => i + 1); Check.Set(); }; FaultedCompleted = Completed; } else { Completed = () => { ac.Quit(new QuitRequest { }).ContinueWith(tt => { bCompleted.Update(b => true); vCompleted.Update(i => i + 1); Check.Set(); }); }; FaultedCompleted = () => { bCompleted.Update(b => true); vCompleted.Update(i => i + 1); Check.Set(); }; } ac.Error += e => { var m = e.Message; Console.WriteLine(m); }; if (InitializeClientContext != null) { InitializeClientContext(NumUser, n, cc, ac, Completed); } bc.Connect(); Action <Exception> UnknownFaulted = ex => { int OldValue = 0; vError.Update(v => { OldValue = v; return(v + 1); }); if (OldValue <= 10) { Console.WriteLine(String.Format("{0}:{1}", n, ex.Message)); } FaultedCompleted(); }; bc.ReceiveAsync ( a => { a(); }, UnknownFaulted ); ac.ServerTime(new ServerTimeRequest { }).ContinueWith(tt => { vConnected.Update(i => i + 1); Check.Set(); }); var t = new Task ( () => { Test(NumUser, n, cc, ac, Completed); } ); var tmr = new Timer ( o => { if (!bAbondon.Check(b => b)) { return; } if (bCompleted.Check(b => b)) { return; } int OldValue = 0; vError.Update(v => { OldValue = v; return(v + 1); }); if (OldValue <= 10) { Console.WriteLine(String.Format("{0}:{1}", n, "Timedout")); } FaultedCompleted(); }, null, 10000, 10000 ); tl.Add(t); bcl.Add(bc); ccl.Add(cc); tmrl.Add(tmr); } while (vConnected.Check(i => i != NumUser)) { Check.WaitOne(); } var Time = Environment.TickCount; foreach (var t in tl) { t.Start(); } while (vCompleted.Check(i => i != NumUser)) { if (!Check.WaitOne(10000)) { if (vCompleted.Check(i => i > 0)) { bAbondon.Update(b => true); break; } } } var NumMutualWaiting = NumUser - vCompleted.Check(i => i); while (vCompleted.Check(i => i != NumUser)) { Check.WaitOne(); } foreach (var tmr in tmrl) { tmr.Dispose(); } var TimeDiff = Environment.TickCount - Time; Task.WaitAll(tl.ToArray()); foreach (var t in tl) { t.Dispose(); } foreach (var bc in bcl) { bc.Dispose(); } if (FinalCheck != null) { FinalCheck(ccl.ToArray()); } var NumError = vError.Check(v => v); if (NumError > 0) { Console.WriteLine("{0} Errors", NumError); } if (NumMutualWaiting > 0) { Console.WriteLine("{0} Users, {1} ms, {2} MutualWaiting", NumUser, TimeDiff, NumMutualWaiting); } else { Console.WriteLine("{0} Users, {1} ms", NumUser, TimeDiff); } }
public static void TestTcpForNumUser(IPEndPoint RemoteEndPoint, SerializationProtocolType ProtocolType, int NumRequestPerUser, int NumUser, String Title, Action <int, int, ClientContext, IApplicationClient, Action> Test) { Console.Write("{0}: ", Title); Console.Out.Flush(); var tll = new Object(); var tl = new List <Task>(); var bcl = new List <TcpClient>(); var ccl = new List <ClientContext>(); var vConnected = new LockedVariable <int>(0); var vCompleted = new LockedVariable <int>(0); var Check = new AutoResetEvent(false); var vError = new LockedVariable <int>(0); for (int k = 0; k < NumUser; k += 1) { Action Completed = null; var n = k; var Lockee = new Object(); IApplicationClient ac; IStreamedVirtualTransportClient vtc; if (ProtocolType == SerializationProtocolType.Binary) { var a = new BinarySerializationClientAdapter(); ac = a.GetApplicationClient(); vtc = new BinaryCountPacketClient(a); } else if (ProtocolType == SerializationProtocolType.Json) { var a = new JsonSerializationClientAdapter(); ac = a.GetApplicationClient(); vtc = new JsonLinePacketClient(a); } else { throw new InvalidOperationException(); } var bc = new TcpClient(RemoteEndPoint, vtc, QueueUserWorkItem); var cc = new ClientContext(); ac.Error += e => { var m = e.Message; Console.WriteLine(m); }; bc.Connect(); Action <Exception> UnknownFaulted = ex => { int OldValue = 0; vError.Update(v => { OldValue = v; return(v + 1); }); if (OldValue <= 10) { Console.WriteLine(String.Format("{0}:{1}", n, ex.Message)); } vCompleted.Update(i => i + 1); Check.Set(); }; bc.ReceiveAsync ( a => { a(); }, UnknownFaulted ); ac.ServerTime(new ServerTimeRequest { }).ContinueWith(tt => { vConnected.Update(i => i + 1); Check.Set(); }); Action f = () => { Test(NumUser, n, cc, ac, Completed); }; var t = new Task(f); lock (tll) { tl.Add(t); } bcl.Add(bc); ccl.Add(cc); int RequestCount = NumRequestPerUser; Completed = () => { if (RequestCount > 0) { RequestCount -= 1; var tt = new Task(f); lock (tll) { tl.Add(t); } tt.Start(); return; } vCompleted.Update(i => i + 1); Check.Set(); }; } while (vConnected.Check(i => i != NumUser)) { Check.WaitOne(); } var Time = Environment.TickCount; lock (tll) { foreach (var t in tl) { t.Start(); } } while (vCompleted.Check(i => i != NumUser)) { Check.WaitOne(); } var TimeDiff = Environment.TickCount - Time; Task.WaitAll(tl.ToArray()); foreach (var t in tl) { t.Dispose(); } foreach (var bc in bcl) { bc.Dispose(); } var NumError = vError.Check(v => v); if (NumError > 0) { Console.WriteLine("{0} Errors", NumError); } Console.WriteLine("{0} Users, {1} Request/User, {2} ms", NumUser, NumRequestPerUser, TimeDiff); }
public static void TestHttpForNumUser(String UrlPrefix, String ServiceVirtualPath, int NumRequestPerUser, int NumUser, String Title, Action <int, int, ClientContext, IApplicationClient, Action> Test) { Console.Write("{0}: ", Title); Console.Out.Flush(); var tll = new Object(); var tl = new List <Task>(); var bcl = new List <Http.HttpClient>(); var ccl = new List <ClientContext>(); var vConnected = new LockedVariable <int>(0); var vCompleted = new LockedVariable <int>(0); var Check = new AutoResetEvent(false); var vError = new LockedVariable <int>(0); for (int k = 0; k < NumUser; k += 1) { Action Completed = null; var n = k; var Lockee = new Object(); var a = new JsonSerializationClientAdapter(); var ac = a.GetApplicationClient(); var vtc = new Http.JsonHttpPacketClient(a); var bc = new Http.HttpClient(UrlPrefix, ServiceVirtualPath, vtc); var cc = new ClientContext(); ac.Error += e => { var m = e.Message; Console.WriteLine(m); }; Action <Exception> HandleError = ex => { int OldValue = 0; vError.Update(v => { OldValue = v; return(v + 1); }); if (OldValue <= 10) { Console.WriteLine(String.Format("{0}:{1}", n, ex.Message)); } vCompleted.Update(i => i + 1); Check.Set(); }; try { ac.ServerTime(new ServerTimeRequest { }).ContinueWith(tt => { vConnected.Update(i => i + 1); Check.Set(); }); } catch (Exception ex) { HandleError(ex); } Action f = () => { try { Test(NumUser, n, cc, ac, Completed); } catch (Exception ex) { HandleError(ex); } }; var t = new Task(f); lock (tll) { tl.Add(t); } bcl.Add(bc); ccl.Add(cc); int RequestCount = NumRequestPerUser; Completed = () => { if (RequestCount > 0) { RequestCount -= 1; var tt = new Task(f); lock (tll) { tl.Add(t); } tt.Start(); return; } ac.Quit(new QuitRequest { }).ContinueWith(tt => { vCompleted.Update(i => i + 1); Check.Set(); }); }; } while (vConnected.Check(i => i != NumUser)) { Check.WaitOne(); } var Time = Environment.TickCount; lock (tll) { foreach (var t in tl) { t.Start(); } } while (vCompleted.Check(i => i != NumUser)) { Check.WaitOne(); } var TimeDiff = Environment.TickCount - Time; Task.WaitAll(tl.ToArray()); foreach (var t in tl) { t.Dispose(); } foreach (var bc in bcl) { bc.Dispose(); } var NumError = vError.Check(v => v); if (NumError > 0) { Console.WriteLine("{0} Errors", NumError); } Console.WriteLine("{0} Users, {1} Request/User, {2} ms", NumUser, NumRequestPerUser, TimeDiff); }
private void DoAsync(SocketAsyncOperation OperationIdentifier, Func <SocketAsyncEventArgs, Boolean> Operation, Func <SocketAsyncEventArgs, Action> ResultToCompleted, Action <Exception> Faulted) { var Context = new AsyncOperationContext(); if (!TryLockAsyncOperation(OperationIdentifier, Context)) { Context.Dispose(); Faulted(new SocketException((int)(SocketError.Shutdown))); return; } var Success = false; try { Context.ResultToCompleted = ResultToCompleted; Context.Faulted = Faulted; var TimeoutSeconds = this.TimeoutSeconds; if (TimeoutSeconds.HasValue) { var IsCompleted = new LockedVariable <Boolean>(false); var Timer = new Timer(o => { if (!IsCompleted.Check(b => b)) { if (TimedOut != null) { TimedOut(); } } }, null, TimeoutSeconds.Value * 1000, Timeout.Infinite); Context.ReleaseAsyncOperation = () => { IsCompleted.Update(b => true); if (Timer != null) { Timer.Dispose(); Timer = null; } ReleaseAsyncOperation(OperationIdentifier); }; } else { Context.ReleaseAsyncOperation = () => ReleaseAsyncOperation(OperationIdentifier); } Success = true; } finally { if (!Success) { ReleaseAsyncOperation(OperationIdentifier); } } Success = false; Exception Exception = null; try { bool willRaiseEvent = Operation(Context.EventArgs); if (!willRaiseEvent) { QueueUserWorkItem(Context.DoOnCompletion); } Success = true; } catch (ObjectDisposedException) { Exception = new SocketException((int)(SocketError.OperationAborted)); } finally { if (!Success) { Context.ReleaseAsyncOperation(); } } if (Exception != null) { Faulted(Exception); } }
public static void Run(Configuration c) { Console.WriteLine(Times.DateTimeUtcWithMillisecondsToString(DateTime.UtcNow) + @" 服务器进程启动。"); var ProcessorCount = Environment.ProcessorCount; var WorkThreadCount = c.NumThread.OnSome ? Math.Max(1, c.NumThread.Value) : ProcessorCount; Console.WriteLine(@"逻辑处理器数量: " + ProcessorCount.ToString()); Console.WriteLine(@"工作线程数量: {0}".Formats(WorkThreadCount)); using (var tp = new CountedThreadPool("Worker", WorkThreadCount)) using (var tpPurifier = new CountedThreadPool("Purifier", 2)) using (var tpLog = new CountedThreadPool("Log", 1)) using (var ExitEvent = new AutoResetEvent(false)) using (var Logger = new ConsoleLogger(tpLog.QueueUserWorkItem)) { Logger.Start(); LockedVariable <ConsoleCancelEventHandler> CancelKeyPressInner = null; CancelKeyPressInner = new LockedVariable <ConsoleCancelEventHandler>((sender, e) => { CancelKeyPressInner.Update(v => { return(null); }); e.Cancel = true; Console.WriteLine(Times.DateTimeUtcWithMillisecondsToString(DateTime.UtcNow) + @" 命令行中断退出。"); ExitEvent.Set(); }); ConsoleCancelEventHandler CancelKeyPress = (sender, e) => { var f = CancelKeyPressInner.Check(v => v); if (f == null) { return; } f(sender, e); }; Console.CancelKeyPress += CancelKeyPress; var ChatContexts = new List <ServerContext>(); var ServerCloses = new List <Action>(); try { foreach (var s in c.Servers) { if (s.OnChat) { var ss = s.Chat; var ServerContext = new ServerContext(); ChatContexts.Add(ServerContext); ServerContext.EnableLogNormalIn = c.EnableLogNormalIn; ServerContext.EnableLogNormalOut = c.EnableLogNormalOut; ServerContext.EnableLogUnknownError = c.EnableLogUnknownError; ServerContext.EnableLogCriticalError = c.EnableLogCriticalError; ServerContext.EnableLogPerformance = c.EnableLogPerformance; ServerContext.EnableLogSystem = c.EnableLogSystem; ServerContext.EnableLogTransport = c.EnableLogTransport; ServerContext.ServerDebug = c.ServerDebug; ServerContext.ClientDebug = c.ClientDebug; ServerContext.Shutdown += () => { Console.WriteLine(Times.DateTimeUtcWithMillisecondsToString(DateTime.UtcNow) + @" 远程命令退出。"); ExitEvent.Set(); }; if (c.EnableLogConsole) { ServerContext.SessionLog += Logger.Push; } var Protocols = new List <IServer>(); var Factory = new TaskFactory(tp); var PurifierFactory = new TaskFactory(tp); foreach (var p in ss.Protocols) { if (System.Diagnostics.Debugger.IsAttached) { Protocols.Add(StartProtocol(c, p, ServerContext, Factory, PurifierFactory)); } else { try { Protocols.Add(StartProtocol(c, p, ServerContext, Factory, PurifierFactory)); } catch (Exception ex) { var Message = Times.DateTimeUtcWithMillisecondsToString(DateTime.UtcNow) + "\r\n" + ExceptionInfo.GetExceptionInfo(ex); Console.WriteLine(Message); FileLoggerSync.WriteLog("Error.log", Message); } } } ServerCloses.Add(() => { foreach (var Session in ServerContext.Sessions.AsParallel()) { Session.SessionLock.EnterReadLock();; try { if (Session.EventPump != null) { Session.EventPump.ServerShutdown(new Communication.ServerShutdownEvent { }); } } finally { Session.SessionLock.ExitReadLock(); } } foreach (var p in Protocols) { if (System.Diagnostics.Debugger.IsAttached) { StopProtocol(p); } else { try { StopProtocol(p); } catch (Exception ex) { var Message = Times.DateTimeUtcWithMillisecondsToString(DateTime.UtcNow) + "\r\n" + ExceptionInfo.GetExceptionInfo(ex); Console.WriteLine(Message); FileLoggerSync.WriteLog("Error.log", Message); } } } if (c.EnableLogConsole) { ServerContext.SessionLog -= Logger.Push; } Console.WriteLine(@"ChatServerContext.RequestCount = {0}".Formats(ServerContext.RequestCount)); Console.WriteLine(@"ChatServerContext.ReplyCount = {0}".Formats(ServerContext.ReplyCount)); Console.WriteLine(@"ChatServerContext.EventCount = {0}".Formats(ServerContext.EventCount)); }); } else { throw new InvalidOperationException("未知服务器类型: " + s._Tag.ToString()); } } ExitEvent.WaitOne(); Console.CancelKeyPress -= CancelKeyPress; } finally { foreach (var a in ServerCloses) { a(); } } } Console.WriteLine(Times.DateTimeUtcWithMillisecondsToString(DateTime.UtcNow) + @" 服务器进程退出完成。"); }
public Projector(Frame frame, ProjectorPlugin projectorPlugin) { mProjectorPlugin = projectorPlugin; mFrame = frame; mTargetH = frame.Height; ProjectorConfig cfg = new ProjectorConfig(frame.Name); mOrientation = new Rotation(cfg.ProjectorPitch, cfg.ProjectorYaw); //Constants mThrowRatio = cfg.ThrowRatio; mUpsideDown = cfg.UpsideDown; mVOffset = cfg.VOffset; mNativeAspectRatio = cfg.NativeAspectRatio; SetAspectRatio(cfg.AspectRatio); CalculateAngles(); mLock = cfg.Lock; if (mLock == LockedVariable.Position/* || mLock == LockedVariable.Nothing*/) { mPosition = cfg.ProjectorPosition; mD = cfg.WallDistance; mFrame.Orientation.Yaw = mOrientation.Yaw; } else { mD = mLock == LockedVariable.Width ? CalculateDFromW() :CalculateDFromH(); mPosition = CalculatePositionFromH(); mOrientation.Yaw = mFrame.Orientation.Yaw; } mOldW = mFrame.Width; mOldH = mFrame.Height; mDraw = cfg.Draw; mDrawLabels = cfg.DrawLabels; mProjectorPlugin.RoomChanged += new Action(mProjectorPlugin_RoomChanged); mOrientation.Changed += new EventHandler(mOrientation_Changed); frame.Changed += new Action<Frame,EventArgs>(frame_Changed); }
private void UpdateUnknowns(LockedVariable l) { switch (l) { case LockedVariable.Width: mD = CalculateDFromW(); mFrame.Height = CalculateH(); mPosition = CalculatePositionFromH(); break; case LockedVariable.Height: mD = CalculateDFromH(); mFrame.Width = CalculateW(); mPosition = CalculatePositionFromH(); break; case LockedVariable.Position: mFrame.Width = CalculateW(); mFrame.Height = CalculateH(); mFrame.TopLeft = CalculateTopLeft(); break; } }
internal void Redraw(LockedVariable source) { if (!mRedrawing && mFrame != null) { mRedrawing = true; UpdateUnknowns(mLock == LockedVariable.Nothing ? source : mLock); mRedrawing = false; } mProjectorPlugin.Redraw(); if (Change != null) Change(); }