1- import { MultiResponseServiceRequest } from "./MultiResponseServiceRequest" ;
2- import { Attachment } from "../../ComplexProperties/Attachment" ;
1+ import { Attachment } from "../../ComplexProperties/Attachment" ;
32import { PropertyDefinitionBase } from "../../PropertyDefinitions/PropertyDefinitionBase" ;
43import { BodyType } from "../../Enumerations/BodyType" ;
4+ import { Strings } from "../../Strings" ;
55import { 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" ;
710import { ExchangeVersion } from "../../Enumerations/ExchangeVersion" ;
11+ import { XmlNamespace } from "../../Enumerations/XmlNamespace" ;
12+ import { ServiceErrorHandling } from "../../Enumerations/ServiceErrorHandling" ;
813import { 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 */
1223export 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