本文整理汇总了C#中MindTouch.Dream.MimeType类的典型用法代码示例。如果您正苦于以下问题:C# MimeType类的具体用法?C# MimeType怎么用?C# MimeType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MimeType类属于MindTouch.Dream命名空间,在下文中一共展示了MimeType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendNoticeToAdmin
public static void SendNoticeToAdmin(string subject, string content, MimeType mime) {
UserBE adminUser = UserBL.GetAdmin(); ;
if (adminUser == null) {
throw new DreamAbortException(DreamMessage.InternalError(DekiResources.CANNOT_RETRIEVE_ADMIN_ACCOUNT));
}
string smtphost = string.Empty;
int smtpport = 0;
if (smtphost == string.Empty)
throw new DreamAbortException(DreamMessage.Conflict(DekiResources.SMTP_SERVER_NOT_CONFIGURED));
if (string.IsNullOrEmpty(adminUser.Email))
throw new DreamAbortException(DreamMessage.Conflict(DekiResources.ADMIN_EMAIL_NOT_SET));
System.Net.Mail.SmtpClient smtpclient = new System.Net.Mail.SmtpClient();
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
msg.To.Add(adminUser.Email);
msg.From = new System.Net.Mail.MailAddress(DekiContext.Current.User.Email, DekiContext.Current.User.Name);
msg.Subject = DekiContext.Current.Instance.SiteName + ": " + subject;
msg.Body = content;
smtpclient.Host = smtphost;
if (smtpport != 0)
smtpclient.Port = smtpport;
smtpclient.Send(msg);
}
示例2: SendNoticeToAdmin
//--- Methods ---
public void SendNoticeToAdmin(string subject, string content, MimeType mime) {
// TODO (arnec): should this be using the email service?
UserBE adminUser = UserBL.GetAdmin();
if(adminUser == null) {
throw new SiteNoAdminFatalException();
}
string smtphost = string.Empty;
int smtpport = 0;
if(smtphost == string.Empty) {
throw new SiteConflictException(DekiResources.SMTP_SERVER_NOT_CONFIGURED());
}
if(string.IsNullOrEmpty(adminUser.Email)) {
throw new SiteConflictException(DekiResources.ADMIN_EMAIL_NOT_SET());
}
var smtpclient = new SmtpClient();
var msg = new MailMessage();
msg.To.Add(adminUser.Email);
msg.From = new MailAddress(_user.Email, _user.Name);
msg.Subject = _dekiInstance.SiteName + ": " + subject;
msg.Body = content;
smtpclient.Host = smtphost;
if(smtpport != 0) {
smtpclient.Port = smtpport;
}
smtpclient.Send(msg);
}
示例3: ResourceContentBE
public ResourceContentBE(string value, MimeType mimeType)
: this(true) {
if(value == null) {
throw new ArgumentNullException("value");
}
if(mimeType == null) {
throw new ArgumentNullException("mimeType");
}
_mimeType = mimeType;
_stream = new ChunkedMemoryStream();
_stream.Write(mimeType.CharSet, value);
_size = (uint)_stream.Length;
}
示例4: AddAttachment
/* =========================================================================
* Asynchronous methods
* =======================================================================*/
/// <summary>
/// <para>Adds an attachment to a document. The document revision must be
/// specified when using this method.</para>
/// <para>(This method is asynchronous.)</para>
/// </summary>
/// <param name="id">ID of the CouchDB document.</param>
/// <param name="rev">Revision of the CouchDB document.</param>
/// <param name="attachment">Stream of the attachment. Will be closed once
/// the request is sent.</param>
/// <param name="attachmentLength">Length of the attachment stream.</param>
/// <param name="fileName">Filename of the attachment.</param>
/// <param name="contentType">Content type of the document.</param>
/// <param name="result"></param>
/// <returns></returns>
public Result<JObject> AddAttachment(
string id,
string rev,
Stream attachment,
long attachmentLength,
string fileName,
MimeType contentType,
Result<JObject> result)
{
if (String.IsNullOrEmpty(id))
throw new ArgumentNullException("id");
if (String.IsNullOrEmpty(rev))
throw new ArgumentNullException("rev");
if (attachment == null)
throw new ArgumentNullException("attachment");
if (attachmentLength < 0)
throw new ArgumentOutOfRangeException("attachmentLength");
if (String.IsNullOrEmpty(fileName))
throw new ArgumentNullException("fileName");
if (contentType == null)
throw new ArgumentNullException("contentType");
if (result == null)
throw new ArgumentNullException("result");
BasePlug
.AtPath(XUri.EncodeFragment(id))
.At(XUri.EncodeFragment(fileName))
.With(Constants.REV, rev)
.Put(DreamMessage.Ok(contentType, attachmentLength, attachment),
new Result<DreamMessage>())
.WhenDone(
a =>
{
if (a.Status == DreamStatus.Created)
result.Return(JObject.Parse(a.ToText()));
else
result.Throw(new CouchException(a));
},
result.Throw
);
return result;
}
示例5: StreamInfo
public StreamInfo(Stream stream, long size, MimeType type, DateTime? modified) {
if(stream == null) {
throw new ArgumentNullException("stream");
}
this.Stream = stream;
this.Length = size;
this.Type = type ?? MimeType.BINARY;
this.Modified = modified;
}
示例6: BuildRevForContentUpdate
public virtual ResourceBE BuildRevForContentUpdate(ResourceBE currentResource, MimeType mimeType, uint size, string description, string name, ResourceContentBE newContent) {
ResourceBE newRev = BuildRevForExistingResource(currentResource, mimeType, size, description);
newRev.Content = newContent;
newRev.ContentId = 0;
newRev.ChangeMask |= ResourceBE.ChangeOperations.CONTENT;
if(name != null && !StringUtil.EqualsInvariant(name, newRev.Name)) {
newRev.ChangeMask |= ResourceBE.ChangeOperations.NAME;
newRev.Name = name;
}
return newRev;
}
示例7: BuildRevForNewResource
private ResourceBE BuildRevForNewResource(string resourcename, MimeType mimeType, uint size, string description, ResourceBE.Type resourceType, uint userId, ResourceContentBE content) {
ResourceBE newResource = new ResourceBE(resourceType);
newResource.Name = resourcename;
newResource.ChangeMask = newResource.ChangeMask | ResourceBE.ChangeOperations.NAME;
newResource.Size = size;
newResource.MimeType = mimeType;
newResource.ChangeDescription = description;
newResource.ResourceCreateUserId = newResource.ResourceUpdateUserId = newResource.UserId = userId;
newResource.ChangeSetId = 0;
newResource.Timestamp = newResource.ResourceCreateTimestamp = newResource.ResourceUpdateTimestamp = DateTime.UtcNow;
newResource.Content = content;
newResource.ChangeMask = newResource.ChangeMask | ResourceBE.ChangeOperations.CONTENT;
newResource.ResourceHeadRevision = ResourceBE.TAILREVISION;
newResource.Revision = ResourceBE.TAILREVISION;
newResource.IsHidden = false;
return newResource;
}
示例8: GetFileInternal
private StreamInfo GetFileInternal(string filename, MimeType type, bool allowFileLink) {
if(allowFileLink && _allowRedirects) {
return new StreamInfo(BuildS3Uri(Verb.GET, _s3.AtPath(filename), _redirectTimeout));
}
// check if file is cached
var entry = GetCachedEntry(filename);
if(entry != null) {
Stream filestream = File.Open(entry.Item1, FileMode.Open, FileAccess.Read, FileShare.Read);
return new StreamInfo(filestream, filestream.Length, type, entry.Item3);
}
// get file from S3
var result = new Result<DreamMessage>();
_s3.AtPath(filename).InvokeEx(Verb.GET, DreamMessage.Ok(), result);
var response = result.Wait();
try {
if(response.IsSuccessful) {
return new StreamInfo(response.AsStream(), response.ContentLength, response.ContentType, GetLastModifiedTimestampFromResponse(response));
}
if(response.Status == DreamStatus.NotFound) {
response.Close();
return null;
}
throw new DreamInternalErrorException(string.Format("S3 unable to fetch file (status {0}, message {1})", response.Status, response.AsText()));
} catch {
if(response != null) {
response.Close();
}
throw;
}
}
示例9: From
/// <summary>
/// Create a document from a text reader.
/// </summary>
/// <param name="reader">Document text reader.</param>
/// <param name="mime">Document mime-type.</param>
/// <returns>New document instance.</returns>
public static XDoc From(TextReader reader, MimeType mime)
{
if(reader == null) {
throw new ArgumentNullException("reader");
}
if(mime == null) {
throw new ArgumentNullException("mime");
}
if(mime.Match(MimeType.VCAL)) {
return VersitUtil.FromVersit(reader, "vcal");
}
if(mime.Match(MimeType.VERSIT)) {
return VersitUtil.FromVersit(reader, "vcard");
}
if(mime.Match(MimeType.HTML)) {
return FromHtml(reader);
}
if(mime.IsXml) {
return FromXml(reader);
}
if(mime.Match(MimeType.FORM_URLENCODED)) {
return XPostUtil.FromXPathValuePairs(XUri.ParseParamsAsPairs(reader.ReadToEnd()), "form");
}
throw new ArgumentException("unsupported mime-type: " + mime.FullType, "mime");
}
示例10: GetResoucePlug
private Plug GetResoucePlug(string graph, string app, string format, MimeType mime) {
string hash = StringUtil.ComputeHashString(graph);
string key = string.Format("{0}.{1}.{2}", hash, Path.GetFileNameWithoutExtension(app), format);
Plug location = Storage.At(key);
// check if the target resource needs to be generated
if(!location.InvokeAsync("HEAD", DreamMessage.Ok()).Wait().IsSuccessful) {
Stream data;
using(Stream input = new MemoryStream(Encoding.UTF8.GetBytes(graph))) {
// execute process
Stream output;
Stream error;
Tuplet<int, Stream, Stream> exitValues = Async.ExecuteProcess(app, "-T" + format, input, new Result<Tuplet<int, Stream, Stream>>(TimeSpan.FromSeconds(30))).Wait();
int status = exitValues.Item1;
using(output = exitValues.Item2) {
using(error = exitValues.Item3) {
if(status != 0) {
string message;
using(StreamReader reader = new StreamReader(error, Encoding.ASCII)) {
message = reader.ReadToEnd();
}
throw new DreamInternalErrorException(string.Format("graphviz failed with status {0}:\n{1}", status, message));
}
data = output.ToChunkedMemoryStream(-1, new Result<ChunkedMemoryStream>()).Wait();
}
}
}
// create result
location.With("ttl", TimeSpan.FromDays(7).TotalSeconds).Put(DreamMessage.Ok(mime, data.Length, data));
}
return Self.At("images", key);
}
示例11: ValidateCommentText
private static void ValidateCommentText(MimeType mimetype, string content) {
if (!MimeType.TEXT.Match(mimetype))
throw new DreamBadRequestException(string.Format(DekiResources.COMMENT_MIMETYPE_UNSUPPORTED, mimetype.ToString(), MimeType.HTML.ToString(), MimeType.TEXT.ToString()));
}
示例12: From
/// <summary>
/// Create a document from a stream.
/// </summary>
/// <param name="stream">Document stream.</param>
/// <param name="mime">Document mime-type.</param>
/// <param name="detectEncoding">Detect character encoding in stream.</param>
/// <returns>New document instance.</returns>
public static XDoc From(Stream stream, MimeType mime, bool detectEncoding)
{
if(stream == null) {
throw new ArgumentNullException("stream");
}
if(mime == null) {
throw new ArgumentNullException("mime");
}
if(!stream.CanSeek && !(stream is BufferedStream)) {
stream = new BufferedStream(stream);
}
var encoding = detectEncoding ? stream.DetectEncoding() : mime.CharSet;
using(TextReader reader = new StreamReader(stream, encoding ?? mime.CharSet)) {
return From(reader, mime);
}
}
示例13: TryParse
/// <summary>
/// Try to parse a mime-type from a content-type string.
/// </summary>
/// <param name="contentTypeWithParameters">Content type string.</param>
/// <param name="result">Mime-type instance return value.</param>
/// <returns><see langword="True"/> if a mime-type could be parsed.</returns>
public static bool TryParse(string contentTypeWithParameters, out MimeType result)
{
string type;
string subtype;
Dictionary<string, string> parameters;
if(!TryParse(contentTypeWithParameters, out type, out subtype, out parameters)) {
result = null;
return false;
}
result = new MimeType(type, subtype, parameters);
return true;
}
示例14: Match
//--- Methods ---
/// <summary>
/// Try to match instance against another instance.
/// </summary>
/// <param name="other">Other mime-type.</param>
/// <returns><see langword="True"/> if the two types match.</returns>
public bool Match(MimeType other)
{
// match main type
if((MainType != "*") && (other.MainType != "*") && (MainType != other.MainType)) {
return false;
}
// match subtype
if((SubType != "*") && (other.SubType != "*") && (SubType != other.SubType)) {
return false;
}
return true;
}
示例15: AddLink
/// <summary>
/// Add a link to the document.
/// </summary>
/// <param name="href">Uri to the linked resource.</param>
/// <param name="relation">Relationship of the linked resource to the current document.</param>
/// <param name="type">Type of resource being linked.</param>
/// <param name="length">Size in bytes.</param>
/// <param name="title">Title of the linked resource.</param>
/// <returns>Returns the current document instance.</returns>
public XAtomBase AddLink(XUri href, LinkRelation relation, MimeType type, long? length, string title)
{
Start("link");
Attr("href", href);
Attr("rel", relation.ToString().ToLowerInvariant());
if(type != null) {
Attr("type", type.FullType);
}
if(length != null) {
Attr("length", length ?? 0);
}
if(!string.IsNullOrEmpty(title)) {
Attr("title", title);
}
End();
return this;
}