public void ProcessGardens(DisplayDelegate displayData) { for (int i = 0; i < gardens.Count; i++) { displayBox.Items.Add(displayData(gardens[i])); } }
public void AddStructureBySaveData(SavableComponent saveData) { GameObject structureGameObject = null; for (int i = 0; i < Structures.Length; i++) { if (Structures[i].name == saveData.name) { structureGameObject = ObjectPoolManager.Instantiate(Structures[i]); } } DisplayDelegate displayEventComponent = structureGameObject.GetComponent <DisplayDelegate>(); displayEventComponent.OnDisableEvent += OnDestroyStructure; GridNode node = grid.GetNodeByIndex(saveData.gridIndeX, saveData.gridIndeY); Structure structureComponent = structureGameObject.GetComponent <Structure>(); structureComponent.SetMainGridNode(node); List <GridNode> nodes = grid.GetBodeNeigbours(node, saveData.gridSizeX, saveData.gridSizeY); for (int i = 0; i < nodes.Count; i++) { nodes[i].userData = structureGameObject; } grid.BlockNeighbourNodes(node, saveData.gridSizeX, saveData.gridSizeY); AdjustStructureForGrid(node, structureGameObject); }
public void ProcessGardens(DisplayDelegate displayData) { for(int i = 0; i < gardens.Count; i++) { displayBox.Items.Add(displayData(gardens[i])); } }
public PlayerScoresPresentation(DisplayDelegate display, PlayerScoresLogic playerScoresLogic, int pointsToWin, Text scoresText) { this.display = display; this.playerScoresLogic = playerScoresLogic; this.pointsToWin = pointsToWin; this.scoresText = scoresText; }
public static Chromosome <TGene, TFitness> HillClimbing(OptimizationDelegate optimizationFunction, ImprovementDelegate isImprovement, OptimalDelegate isOptimal, NextFeatureValueDelegate getNextFeatureValue, DisplayDelegate display, int initialFeatureValue) { var best = optimizationFunction(initialFeatureValue); var stdout = Console.Out; Console.SetOut(TextWriter.Null); while (!isOptimal(best)) { var featureValue = getNextFeatureValue(best); var child = optimizationFunction(featureValue); if (!isImprovement(best, child)) { continue; } best = child; Console.SetOut(stdout); display(best, featureValue); Console.SetOut(TextWriter.Null); } Console.SetOut(stdout); return(best); }
public static Chromosome GetBest(GetFitnessDelegate getFitness, int targetLen, int optimalFitness, IReadOnlyList <char> geneSet, DisplayDelegate display) { var bestParent = GenerateParent(geneSet, targetLen, getFitness); display(bestParent); if (bestParent.Fitness >= optimalFitness) { return(bestParent); } while (true) { var child = Mutate(bestParent, geneSet, getFitness); if (bestParent.Fitness >= child.Fitness) { continue; } display(child); if (child.Fitness >= optimalFitness) { return(child); } bestParent = child; } }
void StartStructurePlacement(GameObject buttonGameObject, int index) { string refName = ObjectPoolManager.GetRefName(Structures[index]); int count = ObjectPoolManager.getActiveCountsByName(refName); Structure structure = Structures[index].GetComponent <Structure>(); if (selectedStructure != null) { UnSelectSelectedStructure(); } if (structure.structureCount > count || structure.structureCount == -1) { selectedStructure = ObjectPoolManager.Instantiate(Structures[index]); DisplayDelegate displayEventComponent = selectedStructure.GetComponent <DisplayDelegate>(); displayEventComponent.OnDisableEvent += OnDestroyStructure; displayEventComponent.UserData = buttonGameObject; selectedStructureSprite = selectedStructure.GetComponent <SpriteRenderer>().sprite; selectedStructureComponent = selectedStructure.GetComponent <Structure>(); int currentCount = structure.structureCount - ObjectPoolManager.getActiveCountsByName(refName); buttonGameObject.GetComponent <StructureButtonCounter>().SetCountText(currentCount); grid.OnGridOverTileChanged += OnGridTileChange; grid.OnGridNodeClick += OnGridNodeClick; } }
public OrderBookViewer() { // This call is required by the Windows Form Designer. InitializeComponent(); random = new Random(15); displayDelegate = new DisplayDelegate(DisplayForeground); this.tickerHandler = new SimulateMarketHandler(SimulateMarket); #if DEBUG // Disable the background threads when in the design mode. They will kill the designer. if (LicenseManager.UsageMode != LicenseUsageMode.Designtime) { #endif // This is used as a signal to terminate the background thread that does the market simulation. this.IsTickerRunning = true; this.thread = new Thread(new ThreadStart(Ticker)); this.thread.Name = "Chart Market Simulation"; this.thread.IsBackground = true; this.thread.Start(); #if DEBUG } #endif }
public BankController(AskDelegate ask, DisplayDelegate display) { var c = new GetPercentageDelegate(GetPercentage); _ask = ask; _display = display; _account = new Account(c); }
public void DisplayChart(int ChannelNumber, int DataNeedToRead, byte[] buf) { if (SideTable.InvokeRequired) { DisplayDelegate d = new DisplayDelegate(DisplayChart); this.Invoke(d, new object[] { ChannelNumber, DataNeedToRead, buf }); } else { if ((option.Fq == Frequence.High && ChannelNumber == 2) || (option.Fq == Frequence.Low && ChannelNumber == 0)) { if (!BinitailChart1 || chartLeft.DisplayLength != DataNeedToRead / 2) { chartLeft.Initialize(2, (int)DataNeedToRead / 2, option.RawMax, 100); waveLeft.Initialize(2, (int)DataNeedToRead / 2, option.RawMax, 100); LayOutSideChange(option.Side); chartLeft.SetColor(option.StartColor, option.EndColor, option.Gamma); chartLeft.Gain = option.Gain; waveLeft.DisplayAmpMax = option.RawMax; BinitailChart1 = true; } chartLeft.Display(buf, true); if (MainForm.mf.bShowRaw) { waveLeft.Display(buf, false); } } if ((option.Fq == Frequence.High && ChannelNumber == 3) || (option.Fq == Frequence.Low && ChannelNumber == 1)) { if (!BinitailChart2 || chartRight.DisplayLength != DataNeedToRead / 2) { chartRight.Initialize(2, (int)DataNeedToRead / 2, 4096, 100); waveRight.Initialize(2, (int)DataNeedToRead / 2, 4096, 100); LayOutSideChange(option.Side); chartRight.SetColor(option.StartColor, option.EndColor, option.Gamma); chartRight.Gain = option.Gain; waveRight.DisplayAmpMax = option.RawMax; BinitailChart2 = true; } chartRight.Display(buf, false); if (MainForm.mf.bShowRaw) { waveRight.Display(buf, false); } } } }
public static void DelegatesExercise() { DisplayDelegate del = new DisplayDelegate(DisplayDictInfo); Dictionary <int, string> dict = new Dictionary <int, string>(); dict.Add(1, "ted"); dict.Add(2, "kostas"); del(dict); }
void OnDestroyStructure(DisplayDelegate displayEvent) { // TODO there is a bug when exit from application in editor. if (this != null) { // delegate triggered just before being disabled. In order to get correct counting, will skip one frame; StartCoroutine(StructureDisabled(displayEvent)); } }
public void Run() { var a = new AskDelegate(Ask); var d = new DisplayDelegate(Ask); var controller = new BankController(a, d); controller.CallCommand("Deposit"); controller.CallCommand("GetBalance"); }
public Connection(string user, IPAddress userip, GetDelegate getDel, DisplayDelegate displayDel, ClearScreen ClearScreen) { userName = user; userIP = userip; get = getDel; display = displayDel; history = new StringBuilder(); synchronizationContext = SynchronizationContext.Current; clearScreen = ClearScreen; }
private static void Hyungseok_Lee_Excercise01() { Console.WriteLine("Excercise 1"); DisplayDelegate displayDelegate = DisplayArray; // Assignin a void method to a delegate displayDelegate(); //Implement the method through the delegate. Console.WriteLine("The searched element's location is " + Search(myArray1(), 5) + "\nIf the element is not found, the value is -1\n"); //Print searched number and explains when the result value is -1. Console.WriteLine("The searched element's location is " + Search(myArray2(), 'D') + "\nIf the element is not found, the value is -1"); //Print searched number and explains when the result value is -1. }
/* code appelé à partir de la thread de travail pour mettre à jour l'affichage * ceci déclenche un appel de méthode passé à l'UI avec le * texte d'état - et cet appel est fait sur la * thread UI */ public void Display() { try { DisplayDelegate disp = new DisplayDelegate(((IClient)frmClient).Display); /* appelle le formulaire client sur la thread UI * pour mettre à jour l'affichage */ frmClient.BeginInvoke(disp); } catch (Exception) { } }
}//End Constructor. /********************************************************************************** * Calls DisplayStatistics after determining if the StatisticsHandler is running in * another thread. *********************************************************************************/ private void DisplayControl() { //Check if the display output needs to be invoked before use. if (this.displayOutput.InvokeRequired) { //If it does, initialize a DisplayDelegate and invoke it. DisplayDelegate displayHandler = new DisplayDelegate(DisplayStatistics); this.displayOutput.Invoke(displayHandler); } else { //Otherwise just call DisplayStatistics. DisplayStatistics(); } }//End DisplayControl.
}//End ClearGraphics. /******************************************************************************************* * RecieveCalendarUpdate watches for the simulation calendar to fire a CalendarUpdate event. ******************************************************************************************/ public void RecieveCalendarUpdate(object sender, EventArgs e) { //Check if the canvas needs to be invoked before use if (this.canvas.InvokeRequired) { //If it does, initialize a DisplayDelegate and invoke it. DisplayDelegate displayHandler = new DisplayDelegate(DrawGraphics); this.canvas.Invoke(displayHandler); } else { //Otherwise just call DrawGraphics. DrawGraphics(); } }//End RecieveCalendarUpdate.
static void Main(string[] args) { Program p = new Program(); DisplayDelegate dd = new DisplayDelegate(Display); dd.Invoke(3.42f, 5.6f); SumDelegate sd = new SumDelegate(Sum); int result = sd.Invoke(60, 90); Console.WriteLine(result); GreetingDelegate gd = new GreetingDelegate(p.Greeting); bool name = gd.Invoke("kavya"); Console.WriteLine(name); Console.ReadKey(); }
private void UnSelectSelectedStructure() { if (selectedStructure != null) { DisplayDelegate displayEventComponent = selectedStructure.GetComponent <DisplayDelegate>(); displayEventComponent.OnDisableEvent -= OnDestroyStructure; grid.OnGridOverTileChanged -= OnGridTileChange; grid.OnGridNodeClick -= OnGridNodeClick; ObjectPoolManager.Destroy(selectedStructure); selectedStructure = null; selectedStructureSprite = null; selectedStructureComponent = null; FillStructureList(); } }
static void Main_07(string[] args) { OperationDelegate op = new OperationDelegate(MulticastDelegate.Add); op += MulticastDelegate.Sub; op += MulticastDelegate.Multi; op += MulticastDelegate.Div; op(10, 2, out int result); Console.WriteLine($"Result : {result}"); // o/p = 5 DisplayDelegate dis = new DisplayDelegate(MulticastDelegate.Display); dis += MulticastDelegate.Print; dis(); // Display1... // Print1... }
public void HistoryPreparing(DisplayDelegate display, string Text) { int HistoryCount = 0, AllLength = Text.Length; string MyHistory = "", History = Text; string Message; while (History != "") { Message = History.Substring(0, History.IndexOf('\n') + 1); HistoryCount += History.IndexOf('\n'); History = History.Remove(0, History.IndexOf('\n') + 1); if (Message.Contains(userIP.ToString())) { Message = Message.Remove(0, Message.IndexOf(userIP.ToString()) - 1); Message = Message.Insert(0, "You"); } MyHistory += Message; } display(MyHistory); }
public void SetMethods( ConstructDelegate construct, OnAssignDelegate onAssign, CheckDelegate check, ActionDelegate action, RegisterDelegate register, DisplayDelegate display, AddVerbDelegate addVerb, ParseInputDelegate parseInput ) { ConstructMethod = construct != null ? construct : ConstructDefault; OnAssignMethod = onAssign != null ? onAssign : OnAssignDefault; CheckMethod = check != null ? check : CheckDefault; ActionMethod = action != null ? action : ActionDefault; RegisterMethod = register != null ? register : RegisterDefault; DisplayMethod = display != null ? display : DisplayDefault; AddVerbMethod = addVerb != null ? addVerb : AddVerbDefault; ParseInputMethod = parseInput != null ? parseInput : ParseInputDefault; }
IEnumerator StructureDisabled(DisplayDelegate displayEvent) { yield return(new WaitForEndOfFrame()); displayEvent.OnDisableEvent -= OnDestroyStructure; Structure structure = displayEvent.gameObject.GetComponent <Structure>(); string refName = ObjectPoolManager.GetRefName(displayEvent.gameObject); int currentCount = structure.structureCount - ObjectPoolManager.getActiveCountsByName(refName); GameObject structureGameObject = (GameObject)displayEvent.UserData; GridNode mainNode = structure.GetMainGridNode(); grid.AllowNeighbourNodes(mainNode, structure.gridSizeX, structure.gridSizeY); if (structureGameObject != null) { structureGameObject.GetComponent <StructureButtonCounter>().SetCountText(currentCount); } else { ResetStructureButtons(); } }
//public delegate void PrintDelegateWithParams(string str); //public void Print() //{ // Console.WriteLine("Msg from print function"); //} //public void PrintParameters(string s) //{ // Console.WriteLine(s); //} static void Main(string[] args) { Program p = new Program(); DisplayDelegate d2 = delegate(string n1, int n2) { Console.WriteLine(n1); Console.WriteLine(n2); }; PrintDelegate d1 = delegate() { Console.WriteLine("Msg from anonymous function"); }; d1(); d2("I am everywhere", 10); SquareDelegate d3 = (x => x * x); Console.WriteLine(d3(45)); //PrintDelegate d1 = new PrintDelegate(p.Print); //PrintDelegateWithParams d2 = new PrintDelegateWithParams(p.PrintParameters); //d1(); //d2("Message from print parameters"); }
static void Main(string[] args) { DisplayDelegate dd = (x, y) => { Console.WriteLine(x + y); }; dd.Invoke(3.02f, 6.78f); SumDelegate sd = (x, y) => { return(x + y); }; int result = sd.Invoke(60, 90); Console.WriteLine(result); GreetingDelegate gd = name => { return(true); }; bool name1 = gd.Invoke("friends"); Console.WriteLine(name1); Console.ReadKey(); }
static void Main(string[] args) { DisplayDelegate dd = delegate(float x, float y) { Console.WriteLine(x + y); }; dd.Invoke(3.02f, 4.2f); SumDelegate sd = delegate(int x, int y) { return(x + y); }; int result = sd.Invoke(60, 90); Console.WriteLine(result); GreetingDelegate gd = delegate(string name) { return(true); }; bool name1 = gd.Invoke("friends"); Console.WriteLine(name1); Console.ReadKey(); }
public static Chromosome <TGene, TFitness> GetBest(GetFitnessDelegate getFitness, int targetLen, TFitness optimalFitness, IReadOnlyList <TGene> geneSet, DisplayDelegate display, MutateGeneDelegate customMutate = null, CreateDelegate customCreate = null, int?maxAge = null) { Chromosome <TGene, TFitness> FnMutate(Chromosome <TGene, TFitness> parent) => customMutate == null ? Mutate(parent, geneSet, getFitness) : MutateCustom(parent, customMutate, getFitness); Chromosome <TGene, TFitness> FnGenerateParent() { if (customCreate == null) { return(GenerateParent(targetLen, geneSet, getFitness)); } var genes = customCreate(); return(new Chromosome <TGene, TFitness>(genes, getFitness(genes))); } foreach (var improvement in GetImprovement(FnMutate, FnGenerateParent, maxAge)) { display(improvement); if (optimalFitness.CompareTo(improvement.Fitness) <= 0) { return(improvement); } } throw new UnauthorizedAccessException(); }
public void ShowOnConsole(List <string> data) { if (terminalTbx.InvokeRequired) { displayDlg = new DisplayDelegate(ShowOnConsole); try { terminalTbx.Invoke(displayDlg, data); } catch (Exception err) { if (err.InnerException == null) { errLog.SaveLogToTxt(err.StackTrace, err.Message, "None"); } else { errLog.SaveLogToTxt(err.StackTrace, err.Message, err.InnerException.ToString()); } } } else { try { if (data.Count > 1) //tylo jeden element czyli error { terminalTbx.Text = data[0]; // header 1 terminalTbx.Text += data[1]; // humidity SHT2x terminalTbx.Text += data[2]; // temperature SHT2x terminalTbx.Text += data[3]; // temperature DS18B20 1 terminalTbx.Text += data[4]; // temperature DS18B20 2 terminalTbx.Text += data[5]; // lux TSL2561T terminalTbx.Text += data[6]; // soil pH terminalTbx.Text += data[7]; // water pH terminalTbx.Text += data[8]; // soil moisture terminalTbx.Text += data[9]; // header 2 terminalTbx.Text += data[10]; // light is? ON/OFF terminalTbx.Text += data[11]; // light time ON/OFF data.Clear(); ReceivedDataList.Clear(); } else { data.Clear(); ReceivedDataList.Clear(); terminalTbx.Text = data[0]; // error } } catch (Exception err) { if (err.InnerException == null) { errLog.SaveLogToTxt(err.StackTrace, err.Message, "None"); } else { errLog.SaveLogToTxt(err.StackTrace, err.Message, err.InnerException.ToString()); } } } }
public void RecvDataParser(Byte[] xRevData) { DisplayDelegate DataReceivedDelegate = new DisplayDelegate(ShowOnConsole); CalibrationPh calibPh = new CalibrationPh(); string[] SplitedReceivedData = null; string ReceivedDataString = null; string humSht = null; string tempSht = null; string tempDS18B20_1 = null; string tempDS18B20_2 = null; string lux = null; string soilpH = null; string waterpH = null; string soilmoistureStr = null; string lightIs = null; int soilmoistureADC = 0; try { if (xRevData != null) { ReceivedDataString = Encoding.ASCII.GetString(xRevData); SplitedReceivedData = ReceivedDataString.Split(new char[] { ' ' }); //rozdziela po spacji // STA BOXER humSht tempSht tempDs1 tempDs2 lux soilPh waterpH soilMoist lightState LightHouCnt END if (SplitedReceivedData[0] == "STA" && SplitedReceivedData[12] == "END" && SplitedReceivedData.Length == 13) { if (SplitedReceivedData[1] == "BOXER") { humSht = SplitedReceivedData[2] + " [%RH]"; tempSht = SplitedReceivedData[3] + " [°C]"; tempDS18B20_1 = SplitedReceivedData[4] + " [°C]"; tempDS18B20_2 = SplitedReceivedData[5] + " [°C]"; lux = SplitedReceivedData[6] + " [lx]"; double soilpHDouble = double.Parse(SplitedReceivedData[7], System.Globalization.CultureInfo.InvariantCulture); double waterpHDouble = double.Parse(SplitedReceivedData[8], System.Globalization.CultureInfo.InvariantCulture); if (calibPh.StartCalibrationCMD == 0) { if ((soilpHDouble <= 0) || (soilpHDouble >= 14)) { soilpH = "------"; } else { soilpH = SplitedReceivedData[7] + " [pH]"; } if ((waterpHDouble <= 0) || (waterpHDouble >= 14)) { waterpH = "------"; } else { waterpH = SplitedReceivedData[8] + " [pH]"; } } else if (calibPh.StartCalibrationCMD == 1) { soilpH = "KALIBRACJA"; if ((waterpHDouble <= 0) || (waterpHDouble >= 14)) { waterpH = "------"; } else { waterpH = SplitedReceivedData[8] + " [pH]"; } } else if (calibPh.StartCalibrationCMD == 2) { if ((soilpHDouble <= 0) || (soilpHDouble >= 14)) { soilpH = "------"; } else { soilpH = SplitedReceivedData[7] + " [pH]"; } waterpH = "KALIBRACJA"; } soilmoistureADC = Convert.ToInt32(SplitedReceivedData[9]); if (soilmoistureADC == 1) { soilmoistureStr = "SUCHA!"; } else if (soilmoistureADC == 2) { soilmoistureStr = "OK"; } else if (soilmoistureADC == 0) { soilmoistureStr = "BŁĄD!"; } byte LightONorOFF = Convert.ToByte(SplitedReceivedData[10]); if (LightONorOFF == 2) { lightIs = "wł."; } else { lightIs = "wył."; } string LightTime = SplitedReceivedData[11] + " h"; ReceivedDataList.Add("========= Informacje podstawowe =========" + Environment.NewLine); ReceivedDataList.Add("Wilgotność powietrza:\t" + humSht + Environment.NewLine); ReceivedDataList.Add("Temperatura przy doniczce:\t" + tempSht + Environment.NewLine); ReceivedDataList.Add("Temperatura przy źr. światła:\t" + tempDS18B20_1 + Environment.NewLine); ReceivedDataList.Add("Temperatura powietrza:\t" + tempDS18B20_2 + Environment.NewLine); ReceivedDataList.Add("Natężenie światła:\t\t" + lux + Environment.NewLine); ReceivedDataList.Add("Wartość pH wody:\t\t" + waterpH + Environment.NewLine); ReceivedDataList.Add("Wartość pH gleby:\t\t" + soilpH + Environment.NewLine); ReceivedDataList.Add("Wilgotność gleby:\t\t" + soilmoistureStr + Environment.NewLine); ReceivedDataList.Add("============== Oświetlenie =============" + Environment.NewLine); ReceivedDataList.Add("Aktualnie:\t\t\t" + lightIs + Environment.NewLine); ReceivedDataList.Add("Czas pracy w danym stanie: \t" + LightTime + Environment.NewLine); DataReceivedDelegate(ReceivedDataList); } } else if (SplitedReceivedData[0] == "STA" && SplitedReceivedData[2] == "END" && SplitedReceivedData.Length == 3) { //STA CD END - koniec kalibracji if (SplitedReceivedData[1] == "CD") { calibPh.StartCalibrationCMD = 0; } } } } catch (Exception err) { if (err.InnerException == null) { errLog.SaveLogToTxt(err.StackTrace, err.Message, "None"); } else { errLog.SaveLogToTxt(err.StackTrace, err.Message, err.InnerException.ToString()); } } }
private void Form1_Load(object sender, EventArgs e) { delg = new DisplayDelegate(BindToRichText); }
public void DisplayChart(int ChannelNumber, int DataNeedToRead, byte[] buf) { if (SideTable.InvokeRequired) { DisplayDelegate d = new DisplayDelegate(DisplayChart); this.Invoke(d, new object[] { ChannelNumber, DataNeedToRead, buf }); } else { if ((option.Fq == Frequence.High && ChannelNumber == 2) || (option.Fq == Frequence.Low && ChannelNumber == 0)) { if (!BinitailChart1 || chartLeft.DisplayLength != DataNeedToRead/2) { chartLeft.Initialize(2, (int) DataNeedToRead/2, option.RawMax, 100); waveLeft.Initialize(2, (int) DataNeedToRead/2, option.RawMax, 100); LayOutSideChange(option.Side); chartLeft.SetColor(option.StartColor, option.EndColor, option.Gamma); chartLeft.Gain = option.Gain; waveLeft.DisplayAmpMax = option.RawMax; BinitailChart1 = true; } chartLeft.Display(buf, true); if (MainForm.mf.bShowRaw) waveLeft.Display(buf, false); } if ((option.Fq == Frequence.High && ChannelNumber == 3) || (option.Fq == Frequence.Low && ChannelNumber == 1)) { if (!BinitailChart2 || chartRight.DisplayLength != DataNeedToRead/2) { chartRight.Initialize(2, (int) DataNeedToRead/2, 4096, 100); waveRight.Initialize(2, (int) DataNeedToRead/2, 4096, 100); LayOutSideChange(option.Side); chartRight.SetColor(option.StartColor, option.EndColor, option.Gamma); chartRight.Gain = option.Gain; waveRight.DisplayAmpMax = option.RawMax; BinitailChart2 = true; } chartRight.Display(buf, false); if (MainForm.mf.bShowRaw) waveRight.Display(buf, false); } } }