Exemplo n.º 1
0
 public LogRequest(string ip, string method, URLShortener uRL)
 {
     DateRequest     = DateTime.Now;
     UserHostAddress = ip;
     Method          = method;
     UrlShortener_fk = uRL.Id;
 }
Exemplo n.º 2
0
        public UploadResult ShortenURL(string url)
        {
            URLShortener urlShortener = null;

            switch (Info.TaskSettings.URLShortenerDestination)
            {
            case UrlShortenerType.BITLY:
                if (Program.UploadersConfig.BitlyOAuth2Info == null)
                {
                    Program.UploadersConfig.BitlyOAuth2Info = new OAuth2Info(APIKeys.BitlyClientID, APIKeys.BitlyClientSecret);
                }

                urlShortener = new BitlyURLShortener(Program.UploadersConfig.BitlyOAuth2Info);
                break;

            case UrlShortenerType.Google:
                urlShortener = new GoogleURLShortener(Program.UploadersConfig.GoogleURLShortenerAccountType, APIKeys.GoogleAPIKey,
                                                      Program.UploadersConfig.GoogleURLShortenerOAuth2Info);
                break;

            case UrlShortenerType.ISGD:
                urlShortener = new IsgdURLShortener();
                break;

            /*case UrlShortenerType.THREELY:
             * urlShortener = new ThreelyURLShortener(Program.ThreelyKey);
             * break;*/
            case UrlShortenerType.TINYURL:
                urlShortener = new TinyURLShortener();
                break;

            case UrlShortenerType.TURL:
                urlShortener = new TurlURLShortener();
                break;

            case UrlShortenerType.YOURLS:
                urlShortener = new YourlsURLShortener
                {
                    APIURL    = Program.UploadersConfig.YourlsAPIURL,
                    Signature = Program.UploadersConfig.YourlsSignature,
                    Username  = Program.UploadersConfig.YourlsUsername,
                    Password  = Program.UploadersConfig.YourlsPassword
                };
                break;

            case UrlShortenerType.CustomURLShortener:
                if (Program.UploadersConfig.CustomUploadersList.IsValidIndex(Program.UploadersConfig.CustomURLShortenerSelected))
                {
                    urlShortener = new CustomURLShortener(Program.UploadersConfig.CustomUploadersList[Program.UploadersConfig.CustomURLShortenerSelected]);
                }
                break;
            }

            if (urlShortener != null)
            {
                return(urlShortener.ShortenURL(url));
            }

            return(null);
        }
Exemplo n.º 3
0
        public void ShortPath_is_long(string str)
        {
            var uss = new URLShortener();

            var result = uss.Decode(str);

            Assert.IsInstanceOf <long>(result);
        }
Exemplo n.º 4
0
        public void SampleId_is_shortened(long aliasId)
        {
            var uss = new URLShortener();

            var result = uss.Encode(aliasId);

            Assert.Less(result.Length, aliasId.ToString().Length);
            Assert.IsInstanceOf <string>(result);
        }
Exemplo n.º 5
0
        // Show the short URL in the window after the long URL has been converted
        private void Shorten_URL(object sender, RoutedEventArgs e)
        {
            shortURL.Text = URLShortener.ShortenURL(longURL.Text);

            // The short URL was retrieved successfully
            if (shortURL.Text.Length > 0)
            {
                copy.Visibility  = System.Windows.Visibility.Visible;
                clear.Visibility = System.Windows.Visibility.Visible;
            }
        }
Exemplo n.º 6
0
 public void Update(URLShortener uRL)
 {
     try
     {
         _context.Urls.Update(uRL);
         _context.SaveChanges();
     }
     catch (Exception)
     {
     }
 }
Exemplo n.º 7
0
        public async Task <IActionResult> CreateURL([FromBody] CreateURLRequest request)
        {
            try
            {
                string normalizedLongUrl = URLNormalizer.Normalize(request.URL);

                if (!string.IsNullOrEmpty(request.CustomPath))
                {
                    if (!Uri.IsWellFormedUriString(request.CustomPath, UriKind.Relative))
                    {
                        return(BadRequest("Invalid custom URL"));
                    }
                    var custom = await Context.URLs.FindAsync(request.CustomPath);

                    if (custom != null || Reserved.Contains(request.CustomPath.ToLower()))
                    {
                        return(BadRequest("URL identifier already exists"));
                    }
                    else
                    {
                        var newCustomUrl = await AddURLToDatabase(request.CustomPath, normalizedLongUrl);

                        return(CreatedAtAction(nameof(CreateURL), newCustomUrl));
                    }
                }

                var existingUrl = await Context.URLs.FirstOrDefaultAsync(x => x.LongURL == normalizedLongUrl);

                if (existingUrl != null)
                {
                    return(Ok(existingUrl));
                }

                var    random = new Random();
                string shortUrlId;
                do
                {
                    var randomId = random.Next();
                    shortUrlId = URLShortener.Encode(randomId);
                } while (await Context.URLs.FindAsync(shortUrlId) != null);

                var newUrl = await AddURLToDatabase(shortUrlId, normalizedLongUrl);

                return(CreatedAtAction(nameof(CreateURL), newUrl));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Exemplo n.º 8
0
        public UploadResult ShortenURL(string url)
        {
            URLShortener urlShortener = null;

            switch (Info.TaskSettings.URLShortenerDestination)
            {
            case UrlShortenerType.BITLY:
                urlShortener = new BitlyURLShortener(ApiKeys.BitlyLogin, ApiKeys.BitlyKey);
                break;

            case UrlShortenerType.Google:
                urlShortener = new GoogleURLShortener(Program.UploadersConfig.GoogleURLShortenerAccountType, ApiKeys.GoogleAPIKey,
                                                      Program.UploadersConfig.GoogleURLShortenerOAuth2Info);
                break;

            case UrlShortenerType.ISGD:
                urlShortener = new IsgdURLShortener();
                break;

            case UrlShortenerType.Jmp:
                urlShortener = new JmpURLShortener(ApiKeys.BitlyLogin, ApiKeys.BitlyKey);
                break;

            /*case UrlShortenerType.THREELY:
             * urlShortener = new ThreelyURLShortener(Program.ThreelyKey);
             * break;*/
            case UrlShortenerType.TINYURL:
                urlShortener = new TinyURLShortener();
                break;

            case UrlShortenerType.TURL:
                urlShortener = new TurlURLShortener();
                break;

            case UrlShortenerType.CustomURLShortener:
                if (Program.UploadersConfig.CustomUploadersList.IsValidIndex(Program.UploadersConfig.CustomURLShortenerSelected))
                {
                    urlShortener = new CustomURLShortener(Program.UploadersConfig.CustomUploadersList[Program.UploadersConfig.CustomURLShortenerSelected]);
                }
                break;
            }

            if (urlShortener != null)
            {
                return(urlShortener.ShortenURL(url));
            }

            return(null);
        }
Exemplo n.º 9
0
        public async Task Add(string store, Dictionary <string, string> entryList)
        {
            Main mf = Application.OpenForms["Main"] as Main;

            foreach (var item in entryList.ToList())
            {
                Database.OpenConnection();
                SQLiteCommand checkEntry = new SQLiteCommand(
                    "SELECT COUNT(*) FROM Products WHERE Store = @store AND [ASIN / ISBN] = @asin_isbn",
                    Database.Connection);
                checkEntry.Parameters.AddWithValue("@store", store);
                checkEntry.Parameters.AddWithValue("@asin_isbn", item.Key);
                int entryExist = Convert.ToInt32(checkEntry.ExecuteScalar());
                if (entryExist > 0)
                {
                    entryList.Remove(item.Key);
                }
            }
            if (!entryList.Any())
            {
                metroLabel1.Text = @"Alle ausgewählten Produkte bereits in der Datenbank vorhanden.";
                return;
            }
            foreach (var item in entryList)
            {
                string asin_isbn = item.Key;
                string name      = item.Value;
                var    shortUrl  = await URLShortener.Generate(Amazon.MakeReferralLink(store, asin_isbn), name, store);

                if (shortUrl == null)
                {
                    continue;
                }
                Database.OpenConnection();
                SQLiteCommand insertEntry =
                    new SQLiteCommand(
                        "INSERT INTO Products (Store, [ASIN / ISBN], Name, URL) Values (@store, @asin_isbn, @name, @shorturl)",
                        Database.Connection);
                insertEntry.Parameters.AddWithValue("@store", store);
                insertEntry.Parameters.AddWithValue("@asin_isbn", asin_isbn);
                insertEntry.Parameters.AddWithValue("@name", name);
                insertEntry.Parameters.AddWithValue("@shorturl", shortUrl);
                insertEntry.ExecuteNonQuery();
            }
            ProductDatabase.Display(mf.metroComboBox2.SelectedIndex == -1 ? "ALLE" : mf.metroComboBox2.Text);
            metroLabel1.Text = @"Alle ausgewählten Produkte Erfolgreich Hinzugefügt.";
        }
Exemplo n.º 10
0
        public UploadResult ShortenURL(string url)
        {
            URLShortenerService service = UploaderFactory.URLShortenerServices[Info.TaskSettings.URLShortenerDestination];

            if (!service.CheckConfig(Program.UploadersConfig))
            {
                return(GetInvalidConfigResult(service));
            }

            URLShortener urlShortener = service.CreateShortener(Program.UploadersConfig, taskReferenceHelper);

            if (urlShortener != null)
            {
                return(urlShortener.ShortenURL(url));
            }

            return(null);
        }
Exemplo n.º 11
0
        public string ShortenURL(string url)
        {
            URLShortener urlShortener = null;

            switch (UploadManager.URLShortener)
            {
            case UrlShortenerType.BITLY:
                urlShortener = new BitlyURLShortener(ZKeys.BitlyLogin, ZKeys.BitlyKey);
                break;

            case UrlShortenerType.Google:
                urlShortener = new GoogleURLShortener(Program.UploadersConfig.GoogleURLShortenerAccountType, ZKeys.GoogleApiKey,
                                                      Program.UploadersConfig.GoogleURLShortenerOAuthInfo);
                break;

            case UrlShortenerType.ISGD:
                urlShortener = new IsgdURLShortener();
                break;

            case UrlShortenerType.Jmp:
                urlShortener = new JmpURLShortener(ZKeys.BitlyLogin, ZKeys.BitlyKey);
                break;

            /*case UrlShortenerType.THREELY:
             *  urlShortener = new ThreelyURLShortener(Program.ThreelyKey);
             *  break;*/
            case UrlShortenerType.TINYURL:
                urlShortener = new TinyURLShortener();
                break;

            case UrlShortenerType.TURL:
                urlShortener = new TurlURLShortener();
                break;
            }

            if (urlShortener != null)
            {
                Status = TaskStatus.URLShortening;
                return(urlShortener.ShortenURL(url));
            }

            return(null);
        }
Exemplo n.º 12
0
        public URLShortener ObterNovaUrl()
        {
            var IsValid = false;

            while (!IsValid)
            {
                var Guid = GerarGuid();
                if (IsValidGuid(Guid))
                {
                    IsValid = true;
                    var retorno = new URLShortener()
                    {
                        Domain = _context.Configs.Single().BackUrlShortenerDomain, Guid = Guid
                    };
                    return(retorno);
                }
            }
            return(null);
        }
        public static void RunInteractiveTesting()
        {
            string intro =
                "==============\n" +
                "= Problem #10 =\n" +
                "==============\n" +
                "\n" +
                "Design a URL shortener like bit.ly.\n";

            Console.WriteLine(intro);

            var host = "bril.ly";

            Console.WriteLine($"Creating a URLShortener using the short host \"{host}\".\n\n");
            var shortener = new URLShortener(host, 6);

            string input = String.Empty;

            while (input != "done")
            {
                Console.WriteLine(shortener.Dict_Debug_View);

                Console.WriteLine("\nEnter URLShortener command or \"done\"\n");
                input = Console.ReadLine();
                string[] commands = input.Split(' ');

                if (commands[0] == "shorten")
                {
                    var item      = commands[1];
                    var shortened = shortener.Shorten(item);
                    Console.WriteLine($"Shortened to: {shortened}\n");
                }
                else if (commands[0] == "lookup")
                {
                    var item     = commands[1];
                    var lookedup = shortener.Lookup(item);
                    Console.WriteLine($"Looked up: {lookedup}\n");
                }
            }
        }
Exemplo n.º 14
0
        public static async Task Add(string[] stores, string asin_isbn)
        {
            if (Tools.ArrayIsNullOrEmpty(stores))
            {
                MetroMessageBox.Show(mf,
                                     "Eintrag konnte nicht hinzugefügt werden!" + Environment.NewLine +
                                     "Bitte wähle mind. 1 Store für dieses Produkt aus!", "Eintrag Hinzufügen Fehlgeschlagen",
                                     MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (String.IsNullOrWhiteSpace(asin_isbn))
            {
                MetroMessageBox.Show(mf,
                                     "Eintrag konnte nicht hinzugefügt werden!" + Environment.NewLine +
                                     "Bitte gebe die Produkt ASIN / ISBN ein.!", "Eintrag Hinzufügen Fehlgeschlagen",
                                     MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            foreach (string store in stores)
            {
                Database.OpenConnection();
                SQLiteCommand checkEntry = new SQLiteCommand(
                    "SELECT COUNT(*) FROM Products WHERE Store = @store AND [ASIN / ISBN] = @asin_isbn", Database.Connection);
                checkEntry.Parameters.AddWithValue("@store", store);
                checkEntry.Parameters.AddWithValue("@asin_isbn", asin_isbn);
                int entryExist = Convert.ToInt32(checkEntry.ExecuteScalar());
                if (entryExist > 0)
                {
                    continue;
                }
                AmazonItemResponse itemInfo;
                try
                {
                    itemInfo = await Task.Run(() => AmazonApi.ItemLookup(store, asin_isbn));

                    if (itemInfo.Items == null)
                    {
                        continue;
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Abfrage Fehler: " + ex.Message, LogLevel.Debug);
                    continue;
                }
                if (itemInfo.Items.Request.Errors != null && itemInfo.Items.Request.Errors.Any())
                {
                    foreach (var error in itemInfo.Items.Request.Errors)
                    {
                        Logger.Write("AmazonAPI Abfrage Fehlgeschlagen - Grund: " + error.Message, LogLevel.Debug);
                    }
                    continue;
                }
                string name     = itemInfo.Items.Item[0].ItemAttributes.Title;
                var    shortUrl = await URLShortener.Generate(Amazon.MakeReferralLink(store, asin_isbn), name, store);

                if (shortUrl == null)
                {
                    continue;
                }
                Database.OpenConnection();
                SQLiteCommand insertEntry =
                    new SQLiteCommand(
                        "INSERT INTO Products (Store, [ASIN / ISBN], Name, URL) Values (@store, @asin_isbn, @name, @shorturl)",
                        Database.Connection);
                insertEntry.Parameters.AddWithValue("@store", store);
                insertEntry.Parameters.AddWithValue("@asin_isbn", asin_isbn);
                insertEntry.Parameters.AddWithValue("@name", name);
                insertEntry.Parameters.AddWithValue("@shorturl", shortUrl);
                insertEntry.ExecuteNonQuery();
            }
            mf.metroTextBox1.Clear();
            Display(mf.metroComboBox2.SelectedIndex == -1 ? "ALLE" : mf.metroComboBox2.Text);
        }
Exemplo n.º 15
0
 public int CadastrarUrl([FromBody] URLShortener cadastro)
 {
     return(_service.AdicionarLink(cadastro));
 }
Exemplo n.º 16
0
 public int AdicionarLink(URLShortener uRL)
 {
     _context.Urls.Add(uRL);
     _context.SaveChanges();
     return(_context.Urls.Where(x => x.Guid == uRL.Guid).FirstOrDefault().Id);
 }
Exemplo n.º 17
0
        private async Task Import(string store, string wishlist, int status = 2)
        {
            Main mf = Application.OpenForms["Main"] as Main;

            string reveal = null;

            switch (status)
            {
            case 0:
                reveal = "all";
                break;

            case 1:
                reveal = "purchased";
                break;

            case 2:
                reveal = "unpurchased";
                break;
            }
            string result = await new BetterWebClient {
                Timeout = 15000
            }.DownloadStringTaskAsync(new Uri(
                                          "https://tools.dealreminder.de/wish-lister/wishlist.php?tld=" +
                                          Amazon.GetTld(store) + "&id=" + wishlist + "&reveal=" + reveal +
                                          "&format=json"));
            dynamic jsonObj = JsonConvert.DeserializeObject(result);

            if (jsonObj == null)
            {
                metroLabel1.Text = @"Fehler beim Abrufen der Wunschliste. Falsche ID? Nicht Öffentlicht?";
                return;
            }
            Dictionary <string, string> resultList = new Dictionary <string, string>();

            foreach (var obj in jsonObj)
            {
                resultList.Add(Convert.ToString(obj.ASIN), Convert.ToString(obj.name));
            }
            foreach (var item in resultList.ToList())
            {
                Database.OpenConnection();
                SQLiteCommand checkEntry = new SQLiteCommand(
                    "SELECT COUNT(*) FROM Products WHERE Store = @store AND [ASIN / ISBN] = @asin_isbn",
                    Database.Connection);
                checkEntry.Parameters.AddWithValue("@store", store);
                checkEntry.Parameters.AddWithValue("@asin_isbn", item.Key);
                int entryExist = Convert.ToInt32(checkEntry.ExecuteScalar());
                if (entryExist > 0)
                {
                    resultList.Remove(item.Key);
                }
            }
            if (!resultList.Any())
            {
                metroLabel1.Text = @"Alle Produkte dieser Wunschliste bereits in der Datenbank vorhanden.";
                return;
            }
            foreach (var item in resultList)
            {
                string asin_isbn = item.Key;
                string name      = item.Value;
                var    shortUrl  = await URLShortener.Generate(Amazon.MakeReferralLink(store, asin_isbn), name, store);

                if (shortUrl == null)
                {
                    continue;
                }
                Database.OpenConnection();
                SQLiteCommand insertEntry =
                    new SQLiteCommand(
                        "INSERT INTO Products (Store, [ASIN / ISBN], Name, URL) Values (@store, @asin_isbn, @name, @shorturl)",
                        Database.Connection);
                insertEntry.Parameters.AddWithValue("@store", store);
                insertEntry.Parameters.AddWithValue("@asin_isbn", asin_isbn);
                insertEntry.Parameters.AddWithValue("@name", name);
                insertEntry.Parameters.AddWithValue("@shorturl", shortUrl);
                insertEntry.ExecuteNonQuery();
            }
            ProductDatabase.Display(mf.metroComboBox2.SelectedIndex == -1 ? "ALLE" : mf.metroComboBox2.Text);
            this.Close();
        }
Exemplo n.º 18
0
 public IHttpActionResult AtualizarUrl([FromBody] URLShortener objeto)
 {
     _service.Update(objeto);
     return(Ok());
 }
Exemplo n.º 19
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();
                    }
                }
            }
        }
Exemplo n.º 20
0
 public void Click(ref URLShortener uRL)
 {
     uRL.Click();
     _context.SaveChanges();
 }