public ActionResult Submit(ProblemModel Problem, string ProblemID) { int pos, ContestID; bool isTwoChars = int.TryParse(ProblemID.Substring(ProblemID.Length - 1), out pos); int ID = Convert.ToInt16(Session["ID"]); if (isTwoChars) { ContestID = int.Parse(ProblemID.Substring(0, ProblemID.Length - 2)); } else { ContestID = int.Parse(ProblemID.Substring(0, ProblemID.Length - 1)); } Automate Judge = new Automate(); Judge.OpenCodeforces(Problem.ProblemCode, ProblemID); string SubmissionJson = Judge.SubmissionJsonFile("A4A_A4A", ContestID); Helpers.SubmissionHelper helper = new Helpers.SubmissionHelper(); int SubmissionID = helper.ParseSubmission(SubmissionJson, ID, Problem.ProblemContestID); return(RedirectToAction("ViewSubmission", new { SubmissionID = SubmissionID })); }
public Automate ReadFile(string nameFile) { Automate automate = new Automate(); StreamReader objReader = new StreamReader(nameFile); automate.name = objReader.ReadLine(); automate.priority = Int32.Parse(objReader.ReadLine()); automate.alphabet = objReader.ReadLine().Split(' ').Select(x => Char.Parse(x)).ToArray(); automate.setStates = objReader.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray(); automate.startStates = objReader.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray(); automate.finishStates = objReader.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray(); automate.Table = new Dictionary <int, List <int[]> >(); int[] transitions; for (int i = 0; i < automate.setStates.Length; i++) { List <int[]> list = new List <int[]>(); string[] masLine = objReader.ReadLine().Split('|'); foreach (string s in masLine) { transitions = s.Split(' ').Select(x => Int32.Parse(x)).ToArray(); list.Add(transitions); } automate.Table.Add(automate.setStates[i], list); } objReader.Close(); return(automate); }
public VinHC1A(byte[] key, int nodeCount = -1) { this.key = key; key[0] = (3 << 4) + (2 << 2) + 1; A = new Automate(key, nodeCount); }
public Automate(Automate a) { name = a.name; priority = a.priority; alphabet = a.alphabet; setStates = a.setStates; startStates = a.startStates; finishStates = a.finishStates; Table = a.Table; }
public RiverLinkLogic(string URL, int LWait, int SWait, IWebDriver chromeDriver) { driver = chromeDriver; BaseURL = URL; LongWait = LWait; ShortWait = SWait; var context = new RiverLink.DAL.DB(); List <VehicleClass> VehicleClasses = context.VehicleClasses.ToList(); List <Transponder> TransponderList = context.Transponders.ToList(); Worker = new Automate(driver, BaseURL, LongWait, ShortWait, VehicleClasses, TransponderList); Worker.OnPrimaryStatusChanged += Worker_OnPrimaryStatusChanged; Worker.OnSecondaryStatusChanged += Worker_OnSecondaryStatusChanged; Worker.OnErrorStatusChanged += Worker_OnErrorStatusChanged; }
public void Run(int hWndMain, Automate automate, KConnection connection, KConnection destination, Form parent) { do { int hWnd = Automate.WinWait("KCMLMasterForm_32", "Enter host details", Automate.WinMatchMode.Start, 5); int ret; if (hWnd == 0) { break; } uint procID = WinApi.GetWindowThreadProcessId(hWnd, 0); uint currThread = WinApi.GetCurrentThreadId(); bool lret = WinApi.AttachThreadInput(currThread, procID, true); WinApi.SetForegroundWindow(hWnd); ret = Automate.SetFocus(hWnd); int hCtrlHost = Automate.ControlGetHandle(hWnd, "KCMLEdit32", 1); ret = Automate.SetFocus(hCtrlHost); Automate.SendString(hCtrlHost, destination.Host); Thread.Sleep(500); int hCtrlUserID = Automate.ControlGetHandle(hWnd, "KCMLEdit32", 2); ret = Automate.SetFocus(hCtrlUserID); Automate.SendString(hCtrlUserID, destination.User); Thread.Sleep(500); int hCtrlPassword = Automate.ControlGetHandle(hWnd, "KCMLEdit32", 3); ret = Automate.SetFocus(hCtrlPassword); Automate.SendString(hCtrlPassword, destination.Password); Thread.Sleep(500); int hCtrlHome = Automate.ControlGetHandle(hWnd, "KCMLEdit32", 4); ret = Automate.SetFocus(hCtrlHome); Automate.SendString(hCtrlHome, destination.Home); Thread.Sleep(500); } while (false); }
public Result maxString(Automate automate, string str, int k) { HashSet <int> currentSet = new HashSet <int>(automate.startStates); Result result = new Result(false, 0, ""); if (automate.finishStates.Intersect(currentSet).Count() != 0) { result.res = true; } HashSet <int> temp; for (int i = k; i < str.Length; i++) { temp = new HashSet <int>(); if (automate.alphabet.Contains(str[i])) { int j = Array.IndexOf(automate.alphabet, str[i]); foreach (var currentState in currentSet) { foreach (var next in automate.Table[currentState][j]) { if (next == -1) { return(result); } temp.Add(next); } if (automate.finishStates.Intersect(temp).Count() != 0) { result.res = true; result.m = i - k + 1; result.number = str.Substring(k, result.m); } } currentSet = temp; } else { break; } } return(result); }
public void Start() { Automate automate = new Automate(); StreamReader objReader = new StreamReader(".\\input.txt"); automate.alphabet = objReader.ReadLine().Split(' ').Select(x => Char.Parse(x)).ToArray(); automate.setStates = objReader.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray(); automate.startStates = objReader.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray(); automate.finishStates = objReader.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray(); automate.Table = new Dictionary <int, List <int[]> >(); int[] transitions; for (int i = 0; i < automate.setStates.Length; i++) { List <int[]> list = new List <int[]>(); string[] masLine = objReader.ReadLine().Split('|'); foreach (string s in masLine) { transitions = s.Split(' ').Select(x => Int32.Parse(x)).ToArray(); list.Add(transitions); } automate.Table.Add(automate.setStates[i], list); } objReader.Close(); string str = "-2.5e-02+10asd-3dkf8.3-e-7"; int k = 0; Result result; for (int i = 0; i < str.Length; i++) { result = maxString(automate, str, k); if (result.res == true) { Console.WriteLine("Начиная с позиции " + k + ", автомат нашел число " + result.number); k += result.m; } else { k += 1; } } }
public void Run(int hWndMain, Automate automate, KConnection connection, KConnection destination, Form parent) { do { int hWnd = Automate.WinWait("KCMLMasterForm_32", "", Automate.WinMatchMode.Start, 5); if (hWnd == 0) { // If the main window did not become active check for a system info windows hWnd = Automate.WinWait("#32770", "System", Automate.WinMatchMode.Any, 3); if (hWnd != 0) { // System info window found, click on the button to close it int hSystemInfoButton = Automate.ControlGetHandle(hWnd, "Button", ""); if (hSystemInfoButton != 0) { Thread.Sleep(500); Automate.ControlClick(hSystemInfoButton); } else { WinApi.SetForegroundWindow(hWndMain); MessageBox.Show("System info button not found"); break; } } else { // System info window not found either, end process WinApi.SetForegroundWindow(hWndMain); MessageBox.Show("Main form not found"); break; } } Thread.Sleep(200); WinApi.SetForegroundWindow(hWnd); Thread.Sleep(500); automate.Send("^{BREAK}"); } while (false); }
public void AutomateMatchWorks(string candidate, bool expected) { //Automate pour le regex (ab)* NodeDFA s0 = new NodeDFA(true); NodeDFA s1 = new NodeDFA(false); NodeDFA s2 = new NodeDFA(false); NodeDFA s3 = new NodeDFA(false); s0.Add('a', s1); s0.Add('b', s3); s1.Add('a', s3); s1.Add('b', s2); s2.Add('a', s1); s2.Add('b', s3); s3.Add('a', s3); s3.Add('b', s3); Automate dfa = new Automate(s0); Assert.That(dfa.Match(candidate), Is.EqualTo(expected)); }
/// <summary> /// Créé un état /// </summary> /// <param name="automate">Automate qui possèdera cet état</param> public Etat(Automate automate) { this.automate = automate; }
public void Run(int hWndMain, Automate automate, KConnection connection, KConnection destination, Form parent) { do { int hWnd = Automate.WinWait("KCMLMasterForm_32", "", Automate.WinMatchMode.Start, 5); if (hWnd == 0) { break; } int hControlUtilities = Automate.ControlGetHandle(hWnd, "KCMLButton_32", "Utilities..."); if (hControlUtilities == 0) { Thread.Sleep(300); automate.Send("%(u)"); int hControlList = Automate.ControlGetHandle(hWnd, "ListBox_Class", ""); if (hControlList == 0) { break; } Thread.Sleep(200); automate.Send("c"); //Automate.SendChar(hControlList, 'c'); Thread.Sleep(200); int hControlOk = Automate.ControlGetHandle(hWnd, "KCMLButton_32", "OK"); if (hControlOk == 0) { break; } Thread.Sleep(200); Automate.ControlClick(hControlOk); } else { Automate.ControlClick(hControlUtilities); Thread.Sleep(200); int hWndUtilities = Automate.WinWait("KCMLMasterForm_32", "Select Item", Automate.WinMatchMode.Start, 5); if (hWndUtilities == 0) { break; } int hControlList = Automate.ControlGetHandle(hWndUtilities, "ListBox_Class", ""); if (hControlList == 0) { break; } Thread.Sleep(200); automate.Send("c"); //Automate.SendChar(hControlList, 'c'); Thread.Sleep(200); int hControlOk = Automate.ControlGetHandle(hWndUtilities, "KCMLButton_32", "OK"); if (hControlOk == 0) { break; } Thread.Sleep(200); Automate.ControlClick(hControlOk); } } while (false); }
public void Run(int hWndMain, Automate automate, KConnection connection, KConnection destination, Form parent) { string password; do { // Open the password form PasswordForm pf = new PasswordForm(); pf.StartPosition = FormStartPosition.CenterParent; if (pf.ShowDialog() == DialogResult.OK) { password = pf.textBoxPassword.Text; } else { break; } // Wait for main window to become active int hWnd = Automate.WinWait("KCMLMasterForm_32", "", Automate.WinMatchMode.Start, 3); if (hWnd == 0) { // If the main window did not become active check for a system info windows hWnd = Automate.WinWait("#32770", "System", Automate.WinMatchMode.Any, 3); if (hWnd != 0) { // System info window found, click on the button to close it int hSystemInfoButton = Automate.ControlGetHandle(hWnd, "Button", ""); if (hSystemInfoButton != 0) { automate.MediumDelay(); Automate.ControlClick(hSystemInfoButton); } else { WinApi.SetForegroundWindow(hWndMain); MessageBox.Show("System info button not found"); break; } } else { // System info window not found either, end process WinApi.SetForegroundWindow(hWndMain); MessageBox.Show("Main form not found"); break; } } WinApi.SetForegroundWindow(hWnd); automate.MediumDelay(); // At this point the Autoline library form should be displayed and we need to select "Kerridge mode" to break into code // Get the handle of the Kerridge mode button int hKerridgeModeButton = Automate.ControlGetHandle(hWnd, "KCMLButton_32", 5); if (hKerridgeModeButton == 0) { WinApi.SetForegroundWindow(hWndMain); MessageBox.Show("Kerridge mode button not found"); break; } automate.ShortDelay(); Automate.ControlClick(hKerridgeModeButton); // Enter the daily password got from the password form int hPasswordCtrl = Automate.ControlGetHandle(hWnd, "KCMLEdit32", 1); if (hPasswordCtrl == 0) { WinApi.SetForegroundWindow(hWndMain); MessageBox.Show("Password control not found"); break; } automate.ShortDelay(); automate.Send(password + "{ENTER}"); automate.MediumDelay(); automate.Send("{TAB}"); automate.MediumDelay(); automate.Send("CLEARP{ENTER}"); automate.MediumDelay(); automate.Send("LOAD \"GB/MKMOD\"{ENTER}"); // This if for loading the make modules program automate.MediumDelay(); automate.Send("TRAP 'ExecuteScript{ENTER}"); // This is to stop the execution right after the module build sript has been created and before it's executed automate.MediumDelay(); automate.Send("RUN{ENTER}"); automate.LongDelay(); // At this point the Make Modules form will be displayed, now we need to press the Build button // Wait for the next form hWnd = Automate.WinWait("KCMLMasterForm_32", "", Automate.WinMatchMode.Start, 5); if (hWnd == 0) { WinApi.SetForegroundWindow(hWndMain); MessageBox.Show("Build modules form not found"); break; } // Click on the button to build int hCtrlBuild = Automate.ControlGetHandle(hWnd, "KCMLButton_32", 2); if (hCtrlBuild == 0) { WinApi.SetForegroundWindow(hWndMain); MessageBox.Show("Build button not found"); break; } automate.MediumDelay(); Automate.ControlClick(hCtrlBuild); // The build modules process will start, now we need to wait for it to reach the trap // as this process can take very variable amounts of time to complete it requires it's own delay time automate.CustomDelay(); automate.Send("{TAB}"); automate.MediumDelay(); // Capture the module build script name by writing it into a known file name that we can get through FTP automate.Send( Automate.ConvertKeys("stream = OPEN $PRINTF(\"%s/%s\", ENV(\"WORKSPACE\"), \"ScriptFileName.txt\"), \"w\"") + "{ENTER}"); automate.Send( Automate.ConvertKeys("pointer = WRITE #stream, ScriptName$") + "{ENTER}"); // Get the file through FTP // Get the object used to communicate with the server. FtpWebRequest requestFile = (FtpWebRequest)WebRequest.Create( //"ftp://" + connection.Host + "/%2f" + connection.Home.Substring(1).Replace("home", "work") + "/ScriptFileName.txt"); "ftp://" + connection.Host + "/%2f" + ReplaceLastOccurrence(connection.Home.Substring(1), "home", "work") + "/ScriptFileName.txt"); requestFile.Method = WebRequestMethods.Ftp.DownloadFile; // This example assumes the FTP site uses anonymous logon. requestFile.Credentials = new NetworkCredential(connection.User, connection.Password); FtpWebResponse responseFile = (FtpWebResponse)requestFile.GetResponse(); // Get the file from the response Stream responseStreamFile = responseFile.GetResponseStream(); StreamReader readerFile = new StreamReader(responseStreamFile); string line = readerFile.ReadLine(); if (line != null) { string test = line.Substring(1); StringCollection result2 = new StringCollection(); FtpWebRequest requestFile2 = (FtpWebRequest)WebRequest.Create("ftp://" + connection.Host + "/%2f" + line.Substring(1)); requestFile2.Method = WebRequestMethods.Ftp.DownloadFile; // This example assumes the FTP site uses anonymous logon. requestFile2.Credentials = new NetworkCredential(connection.User, connection.Password); FtpWebResponse responseFile2 = (FtpWebResponse)requestFile2.GetResponse(); Stream responseStreamFile2 = responseFile2.GetResponseStream(); StreamReader readerFile2 = new StreamReader(responseStreamFile2); line = readerFile2.ReadLine(); while (line != null) { result2.Add(line); line = readerFile2.ReadLine(); } readerFile2.Close(); int firstIndex = result2.IndexOf("CLEAR P"); int lastIndex = 0; foreach (string s in result2) { if (s.Contains("SAVE <G>")) { lastIndex = result2.IndexOf(s); } } for (int index = firstIndex; index <= lastIndex; index++) { string lineCommand = result2[index]; // We now have each command ready to send to the console automate.Send(lineCommand + "{ENTER}"); automate.LongDelay(); } } readerFile.Close(); } while (false); }
public void SimpleProcessingTest() { var dataSource = @"https://github.com/MatthewMWR/WinPerf/blob/master/Scenarios/BOOT-REFERENCE__NormalLightlyManaged.zip?raw=true"; var dataIncomingDir = Path.Combine(Path.GetTempPath(), "SimpleProcessingTest-In"); Directory.CreateDirectory(dataIncomingDir); var dataArchiveDir = Path.Combine(Path.GetTempPath(), "SimpleProcessingTest-Archive"); Directory.CreateDirectory(dataArchiveDir); var dataDownloadStageDir = Path.Combine(Path.GetTempPath(), "SimpleProcessingTest-DownloadStage"); Directory.CreateDirectory(dataDownloadStageDir); var stagedDownlodFilePath = Path.Combine(dataDownloadStageDir, "original.zip"); if (!File.Exists(stagedDownlodFilePath)) { var webClient = new WebClient(); webClient.DownloadFile(dataSource, stagedDownlodFilePath); } var testCopyCount = 26; var i = 0; while (i < testCopyCount) { i++; File.Copy(stagedDownlodFilePath, Path.Combine(dataIncomingDir, $"Copy{i}.zip"), true); } var storeConfig = new MeasurementStoreConfig() { StoreType = StoreType.MicrosoftSqlServer, ConnectionString = @"server=(localdb)\MSSqlLocalDb;Database=SimpleProcessingTest" }; var processingConfig = new ProcessingConfig() { DestinationDataPath = dataArchiveDir }; processingConfig.IncomingDataPaths.Add(dataIncomingDir); using (var store = new MeasurementStore(storeConfig)) { store.Database.EnsureCreated(); store.Database.EnsureDeleted(); store.Database.EnsureCreated(); } Automate.InvokeProcessingOnce(processingConfig, storeConfig); using (var store = new MeasurementStore(storeConfig)) { Assert.True(store.Traces.Count() == testCopyCount); var measuredCount = store.Traces .Include(t => t.ProcessingRecords) .Count(t => t.ProcessingRecords.OrderBy(pr => pr.StateChangeTime).Last().ProcessingState == ProcessingState.Measured); Assert.True(measuredCount == processingConfig.ParallelMeasuringThrottle); var movedCount = store.ProcessingRecords.Count(pr => pr.ProcessingState == ProcessingState.Moved); Assert.True(movedCount == processingConfig.ParallelMovesThrottle); } Automate.InvokeProcessingOnce(processingConfig, storeConfig); Automate.InvokeProcessingOnce(processingConfig, storeConfig); Automate.InvokeProcessingOnce(processingConfig, storeConfig); using (var store = new MeasurementStore(storeConfig)) { var measuredCount = store.Traces .Include(t => t.ProcessingRecords) .Count(t => t.ProcessingRecords.OrderBy(pr => pr.StateChangeTime).Last().ProcessingState == ProcessingState.Measured); Assert.True(measuredCount == testCopyCount); var measuredCountByDifferentPath = store.GetTraceByState(ProcessingState.Measured).Count(); Assert.True(measuredCountByDifferentPath == testCopyCount); var measuredCountByThirdPath = store.GetTraceByFilter(t => t.ProcessingRecords.Latest().ProcessingState == ProcessingState.Measured).Count(); Assert.True(measuredCountByThirdPath == testCopyCount); Assert.True(store.GetTraceByName("copy1.zip", false) != null); Assert.True(store.GetTraceByFilter(t => t.ProcessingRecords.Count == 3).AsEnumerable().Count() == testCopyCount); Assert.NotEmpty(store.GetTraceByName("copy1.zip", true).GetMeasurements <DiskIo>()); } }