public static bool RemoveControl(ControlHandler handlerToRemove) { if (controls.ContainsKey(handlerToRemove.controlName)) { controls.Remove(handlerToRemove.controlName); return true; } else { return false; } }
public static bool AddControl(ControlHandler handlerToAdd) { if(controls == null) { controls = new Dictionary<string, ControlHandler>(); } if(controls.ContainsKey(handlerToAdd.controlName)) { Debug.LogWarning("Cannot add controls of the same name"); return false; } else { controls.Add(handlerToAdd.controlName, handlerToAdd); return true; } }
/// <summary> /// 确定行号 /// </summary> private void gridViewPrReqHead_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e) { ControlHandler.GridView_CustomDrawRowIndicator(e); }
public void SetButtonCancelButtonEnabled(bool isEnabled) { ControlHandler.SetButtonEnabled(btnCancel, isEnabled); }
public void SetButtonExecuteButtonEnabled(bool isEnabled) { ControlHandler.SetButtonEnabled(btnExecute, isEnabled); }
/// <summary> /// 确定行号 /// </summary> private void searchLookUpBussinessBaseNoView_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e) { ControlHandler.GridView_CustomDrawRowIndicator(e); }
public override QSResult Execute(ref QSData data) { int counter = 0; IList <QuadraticPair> smoothpair = data.BSmooth; long productA = 1; long productB = 1; String msg; foreach (QuadraticPair pair in smoothpair) { if (pair.QuadraticStatus == QuadraticStatus.Quadratic) { productA = pair.A; productB = pair.B; break; } } if (productA == 1 && productB == 1) { foreach (QuadraticPair pair in smoothpair) { if (pair.QuadraticStatus == QuadraticStatus.Part) { productA = (productA * pair.A) % data.N; productB *= pair.B; pair.QuadraticStatus = QuadraticStatus.Nope; } } } if (productA == 1 || productB == 1) { ControlHandler.AddRowDefintion(Grid, 1, GridUnitType.Auto); ControlHandler.ExecuteMethod(this, "AddToGrid", new object[] { Grid, String.Format(Primes.Resources.lang.WpfControls.Factorization.Factorization.qs_step4_end, data.N), counter++, 0, 0, 0 }); return(QSResult.Ok); } long sqb = (long)Math.Sqrt(productB); StringBuilder sbInfo = new StringBuilder(); sbInfo.Append(string.Format(Primes.Resources.lang.WpfControls.Factorization.Factorization.qs_step4_abcalculated, productA, sqb)); sbInfo.Append("\n"); sbInfo.Append(Primes.Resources.lang.WpfControls.Factorization.Factorization.qs_step4_checkcong); ControlHandler.SetPropertyValue(m_lblInfo, "Text", sbInfo.ToString()); ControlHandler.AddRowDefintion(Grid, 1, GridUnitType.Auto); ControlHandler.ExecuteMethod(this, "AddToGrid", new object[] { Grid, BuildQuadMod(productA, sqb, data.N), counter++, 0, 0, 0 }); ControlHandler.AddRowDefintion(Grid, 1, GridUnitType.Auto); ControlHandler.ExecuteMethod(this, "AddToGrid", new object[] { Grid, BuildMod(productA, sqb, data.N), counter++, 0, 0, 0 }); if (!ModuloTest(productA, sqb, data.N)) // Modulotest nicht bestanden { data.AddIgnoreQuadrat(PrimesBigInteger.ValueOf(productB)); msg = Primes.Resources.lang.WpfControls.Factorization.Factorization.qs_step4_notproofed; ControlHandler.AddRowDefintion(Grid, 1, GridUnitType.Auto); ControlHandler.ExecuteMethod(this, "AddToGrid", new object[] { Grid, msg, counter++, 0, 0, 0 }); return(QSResult.Failed); } msg = String.Format(Primes.Resources.lang.WpfControls.Factorization.Factorization.qs_step4_proofed, data.N); ControlHandler.AddRowDefintion(Grid, 1, GridUnitType.Auto); ControlHandler.ExecuteMethod(this, "AddToGrid", new object[] { Grid, msg, counter++, 0, 0, 0 }); long factor1 = (long)BigInteger.GreatestCommonDivisor(productA + sqb, data.N); long factor2 = (long)BigInteger.GreatestCommonDivisor(productA - sqb, data.N); bool trivialfactor1 = (factor1 == 1 || factor1 == data.N); bool trivialfactor2 = (factor2 == 1 || factor2 == data.N); String sbfactor1 = string.Format(Primes.Resources.lang.WpfControls.Factorization.Factorization.qs_step4_factor1, productA, sqb, data.N, factor1); ControlHandler.AddRowDefintion(Grid, 1, GridUnitType.Auto); ControlHandler.ExecuteMethod(this, "AddToGrid", new object[] { Grid, sbfactor1, counter++, 0, 0, 0 }); String sbfactor2 = string.Format(Primes.Resources.lang.WpfControls.Factorization.Factorization.qs_step4_factor2, productA, sqb, data.N, factor2); ControlHandler.AddRowDefintion(Grid, 1, GridUnitType.Auto); ControlHandler.ExecuteMethod(this, "AddToGrid", new object[] { Grid, sbfactor2, counter++, 0, 0, 0 }); if (trivialfactor1 && trivialfactor2) { data.AddIgnoreQuadrat(PrimesBigInteger.ValueOf(productB)); msg = string.Format(Primes.Resources.lang.WpfControls.Factorization.Factorization.qs_step4_reset, productA, sqb); ControlHandler.AddRowDefintion(Grid, 1, GridUnitType.Auto); ControlHandler.ExecuteMethod(this, "AddToGrid", new object[] { Grid, msg, counter++, 0, 0, 0 }); return(QSResult.Failed); } long nontrivialfactor = trivialfactor1 ? factor2 : factor1; FireFoundFactorEvent(PrimesBigInteger.ValueOf(nontrivialfactor)); FireFoundFactorEvent(PrimesBigInteger.ValueOf(data.N / nontrivialfactor)); //Boolean p1 = BigIntegerHelper.IsProbablePrime(factor1); //Boolean p2 = BigIntegerHelper.IsProbablePrime(factor2); //if (p1) FireFoundFactorEvent(PrimesBigInteger.ValueOf(factor1)); //if (p2) FireFoundFactorEvent(PrimesBigInteger.ValueOf(factor2)); //if( !(p1 && p2) ) // falls ein Faktor nicht prim ist //{ // long notPrime = p1 ? factor2 : factor1; // msg = string.Format(Primes.Resources.lang.WpfControls.Factorization.Factorization.qs_step4_refactorize, notPrime, notPrime); // ControlHandler.AddRowDefintion(Grid, 1, GridUnitType.Auto); // ControlHandler.ExecuteMethod( this, "AddToGrid", new object[] { Grid, msg, counter++, 0, 0, 0 }); // data.N = notPrime; // return QSResult.Restart; //} return(QSResult.Ok); }
void m_FactorTree_OnActualDivisorChanged(PrimesBigInteger value) { ControlHandler.SetPropertyValue(lblActualDivisor, "Text", Primes.Resources.lang.WpfControls.Factorization.Factorization.bf_actualdiv + value.ToString("D")); }
public BaseCamera(GraphicsDevice graphicsDevice, ControlHandler lookController, ControlHandler movementController) { this.graphicsDevice = graphicsDevice; this.lookController = lookController; this.movementController = movementController; BindControls(); center = new Point(graphicsDevice.Viewport.Width / 2, graphicsDevice.Viewport.Height / 2); }
public AbsoluteCamera(GraphicsDevice graphicsDevice, ControlHandler lookController, ControlHandler movementController) : base(graphicsDevice, lookController, movementController) { }
/// <summary> /// 确定行号 /// </summary> private void treeListBom_CustomDrawNodeIndicator(object sender, DevExpress.XtraTreeList.CustomDrawNodeIndicatorEventArgs e) { ControlHandler.TreeList_CustomDrawNodeIndicator_RootNode(sender, e); }
private void DoExecuteGraphic(PrimesBigInteger a) { lock (m_RunningLockObject) { m_Running = true; } Point lastPoint = new Point(-1, -1); PrimesBigInteger factor = null; ControlHandler.SetPropertyValue(lblA, "Content", a.ToString()); ControlHandler.SetPropertyValue(lblExp, "Text", m_Value.ToString() + "-1"); ControlHandler.SetPropertyValue(lblP, "Content", m_Value.ToString()); ControlHandler.SetPropertyValue(lblCalc, "Text", string.Empty); ControlHandler.SetPropertyValue(lblCalc, "Text", a.ModPow(m_Value.Subtract(PrimesBigInteger.One), m_Value).ToString()); PrimesBigInteger i = PrimesBigInteger.Two; PrimesBigInteger result = null; PrimesBigInteger counter = PrimesBigInteger.Zero; while (i.CompareTo(m_Value.Subtract(PrimesBigInteger.One)) <= 0) { Thread.Sleep(100); result = a.ModPow(i, m_Value); log.Info( string.Format( "Berechne {0}^{1} mod {2} = {3}", new object[] { a.ToString(), i.ToString(), m_Value.ToString(), result.ToString() })); if (factor == null) { factor = result; } else { factor = factor.Multiply(result); } //StringBuilder sbText = new StringBuilder();// new StringBuilder(ControlHandler.GetPropertyValue(lblCalc, "Text") as string); //sbText.Append(result.ToString()); //if (i.CompareTo(m_Value.Subtract(PrimesBigInteger.One)) < 0) // sbText.Append(" * "); //ControlHandler.SetPropertyValue(lblCalc, "Text", sbText.ToString()); if (lastPoint.X == -1 && lastPoint.Y == -1) { lastPoint = m_Points[result.IntValue]; } else { Point newPoint = m_Points[result.IntValue]; CreateArrow(counter, lastPoint, newPoint); lastPoint = newPoint; } i = i.Add(PrimesBigInteger.One); counter = counter.Add(PrimesBigInteger.One); } if (result != null) { if (result.Equals(PrimesBigInteger.One)) { log.Info( string.Format( "Berechne {0}^{1} mod {2} = 1. {3} könnte eine Primzahl sein.", new object[] { a.ToString(), m_Value.Subtract(PrimesBigInteger.One).ToString(), m_Value.ToString(), m_Value.ToString() })); } else { log.Info( string.Format( "Berechne {0}^{1} mod {2} = {3}. {4} ist damit definitiv keine Primzahl.", new object[] { a.ToString(), m_Value.Subtract(PrimesBigInteger.One).ToString(), m_Value.ToString(), result.ToString(), m_Value.ToString() })); } } if (CancelTest != null) { CancelTest(); } lock (m_RunningLockObject) { m_Running = false; } }
/// <summary> /// 确定行号 /// </summary> private void repSearchCodeFileNameView_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e) { ControlHandler.GridView_CustomDrawRowIndicator(e); }
/// <summary> /// 确定行号 /// </summary> private void gridViewOrderList_CustomDrawRowIndicator(object sender, RowIndicatorCustomDrawEventArgs e) { ControlHandler.GridView_CustomDrawRowIndicator(e); }
/// <summary> /// Main thread to host the server process. /// </summary> /// <param name="threadContext">A ZMQ.Context instance.</param> public void Run(object threadContext) { try { Context ctx = (Context)threadContext; using (Socket data = ctx.Socket(SocketType.PUB)) { data.SNDHWM = hwm; // Bind the data publisher socket: if (tsp == Transport.EPGM || tsp == Transport.PGM) { data.Rate = pgmRate; } //data.SndBuf = chunkSize * hwm * 4; // NOTE: work-around for MS bug in WinXP's networking stack. See http://support.microsoft.com/kb/201213 for details. data.SndBuf = 0; data.StringToIdentity(subscription, Encoding.Unicode); string address = tsp.ToString().ToLower() + "://" + device + ":" + port; Console.WriteLine("Bind(\"{0}\")", address); data.Bind(address); isRunning = true; var controlHandler = new ControlHandler(this); var controlHandlerThread = new Thread(new ParameterizedThreadStart(controlHandler.Run)); controlHandlerThread.Start(new object[] { ctx, this }); // Wait for the sockets to bind: Thread.Sleep(500); //PollItem[] pollItems = new PollItem[1]; //pollItems[0] = data.CreatePollItem(IOMultiPlex.POLLOUT); byte[] buf = new byte[chunkSize]; DateTimeOffset lastPing = DateTimeOffset.UtcNow; Stopwatch sendTimer = Stopwatch.StartNew(); long lastElapsedMilliseconds = sendTimer.ElapsedMilliseconds; int msgsSent = 0; int msgsPerMinute = 0; //HashSet<int> chunksSent = new HashSet<int>(); //Queue<int> deliveryOrder = new Queue<int>(hwm); int chunkWindowStart = 0; // Begin the data delivery loop: while (true) { // PING everyone: if (DateTimeOffset.UtcNow.Subtract(lastPing).TotalMilliseconds >= 500d) { lastPing = DateTimeOffset.UtcNow; // Send a PING to all subscribers: trace("PING"); data.SendMore(this.subscription, Encoding.Unicode); data.Send("PING", Encoding.Unicode); } lock (clientLock) { // Anyone fully timed out yet? DateTimeOffset rightMeow = DateTimeOffset.UtcNow; foreach (KeyValuePair<Guid, ClientState> timedOutClient in clients.Where(cli => cli.Value.IsRemovable).ToList()) { // Yes, remove that client: clients.Remove(timedOutClient.Key); if (ClientLeft != null) ClientLeft(this, timedOutClient.Key, ClientLeaveReason.TimedOut); } } // Measure our message send rate per minute: long elapsed = sendTimer.ElapsedMilliseconds - lastElapsedMilliseconds; if (elapsed >= 500L) { msgsPerMinute = (int)((msgsSent * 60000L) / elapsed); lastElapsedMilliseconds = sendTimer.ElapsedMilliseconds; //for (int i = 0; (i < Math.Max(1, hwm * 3 / 4)) && (chunksSent.Count > 0); ++i) // chunksSent.Remove(chunksSent.First()); msgsSent = 0; } if (!sendTimer.IsRunning) { sendTimer.Reset(); sendTimer.Start(); lastElapsedMilliseconds = 0L; } // Find the ACKs/min rates per client: int maxClientACKperMinutes; lock (clientLock) { maxClientACKperMinutes = 0; foreach (var cli in clients.Values) { if (cli.IsTimedOut) { cli.ACKsPerMinute = 0; cli.RunningACKCount = 0; cli.LastElapsedMilliseconds = sendTimer.ElapsedMilliseconds; continue; } if (!cli.HasNAKs) { continue; } // Measure the ACK rate in ACKs per minute: elapsed = sendTimer.ElapsedMilliseconds - cli.LastElapsedMilliseconds; //Console.WriteLine("{0}: {1}", cli.Identity.ToString(), elapsed); if (elapsed >= 100L) { cli.ACKsPerMinute = (int)((cli.RunningACKCount * 60000L) / elapsed); cli.LastElapsedMilliseconds = sendTimer.ElapsedMilliseconds; cli.RunningACKCount = 0; } if (cli.ACKsPerMinute > maxClientACKperMinutes) maxClientACKperMinutes = cli.ACKsPerMinute; } if (clients.Count == 0) { Thread.Sleep(10); continue; } } if (!haveNewNAKs) { Thread.Sleep(1); continue; } //if ((maxClientACKperMinutes > 0) && (msgsPerMinute > 0) && (msgsPerMinute >= maxClientACKperMinutes)) //{ // Thread.Sleep(((msgsPerMinute - maxClientACKperMinutes) / 60) * 4); //} haveNewNAKs = false; List<int> chunkIdxs; lock (clientLock) { long elapsedMsec = sendTimer.ElapsedMilliseconds; chunkIdxs = ( from z in Enumerable.Range(0, numChunks) let i = (chunkWindowStart + z) % numChunks let countNAKdClients = clients.Values.Count(cli => !cli.IsTimedOut && cli.HasNAKs && cli.NAK[i]) where countNAKdClients > 0 orderby countNAKdClients descending select i ).Take(hwm / 2).ToList(); chunkWindowStart = chunkIdxs.LastOrDefault(); } foreach (int idx in chunkIdxs) { int? chunkIdx = idx; // Chunk index first: trace("SEND chunk: {0}", chunkIdx.Value); data.SendMore(this.subscription, Encoding.Unicode); data.SendMore("DATA", Encoding.Unicode); data.SendMore(BitConverter.GetBytes(chunkIdx.Value)); // Chunk size: int currChunkSize; if (!testMode) { tarball.Seek((long)chunkIdx.Value * chunkSize, SeekOrigin.Begin); currChunkSize = tarball.Read(buf, 0, chunkSize); } else { if (lastChunkSize > 0) currChunkSize = (chunkIdx.Value < (numChunks - 1)) ? chunkSize : lastChunkSize; else currChunkSize = chunkSize; } if (currChunkSize < chunkSize) { // Copy to an exact-sized temporary buffer for the last uneven sized chunk: byte[] tmpBuf = new byte[currChunkSize]; Array.Copy(buf, tmpBuf, currChunkSize); data.Send(tmpBuf); tmpBuf = null; } else { // Send the exact-sized chunk: data.Send(buf); } #if false if (deliveryOrder.Count == hwm) { int firstChunk = deliveryOrder.Dequeue(); chunksSent.Remove(firstChunk); } deliveryOrder.Enqueue(chunkIdx.Value); chunksSent.Add(chunkIdx.Value); #endif //chunkSentLastElapsedMilliseconds[chunkIdx.Value] = sendTimer.ElapsedMilliseconds; if (ChunkSent != null) ChunkSent(this, chunkIdx.Value); trace("COMPLETE chunk: {0}", chunkIdx.Value); //Thread.Sleep(1); ++msgsSent; } } // TODO: break out of the while loop somehow //isRunning = false; //controlHandlerThread.Join(); } } catch (System.Exception ex) { Console.Error.WriteLine(ex.ToString()); } }
private int DrawDefaultControlControls(ControlHandler controlTarget) { //Title bar here int selection = 0; if (GUILayout.Button("X", "WinBtnCloseWin", GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(false))) { selection = 1; return selection; } controlTarget.isVisible = EditorGUILayout.Toggle(controlTarget.isVisible, controlTarget.isVisible ? "WinBtnMinWin" : "WinBtnMaxWin", GUILayout.MaxWidth(15), GUILayout.MaxHeight(15)); return selection; }
public ClientConnection(EndPoint connectEndPoint, ControlHandler onOpen = null) : this(new Connection()) => Base.Connect(connectEndPoint);
public override void PreStep() { ControlHandler.ExecuteMethod(this, "_PreStep"); }
public void OnFactorizationCancel() { m_Running = false; m_Needs = DateTime.Now - m_Start; ControlHandler.SetCursor(this, Cursors.Arrow); }