Files
linux-packaging-mono/external/aspnetwebstack/src/Microsoft.Web.Helpers/LinkShare.generated.cs
Jo Shields a575963da9 Imported Upstream version 3.6.0
Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
2014-08-13 10:39:27 +01:00

461 lines
14 KiB
C#

#pragma warning disable 1591
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.239
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Microsoft.Web.Helpers
{
using System;
using System.Collections.Generic;
#line 3 "..\..\LinkShare.cshtml"
using System.Globalization;
#line default
#line hidden
using System.IO;
using System.Linq;
using System.Net;
#line 4 "..\..\LinkShare.cshtml"
using System.Text;
#line default
#line hidden
using System.Web;
using System.Web.Helpers;
using System.Web.Security;
using System.Web.UI;
using System.Web.WebPages;
using System.Web.WebPages.Html;
#line 5 "..\..\LinkShare.cshtml"
using System.Web.WebPages.Scope;
#line default
#line hidden
#line 6 "..\..\LinkShare.cshtml"
using Microsoft.Internal.Web.Utils;
#line default
#line hidden
public class LinkShare : System.Web.WebPages.HelperPage
{
#line 8 "..\..\LinkShare.cshtml"
internal static readonly object _bitlyApiKey = new object();
internal static readonly object _bitlyLogin = new object();
private static readonly Lazy<IEnumerable<LinkShareSite>> _allSites = new Lazy<IEnumerable<LinkShareSite>>(() =>
from site in (LinkShareSite[])Enum.GetValues(typeof(LinkShareSite))
where site != LinkShareSite.All
select site
);
public static string BitlyApiKey {
get {
return ScopeStorage.CurrentScope[_bitlyApiKey] as string;
}
set {
if (value == null) {
throw new ArgumentNullException("value");
}
ScopeStorage.CurrentScope[_bitlyApiKey] = value;
}
}
public static string BitlyLogin {
get {
return ScopeStorage.CurrentScope[_bitlyLogin] as string;
}
set {
if (value == null) {
throw new ArgumentNullException("value");
}
ScopeStorage.CurrentScope[_bitlyLogin] = value;
}
}
private static string GetShortenedUrl(string pageLinkBack) {
if (BitlyLogin.IsEmpty() || BitlyApiKey.IsEmpty()) {
return pageLinkBack;
}
string encodedPageLinkBack = HttpUtility.UrlEncode(pageLinkBack);
string key = "Bitly_pageLinkBack_" + BitlyApiKey + "_" + encodedPageLinkBack;
string shortUrl = WebCache.Get(key) as string;
if (shortUrl != null) {
return shortUrl;
}
string bitlyReq = "http://api.bit.ly/v3/shorten?format=txt&longUrl=" + encodedPageLinkBack + "&login=" + BitlyLogin + "&apiKey=" + BitlyApiKey;
try {
shortUrl = GetWebResponse(bitlyReq);
}
catch (WebException) {
return pageLinkBack;
}
if (shortUrl != null) {
WebCache.Set(key, shortUrl);
return shortUrl;
}
return pageLinkBack;
}
private static string GetWebResponse(string address) {
WebRequest request = WebRequest.Create(address);
request.Method = "GET";
request.Timeout = 5 * 1000; //5 seconds
using (var response = (HttpWebResponse)request.GetResponse()) {
if (response.StatusCode != HttpStatusCode.OK) {
return null;
}
using (Stream stream = response.GetResponseStream()) {
using (MemoryStream memStream = new MemoryStream()) {
stream.CopyTo(memStream);
// Review: Should we use the ContentEncoding from response?
return Encoding.UTF8.GetString(memStream.ToArray());
}
}
}
}
/// <summary>
/// Returns an ordered list of LinkShareSite based on position of "All" parameter occurs in the list.
/// </summary>
/// <remarks>
/// The LinkShareSite is accepted as a params array.
/// In the event that no value is provided or the LinkShareSite.All is the first param, we display all the sites in the order they appear in the enum.
/// If not, the items we look for the first occurence of LinkShareSite.All in the array.
/// The items that appear before this appear in the order they are specified. The All is replaced by all items in the enum that were not already specified by the user
/// in the order they appear in the enum.
/// e.g. sites = [] { Twitter, Facebook, Digg, All }
/// Would result in returning {Twitter, Facebook, Digg, Delicious, GoogleBuzz, Reddit, StumbleUpon}
/// </remarks>
internal static IEnumerable<LinkShareSite> GetSitesInOrder(LinkShareSite[] linkSites) {
var allSites = _allSites.Value;
if (linkSites == null || !linkSites.Any() || linkSites.First() == LinkShareSite.All) {
// Show all sites
return allSites;
}
var result = linkSites.TakeWhile(c => c != LinkShareSite.All).ToList();
if (result.Count != linkSites.Length) {
return Enumerable.Concat(result, allSites.Except(result));
}
else {
return result;
}
}
private static void ConstructPageLinkBack(ref string pageLinkBack, out string shortenedUrl) {
HttpContext context = HttpContext.Current;
if ((pageLinkBack == null) && (context != null)) {
pageLinkBack = context.Request.Url.GetComponents(UriComponents.SchemeAndServer | UriComponents.Path, UriFormat.Unescaped);
}
shortenedUrl = GetShortenedUrl(pageLinkBack);
}
#line default
#line hidden
public static System.Web.WebPages.HelperResult GetHtml(string pageTitle,
string pageLinkBack = null,
string twitterUserName = null,
string additionalTweetText = null,
params LinkShareSite[] linkSites) {
return new System.Web.WebPages.HelperResult(__razor_helper_writer => {
#line 126 "..\..\LinkShare.cshtml"
if (pageTitle.IsEmpty()) {
throw new ArgumentException(String.Format(CultureInfo.CurrentUICulture, CommonResources.Argument_Cannot_Be_Null_Or_Empty, "pageTitle"), "pageTitle");
}
string shortenedUrl;
ConstructPageLinkBack(ref pageLinkBack, out shortenedUrl);
pageLinkBack = HttpUtility.UrlEncode(pageLinkBack);
shortenedUrl = HttpUtility.UrlEncode(shortenedUrl);
pageTitle = HttpUtility.UrlEncode(pageTitle);
foreach (var site in GetSitesInOrder(linkSites)) {
switch (site) {
case LinkShareSite.Delicious:
#line default
#line hidden
WriteLiteralTo(@__razor_helper_writer, " <a href=\"http://delicious.com/save?v=5&amp;noui&amp;jump=close&am" +
"p;url=");
#line 142 "..\..\LinkShare.cshtml"
WriteTo(@__razor_helper_writer, shortenedUrl);
#line default
#line hidden
WriteLiteralTo(@__razor_helper_writer, "&amp;title=");
#line 142 "..\..\LinkShare.cshtml"
WriteTo(@__razor_helper_writer, pageTitle);
#line default
#line hidden
WriteLiteralTo(@__razor_helper_writer, "\" target=\"_blank\" title=\"Add to del.icio.us\">\r\n <img alt=\"Add " +
"to del.icio.us\" src=\"http://www.delicious.com/static/img/delicious.small.gif\" st" +
"yle=\"border:0; height:16px; width:16px; margin:0 1px;\" title=\"Add to del.icio.us" +
"\" /></a>\r\n");
#line 144 "..\..\LinkShare.cshtml"
break;
case LinkShareSite.Digg:
#line default
#line hidden
WriteLiteralTo(@__razor_helper_writer, " <a href=\"http://digg.com/submit?url=");
#line 147 "..\..\LinkShare.cshtml"
WriteTo(@__razor_helper_writer, pageLinkBack);
#line default
#line hidden
WriteLiteralTo(@__razor_helper_writer, "&amp;title=");
#line 147 "..\..\LinkShare.cshtml"
WriteTo(@__razor_helper_writer, pageTitle);
#line default
#line hidden
WriteLiteralTo(@__razor_helper_writer, "\" target=\"_blank\" title=\"Digg!\">\r\n <img alt=\"Digg!\" src=\"http:" +
"//digg.com/img/badges/16x16-digg-guy.gif\" style=\"border:0; height:16px; width:16" +
"px; margin:0 1px;\" title=\"Digg!\" /></a>\r\n");
#line 149 "..\..\LinkShare.cshtml"
break;
case LinkShareSite.Facebook:
#line default
#line hidden
WriteLiteralTo(@__razor_helper_writer, " <a href=\"http://www.facebook.com/sharer.php?u=");
#line 151 "..\..\LinkShare.cshtml"
WriteTo(@__razor_helper_writer, shortenedUrl);
#line default
#line hidden
WriteLiteralTo(@__razor_helper_writer, "&amp;t=");
#line 151 "..\..\LinkShare.cshtml"
WriteTo(@__razor_helper_writer, pageTitle);
#line default
#line hidden
WriteLiteralTo(@__razor_helper_writer, "\" target=\"_blank\" title=\"Share on Facebook\">\r\n <img alt=\"Share" +
" on Facebook\" src=\"http://www.facebook.com/favicon.ico\" style=\"border:0; height:" +
"16px; width:16px; margin:0 1px;\" title=\"Share on Facebook\" /></a>\r\n");
#line 153 "..\..\LinkShare.cshtml"
break;
case LinkShareSite.Reddit:
#line default
#line hidden
WriteLiteralTo(@__razor_helper_writer, " <a href=\"http://reddit.com/submit?url=");
#line 155 "..\..\LinkShare.cshtml"
WriteTo(@__razor_helper_writer, pageLinkBack);
#line default
#line hidden
WriteLiteralTo(@__razor_helper_writer, "&amp;title=");
#line 155 "..\..\LinkShare.cshtml"
WriteTo(@__razor_helper_writer, pageTitle);
#line default
#line hidden
WriteLiteralTo(@__razor_helper_writer, "\" target=\"_blank\" title=\"Reddit!\">\r\n <img alt=\"Reddit!\" src=\"h" +
"ttp://www.Reddit.com/favicon.ico\" style=\"border:0; height:16px; width:16px; marg" +
"in:0 1px;\" title=\"Reddit!\" /></a>\r\n");
#line 157 "..\..\LinkShare.cshtml"
break;
case LinkShareSite.StumbleUpon:
#line default
#line hidden
WriteLiteralTo(@__razor_helper_writer, " <a href=\"http://www.stumbleupon.com/submit?url=");
#line 159 "..\..\LinkShare.cshtml"
WriteTo(@__razor_helper_writer, pageLinkBack);
#line default
#line hidden
WriteLiteralTo(@__razor_helper_writer, "&amp;title=");
#line 159 "..\..\LinkShare.cshtml"
WriteTo(@__razor_helper_writer, pageTitle);
#line default
#line hidden
WriteLiteralTo(@__razor_helper_writer, "\" target=\"_blank\" title=\"Stumble it!\">\r\n <img alt=\"Stumble it!" +
"\" src=\"http://cdn.stumble-upon.com/images/16x16_su_round.gif\" style=\"border:0; h" +
"eight:16px; width:16px; margin:0 1px;\" title=\"Stumble it!\" /></a>\r\n");
#line 161 "..\..\LinkShare.cshtml"
break;
case LinkShareSite.GoogleBuzz:
#line default
#line hidden
WriteLiteralTo(@__razor_helper_writer, " <a href=\"http://www.google.com/reader/link?url=");
#line 163 "..\..\LinkShare.cshtml"
WriteTo(@__razor_helper_writer, shortenedUrl);
#line default
#line hidden
WriteLiteralTo(@__razor_helper_writer, "&amp;title=");
#line 163 "..\..\LinkShare.cshtml"
WriteTo(@__razor_helper_writer, pageTitle);
#line default
#line hidden
WriteLiteralTo(@__razor_helper_writer, @""" target=""_blank"" title=""Share on Google Buzz"">
<img alt=""Share on Google Buzz"" src=""http://mail.google.com/mail/pimages/2/up/buzz-icon2.png"" style=""border:0; height:16px; width:16px; margin:0 1px;"" title=""Share on Google Buzz"" /></a>
");
#line 165 "..\..\LinkShare.cshtml"
break;
case LinkShareSite.Twitter:
string status = String.Empty;
if (!twitterUserName.IsEmpty()) {
status += ", (via @@" + twitterUserName + ")";
}
if (!additionalTweetText.IsEmpty()) {
status += ' ' + additionalTweetText;
}
status = HttpUtility.UrlEncode(status);
#line default
#line hidden
WriteLiteralTo(@__razor_helper_writer, " <a href=\"http://twitter.com/home/?status=");
#line 175 "..\..\LinkShare.cshtml"
WriteTo(@__razor_helper_writer, pageTitle);
#line default
#line hidden
WriteLiteralTo(@__razor_helper_writer, "%3a+");
#line 175 "..\..\LinkShare.cshtml"
WriteTo(@__razor_helper_writer, shortenedUrl);
#line default
#line hidden
#line 175 "..\..\LinkShare.cshtml"
WriteTo(@__razor_helper_writer, status);
#line default
#line hidden
WriteLiteralTo(@__razor_helper_writer, "\" target=\"_blank\" title=\"Share on Twitter\">\r\n <img alt=\"Share " +
"on Twitter\" src=\"http://twitter.com/favicon.ico\" style=\"border:0; height:16px; w" +
"idth:16px; margin:0 1px;\" title=\"Share on Twitter\" />\r\n </a>\r\n");
#line 178 "..\..\LinkShare.cshtml"
break;
}
}
#line default
#line hidden
});
}
public LinkShare()
{
}
}
}
#pragma warning restore 1591