Produced by Araxis Merge on 2/1/2017 2:56:22 PM Eastern Standard Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
| # | Location | File | Last Modified |
|---|---|---|---|
| 1 | C:\Araxis_Merge_Comprasion\Pub_un\BTSSS_CIF_122016.zip\BTSSS_CIF_12_20_16\clean\CRM\trunk\SDK\SampleCode\CS\BusinessDataModel\Activities | DeliverPromoteEmail.cs | Tue Dec 20 19:51:44 2016 UTC |
| 2 | Wed Feb 1 19:56:22 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 0 | 0 |
| Changed | 0 | 0 |
| Inserted | 0 | 0 |
| Removed | 1 | 264 |
| Whitespace | |
|---|---|
| Character case | Differences in character case are significant |
| Line endings | Differences in line endings (CR and LF characters) are ignored |
| CR/LF characters | Not shown in the comparison detail |
No regular expressions were active.
| 1 | // ======= ========== ========== ========== ========== ========== ========== == | |||||
| 2 | // | |||||
| 3 | // This f ile is par t of the M icrosoft D ynamics CR M SDK code samples. | |||||
| 4 | // | |||||
| 5 | // Copyri ght (C) Mi crosoft Co rporation. All righ ts reserve d. | |||||
| 6 | // | |||||
| 7 | // This s ource code is intend ed only as a supplem ent to Mic rosoft | |||||
| 8 | // Develo pment Tool s and/or o n-line doc umentation . See the se other | |||||
| 9 | // materi als for de tailed inf ormation r egarding M icrosoft c ode sample s. | |||||
| 10 | // | |||||
| 11 | // THIS C ODE AND IN FORMATION ARE PROVID ED "AS IS" WITHOUT W ARRANTY OF ANY | |||||
| 12 | // KIND, EITHER EXP RESSED OR IMPLIED, I NCLUDING B UT NOT LIM ITED TO TH E | |||||
| 13 | // IMPLIE D WARRANTI ES OF MERC HANTABILIT Y AND/OR F ITNESS FOR A | |||||
| 14 | // PARTIC ULAR PURPO SE. | |||||
| 15 | // | |||||
| 16 | // ======= ========== ========== ========== ========== ========== ========== == | |||||
| 17 | //<snippet DeliverPro moteEmail> | |||||
| 18 | using Syst em; | |||||
| 19 | using Syst em.Service Model; | |||||
| 20 | using Syst em.Service Model.Desc ription; | |||||
| 21 | using Syst em.Text; | |||||
| 22 | ||||||
| 23 | // These n amespaces are found in the Mic rosoft.Xrm .Sdk.dll a ssembly | |||||
| 24 | // found i n the SDK\ bin folder . | |||||
| 25 | using Micr osoft.Xrm. Sdk; | |||||
| 26 | using Micr osoft.Xrm. Sdk.Query; | |||||
| 27 | using Micr osoft.Xrm. Sdk.Discov ery; | |||||
| 28 | using Micr osoft.Xrm. Sdk.Messag es; | |||||
| 29 | using Micr osoft.Xrm. Sdk.Client ; | |||||
| 30 | ||||||
| 31 | ||||||
| 32 | // This na mespace is found in Microsoft. Crm.Sdk.Pr oxy.dll as sembly | |||||
| 33 | // found i n the SDK\ bin folder . | |||||
| 34 | using Micr osoft.Crm. Sdk.Messag es; | |||||
| 35 | ||||||
| 36 | namespace Microsoft. Crm.Sdk.Sa mples | |||||
| 37 | { | |||||
| 38 | /// <s ummary> | |||||
| 39 | /// Cr eate an e- mail activ ity instan ce from th e specifie d e-mail m essage. | |||||
| 40 | /// </ summary> | |||||
| 41 | /// <r emarks>Thi s sample r equires th at the use r account running th e program have | |||||
| 42 | /// a primary e- mail addre ss defined in Micros oft Dynami cs CRM.</r emarks> | |||||
| 43 | public class Del iverPromot eEmail | |||||
| 44 | { | |||||
| 45 | #r egion Clas s Level Me mbers | |||||
| 46 | ||||||
| 47 | // / <summary > | |||||
| 48 | // / Stores t he organiz ation serv ice proxy. | |||||
| 49 | // / </summar y> | |||||
| 50 | pr ivate Orga nizationSe rviceProxy _serviceP roxy; | |||||
| 51 | ||||||
| 52 | // Define th e IDs need ed for thi s sample. | |||||
| 53 | pr ivate Guid _contactI d; | |||||
| 54 | pr ivate Guid _emailId; | |||||
| 55 | ||||||
| 56 | #e ndregion C lass Level Members | |||||
| 57 | ||||||
| 58 | #r egion How To Sample Code | |||||
| 59 | // / <summary > | |||||
| 60 | // / Create a n e-mail a ctivity in stance fro m the spec ified e-ma il message . | |||||
| 61 | // / <param n ame="serve rConfig">C ontains se rver conne ction info rmation.</ param> | |||||
| 62 | // / <param n ame="promp tforDelete ">When Tru e, the use r will be prompted t o delete a ll | |||||
| 63 | // / created entities.< /param> | |||||
| 64 | // / </summar y> | |||||
| 65 | pu blic void Run(Server Connection .Configura tion serve rConfig, b ool prompt ForDelete) | |||||
| 66 | { | |||||
| 67 | try | |||||
| 68 | { | |||||
| 69 | // C onnect to the Organi zation ser vice. | |||||
| 70 | // T he using s tatement a ssures tha t the serv ice proxy will be pr operly dis posed. | |||||
| 71 | usin g (_servic eProxy = n ew Organiz ationServi ceProxy(se rverConfig .Organizat ionUri, se rverConfig .HomeRealm Uri,server Config.Cre dentials, serverConf ig.DeviceC redentials )) | |||||
| 72 | { | |||||
| 73 | // This st atement is required to enable early-boun d type sup port. | |||||
| 74 | _servicePr oxy.Enable ProxyTypes (); | |||||
| 75 | ||||||
| 76 | // Create a contact to send an email to (To: field ) | |||||
| 77 | Contact em ailContact = new Con tact() | |||||
| 78 | { | |||||
| 79 | FirstN ame = "Lis a", | |||||
| 80 | LastNa me = "Andr ews", | |||||
| 81 | EMailA ddress1 = "lisa@cont oso.com" | |||||
| 82 | }; | |||||
| 83 | _contactId = _servic eProxy.Cre ate(emailC ontact); | |||||
| 84 | Console.Wr iteLine("C reated a s ample cont act."); | |||||
| 85 | ||||||
| 86 | // Get a s ystem user to send t he email ( From: fiel d) | |||||
| 87 | WhoAmIRequ est system UserReques t = new Wh oAmIReques t(); | |||||
| 88 | WhoAmIResp onse syste mUserRespo nse = (Who AmIRespons e)_service Proxy.Exec ute(system UserReques t); | |||||
| 89 | ||||||
| 90 | ColumnSet cols = new ColumnSet ("internal emailaddre ss"); | |||||
| 91 | SystemUser emailSend er = (Syst emUser)_se rviceProxy .Retrieve( SystemUser .EntityLog icalName, systemUser Response.U serId, col s); | |||||
| 92 | ||||||
| 93 | //<snippet DeliverPro moteEmail1 > | |||||
| 94 | ||||||
| 95 | // Create the reques t. | |||||
| 96 | DeliverPro moteEmailR equest del iverEmailR equest = n ew Deliver PromoteEma ilRequest | |||||
| 97 | { | |||||
| 98 | Subjec t = "SDK S ample Emai l", | |||||
| 99 | To = e mailContac t.EMailAdd ress1, | |||||
| 100 | From = emailSend er.Interna lEMailAddr ess, | |||||
| 101 | Bcc = String.Emp ty, | |||||
| 102 | Cc = S tring.Empt y, | |||||
| 103 | Import ance = "hi gh", | |||||
| 104 | Body = "This mes sage will create an email acti vity.", | |||||
| 105 | Messag eId = Guid .NewGuid() .ToString( ), | |||||
| 106 | Submit tedBy = "" , | |||||
| 107 | Receiv edOn = Dat eTime.Now | |||||
| 108 | }; | |||||
| 109 | ||||||
| 110 | // We won' t attach a file to t he email, but the At tachments property i s required . | |||||
| 111 | deliverEma ilRequest. Attachment s = new En tityCollec tion(new A ctivityMim eAttachmen t[0]); | |||||
| 112 | deliverEma ilRequest. Attachment s.EntityNa me = Activ ityMimeAtt achment.En tityLogica lName; | |||||
| 113 | ||||||
| 114 | // Execute the reque st. | |||||
| 115 | DeliverPro moteEmailR esponse de liverEmail Response = (DeliverP romoteEmai lResponse) _servicePr oxy.Execut e(deliverE mailReques t); | |||||
| 116 | ||||||
| 117 | // Verify the succes s. | |||||
| 118 | ||||||
| 119 | // Define an anonymo us type to define th e possible values fo r | |||||
| 120 | // email s tatus | |||||
| 121 | var EmailS tatus = ne w | |||||
| 122 | { | |||||
| 123 | Draft = 1, | |||||
| 124 | Comple ted = 2, | |||||
| 125 | Sent = 3, | |||||
| 126 | Receiv ed = 3, | |||||
| 127 | Cancel ed = 5, | |||||
| 128 | Pendin gSend = 6, | |||||
| 129 | Sendin g = 7, | |||||
| 130 | Failed = 8, | |||||
| 131 | }; | |||||
| 132 | ||||||
| 133 | // Query f or the del ivered ema il, and ve rify the s tatus code is "Sent" . | |||||
| 134 | ColumnSet deliveredM ailColumns = new Col umnSet("st atuscode") ; | |||||
| 135 | Email deli veredEmail = (Email) _servicePr oxy.Retrie ve(Email.E ntityLogic alName, de liverEmail Response.E mailId, de liveredMai lColumns); | |||||
| 136 | ||||||
| 137 | _emailId = delivered Email.Acti vityId.Val ue; | |||||
| 138 | ||||||
| 139 | if (delive redEmail.S tatusCode. Value == E mailStatus .Sent) | |||||
| 140 | { | |||||
| 141 | Consol e.WriteLin e("Success fully crea ted and de livered th e e-mail m essage."); | |||||
| 142 | } | |||||
| 143 | ||||||
| 144 | //</snippe tDeliverPr omoteEmail 1> | |||||
| 145 | ||||||
| 146 | DeleteRequ iredRecord s(promptFo rDelete); | |||||
| 147 | } | |||||
| 148 | } | |||||
| 149 | ||||||
| 150 | // Catch any servi ce fault e xceptions that Micro soft Dynam ics CRM th rows. | |||||
| 151 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault>) | |||||
| 152 | { | |||||
| 153 | // Y ou can han dle an exc eption her e or pass it back to the calli ng method. | |||||
| 154 | thro w; | |||||
| 155 | } | |||||
| 156 | } | |||||
| 157 | ||||||
| 158 | ||||||
| 159 | // / <summary > | |||||
| 160 | // / Deletes the custom entity re cord that was create d for this sample. | |||||
| 161 | // / <param n ame="promp t">Indicat es whether to prompt the user | |||||
| 162 | // / to delet e the enti ty created in this s ample.</pa ram> | |||||
| 163 | // / </summar y> | |||||
| 164 | pu blic void DeleteRequ iredRecord s(bool pro mpt) | |||||
| 165 | { | |||||
| 166 | bool del eteRecords = true; | |||||
| 167 | ||||||
| 168 | if (prom pt) | |||||
| 169 | { | |||||
| 170 | Cons ole.WriteL ine("\nDo you want t hese entit y records deleted? ( y/n)"); | |||||
| 171 | Stri ng answer = Console. ReadLine() ; | |||||
| 172 | ||||||
| 173 | dele teRecords = (answer. StartsWith ("y") || a nswer.Star tsWith("Y" )); | |||||
| 174 | } | |||||
| 175 | ||||||
| 176 | if (dele teRecords) | |||||
| 177 | { | |||||
| 178 | /// Delete the sent emai ls | |||||
| 179 | _ser viceProxy. Delete(Ema il.EntityL ogicalName , _emailId ); | |||||
| 180 | ||||||
| 181 | // D elete the contacts c reated for emails | |||||
| 182 | _ser viceProxy. Delete(Con tact.Entit yLogicalNa me, _conta ctId); | |||||
| 183 | ||||||
| 184 | Cons ole.WriteL ine("Entit y records have been deleted.") ; | |||||
| 185 | } | |||||
| 186 | } | |||||
| 187 | ||||||
| 188 | #e ndregion H ow To Samp le Code | |||||
| 189 | ||||||
| 190 | #r egion Main | |||||
| 191 | // / <summary > | |||||
| 192 | // / Main. Ru ns the sam ple and pr ovides err or output. | |||||
| 193 | // / <param n ame="args" >Array of arguments to Main me thod.</par am> | |||||
| 194 | // / </summar y> | |||||
| 195 | st atic publi c void Mai n(string[] args) | |||||
| 196 | { | |||||
| 197 | try | |||||
| 198 | { | |||||
| 199 | // O btain the target org anization' s Web addr ess and cl ient logon | |||||
| 200 | // c redentials from the user. | |||||
| 201 | Serv erConnecti on serverC onnect = n ew ServerC onnection( ); | |||||
| 202 | Serv erConnecti on.Configu ration con fig = serv erConnect. GetServerC onfigurati on(); | |||||
| 203 | ||||||
| 204 | Deli verPromote Email app = new Deli verPromote Email(); | |||||
| 205 | app. Run(config , true); | |||||
| 206 | ||||||
| 207 | } | |||||
| 208 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault> ex ) | |||||
| 209 | { | |||||
| 210 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 211 | Cons ole.WriteL ine("Times tamp: {0}" , ex.Detai l.Timestam p); | |||||
| 212 | Cons ole.WriteL ine("Code: {0}", ex. Detail.Err orCode); | |||||
| 213 | Cons ole.WriteL ine("Messa ge: {0}", ex.Detail. Message); | |||||
| 214 | Cons ole.WriteL ine("Plugi n Trace: { 0}", ex.De tail.Trace Text); | |||||
| 215 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 216 | null == ex .Detail.In nerFault ? "No Inner Fault" : "Has Inner Fault"); | |||||
| 217 | } | |||||
| 218 | catch (S ystem.Time outExcepti on ex) | |||||
| 219 | { | |||||
| 220 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 221 | Cons ole.WriteL ine("Messa ge: {0}", ex.Message ); | |||||
| 222 | Cons ole.WriteL ine("Stack Trace: {0 }", ex.Sta ckTrace); | |||||
| 223 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 224 | null == ex .InnerExce ption.Mess age ? "No Inner Faul t" : ex.In nerExcepti on.Message ); | |||||
| 225 | } | |||||
| 226 | catch (S ystem.Exce ption ex) | |||||
| 227 | { | |||||
| 228 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 229 | Cons ole.WriteL ine(ex.Mes sage); | |||||
| 230 | ||||||
| 231 | // D isplay the details o f the inne r exceptio n. | |||||
| 232 | if ( ex.InnerEx ception != null) | |||||
| 233 | { | |||||
| 234 | Console.Wr iteLine(ex .InnerExce ption.Mess age); | |||||
| 235 | ||||||
| 236 | FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault> f e = | |||||
| 237 | ex.Inn erExceptio n | |||||
| 238 | as Fau ltExceptio n<Microsof t.Xrm.Sdk. Organizati onServiceF ault>; | |||||
| 239 | if (fe != null) | |||||
| 240 | { | |||||
| 241 | Consol e.WriteLin e("Timesta mp: {0}", fe.Detail. Timestamp) ; | |||||
| 242 | Consol e.WriteLin e("Code: { 0}", fe.De tail.Error Code); | |||||
| 243 | Consol e.WriteLin e("Message : {0}", fe .Detail.Me ssage); | |||||
| 244 | Consol e.WriteLin e("Plugin Trace: {0} ", fe.Deta il.TraceTe xt); | |||||
| 245 | Consol e.WriteLin e("Inner F ault: {0}" , | |||||
| 246 | nu ll == fe.D etail.Inne rFault ? " No Inner F ault" : "H as Inner F ault"); | |||||
| 247 | } | |||||
| 248 | } | |||||
| 249 | } | |||||
| 250 | // Addit ional exce ptions to catch: Sec urityToken Validation Exception, ExpiredSe curityToke nException , | |||||
| 251 | // Secur ityAccessD eniedExcep tion, Mess ageSecurit yException , and Secu rityNegoti ationExcep tion. | |||||
| 252 | ||||||
| 253 | finally | |||||
| 254 | { | |||||
| 255 | Cons ole.WriteL ine("Press <Enter> t o exit."); | |||||
| 256 | Cons ole.ReadLi ne(); | |||||
| 257 | } | |||||
| 258 | ||||||
| 259 | } | |||||
| 260 | #e ndregion M ain | |||||
| 261 | ||||||
| 262 | } | |||||
| 263 | } | |||||
| 264 | //</snippe tDeliverPr omoteEmail > |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.