/// <summary> /// Saves the received File from the Server Request. /// </summary> /// <param name="obj"></param> public void SaveFile(object obj) { string path = null; System.Windows.Forms.SaveFileDialog ofd = new System.Windows.Forms.SaveFileDialog(); ofd.FileName = filename; ofd.RestoreDirectory = true; if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { path = ofd.FileName; } if (path != null) { try { FileStream fileStream = new FileStream(path, FileMode.Create, FileAccess.Write); fileStream.Write(byteResult, 0, byteResult.Length); fileStream.Close(); ((MetroWindow)Application.Current.MainWindow).HideMetroDialogAsync(dial); } catch (Exception e) { ((MetroWindow)Application.Current.MainWindow).HideMetroDialogAsync(dial); FailView fail = new FailView(this); dial = new ResponseWindow(); fail.ServerStatus.Text = "File Save Error"; fail.Details.Text = "There has been an Error while reading the byte stream. \r Exception: " + e.Message + ""; dial.Content = fail; dial.Height = 300; dial.Width = 300; ((MetroWindow)Application.Current.MainWindow).ShowMetroDialogAsync(dial); } } }
public async void ExecuteOpenAdvSettings(object obj) { advView = new AdvancedViewModel(Request); dial = new ResponseWindow(); dial.Height = 400; dial.Width = 400; dial.Content = advView.GetContext(); await((MetroWindow)Application.Current.MainWindow).ShowMetroDialogAsync(dial); }
private void ShowFullLicense(object sender, System.Windows.RoutedEventArgs e) { ResponseWindow dial = new ResponseWindow(); License licenseWindow = new License(); var asm = Assembly.GetExecutingAssembly(); using (var stream = asm.GetManifestResourceStream("OneOffixx.ConnectClient.WinApp.Licenses.Licenses.txt")) { var reader = new StreamReader(stream); licenseWindow.Content.Text = reader.ReadToEnd(); } dial.Height = 400; dial.Width = 700; dial.Content = licenseWindow; this.ShowMetroDialogAsync(dial); }
//Trial Block: Actual trial. Presenting 80 stimuli IEnumerator TrialBlock() { Debug.Log("TrialBlock"); CurrentBlockType = BlockType.TrialBlock; MainGO.SetActive(false); //reset ISI trackers float isi = 0; int ISIindex = 0; //320 total stimuli presented foreach (int value in _trialBlock) { //storing stim code StimCode = value; //time stamp when stimulus shown StimTime = (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond); //storing StimTime in array _stimTimes.Add(StimTime); //pick out corresponding ISI isi = _interStimInterval[ISIindex]; MainGO.GetComponent <SpriteRenderer>().sprite = _spriteArray[value]; MainGO.SetActive(true); CurrentResponseState = ResponseWindow.Open; yield return(new WaitForSeconds(_stimDuration)); MainGO.SetActive(false); MainGO.GetComponent <SpriteRenderer>().sprite = _spriteArray[10]; MainGO.SetActive(true); yield return(new WaitForSeconds(isi)); MainGO.SetActive(false); //increment ISI to match stimulus ISIindex++; //log responses ResponseLogger(); } }
public void OpenFile(object obj) { try { string tempPath = Path.GetTempFileName() + filename; FileStream fileStream = new FileStream(tempPath, FileMode.Create, FileAccess.Write); fileStream.Write(byteResult, 0, byteResult.Length); fileStream.Close(); ((MetroWindow)Application.Current.MainWindow).HideMetroDialogAsync(dial); var process = Process.Start(tempPath); } catch (Exception e) { ((MetroWindow)Application.Current.MainWindow).HideMetroDialogAsync(dial); FailView fail = new FailView(this); dial = new ResponseWindow(); fail.ServerStatus.Text = "200"; fail.Details.Text = "There has been an Error while reading the byte stream. \r Exception: " + e.Message + ""; dial.Content = fail; dial.Height = 300; dial.Width = 300; ((MetroWindow)Application.Current.MainWindow).ShowMetroDialogAsync(dial); } }
/// <summary> /// Examines if the XML input is valid based on a given .xsd from OneOffixx. /// </summary> /// <param name="obj"></param> public async void ExecuteValidation(object obj) { dial = new ResponseWindow(); XmlSchemaSet xmlSchema = new XmlSchemaSet(); var asm = Assembly.GetExecutingAssembly(); using (var stream = asm.GetManifestResourceStream("OneOffixx.ConnectClient.WinApp.XSD.OneOffixxValidation.xsd")) { if (stream != null) { var reader = new StreamReader(stream); var xmlString = reader.ReadToEnd(); xmlSchema.Add("", XmlReader.Create(new StringReader(xmlString))); } } try { var xdoc = new XmlDocument(); xdoc.LoadXml(Request.XmlString); xdoc.Schemas = xmlSchema; ValidationEventHandler eventHandler = new ValidationEventHandler(XmlSettingsValidationEventHandler); xdoc.Validate(eventHandler); if (validation) { SuccessView success = new SuccessView(this); success.tb.Visibility = Visibility.Hidden; success.tb1.Visibility = Visibility.Hidden; success.tb2.Visibility = Visibility.Hidden; success.tb3.Visibility = Visibility.Hidden; success.Save.Visibility = Visibility.Hidden; success.Open.Visibility = Visibility.Hidden; success.Time.Visibility = Visibility.Hidden; success.Size.Visibility = Visibility.Hidden; success.Filename.Visibility = Visibility.Hidden; dial.Content = success; dial.Height = 300; dial.Width = 300; await((MetroWindow)Application.Current.MainWindow).ShowMetroDialogAsync(dial); } else { FailView fail = new FailView(this); fail.ServerStatus.Text = "The XML is not valid."; fail.Details.Text = validationText; dial.Content = fail; dial.Height = 300; dial.Width = 300; await((MetroWindow)Application.Current.MainWindow).ShowMetroDialogAsync(dial); validation = true; } } catch (XmlException e) { FailView fail = new FailView(this); fail.ServerStatus.Text = "Xml Parse Exception"; fail.Details.Text = "The XML contains an error. Make sure it is well formed and validate again."; dial.Content = fail; dial.Height = 300; dial.Width = 300; await((MetroWindow)Application.Current.MainWindow).ShowMetroDialogAsync(dial); validation = true; } }
/// <summary> /// Sends the Server Request. /// Posts given input fields to the OneOffixx Server. /// </summary> /// <param name="obj"></param> public async void SendRequest(object obj) { double length; isErrorAppeared = false; Request.CanExecute = false; LogEntryViewModel values = new LogEntryViewModel(this); var date = System.DateTime.Now; values.Id = Guid.NewGuid(); values.Name = date.ToString(); values.Action = "Server"; values.RequestEntry = new Request() { Uri = Request.Url, Content = Request.XmlString, Username = Request.Username, Password = Request.Password, Date = date }; values.ResponseEntry = new Response(); values.IsFavorite = false; using (HttpClient client = new HttpClient()) { try { var inBytes = Encoding.ASCII.GetBytes($"{Request.Username}:{Request.Password}"); client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(inBytes)); HttpContent content = new StringContent(Request.XmlString); Stopwatch sw = Stopwatch.StartNew(); var result = await client.PostAsync(Request.Url, content); sw.Stop(); values.ResponseEntry.TimeUsed = Math.Round((decimal)sw.ElapsedMilliseconds / 1000, 3).ToString(); if (result.StatusCode == HttpStatusCode.OK) { using (content = result.Content) { length = (double)content.Headers.ContentLength; filename = content.Headers.ContentDisposition.FileName; filename = filename.Replace("\"", ""); byteResult = await content.ReadAsByteArrayAsync(); } values.ResponseEntry.StatusCode = ((int)result.StatusCode).ToString(); SuccessView success = new SuccessView(this); dial = new ResponseWindow(); length = Math.Round((length / 1048576), 2); success.Size.Text = length.ToString() + " MB"; success.Filename.Text = filename; success.Time.Text = values.ResponseEntry.TimeUsed + " Seconds"; dial.Content = success; dial.Height = 300; dial.Width = 300; await((MetroWindow)Application.Current.MainWindow).ShowMetroDialogAsync(dial); } else { FailView fail = new FailView(this); dial = new ResponseWindow(); values.ResponseEntry.StatusCode = ((int)result.StatusCode).ToString(); fail.ServerStatus.Text = result.StatusCode.ToString() + " " + (int)result.StatusCode; fail.Details.Text = result.ReasonPhrase; dial.Content = fail; dial.Height = 300; dial.Width = 300; await((MetroWindow)Application.Current.MainWindow).ShowMetroDialogAsync(dial); } } catch (Exception) { FailView fail = new FailView(this); dial = new ResponseWindow(); fail.ServerStatus.Text = "Uri not found"; values.ResponseEntry = new Response() { StatusCode = "Uri not found" }; fail.Details.Text = "Your Server input may be wrong as we could not find the Uri you requested."; dial.Content = fail; dial.Height = 300; dial.Width = 300; await((MetroWindow)Application.Current.MainWindow).ShowMetroDialogAsync(dial); } finally { values.ResponseEntry.Filename = filename; Request.CanExecute = true; log.Logs.Add(values); Request.Log = new ObservableCollection <LogEntryViewModel>(log.Logs.OrderByDescending(x => x.RequestEntry.Date).ToList()); Request.FavoriteLog = new ObservableCollection <LogEntryViewModel>(log.Logs.Where(x => x.IsFavorite)); SaveHistory(); } } }
public void LoadHistoryFromFile() { string filepath = Path.Combine(GetHistorySavePath() + historyFileName); if (File.Exists(filepath)) { try { XDocument xdoc = XDocument.Load(filepath); string xml = xdoc.ToString(); var elements = XmlSerializer.Deserialize <HistoryEntry>(xml); foreach (var item in elements.Logs) { log.Logs.Add(new LogEntryViewModel(this) { Id = item.Id, Name = item.Name, Action = item.Action, RequestEntry = new Request() { Uri = item.RequestEntry.Uri, Username = item.RequestEntry.Username, Password = item.RequestEntry.Password, Content = item.RequestEntry.Content, Date = item.RequestEntry.Date }, ResponseEntry = new Response() { StatusCode = item.ResponseEntry.StatusCode, Filename = item.ResponseEntry.Filename, TimeUsed = item.ResponseEntry.TimeUsed }, IsFavorite = item.IsFavorite }); } } catch (Exception ex) { string newFilepath = GetHistorySavePath() + Guid.NewGuid().ToString() + "\\" + historyFileName; System.IO.File.Move("filepath", newFilepath); FailView fail = new FailView(this); dial = new ResponseWindow(); fail.ServerStatus.Text = "History Error"; fail.Details.Text = "An Error occured while trying to read your History. It seems that the xml structure was changed or is from an older version. Your History file was renamed to: " + newFilepath; dial.Content = fail; dial.Height = 300; dial.Width = 300; ((MetroWindow)Application.Current.MainWindow).ShowMetroDialogAsync(dial); } RequestModel request = new RequestModel(); if (log.Logs.FirstOrDefault()?.Action == "Server") { request.WarningVisibility = Visibility.Hidden; request.Url = log.Logs[0].RequestEntry.Uri; request.Username = log.Logs[0].RequestEntry.Username; request.Password = log.Logs[0].RequestEntry.Password; request.XmlString = log.Logs[0].RequestEntry.Content; Request = request; } else if (log.Logs.FirstOrDefault()?.Action == "Client") { request.WarningVisibility = Visibility.Hidden; request.Directory = log.Logs[0].RequestEntry.Uri; request.XmlString = log.Logs[0].RequestEntry.Content; Request = request; Request.SelectedIndex = 1; } else { Request = new RequestModel(); } SelectedLogEntryViewModelItem = log.Logs.FirstOrDefault(); Request.Log = new ObservableCollection <LogEntryViewModel>(log.Logs); Request.FavoriteLog = new ObservableCollection <LogEntryViewModel>(log.Logs.Where(x => x.IsFavorite)); } else { RequestModel request = new RequestModel() { WarningVisibility = Visibility.Hidden }; Request = request; } }
/// <summary> /// Sends the Client Request. /// Uses the system Process which is used for OneConnect. /// </summary> /// <param name="obj"></param> public async void ClientConnect(object obj) { LogEntryViewModel values = new LogEntryViewModel(this); values.Action = "Client"; values.Name = System.DateTime.Now.ToString(); values.RequestEntry = new Request() { Date = System.DateTime.Now, Uri = Request.Directory, Content = Request.XmlString }; values.ResponseEntry = new Response(); SaveHistory(); Request.CanExecuteClient = false; filename = Path.GetTempPath() + Guid.NewGuid().ToString() + ".oocx"; try { XDocument xdoc = XDocument.Parse(Request.XmlString); xdoc.Save(filename); try { if (File.Exists(Request.Directory)) { var command = Process.Start($"{Request.Directory}", $"/connector \"{filename}\""); values.ResponseEntry.StatusCode = "200"; } else { FailView fail = new FailView(this); dial = new ResponseWindow(); fail.ServerStatus.Text = "failed"; values.ResponseEntry = new Response() { StatusCode = "File not found" }; fail.Details.Text = "Since we could not find the file please check your input directory and confirm if there has crept in an error. "; dial.Content = fail; dial.Height = 300; dial.Width = 300; await((MetroWindow)Application.Current.MainWindow).ShowMetroDialogAsync(dial); } } catch (Exception ex) { FailView fail = new FailView(this); dial = new ResponseWindow(); fail.ServerStatus.Text = "Uri not found"; values.ResponseEntry = new Response() { StatusCode = "Unexpected Error" }; fail.Details.Text = "There has been an unexpected Error while trying to execute the Connector. Error: " + ex.Message; dial.Content = fail; dial.Height = 300; dial.Width = 300; await((MetroWindow)Application.Current.MainWindow).ShowMetroDialogAsync(dial); } } catch (System.Xml.XmlException) { FailView fail = new FailView(this); dial = new ResponseWindow(); fail.ServerStatus.Text = "Uri not found"; values.ResponseEntry = new Response() { StatusCode = "Unexpected Error" }; fail.Details.Text = "An unexpected error has occured while trying to create the temp .oocx file. Please check the XML syntax of your content input."; dial.Content = fail; dial.Height = 300; dial.Width = 300; await((MetroWindow)Application.Current.MainWindow).ShowMetroDialogAsync(dial); } log.Logs.Add(values); Request.Log = new ObservableCollection <LogEntryViewModel>(log.Logs.OrderByDescending(x => x.RequestEntry.Date)); Request.FavoriteLog = new ObservableCollection <LogEntryViewModel>(log.Logs.Where(x => x.IsFavorite).OrderByDescending(x => x.RequestEntry.Date)); Request.CanExecuteClient = true; }