void Destroy() { Instance = null; actions.Clear(); execCount = 0; currentAction = null; waitHandle.Close(); }
public Opcode(string disasm, byte operands, byte t, byte m, Exec exe) { Disassembly = disasm; Length = (byte)(operands + 1); Execute = exe; T = t; M = m; }
public override bool Execute() { HashSet <string> activeIgnorableErrorMessages = new HashSet <string>(); // Add any "Ignore" messages that don't have conditionals to our active list. if (IgnoredErrorMessagesWithConditional != null) { foreach (var message in IgnoredErrorMessagesWithConditional) { string conditional = message.GetMetadata("ConditionalErrorMessage"); if (string.IsNullOrEmpty(conditional)) { activeIgnorableErrorMessages.Add(message.ItemSpec); } } } for (int i = 0; i < MaxAttempts; i++) { string attemptMessage = $"(attempt {i + 1}/{MaxAttempts})"; _runningExec = new Exec { BuildEngine = BuildEngine, Command = Command, LogStandardErrorAsError = false, IgnoreExitCode = true, ConsoleToMSBuild = true }; if (!_runningExec.Execute()) { Log.LogError("Child Exec task failed to execute."); break; } int exitCode = _runningExec.ExitCode; if (exitCode == 0) { return(true); } if (_runningExec.ConsoleOutput != null && IgnoredErrorMessagesWithConditional != null && _runningExec.ConsoleOutput.Length > 0) { var consoleOutput = _runningExec.ConsoleOutput.Select(c => c.ItemSpec); // If the console output contains a "conditional" message, add the item to the active list. var conditionMessages = IgnoredErrorMessagesWithConditional.Where(m => consoleOutput.Any(n => n.Contains(m.GetMetadata("ConditionalErrorMessage")))); foreach (var condition in conditionMessages) { activeIgnorableErrorMessages.Add(condition.ItemSpec); } // If an active "ignore" message is present in the console output, then return true instead of retrying. foreach (var ignoreMessage in activeIgnorableErrorMessages) { if (consoleOutput.Any(c => c.Contains(ignoreMessage))) { Log.LogMessage(MessageImportance.High, $"Error detected, but error condition is valid, ignoring error \"{ignoreMessage}\""); return(true); } } } string message = $"Exec FAILED: exit code {exitCode} {attemptMessage}"; if (i + 1 == MaxAttempts || _cancelTokenSource.IsCancellationRequested) { Log.LogError(message); break; } Log.LogMessage(MessageImportance.High, message); TimeSpan delay = TimeSpan.FromSeconds( Math.Pow(RetryDelayBase, i) + RetryDelayConstant); Log.LogMessage(MessageImportance.High, $"Retrying after {delay}..."); try { Task.Delay(delay, _cancelTokenSource.Token).Wait(); } catch (AggregateException e) when(e.InnerException is TaskCanceledException) { break; } } return(false); }
public void RenameObject( string objtype, string sch, string name, string newsch, string newname, Exec e ) { Table t = objtype == "TABLE" ? GetTable( sch, name, e ) : null; string error = (string)ScalarSql( "SELECT sys.RenameObject( " + Util.Quote(objtype) + "," + Util.Quote(sch) + "," + Util.Quote(name) + "," + Util.Quote(newsch) + "," + Util.Quote(newname) + ")" )._O; if ( error != "" ) e.Error( error ); else if ( t != null ) { Schema s = GetSchema( sch, true, e ); Schema ns = GetSchema( newsch, true, e ); s.TableDict.Remove( name ); ns.TableDict[ newname ] = t; } else { ResetCache(); } }
// Indexes. public void CreateIndex( string schemaName, string tableName, string indexName, string [] names, Exec e ) { Table t = (Table)GetTable( schemaName, tableName, e ); long tid = t.TableId; long indexId = GetIndexId( tid, indexName ); if ( indexId != 0 ) e.Error( "Index already exists" ); int [] colIx = new int[ names.Length ]; for ( int i=0; i < names.Length; i +=1 ) { colIx[ i ] = t.ColumnIx( names[i], e ); } // Create the index. { var r = new RowCursor( SysIndex ); r.V[1].L = tid; r.V[2].O = indexName; indexId = r.Insert(); } // Create the index columns. { var r = new RowCursor( SysIndexCol ); r.V[1].L = tid; r.V[2].L = indexId; for ( int i = 0; i < names.Length; i += 1 ) { r.V[3].L = colIx[ i ]; r.Insert(); } } if ( Normal ) { t.OpenIndexes(); t.InitIndex( indexId ); } }
public void CreateTable( string schemaName, string tableName, ColInfo cols, string definition, bool isView, bool alter, Exec e ) { Schema schema = GetSchema( schemaName, true, e ); bool isView1; string definition1; long tableId = tableId = ReadTableId( schema, tableName, out isView1, out definition1 ); if ( alter ) { if ( tableId == 0 || !isView1 ) e.Error( "View does not exist" ); } else if ( Normal && schema.GetCachedTable( tableName ) != null || tableId >= 0 ) e.Error( "Table/View " + schemaName + "." + tableName + " already exists" ); var r = new RowCursor( SysTable ); r.V[1].L = schema.Id; r.V[2].O = tableName; r.V[3].L = isView ? 1 : 0; r.V[4].O = isView ? definition.Trim() : ""; if ( alter ) r.Update( tableId ); else tableId = r.Insert(); if ( !isView) SaveColumns( tableId, cols ); if ( isView ) ResetCache(); }
public REPLACE(G.List <Exp> args, Exec e) : base(args, DataType.String, new DataType[] { DataType.String, DataType.String, DataType.String }, e) { }
public FILEATTR(G.List <Exp> args, Exec e) : base(args, DataType.String, new DataType[] { DataType.Bigint, DataType.Bigint }, e) { }
public Opcode(string disasm, byte operands, byte t, Exec exe) : this(disasm, operands, t, (byte)(t / 4), exe) { }
public HalloweenRocker( DigitalOutput2 rockingMotor, DigitalOutput2 ladyEyes, StrobeColorDimmer3 strobeLight, AudioPlayer audioPlayer, [System.Runtime.CompilerServices.CallerMemberName] string name = "") : base(name) { pulsatingRocking.ConnectTo(strobeLight, Utils.Data(DataElements.Color, Color.HotPink)); OutputPower.Subscribe(x => { if (x) { LockDevices(rockingMotor, ladyEyes, strobeLight); audioPlayer.SetBackgroundVolume(0.2); audioPlayer.PlayBackground(); sub.Run(); } else { audioPlayer.PauseBackground(); UnlockDevices(); Exec.Cancel(sub); } }); sub .SetUp(ins => { ladyEyes.SetValue(true, this.controlToken); rockingMotor.SetValue(true, this.controlToken); }) .RunAction(ins => { while (!ins.IsCancellationRequested) { isRockingLadyTalking = true; audioPlayer.PlayEffect("A conversation with Mother.wav"); ins.WaitFor(S(42), true); isRockingLadyTalking = false; ins.WaitFor(S(15.0)); } }) .TearDown(ins => { audioPlayer.PauseFX(); ladyEyes.SetValue(false, this.controlToken); rockingMotor.SetValue(false, this.controlToken); }); PowerOn.RunAction(ins => { pulsatingRocking.Start(token: this.controlToken); if (!isRockingLadyTalking) { switch (random.Next(3)) { case 0: audioPlayer.PlayEffect("032495843-old-woman-cough.wav"); break; case 1: audioPlayer.PlayEffect("049951942-grampy-old-woman-cackle.wav"); break; case 2: audioPlayer.PlayEffect("053851373-old-ungly-female-laughter.wav"); break; } } ins.WaitFor(S(7)); }) .TearDown(ins => { pulsatingRocking.Stop(); }); }
void Start() { Instance = this; waitHandle = new AutoResetEvent(false); }
public override void Start() { hoursSmall.AddRange("5:00 pm", "9:00 pm"); hoursFull.AddRange("5:00 pm", "9:00 pm"); //hoursFull.SetForced(true); //hoursSmall.SetForced(true); //hoursFull.SetForced(false); //hoursSmall.SetForced(false); #if !true hoursFull.SetForced(true); audioBeauty.SetSilent(true); audioCat.SetSilent(true); audioGeorge.SetSilent(true); audioSpider.SetSilent(true); georgeMotor.SetDisabled(true); #endif var backgroundSeq = new Controller.Sequence("BG Sequence"); backgroundSeq.WhenExecuted .SetUp(() => { audioGeorge.PlayBackground(); lightFloor.SetOnlyColor(Color.Orange); pulsatingEffect1.Start(); flickerEffect.Start(); }) .Execute(instance => { while (!instance.IsCancellationRequested) { instance.WaitFor(S(1)); if (!this.lastFogRun.HasValue || (DateTime.Now - this.lastFogRun.Value).TotalMinutes > 10) { // Run the fog for a little while switchFog.SetPower(true); instance.WaitFor(S(4)); switchFog.SetPower(false); this.lastFogRun = DateTime.Now; } } }) .TearDown(() => { audioGeorge.PauseBackground(); pulsatingEffect1.Stop(); flickerEffect.Stop(); }); var deadendSeq = new Controller.Sequence("Deadend dr"); deadendSeq.WhenExecuted .Execute(instance => { switchDeadendDrive.SetPower(true); Thread.Sleep(1000); switchDeadendDrive.SetPower(false); }); var stairSeq = new Controller.Sequence("Stair Sequence"); stairSeq.WhenExecuted .SetUp(() => { }) .Execute(instance => { switchFog.SetPower(true); this.lastFogRun = DateTime.Now; Executor.Current.Execute(deadendSeq); audioGeorge.PlayEffect("ghostly"); instance.WaitFor(S(0.5)); popOutEffect.Pop(1.0); instance.WaitFor(S(1.0)); audioSpider.PlayNewEffect("348 Spider Hiss"); switchSpider.SetPower(true); instance.WaitFor(S(0.5)); switchSpiderEyes1.SetPower(true); instance.WaitFor(S(2)); switchSpider.SetPower(false); switchSpiderEyes1.SetPower(false); instance.WaitFor(S(4)); stateMachine.NextState(); }) .TearDown(() => { switchFog.SetPower(false); audioGeorge.PauseFX(); }); var georgeReturnSeq = new Controller.Sequence("George Return Seq"); georgeReturnSeq.WhenExecuted .Execute(instance => { georgeMotor.WaitForVectorReached(); georgeMotor.SetVector(0.9, 0, S(15)); georgeMotor.WaitForVectorReached(); }); var georgeSeq = new Controller.Sequence("George Sequence"); georgeSeq.WhenExecuted .Execute(instance => { //Exec.WaitUntilFinished(georgeReturnSeq); audioGeorge.PlayEffect("laugh"); georgeMotor.SetVector(1.0, 350, S(10)); instance.WaitFor(TimeSpan.FromSeconds(0.8)); lightGeorge.SetColor(Color.Red); georgeMotor.WaitForVectorReached(instance); instance.WaitFor(TimeSpan.FromSeconds(2)); georgeMotor.SetVector(0.9, 0, S(15)); lightGeorge.RunEffect(new Effect2.Fader(1.0, 0.0), S(1.0)); instance.WaitFor(TimeSpan.FromSeconds(1)); lightFloor.SetOnlyColor(Color.Green); pulsatingEffect1.Start(); georgeMotor.WaitForVectorReached(instance); instance.WaitFor(S(15)); }) .TearDown(() => { Exec.Execute(georgeReturnSeq); pulsatingEffect1.Stop(); lightGeorge.TurnOff(); }); var spiderEyes2Seq = new Controller.Sequence("Spider Eyes 2"); spiderEyes2Seq.WhenExecuted .Execute(instance => { var rnd = new Random(); while (!instance.IsCancellationRequested) { switchSpiderEyes2.SetPower(true); instance.WaitFor(S(1.0 + rnd.Next(10))); switchSpiderEyes2.SetPower(false); instance.WaitFor(S(1.0 + rnd.Next(2))); } }); var popupSeq = new Controller.Sequence("Popup Sequence"); popupSeq.WhenExecuted .Execute(instance => { audioBeauty.PlayEffect("scream", 0.0, 1.0); switchPopEyes.SetPower(true); instance.WaitFor(TimeSpan.FromSeconds(1.0)); lightPopup.SetBrightness(1.0); switchPopUp.SetPower(true); instance.WaitFor(S(3)); lightPopup.RunEffect(new Effect2.Fader(1.0, 0.0), S(1.0)); switchPopEyes.TurnOff(); switchPopUp.TurnOff(); }); var beautySeq = new Controller.Sequence("Beauty Sequence"); beautySeq.WhenExecuted .Execute(instance => { flickerEffect2.Stop(); lightBeauty.SetColor(Color.Purple); switchHand.SetPower(true); instance.WaitFor(TimeSpan.FromSeconds(1)); audioBeauty.PlayEffect("gollum_precious1", 1.0, 0.0); instance.WaitFor(TimeSpan.FromSeconds(0.4)); switchHead.SetPower(true); instance.WaitFor(TimeSpan.FromSeconds(6)); switchHead.SetPower(false); switchHand.SetPower(false); instance.WaitFor(TimeSpan.FromSeconds(1.5)); lightBeauty.TurnOff(); instance.WaitFor(TimeSpan.FromSeconds(0.5)); switchDrawer1.SetPower(true); switchHead.SetPower(true); instance.WaitFor(TimeSpan.FromSeconds(0.5)); lightBeauty.SetColor(Color.Red, 1.0); audioBeauty.PlayEffect("my_pretty", 1.0, 0.0); instance.WaitFor(TimeSpan.FromSeconds(4)); switchDrawer2.SetPower(true); instance.WaitFor(TimeSpan.FromSeconds(2)); switchDrawer1.SetPower(false); instance.WaitFor(TimeSpan.FromSeconds(0.15)); switchDrawer2.SetPower(false); instance.WaitFor(TimeSpan.FromSeconds(1)); switchHead.SetPower(false); lightBeauty.RunEffect(new Effect2.Fader(1.0, 0.0), S(1.0)); if (hoursSmall.IsOpen) { flickerEffect2.Start(); } instance.WaitFor(TimeSpan.FromSeconds(5)); }); var catSeq = new Controller.Sequence("Cat Sequence"); catSeq.WhenExecuted .Execute(instance => { var maxRuntime = System.Diagnostics.Stopwatch.StartNew(); var random = new Random(); catLights.SetPower(true); while (true) { switch (random.Next(4)) { case 0: audioCat.PlayEffect("266 Monster Growl 7", 1.0, 1.0); instance.WaitFor(TimeSpan.FromSeconds(2.0)); break; case 1: audioCat.PlayEffect("285 Monster Snarl 2", 1.0, 1.0); instance.WaitFor(TimeSpan.FromSeconds(3.0)); break; case 2: audioCat.PlayEffect("286 Monster Snarl 3", 1.0, 1.0); instance.WaitFor(TimeSpan.FromSeconds(2.5)); break; case 3: audioCat.PlayEffect("287 Monster Snarl 4", 1.0, 1.0); instance.WaitFor(TimeSpan.FromSeconds(1.5)); break; default: instance.WaitFor(TimeSpan.FromSeconds(3.0)); break; } instance.CancelToken.ThrowIfCancellationRequested(); if (maxRuntime.Elapsed.TotalSeconds > 10) { break; } } }) .TearDown(() => { catLights.TurnOff(); }); var candyCane = new Controller.Sequence("Candy Cane"); candyCane .WhenExecuted .SetUp(() => allPixels.TurnOff()) .Execute(instance => { var cbList = new List <ColorBrightness>(); //cbList.Add(new ColorBrightness(Color.Green, 1.00)); //cbList.Add(new ColorBrightness(Color.Green, 0.70)); //cbList.Add(new ColorBrightness(Color.Green, 0.40)); //cbList.Add(new ColorBrightness(Color.White, 1.00)); //cbList.Add(new ColorBrightness(Color.White, 0.70)); //cbList.Add(new ColorBrightness(Color.White, 0.40)); //cbList.Add(new ColorBrightness(Color.Red, 1.00)); //cbList.Add(new ColorBrightness(Color.Red, 0.70)); //cbList.Add(new ColorBrightness(Color.Red, 0.40)); //cbList.Add(new ColorBrightness(Color.Black, 0.0)); //cbList.Add(new ColorBrightness(Color.Black, 0.0)); //cbList.Add(new ColorBrightness(Color.Black, 0.0)); //cbList.Add(new ColorBrightness(Color.Black, 0.0)); double b1 = 1.00; double b2 = 0.70; double b3 = 0.40; Color c1 = Color.Blue; Color c2 = Color.Yellow; Color c3 = Color.Blue; Color c4 = Color.Black; cbList.Add(new ColorBrightness(c1, b1)); cbList.Add(new ColorBrightness(c1, b2)); cbList.Add(new ColorBrightness(c1, b3)); cbList.Add(new ColorBrightness(c2, b1)); cbList.Add(new ColorBrightness(c2, b2)); cbList.Add(new ColorBrightness(c2, b3)); cbList.Add(new ColorBrightness(c3, b1)); cbList.Add(new ColorBrightness(c3, b2)); cbList.Add(new ColorBrightness(c3, b3)); cbList.Add(new ColorBrightness(c4, 0.0)); cbList.Add(new ColorBrightness(c4, 0.0)); cbList.Add(new ColorBrightness(c4, 0.0)); cbList.Add(new ColorBrightness(c4, 0.0)); b1 = 1.00; b2 = 0.70; b3 = 0.40; c1 = Color.White; c2 = Color.Blue; c3 = Color.Red; c4 = Color.Black; cbList.Add(new ColorBrightness(c1, b1)); cbList.Add(new ColorBrightness(c1, b2)); cbList.Add(new ColorBrightness(c1, b3)); cbList.Add(new ColorBrightness(c2, b1)); cbList.Add(new ColorBrightness(c2, b2)); cbList.Add(new ColorBrightness(c2, b3)); cbList.Add(new ColorBrightness(c3, b1)); cbList.Add(new ColorBrightness(c3, b2)); cbList.Add(new ColorBrightness(c3, b3)); cbList.Add(new ColorBrightness(c4, 0.0)); cbList.Add(new ColorBrightness(c4, 0.0)); cbList.Add(new ColorBrightness(c4, 0.0)); cbList.Add(new ColorBrightness(c4, 0.0)); b1 = 1.00; b2 = 0.70; b3 = 0.40; c1 = Color.Red; c2 = Color.White; c3 = Color.Blue; c4 = Color.Black; cbList.Add(new ColorBrightness(c1, b1)); cbList.Add(new ColorBrightness(c1, b2)); cbList.Add(new ColorBrightness(c1, b3)); cbList.Add(new ColorBrightness(c2, b1)); cbList.Add(new ColorBrightness(c2, b2)); cbList.Add(new ColorBrightness(c2, b3)); cbList.Add(new ColorBrightness(c3, b1)); cbList.Add(new ColorBrightness(c3, b2)); cbList.Add(new ColorBrightness(c3, b3)); cbList.Add(new ColorBrightness(c4, 0.0)); cbList.Add(new ColorBrightness(c4, 0.0)); cbList.Add(new ColorBrightness(c4, 0.0)); cbList.Add(new ColorBrightness(c4, 0.0)); while (true) { foreach (var cb in cbList) { allPixels.Inject(cb); instance.WaitFor(S(0.350), true); } } }) .TearDown(() => { allPixels.TurnOff(); }); stateMachine.ForFromSequence(States.Background, backgroundSeq); stateMachine.ForFromSequence(States.Stair, stairSeq); stateMachine.ForFromSequence(States.George, georgeSeq); stateMachine.ForFromSequence(States.Popup, popupSeq); hoursSmall.OpenHoursChanged += (sender, e) => { if (e.IsOpenNow) { pulsatingEffect2.Start(); flickerEffect.Start(); flickerEffect2.Start(); catFan.SetPower(true); lightEyes.SetPower(true); lightTreeGhost.SetBrightness(1.0); // Exec.Execute(candyCane); allPixels.SetAll(Color.FromArgb(255, 115, 0), 0.5); } else { pulsatingEffect2.Stop(); flickerEffect.Stop(); flickerEffect2.Stop(); catFan.SetPower(false); lightEyes.SetPower(false); lightTreeGhost.TurnOff(); allPixels.TurnOff(); } }; hoursFull.OpenHoursChanged += (sender, e) => { if (e.IsOpenNow) { Executor.Current.Execute(spiderEyes2Seq); stateMachine.SetBackgroundState(States.Background); stateMachine.SetState(States.Background); } else { Executor.Current.Cancel(spiderEyes2Seq); stateMachine.Hold(); stateMachine.SetBackgroundState(null); audioGeorge.PauseBackground(); } }; buttonMotionCat.ActiveChanged += (sender, e) => { #if CHECK_SENSOR_ALIGNMENT catLights.SetPower(e.NewState); #else if (e.NewState && hoursSmall.IsOpen) { Executor.Current.Execute(catSeq); } #endif }; buttonMotionBeauty.ActiveChanged += (sender, e) => { if (e.NewState && hoursFull.IsOpen) { Executor.Current.Execute(beautySeq); } }; buttonTriggerStairs.ActiveChanged += (sender, e) => { if (!hoursSmall.IsOpen) { lightFloor.SetColor(Color.Purple, e.NewState ? 0.6 : 0.0); } else { if (e.NewState && hoursFull.IsOpen) { if (!stateMachine.CurrentState.HasValue || stateMachine.CurrentState == States.Background) { stateMachine.SetState(States.Stair); } } } }; buttonTriggerPopup.ActiveChanged += (sender, e) => { if (!hoursSmall.IsOpen) { lightPopup.SetBrightness(e.NewState ? 0.5 : 0.0); } else { if (e.NewState) { if (stateMachine.CurrentState == States.George) { stateMachine.SetState(States.Popup); } } } }; flickerEffect.AddDevice(skullsLight); flickerEffect2.AddDevice(skullsLight2); lightFloor.SetColor(Color.Orange, 0); lightSign.SetColor(Color.Pink, 0); pulsatingEffect1.AddDevice(lightFloor); pulsatingEffect1.AddDevice(lightSpiderWeb); pulsatingEffect2.AddDevice(lightSign); popOutEffect.AddDevice(skullsLight); ForTest(); }
public virtual void CheckNames( Exec e ){} // Checks the column names are distinct and not blank. public virtual void Convert( DataType [] types, Exec e ){} // Converts the expressions ready to be assigned
public virtual TableExpression Load( SqlExec e ) { return this; } // Loads table or view definition from database. public virtual void CheckNames( Exec e ){} // Checks the column names are distinct and not blank.
static void Main(string[] args) { #region 1 - Delegar noutro método //cria instâncias dos delegates NumberChanger nc1 = new NumberChanger(Delegates.AddNum); //ou //nc1 = Delegates.AddNum; NumberChanger nc2 = new NumberChanger(Delegates.MultNum); //chama os métodos usando os delegates nc1(25); Console.WriteLine("Numero: {0}", Delegates.Num); nc2(5); Console.WriteLine("Numero: {0}", Delegates.Num); Console.ReadKey(); #endregion #region 2 - Delegar noutro método Pessoa p = new Pessoa("Ola", new DateTime(2000, 12, 24)); //cria instâncias de delegates MyDelegate1 nc3 = new MyDelegate1(p.GetIdade); MyDelegate2 nc4 = new MyDelegate2(Console.WriteLine); //o mesmo que //nc4 = Console.WriteLine; //chama metodos usando delegates int idade = nc3(); Console.WriteLine("Idade: {0}", idade); idade = p.GetIdade(); nc4("Nascimento: " + p.Nasci.ToString()); Console.ReadKey(); #endregion #region 3 - Delegates como parâmetros PrintString ps1 = new PrintString(Print.WriteToScreen); PrintString ps2 = new PrintString(Print.WriteToFile); Print.SendString(ps1); Print.SendString(ps2); Console.ReadKey(); #endregion #region 4 - Delegates como parâmetros //cria delegate com callback associado Exec d1 = new Exec(Delegates.AddNumNum); //invoca metodo com callback no parametro int aux = Delegates.ExecSomething(12, 13, d1); //invoca delegate Print.SendString(ps1, "Resultado: " + aux.ToString()); Console.ReadKey(); #endregion #region 5 - Mulcasting Delegates MethodClass obj = new MethodClass(); MyDelegate2 nc5 = new MyDelegate2(Console.WriteLine); MyDelegate2 m1 = obj.Method1; MyDelegate2 m2 = obj.Method2; nc5 = Console.WriteLine; //ou MyDelegate2 allMethodsDelegate = m1 + m2; allMethodsDelegate += nc5; allMethodsDelegate("-Teste-"); //ao invocar allMethodsDelegate serão executados Method1, Method2 e WriteLine Console.ReadKey(); #endregion #region 6 - Outros Delegates MethodClass.Method3(new int[] { 3, 4, 5, 6 }, Console.WriteLine); Console.ReadKey(); MethodClass.Method3(new int[] { 3, 4, 5, 6 }, MethodClass.ShowOdd); Console.ReadKey(); #endregion #region 7 - Anonymous Methods MyPrint print = delegate(int val) { Console.WriteLine("Inside Anonymous method. Value: {0}", val); }; print(100); #endregion #region 8 - Eventos FileLogger fl = new FileLogger(@"c:\temp\Process.log"); MyClass myClass = new MyClass(); // Subscribe the Functions Logger and fl.Logger myClass.Log += new MyClass.LogHandler(MyClass.Logger); //Event Handlers myClass.Log += new MyClass.LogHandler(fl.Logger); // The Event will now be triggered in the Process() Method myClass.Process(); fl.Close(); #endregion #region 10 - Events Handler Counter c = new Counter(new Random().Next(10)); c.ThresholdReached += c_ThresholdReached; Console.WriteLine("press 'a' key to increase total"); while (Console.ReadKey(true).KeyChar == 'a') { Console.WriteLine("adding one"); c.Add(1); } #endregion #region 9 - Eventos // Create a new clock Clock theClock = new Clock(); // Create the display and tell it to subscribe to the clock just created DisplayClock dc = new DisplayClock(); dc.Subscribe(theClock); // Create a Log object and tell it to subscribe to the clock LogClock lc = new LogClock(); lc.Subscribe(theClock); // Get the clock started theClock.Run(); #endregion }
public IAsyncResult BeginExecute(AsyncCallback callback, object obj) { _exec = new Exec(Execute); return _exec.BeginInvoke(callback, null); }
private static void GetLatest() { if (!Directory.Exists(@"C:\JizHydrusLatest\")) { Directory.CreateDirectory(@"C:\JizHydrusLatest\"); } //try //{ var gateway = Gateway.GatewayList(); //delete all latest here var result = Delete.LatestReading(); Console.WriteLine($"Delete {result}"); foreach (var g in gateway) { //var x = context.GetLatestMeterReading(g.Name); Exec.LatestReading(g); //Console.WriteLine(x); //var extractMeter = context.Database // .SqlQuery<CustomLatest>("SELECT DISTINCT MeterAddress, ReadingDate, RawTelegram FROM tblLatest WHERE GatewayId=@GatewayId", // new SqlParameter("@GatewayId", g.Name)); var extractMeter = Get.LatestReading(g); var fileName = Timex.CurrentTime(); string path2 = @"C:\JizHydrusLatest\" + g + "\\" + fileName + ".csv"; if (!Directory.Exists(@"C:\JizHydrusLatest\" + g + "\\")) { Directory.CreateDirectory(@"C:\JizHydrusLatest\" + g + "\\"); } using (StreamWriter writer = new StreamWriter(path2, false)) { string[] separator = { "," }; var filecontents = new StringBuilder(); filecontents.Append("METER_ADDRESS, READING_DATE, PACKET\r\n"); string extract = null; foreach (DataRow em in extractMeter.Tables["MeterReading"].Rows) { extract += em["MeterAddress"] + ","; //Serial extract += em["ReadingDate"] .ToString() .DBtoCSVDateConvert() + ","; //Date extract += em["RawTelegram"]; //Packet extract += "\r\n"; } filecontents.Append(extract); writer.Write(filecontents.ToString()); writer.Flush(); writer.Close(); } } Console.WriteLine("Extracted"); //} //catch (Exception exception) //{ // Console.WriteLine(exception); // throw; //} }
public IAsyncResult BeginExecute(AsyncCallback callback, object obj) { _execute = new Exec(Execute); return(_execute.BeginInvoke(callback, obj)); }
public App() { DispatcherUnhandledException += App_DispatcherUnhandledException; Exec.Initialize(Dispatcher); }
public FILECONTENT(G.List <Exp> args, Exec e) : base(args, DataType.Binary, new DataType[] { DataType.Bigint }, e) { }
public IAsyncResult BeginExecute(AsyncCallback callback, object obj) { this._exec = new Exec(this.Execute); return(this._exec.BeginInvoke(callback, null)); }
public SUBSTRING(G.List <Exp> args, Exec e) : base(args, DataType.String, new DataType[] { DataType.String, DataType.Bigint, DataType.Bigint }, e) { }
public CoffeeMissionAct(SelectLayoutLong select, Exec exec) : base(select, exec) { returnAct = exec; }
public void AlterTable( string schemaName, string tableName, G.List<AlterAction> alist, Exec e ) { Table t = (Table) GetTable( schemaName, tableName, e ); var names = new G.List<string>( t.Cols.Names ); var types = new G.List<DataType>( t.Cols.Types ); var map = new G.List<int>(); for ( int i = 0; i < names.Count; i += 1 ) map.Add( i ); foreach ( AlterAction aa in alist ) { int ix = names.IndexOf( aa.Name ); if ( aa.Operation != Action.Add && ix == -1 ) e.Error( "Column " + aa.Name + " not found" ); switch ( aa.Operation ) { case Action.Add: if ( ix != -1 ) e.Error( "Column " + aa.Name + " already exists" ); names.Add( aa.Name ); types.Add( aa.Type ); map.Add( 0 ); Sql( "INSERT INTO sys.Column( Table, Name, Type ) VALUES ( " + t.TableId + "," + Util.Quote(aa.Name) + "," + (int)aa.Type + ")" ); break; case Action.Drop: names.RemoveAt( ix ); types.RemoveAt( ix ); map.RemoveAt( ix ); Sql( "DELETE FROM sys.Column WHERE Table = " + t.TableId + " AND Name = " + Util.Quote(aa.Name) ); Sql( "EXEC sys.DroppedColumn(" + t.TableId + "," + ix + ")" ); break; case Action.ColumnRename: names.RemoveAt( ix ); names.Insert( ix, aa.NewName ); Sql( "UPDATE sys.Column SET Name = " + Util.Quote(aa.NewName) + " WHERE Table=" + t.TableId + " AND Name = " + Util.Quote(aa.Name) ); break; case Action.Modify: if ( DTI.Base( aa.Type ) != DTI.Base( types[ ix ] ) ) e.Error( "Modify cannot change base type" ); if ( DTI.Scale( aa.Type ) != DTI.Scale( types[ ix ] ) ) e.Error( "Modify cannot change scale" ); types.RemoveAt( ix ); types.Insert( ix, aa.Type ); Sql( "UPDATE sys.Column SET Type = " + (int)aa.Type + " WHERE Table=" + t.TableId + " AND Name = " + Util.Quote(aa.Name) ); Sql( "EXEC sys.ModifiedColumn(" + t.TableId + "," + ix + ")" ); break; } } var newcols = ColInfo.New( names, types ); t.AlterData( newcols, map.ToArray() ); Sql( "EXEC sys.RecreateModifiedIndexes()" ); t.OpenIndexes(); ResetCache(); }
// Stored procedures and functions. public void CreateRoutine( string schemaName, string name, string definition, bool func, bool alter, Exec e ) { int schemaId = GetSchemaId( schemaName, true, e ); name = Util.Quote( name ); string tname = func ? "Function" : "Procedure"; string exists = (string) ScalarSql( "SELECT Name from sys." + tname + " where Name=" + name + " AND Schema=" + schemaId )._O; if ( exists != null && !alter ) e.Error( tname + " " + name + " already exists" ); else if ( exists == null && alter ) e.Error( tname + " " + name + " does not exist" ); if ( alter ) { Sql( "UPDATE sys." + tname + " SET Definition = " + Util.Quote(definition.Trim()) + " WHERE Name = " + name + " AND Schema = " + schemaId ); } else { Sql( "INSERT INTO sys." + tname + "( Schema, Name, Definition ) VALUES ( " + schemaId + "," + name + "," + Util.Quote(definition.Trim()) + ")" ); } ResetCache(); }
public override async void OnToolState(IModel sender, bool state) { var layer = sender.CurrentLayer; if (!layer.IsEdit || !layer.IsShow) { return; } if (layer.Bitmap == null) { return; } Debug.WriteLine("state:" + state); if (state) { layer.getRect(out orec, out obb); if (Clipper.IsCliping) { VModel.vm.Loading = true; //拷贝选区 var Bitmap = new WriteableBitmap((int)DrawRect.Width, (int)DrawRect.Height); IGrap.copyImg(obb, Bitmap, (int)orec.X, (int)orec.Y); layer.Child = Clipper.createPolygon(Bitmap); var p = (Point)layer.Child.Tag; var xb = await(layer.Child.Render()); Clipper.Points.Clear(); layer.Child = null; if (xb != null) { var i = sender.Layers.IndexOf(layer); var nb = obb; var ob = obb; if (layer.Bitmap != null) { nb = layer.Bitmap.Clone(); IGrap.delImg(xb, nb, (int)(p.X - orec.X), (int)(p.Y - orec.Y)); nb.Invalidate(); } obb = xb; orec = new Rect(p.X, p.Y, xb.PixelWidth, xb.PixelHeight); Exec.Do(new Exec() { exec = () => { sender.Layers[i].Bitmap = nb; sender.Layers.Insert(i, new LayerModel() { Bitmap = xb, X = p.X, Y = p.Y }); sender.CurrentLayer = sender.Layers[i]; }, undo = () => { sender.Layers.RemoveAt(i); sender.CurrentLayer = sender.Layers[i]; sender.CurrentLayer.Bitmap = ob; } }); } VModel.vm.Loading = false; } sender.ElemArea.Child = CreateRect(sender); ch = false; } else { sender.ElemArea.Child = null; if (!ch) { return; } var vc = new CompositeTransform() { Rotation = com.Rotation, ScaleX = com.ScaleX, ScaleY = com.ScaleY, CenterX = com.TranslateX + layer.W / 2, CenterY = com.TranslateY + layer.H / 2 }; var or = orec; var ob = obb; layer.getRect(out Rect nr, out WriteableBitmap nb); if (com.ScaleX != 1 || com.ScaleY != 1 || com.Rotation != 0) { var elem = (FrameworkElement)((DrawPanel)sender).ITEMS.ContainerFromItem(layer); VModel.vm.Loading = true; var b = await(elem).Render(); VModel.vm.Loading = false; var vr = vc.TransformBounds(nr); nr = RectHelper.Intersect(DrawRect, vr); if (nr.IsEmpty) { nb = null; layer.setRect(nr, nb); } else { nb = new WriteableBitmap((int)nr.Width, (int)nr.Height); IGrap.addImg(b, nb, (int)(vr.X - nr.X), (int)(vr.Y - nr.Y)); layer.setRect(nr, nb); } com.Rotation = 0; com.ScaleX = 1; com.ScaleY = 1; } var i = sender.Layers.IndexOf(sender.CurrentLayer); Exec.Save(new Exec() { exec = () => { sender.Layers[i].setRect(nr, nb); }, undo = () => { sender.Layers[i].setRect(or, ob); } }); } }
int GetSchemaId( string schemaName, bool mustExist, Exec e ) { Schema s = GetSchema( schemaName, mustExist, e ); if ( s == null ) return -1; return s.Id; }
static int Main(string[] args) { if (args.Length != 1) { Cout.printf("Usage: {0} file.json", AppDomain.CurrentDomain.FriendlyName); return 1; } string json_raw = ""; try { json_raw = File.ReadAllText(args[0]); } catch { Console.WriteLine("The provided path does not identify a file"); return 1; } Keyboard keyboard = new Keyboard(); var assembly = Assembly.GetExecutingAssembly(); try { keyboard = JsonConvert.DeserializeObject<Keyboard>(json_raw); keyboard.desc.product_name = keyboard.desc.product_name.Replace(" ", "_"); } catch { Console.WriteLine("The format of the provided file is invalid"); return 2; } //Validations if (!Validations.has_valid_key_codes(keyboard)) { Console.WriteLine("Configuration File contains invalid keycodes"); return 3; } if(!Validations.ensure_critical_values(keyboard)) { Console.WriteLine("Configuration file is missing critical elements"); return 4; } if(!Validations.confirm_microprocessor(keyboard)) { Console.WriteLine("Specified partno(_verbose) is not valid"); return 5; } //register helpers Handlebars.RegisterHelper("keymap_user_friendly", (writer, context, parameters) => { writer.Write(matrix_helpers.user_friendly(keyboard)); }); Handlebars.RegisterHelper("keymap_with_kc_no", (writer, context, parameters) => { writer.Write(matrix_helpers.with_kc_no(keyboard)); }); Handlebars.RegisterHelper("keymap", (writer, context, parameters) => { writer.Write(matrix_helpers.keymap(keyboard)); }); Handlebars.RegisterHelper("macros", (writer, context, parameters) => { writer.Write(macro_helpers.macros(keyboard)); }); try { string rootDirectory = System.IO.Path.GetDirectoryName(assembly.Location); string directoryStructureJson = Self.getFileContents(assembly, System.IO.Path.Combine( "QMKStructures", "templates", "default_qmk_structure.json")); QMKStructure qs = JsonConvert.DeserializeObject<QMKStructure>(directoryStructureJson); qs.testTemplates(assembly, keyboard); qs.generateDirectories(assembly, keyboard); qs.generateFiles(assembly, keyboard); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine("The format of the provided file is invalid"); return 6; } if(!Validations.is_valid_filename(keyboard.desc.product_name)) { Console.WriteLine("The product name of your keyboard is not a valid filename"); return 7; } string qmk_firmware_path = System.IO.Path.Combine( new DirectoryInfo(System.IO.Path.GetDirectoryName(assembly.Location)).FullName, "qmk_firmware" ); string exec_args = "/bin/bash -lic 'cd \"$(cygpath \"" + qmk_firmware_path + "\")\"; make " + keyboard.desc.product_name + ":default:avrdude'"; //string mintty_path = @"C:/msys64/usr/bin/mintty.exe"; string mingw64_path = @"C:/msys64/mingw64.exe"; //open up the flashing utility try { Exec.launch(mingw64_path, exec_args); } catch(Exception e) { Console.WriteLine("Error launching " + mingw64_path); Console.WriteLine("Error Message:" + e.Message); return 8; } return 0; }
static void Main(string[] args) { var conf = "conf/ffcm_c.properties"; if (args.Length > 0) { conf = args[0]; } var cfg = new FCfg(); cfg.Load(conf, true); cfg.Print(); var addr = cfg.Val("srv_addr", ""); if (addr.Length < 1) { Console.WriteLine("the srv_addr is not setted"); Environment.Exit(1); return; } L.I("starting ffcm..."); //Samba. var lambah = new LambdaEvnH(); var ffcm = new DocCov("FFCM", cfg, new SckDailer(addr).Dail, lambah); var ffcmh = new FFCM(ffcm, ffcm.Srv); ffcm.InitConfig(); ffcm.StartMonitor(); ffcm.StartWindowCloser(); ffcm.Start(); ffcm.StartProcSrv(); var activated = false; if (cfg.Val("samba", "N") == "Y") { L.I("start initial samba..."); var samba = Samba.AddVolume2(cfg.Val("samba_vol", ""), cfg.Val("samba_uri", ""), cfg.Val("samba_user", ""), cfg.Val("samba_pwd", ""), cfg.Val("samba_paths", "")); samba.Fail = (s, e) => { ffcm.ChangeStatus(DTM_C.DCS_UNACTIVATED); activated = false; }; samba.Success = (s) => { if (!activated) { ffcm.ChangeStatus(DTM_C.DCS_ACTIVATED); activated = true; } }; new Thread(run_samba).Start(); } else { activated = true; } lambah.OnLogin = (nr, token) => { if (activated) { ffcm.ChangeStatus(DTM_C.DCS_ACTIVATED); } }; lambah.EndCon = (nr) => { ffcm.ChangeStatus(DTM_C.DCS_UNACTIVATED); }; var reboot = cfg.Val("reboot", ""); if (reboot.Length > 0) { ProcKiller.Shared.OnHavingNotKill = (c) => { string output; Exec.exec(out output, reboot); }; } new Thread(run_hb).Start(ffcm); ffcm.Wait(); }
public PARSEINT(G.List <Exp> args, Exec e) : base(args, DataType.Bigint, new DataType[] { DataType.String }, e) { }
// $ANTLR end "increment" // $ANTLR start "exec" // D:\\Documents\\Visual Studio 2010\\Projects\\Installer\\Installer\\Model\\DAL\\SourceEval.g:86:1: exec returns [Exec exec] : ( ^( EXEC i1= ID ) | ^( EXEC i1= ID RCON ) ); public Exec exec() // throws RecognitionException [1] { Exec exec = default(Exec); CommonTree i1 = null; string id1 = null; bool rcon=false; try { // D:\\Documents\\Visual Studio 2010\\Projects\\Installer\\Installer\\Model\\DAL\\SourceEval.g:89:2: ( ^( EXEC i1= ID ) | ^( EXEC i1= ID RCON ) ) int alt10 = 2; int LA10_0 = input.LA(1); if ( (LA10_0 == EXEC) ) { int LA10_1 = input.LA(2); if ( (LA10_1 == DOWN) ) { int LA10_2 = input.LA(3); if ( (LA10_2 == ID) ) { int LA10_3 = input.LA(4); if ( (LA10_3 == UP) ) { alt10 = 1; } else if ( (LA10_3 == RCON) ) { alt10 = 2; } else { NoViableAltException nvae_d10s3 = new NoViableAltException("", 10, 3, input); throw nvae_d10s3; } } else { NoViableAltException nvae_d10s2 = new NoViableAltException("", 10, 2, input); throw nvae_d10s2; } } else { NoViableAltException nvae_d10s1 = new NoViableAltException("", 10, 1, input); throw nvae_d10s1; } } else { NoViableAltException nvae_d10s0 = new NoViableAltException("", 10, 0, input); throw nvae_d10s0; } switch (alt10) { case 1 : // D:\\Documents\\Visual Studio 2010\\Projects\\Installer\\Installer\\Model\\DAL\\SourceEval.g:89:4: ^( EXEC i1= ID ) { Match(input,EXEC,FOLLOW_EXEC_in_exec458); Match(input, Token.DOWN, null); i1=(CommonTree)Match(input,ID,FOLLOW_ID_in_exec462); Match(input, Token.UP, null); id1=((i1 != null) ? i1.Text : null); } break; case 2 : // D:\\Documents\\Visual Studio 2010\\Projects\\Installer\\Installer\\Model\\DAL\\SourceEval.g:90:4: ^( EXEC i1= ID RCON ) { Match(input,EXEC,FOLLOW_EXEC_in_exec471); Match(input, Token.DOWN, null); i1=(CommonTree)Match(input,ID,FOLLOW_ID_in_exec475); Match(input,RCON,FOLLOW_RCON_in_exec477); Match(input, Token.UP, null); id1=((i1 != null) ? i1.Text : null); rcon=true; } break; } exec = new Exec(id1, StatementType.Exec, currentMetaData, rcon); } catch (RecognitionException re) { ReportError(re); Recover(input,re); } finally { } return exec; }
public PARSEDECIMAL(G.List <Exp> args, Exec e) : base(args, DataType.ScaledInt, new DataType[] { DataType.String, DataType.Bigint }, e) { }
public PARSEDOUBLE(G.List <Exp> args, Exec e) : base(args, DataType.Double, new DataType[] { DataType.String }, e) { }
public ARG(G.List <Exp> args, Exec e) : base(args, DataType.String, new DataType[] { DataType.Bigint, DataType.String }, e) { }
internal static stmt Convert(Statement stmt) { stmt ast; if (stmt is FunctionDefinition) ast = new FunctionDef((FunctionDefinition)stmt); else if (stmt is ReturnStatement) ast = new Return((ReturnStatement)stmt); else if (stmt is AssignmentStatement) ast = new Assign((AssignmentStatement)stmt); else if (stmt is AugmentedAssignStatement) ast = new AugAssign((AugmentedAssignStatement)stmt); else if (stmt is DelStatement) ast = new Delete((DelStatement)stmt); else if (stmt is PrintStatement) ast = new Print((PrintStatement)stmt); else if (stmt is ExpressionStatement) ast = new Expr((ExpressionStatement)stmt); else if (stmt is ForStatement) ast = new For((ForStatement)stmt); else if (stmt is WhileStatement) ast = new While((WhileStatement)stmt); else if (stmt is IfStatement) ast = new If((IfStatement)stmt); else if (stmt is WithStatement) ast = new With((WithStatement)stmt); else if (stmt is RaiseStatement) ast = new Raise((RaiseStatement)stmt); else if (stmt is TryStatement) ast = Convert((TryStatement)stmt); else if (stmt is AssertStatement) ast = new Assert((AssertStatement)stmt); else if (stmt is ImportStatement) ast = new Import((ImportStatement)stmt); else if (stmt is FromImportStatement) ast = new ImportFrom((FromImportStatement)stmt); else if (stmt is ExecStatement) ast = new Exec((ExecStatement)stmt); else if (stmt is GlobalStatement) ast = new Global((GlobalStatement)stmt); else if (stmt is ClassDefinition) ast = new ClassDef((ClassDefinition)stmt); else if (stmt is BreakStatement) ast = new Break(); else if (stmt is ContinueStatement) ast = new Continue(); else if (stmt is EmptyStatement) ast = new Pass(); else throw new ArgumentTypeException("Unexpected statement type: " + stmt.GetType()); ast.GetSourceLocation(stmt); return ast; }
public static string GetSymbolicRef(string revision) => Exec.Run("git", "symbolic-ref", revision).FirstOrDefault()?.Replace( "refs/heads/", string.Empty);