Modified how attachments are pushed to the API.
Added support for BMP and GIF image types.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using PWAPPv2.Source.DataObjects;
|
||||
using Microsoft.Identity.Client;
|
||||
using PWAPPv2.Source.DataObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -49,5 +50,29 @@ namespace PWAPPv2.Source.Attachments
|
||||
return attachment;
|
||||
|
||||
}
|
||||
|
||||
public static PWBaseAttachment BuildBaseAttachment(string token, PWImage image)
|
||||
{
|
||||
PWBaseAttachment attachment = new PWBaseAttachment();
|
||||
attachment.AttToken = token.Replace("\"", "");
|
||||
attachment.ThumbExists = true;
|
||||
attachment.ZoomExists = true;
|
||||
attachment.FileDate = "";
|
||||
attachment.FileName = image.ShortFileName();
|
||||
attachment.FileType = image.FileType;
|
||||
return attachment;
|
||||
}
|
||||
|
||||
public static PWBaseAttachment BuildBaseAttachment(string token, PWPdf pdf)
|
||||
{
|
||||
PWBaseAttachment attachment = new PWBaseAttachment();
|
||||
attachment.AttToken = token.Replace("\"", "");
|
||||
attachment.ThumbExists = false;
|
||||
attachment.ZoomExists = true;
|
||||
attachment.FileDate = "";
|
||||
attachment.FileName = pdf.ShortFileName();
|
||||
attachment.FileType = "application/pdf";
|
||||
return attachment;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PWAPPv2.Source.Attachments
|
||||
{
|
||||
public class AttachmentResponse
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,10 @@ namespace PWAPPv2.Source.Attachments
|
||||
SupportedImageTypes.Add(".jpeg");
|
||||
SupportedImageTypes.Add(".jpg");
|
||||
SupportedImageTypes.Add(".png");
|
||||
//SupportedImageTypes.Add(".tiff");
|
||||
SupportedImageTypes.Add(".tiff");
|
||||
SupportedImageTypes.Add(".tif");
|
||||
SupportedImageTypes.Add(".gif");
|
||||
SupportedImageTypes.Add(".bmp");
|
||||
|
||||
SupportedDocumentTypes.Clear();
|
||||
SupportedDocumentTypes.Add(".pdf");
|
||||
@@ -108,23 +111,50 @@ namespace PWAPPv2.Source.Attachments
|
||||
}
|
||||
foreach(DataObjects.Attachment attachment in Attachments)
|
||||
{
|
||||
PWAttachment att = null;
|
||||
//PWAttachment att = null;
|
||||
PWBaseAttachment ba = null;
|
||||
|
||||
List<PWFileUpload> fileUploads = new List<PWFileUpload>();
|
||||
|
||||
if (attachment.image != null)
|
||||
{
|
||||
att = AttachmentFactory.BuildAttachment(credentials, token, attachment.image);
|
||||
//att = AttachmentFactory.BuildAttachment(credentials, token, attachment.image);
|
||||
ba = AttachmentFactory.BuildBaseAttachment(token, attachment.image);
|
||||
//fileUploads.Add(attachment.image.GetFileUploads(attachment.co))
|
||||
|
||||
string json = JsonSerializer.Serialize(ba);
|
||||
string contId = connection.SendPostWithCredsInHeader("api/PWAddAttachment", json);
|
||||
contId = contId.Replace("\"", "").Replace("\\n", "").Trim();
|
||||
fileUploads = attachment.image.GetFileUploads(token, contId);
|
||||
foreach(PWFileUpload file in fileUploads)
|
||||
{
|
||||
json = JsonSerializer.Serialize(file);
|
||||
connection.SendPostWithCredsInHeader("api/PWUploadFile", json);
|
||||
}
|
||||
}
|
||||
else if (attachment.pdf != null)
|
||||
{
|
||||
att = AttachmentFactory.BuildAttachment(credentials, token, attachment.pdf);
|
||||
//att = AttachmentFactory.BuildAttachment(credentials, token, attachment.pdf);
|
||||
ba = AttachmentFactory.BuildBaseAttachment(token, attachment.pdf);
|
||||
|
||||
string json = JsonSerializer.Serialize(ba);
|
||||
string contId = connection.SendPostWithCredsInHeader("api/PWAddAttachment", json);
|
||||
fileUploads = attachment.pdf.GetFileUploads(token, contId);
|
||||
foreach (PWFileUpload file in fileUploads)
|
||||
{
|
||||
json = JsonSerializer.Serialize(file);
|
||||
connection.SendPostWithCredsInHeader("api/PWUploadFile", json);
|
||||
}
|
||||
}
|
||||
|
||||
if (att == null)
|
||||
{
|
||||
throw new AttachmentTypeNotYetSupportedException();
|
||||
}
|
||||
string json = JsonSerializer.Serialize(att);
|
||||
connection.SendPostWithCredsInHeader("api/PWAttachment", json);
|
||||
//if (att == null)
|
||||
//{
|
||||
// throw new AttachmentTypeNotYetSupportedException();
|
||||
//}
|
||||
//string json = JsonSerializer.Serialize(att);
|
||||
//connection.SendPostWithCredsInHeader("api/PWAttachment", json);
|
||||
//json = JsonSerializer.Serialize(ba);
|
||||
//connection.SendPostWithCredsInHeader("api/PWAddAttachment", json);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PWAPPv2.Source.Attachments
|
||||
{
|
||||
public class PWBaseAttachment
|
||||
{
|
||||
public string AttToken { get; set; }
|
||||
public string FileName { get; set; }
|
||||
public bool ThumbExists { get; set; }
|
||||
public bool ZoomExists { get; set; }
|
||||
public string FileDate { get; set; }
|
||||
public string FileType { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PWAPPv2.Source.Attachments
|
||||
{
|
||||
public class PWFileUpload
|
||||
{
|
||||
public string Base64Content { get; set; }
|
||||
public string AttToken { get; set; }
|
||||
public string ContentId { get; set; }
|
||||
public string Tag { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user