public async Task <JsonResult> GetIsGd(string url)
        {
            IsGd           provider = new IsGd(url);
            ShortUrlClient client   = ShortUrlClientFactory.Create(provider);

            return(Json(await client.ReceiveAsync(), JsonRequestBehavior.DenyGet));
        }
Example #2
0
        /// <summary>
        /// Actual command logic
        /// </summary>
        /// <param name="source">The user who triggered the command.</param>
        /// <param name="channel">The channel the command was triggered in.</param>
        /// <param name="args">The arguments to the command.</param>
        /// <returns></returns>
        protected override CommandResponseHandler execute(User source, string channel, string[] args)
        {
            if (args.Length == 0)
            {
                string[] messageParameters = { "isgd", "1", args.Length.ToString() };
                return(new CommandResponseHandler(new Message().get("notEnoughParameters", messageParameters)));
            }

            return(new CommandResponseHandler(IsGd.shorten(new Uri(args[0])).ToString()));
        }
Example #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                string Url = "http://www.uol.com.br"; // digite o endereço

                IsGd            isgd     = new IsGd(Url);
                ShortUrlClient  client   = new ShortUrlClient(isgd);
                ShortUrlReceive response = client.Receive();
                client.Dispose();
                HLink.NavigateUrl = response.ShortUrl.AbsoluteUri;
            }
        }
        //private string compileMessage( ArrayList items, string keyword )
        //{
        //    return compileMessage( items, keyword, "" , false);
        //}
        private static string compileMessage(ArrayList items, string keyword, string destination, bool forceShowAll)
        {
            // keywordHasItems: 0: count, 1: plural word(s), 2: items in category
            // keywordNoItems: 0: plural word(s)
            // keywordPlural
            // keywordSingular

            string fakedestination = destination == ">TWITTER<" ? "" : destination;

            bool showWaitTime = (fakedestination != "" && (Configuration.singleton()["showWaitTime", destination] == "true"));

            TimeSpan minimumWaitTime;

            if (
                !TimeSpan.TryParse(Configuration.singleton()["minimumWaitTime", destination],
                                   out minimumWaitTime))
            {
                minimumWaitTime = new TimeSpan(0);
            }

            bool shortenUrls = (fakedestination != "" && (Configuration.singleton()["useShortUrlsInsteadOfWikilinks", destination] == "true"));
            bool showDelta   = (fakedestination != "" && (Configuration.singleton()["catWatcherShowDelta", destination] == "true"));

            if (destination == ">TWITTER<")
            {
                shortenUrls = true;
                showDelta   = true;
            }

            if (forceShowAll)
            {
                showDelta = false;
            }

            string message;


            if (items != null && items.Count > 0)
            {
                string listString = "";
                foreach (string item in items)
                {
                    if (!shortenUrls)
                    {
                        listString += "[[" + item + "]]";
                    }
                    else
                    {
                        try
                        {
                            Uri uri = new Uri(Configuration.singleton()["wikiUrl"] + item);
                            listString += IsGd.shorten(uri).ToString();
                        }
                        catch (UriFormatException ex)
                        {
                            listString += Configuration.singleton()["wikiUrl"] + item;
                            GlobalFunctions.errorLog(ex);
                        }
                    }

                    if (showWaitTime)
                    {
                        DAL.Select q = new DAL.Select("item_entrytime");
                        q.addWhere(new DAL.WhereConds("item_name", item));
                        q.addWhere(new DAL.WhereConds("item_keyword", keyword));
                        q.setFrom("categoryitems");

                        string   insertDate = DAL.singleton().executeScalarSelect(q);
                        DateTime realInsertDate;
                        if (!DateTime.TryParse(insertDate, out realInsertDate))
                        {
                            realInsertDate = DateTime.Now;
                        }

                        TimeSpan ts = DateTime.Now - realInsertDate;

                        if (ts >= minimumWaitTime)
                        {
                            string[] messageparams =
                            {
                                ts.Hours.ToString().PadLeft(2,   '0'),
                                ts.Minutes.ToString().PadLeft(2, '0'),
                                ts.Seconds.ToString().PadLeft(2, '0'),
                                ts.TotalDays >= 1 ? ((int)Math.Floor(ts.TotalDays)) + "d " : ""
                            };
                            listString += new Message().get("catWatcherWaiting", messageparams);
                        }
                    }

                    // trailing space added as a hack because MediaWiki doesn't preserve the trailing space :(
                    listString += new Message().get("listSeparator") + " ";
                }
                listString = listString.TrimEnd(' ', ',');
                string   pluralString  = items.Count == 1 ? new Message().get(keyword + "Singular", "keywordSingularDefault") : new Message().get(keyword + "Plural", "keywordPluralDefault");
                string[] messageParams = { items.Count.ToString(), pluralString, listString };
                message = new Message().get(keyword + (showDelta ? "New" : "") + "HasItems",
                                            messageParams);
            }
            else
            {
                string[] mp = { new Message().get(keyword + "Plural", "keywordPluralDefault") };
                message = new Message().get(keyword + "NoItems", mp);
            }
            return(message);
        }