/// <summary> /// Сохранить вложение в документ. /// </summary> /// <param name="attachment">Сохраняемое вложение в документ.</param> /// <returns>Сохраненное вложение в документ с заполненным идентификатором</returns> public Guid Save(AttachmentBase attachment) { using (var uow = CreateUnitOfWork()) { return(uow.AttachmentRepository.Save(attachment)); } }
private static MimePart GetMimePart(AttachmentBase item) { var mimeType = item.ContentType.ToString(); var contentType = ContentType.Parse(mimeType); var attachment = item as Attachment; MimePart part; if (contentType.MediaType.Equals("text", StringComparison.OrdinalIgnoreCase)) { // Original: part = new TextPart(contentType); // Due to constructor of TextPart(ContentType contentType) being internal, // mimic the instantiation by using MimePart(ContentType contentType) part = new MimePart(contentType); } else { part = new MimePart(contentType); } if (attachment != null) { var disposition = attachment.ContentDisposition.ToString(); part.ContentDisposition = ContentDisposition.Parse(disposition); } switch (item.TransferEncoding) { case System.Net.Mime.TransferEncoding.QuotedPrintable: part.ContentTransferEncoding = ContentEncoding.QuotedPrintable; break; case System.Net.Mime.TransferEncoding.Base64: part.ContentTransferEncoding = ContentEncoding.Base64; break; case System.Net.Mime.TransferEncoding.SevenBit: part.ContentTransferEncoding = ContentEncoding.SevenBit; break; case System.Net.Mime.TransferEncoding.EightBit: part.ContentTransferEncoding = ContentEncoding.EightBit; break; } if (item.ContentId != null) { part.ContentId = item.ContentId; } var stream = new MemoryBlockStream(); item.ContentStream.CopyTo(stream); stream.Position = 0; #pragma warning disable CS0618 // Type or member is obsolete, this line will be removed once the ContentObject property is fully removed part.ContentObject = new ContentObject(stream); #pragma warning restore CS0618 // Type or member is obsolete, this line will be removed once the ContentObject property is fully removed return(part); }
public void RandamSet(AttachmentBase attachment) { bool check = false, s = false; Box box = coreBox.GetComponent <Box>(); List <Box> boxes = new List <Box>(); while (true) { for (int i = 0; i < box.aList.Length; i++) { if (box.aList[i] == null) { box.aList[i] = attachment; box.ListUpdata(); return; } else if (box.aList[i] is Box) { boxes.Add((Box)box.aList[i]); } } box = boxes[0]; boxes.Remove(boxes[0]); } }
private void OnTriggerEnter(Collider other) { GameObject target = other.gameObject; if (other.tag == "Attachment") { AttachmentBase a = other.GetComponent <AttachmentBase>(); target = a.parent.gameObject; if (target.tag == "Enemy") { MobBase mob = other.GetComponent <MobBase>(); mob.Damage(damage); } if (target.tag != "Player") { Destroy(gameObject); } } if (other.tag == "Enemy") { MobBase mob = other.GetComponent <MobBase>(); mob.Damage(damage); } if (other.tag != "Player") { Destroy(gameObject); } }
/// <summary> /// Creates a MIME body part from an entry of the AlternateView or Attachments collection of a /// MailMessage instance and appends it to the specified Stringbuilder instance. /// </summary> /// <param name="builder">The Stringbuilder instance to append the body part to.</param> /// <param name="view">An entry from either the AlternateView or the Attachments collection of /// a MailMessage instance.</param> static void AddAttachment(StringBuilder builder, AttachmentBase view) { // Append the MIME headers for this body part. string contentType = "Content-Type: " + view.ContentType.MediaType; foreach (string key in view.ContentType.Parameters.Keys) { contentType = contentType + "; " + key + "=" + view.ContentType.Parameters[key]; } builder.AppendLine(contentType); builder.AppendLine("Content-Transfer-Encoding: base64"); if (!string.IsNullOrEmpty(view.ContentId)) builder.AppendLine("Content-Id: <" + view.ContentId + ">"); if (view is Attachment) builder.AppendLine("Content-Disposition: attachment"); builder.AppendLine(); // Append the actual body part contents encoded as Base64. using (MemoryStream memstream = new MemoryStream()) { int bytesRead; byte[] buffer = new byte[4096]; while ((bytesRead = view.ContentStream.Read(buffer, 0, buffer.Length)) > 0) { memstream.Write(buffer, 0, bytesRead); } string str = Convert.ToBase64String(memstream.ToArray()); StringReader reader = new StringReader(str); char[] line = new char[76]; int read; while ((read = reader.Read(line, 0, line.Length)) > 0) builder.AppendLine(new string(line, 0, read)); } // Rewind the stream if it supports seeking. if (view.ContentStream.CanSeek) view.ContentStream.Seek(0, SeekOrigin.Begin); }
private static string GetStringFromView(AttachmentBase view) { var data = new byte[view.ContentStream.Length]; view.ContentStream.Read(data, 0, data.Length); return(Encoding.ASCII.GetString(data)); }
public void ListUpdata() { up = aList[0]; down = aList[1]; left = aList[2]; right = aList[3]; forward = aList[4]; back = aList[5]; }
protected static string GetStringFromView(AttachmentBase view) { Encoding encoding = resolveViewEncoding(view, Encoding.ASCII); var data = new byte[view.ContentStream.Length]; view.ContentStream.Read(data, 0, data.Length); return(encoding.GetString(data)); }
private static MimePart GetMimePart(AttachmentBase item) { var mimeType = item.ContentType.ToString(); var contentType = ContentType.Parse(mimeType); var attachment = item as Attachment; var part = new MimePart(contentType); // if (attachment != null) { var disposition = attachment.ContentDisposition.ToString(); part.ContentDisposition = ContentDisposition.Parse(disposition); } // Adjust the transfer encoding switch (item.TransferEncoding) { case TransferEncoding.QuotedPrintable: part.ContentTransferEncoding = ContentEncoding.QuotedPrintable; break; case TransferEncoding.Base64: part.ContentTransferEncoding = ContentEncoding.Base64; break; case TransferEncoding.SevenBit: part.ContentTransferEncoding = ContentEncoding.SevenBit; break; case TransferEncoding.EightBit: part.ContentTransferEncoding = ContentEncoding.EightBit; break; case TransferEncoding.Unknown: break; default: throw new ArgumentOutOfRangeException(); } // Adjust the attachment content identifier if (item.ContentId != null) { part.ContentId = item.ContentId; } // Copy the content of the attachment var stream = new MemoryBlockStream(); item.ContentStream.CopyTo(stream); stream.Position = 0; part.Content = new MimeContent(stream); // Done return(part); }
private static object GetHeaderCollection(AttachmentBase att) { const BindingFlags flags = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static; // Get System.Net.Mime.MimePart: object mimePart = GetMimePart(att); // Get System.Net.Mime.MimeBasePart.HeaderCollection: return(mimePart.GetType().BaseType.GetField("headers", flags).GetValue(mimePart)); }
private static string GetViewContent(AttachmentBase view) { var reader = new StreamReader(view.ContentStream); if (view.ContentStream.CanSeek) { view.ContentStream.Position = 0; } return(reader.ReadToEnd()); }
void SetMoveForceFromInput() { moveForce.Clear(parameters); InputData inputData = InputManager.Instance.Read(); sensors.UpdateAll(kobotoTransform, activeCollider); sensors.UpdateZones(levelZones); cameraPivotOffsetTarget = Vector3.zero; foreach (var attachmentType in attachmentOrder) { if (currentAttachments.ContainsKey(attachmentType)) { AttachmentBase attachment = currentAttachments[attachmentType]; attachment.ModifyMoveForce(moveForce, inputData, sensors, parameters); attachment.ModifyCameraPivot(ref cameraPivotOffsetTarget); } } ProcessMoveForce(moveForce, inputData, sensors, parameters); physMat.dynamicFriction = moveForce.dynamicFriction; physMat.staticFriction = moveForce.staticFriction; rb.drag = moveForce.airDrag; rb.useGravity = moveForce.useGravity; rb.AddForce(moveForce.TotalForce(), moveForce.forceMode); upRotation = Quaternion.Lerp(upRotation, moveForce.upRotation, 0.5f); float targetAngle = Utils.AngleFromWorldUp(upRotation) + tiltAngle; float currentAngle = Utils.AngleFromWorldUp(kobotoTransform.up); float rotationAngleError = targetAngle - currentAngle; float correction = rotationController.Update(rotationAngleError, Time.fixedDeltaTime); rb.AddTorque(correction * Vector3.right); tiltAngle = Mathf.Lerp(tiltAngle, moveForce.tiltAngle, 4f * Time.fixedDeltaTime); float clampedTilt = Mathf.Clamp(tiltAngle + currentAngle, -75f, 75f) - currentAngle; rotatePivot.localRotation = Quaternion.Lerp(rotatePivot.localRotation, Quaternion.AngleAxis(moveForce.tiltStrength * clampedTilt, Vector3.right), 16f * Time.fixedDeltaTime); }
protected static Encoding resolveViewEncoding(AttachmentBase view, Encoding fallbackEncoding) { String charSet = view.ContentType.CharSet; try { return(Encoding.GetEncoding(charSet)); } catch { return(fallbackEncoding); } }
public async Task <List <AttachmentBase> > GetAllAttachmentsAsync(FolderContentType folderContentType, string itemId) { // Get all attachments of the specified item. // The property of the item to get is very limited. Uri URL; List <AttachmentBase> result = new List <AttachmentBase>(); switch (folderContentType) { case FolderContentType.Message: case FolderContentType.MsgFolderRoot: case FolderContentType.Drafts: URL = Util.UseMicrosoftGraphInMailboxViewer ? new Uri($"https://graph.microsoft.com/v1.0/me/messages/{itemId}/attachments/?$Top=1000&$select=Id,Name,ContentType") : new Uri($"https://outlook.office.com/api/v2.0/me/messages/{itemId}/attachments/?$Top=1000&$select=Id,Name,ContentType"); break; case FolderContentType.Calendar: URL = Util.UseMicrosoftGraphInMailboxViewer? new Uri($"https://graph.microsoft.com/v1.0/me/events/{itemId}/attachments/?$Top=1000&$select=Id,Name,ContentType") : new Uri($"https://outlook.office.com/api/v2.0/me/events/{itemId}/attachments/?$Top=1000&$select=Id,Name,ContentType"); break; case FolderContentType.Task: URL = Util.UseMicrosoftGraphInMailboxViewer ? new Uri($"https://graph.microsoft.com/beta/me/outlook/tasks/{itemId}/attachments/?$Top=1000&$select=Id,Name,ContentType") : new Uri($"https://outlook.office.com/api/v2.0/me/tasks/{itemId}/attachments/?$Top=1000&$select=Id,Name,ContentType"); break; case FolderContentType.Contact: // contact item (Contact API) does not have attachment. default: return(new List <AttachmentBase>()); } try { string stringResponse = await SendGetRequestAsync(URL); var jsonResponse = (JObject)JsonConvert.DeserializeObject(stringResponse); var attachments = (JArray)jsonResponse.GetValue("value"); foreach (var item in attachments) { var serializedObject = new AttachmentBase(JsonConvert.SerializeObject(item)); result.Add(serializedObject); } } catch (Exception ex) { throw ex; } return(result); }
public void RemoveAttachmentOfType(EAttachmentType type) { AttachmentBase attachment = null; if (currentAttachments.TryGetValue(type, out attachment)) { attachment.Remove(); EAttachmentTarget target = Attachments.AttachmentTarget(type); currentAttachments.Remove(type); attachmentTargetContents.Remove(target); SetupCollider(); } }
private static void WriteAttachmentBase(this BinaryWriter w, AttachmentBase attachment) { w.Write(attachment.ContentStream); // ContentType is completely serialized through it's `ToString()` method w.Write(attachment.ContentType.ToString()); w.Write(attachment.ContentId != null); if (attachment.ContentId != null) { w.Write(attachment.ContentId); } w.Write((int)attachment.TransferEncoding); }
void au(AttachmentBase ab, Vector3 dir) { if (ab != null) { ab.transform.parent = transform; ab.transform.localPosition = dir; ab.mobBase = mobBase; ab.parent = this; //ab.transform.localRotation = Quaternion.Euler(Vector3.zero); if (dir == Vector3.up) { aList[0] = ab; dir = Vector3.left * 90; } else if (dir == Vector3.down) { aList[1] = ab; dir = Vector3.left * -90; } else if (dir == Vector3.left) { aList[2] = ab; dir = Vector3.up * -90; } else if (dir == Vector3.right) { aList[3] = ab; dir = Vector3.up * 90; } else if (dir == Vector3.forward) { aList[4] = ab; dir = Vector3.zero; } else if (dir == Vector3.back) { aList[5] = ab; dir = Vector3.up * 180; } else { Debug.LogError("よくわからん値が入力されとるぞ"); } ab.transform.localRotation = Quaternion.Euler(dir); } }
public void RemoveAttachmentFromTarget(EAttachmentTarget target) { AttachmentBase attachment = null; if (attachmentTargetContents.TryGetValue(target, out attachment)) { attachment.OnRemoveFromKoboto(this); attachment.Remove(); EAttachmentType type = attachment.attachmentType; currentAttachments.Remove(type); attachmentTargetContents.Remove(target); SetupCollider(); Debug.Log("Removeing attachment: " + type + " from " + target); } }
private static void DumpAttachment(string dir, AttachmentBase attachment) { string name = null; if (!string.IsNullOrEmpty(attachment.ContentType.Name)) { name = attachment.ContentType.Name; } else { name = attachment is AlternateView ? "alternate-view" : "attachment"; string ext = MimeUtility.GetFileExtensionFromMediaType(attachment.ContentType.MediaType); if (ext == "eml") { name = "attached-message"; } name = string.Format(name + "." + ext); } int i = 1; string shortname = null; while (File.Exists(dir + Path.DirectorySeparatorChar + name)) { FileInfo fi = new FileInfo(name); if (null == shortname) { shortname = fi.Name.Substring(0, fi.Name.Length - fi.Extension.Length); } name = string.Format("{0} ({1}){2}", shortname, i, fi.Extension); i++; } using (Stream stream = File.Create(dir + Path.DirectorySeparatorChar + name)) { byte[] buffer = new byte[32768]; while (true) { int read = attachment.ContentStream.Read(buffer, 0, buffer.Length); if (read <= 0) { break; } stream.Write(buffer, 0, read); } } }
public void AddAttachment(EAttachmentType type) { AttachmentBase attachment = Attachments.CreateNewAttachment(type); EAttachmentTarget target = Attachments.AttachmentTarget(type); RemoveAttachmentFromTarget(target); Transform attachToTransform = GetAttachmentTargetTransform(target); attachment.transform.SetParent(attachToTransform, false); attachmentTargetContents[target] = attachment; currentAttachments[attachment.attachmentType] = attachment; Debug.Log("Adding attachment: " + type + " to " + target); SetupCollider(); attachment.OnAttachToKoboto(this); }
private static byte[] getAttachmentBytes(AttachmentBase attachment) { MemoryStream actual = new MemoryStream(); Stream stream = attachment.ContentStream; while (true) { int outByte = stream.ReadByte(); if (outByte != -1) { actual.Write(new[] { (byte)outByte }, 0, 1); } else { break; } } return(actual.ToArray()); }
public ActionResult <IEnumerable <AttachmentBase> > Attachments(string id, string attachmentTypeCode) { if (string.IsNullOrWhiteSpace(id)) { throw new ArgumentNullException(nameof(id), "Customer id cannot be null"); } List <AttachmentBase> Result = new List <AttachmentBase>(); var predicate = PredicateBuilder.New <CM_B_ATTACHMENT>(E => E.CUSTOMER_CODE == id); if (!string.IsNullOrWhiteSpace(attachmentTypeCode)) { predicate = predicate.And(E => E.ATTACHMENT_TYPE_CODE == attachmentTypeCode); } foreach (CM_B_ATTACHMENT Item in DBContext.CM_B_ATTACHMENT.Where(predicate)) { AttachmentBase I = EntityMapper.Map <AttachmentBase, CM_B_ATTACHMENT>(DBContext, Item); Result.Add(I); } return(Result); }
public Guid Post([FromBody] AttachmentBase attachment) { return(AttachmentService.Save(attachment)); }
/// <summary> /// 获取MimePart /// </summary> /// <param name="item">附件基类</param> /// <returns></returns> private static MimePart GetMimePart(AttachmentBase item) { var mimeType = item.ContentType.ToString(); var contentType = ContentType.Parse(mimeType); var attachemt = item as Attachment; MimePart part; if (contentType.MediaType.Equals("text", StringComparison.OrdinalIgnoreCase)) { part = new TextPart(); } else { part = new MimePart(contentType); } if (attachemt != null) { //var disposition = attachemt.ContentDisposition.ToString(); //part.ContentDisposition = ContentDisposition.Parse(disposition); part.ContentDisposition = new ContentDisposition(ContentDisposition.Attachment); } switch (item.TransferEncoding) { case System.Net.Mime.TransferEncoding.QuotedPrintable: part.ContentTransferEncoding = ContentEncoding.QuotedPrintable; break; case System.Net.Mime.TransferEncoding.Base64: part.ContentTransferEncoding = ContentEncoding.Base64; break; case System.Net.Mime.TransferEncoding.SevenBit: part.ContentTransferEncoding = ContentEncoding.SevenBit; break; case System.Net.Mime.TransferEncoding.EightBit: part.ContentTransferEncoding = ContentEncoding.EightBit; break; } if (item.ContentId != null) { part.ContentId = item.ContentId; } var stream = new MemoryBlockStream(); item.ContentStream.CopyTo(stream); stream.Position = 0; part.Content = new MimeContent(stream); if (attachemt != null) { // 解决中文文件名乱码 var charset = "GB18030"; part.ContentType.Parameters.Clear(); part.ContentDisposition.Parameters.Clear(); var fileName = attachemt.Name; part.ContentType.Parameters.Add(charset, "name", fileName); part.ContentDisposition.Parameters.Add(charset, "filename", fileName); // 解决文件名不能超过41字符 foreach (var parameter in part.ContentDisposition.Parameters) { parameter.EncodingMethod = ParameterEncodingMethod.Rfc2047; } foreach (var parameter in part.ContentType.Parameters) { parameter.EncodingMethod = ParameterEncodingMethod.Rfc2047; } } return(part); }
private static object GetMimePart(AttachmentBase att) { const BindingFlags flags = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static; return(typeof(AttachmentBase).GetField("part", flags).GetValue(att)); }
public AttachmentFormPart(AttachmentBase attachment) { Attachment = attachment; }
public virtual void Dispose() { AttachmentBase.Dispose(); }
private List <PageHtml> GetHtmlPages(AttachmentBase attachment, HtmlOptions htmlOptions, out List <string> cssList) { var htmlPages = _htmlHandler.GetPages(attachment, htmlOptions); cssList = new List <string>(); foreach (var page in htmlPages) { var test = page.HtmlResources; var indexOfBodyOpenTag = page.HtmlContent.IndexOf("<body>", StringComparison.InvariantCultureIgnoreCase); if (indexOfBodyOpenTag > 0) { page.HtmlContent = page.HtmlContent.Substring(indexOfBodyOpenTag + "<body>".Length); } var indexOfBodyCloseTag = page.HtmlContent.IndexOf("</body>", StringComparison.InvariantCultureIgnoreCase); if (indexOfBodyCloseTag > 0) { page.HtmlContent = page.HtmlContent.Substring(0, indexOfBodyCloseTag); } //if (Path.GetExtension(filePath) == ".msg") //{ // foreach (var resource in page.HtmlResources.Where(_ => _.ResourceType == HtmlResourceType.Image)) // { // string imagePath = string.Format("resources\\page{0}\\{1}", // page.PageNumber, resource.ResourceName); // page.HtmlContent = page.HtmlContent.Replace(resource.ResourceName, // string.Format("/document-viewer/GetResourceForHtml?documentPath={0}&pageNumber={1}&resourceName={2}", // filePath, page.PageNumber, resource.ResourceName)); // } //} foreach (var resource in page.HtmlResources.Where(_ => _.ResourceType == HtmlResourceType.Style)) { var cssStream = _htmlHandler.GetResource(attachment, resource); var text = new StreamReader(cssStream).ReadToEnd(); var needResave = false; if (text.IndexOf("url(\"", StringComparison.Ordinal) >= 0 && text.IndexOf("url(\"/document-viewer/GetResourceForHtml?documentPath=", StringComparison.Ordinal) < 0) { needResave = true; text = text.Replace("url(\"", string.Format("url(\"/document-viewer/GetResourceForHtml?documentPath={0}&pageNumber={1}&resourceName=", attachment.Name, page.PageNumber)); } if (text.IndexOf("url('", StringComparison.Ordinal) >= 0 && text.IndexOf("url('/document-viewer/GetResourceForHtml?documentPath=", StringComparison.Ordinal) < 0) { needResave = true; text = text.Replace("url('", string.Format( "url('/document-viewer/GetResourceForHtml?documentPath={0}&pageNumber={1}&resourceName=", attachment.Name, page.PageNumber)); } // update path to image resource cssList.Add(text); if (needResave) { var fullPath = Path.Combine(_tempPath, attachment.Name.Replace('.', '_'), "html", "resources", string.Format("page{0}", page.PageNumber), resource.ResourceName); System.IO.File.WriteAllText(fullPath, text); } } List <string> cssClasses = Utils.GetCssClasses(page.HtmlContent); foreach (var cssClass in cssClasses) { var newCssClass = string.Format("page-{0}-{1}", page.PageNumber, cssClass); page.HtmlContent = page.HtmlContent.Replace(cssClass, newCssClass); for (int i = 0; i < cssList.Count; i++) { cssList[i] = cssList[i].Replace(cssClass, newCssClass); } } } return(htmlPages); }