public static string GetIdleTime(string service_id, string username) { if (!init) { return(null); } Galago.Service service = Galago.Global.GetService(service_id, Galago.Origin.Remote, true); if (service == null) { return(null); } Galago.Account account = service.GetAccount(username, true); if (account == null) { return(null); } Galago.Presence presence = account.Presence; if (presence == null) { return(null); } string str = StringFu.DurationToPrettyString(DateTime.Now, presence.IdleStartTime); return(str); }
public Archive(string filename, string mimeType) { this.uri = StringFu.PathToQuotedFileUri(filename); baseStream = new FileStream(filename, FileMode.Open); switch (mimeType) { case "application/zip": baseStream = new ZipInputStream(baseStream); getNextEntry = new GetNextEntryType(GetNextEntryZip); method = "#zip:"; break; case "application/x-bzip-compressed-tar": baseStream = new BZip2InputStream(baseStream); baseStream = new TarInputStream(baseStream); getNextEntry = new GetNextEntryType(GetNextEntryTar); method = "#bzip2:#tar:"; break; case "application/x-compressed-tar": baseStream = new GZipInputStream(baseStream); baseStream = new TarInputStream(baseStream); getNextEntry = new GetNextEntryType(GetNextEntryTar); method = "#gzip:#tar:"; break; case "application/x-tar": baseStream = new TarInputStream(baseStream); getNextEntry = new GetNextEntryType(GetNextEntryTar); method = "#tar:"; break; case "application/x-gzip": baseStream = new GZipInputStream(baseStream); getNextEntry = new GetNextEntryType(GetNextEntrySingle); method = "#gzip:"; break; case "application/x-bzip": baseStream = new BZip2InputStream(baseStream); getNextEntry = new GetNextEntryType(GetNextEntrySingle); method = "#bzip:"; break; default: throw new ArgumentException("Invalid or unsupported mime type."); } }
public override string ReadLine() { string line = reader.ReadLine(); if (line == null) { return(null); } sb.Length = 0; line = StringFu.StripTags(line, sb); line = StringFu.ConvertSpecialEntities(line); return(line); }
static public string EscapedUriToString(Uri uri) { if (!uri.UserEscaped) { return(uri.AbsoluteUri); } UriBuilder new_uri = new UriBuilder(uri); new_uri.Path = StringFu.HexUnescape(uri.AbsolutePath); if (!String.IsNullOrEmpty(new_uri.Fragment)) { new_uri.Fragment = StringFu.HexUnescape(uri.Fragment.Substring(1)); // remove leading '#' } return(new_uri.Uri.ToString()); }
// DEPRECATED! path is always escaped but escaping of fragment is // context dependent. //static public Uri PathToFileUri (string path, string fragment) // // Whether fragment should be escaped or not is crucial and depends on the context. // Hence the caller of the method should set it accordingly and no default // value for escape_fragment is provided. static public Uri AddFragment(Uri uri, string fragment, bool dont_escape_fragment) { if (fragment [0] == '#') { fragment = fragment.Substring(1); } if (!dont_escape_fragment) { fragment = StringFu.HexEscape(fragment); } fragment = String.Concat(uri.Fragment, '#', fragment); // Append to existing fragment return(new Uri(uri, fragment, true /* dont escape*/)); }
// Get a uri of our liking from a user-entered uri // Basically hex-escape the path, query and the fragment static public Uri UserUritoEscapedUri(string user_uri) { // We hex escape explicitly later Uri uri = new Uri(user_uri, true); // This is deprecated in .Net-2.0 - need new strategy to create custom Uris UriBuilder new_uri = new UriBuilder(); new_uri.Scheme = uri.Scheme; new_uri.Host = uri.Host; if (uri.UserInfo != String.Empty) { int index = uri.UserInfo.IndexOf(":"); if (index == -1) { new_uri.UserName = uri.UserInfo; } else { new_uri.UserName = uri.UserInfo.Substring(0, index); index++; if (index < uri.UserInfo.Length) { new_uri.Password = uri.UserInfo.Substring(index); } } } if (!uri.IsDefaultPort) { new_uri.Port = uri.Port; } new_uri.Path = StringFu.HexEscape(uri.AbsolutePath); new_uri.Query = uri.Query; // FIXME: escape ? new_uri.Fragment = StringFu.HexEscape(uri.Fragment); return(new_uri.Uri); }
static public string PathToFileUriString(string path) { return(String.Concat(Uri.UriSchemeFile, Uri.SchemeDelimiter, StringFu.HexEscape(Path.GetFullPath(path)))); }