Produced by Araxis Merge on 2/1/2017 2:56:28 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\Templates | CreateEmailUsingTemplate.cs | Tue Dec 20 19:51:43 2016 UTC |
| 2 | Wed Feb 1 19:56:28 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 0 | 0 |
| Changed | 0 | 0 |
| Inserted | 0 | 0 |
| Removed | 1 | 271 |
| 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 CreateEmai lUsingTemp late> | |||||
| 18 | using Syst em; | |||||
| 19 | using Syst em.IO; | |||||
| 20 | using Syst em.Text; | |||||
| 21 | using Syst em.Service Model; | |||||
| 22 | using Syst em.Xml.Ser ialization ; | |||||
| 23 | using Syst em.Service Model.Desc ription; | |||||
| 24 | ||||||
| 25 | // These n amespaces are found in the Mic rosoft.Xrm .Sdk.dll a ssembly | |||||
| 26 | // located in the SD K\bin fold er of the SDK downlo ad. | |||||
| 27 | using Micr osoft.Xrm. Sdk; | |||||
| 28 | using Micr osoft.Xrm. Sdk.Query; | |||||
| 29 | using Micr osoft.Xrm. Sdk.Client ; | |||||
| 30 | using Micr osoft.Xrm. Sdk.Messag es; | |||||
| 31 | ||||||
| 32 | ||||||
| 33 | // This na mespace is found in Microsoft. Crm.Sdk.Pr oxy.dll as sembly | |||||
| 34 | // found i n the SDK\ bin folder . | |||||
| 35 | using Micr osoft.Crm. Sdk.Messag es; | |||||
| 36 | ||||||
| 37 | namespace Microsoft. Crm.Sdk.Sa mples | |||||
| 38 | { | |||||
| 39 | public class Cre ateEmailUs ingTemplat e | |||||
| 40 | { | |||||
| 41 | #r egion Clas s Level Me mbers | |||||
| 42 | ||||||
| 43 | // Define th e IDs need ed for thi s sample. | |||||
| 44 | pr ivate Guid _accountI d; | |||||
| 45 | pr ivate Guid _template Id; | |||||
| 46 | ||||||
| 47 | pr ivate Orga nizationSe rviceProxy _serviceP roxy; | |||||
| 48 | #e ndregion C lass Level Members | |||||
| 49 | ||||||
| 50 | #r egion How To Sample Code | |||||
| 51 | // / <summary > | |||||
| 52 | // / Create a n e-mail u sing a tem plate. | |||||
| 53 | // / </summar y> | |||||
| 54 | // / <param n ame="serve rConfig">C ontains se rver conne ction info rmation.</ param> | |||||
| 55 | // / <param n ame="promp tforDelete ">When Tru e, the use r will be prompted t o delete a ll | |||||
| 56 | // / created entities.< /param> | |||||
| 57 | pu blic void Run(Server Connection .Configura tion serve rConfig, b ool prompt forDelete) | |||||
| 58 | { | |||||
| 59 | try | |||||
| 60 | { | |||||
| 61 | // C onnect to the Organi zation ser vice. | |||||
| 62 | // T he using s tatement a ssures tha t the serv ice proxy will be pr operly dis posed. | |||||
| 63 | usin g (_servic eProxy = n ew Organiz ationServi ceProxy(se rverConfig .Organizat ionUri, se rverConfig .HomeRealm Uri, | |||||
| 64 | s erverConfi g.Credenti als, serve rConfig.De viceCreden tials)) | |||||
| 65 | { | |||||
| 66 | // This st atement is required to enable early-boun d type sup port. | |||||
| 67 | _servicePr oxy.Enable ProxyTypes (); | |||||
| 68 | ||||||
| 69 | CreateRequ iredRecord s(); | |||||
| 70 | ||||||
| 71 | //<snippet CreateEmai lUsingTemp late1> | |||||
| 72 | ||||||
| 73 | // Use the Instantia teTemplate message t o create a n e-mail m essage usi ng a templ ate. | |||||
| 74 | Instantiat eTemplateR equest ins tTemplateR eq = new I nstantiate TemplateRe quest | |||||
| 75 | { | |||||
| 76 | Templa teId = _te mplateId, | |||||
| 77 | Object Id = _acco untId, | |||||
| 78 | Object Type = Acc ount.Entit yLogicalNa me | |||||
| 79 | }; | |||||
| 80 | Instantiat eTemplateR esponse in stTemplate Resp = (In stantiateT emplateRes ponse)_ser viceProxy. Execute(in stTemplate Req); | |||||
| 81 | ||||||
| 82 | // Seriali ze the ema il message to XML, a nd save to a file. | |||||
| 83 | XmlSeriali zer serial izer = new XmlSerial izer(typeo f(Instanti ateTemplat eResponse) ); | |||||
| 84 | string fil ename = "e mail-messa ge.xml"; | |||||
| 85 | using (Str eamWriter writer = n ew StreamW riter(file name)) | |||||
| 86 | { | |||||
| 87 | serial izer.Seria lize(write r, instTem plateResp) ; | |||||
| 88 | } | |||||
| 89 | Console.Wr iteLine("C reated e-m ail using the templa te."); | |||||
| 90 | //</snippe tCreateEma ilUsingTem plate1> | |||||
| 91 | ||||||
| 92 | ||||||
| 93 | DeleteRequ iredRecord s(promptfo rDelete); | |||||
| 94 | } | |||||
| 95 | } | |||||
| 96 | ||||||
| 97 | // Catch any servi ce fault e xceptions that Micro soft Dynam ics CRM th rows. | |||||
| 98 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault>) | |||||
| 99 | { | |||||
| 100 | // Y ou can han dle an exc eption her e or pass it back to the calli ng method. | |||||
| 101 | thro w; | |||||
| 102 | } | |||||
| 103 | } | |||||
| 104 | ||||||
| 105 | // / <summary > | |||||
| 106 | // / Creates any entity records t hat this s ample requ ires. | |||||
| 107 | // / </summar y> | |||||
| 108 | pu blic void CreateRequ iredRecord s() | |||||
| 109 | { | |||||
| 110 | // Creat e an accou nt. | |||||
| 111 | Account account = new Accoun t | |||||
| 112 | { | |||||
| 113 | Name = "Fourth Coffee", | |||||
| 114 | }; | |||||
| 115 | _account Id = _serv iceProxy.C reate(acco unt); | |||||
| 116 | Console. WriteLine( "Created a sample ac count: {0} .", accoun t.Name); | |||||
| 117 | ||||||
| 118 | // Defin e the body and subje ct of the email temp late in XM L format. | |||||
| 119 | string b odyXml = | |||||
| 120 | "<?xm l version= \"1.0\" ?> " | |||||
| 121 | + "<x sl:stylesh eet xmlns: xsl=\"http ://www.w3. org/1999/X SL/Transfo rm\" versi on=\"1.0\" >" | |||||
| 122 | + "<x sl:output method=\"t ext\" inde nt=\"no\"/ ><xsl:temp late match =\"/data\" >" | |||||
| 123 | + "<! [CDATA[" | |||||
| 124 | + "Th is message is to not ify you th at a new a ccount has been crea ted." | |||||
| 125 | + "]] ></xsl:tem plate></xs l:styleshe et>"; | |||||
| 126 | ||||||
| 127 | string s ubjectXml = | |||||
| 128 | "<?xm l version= \"1.0\" ?> " | |||||
| 129 | + "<x sl:stylesh eet xmlns: xsl=\"http ://www.w3. org/1999/X SL/Transfo rm\" versi on=\"1.0\" >" | |||||
| 130 | + "<x sl:output method=\"t ext\" inde nt=\"no\"/ ><xsl:temp late match =\"/data\" >" | |||||
| 131 | + "<! [CDATA[New account n otificatio n]]></xsl: template>< /xsl:style sheet>"; | |||||
| 132 | ||||||
| 133 | string p resentatio nXml = | |||||
| 134 | "<tem plate><tex t><![CDATA [" | |||||
| 135 | + "Th is message is to not ify you th at a new a ccount has been crea ted." | |||||
| 136 | + "]] ></text></ template>" ; | |||||
| 137 | ||||||
| 138 | string s ubjectPres entationXm l = | |||||
| 139 | "<tem plate><tex t><![CDATA [New accou nt notific ation]]></ text></tem plate>"; | |||||
| 140 | ||||||
| 141 | // Creat e an e-mai l template . | |||||
| 142 | Template template = new Temp late | |||||
| 143 | { | |||||
| 144 | Titl e = "Sampl e E-mail T emplate fo r Account" , | |||||
| 145 | Body = bodyXml , | |||||
| 146 | Subj ect = subj ectXml, | |||||
| 147 | Pres entationXm l = presen tationXml, | |||||
| 148 | Subj ectPresent ationXml = subjectPr esentation Xml, | |||||
| 149 | Temp lateTypeCo de = Accou nt.EntityL ogicalName , | |||||
| 150 | Lang uageCode = 1033, // For US Eng lish. | |||||
| 151 | IsPe rsonal = f alse | |||||
| 152 | }; | |||||
| 153 | ||||||
| 154 | _templat eId = _ser viceProxy. Create(tem plate); | |||||
| 155 | Console. WriteLine( "Created { 0}.", temp late.Title ); | |||||
| 156 | } | |||||
| 157 | ||||||
| 158 | ||||||
| 159 | // / <summary > | |||||
| 160 | // / Deletes any entity records t hat were c reated for this samp le. | |||||
| 161 | // / <param n ame="promp t">Indicat es whether to prompt the user | |||||
| 162 | // / to delet e the reco rds create d in this sample.</p aram> | |||||
| 163 | // / </summar y> | |||||
| 164 | pu blic void DeleteRequ iredRecord s(bool pro mpt) | |||||
| 165 | { | |||||
| 166 | bool toB eDeleted = true; | |||||
| 167 | ||||||
| 168 | if (prom pt) | |||||
| 169 | { | |||||
| 170 | // A sk the use r if the c reated ent ities shou ld be dele ted. | |||||
| 171 | Cons ole.Write( "\nDo you want these entity re cords dele ted? (y/n) [y]: "); | |||||
| 172 | Stri ng answer = Console. ReadLine() ; | |||||
| 173 | if ( answer.Sta rtsWith("y ") || | |||||
| 174 | answer.Sta rtsWith("Y ") || | |||||
| 175 | answer == String.Emp ty) | |||||
| 176 | { | |||||
| 177 | toBeDelete d = true; | |||||
| 178 | } | |||||
| 179 | else | |||||
| 180 | { | |||||
| 181 | toBeDelete d = false; | |||||
| 182 | } | |||||
| 183 | } | |||||
| 184 | ||||||
| 185 | if (toBe Deleted) | |||||
| 186 | { | |||||
| 187 | // D elete all records cr eated in t his sample . | |||||
| 188 | _ser viceProxy. Delete(Tem plate.Enti tyLogicalN ame, _temp lateId); | |||||
| 189 | _ser viceProxy. Delete(Acc ount.Entit yLogicalNa me, _accou ntId); ; | |||||
| 190 | ||||||
| 191 | Cons ole.WriteL ine("Entit y record(s ) have bee n deleted. "); | |||||
| 192 | } | |||||
| 193 | } | |||||
| 194 | ||||||
| 195 | #e ndregion H ow To Samp le Code | |||||
| 196 | ||||||
| 197 | #r egion Main method | |||||
| 198 | // / <summary > | |||||
| 199 | // / Main. Ru ns the sam ple and pr ovides err or output. | |||||
| 200 | // / <param n ame="args" >Array of arguments to Main me thod.</par am> | |||||
| 201 | // / </summar y> | |||||
| 202 | st atic publi c void Mai n(string[] args) | |||||
| 203 | { | |||||
| 204 | try | |||||
| 205 | { | |||||
| 206 | // O btain the target org anization' s Web addr ess and cl ient logon | |||||
| 207 | // c redentials from the user. | |||||
| 208 | Serv erConnecti on serverC onnect = n ew ServerC onnection( ); | |||||
| 209 | Serv erConnecti on.Configu ration con fig = serv erConnect. GetServerC onfigurati on(); | |||||
| 210 | ||||||
| 211 | Crea teEmailUsi ngTemplate app = new CreateEma ilUsingTem plate(); | |||||
| 212 | app. Run(config , true); | |||||
| 213 | ||||||
| 214 | } | |||||
| 215 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault> ex ) | |||||
| 216 | { | |||||
| 217 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 218 | Cons ole.WriteL ine("Times tamp: {0}" , ex.Detai l.Timestam p); | |||||
| 219 | Cons ole.WriteL ine("Code: {0}", ex. Detail.Err orCode); | |||||
| 220 | Cons ole.WriteL ine("Messa ge: {0}", ex.Detail. Message); | |||||
| 221 | Cons ole.WriteL ine("Plugi n Trace: { 0}", ex.De tail.Trace Text); | |||||
| 222 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 223 | null == ex .Detail.In nerFault ? "No Inner Fault" : "Has Inner Fault"); | |||||
| 224 | } | |||||
| 225 | catch (S ystem.Time outExcepti on ex) | |||||
| 226 | { | |||||
| 227 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 228 | Cons ole.WriteL ine("Messa ge: {0}", ex.Message ); | |||||
| 229 | Cons ole.WriteL ine("Stack Trace: {0 }", ex.Sta ckTrace); | |||||
| 230 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 231 | null == ex .InnerExce ption.Mess age ? "No Inner Faul t" : ex.In nerExcepti on.Message ); | |||||
| 232 | } | |||||
| 233 | catch (S ystem.Exce ption ex) | |||||
| 234 | { | |||||
| 235 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 236 | Cons ole.WriteL ine(ex.Mes sage); | |||||
| 237 | ||||||
| 238 | // D isplay the details o f the inne r exceptio n. | |||||
| 239 | if ( ex.InnerEx ception != null) | |||||
| 240 | { | |||||
| 241 | Console.Wr iteLine(ex .InnerExce ption.Mess age); | |||||
| 242 | ||||||
| 243 | FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault> f e = | |||||
| 244 | ex.Inn erExceptio n | |||||
| 245 | as Fau ltExceptio n<Microsof t.Xrm.Sdk. Organizati onServiceF ault>; | |||||
| 246 | if (fe != null) | |||||
| 247 | { | |||||
| 248 | Consol e.WriteLin e("Timesta mp: {0}", fe.Detail. Timestamp) ; | |||||
| 249 | Consol e.WriteLin e("Code: { 0}", fe.De tail.Error Code); | |||||
| 250 | Consol e.WriteLin e("Message : {0}", fe .Detail.Me ssage); | |||||
| 251 | Consol e.WriteLin e("Plugin Trace: {0} ", fe.Deta il.TraceTe xt); | |||||
| 252 | Consol e.WriteLin e("Inner F ault: {0}" , | |||||
| 253 | nu ll == fe.D etail.Inne rFault ? " No Inner F ault" : "H as Inner F ault"); | |||||
| 254 | } | |||||
| 255 | } | |||||
| 256 | } | |||||
| 257 | // Addit onal excep tions to c atch: Secu rityTokenV alidationE xception, ExpiredSec urityToken Exception, | |||||
| 258 | // Secur ityAccessD eniedExcep tion, Mess ageSecurit yException , and Secu rityNegoti ationExcep tion. | |||||
| 259 | ||||||
| 260 | finally | |||||
| 261 | { | |||||
| 262 | Cons ole.WriteL ine("Press <Enter> t o exit."); | |||||
| 263 | Cons ole.ReadLi ne(); | |||||
| 264 | } | |||||
| 265 | ||||||
| 266 | } | |||||
| 267 | #e ndregion M ain method | |||||
| 268 | ||||||
| 269 | } | |||||
| 270 | } | |||||
| 271 | //</snippe tCreateEma ilUsingTem plate> |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.