private async void button1_Click(object sender, EventArgs e) { var bitly = new BitlyAPI(); bitly.ACCESS_TOKEN = "YOUR ACCESS TOKEN KEY"; if (textBox1.Text != "") { textBox2.Text = await bitly.ShortenAsync(textBox1.Text); } }
public async Task <ActionResult> Index(string link) { if (string.IsNullOrEmpty(link)) { return(View()); } Regex pattern = null; Match m = null; string result = string.Empty; if (link.Contains("https://drive.google.com")) { pattern = new Regex(@"https?:\/\/(?:drive\.google\.com\/file\/d\/)([\w-]{28}).*"); if (pattern.IsMatch(link)) { m = pattern.Match(link); result = @"https://drive.google.com/uc?export=download&id=" + m.Groups[1].Value; } else { pattern = new Regex(@"https?:\/\/(?:drive\.google\.com\/open\?id=)([\w-]{28}).*"); if (pattern.IsMatch(link)) { m = pattern.Match(link); result = @"https://drive.google.com/uc?export=download&id=" + m.Groups[1].Value; } } } else if (link.Contains("dropbox.com")) { //pattern = new Regex(@"https://www.dropbox.com/s/jh7dq4uh4k26d0b/Huong%20dan.txt?dl=0"); //if (pattern.IsMatch(link)) //{ // m = pattern.Match(link); // result = @"https://dl.dropboxusercontent.com/s/" + m.Groups[1].Value; //} result = link.Replace("www.dropbox.com", "dl.dropboxusercontent.com").Replace("dl=0", "dl=1"); } else if (link.Contains(@"https://onedrive.live.com/embed")) { result = link.Replace("embed", "download"); } if (!string.IsNullOrEmpty(result)) { string accesstoken = "19ef39ce4a13e2448b98ac7beed5556552b05bd5"; var bitly = new BitlyAPI(accesstoken); var shortlink = await bitly.ShortenAsync(result); ViewBag.Short = string.IsNullOrEmpty(shortlink)? "Lỗi ! Không rút gọn link." : shortlink; } ViewBag.Result = string.IsNullOrEmpty(result) ? "Lỗi ! Không lấy được link." : result; return(View()); }
public void IssueZendeskReturnLabel(string no, string docNo, bool closeWindow, Zendesk ticket) { SendService ss = new SendService(); string pdf64String = string.Empty; string amazonBucketURL = string.Empty; try { if (ExistingZendeskTicket) { string message = string.Empty; ZendeskTicket = ticket; if (EmailTo != null) { int index = EmailTo.IndexOf('@'); EmailTo = EmailTo.Insert(index, "+id" + TicketNo); } else { EmailTo = string.Empty; } if (FromEmail == null) { FromEmail = string.Empty; } pdf64String = ss.IssueReturnLabel(no, EmailTo, ExistingZendeskTicket, FromEmail, DownloadManually, CustomerEmailAddress, FromEmailName, EmailSubject, ref amazonBucketURL, GenerateURL); Session["NoUserInteraction"] = true; ZendeskTicket.UpdateZendeskTicketWithPDFFile(pdf64String, no, amazonBucketURL); message = no + ", Return label is being processed and will be emailed within 1 hour."; Page.ClientScript.RegisterStartupScript(this.GetType(), "issueReturnLableExistingTicket", "alert('" + Json.Encode(message) + "');", true); if (closeWindow) { Page.ClientScript.RegisterStartupScript(this.GetType(), "closeAfterProcessing", "parent.window.close();", true); } } else if (NewZendeskTicket) { string message = string.Empty; pdf64String = ss.IssueReturnLabel(no, EmailTo, ExistingZendeskTicket, FromEmail, DownloadManually, CustomerEmailAddress, FromEmailName, EmailSubject, ref amazonBucketURL, GenerateURL); Session["NoUserInteraction"] = true; long?newZendeskTicketID = 0; ZendeskTicket = new Zendesk(); newZendeskTicketID = ZendeskTicket.CreateNewZendeskTicketWithPDFFile(pdf64String, no, amazonBucketURL, EmailTo, CustomerName, docNo); message = "New Zendesk Ticket is: " + newZendeskTicketID + @". " + no + ", Return label is being processed and will be emailed within 1 hour."; Page.ClientScript.RegisterStartupScript(this.GetType(), "issueReturnLabelNewTicket", "alert('" + Json.Encode(message) + "');", true); Page.ClientScript.RegisterStartupScript(this.GetType(), "closeErrorAlert", "parent.window.close();", true); } else if (DownloadManually) { string message = string.Empty; pdf64String = ss.IssueReturnLabel(no, string.Empty, ExistingZendeskTicket, string.Empty, DownloadManually, CustomerEmailAddress, FromEmailName, EmailSubject, ref amazonBucketURL, GenerateURL); Session["NoUserInteraction"] = true; if (pdf64String != string.Empty) // Display only the URL { ZendeskTicket = new Zendesk(); ZendeskTicket.DownloadRMAPDFManually(pdf64String, no); message = no + ", Return label has been successfully downloaded."; Page.ClientScript.RegisterStartupScript(this.GetType(), "manualDownloadExistingTicket", "alert('" + Json.Encode(message) + "');", true); Page.ClientScript.RegisterStartupScript(this.GetType(), "closeAfterDownload", "parent.window.close();", true); } else { Page.ClientScript.RegisterStartupScript(this.GetType(), "manualDownloadExistingTicket", "alert('The file could not be downloaded.');", true); } } else if (GenerateURL) { string message = string.Empty; string clipboardMessage = string.Empty; pdf64String = ss.IssueReturnLabel(no, string.Empty, ExistingZendeskTicket, string.Empty, DownloadManually, CustomerEmailAddress, FromEmailName, EmailSubject, ref amazonBucketURL, GenerateURL); Session["NoUserInteraction"] = true; if (amazonBucketURL != string.Empty) // Display only the URL { BitlyAPI bitlyAPI = new BitlyAPI(); string url = bitlyAPI.ShortenURL(amazonBucketURL); message = no + ", Return label URL has been successfully generated."; clipboardMessage = @"Hello, Your return request has been approved. Your Return Merchandise Authorization number is " + no + @" Follow the link below to download your return instructions and shipping label. Or copy and paste the link into your browser. " + url + @" IMPORTANT: Please remove ALL locks and passwords. Any device(s) received locked with your information will be denied, returned at your expense with no refund submitted for processing. Thank You"; Page.ClientScript.RegisterStartupScript(this.GetType(), "clipboardMessage", "CopyToClipboard('" + Json.Encode(clipboardMessage) + "');", true); } else { Page.ClientScript.RegisterStartupScript(this.GetType(), "manualGenerateURL", "alert('The URL could not be generated.');", true); } } else { Page.ClientScript.RegisterStartupScript(this.GetType(), "manualDownloadExistingTicket", "alert('Please select a valid option.');", true); } } catch (Exception ex) { Log.Error(ex.Message, ex); Page.ClientScript.RegisterStartupScript(this.GetType(), "errorAlert", "alert('" + ex.Message.Replace("'", "\"").Replace("\n", "\\n") + "');", true); if (ex.Message.ToLower().Contains("session")) { Page.ClientScript.RegisterStartupScript(this.GetType(), "closeErrorAlert", "parent.window.close();", true); } } }