Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Add support for ExportItems and UploadItems #109

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,4 @@ UpgradeLog*.htm

# Microsoft Fakes
FakesAssemblies/
/.vs/slnx.sqlite
/.vs/slnx.sqlite
25 changes: 25 additions & 0 deletions Core/ExchangeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1553,6 +1553,18 @@ public ServiceResponseCollection<MarkAsJunkResponse> MarkAsJunk(IEnumerable<Item
request.MoveItem = moveItem;
return request.Execute();
}
/// <summary>
/// Export items from exchange
/// </summary>
/// <param name="itemIds">The ids of the items to be exported.</param>
/// <returns></returns>
public ServiceResponseCollection<ExportItemsResponse> ExportItems(IEnumerable<ItemId> itemIds)
{
ExportItemsRequest request = new ExportItemsRequest(this, ServiceErrorHandling.ReturnErrors);
request.ItemIds.AddRange(itemIds);
return request.Execute();
}


#endregion

Expand Down Expand Up @@ -5885,5 +5897,18 @@ internal string TargetServerVersion
}

#endregion
/// <summary>
/// Upload items to Exchange
/// </summary>
/// <param name="item">The item to Upload</param>
/// <returns>An UploadItemsResponse for the requested UploadItem</returns>
public UploadItemsResponse UploadItem(UploadItem item)
{
UploadItemsRequest request = new UploadItemsRequest(this, ServiceErrorHandling.ReturnErrors);

request.Items = new UploadItem[] { item };

return request.Execute()[0];
}
}
}
58 changes: 58 additions & 0 deletions Core/Requests/ExportItemsRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Microsoft.Exchange.WebServices.Data
{
internal class ExportItemsRequest: MultiResponseServiceRequest<ExportItemsResponse>
{
private ItemIdWrapperList itemIds = new ItemIdWrapperList();

internal ExportItemsRequest(ExchangeService exchangeService, ServiceErrorHandling serviceErrorHandling) : base(exchangeService, serviceErrorHandling)
{

}

internal override ExportItemsResponse CreateServiceResponse(ExchangeService service, int responseIndex)
{
return new ExportItemsResponse();
}

internal override string GetResponseMessageXmlElementName()
{
return XmlElementNames.ExportItemsResponseMessage;
}

internal override int GetExpectedResponseMessageCount()
{
return itemIds.Count;
}

internal override string GetXmlElementName()
{
return XmlElementNames.ExportItems;
}

internal override string GetResponseXmlElementName()
{
return XmlElementNames.ExportItemsResponse;
}

internal override ExchangeVersion GetMinimumRequiredServerVersion()
{
return ExchangeVersion.Exchange2013;
}

internal override void WriteElementsToXml(EwsServiceXmlWriter writer)
{
base.WriteAttributesToXml(writer);
itemIds.WriteToXml(writer, XmlNamespace.Messages, XmlElementNames.ItemIds);
}

public ItemIdWrapperList ItemIds
{
get { return this.itemIds; }
}
}
}
79 changes: 79 additions & 0 deletions Core/Requests/UploadItemsRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Microsoft.Exchange.WebServices.Data
{
internal class UploadItemsRequest : MultiResponseServiceRequest<UploadItemsResponse>
{
IEnumerable<UploadItem> uploadItems;

internal UploadItemsRequest(ExchangeService service, ServiceErrorHandling errorHandling) : base(service, errorHandling)
{

}

internal override UploadItemsResponse CreateServiceResponse(ExchangeService service, int responseIndex)
{
return new UploadItemsResponse();
}

internal override string GetResponseMessageXmlElementName()
{
return XmlElementNames.UploadItemsResponseMessage;
}

internal override int GetExpectedResponseMessageCount()
{
return EwsUtilities.GetEnumeratedObjectCount(this.uploadItems);
}

internal override string GetXmlElementName()
{
return XmlElementNames.UploadItems;
}

internal override string GetResponseXmlElementName()
{
return XmlElementNames.UploadItemsResponse;
}

internal override ExchangeVersion GetMinimumRequiredServerVersion()
{
return ExchangeVersion.Exchange2010;
}

internal override void WriteElementsToXml(EwsServiceXmlWriter writer)
{
writer.WriteStartElement(XmlNamespace.Messages, XmlElementNames.Items);

foreach(UploadItem uploadItem in uploadItems)
{
writer.WriteStartElement(XmlNamespace.Types, XmlElementNames.Item);
writer.WriteAttributeString("CreateAction", uploadItem.CreateAction.ToString());

uploadItem.ParentFolderId.WriteToXml(writer, XmlNamespace.Types, XmlElementNames.ParentFolderId);

if(uploadItem.Id != null)
{
uploadItem.Id.WriteToXml(writer);
}

writer.WriteStartElement(XmlNamespace.Types, XmlElementNames.Data);
writer.WriteBase64ElementValue(uploadItem.Data);
writer.WriteEndElement();

writer.WriteEndElement();
}

writer.WriteEndElement();
}

public IEnumerable<UploadItem> Items
{
get { return uploadItems; }
set { uploadItems = value; }
}
}
}
58 changes: 58 additions & 0 deletions Core/Responses/ExportItemsResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Microsoft.Exchange.WebServices.Data
{
/// <summary>
/// Represents the response from an Export Items Request
/// </summary>
public class ExportItemsResponse : ServiceResponse
{
private ItemId itemId = new ItemId();
private byte[] data;

internal override void ReadElementsFromXml(EwsServiceXmlReader reader)
{
base.ReadElementsFromXml(reader);

if(!reader.IsStartElement(XmlNamespace.Messages, XmlElementNames.ItemId))
{
reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.ItemId);
}

itemId.LoadFromXml(reader, XmlNamespace.Messages, XmlAttributeNames.ItemId);

if(!reader.IsStartElement(XmlNamespace.Messages, XmlElementNames.Data))
{
reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.Data);
}
data = reader.ReadBase64ElementValue();
}

/// <summary>
/// ItemId of the item exported.
/// </summary>

public ItemId ItemId
{
get
{
return itemId;
}
}

/// <summary>
/// Field containing the item exported.
/// </summary>
public byte[] Data
{
get
{
return data;
}
}

}
}
35 changes: 35 additions & 0 deletions Core/Responses/UploadItemsResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Microsoft.Exchange.WebServices.Data
{
/// <summary>
/// Reponse of the Upload items operation.
/// </summary>
public class UploadItemsResponse : ServiceResponse
{
private ItemId itemId = new ItemId();

internal override void ReadElementsFromXml(EwsServiceXmlReader reader)
{
base.ReadElementsFromXml(reader);

if(!reader.IsStartElement(XmlNamespace.Messages, XmlElementNames.ItemId))
{
reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.ItemId);
}

itemId.LoadFromXml(reader, XmlNamespace.Messages, XmlElementNames.ItemId);
}

/// <summary>
/// Id of the item uploaded
/// </summary>
public ItemId Id
{
get { return itemId; }
}
}
}
76 changes: 76 additions & 0 deletions Core/ServiceObjects/Items/UploadItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Microsoft.Exchange.WebServices.Data
{
/// <summary>
/// Represents and item to be uploaded to exchange.
/// </summary>
public class UploadItem : ServiceObject
{
/// <summary>
/// The default contructor for UploadItem
/// </summary>
/// <param name="service">The exchange service this item is related to.</param>
public UploadItem(ExchangeService service) : base(service) { }

internal override ServiceObjectSchema GetSchema()
{
return UploadSchema.Instance;
}

internal override ExchangeVersion GetMinimumRequiredServerVersion()
{
return ExchangeVersion.Exchange2010;
}

internal override void InternalLoad(PropertySet propertySet)
{
throw new NotImplementedException();
}

internal override void InternalDelete(DeleteMode deleteMode, SendCancellationsMode? sendCancellationsMode, AffectedTaskOccurrence? affectedTaskOccurrences)
{
throw new NotImplementedException();
}

internal override PropertyDefinition GetIdPropertyDefinition()
{
return UploadSchema.Id;
}

/// <summary>
/// The Id of the item to upload
/// </summary>
public ItemId Id
{
get { return (ItemId)this.PropertyBag[GetIdPropertyDefinition()]; }
set { this.PropertyBag[GetIdPropertyDefinition()] = value; }
}

/// <summary>
/// The id of the folder to upload the item to.
/// </summary>
public FolderId ParentFolderId
{
get { return (FolderId)this.PropertyBag[UploadSchema.ParentFolderId]; }
set { this.PropertyBag[UploadSchema.ParentFolderId] = value; }
}

/// <summary>
/// The data of the item.
/// </summary>
public byte[] Data
{
get { return (byte[])this.PropertyBag[UploadSchema.Data]; }
set { this.PropertyBag[UploadSchema.Data] = value; }
}

/// <summary>
/// The action to take for the uploaded item.
/// </summary>
public CreateAction CreateAction { get; set; }
}
}
1 change: 1 addition & 0 deletions Core/ServiceObjects/Schemas/ServiceObjectSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public abstract class ServiceObjectSchema : IEnumerable<PropertyDefinition>
typeList.Add(typeof(ServiceObjectSchema));
typeList.Add(typeof(SearchFolderSchema));
typeList.Add(typeof(TaskSchema));
typeList.Add(typeof(UploadSchema));

#if DEBUG
// Verify that all Schema types in the Managed API assembly have been included.
Expand Down
Loading