Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            AppDomain.CurrentDomain.SetData("DataDirectory", Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Data"));
            Settings.ChangeAppConfig(Settings.SettingsFile);

            // For the sake of this example, we're just printing the arguments to the console.

            /*
             * for (int i = 0; i < args.Length; i++)
             * {
             *  MessageBox.Show("args["+ i + "] == " + args[i]);
             * }
             */

            Logger.SetLogger();

            if (Updater.UpdateAvailable())
            {
                Logger.Write("Loading Updater GUI...");
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Updater());
                return;
            }

            FoldersFilesAndPaths.StartUpCheck();
            Settings.StartUpCheck();
            Database.StartUpCheck();

            if (!String.IsNullOrWhiteSpace(Settings.Get <string>("PremiumEmail")) &&
                !String.IsNullOrWhiteSpace(Settings.Get <string>("PremiumKey")))
            {
                Premium.CheckAutomatic();
            }

            if (!Settings.IsPremium && Process
                .GetProcessesByName(
                    Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetEntryAssembly().Location))
                .Length > 1)
            {
                Logger.Write(
                    "DealReminder läuft bereits....Multi Instanzen nur mit Premium möglich...");
                MessageBox.Show(@"DealReminder läuft bereits!" + Environment.NewLine +
                                @"Nur mit Premium sind keine mehrfach Instanzen von DealReminder erlaubt!" +
                                Environment.NewLine +
                                @"Diese DealReminder Instanz wird beendet!",
                                @"DealReminder für Amazon", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();
            }

            //Browser Link zum Premium Kaufen
            //if (!Settings.IsPremium)
            //WebUtils.OpenBrowser("http://amzn.to/2rPwKP1");

            Logger.Write("Loading Main GUI...");
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Main());
        }
Ejemplo n.º 2
0
        public static async Task DoRemindWhenPossible(string productid)
        {
            Database.OpenConnection();
            var getReminderEntrys =
                new SQLiteCommand("SELECT * FROM Reminders INNER JOIN Products ON Products.ID = Reminders.ProductID WHERE Reminders.ProductID = @productid AND (Reminders.[Erinnerung Gesendet] IS NULL OR Reminders.[Erinnerung Gesendet] < @datetime)",
                                  Database.Connection);

            getReminderEntrys.Parameters.AddWithValue("@productid", productid);
            getReminderEntrys.Parameters.AddWithValue("@datetime", DateTime.Now.AddMinutes(-Settings.Get <int>("RemindResendAfterMinutes")).ToString("yyyy-MM-dd HH:mm:ss"));
            using (SQLiteDataReader remind = getReminderEntrys.ExecuteReader())
            {
                List <string> remindsToSend = new List <string>();
                while (remind.Read())
                {
                    Logger.Write("Erinnerungen gefunden für ProductID: " + productid + " mit dem Erinnerungspreis: " + remind["Preis"], LogLevel.Debug);

                    List <string> conditions = new List <string>();
                    Convert.ToString(remind["Zustand"]).TrimEnd().Split(',')
                    .ToList()
                    .ForEach(item =>
                    {
                        if (String.IsNullOrWhiteSpace(Convert.ToString(remind["Preis: " + item])) || Convert.ToDecimal(remind["Preis: " + item]) > Convert.ToDecimal(remind["Preis"]))
                        {
                            return;
                        }
                        remindsToSend.Add(item + ": " + Convert.ToString(remind["Preis: " + item]));
                        conditions.Add(item);
                        Logger.Write("Treffer zur Erinnerung hinzugefügt: " + item + ": " + Convert.ToString(remind["Preis: " + item]), LogLevel.Debug);
                    });

                    if (remindsToSend.Any())
                    {
                        /* Erstellt einen neuen Warenkorb
                         * var catInfo = AmazonApi.CreateCart("DE", "B00YUIM2J0");
                         * if (catInfo?.Cart.PurchaseURL != null)
                         * {
                         *  Debug.WriteLine(catInfo?.Cart.PurchaseURL);
                         * }
                         */

                        string shortUrl = Settings.Get <bool>("ShowOnlyDealConditions")
                            ? await URLShortener.Generate(Amazon.MakeReferralLink(Convert.ToString(remind["Store"]),
                                                                                  Convert.ToString(remind["ASIN / ISBN"]), conditions))
                            : null;

                        shortUrl = shortUrl ?? Convert.ToString(remind["URL"]);

                        string notificationText = remind["Name"] + "\n" +
                                                  "Store: " + remind["Store"] + " - ASIN/ISBN: " +
                                                  remind["ASIN / ISBN"] + "\n\n" +
                                                  "Erinnerungs Preis: " + remind["Preis"] + "\n\n" +
                                                  "Aktuelle Amazon Preise:\n";
                        remindsToSend.ForEach(i => notificationText += i + "\n");
                        notificationText += "\nLink: " + shortUrl;

                        if (!String.IsNullOrWhiteSpace(Convert.ToString(remind["Telegram"])))
                        {
                            await TelegramApi.SendMessage(Convert.ToString(remind["Telegram"]), notificationText);
                        }

                        if (!String.IsNullOrWhiteSpace(Convert.ToString(remind["Email"])))
                        {
                            await Mail.NotificationSend(Convert.ToString(remind["Email"]), notificationText,
                                                        Convert.ToString(remind["Name"]));
                        }

                        Database.OpenConnection();
                        SQLiteCommand updateRemind =
                            new SQLiteCommand(
                                "UPDATE Reminders SET [Erinnerung Gesendet] = @lastsend WHERE ID = @id",
                                Database.Connection);
                        updateRemind.Parameters.AddWithValue("@id", remind["ID"]);
                        updateRemind.Parameters.AddWithValue("@lastsend", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                        updateRemind.ExecuteNonQuery();

                        Display();
                    }
                }
            }
        }