Skip to content

Commit e465b97

Browse files
committed
GetAttachmentRequest and Response is complete, attachments can not be created and sent, fetched.
1 parent bd8160e commit e465b97

File tree

8 files changed

+255
-63
lines changed

8 files changed

+255
-63
lines changed

src/js/ComplexProperties/AttachmentCollection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class AttachmentCollection extends ComplexPropertyCollection<Attachment>
3838
/**
3939
* The item owner that owns this attachment collection
4040
*/
41-
private owner: Item;
41+
private owner: Item = null;
4242
/**
4343
* @interface:IOwnedProperty The owner of this attachment collection.
4444
*/

src/js/ComplexProperties/ComplexPropertyCollection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export class ComplexPropertyCollection<TComplexProperty extends ComplexProperty>
138138
}
139139
}
140140
for (let jsonObject of collection) {
141-
let jsonProperty = jsonObject;;
141+
let jsonProperty = jsonObject;
142142

143143
if (jsonProperty != null) {
144144
let complexProperty: TComplexProperty = null;

src/js/ComplexProperties/ItemAttachment.ts

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export class ItemAttachment extends Attachment {
6565
* @return {string} The XML element name.
6666
*/
6767
GetXmlElementName(): string { return XmlElementNames.ItemAttachment; }
68-
68+
6969
//InternalToJson(service: ExchangeService): any { throw new Error("ItemAttachment.ts - InternalToJson : Not implemented."); }
7070

7171
/**
@@ -78,7 +78,7 @@ export class ItemAttachment extends Attachment {
7878
this.Owner.PropertyBag.Changed();
7979
}
8080
}
81-
81+
8282
//Load(...additionalProperties: PropertyDefinitionBase[]): IPromise<void>;
8383
/**
8484
* Loads this attachment.
@@ -96,36 +96,20 @@ export class ItemAttachment extends Attachment {
9696
Load(bodyType: BodyType, additionalProperties: PropertyDefinitionBase[] /** System.Collections.Generic.IEnumerable<PropertyDefinitionBase> */): IPromise<void>;
9797
Load(bodyTypeOrPeoperties: BodyType | PropertyDefinitionBase[], additionalProperties?: PropertyDefinitionBase[]): IPromise<void> {
9898
let argsLength = arguments.length;
99-
let props: PropertyDefinitionBase[] = [];
99+
let props: PropertyDefinitionBase[] = null;
100100
let bodyType: BodyType = null;
101101
if (argsLength === 1) {
102-
if (Array.isArray(bodyTypeOrPeoperties)) {
103-
props = bodyTypeOrPeoperties;
104-
}
105-
else {
106-
throw new Error("ItemAttachment.ts - Load with " + argsLength + " parameters, incorrect uses of parameter at 1st position, it must be array of PropertyDefinitionBase or its derived type");
107-
} throw new Error("ExchangeServiceBase.ts - ctor with " + argsLength + " parameters - incorrect uses of parameter at 1st position, it must be ExchangeVersion when using TimeZoneInfo at 2nd place");
108-
102+
props = <PropertyDefinitionBase[]>bodyTypeOrPeoperties;
109103
}
110104
if (argsLength === 2) {
111-
if (typeof bodyTypeOrPeoperties === "number") {
112-
113-
bodyType = bodyTypeOrPeoperties;
114-
props = additionalProperties;
115-
}
116-
else {
117-
throw new Error("ItemAttachment.ts - Load with " + argsLength + " parameters, incorrect uses of parameter at 1st position, it must be BodyType enumeration");
118-
}
119-
if (!Array.isArray(additionalProperties)) {
120-
throw new Error("ItemAttachment.ts - Load with " + argsLength + " parameters, incorrect uses of parameter at 2nd position, it must be array of PropertyDefinitionBase or its derived type");
121-
}
105+
bodyType = <BodyType>bodyTypeOrPeoperties;
122106
}
123107
if (argsLength > 2) {
124108
throw new Error("ItemAttachment.ts - Load with " + argsLength + " parameters, invalid number of arguments, check documentation and try again.");
125109
}
126110
return this.InternalLoad(bodyType, props);
127111
}
128-
112+
129113
/**
130114
* @internal Loads from XMLjsObject.
131115
*
@@ -162,7 +146,7 @@ export class ItemAttachment extends Attachment {
162146
}
163147
}
164148
}
165-
149+
166150
//ReadElementsFromXmlJsObject(reader: any): void { throw new Error("ItemAttachment.ts - TryReadElementFromXmlJsObject : Not implemented."); }
167151
ReadElementsFromXmlJsObjectToPatch(reader: any): boolean { throw new Error("ItemAttachment.ts - TryReadElementFromXmlToPatch : Not implemented."); }
168152

src/js/Core/EwsUtilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ export class EwsUtilities {
632632
static ValidateParamAllowNull(param: any, paramName: string): void {
633633
var selfValidate: ISelfValidate = param;
634634

635-
if (selfValidate.Validate) {//todo: interface detection for ISelfValidate
635+
if (selfValidate.Validate && false) {//todo: interface detection for ISelfValidate
636636
try {
637637
selfValidate.Validate();
638638
}

src/js/Core/PropertySet.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,7 @@ export class PropertySet /*implements ISelfValidate*/ { //IEnumerable<PropertyDe
232232
}
233233
}
234234
}
235-
//WriteAdditionalPropertiesToJson(jsonItemShape: JsonObject, service: ExchangeService, propertyDefinitions: System.Collections.Generic.IEnumerable<T>): any { throw new Error("PropertySet.ts - WriteAdditionalPropertiesToJson : Not implemented."); }
236-
WriteAdditionalPropertiesToXml(writer: EwsServiceXmlWriter, propertyDefinitions: PropertyDefinitionBase[]): void {
235+
static WriteAdditionalPropertiesToXml(writer: EwsServiceXmlWriter, propertyDefinitions: PropertyDefinitionBase[]): void {
237236
writer.WriteStartElement(XmlNamespace.Types, XmlElementNames.AdditionalProperties);
238237

239238
for (var propertyDefinition of propertyDefinitions) {
@@ -324,7 +323,7 @@ export class PropertySet /*implements ISelfValidate*/ { //IEnumerable<PropertyDe
324323
}
325324

326325
if (this.additionalProperties.length > 0) {
327-
this.WriteAdditionalPropertiesToXml(writer, this.additionalProperties);
326+
PropertySet.WriteAdditionalPropertiesToXml(writer, this.additionalProperties);
328327
}
329328

330329
writer.WriteEndElement(); // Item/FolderShape
Lines changed: 192 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,201 @@
1-
import {MultiResponseServiceRequest} from "./MultiResponseServiceRequest";
2-
import {Attachment} from "../../ComplexProperties/Attachment";
1+
import {Attachment} from "../../ComplexProperties/Attachment";
32
import {PropertyDefinitionBase} from "../../PropertyDefinitions/PropertyDefinitionBase";
43
import {BodyType} from "../../Enumerations/BodyType";
4+
import {Strings} from "../../Strings";
55
import {ExchangeService} from "../ExchangeService";
6-
import {GetAttachmentResponse} from "../Responses/GetAttachmentResponse";
6+
import {EwsUtilities} from "../EwsUtilities";
7+
import {PropertySet} from "../PropertySet";
8+
import {XmlElementNames} from "../XmlElementNames";
9+
import {XmlAttributeNames} from "../XmlAttributeNames";
710
import {ExchangeVersion} from "../../Enumerations/ExchangeVersion";
11+
import {XmlNamespace} from "../../Enumerations/XmlNamespace";
12+
import {ServiceErrorHandling} from "../../Enumerations/ServiceErrorHandling";
813
import {EwsServiceXmlWriter} from "../EwsServiceXmlWriter";
14+
import {Schemas} from "../ServiceObjects/Schemas/Schemas";
15+
import {ArgumentException, ArgumentNullException} from "../../Exceptions/ArgumentException";
16+
import {StringHelper, Convert} from "../../ExtensionMethods";
17+
18+
import {GetAttachmentResponse} from "../Responses/GetAttachmentResponse";
19+
import {MultiResponseServiceRequest} from "./MultiResponseServiceRequest";
920
/**
10-
* ## *Not Implemented*
21+
* @internal Represents a GetAttachment request.
1122
*/
1223
export class GetAttachmentRequest extends MultiResponseServiceRequest<GetAttachmentResponse> { //IJsonSerializable
13-
Attachments: Attachment[];//System.Collections.Generic.List<Attachment>;
14-
AttachmentIds: string[];//System.Collections.Generic.List<string>;
15-
AdditionalProperties: PropertyDefinitionBase[];//System.Collections.Generic.List<PropertyDefinitionBase>;
16-
BodyType: BodyType;
17-
EmitTimeZoneHeader: boolean;
18-
private attachments: Attachment[];//System.Collections.Generic.List<Attachment>;
19-
private attachmentIds: string[];//System.Collections.Generic.List<string>;
20-
private additionalProperties: PropertyDefinitionBase[];//System.Collections.Generic.List<PropertyDefinitionBase>;
21-
private bodyType: BodyType;
22-
AddJsonAttachmentIdToList(attachmentIds: any[]/*System.Collections.Generic.List<T>*/, attachmentId: string): any { throw new Error("GetAttachmentRequest.ts - AddJsonAttachmentIdToList : Not implemented."); }
23-
CreateServiceResponse(service: ExchangeService, responseIndex: number): GetAttachmentResponse { throw new Error("GetAttachmentRequest.ts - CreateServiceResponse : Not implemented."); }
24-
GetExpectedResponseMessageCount(): number { throw new Error("GetAttachmentRequest.ts - GetExpectedResponseMessageCount : Not implemented."); }
25-
GetMinimumRequiredServerVersion(): ExchangeVersion { throw new Error("GetAttachmentRequest.ts - GetMinimumRequiredServerVersion : Not implemented."); }
26-
GetResponseMessageXmlElementName(): string { throw new Error("GetAttachmentRequest.ts - GetResponseMessageXmlElementName : Not implemented."); }
27-
GetResponseXmlElementName(): string { throw new Error("GetAttachmentRequest.ts - GetResponseXmlElementName : Not implemented."); }
28-
//GetXmlElementName(): string { throw new Error("GetAttachmentRequest.ts - GetXmlElementName : Not implemented."); }
29-
Validate(): any { throw new Error("GetAttachmentRequest.ts - Validate : Not implemented."); }
30-
WriteAttachmentIdXml(writer: EwsServiceXmlWriter, attachmentId: string): any { throw new Error("GetAttachmentRequest.ts - WriteAttachmentIdXml : Not implemented."); }
31-
WriteElementsToXml(writer: EwsServiceXmlWriter): any { throw new Error("GetAttachmentRequest.ts - WriteElementsToXml : Not implemented."); }
24+
private attachments: Attachment[] = [];
25+
private attachmentIds: string[] = [];
26+
private additionalProperties: PropertyDefinitionBase[] = [];
27+
private bodyType: BodyType = null;
28+
29+
/**
30+
* Gets the attachments.
31+
*
32+
* @value The attachments.
33+
*/
34+
get Attachments(): Attachment[] {
35+
return this.attachments;
36+
}
37+
38+
/**
39+
* Gets the attachment ids.
40+
*
41+
* @value The attachment ids.
42+
*/
43+
get AttachmentIds(): string[] {
44+
return this.attachmentIds;
45+
}
46+
47+
/**
48+
* Gets the additional properties.
49+
*
50+
* @value The additional properties.
51+
*/
52+
get AdditionalProperties(): PropertyDefinitionBase[] {
53+
return this.additionalProperties;
54+
}
55+
56+
/**
57+
* Gets or sets the type of the body.
58+
*
59+
* @value The type of the body.
60+
*/
61+
get BodyType(): BodyType {
62+
return this.bodyType;
63+
}
64+
set BodyType(value: BodyType) {
65+
this.bodyType = value;
66+
}
67+
68+
/**
69+
* @internal Gets a value indicating whether the TimeZoneContext SOAP header should be emitted.
70+
*
71+
* @value *true* if the time zone should be emitted; otherwise, *false*.
72+
*/
73+
get EmitTimeZoneHeader(): boolean {
74+
return this.additionalProperties.indexOf(Schemas.ItemSchema.MimeContent) >= 0;
75+
}
76+
77+
/**
78+
* @internal Initializes a new instance of the **GetAttachmentRequest** class.
79+
*
80+
* @param {ExchangeService} service The service.
81+
* @param {ServiceErrorHandling} errorHandlingMode Indicates how errors should be handled.
82+
*/
83+
constructor(service: ExchangeService, errorHandlingMode: ServiceErrorHandling) {
84+
super(service, errorHandlingMode);
85+
}
86+
87+
/**
88+
* @internal Creates the service response.
89+
*
90+
* @param {ExchangeService} service The service.
91+
* @param {number} responseIndex Index of the response.
92+
* @return {GetAttachmentResponse} Service response.
93+
*/
94+
CreateServiceResponse(service: ExchangeService, responseIndex: number): GetAttachmentResponse {
95+
return new GetAttachmentResponse(this.Attachments.length > 0 ? this.Attachments[responseIndex] : null);
96+
}
97+
98+
/**
99+
* @internal Gets the expected response message count.
100+
*
101+
* @return {number} Number of expected response messages.
102+
*/
103+
GetExpectedResponseMessageCount(): number { return this.Attachments.length + this.AttachmentIds.length; }
104+
105+
/**
106+
* @internal Gets the request version.
107+
*
108+
* @return {ExchangeVersion} Earliest Exchange version in which this request is supported.
109+
*/
110+
GetMinimumRequiredServerVersion(): ExchangeVersion { return ExchangeVersion.Exchange2007_SP1; }
111+
112+
/**
113+
* @internal Gets the name of the response message XML element.
114+
*
115+
* @return {string} XML element name,
116+
*/
117+
GetResponseMessageXmlElementName(): string { return XmlElementNames.GetAttachmentResponseMessage; }
118+
119+
/**
120+
* @internal Gets the name of the response XML element.
121+
*
122+
* @return {string} XML element name,
123+
*/
124+
GetResponseXmlElementName(): string { return XmlElementNames.GetAttachmentResponse; }
125+
126+
/**
127+
* @internal Gets the name of the XML element.
128+
*
129+
* @return {string} XML element name,
130+
*/
131+
GetXmlElementName(): string { return XmlElementNames.GetAttachment; }
132+
133+
/**
134+
* @internal Validate request.
135+
*/
136+
Validate(): void {
137+
super.Validate();
138+
if (this.Attachments.length > 0) {
139+
EwsUtilities.ValidateParamCollection(this.Attachments, "Attachments");
140+
}
141+
142+
if (this.AttachmentIds.length > 0) {
143+
EwsUtilities.ValidateParamCollection(this.AttachmentIds, "AttachmentIds");
144+
}
145+
146+
if (this.AttachmentIds.length == 0 && this.Attachments.length == 0) {
147+
throw new ArgumentException(Strings.CollectionIsEmpty, "Attachments/AttachmentIds");
148+
}
149+
for (let i = 0; i < this.AdditionalProperties.length; i++) {
150+
EwsUtilities.ValidateParam(this.AdditionalProperties[i], StringHelper.Format("AdditionalProperties[{0}]", i));
151+
}
152+
}
153+
154+
/**
155+
* @internal Writes attachment id elements.
156+
*
157+
* @param {EwsServiceXmlWriter} writer The writer.
158+
* @param {string} attachmentId The attachment id.
159+
*/
160+
WriteAttachmentIdXml(writer: EwsServiceXmlWriter, attachmentId: string): void {
161+
writer.WriteStartElement(XmlNamespace.Types, XmlElementNames.AttachmentId);
162+
writer.WriteAttributeValue(XmlAttributeNames.Id, attachmentId);
163+
writer.WriteEndElement();
164+
}
165+
166+
/**
167+
* @internal Writes XML elements.
168+
*
169+
* @param {EwsServiceXmlWriter} writer The writer.
170+
*/
171+
WriteElementsToXml(writer: EwsServiceXmlWriter): void {
172+
if (this.BodyType || this.AdditionalProperties.length > 0) {
173+
writer.WriteStartElement(XmlNamespace.Messages, XmlElementNames.AttachmentShape);
174+
175+
if (this.BodyType) {
176+
writer.WriteElementValue(
177+
XmlNamespace.Types,
178+
XmlElementNames.BodyType,
179+
BodyType[this.BodyType]);
180+
}
181+
182+
if (this.AdditionalProperties.length > 0) {
183+
PropertySet.WriteAdditionalPropertiesToXml(writer, this.AdditionalProperties);
184+
}
185+
186+
writer.WriteEndElement(); // AttachmentShape
187+
}
188+
189+
writer.WriteStartElement(XmlNamespace.Messages, XmlElementNames.AttachmentIds);
190+
191+
for (let attachment of this.Attachments) {
192+
this.WriteAttachmentIdXml(writer, attachment.Id);
193+
}
194+
195+
for (let attachmentId of this.AttachmentIds) {
196+
this.WriteAttachmentIdXml(writer, attachmentId);
197+
}
198+
199+
writer.WriteEndElement();
200+
}
32201
}

0 commit comments

Comments
 (0)