/// <summary> /// AppMonitorLoader Main Method for STi consumption, direct-application-launching version /// </summary> /// <param name="commandline">Arguments to AppMonitor loader, either a config file or original format</param> public static void RunApplication(string commandline) { ProcessStartInfo pInfo = ProcessArgs(commandline); DictionaryStore.StartServer(); ApplicationMonitor appMon = new ApplicationMonitor(); // if we're launching a ClickOnce application, clean the cache // Since this method precludes remote deployment and our enlistment should build properly signed manifests, there's no need to update / resign the manifests. if (pInfo.FileName.ToLowerInvariant().EndsWith(ApplicationDeploymentHelper.STANDALONE_APPLICATION_EXTENSION) || pInfo.FileName.ToLowerInvariant().EndsWith(ApplicationDeploymentHelper.BROWSER_APPLICATION_EXTENSION)) { ApplicationDeploymentHelper.CleanClickOnceCache(); } // shell exec the app appMon.StartProcess(pInfo); // Some Xbap tests exit early unless we add PresentationHost.exe as a monitored process. Has to happen after StartProcess. // Timing is not an issue, since this is simply adding a string to a List, so will execute orders of magnitude faster than actually starting any Xbap. if (pInfo.FileName.ToLowerInvariant().EndsWith(ApplicationDeploymentHelper.BROWSER_APPLICATION_EXTENSION)) { appMon.MonitorProcess("PresentationHost.exe"); } appMon.WaitForUIHandlerAbort(); CloseCurrentVariationIfOneExists(); appMon.Close(); }
public void StartRecordEffectCompile(DictionaryStore <EffectCompileRequest, bool> requestStore) { lock (effectCompileRecordLock) { if (this.recordedEffectCompile != null) { throw new InvalidOperationException("Effect compile requests were already being recorded."); } this.recordedEffectCompile = requestStore; } }
/// <summary> /// AppMonitorLoader Main Method for STi consumption, configuration File version /// </summary> /// <param name="filename">File name of application monitor config file</param> public static void RunConfigurationFile(string filename) { DictionaryStore.StartServer(); // ApplicationMonitorConfig config = new ApplicationMonitorConfig(filename); config.RunSteps(); CloseCurrentVariationIfOneExists(); }
//internal static void Run() //{ // string s; // while (!string.IsNullOrEmpty(s = Console.ReadLine())) // { // if (_store.EntriesByReading.TryGetValue(s, out var entries)) // { // foreach (var entry in entries) // { // Console.WriteLine($"Id: {entry.Id}"); // Console.WriteLine($"Readings: {string.Join(", ", entry.Readings)}"); // Console.WriteLine("Glosses:"); // foreach (var gloss in entry.Glosses) // Console.WriteLine($" {gloss}"); // Console.WriteLine(); // } // } // else // { // Console.WriteLine($"Could not find '{s}'."); // } // } //} //internal static bool TryLookupKanji(string term, [NotNullWhen(true)] out List<DictionaryEntry>? entry) //{ // return _store.EntriesByKanji.TryGetValue(term, out entry); //} //internal static bool TryLookupReading(string term, [NotNullWhen(true)] out List<DictionaryEntry>? entry) //{ // return _store.EntriesByReading.TryGetValue(term, out entry); //} private static DictionaryStore LoadStore() { var stopwatch = new Stopwatch(); Console.WriteLine("Loading JMdict..."); stopwatch.Start(); var store = DictionaryStore.Load(@"C:\Data\OneDrive\Study & Practice\Japanese\JMdict\JMdict_e.xml"); stopwatch.Stop(); Console.WriteLine($"Loaded JMdict in {stopwatch.Elapsed}."); Console.WriteLine($"Loaded {store.EntriesByReading.Count} unique readings"); return(store); }
/// <summary> /// Start Host /// </summary> /// <param name="startupUri"></param> public void StartHost(string startupUri) { if (monitor != null) { throw new InvalidOperationException("You must first Close the Host before calling StartHost again."); } DictionaryStore.StartServer(); //use a custom startup page if (!string.IsNullOrEmpty(startupUri)) { DictionaryStore.Current[UiaDistributedTestcaseHost.StartupUriId] = startupUri; } monitor = new ApplicationMonitor(); GetHwndUIHandler handler = new GetHwndUIHandler(); // register for iexplore and have your app set the title monitor.RegisterUIHandler(handler, "iexplore", "RegExp:(Ready)", UIHandlerNotification.TitleChanged); //Clear the Click Once cache so the app is always re-activated ApplicationDeploymentHelper.CleanClickOnceCache(); //run the app monitor.StartProcess(xbapFileName); //wait for the UIHandler to return abort or timeout in 90 seconds if (!monitor.WaitForUIHandlerAbort(90000) || handler.topLevelhWnd == IntPtr.Zero) { throw new TimeoutException("A timeout occured while waiting for the XamlBrowserHost to navigate to the startUpPage"); } // monitor.StopMonitoring(); //Get the remoteHost object // //if we timedout then let the caller know that the app is not hosting this object //if (remoteHost == null) // throw new InvalidOperationException("The launched application did not create a host object in the Harness remote site"); //set the host hwnd hWndHost = handler.topLevelhWnd; }
public void DictionarySimple() { using (var tempFile = new TemporaryFile()) using (var store1 = new DictionaryStore<int, int>(VirtualFileSystem.OpenStream(tempFile.Path, VirtualFileMode.OpenOrCreate, VirtualFileAccess.ReadWrite, VirtualFileShare.ReadWrite))) using (var store2 = new DictionaryStore<int, int>(VirtualFileSystem.OpenStream(tempFile.Path, VirtualFileMode.OpenOrCreate, VirtualFileAccess.ReadWrite, VirtualFileShare.ReadWrite))) { store1.UseTransaction = true; // Check successive sets store1[1] = 1; Assert.That(store1[1], Is.EqualTo(1)); store1[1] = 2; Assert.That(store1[1], Is.EqualTo(2)); // Check saving (before and after completion) store1.Save(); Assert.That(store1[1], Is.EqualTo(2)); Assert.That(store1[1], Is.EqualTo(2)); // Check set after save store1[1] = 3; Assert.That(store1[1], Is.EqualTo(3)); // Check loading from another store store2.LoadNewValues(); Assert.That(store2[1], Is.EqualTo(2)); // Concurrent changes store1[1] = 5; store2[1] = 6; // Write should be scheduled for save immediately since dictionaryStore2 doesn't use transaction store2[2] = 6; // Check intermediate state (should get new value for 2, but keep intermediate non-saved value for 1) store1.LoadNewValues(); Assert.That(store1[1], Is.EqualTo(5)); Assert.That(store1[2], Is.EqualTo(6)); // Check after save/reload, both stores should be synchronized store1.Save(); store2.LoadNewValues(); Assert.That(store1[1], Is.EqualTo(store2[1])); Assert.That(store1[2], Is.EqualTo(store2[2])); } }
public void DictionarySimple() { using (var tempFile = new TemporaryFile()) using (var store1 = new DictionaryStore <int, int>(VirtualFileSystem.OpenStream(tempFile.Path, VirtualFileMode.OpenOrCreate, VirtualFileAccess.ReadWrite, VirtualFileShare.ReadWrite))) using (var store2 = new DictionaryStore <int, int>(VirtualFileSystem.OpenStream(tempFile.Path, VirtualFileMode.OpenOrCreate, VirtualFileAccess.ReadWrite, VirtualFileShare.ReadWrite))) { store1.UseTransaction = true; // Check successive sets store1[1] = 1; Assert.That(store1[1], Is.EqualTo(1)); store1[1] = 2; Assert.That(store1[1], Is.EqualTo(2)); // Check saving (before and after completion) store1.Save(); Assert.That(store1[1], Is.EqualTo(2)); Assert.That(store1[1], Is.EqualTo(2)); // Check set after save store1[1] = 3; Assert.That(store1[1], Is.EqualTo(3)); // Check loading from another store store2.LoadNewValues(); Assert.That(store2[1], Is.EqualTo(2)); // Concurrent changes store1[1] = 5; store2[1] = 6; // Write should be scheduled for save immediately since dictionaryStore2 doesn't use transaction store2[2] = 6; // Check intermediate state (should get new value for 2, but keep intermediate non-saved value for 1) store1.LoadNewValues(); Assert.That(store1[1], Is.EqualTo(5)); Assert.That(store1[2], Is.EqualTo(6)); // Check after save/reload, both stores should be synchronized store1.Save(); store2.LoadNewValues(); Assert.That(store1[1], Is.EqualTo(store2[1])); Assert.That(store1[2], Is.EqualTo(store2[2])); } }
public void StopRecordEffectCompile() { DictionaryStore <EffectCompileRequest, bool> effectCompileLog; lock (effectCompileRecordLock) { if (recordedEffectCompile == null) { throw new InvalidOperationException("Effect compile requests were not being recorded."); } effectCompileLog = recordedEffectCompile; recordedEffectCompile = null; } effectCompileLog.Dispose(); }
public MainWindow() { InitializeComponent(); this.Closing += this.handleClose; this.dataDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); this.dataDir = System.IO.Path.Combine(this.dataDir, "XPCalc"); this.elBox = new SpinBox(); this.elBox.Value = 1; this.elBox.Minimum = 1; this.elBox.ValueChanged += this.calculateSimpleXp; Grid.SetRow(this.elBox, 0); Grid.SetColumn(this.elBox, 1); simpleGrid.Children.Add(this.elBox); this.partyLevelBox = new SpinBox(); this.partyLevelBox.Value = 1; this.partyLevelBox.Minimum = 1; this.partyLevelBox.ValueChanged += this.calculateSimpleXp; Grid.SetRow(this.partyLevelBox, 0); Grid.SetColumn(this.partyLevelBox, 3); simpleGrid.Children.Add(this.partyLevelBox); this.partySizeBox = new SpinBox(); this.partySizeBox.Value = 4; this.partySizeBox.Minimum = 1; this.partySizeBox.ValueChanged += this.calculateSimpleXp; Grid.SetRow(this.partySizeBox, 0); Grid.SetColumn(this.partySizeBox, 5); simpleGrid.Children.Add(this.partySizeBox); this.calculateSimpleXp(null, null); this.opponentList.Items.SortDescriptions.Add(new SortDescription("name", ListSortDirection.Ascending)); this.partyList.Items.SortDescriptions.Add(new SortDescription("name", ListSortDirection.Ascending)); //... this.partyXpBox = new SpinBox(); this.partyXpBox.Value = 0; Grid.SetRow(this.partyXpBox, 1); Grid.SetColumn(this.partyXpBox, 1); Grid.SetColumnSpan(this.partyXpBox, 3); xpGrid.Children.Add(this.partyXpBox); System.IO.Directory.CreateDirectory(this.dataDir); this.preferences = new DictionaryStore <string, string>(System.IO.Path.Combine(this.dataDir, "prefs.cfg")); this.opponents = new DictionaryStore <string, int>(System.IO.Path.Combine(this.dataDir, "opponents.db")); if (this.preferences.ContainsKey("partyFile")) { this.doPartyLoad(); } }
private void doPartySave() { if (!this.preferences.ContainsKey("partyFile")) { return; } DictionaryStore <String, Dictionary <String, int> > partyDict = new DictionaryStore <String, Dictionary <String, int> >(this.preferences["partyFile"]); foreach (CharacterRow c in this.partyList.Items) { Dictionary <String, int> character = new Dictionary <string, int>(); character["present"] = (c.present ? 1 : 0); character["level"] = c.level; character["xp"] = c.unspentXp; partyDict[c.name] = character; } partyDict.save(); this.partyChanged = false; }
public OpponentWindow(DictionaryStore <string, int> opponents) { InitializeComponent(); this.opponents = opponents; foreach (String name in opponents.Keys.OrderBy(k => k)) { nameBox.Items.Add(name); } this.crBox = new SpinBox(); this.crBox.Value = 1; this.crBox.Minimum = 1; Grid.SetRow(this.crBox, 1); Grid.SetColumn(this.crBox, 1); opponentGrid.Children.Add(this.crBox); this.countBox = new SpinBox(); this.countBox.Value = 1; this.countBox.Minimum = 1; Grid.SetRow(this.countBox, 2); Grid.SetColumn(this.countBox, 1); opponentGrid.Children.Add(this.countBox); }
private void doPartyLoad() { if (!this.preferences.ContainsKey("partyFile")) { return; } DictionaryStore <String, Dictionary <String, int> > partyDict = new DictionaryStore <String, Dictionary <String, int> >(this.preferences["partyFile"]); this.partyList.Items.Clear(); foreach (String name in partyDict.Keys) { CharacterRow c = new CharacterRow { present = (partyDict[name]["present"] != 0), name = name, level = partyDict[name]["level"], totalXp = partyDict[name]["level"] * (partyDict[name]["level"] - 1) * 500 + partyDict[name]["xp"], unspentXp = partyDict[name]["xp"] }; this.partyList.Items.Add(c); } this.partyList.Items.Refresh(); this.partyChanged = false; }
/// <summary> /// Records the effect compilation request to the specified file. /// </summary> /// <param name="filePath">The file path.</param> /// <param name="reset">if set to <c>true</c> erase the previous file, otherwise append.</param> public void StartRecordEffectCompile(string filePath, bool reset) { try { if (reset && File.Exists(filePath)) { File.Delete(filePath); } } catch (IOException) { } var fileStream = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite); var effectCompileLog = new DictionaryStore <EffectCompileRequest, bool>(fileStream); if (!reset) { effectCompileLog.LoadNewValues(); } StartRecordEffectCompile(effectCompileLog); }
static void Main(string[] args) { DictionaryStore dictionaryStore = new DictionaryStore(); dictionaryStore.numbers.Add("one", 1); dictionaryStore.numbers.Add("two", 2); dictionaryStore.numbers.Add("three", 3); dictionaryStore.numbers.Add("four", 4); dictionaryStore.numbers.Add("five", 5); dictionaryStore.numbers.Add("six", 6); dictionaryStore.numbers.Add("seven", 7); dictionaryStore.numbers.Add("eight", 8); dictionaryStore.numbers.Add("nine", 9); dictionaryStore.numbers.Add("ten", 10); dictionaryStore.isNice.Add(1.337f, true); dictionaryStore.isNice.Add(1.2374f, false); dictionaryStore.isNice.Add(2.437f, false); dictionaryStore.isNice.Add(0.69f, true); dictionaryStore.isNice.Add(1.234f, false); dictionaryStore.isNice.Add(4.20f, true); dictionaryStore.isNice.Add(420.69f, true); dictionaryStore.isNice.Add(0.001f, false); dictionaryStore.isNice.Add(10.10f, false); dictionaryStore.isNice.Add(80.085f, true); dictionaryStore.nicknames.Add(new Person("Jesper Jespersen", 21), "Jepper"); dictionaryStore.nicknames.Add(new Person("Lasse Slumstrup", 18), "Slumme"); dictionaryStore.nicknames.Add(new Person("Jakob Thuesen", 18), "Thue"); while (true) { Console.WriteLine("Chose dictionary to look in:"); Console.WriteLine("1) numbers"); Console.WriteLine("2) isNice"); char choiceChar = Console.ReadKey().KeyChar; int choice; Console.Clear(); choice = char.IsDigit(choiceChar) ? int.Parse(choiceChar.ToString()) : 0; switch (choice) { case 1: Console.WriteLine("Enter a number in word form between 'one' and 'ten'"); string numberToCheck = Console.ReadLine().ToLower(); dictionaryStore.numbers.TryGetValue(numberToCheck, out int intReturn); Console.WriteLine(intReturn); break; case 2: Console.WriteLine("Enter a float, so we can check our database to see if the number is cool or not."); float.TryParse(Console.ReadLine(), out float floatToCheck); dictionaryStore.isNice.TryGetValue(floatToCheck, out bool isNice); Console.WriteLine(isNice ? "That number is VERY nice" : "Not nice bro"); break; default: Console.WriteLine("Please choose a dictionary next time"); break; } Thread.Sleep(2000); Console.Clear(); } }
public static BuildResultCode BuildSlave(BuilderOptions options) { // Mount build path ((FileSystemProvider)VirtualFileSystem.ApplicationData).ChangeBasePath(options.BuildDirectory); PrepareDatabases(options); try { VirtualFileSystem.CreateDirectory("/data/"); VirtualFileSystem.CreateDirectory("/data/db/"); } catch (Exception) { throw new OptionException("Invalid Build database path", "database"); } // Open WCF channel with master builder var namedPipeBinding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None) { SendTimeout = TimeSpan.FromSeconds(300.0) }; var processBuilderRemote = ChannelFactory <IProcessBuilderRemote> .CreateChannel(namedPipeBinding, new EndpointAddress(options.SlavePipe)); try { RegisterRemoteLogger(processBuilderRemote); // Create scheduler var scheduler = new Scheduler(); var status = ResultStatus.NotProcessed; // Schedule command string buildPath = options.BuildDirectory; Logger logger = options.Logger; MicroThread microthread = scheduler.Add(async() => { // Deserialize command and parameters Command command = processBuilderRemote.GetCommandToExecute(); BuildParameterCollection parameters = processBuilderRemote.GetBuildParameters(); // Run command var inputHashes = new DictionaryStore <InputVersionKey, ObjectId>(VirtualFileSystem.OpenStream("/data/db/InputHashes", VirtualFileMode.OpenOrCreate, VirtualFileAccess.ReadWrite, VirtualFileShare.ReadWrite)); var builderContext = new BuilderContext(buildPath, inputHashes, parameters, 0, null); var commandContext = new RemoteCommandContext(processBuilderRemote, command, builderContext, logger); command.PreCommand(commandContext); status = await command.DoCommand(commandContext); command.PostCommand(commandContext, status); // Returns result to master builder processBuilderRemote.RegisterResult(commandContext.ResultEntry); }); while (true) { scheduler.Run(); // Exit loop if no more micro threads lock (scheduler.MicroThreads) { if (!scheduler.MicroThreads.Any()) { break; } } Thread.Sleep(0); } // Rethrow any exception that happened in microthread if (microthread.Exception != null) { options.Logger.Fatal(microthread.Exception.ToString()); return(BuildResultCode.BuildError); } if (status == ResultStatus.Successful || status == ResultStatus.NotTriggeredWasSuccessful) { return(BuildResultCode.Successful); } return(BuildResultCode.BuildError); } finally { // Close WCF channel // ReSharper disable SuspiciousTypeConversion.Global ((IClientChannel)processBuilderRemote).Close(); // ReSharper restore SuspiciousTypeConversion.Global } }
public static BuildResultCode BuildSlave(BuilderOptions options) { // Mount build path ((FileSystemProvider)VirtualFileSystem.ApplicationData).ChangeBasePath(options.BuildDirectory); PrepareDatabases(options); try { VirtualFileSystem.CreateDirectory("/data/"); VirtualFileSystem.CreateDirectory("/data/db/"); } catch (Exception) { throw new OptionException("Invalid Build database path", "database"); } // Open WCF channel with master builder var namedPipeBinding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None) { SendTimeout = TimeSpan.FromSeconds(300.0) }; var processBuilderRemote = ChannelFactory<IProcessBuilderRemote>.CreateChannel(namedPipeBinding, new EndpointAddress(options.SlavePipe)); try { RegisterRemoteLogger(processBuilderRemote); // Create scheduler var scheduler = new Scheduler(); var status = ResultStatus.NotProcessed; // Schedule command string buildPath = options.BuildDirectory; Logger logger = options.Logger; MicroThread microthread = scheduler.Add(async () => { // Deserialize command and parameters Command command = processBuilderRemote.GetCommandToExecute(); BuildParameterCollection parameters = processBuilderRemote.GetBuildParameters(); // Run command var inputHashes = new DictionaryStore<InputVersionKey, ObjectId>(VirtualFileSystem.OpenStream("/data/db/InputHashes", VirtualFileMode.OpenOrCreate, VirtualFileAccess.ReadWrite, VirtualFileShare.ReadWrite)); var builderContext = new BuilderContext(buildPath, inputHashes, parameters, 0, null); var commandContext = new RemoteCommandContext(processBuilderRemote, command, builderContext, logger); command.PreCommand(commandContext); status = await command.DoCommand(commandContext); command.PostCommand(commandContext, status); // Returns result to master builder processBuilderRemote.RegisterResult(commandContext.ResultEntry); }); while (true) { scheduler.Run(); // Exit loop if no more micro threads lock (scheduler.MicroThreads) { if (!scheduler.MicroThreads.Any()) break; } Thread.Sleep(0); } // Rethrow any exception that happened in microthread if (microthread.Exception != null) { options.Logger.Fatal(microthread.Exception.ToString()); return BuildResultCode.BuildError; } if (status == ResultStatus.Successful || status == ResultStatus.NotTriggeredWasSuccessful) return BuildResultCode.Successful; return BuildResultCode.BuildError; } finally { // Close WCF channel // ReSharper disable SuspiciousTypeConversion.Global ((IClientChannel)processBuilderRemote).Close(); // ReSharper restore SuspiciousTypeConversion.Global } }
public GameMode() { VisualElements = new DictionaryStore <IVisualElement>(); }