private void button1_Click(object sender, EventArgs e) { string link = "https://login.iee.ihu.gr/login?client_id=" + Program.CLIENT_ID + "&response_type=code&scope=announcements,notifications,profile&redirect_uri=https://users.it.teithe.gr/~it185246/accepted.html"; Process.Start(link); StringEdit.Out("Please use the opened browser window to authorize and paste the code back here.", ref richTextBox1, StringEdit.OutType.Alert); }
private async Task LoadAnnouncements() { StringEdit.Out("Fetching announcements...", ref richTextBox1); using (var request = new HttpRequestMessage(new HttpMethod("GET"), "http://api.iee.ihu.gr/announcements")) { request.Headers.TryAddWithoutValidation("x-access-token", Program.access_token); var response = await client.SendAsync(request); string responseString = await response.Content.ReadAsStringAsync(); responseString = responseString.Replace("},{", "}^{"); responseString = responseString.Substring(1, responseString.Length - 2); string[] vs = responseString.Split('^'); foreach (string s in vs) { Announcement temp = JsonConvert.DeserializeObject <Announcement>(s); Program.Announcements.Add(temp); } if (Program.Announcements.Count > 0) { StringEdit.Out("Found " + Program.Announcements.Count + " announcements.", ref richTextBox1, StringEdit.OutType.Success); } else { StringEdit.Out("Something went wrong while fetching the announcements.", ref richTextBox1, StringEdit.OutType.Error); return; } } }
private async Task Initialize() { RegistryKey rk = Registry.CurrentUser.OpenSubKey ("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); if (rk.GetValue("AnnouncementHelper") != null) { Program.StartupEnabled = true; } if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\AnnouncementHelper\\")) { Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\AnnouncementHelper\\"); } string[] files = Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\AnnouncementHelper\\"); foreach (string s in files) { string filename = s.Split('\\').Last(); if (filename.Contains("reminder")) { string date = filename.Split('_')[1].Split('T')[0]; if (DateTime.ParseExact(date, "yyyy-MM-dd", CultureInfo.InvariantCulture) <= DateTime.Now.Date) { StringEdit.Out("Βρέθηκε ανακοίνωση για σήμερα!", ref richTextBox1, StringEdit.OutType.Success); await Task.Delay(1000); Announcement temp = AnnouncementConvert.FromBase64(File.ReadAllText(s)); File.Delete(s); new Thread(() => { AnnouncementForm f1 = new AnnouncementForm(temp); f1.ShowDialog(); }) { IsBackground = true }.Start(); } } } // Το httpClient χρησιμοποιεί proxy σαν default που το κάνει αργό // οπότε το αφαιρούμε HttpClientHandler hch = new HttpClientHandler { Proxy = null, UseProxy = false, }; client = new HttpClient(hch); }
private async void AfterAccessTokenWork() { if (Program.access_token == "error") { StringEdit.Out("Error when loading access token. Please report to the developer.", ref richTextBox1, StringEdit.OutType.Error); return; } var task1 = LoadCategories(); var task2 = LoadUserProfile(); var task3 = LoadAnnouncements(); await Task.WhenAll(task1, task2, task3); this.Hide(); var organizer = new Organizer(); organizer.Closed += (s, args) => this.Close(); organizer.Show(); }
private async Task GetAccessTokenUsingRefresh(string code) { var values = new Dictionary <string, string> { { "client_id", Program.CLIENT_ID }, { "client_secret", Program.CLIENT_SECRET }, { "grant_type", "refresh_token" }, { "code", code } }; var content = new FormUrlEncodedContent(values); var response = await client.PostAsync("https://login.iee.ihu.gr/token", content); var responseString = await response.Content.ReadAsStringAsync(); MatchCollection matches = Regex.Matches(responseString, "\"([^\"]*)\""); if (matches.Count == 0) { StringEdit.Out("JSON answer missing error.", ref richTextBox1, StringEdit.OutType.Error); } else { if (matches[0].ToString().Contains("access_token")) { StringEdit.Out("Got access token using the refresh token!", ref richTextBox1, StringEdit.OutType.Success); File.WriteAllText(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\AnnouncementHelper\\refresh.token", matches[5].ToString().Replace("\"", "")); Program.access_token = matches[1].ToString().Replace("\"", ""); return; } else { StringEdit.Out("JSON error:" + Environment.NewLine + responseString, ref richTextBox1, StringEdit.OutType.Error); StringEdit.Out("Possibly expired refresh_token.", ref richTextBox1); StringEdit.Out("Please restart the program.", ref richTextBox1); if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\AnnouncementHelper\\refresh.token")) { File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\AnnouncementHelper\\refresh.token"); } return; } } }
private async void BeforeAccessTokenWork() { await Initialize(); if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\AnnouncementHelper\\refresh.token")) { StringEdit.Out("Refresh token found!", ref richTextBox1, StringEdit.OutType.Success); await GetAccessTokenUsingRefresh(File.ReadAllText(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\AnnouncementHelper\\refresh.token")); AfterAccessTokenWork(); } else { StringEdit.Out("Please choose your login method and login.", ref richTextBox1); radiopanel.Enabled = true; loginBox.Enabled = true; loginManual.Enabled = true; } }
private async Task LoadUserProfile() { using (var request = new HttpRequestMessage(new HttpMethod("GET"), "http://api.iee.ihu.gr/profile")) { request.Headers.TryAddWithoutValidation("x-access-token", Program.access_token); var response = await client.SendAsync(request); string responseString = await response.Content.ReadAsStringAsync(); Program.UserProfile = JsonConvert.DeserializeObject <Profile>(responseString); if (Program.UserProfile.GivenName == string.Empty) { StringEdit.Out("Something went wrong while fetching the profile.", ref richTextBox1, StringEdit.OutType.Error); return; } } StringEdit.Out("Semester found:" + Program.UserProfile.Sem, ref richTextBox1); }
public void OneEditApartTest01() { var instance = new StringEdit(); Assert.IsFalse(instance.OneEditApart("cat", "dog")); Assert.IsFalse(instance.OneEditApart("cat", "act")); Assert.IsTrue(instance.OneEditApart("cat", "cats")); Assert.IsTrue(instance.OneEditApart("cat", "cut")); Assert.IsTrue(instance.OneEditApart("cat", "cast")); Assert.IsTrue(instance.OneEditApart("cat", "at")); Assert.IsTrue(instance.OneEditApart("1203", "1213")); instance = new StringEdit(); Assert.IsFalse(instance.OneEditApartEfficient("cat", "dog")); Assert.IsFalse(instance.OneEditApartEfficient("cat", "act")); Assert.IsTrue(instance.OneEditApartEfficient("cat", "cats")); Assert.IsTrue(instance.OneEditApartEfficient("cat", "cut")); Assert.IsTrue(instance.OneEditApartEfficient("cat", "cast")); Assert.IsTrue(instance.OneEditApartEfficient("cat", "at")); Assert.IsTrue(instance.OneEditApartEfficient("1203", "1213")); }
internal async Task Bind_RepositoryItems(Type viewType) { var boundTypes = 2; var controlTypes = new[] { typeof(XafGridView), typeof(GridColumn) }; var predefinedMaps = new[] { PredefinedMap.RepositoryItem, PredefinedMap.RepositoryItemTextEdit }; controlTypes.ToObservable().Do(type => Assembly.LoadFile(type.Assembly.Location)).Subscribe(); InitializeMapperService($"{nameof(Bind_RepositoryItems)}{predefinedMaps.First()}", Platform.Win); var module = predefinedMaps.Extend(); var application = DefaultModelMapperModule(Platform.Win, module).Application; var controlBound = ModelBindingService.ControlBind.Replay(); controlBound.Connect(); var modelPropertyEditor = ((IModelPropertyEditor)application.Model.GetNodeByPath(MMDetailViewTestItemNodePath)); var controlInstance = new StringEdit(); var repositoryItemTextEdit = controlInstance.Properties; if (viewType == typeof(ListView)) { MockListEditor(Platform.Win, controlTypes, application, PredefinedMap.GridView, repositoryItemTextEdit); } else { application.MockDetailViewEditor(modelPropertyEditor, controlInstance); } var objectView = application.CreateObjectView(viewType, typeof(MM)); var values = ConfigureModelRepositories(objectView); objectView.DelayedItemsInitialization = false; objectView.CreateControls(); await controlBound.Take(boundTypes).WithTimeOut(TimeSpan.FromSeconds(10)); Debug.Assert(repositoryItemTextEdit != null, nameof(repositoryItemTextEdit) + " != null"); repositoryItemTextEdit.CharacterCasing.ShouldBe(values.concreteTypePropertyValue); repositoryItemTextEdit.AccessibleDescription.ShouldBe(values.basePropertyValue); }
private async Task LoadCategories() { using (var request = new HttpRequestMessage(new HttpMethod("GET"), "http://api.iee.ihu.gr/categories/")) { request.Headers.TryAddWithoutValidation("x-access-token", Program.access_token); var response = await client.SendAsync(request); string responseString = await response.Content.ReadAsStringAsync(); responseString = responseString.Replace("},{", "}^{"); responseString = responseString.Substring(1, responseString.Length - 2); string[] vs = responseString.Split('^'); int i = 0; foreach (string s in vs) { if (s.Contains("error")) { StringEdit.Out(s, ref richTextBox1); return; } Category temp; temp = JsonConvert.DeserializeObject <Category>(s); temp.Index = i; Program.Categories.Add(temp); i++; } if (Program.Categories.Count > 0) { StringEdit.Out("Found " + Program.Categories.Count + " categories.", ref richTextBox1, StringEdit.OutType.Success); } else { StringEdit.Out("Something went wrong while fetching the categories.", ref richTextBox1, StringEdit.OutType.Error); return; } } }
private void SearchButton_Click(object sender, EventArgs e) { string temp = SearchBar.Text; temp = StringEdit.ReplaceGreek(temp, CaseCheckbox.Checked, StressCheckbox.Checked, GrammarCheckbox.Checked); string[] searchValues = temp.Split(','); if (searchValues.Length > 0) { List <Announcement> searchResults = new List <Announcement>(); if (AnnouncementGridView.Rows.Count - 1 != Program.Announcements.Count && AnnouncementGridView.Rows.Count > 1) { DialogResult dialogResult = MessageBox.Show("Αναζήτηση στην τρέχουσα λίστα?", "Διευκρίνηση", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { for (int i = 0; i < AnnouncementGridView.Rows.Count - 1; i++) { Announcement curAnnouncement = Program.Announcements[int.Parse(AnnouncementGridView.Rows[i].Cells["ID"].Value.ToString())]; foreach (string s in searchValues) { string temptext = StringEdit.ReplaceGreek(curAnnouncement.Text, CaseCheckbox.Checked, StressCheckbox.Checked, GrammarCheckbox.Checked); string temptitle = StringEdit.ReplaceGreek(curAnnouncement.Title, CaseCheckbox.Checked, StressCheckbox.Checked, GrammarCheckbox.Checked); if (temptitle.Contains(s) || temptext.Contains(s)) { searchResults.Add(curAnnouncement); break; } } } } else if (dialogResult == DialogResult.No) { foreach (Announcement curAnnouncement in Program.Announcements) { foreach (string s in searchValues) { string temptext = StringEdit.ReplaceGreek(curAnnouncement.Text, CaseCheckbox.Checked, StressCheckbox.Checked, GrammarCheckbox.Checked); string temptitle = StringEdit.ReplaceGreek(curAnnouncement.Title, CaseCheckbox.Checked, StressCheckbox.Checked, GrammarCheckbox.Checked); if (temptitle.Contains(s) || temptext.Contains(s)) { searchResults.Add(curAnnouncement); break; } } } } } else { foreach (Announcement curAnnouncement in Program.Announcements) { foreach (string s in searchValues) { string temptext = StringEdit.ReplaceGreek(curAnnouncement.Text, CaseCheckbox.Checked, StressCheckbox.Checked, GrammarCheckbox.Checked); string temptitle = StringEdit.ReplaceGreek(curAnnouncement.Title, CaseCheckbox.Checked, StressCheckbox.Checked, GrammarCheckbox.Checked); if (temptitle.Contains(s) || temptext.Contains(s)) { searchResults.Add(curAnnouncement); break; } } } } AnnouncementGridView.Rows.Clear(); foreach (Announcement a in searchResults) { int j = Program.Announcements.IndexOf(a); AnnouncementGridView.Rows.Add(new object[] { j, a.Category, a.Title, a.Publisher.Name, a.Date.Split('T')[0], a.Attachments.Length }); } } }
protected override object CreateControlCore() { BaseEdit result; if (IsComboBoxStringEdit()) { result = new AurumPredefinedValuesStringEdit(Model.MaxLength, PredefinedValuesEditorHelper.CreatePredefinedValuesFromString(Model.PredefinedValues)); } else if (IsSimpleStringEdit()) { result = new StringEdit(Model.MaxLength); } else { result = new LargeStringEdit(Model.RowCount, Model.MaxLength); } return result; }
private void drawPath(StringBuilder output, String top, String left) { if (at == null) { return; } foreach (Control c in dynamicProgrammingTableLayoutPanel.Controls) { ((Label)c).BackColor = SystemColors.Control; } lastAlignmentButton.Enabled = nextAlignmentButton.Enabled = at.NumberOfAlignments > 0 && selectedAlignment < (at.NumberOfAlignments - 1); firstAlignmentButton.Enabled = previousAlignmentButton.Enabled = at.NumberOfAlignments > 0 && selectedAlignment > 0; try { if (at.GetType() == typeof(AffineLocalAlignmentTable) || at.GetType() == typeof(LocalAlignmentTable)) { List <Tuple <int, int> > startingPoints = new List <Tuple <int, int> >(); for (int row = at.Left.Value.Length; row > 0; row--) { for (int col = at.Top.Value.Length; col > 0; col--) { if (at[row, col].Value == at.MaxScore) { startingPoints.Add(new Tuple <int, int>(row, col)); } } } List <Label> path = new List <Label>(); foreach (Tuple <int, int> start in startingPoints) { int row = start.Item1 + 1; int col = start.Item2 + 1; try { for (int i = top.Length - 1; i >= 0; i--) { if (top[i] == left[i] && left[i] == '_') { throw new Exception("Cannot have both insert and delete at the same position!"); } StringEdit se = at[row - 1, col - 1]; if (top[i] == '_' && se.Edits.HasFlag(StringEdit.EditType.Insert)) { if (left[i] != ((Label)dynamicProgrammingTableLayoutPanel.GetControlFromPosition(0, row)).Text.Trim()[0]) { throw new Exception("Value specified in alignment for left sequence does not match that of table row!"); } ((Label)dynamicProgrammingTableLayoutPanel.GetControlFromPosition(col, row)).BackColor = Color.LightBlue; path.Add(((Label)dynamicProgrammingTableLayoutPanel.GetControlFromPosition(col, row))); --row; } else if (left[i] == '_' && se.Edits.HasFlag(StringEdit.EditType.Delete)) { if (top[i] != ((Label)dynamicProgrammingTableLayoutPanel.GetControlFromPosition(col, 0)).Text.Trim()[0]) { throw new Exception("Value specified in alignment for top sequence does not match that of table column!"); } ((Label)dynamicProgrammingTableLayoutPanel.GetControlFromPosition(col, row)).BackColor = Color.Yellow; path.Add(((Label)dynamicProgrammingTableLayoutPanel.GetControlFromPosition(col, row))); --col; } else { if (top[i] != ((Label)dynamicProgrammingTableLayoutPanel.GetControlFromPosition(col, 0)).Text.Trim()[0]) { throw new Exception("Value specified in alignment for top sequence does not match that of table column!"); } if (left[i] != ((Label)dynamicProgrammingTableLayoutPanel.GetControlFromPosition(0, row)).Text.Trim()[0]) { throw new Exception("Value specified in alignment for left sequence does not match that of table row!"); } if (top[i] == left[i]) { ((Label)dynamicProgrammingTableLayoutPanel.GetControlFromPosition(col, row)).BackColor = Color.LightGreen; } else { ((Label)dynamicProgrammingTableLayoutPanel.GetControlFromPosition(col, row)).BackColor = Color.LightPink; } path.Add(((Label)dynamicProgrammingTableLayoutPanel.GetControlFromPosition(col, row))); --row; --col; } } break; } catch (Exception ex) { foreach (Label l in path) { l.BackColor = Color.White; } path.Clear(); continue; } } if (path.Count == 0) { outputRichTextBox.Text += "\r\nValidation failed!"; } } else { int row = at.Left.Value.Length + 1; int col = at.Top.Value.Length + 1; int i = top.Length - 1; try { for (; i >= 0; i--) { if (top[i] == left[i] && left[i] == '_') { throw new Exception("Cannot have both insert and delete at the same position!"); } StringEdit se = at[row - 1, col - 1]; if (top[i] == '_' && se.Edits.HasFlag(StringEdit.EditType.Insert)) { if (left[i] != ((Label)dynamicProgrammingTableLayoutPanel.GetControlFromPosition(0, row)).Text.Trim()[0]) { throw new Exception("Value specified in alignment for left sequence does not match that of table row!"); } ((Label)dynamicProgrammingTableLayoutPanel.GetControlFromPosition(col, row)).BackColor = Color.LightBlue; --row; } else if (left[i] == '_' && se.Edits.HasFlag(StringEdit.EditType.Delete)) { if (top[i] != ((Label)dynamicProgrammingTableLayoutPanel.GetControlFromPosition(col, 0)).Text.Trim()[0]) { throw new Exception("Value specified in alignment for top sequence does not match that of table column!"); } ((Label)dynamicProgrammingTableLayoutPanel.GetControlFromPosition(col, row)).BackColor = Color.Yellow; --col; } else { if (top[i] != ((Label)dynamicProgrammingTableLayoutPanel.GetControlFromPosition(col, 0)).Text.Trim()[0]) { throw new Exception("Value specified in alignment for top sequence does not match that of table column!"); } if (left[i] != ((Label)dynamicProgrammingTableLayoutPanel.GetControlFromPosition(0, row)).Text.Trim()[0]) { throw new Exception("Value specified in alignment for left sequence does not match that of table row!"); } if (top[i] == left[i]) { ((Label)dynamicProgrammingTableLayoutPanel.GetControlFromPosition(col, row)).BackColor = Color.LightGreen; } else { ((Label)dynamicProgrammingTableLayoutPanel.GetControlFromPosition(col, row)).BackColor = Color.LightPink; } --row; --col; } } } catch (Exception ex) { ((Label)dynamicProgrammingTableLayoutPanel.GetControlFromPosition(col, row)).BackColor = Color.Red; outputRichTextBox.Text += "\r\nValidation failed at table row = " + row + ", table column = " + col + ", alignment index = " + i + ":\r\n" + ex.Message + "\r\n" + ex.StackTrace; } } } catch (Exception ex) { outputRichTextBox.Text = "Invalid parameter or input data\r\n" + ex.Message + "\r\n" + ex.StackTrace; } }
private void getLcsPathsFromStart(int row, int col, String lcs, List <List <Tuple <int, int, StringEdit.EditType> > > paths, List <Tuple <int, int, StringEdit.EditType> > path) { if (lcs.Length == 0) { paths.Add(path); return; } StringEdit se = at[row + 1, col + 1]; if (se.Value == 0) { return; } if (se.Edits.HasFlag(StringEdit.EditType.Delete)) { Tuple <int, int, StringEdit.EditType> curCoord = new Tuple <int, int, SequenceAlignment.StringEdit.EditType>(row, col, StringEdit.EditType.Delete); List <Tuple <int, int, StringEdit.EditType> > newPath = new List <Tuple <int, int, StringEdit.EditType> >(); foreach (Tuple <int, int, StringEdit.EditType> t in path) { newPath.Add(t); } newPath.Add(curCoord); getLcsPathsFromStart(row, col - 1, lcs, paths, newPath); } if (se.Edits.HasFlag(SequenceAlignment.StringEdit.EditType.Insert)) { Tuple <int, int, StringEdit.EditType> curCoord = new Tuple <int, int, SequenceAlignment.StringEdit.EditType>(row, col, StringEdit.EditType.Insert); List <Tuple <int, int, StringEdit.EditType> > newPath = new List <Tuple <int, int, StringEdit.EditType> >(); foreach (Tuple <int, int, StringEdit.EditType> t in path) { newPath.Add(t); } newPath.Add(curCoord); getLcsPathsFromStart(row - 1, col, lcs, paths, newPath); } if (se.Edits.HasFlag(SequenceAlignment.StringEdit.EditType.Mismatch)) { Tuple <int, int, StringEdit.EditType> curCoord = new Tuple <int, int, SequenceAlignment.StringEdit.EditType>(row, col, StringEdit.EditType.Mismatch); List <Tuple <int, int, StringEdit.EditType> > newPath = new List <Tuple <int, int, StringEdit.EditType> >(); foreach (Tuple <int, int, StringEdit.EditType> t in path) { newPath.Add(t); } newPath.Add(curCoord); getLcsPathsFromStart(row - 1, col - 1, lcs, paths, newPath); } if (se.Edits.HasFlag(SequenceAlignment.StringEdit.EditType.Match)) { if (at.Top.Value[col] != lcs[lcs.Length - 1] || at.Left.Value[row] != lcs[lcs.Length - 1]) { return; } Tuple <int, int, StringEdit.EditType> curCoord = new Tuple <int, int, SequenceAlignment.StringEdit.EditType>(row, col, StringEdit.EditType.Match); List <Tuple <int, int, StringEdit.EditType> > newPath = new List <Tuple <int, int, StringEdit.EditType> >(); foreach (Tuple <int, int, StringEdit.EditType> t in path) { newPath.Add(t); } newPath.Add(curCoord); getLcsPathsFromStart(row - 1, col - 1, lcs.Substring(0, lcs.Length - 1), paths, newPath); } }