/* * Method: deleteFavourite() * Summary: Deletes the currently highlighted favourite from the list * Parameter: sender - The control that the action is for, in this case the delete button * Parameter: e - The key event arguments */ private void deleteFavourite(object sender, EventArgs e) { // Iterate over the users favourites foreach (string rec in Properties.Settings.Default.favouriteRecordings.ToArray()) { if(rec != "") { // Instantiate the RecordingManager variable recording = new RecordingManager(rec); // If the highlighted recording matches one of the favourites if (Convert.ToString(recording.Title) == recordingsList.SelectedItem.ToString()) { // Delete the recording Properties.Settings.Default.favouriteRecordings.Remove(rec); BigMessageBox.Show("Removed from favourites"); // Refresh the the list and save the settings prepareList(); Properties.Settings.Default.Save(); break; } } } }
/* * Method: getRecordings() * Summary: Retrives the list of recordings stored on the server * Returns: A list of objects of type RecordingManager, used to populate the main list within the application */ public static List<RecordingManager> getRecordings() { // Prepare the GET HTTP request to the "recordings" endpoint prepareRequest(recordingUrl, "", "GET"); // Initialise the list to be returned by the function List<RecordingManager> dirContents = new List<RecordingManager>(); try { // Send the request and store the response in the response variable response = (HttpWebResponse)request.GetResponse(); using (var reader = new StreamReader(response.GetResponseStream())) { responseStr = reader.ReadToEnd(); } // Declare the recording variable RecordingManager recording; // Trim the unnecessary characters from the response string string responseStripped = string.Join("", responseStr.Split('"', '[', ']', ' ', '\n')); // Split the remaining contents at each "," and store the results as an array string[] responseSplit = responseStripped.Split(','); // Loop through the array elements and instantiate a recording variable for each element, add // them to the dirContents variable, assuming the element is not "." or "..", which are the // current and parent directory identifiers on the server foreach (string recname in responseSplit) { if (recname != "." && recname != "..") { string tempRec = getRecInfo(recname); recording = new RecordingManager(tempRec); dirContents.Add(recording); } } response.Close(); } // If there is an error, set the value of the dirContents variable to null catch (WebException we) { Console.WriteLine(we.Message); dirContents = null; } return dirContents; }
/* * Method: validateJson() * Summary: Validates whether or not a string in in the valid JSON format * Parameter: recJson - The string to be validated * Return: True or false depending on whether or not the recording is in the valid format */ public static bool validateJson(string recJson) { try { // Instantate the recording RecordingManager recording = new RecordingManager(recJson); // If the title or description are empty or non-existent if (recording.Title == null || recording.Title == "" || recording.Description == null || recording.Description == "") { return false; } // Store the inputJson string into a dynamic object dynamic jsonKeys = JsonConvert.DeserializeObject(recJson); // Iterate over the outer layer of the JSON string, in this instance it is the time keys of the JSON string foreach (dynamic key in jsonKeys) { // If the key is one of the information keys if (Convert.ToString(key.Name) == "Name" || Convert.ToString(key.Name) == "Desc" || Convert.ToString(key.Name) == "recId" || Convert.ToString(key.Name) == "userName" || Convert.ToString(key.Name) == "AuthorFirstname" || Convert.ToString(key.Name) == "AuthorSurname" || Convert.ToString(key.Name) == "UserId") { Console.WriteLine("Not time val"); } else { try { // Try and convert the key to a long long time = Convert.ToInt64(key.Name); } // If the key cannot be converted to a long catch (Exception e) { Console.WriteLine(e.Message); return false; } } } return true; } // If the instantiation fails catch (Exception e) { Console.WriteLine(e.Message); return false; } }
/* * Method: getRecId() * Summary: Extracts the ID from a recording * Parameter: recJson - The recording to retrive the ID of * Returns: A string containing the recording ID */ public static string getRecId(string recJson) { RecordingManager rec = new RecordingManager(recJson); return rec.Id; }
private void gotoPlayRec(object sender, TextEventArgs e) { if (e.json != "") { RecordingManager recording = new RecordingManager(e.json); tutorialPlayRec.recJson = e.json; tutorialPlayRec.currentRecTitle.Text = recording.Title; tutorialPlayRec.recTitle = e.name; } ClientSize = new Size(1000, 697); tutorialPlayRec.BringToFront(); CenterToScreen(); }
/* * Method: updateInfo() * Summary: Updates the recording information displayed */ private void updateInfo() { if (recJson != null && recJson != "") { // Instantiate a recording manager variable and extract the title, description and author recording = new RecordingManager(recJson); string title = recording.Title; string description = recording.Description; string author = recording.Author; if (recording.Title == "" || recording.Title == null) { title = "Unavailable"; } if (recording.Description == "" || recording.Description == null) { description = "Unavailable"; } recTitleLabel.Text = title; recDescLabel.Text = description; recAuthorLabel.Text = author; } }
/* * Summary: Updates the recording info with the currently selected one */ private void updateInfo(RecordingManager rec) { if (rec != null) { recTitleLabel.Text = rec.Title; recDescLabel.Text = rec.Description; recAuthorLabel.Text = rec.Author; } }
/* * Method: updateInfo() * Summary: Updates the recording information panel with the information on the currently selected recording * Parameter: sender - The control that the action is for * Parameter: e - Any arguments the method uses */ private void updateInfo(object sender, EventArgs e) { // Get the title of the active recording string activeRecTitle = recordingsList.SelectedItem.ToString(); // Find the recording in the recording list foreach(KeyValuePair<string, string> kvp in recList) { if(kvp.Key == activeRecTitle) { recJson = kvp.Value; } } string title = ""; string description = ""; if (recJson != "") { // Instantiate the RecordingManager variable recording = new RecordingManager(recJson); // If the recording title is null or empty if (recording.Title == "" || recording.Title == null) { title = "Unavailable"; } else { title = recording.Title; } // If the recording description is null or empty if (recording.Description == "" || recording.Description == null) { description = "Unavailable"; } else { description = recording.Description; } } // Set the labels to the recording title and information recTitleLabel.Text = title; recDescLabel.Text = description; }
/* * Method: prepareList() * Summary: Prepares the list of favourites */ private void prepareList() { // Initialise the list recList = new Dictionary<string, string>(); // Iterate over the stored local recordings foreach (string rec in Properties.Settings.Default.favouriteRecordings.ToArray()) { if (rec != "") { // Instantiate each recording in the favourites and add it to the recordings list recording = new RecordingManager(rec); if (!recList.ContainsKey(recording.Title)) { recList.Add(recording.Title, rec); } } } // If there are on favourites if(recList.Count == 0) { recList.Add("No favourites", ""); recTitleLabel.Text = "Unavailable"; recDescLabel.Text = "Unavailable"; } // Update the list with the keys in the dictionary recordingsList.DataSource = (from keys in recList.Keys select keys).ToList(); ActiveControl = recordingsList; object x = new object(); EventArgs y = new EventArgs(); updateInfo(x, y); }
/* * Method: deleteRec() * Summary: Deletes a recording from the server */ private void deleteRec(object sender, EventArgs e) { Cursor.Current = Cursors.WaitCursor; // If the user is not logged in if (Properties.Settings.Default.currentUser != "") { // Attempt to delete the recording if (ConnectionManager.deleteRecording(recJson)) { // Instantiate a RecordingManager class RecordingManager rec = new RecordingManager(recJson); // Iterate over the recordings and remove the one just deleted foreach (RecordingManager recording in recObjectList.ToArray()) { if (rec.Id == recording.Id) { BigMessageBox.Show("Deleted"); recObjectList.Remove(recording); } } } else { BigMessageBox.Show("You cannot delete recordings you did not create"); } } else BigMessageBox.Show("You must be logged in to delete recordings"); refreshList(); Cursor.Current = Cursors.Arrow; }