Beispiel #1
0
 /// <summary>
 /// Lädt die gespeicherten Standards in die Form
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnRestoreDefaults_Click(object sender, EventArgs e)
 {
     if (Supporter.AreDefaultsValid())
     {
         RestoreDefault();
     }
 }
Beispiel #2
0
        /// ------------------------------------------------------------------------------------------------------------------------
        /// <summary>
        /// Schreibt Änderungen in die Datei
        /// </summary>
        public void WriteArrays()
        {
            try
            {
                List <string> lines = new List <string>();

                for (int i = 0; i < TokenIDs.Length; i++)
                {
                    lines.Add(TokenNames[i]);
                    lines.Add(TokenIDs[i]);
                }
                Supporter.ClearGarbageContainer();
                File.WriteAllLines(TokenFilePath, lines);
            }
            catch (System.Exception e)
            {
                DialogResult result = MessageBox.Show(e.Message, "Error while writing!", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
                if (result == DialogResult.Retry)
                {
                    Supporter.ClearGarbageContainer();
                    WriteArrays();
                }
            }
            // ToDo: GoogleDrive-Upload
        }
Beispiel #3
0
        private void btnGoogleDriveDirectLink_Click(object sender, EventArgs e)
        {
            InputMessageBox directLink = new InputMessageBox("Get GoogleDrive-directLink", "Insert your sharing-link", string.Empty, Resources.GoogleDrive128, false);

            directLink.ShowDialog();
            if (Settings.Default.lastInputCorrect)
            {
                string link = Supporter.GetGoogleDriveDirectLink(Settings.Default.lastInputString);
                if (Settings.Default.lastInputCorrect)
                {
                    DialogResult result = MessageBox.Show("Do you want to use this directlink as new fileURL?\r\nOtherwise it will be copied to your clipboard", "Success", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (result == DialogResult.Yes)
                    {
                        Settings.Default.fileURL = link;
                    }
                    else
                    {
                        Clipboard.SetText(link);
                    }
                }
                else
                {
                    MessageBox.Show("There was an error with the sharinglink.\r\nYou will be redirected to a website...", "Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Supporter.OpenBrowser("https://sites.google.com/site/gdocs2direct/");
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// Setzt den Log-Datei-Pfad
        /// </summary>
        /// <param name="withDefault"></param>
        public void SetLogPath(bool withDefault = false)
        {
            InputMessageBox filePath = new InputMessageBox("Path of Log-File", "Insert your filepath", Settings.Default.logFilePath, Resources.Pencil128, /*"RequestLog.xml",*/ true);

            filePath.ShowDialog();
            if (Settings.Default.lastInputCorrect)
            {
                LogFilePath = Supporter.BuildPath(Settings.Default.lastInputString, Settings.Default.SettingUseJSON, "RequestLog");
                if (!File.Exists(LogFilePath))
                {
                    if (Directory.Exists(Path.GetDirectoryName(LogFilePath)))
                    {
                        File.Create(LogFilePath);
                    }
                    else
                    {
                        HelpUser(1);
                        return;
                    }
                }
                Settings.Default.logFilePath = LogFilePath;
                Settings.Default.Save();
            }
            else
            {
                if (withDefault)
                {
                    string path = Application.StartupPath + @"\RequestLog.txt";
                    LogFilePath = path;
                }
            }
        }
Beispiel #5
0
        /// ------------------------------------------------------------------------------------------------------------------------
        /// <summary>
        /// Read-Decider (Online/Offline)
        /// </summary>
        public void DecideArrays(bool startUp = true)
        {
            string path = Supporter.BuildPath(Settings.Default.filePath, Settings.Default.SettingUseJSON);

            if (!Settings.Default.SettingUseLocalFile)
            {
                try
                {
                    Networker.DownloadFile(2, startUp);
                }
                catch (Exception)
                {
                    Settings.Default.SettingUseLocalFile = true;
                    DecideArrays(startUp);
                }
            }

            if (Settings.Default.SettingUseJSON)
            {
                TryReadJSONArrays(path);
            }
            else
            {
                TryReadArrays(path);
            }
        }
Beispiel #6
0
        /// <summary>
        /// Setzt den Token-Datei-Pfad
        /// </summary>
        /// <param name="withDefault"></param>
        public void SetTokenPath(bool withDefault = false)
        {
            InputMessageBox filePath = new InputMessageBox("Path of Token-File", "Insert your filepath", Settings.Default.filePath, Resources.Document128, /*"Tokens.xml",*/ true);

            filePath.ShowDialog();
            if (Settings.Default.lastInputCorrect)
            {
                TokenFilePath = Supporter.BuildPath(Settings.Default.lastInputString, Settings.Default.SettingUseJSON, "Tokens");
                if (!File.Exists(TokenFilePath))
                {
                    if (Directory.Exists(Path.GetDirectoryName(TokenFilePath)))
                    {
                        File.Create(TokenFilePath);
                    }
                    else
                    {
                        HelpUser(0);
                        return;
                    }
                }
                Settings.Default.filePath = TokenFilePath;
                Settings.Default.Save();
            }
            else
            {
                if (withDefault)
                {
                    string path = Application.StartupPath + @"\Tokens.txt";
                    TokenFilePath = path;
                }
            }
        }
Beispiel #7
0
 /// <summary>
 /// Event für den Offline-Modus
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void ChoiceButton1_Click(object sender, EventArgs e)
 {
     webExceptionDialog.Close();
     Settings.Default.SettingUseLocalFile = true;
     Settings.Default.Save();
     Supporter.ClearGarbageContainer();
     Application.Restart();
 }
Beispiel #8
0
        /// <summary>
        ///
        /// </summary>
        public string CheckDataMode(bool isJSON)
        {
            string path = TokenFilePath;

            if (Supporter.FileIsJSON(path) != isJSON)
            {
                Settings.Default.filePath = Supporter.BuildPath(path, isJSON);
            }
            CheckFiles();
            return(Settings.Default.filePath);
        }
Beispiel #9
0
 private void FormatToJSON()
 {
     if (Settings.Default.SettingUseJSON)
     {
         richTextBoxPreview.Text = Settings.Default.SettingUseLocalFile ? Supporter.FormatJson(File.ReadAllText(Settings.Default.filePath)) : File.ReadAllText(Settings.Default.filePath);
     }
     else
     {
         richTextBoxPreview.Text = File.ReadAllText(Settings.Default.filePath);
     }
 }
Beispiel #10
0
 private void checkBoxShowDownloadedContent_CheckedChanged(object sender, EventArgs e)
 {
     if (checkBoxShowDownloadedContent.Checked)
     {
         richTextBoxPreview.Text    = Supporter.FormatJson(File.ReadAllText(Settings.Default.filePath));
         richTextBoxPreview.Visible = true;
     }
     else
     {
         richTextBoxPreview.Visible = false;
     }
 }
Beispiel #11
0
        /// <summary>
        /// Baut das ContextMenu für FrmVariables
        /// </summary>
        /// <returns></returns>
        private ContextMenuStrip BuildVariablesContextMenu()
        {
            dataStore.var = Supporter.ExtraxtParams(listBoxVariables.SelectedItem.ToString());
            //ToolStripMenuItem insertAtCursor = new ToolStripMenuItem("Insert", Resources.Rename24);
            //insertAtCursor.Click += InsertAtCursor_Click;
            ToolStripMenuItem copyToClipboard = new ToolStripMenuItem("Copy", Resources.Clipboard24);

            copyToClipboard.Click += CopyToClipboard_Click;
            ContextMenuStrip menu = new ContextMenuStrip();

            //menu.Items.Add(insertAtCursor);
            menu.Items.Add(copyToClipboard);
            return(menu);
        }
Beispiel #12
0
        /// <summary>
        /// Checkt, ob Notify lauffähig ist und verändert 'NotifyIsExecutable' dementsprechend.
        /// </summary>
        /// <param name="focus"></param>
        /// <returns></returns>
        public bool CheckStatus(bool focus = false)
        {
            // FilePath
            // LogPath
            // FileURL
            // UserToken
            // UserTokenList
            // Defaults
            List <bool> configList = new List <bool>();

            configList.Add(File.Exists(Settings.Default.filePath));
            configList.Add(File.Exists(Settings.Default.logFilePath));
            configList.Add(Settings.Default.SettingUseLocalFile ? true : !string.IsNullOrEmpty(Settings.Default.fileURL));
            configList.Add(!string.IsNullOrEmpty(Settings.Default.userToken));
            configList.Add(TokenIDs.Length >= 1);
            configList.Add(Supporter.AreDefaultsValid());
            if (focus)
            {
                for (int i = 0; i < configList.Count; i++)
                {
                    if (!configList[i])
                    {
                        HelpUser(i);
                    }
                }
                foreach (bool configItem in configList)
                {
                    if (!configItem)
                    {
                        NotifyIsExecutable = false;
                    }
                }
                NotifyIsExecutable = true;
                return(true);
            }
            else
            {
                foreach (bool configItem in configList)
                {
                    if (!configItem)
                    {
                        NotifyIsExecutable = false;
                    }
                    return(false);
                }
                NotifyIsExecutable = true;
                return(true);
            }
        }
Beispiel #13
0
        /// <summary>
        /// Feuert den Konfigurierten Request
        /// </summary>
        /// <param name="title">Titel des POSTs</param>
        /// <param name="body">Textkörper des POSTs</param>
        /// <param name="htmlEnabled">HTML Aktivieren/Deaktivieren</param>
        /// <param name="variablesEnabled">Variablen Aktivieren/Deaktivieren</param>
        /// <param name="tokenIndex">Index des ausgewählten Tokens</param>
        /// <param name="tokenEnabled">Ausgewählter Token/Standard-Token</param>
        /// <param name="priorityIndex">Index der ausgewählten Priorität</param>
        /// <param name="priorityEnabled">Ausgewählte Priorität/Standard-Priorität</param>
        public static bool FireRequest(string title, string body, bool htmlEnabled, bool variablesEnabled, int tokenIndex, bool tokenEnabled, int priorityIndex, bool priorityEnabled)
        {
            string calculatedUser      = dataStore.UserToken;
            string calculatedTitle     = variablesEnabled ? Supporter.FormatText(title) : title;
            string calculatedBody      = variablesEnabled ? Supporter.FormatText(body) : body;
            string calculatedToken     = tokenEnabled ? dataStore.GetTokenByIndex(tokenIndex) : dataStore.GetDefaultToken();
            string calculatedPriority  = priorityEnabled ? dataStore.GetPriority(priorityIndex) : "0";
            string calculatedHtml      = htmlEnabled ? "1" : "0";
            string calculatedTimestamp = Supporter.GetUnixTimestamp(TimeZone.CurrentTimeZone.GetUtcOffset(new DateTime()).Hours).ToString();
            string jsonString;

            byte[]     jsonBytes;
            RequestDAO response = new RequestDAO();

            var parameters = new NameValueCollection // Building components...
            {
                { "user", calculatedUser },
                { "title", calculatedTitle },
                { "message", calculatedBody },
                { "token", calculatedToken },
                { "priority", calculatedPriority },
                { "html", calculatedHtml },
                { "timestamp", calculatedTimestamp },
            };

            try
            {
                using (var client = new WebClient())
                {
                    //client.UploadValuesCompleted += Client_UploadValuesCompleted; // sending...
                    //client.UploadValuesAsync(new Uri("https://api.pushover.net/1/messages.json"), parameters);
                    jsonBytes  = client.UploadValues(new Uri("https://api.pushover.net/1/messages.json"), parameters);
                    jsonString = Encoding.ASCII.GetString(jsonBytes);
                    response   = JsonConvert.DeserializeObject <RequestDAO>(jsonString);
                    dataStore.LogTransaction(calculatedTitle, calculatedBody, calculatedUser, tokenIndex, priorityIndex, response.request); // logging...
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Something went wrong...\r\n" + e.Message, "Error while request", MessageBoxButtons.OK, MessageBoxIcon.Error);
                RequestErrorProvider(e.Message);
                return(false);
            }

            return(response.GetStatus());
        }
Beispiel #14
0
 /// ------------------------------------------------------------------------------------------------------------------------
 /// <summary>
 /// Schreibt Änderungen in die Datei
 /// </summary>
 public void WriteJSONArrays()
 {
     try
     {
         FillArrays();
         string jsonString = JsonConvert.SerializeObject(TokenJSONList);
         Supporter.ClearGarbageContainer();
         File.WriteAllText(TokenFilePath, jsonString);
     }
     catch (System.Exception e)
     {
         DialogResult result = MessageBox.Show(e.Message, "Error while writing!", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
         if (result == DialogResult.Retry)
         {
             Supporter.ClearGarbageContainer();
             WriteArrays();
         }
     }
     // ToDo: GoogleDrive-Upload
 }
Beispiel #15
0
        ///// <summary>
        /////
        ///// </summary>
        //private void CreateDefaultArrays() // ToDo: Rausnehmen
        //{
        //    string[] nameArray =
        //        {
        //    "Notification.Default",
        //    "Ibo.Food.Order",
        //    "Ibo.Food.Success",
        //    "Pc.Started",
        //    "Ibo.Cake",
        //    "EMail.Inbox",
        //    "EMail.Private"
        //        };

        //    string[] tokenArray =
        //        {
        //        "aCbwemDsa3rwWmtqj1BGsecNVgjPK4",
        //    "arZjan33BPf5tQB9DHZCwA4kKXLEsT",
        //    "aygTN3PH58fh1VqRS2zdq5V2o858qH",
        //    "afh6e5289QD1X8efymoDZXunWoPmRb",
        //    "apGMNL9qgxeQVKdCR4crdE7GsstgY3",
        //    "aPbXdi9KALc6dqooGk2SPqJCnTaUdn",
        //    "abyYLX4tp5vdf6jK2XsEnShWNBjyar"
        //        };

        //    List<string> names = new List<string>(nameArray);
        //    List<string> tokens = new List<string>(tokenArray);
        //    names.AddRange(nameArray);
        //    tokens.AddRange(tokenArray);
        //    TokenNames = names.ToArray();
        //    TokenIDs = tokens.ToArray();
        //}

        /// <summary>
        /// Liefert die angeforderte Variable zurück
        /// </summary>
        /// <returns>The variable.</returns>
        /// <param name="expression">Expression.</param>
        public string GetVariable(string expression)
        {
            if (expression == Variables[0]) // Die Systemzeit
            {
                return(string.Format("{0} {1}", DateTime.Now.ToShortTimeString(), Supporter.GetAM(DateTime.Now)));
            }
            else if (expression == Variables[1]) // Das Systemdatum als zahlenfolge
            {
                return(DateTime.Now.ToShortDateString());
            }
            else if (expression == Variables[2]) // Das Systemdatum als Text
            {
                return(DateTime.Now.ToLongDateString());
            }
            else if (expression == Variables[3]) // Systemzeit & datum
            {
                return(string.Format("{0} {1}", DateTime.Now.ToLongDateString(), string.Format("{0} {1}", DateTime.Now.ToShortTimeString(), Supporter.GetAM(DateTime.Now))));
            }
            else if (expression == Variables[4]) // Angemeldeter Nutzer
            {
                return(Environment.UserName);
            }
            else if (expression == Variables[5]) // Domain
            {
                return(Environment.UserDomainName);
            }
            else if (expression == Variables[6]) // Computer
            {
                return(Environment.MachineName);
            }
            else if (expression == Variables[7]) // Domain & Angemeldeter Benutzer
            {
                return(System.Security.Principal.WindowsIdentity.GetCurrent().Name);
            }
            else
            {
                return(string.Empty);
            }
        }
Beispiel #16
0
 private void UpdateListBox(int index, bool itemSwitch)
 {
     if (!itemSwitch)
     {
         if (index >= 0)
         {
             dataStore.TokenNames[index] = (textBoxName.Text == string.Empty && !Supporter.ArrayContains(dataStore.TokenNames, textBoxName.Text)) ? dataStore.TokenNames[index] : textBoxName.Text;
             dataStore.TokenIDs[index]   = (textBoxToken.Text == string.Empty && !Supporter.ArrayContains(dataStore.TokenIDs, textBoxToken.Text)) ? dataStore.TokenIDs[index] : textBoxToken.Text;
             listBox.Items[index]        = string.Format("{0} - {1}", dataStore.TokenNames[index], dataStore.TokenIDs[index]);
         }
     }
     itemSwitch = false;
 }
Beispiel #17
0
 private void SetUpUser(string token, string secret)
 {
     if (Settings.Default.userToken == string.Empty) // Neu erstellen
     {
         Settings.Default.userToken  = token;
         Settings.Default.userSecret = secret;
         LoginLabel(true);
     }
     else if (Settings.Default.userToken != string.Empty && Settings.Default.userToken != token) // Vorhandenen überschreiben
     {
         DialogResult result = MessageBox.Show("Override the existing account?\r\n" + Settings.Default.userToken, "Existing UserToken", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk);
         if (result == DialogResult.Yes)
         {
             Settings.Default.userToken  = token;
             Settings.Default.userSecret = secret;
             LoginLabel(true);
         }
         else
         {
             return;
         }
     }
     else
     {
         LoginLabel(true);
     }
     labelUser.Text = Settings.Default.loginName;
     labelDate.Text = string.Format("{0} {1}", Settings.Default.loginDate.ToLongDateString(), string.Format("{0} {1}", Settings.Default.loginDate.ToShortTimeString(), Supporter.GetAM(Settings.Default.loginDate)));
     Settings.Default.userIsLoggedIn = true;
     SwitchLogStatus(true);
     Settings.Default.Save();
 }
Beispiel #18
0
 private void pictureBox1_DoubleClick(object sender, EventArgs e)
 {
     Supporter.OpenBrowser("https://pushover.net/api");
 }