private void mnuListExcudeDoc_Click(object sender, EventArgs e) { FileState fs = (FileState)lvwChanges.SelectedItems[0].Tag; try { excludedFiles.Add(fs.id, fs); saveExcludes(); doCheck(); } catch (Exception) { // Do nothing here - we'd just be adding a duplicate } }
public void addOpenFileToTaskBard(int itemNo, FileState fs) { if (itemNo == 0) { // Need to clear down old items //int menuCount = 2; while (mnuTaskBar.Items[3].Text != "") { mnuTaskBar.Items.RemoveAt(3); } } ToolStripMenuItem mnu = new ToolStripMenuItem(fs.name, null, mnuFileOpen); mnu.Tag = fs; mnuTaskBar.Items.Insert(3 + itemNo, mnu); }
/// <summary> /// Open currently selected document in google docs in browser /// </summary> private void openDoc(FileState fs = null) { string strURL = "https://drive.google.com/"; if (fs is null) { if (lvwChanges.SelectedItems.Count > 0) { fs = (FileState)lvwChanges.SelectedItems[0].Tag; } } if (fs is null) { return; } else { if (fs.editURL != null) { strURL = fs.editURL.ToString().Split('|')[0]; } System.Diagnostics.Process.Start(strURL); } }
public void checkChanges() { bool blPaused = NotificationsPaused(); string strDocsChanged = ""; tmrCheck.Stop(); log("Checking changes", 5); if (credential == null) { getCredentials(); } // Create Drive API service. var service = new DriveService(new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = ApplicationName, }); // List files. FilesResource.ListRequest listRequest = service.Files.List(); listRequest.Fields = "nextPageToken, files(id, name, lastModifyingUser(displayName), modifiedTime, parents, trashed, webViewLink)"; var response = listRequest.Execute(); IList <Google.Apis.Drive.v3.Data.File> files = response.Files; Console.WriteLine("Files:"); //List<ToastContentBuilder> lstToasts = new List<ToastContentBuilder>(); string strDocChangeKey = ""; if (files != null && files.Count > 0) { foreach (var file in files) { FileState fileState = null; if (driveState.FileStates.ContainsKey(file.Id)) { fileState = driveState.FileStates[file.Id]; } // Determine if we know who last edited the file string lastEditBy = "Unknown"; if (file.LastModifyingUser != null && file.LastModifyingUser.DisplayName != null) { lastEditBy = file.LastModifyingUser.DisplayName; } bool blnShowToast = (fileState == null || file.ModifiedTime > fileState.lastEditWhen.AddSeconds(Properties.Settings.Default.CheckSeconds * 5) || fileState.lastEditBy != lastEditBy); updateFileState(file); if (file.ModifiedTime > datLast && !excludedFiles.ContainsKey(file.Id) && Properties.Settings.Default.MyName != lastEditBy) { // If this is a new file or the file hasn't been edited in a while or the file has been edited by someone new then notify if (blnShowToast && !blPaused) { // Build the basic toast config ToastContentBuilder tst = new ToastContentBuilder() .AddArgument("action", "viewFile") .AddArgument("fileId", file.Id) .AddArgument("url", file.WebViewLink) .AddText(file.Name); // Set the toast duration based on settings. if (Properties.Settings.Default.LongNotification) { tst = tst.SetToastDuration(ToastDuration.Long); } else { tst = tst.SetToastDuration(ToastDuration.Short); } // Try and set the EditBy and modified time. try { tst = tst.AddCustomTimeStamp((DateTime)file.ModifiedTime); if (file.ModifiedTime.Value.Date == DateTime.Now.Date) { tst = tst.AddAttributionText(lastEditBy + " @ " + string.Format("{0:HH:mm}", file.ModifiedTime.Value)); } else { tst = tst.AddAttributionText(lastEditBy + " @ " + string.Format("{0:HH:mm dd/MM/yyyy}", file.ModifiedTime.Value)); } } catch (Exception) { // We failed so just set the EditBy tst = tst.AddAttributionText(lastEditBy); } // Display the toast tst.Show(); } //lstToasts.Add(tst); strDocChangeKey += file.Name + "|" + lastEditBy + "|"; if (file.Name.Length > 35) { strDocsChanged += file.Name.Substring(0, 34) + Environment.NewLine; } else { strDocsChanged += file.Name + Environment.NewLine; } setIcon("red"); } log(file.Name, 10); } } else { log("No files found.", 10); } if (strDocChangeKey != "") { if (Properties.Settings.Default.WindowsNotifications && strDocChangeKey != strLastTip) { strLastTip = strDocChangeKey; //foreach (ToastContentBuilder tst in lstToasts) //{ // tst.Show(); //} } if (strDocsChanged.Length > 64) { nfyIcon.Text = strDocsChanged.Substring(0, 63); } else { nfyIcon.Text = strDocsChanged; } } else { strLastTip = ""; nfyIcon.Text = "No changes"; } saveState(); showFiles(); tmrCheck.Interval = Properties.Settings.Default.CheckSeconds * 1000; tmrCheck.Start(); }