Fixed Copy empty size problem, Moved URL related functions to URLHelpers

This commit is contained in:
Jaex 2014-06-09 23:00:59 +03:00
parent fe80e21d2f
commit 5505212127
18 changed files with 191 additions and 189 deletions

View file

@ -212,44 +212,6 @@ public static string GetXMLValue(string input, string tag)
return Regex.Match(input, String.Format("(?<={0}>).+?(?=</{0})", tag)).Value;
}
public static string CombineURL(string url1, string url2)
{
bool url1Empty = string.IsNullOrEmpty(url1);
bool url2Empty = string.IsNullOrEmpty(url2);
if (url1Empty && url2Empty)
{
return string.Empty;
}
if (url1Empty)
{
return url2;
}
if (url2Empty)
{
return url1;
}
if (url1.EndsWith("/"))
{
url1 = url1.Substring(0, url1.Length - 1);
}
if (url2.StartsWith("/"))
{
url2 = url2.Remove(0, 1);
}
return url1 + "/" + url2;
}
public static string CombineURL(params string[] urls)
{
return urls.Aggregate(CombineURL);
}
public static string GetMimeType(string fileName)
{
if (!string.IsNullOrEmpty(fileName))
@ -351,43 +313,6 @@ public static string GetProperExtension(string filePath)
return null;
}
public static string Encode(string text, string unreservedCharacters)
{
StringBuilder result = new StringBuilder();
if (!string.IsNullOrEmpty(text))
{
foreach (char c in text)
{
if (unreservedCharacters.Contains(c))
{
result.Append(c);
}
else
{
byte[] bytes = Encoding.UTF8.GetBytes(c.ToString());
foreach (byte b in bytes)
{
result.AppendFormat(CultureInfo.InvariantCulture, "%{0:X2}", b);
}
}
}
}
return result.ToString();
}
public static string URLEncode(string text)
{
return Encode(text, URLCharacters);
}
public static string URLPathEncode(string text)
{
return Encode(text, URLPathCharacters);
}
public static void OpenFolder(string folderPath)
{
if (!string.IsNullOrEmpty(folderPath))
@ -485,61 +410,6 @@ public static void OpenURL(string url)
}
}
public static bool IsValidURL(string url)
{
if (!string.IsNullOrEmpty(url))
{
url = url.Trim();
return !url.StartsWith("file://") && Uri.IsWellFormedUriString(url, UriKind.RelativeOrAbsolute);
}
return false;
}
public static bool IsValidURLRegex(string url)
{
if (string.IsNullOrEmpty(url)) return false;
// https://gist.github.com/729294
string pattern =
"^" +
// protocol identifier
"(?:(?:https?|ftp)://)" +
// user:pass authentication
"(?:\\S+(?::\\S*)?@)?" +
"(?:" +
// IP address exclusion
// private & local networks
"(?!10(?:\\.\\d{1,3}){3})" +
"(?!127(?:\\.\\d{1,3}){3})" +
"(?!169\\.254(?:\\.\\d{1,3}){2})" +
"(?!192\\.168(?:\\.\\d{1,3}){2})" +
"(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})" +
// IP address dotted notation octets
// excludes loopback network 0.0.0.0
// excludes reserved space >= 224.0.0.0
// excludes network & broacast addresses
// (first & last IP address of each class)
"(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])" +
"(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}" +
"(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))" +
"|" +
// host name
"(?:(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)" +
// domain name
"(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)*" +
// TLD identifier
"(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))" +
")" +
// port number
"(?::\\d{2,5})?" +
// resource path
"(?:/[^\\s]*)?" +
"$";
return Regex.IsMatch(url.Trim(), pattern, RegexOptions.IgnoreCase);
}
public static bool IsValidIPAddress(string ip)
{
if (string.IsNullOrEmpty(ip)) return false;

View file

@ -26,14 +26,146 @@ You should have received a copy of the GNU General Public License
using HelpersLib;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace HelpersLib
{
public static class URLHelpers
{
private static string Encode(string text, string unreservedCharacters)
{
StringBuilder result = new StringBuilder();
if (!string.IsNullOrEmpty(text))
{
foreach (char c in text)
{
if (unreservedCharacters.Contains(c))
{
result.Append(c);
}
else
{
byte[] bytes = Encoding.UTF8.GetBytes(c.ToString());
foreach (byte b in bytes)
{
result.AppendFormat(CultureInfo.InvariantCulture, "%{0:X2}", b);
}
}
}
}
return result.ToString();
}
public static string URLEncode(string text)
{
return Encode(text, Helpers.URLCharacters);
}
public static string URLPathEncode(string text)
{
return Encode(text, Helpers.URLPathCharacters);
}
public static string CombineURL(string url1, string url2)
{
bool url1Empty = string.IsNullOrEmpty(url1);
bool url2Empty = string.IsNullOrEmpty(url2);
if (url1Empty && url2Empty)
{
return string.Empty;
}
if (url1Empty)
{
return url2;
}
if (url2Empty)
{
return url1;
}
if (url1.EndsWith("/"))
{
url1 = url1.Substring(0, url1.Length - 1);
}
if (url2.StartsWith("/"))
{
url2 = url2.Remove(0, 1);
}
return url1 + "/" + url2;
}
public static string CombineURL(params string[] urls)
{
return urls.Aggregate(CombineURL);
}
public static bool IsValidURL(string url)
{
if (!string.IsNullOrEmpty(url))
{
url = url.Trim();
return !url.StartsWith("file://") && Uri.IsWellFormedUriString(url, UriKind.RelativeOrAbsolute);
}
return false;
}
public static bool IsValidURLRegex(string url)
{
if (string.IsNullOrEmpty(url)) return false;
// https://gist.github.com/729294
string pattern =
"^" +
// protocol identifier
"(?:(?:https?|ftp)://)" +
// user:pass authentication
"(?:\\S+(?::\\S*)?@)?" +
"(?:" +
// IP address exclusion
// private & local networks
"(?!10(?:\\.\\d{1,3}){3})" +
"(?!127(?:\\.\\d{1,3}){3})" +
"(?!169\\.254(?:\\.\\d{1,3}){2})" +
"(?!192\\.168(?:\\.\\d{1,3}){2})" +
"(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})" +
// IP address dotted notation octets
// excludes loopback network 0.0.0.0
// excludes reserved space >= 224.0.0.0
// excludes network & broacast addresses
// (first & last IP address of each class)
"(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])" +
"(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}" +
"(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))" +
"|" +
// host name
"(?:(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)" +
// domain name
"(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)*" +
// TLD identifier
"(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))" +
")" +
// port number
"(?::\\d{2,5})?" +
// resource path
"(?:/[^\\s]*)?" +
"$";
return Regex.IsMatch(url.Trim(), pattern, RegexOptions.IgnoreCase);
}
public static string AddSlash(string url, SlashType slashType)
{
return AddSlash(url, slashType, 1);

View file

@ -174,7 +174,7 @@ public static void ClipboardUpload(TaskSettings taskSettings = null)
{
string url = text.Trim();
if (Helpers.IsValidURLRegex(url))
if (URLHelpers.IsValidURLRegex(url))
{
if (taskSettings.UploadSettings.ClipboardUploadURLContents)
{

View file

@ -298,7 +298,7 @@ private void FTPCreateDirectory()
BringToFront();
if (ib.DialogResult == DialogResult.OK)
{
Client.CreateDirectory(Helpers.CombineURL(currentDirectory, ib.InputText));
Client.CreateDirectory(URLHelpers.CombineURL(currentDirectory, ib.InputText));
RefreshDirectory();
}
}
@ -435,7 +435,7 @@ private void lvFTPList_DragDrop(object sender, DragEventArgs e)
{
if (file.Name != filename)
{
string path = Helpers.CombineURL(currentDirectory, filename);
string path = URLHelpers.CombineURL(currentDirectory, filename);
string movePath = string.Empty;
if (file.Type == FtpFileSystemObjectType.Link)
{
@ -450,7 +450,7 @@ private void lvFTPList_DragDrop(object sender, DragEventArgs e)
}
else
{
movePath = Helpers.CombineURL(file.FullName, filename);
movePath = URLHelpers.CombineURL(file.FullName, filename);
}
if (!string.IsNullOrEmpty(movePath))
@ -489,7 +489,7 @@ private void lvFTPList_SubItemEndEditing(object sender, SubItemEndEditingEventAr
FtpListItem file = (FtpListItem)lvFTPList.SelectedItems[0].Tag;
if (file.Name != e.DisplayText)
{
Client.Rename(file.FullName, Helpers.CombineURL(currentDirectory, e.DisplayText));
Client.Rename(file.FullName, URLHelpers.CombineURL(currentDirectory, e.DisplayText));
RefreshDirectory();
}
}

View file

@ -100,13 +100,13 @@ private string CreateSignature(string secretKey, byte[] policyBytes)
private string GetObjectKey(string fileName)
{
string objectPrefix = NameParser.Parse(NameParserType.FolderPath, S3Settings.ObjectPrefix.Trim('/'));
return Helpers.CombineURL(objectPrefix, fileName);
return URLHelpers.CombineURL(objectPrefix, fileName);
}
private string GetObjectURL(string objectName)
{
objectName = objectName.Trim('/');
objectName = Helpers.URLPathEncode(objectName);
objectName = URLHelpers.URLPathEncode(objectName);
string url = string.Empty;
@ -114,16 +114,16 @@ private string GetObjectURL(string objectName)
{
if (!string.IsNullOrEmpty(S3Settings.CustomDomain))
{
url = Helpers.CombineURL(S3Settings.CustomDomain, objectName);
url = URLHelpers.CombineURL(S3Settings.CustomDomain, objectName);
}
else
{
url = Helpers.CombineURL(S3Settings.Bucket, objectName);
url = URLHelpers.CombineURL(S3Settings.Bucket, objectName);
}
}
else
{
url = Helpers.CombineURL(GetEndpoint(), objectName);
url = URLHelpers.CombineURL(GetEndpoint(), objectName);
}
if (!URLHelpers.HasPrefix(url))

View file

@ -119,7 +119,7 @@ public bool DownloadFile(string path, Stream downloadStream)
{
if (!string.IsNullOrEmpty(path) && OAuthInfo.CheckOAuth(AuthInfo))
{
string url = Helpers.CombineURL(URLFiles, Helpers.URLPathEncode(path));
string url = URLHelpers.CombineURL(URLFiles, URLHelpers.URLPathEncode(path));
string query = OAuthManager.GenerateQuery(url, null, HttpMethod.GET, AuthInfo);
return SendRequest(HttpMethod.GET, downloadStream, query);
}
@ -137,7 +137,7 @@ public UploadResult UploadFile(Stream stream, string path, string fileName)
return null;
}
string url = Helpers.CombineURL(URLFiles, Helpers.URLPathEncode(path));
string url = URLHelpers.CombineURL(URLFiles, URLHelpers.URLPathEncode(path));
Dictionary<string, string> args = new Dictionary<string, string>();
args.Add("overwrite", "true");
@ -151,7 +151,7 @@ public UploadResult UploadFile(Stream stream, string path, string fileName)
{
CopyUploadInfo content = JsonConvert.DeserializeObject<CopyUploadInfo>(result.Response);
if (content != null)
if (content != null && content.objects != null && content.objects.Length > 0)
{
AllowReportProgress = false;
result.URL = CreatePublicURL(content.objects[0].path, URLType);
@ -169,7 +169,7 @@ public CopyContentInfo GetMetadata(string path)
if (OAuthInfo.CheckOAuth(AuthInfo))
{
string url = Helpers.CombineURL(URLMetaData, Helpers.URLPathEncode(path));
string url = URLHelpers.CombineURL(URLMetaData, URLHelpers.URLPathEncode(path));
string query = OAuthManager.GenerateQuery(url, null, HttpMethod.GET, AuthInfo);
@ -193,7 +193,7 @@ public override UploadResult Upload(Stream stream, string fileName)
public string GetLinkURL(CopyLinksInfo link, string path, CopyURLType urlType = CopyURLType.Default)
{
string filename = URLHelpers.GetFileName(path);
string filename = URLHelpers.URLEncode(URLHelpers.GetFileName(path));
switch (urlType)
{
@ -211,7 +211,7 @@ public string CreatePublicURL(string path, CopyURLType urlType = CopyURLType.Def
{
path = path.Trim('/');
string url = Helpers.CombineURL(URLLinks, Helpers.URLPathEncode(path));
string url = URLHelpers.CombineURL(URLLinks, URLHelpers.URLPathEncode(path));
string query = OAuthManager.GenerateQuery(url, null, HttpMethod.POST, AuthInfo);
@ -310,11 +310,11 @@ public class CopyLinksInfo
public class CopyContentInfo // https://api.copy.com/rest/meta also works on 'rest/files'
{
public string id { get; set; } // Internal copy name
public string path { get; set; } // hmm?
public string path { get; set; } // file path
public string name { get; set; } // Human readable (Filesystem) folder name
public string type { get; set; } // "inbox", "root", "copy", "dir", "file"?
public bool stub { get; set; } // 'The stub attribute you see on all of the nodes represents if the specified node is incomplete, that is, if the children have not all been delivered to you. Basically, they will always be a stub, unless you are looking at that item directly.'
public long size { get; set; } // size of the folder/file
public long? size { get; set; } // Filesizes (size attributes) are measured in bytes. If an item displayed in the filesystem is a directory or an otherwise special location which doesn't represent a file, the size attribute will be null.
public long date_last_synced { get; set; }
public bool @public { get; set; } // is available to public; isnt everything private but shared in copy???
public string url { get; set; } // web access url (private)

View file

@ -163,7 +163,7 @@ public bool DownloadFile(string path, Stream downloadStream)
{
if (!string.IsNullOrEmpty(path) && OAuth2Info.CheckOAuth(AuthInfo))
{
string url = Helpers.CombineURL(URLFiles, Helpers.URLPathEncode(path));
string url = URLHelpers.CombineURL(URLFiles, URLHelpers.URLPathEncode(path));
return SendRequest(HttpMethod.GET, downloadStream, url, headers: GetAuthHeaders());
}
@ -179,7 +179,7 @@ public UploadResult UploadFile(Stream stream, string path, string fileName, bool
return null;
}
string url = Helpers.CombineURL(URLFiles, Helpers.URLPathEncode(path));
string url = URLHelpers.CombineURL(URLFiles, URLHelpers.URLPathEncode(path));
// There's a 150MB limit to all uploads through the API.
UploadResult result = UploadData(stream, url, fileName, headers: GetAuthHeaders());
@ -211,7 +211,7 @@ public DropboxContentInfo GetMetadata(string path, bool list)
if (OAuth2Info.CheckOAuth(AuthInfo))
{
string url = Helpers.CombineURL(URLMetaData, Helpers.URLPathEncode(path));
string url = URLHelpers.CombineURL(URLMetaData, URLHelpers.URLPathEncode(path));
Dictionary<string, string> args = new Dictionary<string, string>();
args.Add("list", list ? "true" : "false");
@ -238,7 +238,7 @@ public string CreateShareableLink(string path, DropboxURLType urlType)
{
if (!string.IsNullOrEmpty(path) && OAuth2Info.CheckOAuth(AuthInfo))
{
string url = Helpers.CombineURL(URLShares, Helpers.URLPathEncode(path));
string url = URLHelpers.CombineURL(URLShares, URLHelpers.URLPathEncode(path));
Dictionary<string, string> args = new Dictionary<string, string>();
args.Add("short_url", urlType == DropboxURLType.Shortened ? "true" : "false");
@ -257,7 +257,7 @@ public string CreateShareableLink(string path, DropboxURLType urlType)
string urlPath = match.Groups["path"].Value;
if (!string.IsNullOrEmpty(urlPath))
{
return Helpers.CombineURL(URLShareDirect, urlPath);
return URLHelpers.CombineURL(URLShareDirect, urlPath);
}
}
}
@ -385,8 +385,8 @@ public static string GetPublicURL(long userID, string path)
if (path.StartsWith("Public/", StringComparison.InvariantCultureIgnoreCase))
{
path = Helpers.URLPathEncode((path.Substring(7)));
return Helpers.CombineURL(URLPublicDirect, userID.ToString(), path);
path = URLHelpers.URLPathEncode((path.Substring(7)));
return URLHelpers.CombineURL(URLPublicDirect, userID.ToString(), path);
}
}

View file

@ -229,14 +229,14 @@ public void UploadFiles(string[] localPaths, string remotePath)
if (File.Exists(file))
{
UploadFile(file, Helpers.CombineURL(remotePath, filename));
UploadFile(file, URLHelpers.CombineURL(remotePath, filename));
}
else if (Directory.Exists(file))
{
List<string> filesList = new List<string>();
filesList.AddRange(Directory.GetFiles(file));
filesList.AddRange(Directory.GetDirectories(file));
string path = Helpers.CombineURL(remotePath, filename);
string path = URLHelpers.CombineURL(remotePath, filename);
CreateDirectory(path);
UploadFiles(filesList.ToArray(), path);
}

View file

@ -141,7 +141,7 @@ public FTPAccount()
public string GetSubFolderPath(string filename = null)
{
string path = NameParser.Parse(NameParserType.URL, SubFolderPath.Replace("%host", Host));
return Helpers.CombineURL(path, filename);
return URLHelpers.CombineURL(path, filename);
}
public string GetHttpHomePath()
@ -170,13 +170,13 @@ public string GetUriPath(string filename)
filename = Path.GetFileNameWithoutExtension(filename);
}
filename = Helpers.URLEncode(filename);
filename = URLHelpers.URLEncode(filename);
string subFolderPath = GetSubFolderPath();
subFolderPath = Helpers.URLPathEncode(subFolderPath);
subFolderPath = URLHelpers.URLPathEncode(subFolderPath);
string httpHomePath = GetHttpHomePath();
httpHomePath = Helpers.URLPathEncode(httpHomePath);
httpHomePath = URLHelpers.URLPathEncode(httpHomePath);
string path;
@ -189,13 +189,13 @@ public string GetUriPath(string filename)
host = host.Substring(4);
}
path = Helpers.CombineURL(host, subFolderPath, filename);
path = URLHelpers.CombineURL(host, subFolderPath, filename);
}
else
{
if (HttpHomePathAutoAddSubFolderPath)
{
path = Helpers.CombineURL(httpHomePath, subFolderPath);
path = URLHelpers.CombineURL(httpHomePath, subFolderPath);
}
else
{
@ -208,7 +208,7 @@ public string GetUriPath(string filename)
}
else
{
path = Helpers.CombineURL(path, filename);
path = URLHelpers.CombineURL(path, filename);
}
}
@ -229,7 +229,7 @@ public string GetFtpPath(string filemame)
return string.Empty;
}
return Helpers.CombineURL(FTPAddress, GetSubFolderPath(filemame));
return URLHelpers.CombineURL(FTPAddress, GetSubFolderPath(filemame));
}
public override string ToString()

View file

@ -269,11 +269,11 @@ public void RemoveDirectory(string url)
{
if (file.IsDirectory)
{
RemoveDirectory(Helpers.CombineURL(url, file.Name));
RemoveDirectory(URLHelpers.CombineURL(url, file.Name));
}
else
{
DeleteFile(Helpers.CombineURL(url, file.Name));
DeleteFile(URLHelpers.CombineURL(url, file.Name));
}
}
@ -401,8 +401,8 @@ public void MakeMultiDirectory(string dirName)
{
if (!string.IsNullOrEmpty(dir))
{
path = Helpers.CombineURL(path, dir);
MakeDirectory(Helpers.CombineURL(Options.Account.FTPAddress, path));
path = URLHelpers.CombineURL(path, dir);
MakeDirectory(URLHelpers.CombineURL(Options.Account.FTPAddress, path));
}
}

View file

@ -45,7 +45,7 @@ public GoogleDrive(OAuth2Info oauth)
public string GetAuthorizationURL()
{
return string.Format("https://accounts.google.com/o/oauth2/auth?response_type={0}&client_id={1}&redirect_uri={2}&scope={3}",
"code", AuthInfo.Client_ID, "urn:ietf:wg:oauth:2.0:oob", Helpers.URLEncode("https://www.googleapis.com/auth/drive"));
"code", AuthInfo.Client_ID, "urn:ietf:wg:oauth:2.0:oob", URLHelpers.URLEncode("https://www.googleapis.com/auth/drive"));
}
public bool GetAccessToken(string code)

View file

@ -141,10 +141,10 @@ public string GetUriPath(string filename)
filename = Path.GetFileNameWithoutExtension(filename);
}
filename = Helpers.URLEncode(filename);
filename = URLHelpers.URLEncode(filename);
string subFolderPath = GetSubFolderPath();
subFolderPath = Helpers.URLPathEncode(subFolderPath);
subFolderPath = URLHelpers.URLPathEncode(subFolderPath);
string httpHomePath = GetHttpHomePath();
@ -157,7 +157,7 @@ public string GetUriPath(string filename)
}
else
{
path = Helpers.URLPathEncode(httpHomePath);
path = URLHelpers.URLPathEncode(httpHomePath);
}
if (Port != 80)
@ -167,10 +167,10 @@ public string GetUriPath(string filename)
if (HttpHomePathAutoAddSubFolderPath)
{
path = Helpers.CombineURL(path, subFolderPath);
path = URLHelpers.CombineURL(path, subFolderPath);
}
path = Helpers.CombineURL(path, filename);
path = URLHelpers.CombineURL(path, filename);
string remoteProtocol = RemoteProtocol.GetDescription();
@ -200,7 +200,7 @@ public string GetLocalhostUri(string fileName)
return string.Empty;
}
return Helpers.CombineURL(localhostAddress, GetSubFolderPath(), fileName);
return URLHelpers.CombineURL(localhostAddress, GetSubFolderPath(), fileName);
}
public override string ToString()

View file

@ -178,7 +178,7 @@ public override UploadResult Upload(Stream stream, string fileName)
{
fileName = Helpers.GetValidURL(fileName);
string folderPath = Account.GetSubFolderPath();
string filePath = Helpers.CombineURL(folderPath, fileName);
string filePath = URLHelpers.CombineURL(folderPath, fileName);
try
{

View file

@ -214,7 +214,7 @@ private void tsmiCreateDirectory_Click(object sender, EventArgs e)
{
if (ib.ShowDialog() == DialogResult.OK)
{
string path = Helpers.CombineURL(CurrentFolderPath, ib.InputText);
string path = URLHelpers.CombineURL(CurrentFolderPath, ib.InputText);
dropbox.CreateFolder(path);
RefreshDirectory();
}

View file

@ -122,7 +122,7 @@ public static string GenerateQuery(string url, Dictionary<string, string> args,
throw new NotImplementedException("Unsupported signature method");
}
string signature = Helpers.URLEncode(Convert.ToBase64String(signatureData));
string signature = URLHelpers.URLEncode(Convert.ToBase64String(signatureData));
return string.Format("{0}?{1}&{2}={3}", normalizedUrl, normalizedParameters, ParameterSignature, signature);
}
@ -139,7 +139,7 @@ public static string GetAuthorizationURL(string requestTokenResponse, OAuthInfo
if (!string.IsNullOrEmpty(callback))
{
url += string.Format("&{0}={1}", ParameterCallback, Helpers.URLEncode(callback));
url += string.Format("&{0}={1}", ParameterCallback, URLHelpers.URLEncode(callback));
}
if (args[ParameterTokenSecret] != null)
@ -174,8 +174,8 @@ private static string GenerateSignatureBase(HttpMethod httpMethod, string normal
{
StringBuilder signatureBase = new StringBuilder();
signatureBase.AppendFormat("{0}&", httpMethod.ToString());
signatureBase.AppendFormat("{0}&", Helpers.URLEncode(normalizedUrl));
signatureBase.AppendFormat("{0}", Helpers.URLEncode(normalizedParameters));
signatureBase.AppendFormat("{0}&", URLHelpers.URLEncode(normalizedUrl));
signatureBase.AppendFormat("{0}", URLHelpers.URLEncode(normalizedParameters));
return signatureBase.ToString();
}
@ -253,7 +253,7 @@ private static string NormalizeUrl(string url)
private static string NormalizeParameters(Dictionary<string, string> parameters)
{
return string.Join("&", parameters.OrderBy(x => x.Key).ThenBy(x => x.Value).Select(x => x.Key + "=" + Helpers.URLEncode(x.Value)).ToArray());
return string.Join("&", parameters.OrderBy(x => x.Key).ThenBy(x => x.Value).Select(x => x.Key + "=" + URLHelpers.URLEncode(x.Value)).ToArray());
}
}
}

View file

@ -177,7 +177,7 @@ public string GetAuthLink(FlickrPermission perm)
public string GetPhotosLink(string userID)
{
return Helpers.CombineURL("http://www.flickr.com/photos", userID);
return URLHelpers.CombineURL("http://www.flickr.com/photos", userID);
}
public string GetPhotosLink()
@ -250,8 +250,8 @@ public override UploadResult Upload(Stream stream, string fileName)
if (null != xele)
{
string photoid = xele.Value;
string url = Helpers.CombineURL(GetPhotosLink(), photoid);
result.URL = Helpers.CombineURL(url, "sizes/o");
string url = URLHelpers.CombineURL(GetPhotosLink(), photoid);
result.URL = URLHelpers.CombineURL(url, "sizes/o");
}
}

View file

@ -50,7 +50,7 @@ public Picasa(OAuth2Info oauth)
public string GetAuthorizationURL()
{
return string.Format("https://accounts.google.com/o/oauth2/auth?response_type={0}&client_id={1}&redirect_uri={2}&scope={3}",
"code", AuthInfo.Client_ID, "urn:ietf:wg:oauth:2.0:oob", Helpers.URLEncode("https://picasaweb.google.com/data"));
"code", AuthInfo.Client_ID, "urn:ietf:wg:oauth:2.0:oob", URLHelpers.URLEncode("https://picasaweb.google.com/data"));
}
public bool GetAccessToken(string code)
@ -178,7 +178,7 @@ public override UploadResult Upload(Stream stream, string fileName)
string contentType = Helpers.GetMimeType(fileName);
NameValueCollection headers = GetAuthHeaders();
headers.Add("Slug", Helpers.URLEncode(fileName));
headers.Add("Slug", URLHelpers.URLEncode(fileName));
ur.Response = SendPostRequestStream(url, stream, contentType, headers: headers);

View file

@ -58,7 +58,7 @@ public GoogleURLShortener(OAuth2Info oauth)
public string GetAuthorizationURL()
{
return string.Format("https://accounts.google.com/o/oauth2/auth?response_type={0}&client_id={1}&redirect_uri={2}&scope={3}",
"code", AuthInfo.Client_ID, "urn:ietf:wg:oauth:2.0:oob", Helpers.URLEncode("https://www.googleapis.com/auth/urlshortener"));
"code", AuthInfo.Client_ID, "urn:ietf:wg:oauth:2.0:oob", URLHelpers.URLEncode("https://www.googleapis.com/auth/urlshortener"));
}
public bool GetAccessToken(string code)