Exemple #1
0
        private void frmTextPad_Load(object sender, EventArgs e)
        {
            try
            {
                flowLayoutPanel.HorizontalScroll.Enabled = false;
                flowLayoutPanel.VerticalScroll.Enabled   = true;

                this.AllowDrop              = true;
                this.txtDocument.DragEnter += new DragEventHandler(txtDocument_DragEnter);
                this.txtDocument.DragDrop  += new DragEventHandler(txtDocument_DragDrop);

                System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;

                if (!Directory.Exists(Path.Combine(Application.StartupPath, "Documents")))
                {
                    Directory.CreateDirectory(Path.Combine(Application.StartupPath, "Documents"));
                }

                initTabUIforNewTab();
                label_Click(selectedLabel, null);

                loadAppSettings();
                initSignInTimer();
                DriveCommand.initGoogleService();
                initAutoSaveTimer();
            }
            catch (Exception)
            {
            }
        }
Exemple #2
0
 private void toolStripMenuIRemoveAccount_Click(object sender, EventArgs e)
 {
     try
     {
         if (DriveCommand.removeUserCredentials())
         {
             MessageBox.Show("Google Account removed successfully. Application will now restart and will ask for new login credentials.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
             Application.Restart();
         }
     }
     catch (Exception)
     {
     }
 }
Exemple #3
0
        private void saveToCloud()
        {
            this.Cursor = Cursors.WaitCursor;
            this.Text  += " - Uploading to google drive - Please wait...";
            System.Collections.Hashtable localTable = new System.Collections.Hashtable();

            try
            {
                SaveSelectedTabState();
            }
            catch (Exception)
            {
                throw;
            }

            try
            {
                List <int> listOfKeys = hashTableTabCollection.Keys.Cast <int>().ToList();

                for (int counter = 0; counter < listOfKeys.Count; counter++)
                {
                    int         key   = (int)listOfKeys[counter];
                    DocumentTab value = (DocumentTab)hashTableTabCollection[key];
                    Google.Apis.Drive.v2.Data.File currentJobFile = null;
                    System.IO.MemoryStream         stream;
                    stream = new System.IO.MemoryStream(Encoding.Default.GetBytes(value.content));

                    if (value.currentJobFile != null)
                    {
                        if (value.title.Trim() != string.Empty)
                        {
                            currentJobFile = DriveCommand.updateFile(value.currentJobFile.Id, value.title.Trim(), stream, value.currentJobFile.OriginalFilename, true);
                        }
                        else
                        {
                            currentJobFile = DriveCommand.updateFile(value.currentJobFile.Id, value.currentJobFile.Title, stream, value.currentJobFile.OriginalFilename, true);
                        }
                    }
                    else
                    {
                        if (validateDocument(value))
                        {
                            DriveCommand.createFile(value.title.Trim(), stream, out currentJobFile);

                            localTable.Add(key, currentJobFile);
                        }
                        else
                        {
                            string TopicName = value.textContent.Trim();

                            if (TopicName.Length > 10)
                            {
                                TopicName = TopicName.Substring(0, 10);
                                DriveCommand.createFile(TopicName, stream, out currentJobFile);

                                localTable.Add(key, currentJobFile);
                            }
                            else
                            {
                                MessageBox.Show("Please enter 10 or more characters to save the document when title is not provided.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                        }
                    }
                }

                foreach (int key in localTable.Keys)
                {
                    if (hashTableTabCollection.ContainsKey(key))
                    {
                        DocumentTab dTab = (DocumentTab)hashTableTabCollection[key];
                        dTab.currentJobFile         = (Google.Apis.Drive.v2.Data.File)localTable[key];
                        hashTableTabCollection[key] = dTab;
                    }
                }
            }
            catch (Exception)
            {
            }

            #region Single File Code
            //try
            //{
            //    System.IO.MemoryStream stream;
            //    stream = new System.IO.MemoryStream(Encoding.Default.GetBytes(txtDocument.Rtf));


            //    if (DriveCommand.currentJobFile != null)
            //    {
            //        if (txtTopic.Text.Trim() != string.Empty)
            //            DriveCommand.updateFile(DriveCommand.currentJobFile.Id, txtTopic.Text.Trim(), stream, DriveCommand.currentJobFile.OriginalFilename, true);
            //        else
            //            DriveCommand.updateFile(DriveCommand.currentJobFile.Id, DriveCommand.currentJobFile.Title, stream, DriveCommand.currentJobFile.OriginalFilename, true);
            //    }
            //    else
            //    {
            //        if (validateDocument())
            //            DriveCommand.createFile(txtTopic.Text.Trim(), stream);
            //        else
            //        {
            //            string TopicName = txtDocument.Text.TrimStart();

            //            if (TopicName.Length > 10)
            //            {
            //                TopicName = TopicName.Substring(0, 10);
            //                DriveCommand.createFile(TopicName, stream);
            //            }
            //            else
            //            {
            //                MessageBox.Show("Please enter 10 or more characters to save the document when title is not provided.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
            //            }
            //        }
            //    }
            //}
            //catch (Exception)
            //{
            //}
            #endregion

            this.Text   = this.Text.Replace(" - Uploading to google drive - Please wait...", string.Empty);
            this.Cursor = Cursors.Arrow;
        }