public void GivenIHaveRestrictedTheThreadCountTo(int count) { this.testContext.Boilerplate = Boilerplate.New(visibility: Visibility.Debug) .BeginContract() .Restrict.Threads.ToMaxOf(count) .EndContract(); }
private static void Go() { IIdentity identity; IBoilerplateContext boilerplate; identity = null; boilerplate = Boilerplate.New(identity); boilerplate .BeginContract() .Handles <ArgumentException>(ex => System.Diagnostics.Debug.WriteLine("Caught ArgumentException")) .Handles <Exception>(ex => System.Diagnostics.Debug.WriteLine("Caught Exception")) .EndContract() .Do(context => { throw new Exception(); }); }
private void chkFileGroup_CheckedChanged(object sender, EventArgs e) { //skip extension validation for boilerplate, in case the extension is something like CSS (which doesn't have bp, but HTML does) //this may need to be expanded on if groups are added that have no boilerplate for any extension if (FileGroup.HasFileGroup(cboExtensions.Text) && chkFileGroup.Checked == true) { ToggleBoilerPlate(true); } //else, re-validate extension else { ToggleBoilerPlate(Boilerplate.HasBoilerplate(cboExtensions.Text)); } //change text for button + checkbox btnGenerate.Text = chkFileGroup.Checked ? "&Create Files" : "&Create File"; chkOpenFiles.Text = chkFileGroup.Checked ? "&Open Files When Complete" : "&Open File When Complete"; }
public void WhenICreateTheBoilerplate() { this.testContext.Boilerplate = Boilerplate.New(this.testContext.Identity, this.testContext.Access); }
private void MakeFiles(List <string> extensionList = null) { //function will run once per item in file group (or just once if there is no group) string extension = extensionList == null?cboExtensions.Text.Trim() : extensionList[0]; string filePath = txtFilePath.Text.Trim(); string fileName = txtFileName.Text.Trim(); try { //create file string path = $"{filePath}/{fileName}.{extension}"; if (File.Exists(path)) { if (MessageBox.Show($"{fileName}.{extension} already exists in this directory. Would you like to replace it?", "Error", MessageBoxButtons.YesNo) == DialogResult.No) { return; } } FileStream fs = File.Create(path); //if boilerplate is checked and valid, generate it and add to file if (chkBoilerplate.Checked && Boilerplate.HasBoilerplate(extension)) { string bp = Boilerplate.CreateBoilerplate(extension, fileName, chkFileGroup.Checked); UTF8Encoding encoding = new UTF8Encoding(); fs.Write(encoding.GetBytes(bp), 0, encoding.GetByteCount(bp)); } fs.Close(); //attempt to open new file if needed if (chkOpenFiles.Checked) { try { Process.Start(path); } catch (Exception) { MessageBox.Show("Unable to open file. Check your selected directory to verify the file exists.", "Error"); } } AddMessage($"{fileName}.{extension} created in {filePath}"); //if file group, repeat function for next file. stop the process if the list is empty if (extensionList != null && extensionList.Count() > 1) { MakeFiles(extensionList.GetRange(1, extensionList.Count() - 1)); } } catch (Exception ex) { MessageBox.Show("Unable to create file. Verify file extension and path are valid.", "Error"); } }
//checks user input; enables boilerplate checkbox where supported private void cboExtensions_TextUpdate(object sender, EventArgs e) { ToggleBoilerPlate(Boilerplate.HasBoilerplate(cboExtensions.Text)); ToggleFileGroup(FileGroup.HasFileGroup(cboExtensions.Text)); }
public void Test() { var b = Boilerplate.New(); b .BeginContract() .Handles <ArgumentException>(ex => { }).WithRetryOf(3, 1000, BackoffStrategy.Exponential) .EndContract() .Do(_ => { throw new ArgumentException(); }); //IMethod method; //ILocalVariable first = method.DefineLocalVariable<int>(); //ILocalVariable second = method.DefineLocalVariable(typeof(int)); //var writtenMethod = // method.Body // .If(first.Equals(second)).Then // .AssignStackValue.To(first) // .Do(first.Call(KnownMetadata.Methods.Object_ToString, second)) // .AssignStackValue.To(second) // .End // .Else // .If(method.Parameter(1).Equals(first)).Then // .End // .NoElse // .End // .End; var boilerplate = Boilerplate.New(visibility: Visibility.Debug); object instance = "Hello"; //boilerplate.BeginContract().RequireValidInstanceOf(new Number { Text = "b" }).EndContract().Do(x => { }); //boilerplate.Use(instance).IfTypeIsAnyOf<int, string, long, object>().DoFirstMatched( // num => { }, // text => { }, // num2 => { }, // obj => { }); // NewMethod(boilerplate, instance); Atomic <object> atom = Atomic <object> .New(instance); Atomic <int> atomInt = Atomic <int> .New(5); boilerplate .BeginContract() //.Handles<Exception, int>(ex => { return 0; }) //.Restrict.Threads.ToMaxOf(1) //.Restrict.Threads.ToMaxOf(5) .Restrict.Threads.ByWaitingFor(new ManualResetEvent(false), 5000) //.Restrict.Threads.ByTransaction // .Of(atom) // .And(atomInt) // .OrderedBy.Default .EndContract() .Do(_ => { object obj = atom; int value = atomInt; atom.Value = obj; atomInt.Value = value; }); int variable = 5; var atomic = boilerplate.Use(variable).AsAtomic(); int o = atomic; var timings = boilerplate .BeginContract() .Handles <Exception>(ex => { }) .IsTimedUnder(Visibility.Debug) .EndContract() .Do(_ => Go()) .Do(_ => Go()) .CallTimings; foreach (var timing in timings) { Console.WriteLine(timing.TotalMilliseconds); } var verifier = new TranslationVerifier <From>(); var results = verifier.VerifyWithTargetOf <To>(); foreach (var result in results) { Debug.WriteLine(result); } var boilerplate2 = Boilerplate.New(visibility: Visibility.Debug); var timings2 = boilerplate2 .BeginContract() .IsTimedUnder(Visibility.Debug) .EndContract() .Do(_ => Go()) .Do(_ => Go()) .Do(_ => Go()) .CallTimings; foreach (var timing in timings) { Console.WriteLine(timing.TotalMilliseconds); } //var provider = new AdoNetConnectionProvider("FluentBoilerplate", DataSource.SQL); //var access = new TypeAccessProvider(provider); //var boilerplate = Boilerplate.New(accessProvider: access); //boilerplate.Open<IAdoNetConnection>().AndDo((_, connection) => // { // var parameter = connection.CreateParameter("count", 5); // var result = connection.ExecuteStoredProcedure("GetPeople", new Interpreter(), parameter); // foreach (var person in result) // Console.WriteLine(person.Name + " " + person.Description); // }); //var boilerplate = Boilerplate.New(accessProvider: new TypeAccessProvider(TypeAccessProvider.w)) //var me = Identity.CurrentWindowsUser; //var context = Boilerplate.New(me); //context.BeginContract() // .MustNotHaveRoles(ActiveDirectoryGroup.Administrators) // .EndContract() // .Do(c => // { // Console.WriteLine("Did not have admin role"); // }); //var stopwatch = new Stopwatch(); //stopwatch.Start(); //Go(); //stopwatch.Stop(); //Debug.WriteLine(stopwatch.ElapsedMilliseconds); //stopwatch.Reset(); //stopwatch.Start(); //Go(); //stopwatch.Stop(); //Debug.WriteLine(stopwatch.ElapsedMilliseconds); }