Produced by Araxis Merge on 2/1/2017 2:56:54 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\QuickStart | CRUDOperations.cs | Tue Dec 20 19:51:42 2016 UTC |
| 2 | Wed Feb 1 19:56:54 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 0 | 0 |
| Changed | 0 | 0 |
| Inserted | 0 | 0 |
| Removed | 1 | 216 |
| 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 | // This f ile is par t of the M icrosoft D ynamics CR M SDK code samples. | |||||
| 3 | // | |||||
| 4 | // Copyri ght (C) Mi crosoft Co rporation. All righ ts reserve d. | |||||
| 5 | // | |||||
| 6 | // This s ource code is intend ed only as a supplem ent to Mic rosoft | |||||
| 7 | // Develo pment Tool s and/or o n-line doc umentation . See the se other | |||||
| 8 | // materi als for de tailed inf ormation r egarding M icrosoft c ode sample s. | |||||
| 9 | // | |||||
| 10 | // THIS C ODE AND IN FORMATION ARE PROVID ED "AS IS" WITHOUT W ARRANTY OF ANY | |||||
| 11 | // KIND, EITHER EXP RESSED OR IMPLIED, I NCLUDING B UT NOT LIM ITED TO TH E | |||||
| 12 | // IMPLIE D WARRANTI ES OF MERC HANTABILIT Y AND/OR F ITNESS FOR A | |||||
| 13 | // PARTIC ULAR PURPO SE. | |||||
| 14 | // ======= ========== ========== ========== ========== ========== ========== == | |||||
| 15 | ||||||
| 16 | //<snippet CRUDOperat ions> | |||||
| 17 | using Syst em; | |||||
| 18 | using Syst em.Service Model; | |||||
| 19 | using Syst em.Identit yModel.Tok ens; | |||||
| 20 | using Syst em.Service Model.Secu rity; | |||||
| 21 | ||||||
| 22 | // These n amespaces are found in the Mic rosoft.Xrm .Sdk.dll a nd | |||||
| 23 | // Microso ft.Crm.Sdk .Proxy.dll assemblie s. | |||||
| 24 | using Micr osoft.Xrm. Sdk; | |||||
| 25 | using Micr osoft.Xrm. Sdk.Query; | |||||
| 26 | using Micr osoft.Xrm. Sdk.Client ; | |||||
| 27 | using Micr osoft.Crm. Sdk.Messag es; | |||||
| 28 | ||||||
| 29 | namespace Microsoft. Crm.Sdk.Sa mples | |||||
| 30 | { | |||||
| 31 | /// <s ummary> | |||||
| 32 | /// De monstrates how to pe rform crea te, retrie ve, update , and dele te entity | |||||
| 33 | /// re cord opera tions.</su mmary> | |||||
| 34 | /// <r emarks> | |||||
| 35 | /// At run-time, you will be given t he option to delete all the | |||||
| 36 | /// en tity recor ds created by this p rogram.</r emarks> | |||||
| 37 | public class CRU DOperation s | |||||
| 38 | { | |||||
| 39 | st atic publi c void Mai n(string[] args) | |||||
| 40 | { | |||||
| 41 | // The c onnection to the Org anization web servic e. | |||||
| 42 | Organiza tionServic eProxy ser viceProxy = null; | |||||
| 43 | ||||||
| 44 | try | |||||
| 45 | { | |||||
| 46 | // O btain the target org anization' s web addr ess and cl ient logon credentia ls | |||||
| 47 | // f rom the us er by usin g a helper class. | |||||
| 48 | Serv erConnecti on serverC onnect = n ew ServerC onnection( ); | |||||
| 49 | Serv erConnecti on.Configu ration con fig = serv erConnect. GetServerC onfigurati on(); | |||||
| 50 | ||||||
| 51 | // E stablish a n authenti cated conn ection to the Organi zation web service. | |||||
| 52 | serv iceProxy = new Organ izationSer viceProxy( config.Org anizationU ri, config .HomeRealm Uri, | |||||
| 53 | config.Cre dentials, config.Dev iceCredent ials); | |||||
| 54 | ||||||
| 55 | CRUD Operations app = new CRUDOpera tions(); | |||||
| 56 | ||||||
| 57 | // C reate any records th at must ex ist in the database. These rec ord refere nces are | |||||
| 58 | // s tored in a collectio n so the r ecords can be delete d later. | |||||
| 59 | Enti tyReferenc eCollectio n records = | |||||
| 60 | app.Create RequiredEn tityRecord s(serviceP roxy); | |||||
| 61 | ||||||
| 62 | // P erform the primary o peration o f this sam ple. | |||||
| 63 | app. Run(servic eProxy, re cords); | |||||
| 64 | ||||||
| 65 | // D elete all remaining records th at were cr eated by t his sample . | |||||
| 66 | app. DeleteEnti tyRecords( servicePro xy, record s, true); | |||||
| 67 | } | |||||
| 68 | ||||||
| 69 | // Some exceptions to consid er catchin g. | |||||
| 70 | //<snipp etCRUDOper ations3> | |||||
| 71 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault> e) { HandleE xception(e ); } | |||||
| 72 | catch (T imeoutExce ption e) { HandleExc eption(e); } | |||||
| 73 | catch (S ecurityTok enValidati onExceptio n e) { Han dleExcepti on(e); } | |||||
| 74 | catch (E xpiredSecu rityTokenE xception e ) { Handle Exception( e); } | |||||
| 75 | catch (M essageSecu rityExcept ion e) { H andleExcep tion(e); } | |||||
| 76 | catch (S ecurityNeg otiationEx ception e) { HandleE xception(e ); } | |||||
| 77 | catch (S ecurityAcc essDeniedE xception e ) { Handle Exception( e); } | |||||
| 78 | catch (E xception e ) { Handle Exception( e); } | |||||
| 79 | //</snip petCRUDOpe rations3> | |||||
| 80 | ||||||
| 81 | finally | |||||
| 82 | { | |||||
| 83 | // A lways disp ose the se rvice obje ct to clos e the serv ice connec tion and f ree resour ces. | |||||
| 84 | if ( servicePro xy != null ) serviceP roxy.Dispo se(); | |||||
| 85 | ||||||
| 86 | Cons ole.WriteL ine("Press <Enter> t o exit."); | |||||
| 87 | Cons ole.ReadLi ne(); | |||||
| 88 | } | |||||
| 89 | } | |||||
| 90 | ||||||
| 91 | // <snippetCR UDOperatio ns1> | |||||
| 92 | // / <summary > | |||||
| 93 | // / This met hod perfor ms entity create, re trieve, an d update o perations. | |||||
| 94 | // / The dele te operati on is hand led in the DeleteReq uiredrecor ds() metho d. | |||||
| 95 | // / </summar y> | |||||
| 96 | // / <param n ame="servi ceProxy">A n establis hed connec tion to th e Organiza tion web s ervice.</p aram> | |||||
| 97 | // / <param n ame="recor ds">A coll ection of entity rec ords creat ed by this sample.</ param> | |||||
| 98 | pu blic void Run(Organi zationServ iceProxy s erviceProx y, EntityR eferenceCo llection r ecords) | |||||
| 99 | { | |||||
| 100 | // Enabl e early-bo und entity types. Th is enables use of In telliSense in Visual Studio | |||||
| 101 | // and a voids spel ling error s in attri bute names when usin g the Enti ty propert y bag. | |||||
| 102 | serviceP roxy.Enabl eProxyType s(); | |||||
| 103 | ||||||
| 104 | // Here we will us e the inte rface inst ead of the proxy obj ect. | |||||
| 105 | IOrganiz ationServi ce service = (IOrgan izationSer vice)servi ceProxy; | |||||
| 106 | ||||||
| 107 | // Displ ay informa tion about the logge d on user. | |||||
| 108 | Guid use rid = ((Wh oAmIRespon se)service .Execute(n ew WhoAmIR equest())) .UserId; | |||||
| 109 | SystemUs er systemU ser = (Sys temUser)se rvice.Retr ieve("syst emuser", u serid, | |||||
| 110 | new ColumnSet( new string [] { "firs tname", "l astname" } )); | |||||
| 111 | Console. WriteLine( "Logged on user is { 0} {1}.", systemUser .FirstName , systemUs er.LastNam e); | |||||
| 112 | ||||||
| 113 | // Retri eve the ve rsion of M icrosoft D ynamics CR M. | |||||
| 114 | Retrieve VersionReq uest versi onRequest = new Retr ieveVersio nRequest() ; | |||||
| 115 | Retrieve VersionRes ponse vers ionRespons e = | |||||
| 116 | (Ret rieveVersi onResponse )service.E xecute(ver sionReques t); | |||||
| 117 | Console. WriteLine( "Microsoft Dynamics CRM versio n {0}.", v ersionResp onse.Versi on); | |||||
| 118 | ||||||
| 119 | //<snipp etCRUDOper ations2> | |||||
| 120 | // Insta ntiate an account ob ject. Note the use o f the opti on set enu merations defined | |||||
| 121 | // in Op tionSets.c s. | |||||
| 122 | Account account = new Accoun t { Name = "Fourth C offee" }; | |||||
| 123 | account. AccountCat egoryCode = new Opti onSetValue ((int)Acco untAccount CategoryCo de.Preferr edCustomer ); | |||||
| 124 | account. CustomerTy peCode = n ew OptionS etValue((i nt)Account CustomerTy peCode.Inv estor); | |||||
| 125 | ||||||
| 126 | // Creat e an accou nt record named Four th Coffee. | |||||
| 127 | // Save the record reference so we can delete it during cl eanup late r. | |||||
| 128 | Guid acc ountId = s ervice.Cre ate(accoun t); | |||||
| 129 | //</snip petCRUDOpe rations2> | |||||
| 130 | var eref = new Ent ityReferen ce(Account .EntityLog icalName, accountId) ; | |||||
| 131 | eref.Nam e = accoun t.Name; | |||||
| 132 | records. Add(eref); | |||||
| 133 | ||||||
| 134 | Console. Write("{0} {1} creat ed, ", acc ount.Logic alName, ac count.Name ); | |||||
| 135 | ||||||
| 136 | // Retri eve the ac count cont aining sev eral of it s attribut es. This r esults in | |||||
| 137 | // bette r performa nce compar ed to retr ieving all attribute s. | |||||
| 138 | ColumnSe t cols = n ew ColumnS et( | |||||
| 139 | new String[] { "name", " address1_p ostalcode" , "lastuse dincampaig n" }); | |||||
| 140 | ||||||
| 141 | Account retrievedA ccount = ( Account)se rvice.Retr ieve("acco unt", acco untId, col s); | |||||
| 142 | Console. Write("ret rieved, ") ; | |||||
| 143 | ||||||
| 144 | // Updat e the post al code at tribute. | |||||
| 145 | retrieve dAccount.A ddress1_Po stalCode = "98052"; | |||||
| 146 | ||||||
| 147 | // There is no add ress 2 pos tal code n eeded. | |||||
| 148 | retrieve dAccount.A ddress2_Po stalCode = null; | |||||
| 149 | ||||||
| 150 | // Shows use of a Money valu e. | |||||
| 151 | retrieve dAccount.R evenue = n ew Money(5 000000); | |||||
| 152 | ||||||
| 153 | // Shows use of a Boolean va lue. | |||||
| 154 | retrieve dAccount.C reditOnHol d = false; | |||||
| 155 | ||||||
| 156 | // Updat e the acco unt record . | |||||
| 157 | service. Update(ret rievedAcco unt); | |||||
| 158 | Console. WriteLine( "and updat ed."); | |||||
| 159 | } | |||||
| 160 | // </snippetC RUDOperati ons1> | |||||
| 161 | ||||||
| 162 | // / <summary > | |||||
| 163 | // / Create a ny entity records th at the Run () method requires. | |||||
| 164 | // / </summar y> | |||||
| 165 | pu blic Entit yReference Collection CreateReq uiredEntit yRecords(O rganizatio nServicePr oxy servic e) | |||||
| 166 | { | |||||
| 167 | // For t his sample , all requ ired entit y records are create d in the R un() metho d. | |||||
| 168 | return n ew EntityR eferenceCo llection() ; | |||||
| 169 | } | |||||
| 170 | ||||||
| 171 | // / <summary > | |||||
| 172 | // / Delete a ll remaini ng entity records th at were cr eated by t his sample . | |||||
| 173 | // / <param n ame="promp t">When tr ue, the us er is prom pted wheth er | |||||
| 174 | // / the reco rds create d in this sample sho uld be del eted; othe rwise, fal se.</param > | |||||
| 175 | // / </summar y> | |||||
| 176 | pu blic void DeleteEnti tyRecords( Organizati onServiceP roxy servi ce, | |||||
| 177 | EntityRefe renceColle ction reco rds, bool prompt) | |||||
| 178 | { | |||||
| 179 | bool del eteRecords = true; | |||||
| 180 | ||||||
| 181 | if (prom pt) | |||||
| 182 | { | |||||
| 183 | Cons ole.WriteL ine("\nDo you want t hese entit y records deleted? ( y/n) [y]: "); | |||||
| 184 | Stri ng answer = Console. ReadLine() ; | |||||
| 185 | ||||||
| 186 | dele teRecords = (answer. StartsWith ("y") || a nswer.Star tsWith("Y" ) || answe r == Strin g.Empty); | |||||
| 187 | } | |||||
| 188 | ||||||
| 189 | if (dele teRecords) | |||||
| 190 | { | |||||
| 191 | whil e (records .Count > 0 ) | |||||
| 192 | { | |||||
| 193 | EntityRefe rence enti tyRef = re cords[reco rds.Count - 1]; | |||||
| 194 | Console.Wr iteLine("D eleting {0 } '{1}' .. .", entity Ref.Logica lName, ent ityRef.Nam e); | |||||
| 195 | service.De lete(entit yRef.Logic alName, en tityRef.Id ); | |||||
| 196 | records.Re move(entit yRef); | |||||
| 197 | } | |||||
| 198 | ||||||
| 199 | Cons ole.WriteL ine("Entit y records have been deleted.") ; | |||||
| 200 | } | |||||
| 201 | } | |||||
| 202 | ||||||
| 203 | // / Handle a thrown ex ception. | |||||
| 204 | // / </summar y> | |||||
| 205 | // / <param n ame="ex">A n exceptio n.</param> | |||||
| 206 | pr ivate stat ic void Ha ndleExcept ion(Except ion e) | |||||
| 207 | { | |||||
| 208 | // Displ ay the det ails of th e exceptio n. | |||||
| 209 | Console. WriteLine( "\n" + e.M essage); | |||||
| 210 | Console. WriteLine( e.StackTra ce); | |||||
| 211 | ||||||
| 212 | if (e.In nerExcepti on != null ) HandleEx ception(e. InnerExcep tion); | |||||
| 213 | } | |||||
| 214 | } | |||||
| 215 | } | |||||
| 216 | //</snippe tCRUDOpera tions> |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.