Produced by Araxis Merge on 2/1/2017 2:56:35 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\GeneralProgramming\Queries | QueryByAttribute.cs | Tue Dec 20 19:51:46 2016 UTC |
| 2 | Wed Feb 1 19:56:35 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 0 | 0 |
| Changed | 0 | 0 |
| Inserted | 0 | 0 |
| Removed | 1 | 245 |
| 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 QueryByAtt ribute> | |||||
| 17 | using Syst em; | |||||
| 18 | using Syst em.Service Model; | |||||
| 19 | using Syst em.Service Model.Desc ription; | |||||
| 20 | using Syst em.Collect ions.Gener ic; | |||||
| 21 | ||||||
| 22 | // These n amespaces are found in the Mic rosoft.Xrm .Sdk.dll a ssembly | |||||
| 23 | // located in the SD K\bin fold er of the SDK downlo ad. | |||||
| 24 | using Micr osoft.Xrm. Sdk; | |||||
| 25 | using Micr osoft.Xrm. Sdk.Query; | |||||
| 26 | using Micr osoft.Xrm. Sdk.Client ; | |||||
| 27 | ||||||
| 28 | namespace Microsoft. Crm.Sdk.Sa mples | |||||
| 29 | { | |||||
| 30 | /// <s ummary> | |||||
| 31 | /// De monstrates how to do basic ent ity operat ions like create, re trieve, | |||||
| 32 | /// up date, and delete.</s ummary> | |||||
| 33 | ||||||
| 34 | public class Que ryByAttrib uteSample | |||||
| 35 | { | |||||
| 36 | #r egion Clas s Level Me mbers | |||||
| 37 | ||||||
| 38 | pr ivate Orga nizationSe rviceProxy _serviceP roxy; | |||||
| 39 | pr ivate IOrg anizationS ervice _se rvice; | |||||
| 40 | pr ivate List <Guid> _ac countIds = new List< Guid>(); | |||||
| 41 | ||||||
| 42 | #e ndregion C lass Level Members | |||||
| 43 | ||||||
| 44 | #r egion How To Sample Code | |||||
| 45 | // / <summary > | |||||
| 46 | // / This met hod first connects t o the Orga nization s ervice. Af terwards, | |||||
| 47 | // / basic cr eate, retr ieve, upda te, and de lete entit y operatio ns are per formed. | |||||
| 48 | // / </summar y> | |||||
| 49 | // / <param n ame="serve rConfig">C ontains se rver conne ction info rmation.</ param> | |||||
| 50 | // / <param n ame="promp tforDelete ">When Tru e, the use r will be prompted t o delete a ll | |||||
| 51 | // / created entities.< /param> | |||||
| 52 | pu blic void Run(Server Connection .Configura tion serve rConfig, b ool prompt forDelete) | |||||
| 53 | { | |||||
| 54 | try | |||||
| 55 | { | |||||
| 56 | ||||||
| 57 | // C onnect to the Organi zation ser vice. | |||||
| 58 | // T he using s tatement a ssures tha t the serv ice proxy will be pr operly dis posed. | |||||
| 59 | 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 )) | |||||
| 60 | { | |||||
| 61 | // This st atement is required to enable early-boun d type sup port. | |||||
| 62 | _servicePr oxy.Enable ProxyTypes (); | |||||
| 63 | ||||||
| 64 | _service = (IOrganiz ationServi ce)_servic eProxy; | |||||
| 65 | ||||||
| 66 | CreateRequ iredRecord s(); | |||||
| 67 | ||||||
| 68 | //<snippet QueryByAtt ribute1> | |||||
| 69 | // Create query usi ng QueryBy Attribute. | |||||
| 70 | QueryByAtt ribute que rybyattrib ute = new QueryByAtt ribute("ac count"); | |||||
| 71 | querybyatt ribute.Col umnSet = n ew ColumnS et("name", "address1 _city", "e mailaddres s1"); | |||||
| 72 | ||||||
| 73 | // Attrib ute to que ry. | |||||
| 74 | querybyatt ribute.Att ributes.Ad dRange("ad dress1_cit y"); | |||||
| 75 | ||||||
| 76 | // Value of queried attribute to return . | |||||
| 77 | querybyatt ribute.Val ues.AddRan ge("Redmon d"); | |||||
| 78 | ||||||
| 79 | // Query passed to service pr oxy. | |||||
| 80 | EntityColl ection ret rieved = _ service.Re trieveMult iple(query byattribut e); | |||||
| 81 | ||||||
| 82 | System.Con sole.Write Line("Quer y Using Qu eryByAttri bute"); | |||||
| 83 | System.Con sole.Write Line("==== ========== ========== ======="); | |||||
| 84 | ||||||
| 85 | // Iterat e through returned c ollection. | |||||
| 86 | foreach (v ar c in re trieved.En tities) | |||||
| 87 | { | |||||
| 88 | System .Console.W riteLine(" Name: " + c.Attribut es["name"] ); | |||||
| 89 | ||||||
| 90 | if( c. Attributes .Contains( "address1_ city") ) | |||||
| 91 | Sy stem.Conso le.WriteLi ne("Addres s: " + c.A ttributes[ "address1_ city"]); | |||||
| 92 | ||||||
| 93 | if( c. Attributes .Contains( "emailaddr ess1") ) | |||||
| 94 | Sy stem.Conso le.WriteLi ne("E-mail : " + c.At tributes[" emailaddre ss1"]); | |||||
| 95 | } | |||||
| 96 | System.Con sole.Write Line("==== ========== ========== ======="); | |||||
| 97 | //</snippe tQueryByAt tribute1> | |||||
| 98 | ||||||
| 99 | DeleteRequ iredRecord s(promptfo rDelete); | |||||
| 100 | } | |||||
| 101 | } | |||||
| 102 | // Catch any servi ce fault e xceptions that Micro soft Dynam ics CRM th rows. | |||||
| 103 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault>) | |||||
| 104 | { | |||||
| 105 | // Y ou can han dle an exc eption her e or pass it back to the calli ng method. | |||||
| 106 | thro w; | |||||
| 107 | } | |||||
| 108 | } | |||||
| 109 | ||||||
| 110 | // / <summary > | |||||
| 111 | // / Creates any entity records t hat this s ample requ ires. | |||||
| 112 | // / </summar y> | |||||
| 113 | pu blic void CreateRequ iredRecord s() | |||||
| 114 | { | |||||
| 115 | // Creat e two acco unts. | |||||
| 116 | Account account = new Accoun t | |||||
| 117 | { | |||||
| 118 | Name = "A. Dat um Corpora tion", | |||||
| 119 | Addr ess1_State OrProvince = "Colora do", | |||||
| 120 | Addr ess1_Telep hone1 = "( 206)555-55 55", | |||||
| 121 | EMai lAddress1 = "info@da tum.com" | |||||
| 122 | }; | |||||
| 123 | _account Ids.Add(_s ervice.Cre ate(accoun t)); | |||||
| 124 | ||||||
| 125 | account = new Acco unt | |||||
| 126 | { | |||||
| 127 | Name = "Advent ure Works Cycle", | |||||
| 128 | Addr ess1_State OrProvince = "Washin gton", | |||||
| 129 | Addr ess1_City = "Redmond ", | |||||
| 130 | Addr ess1_Telep hone1 = "( 206)555-55 55", | |||||
| 131 | EMai lAddress1 = "contact us@adventu reworkscyc le.com" | |||||
| 132 | }; | |||||
| 133 | _account Ids.Add(_s ervice.Cre ate(accoun t)); | |||||
| 134 | } | |||||
| 135 | ||||||
| 136 | // / <summary > | |||||
| 137 | // / Deletes any entity records t hat were c reated for this samp le. | |||||
| 138 | // / <param n ame="promp t">Indicat es whether to prompt the user | |||||
| 139 | // / to delet e the reco rds create d in this sample.</p aram> | |||||
| 140 | // / </summar y> | |||||
| 141 | pu blic void DeleteRequ iredRecord s(bool pro mpt) | |||||
| 142 | { | |||||
| 143 | bool toB eDeleted = true; | |||||
| 144 | ||||||
| 145 | if (prom pt) | |||||
| 146 | { | |||||
| 147 | // A sk the use r if the c reated ent ities shou ld be dele ted. | |||||
| 148 | Cons ole.Write( "\nDo you want these entity re cords dele ted? (y/n) [y]: "); | |||||
| 149 | Stri ng answer = Console. ReadLine() ; | |||||
| 150 | if ( answer.Sta rtsWith("y ") || answ er.StartsW ith("Y") | | | |||||
| 151 | answer == String.Emp ty) | |||||
| 152 | { | |||||
| 153 | toBeDelete d = true; | |||||
| 154 | } | |||||
| 155 | else | |||||
| 156 | { | |||||
| 157 | toBeDelete d = false; | |||||
| 158 | } | |||||
| 159 | } | |||||
| 160 | ||||||
| 161 | if (toBe Deleted) | |||||
| 162 | { | |||||
| 163 | // D elete all records cr eated in t his sample . | |||||
| 164 | fore ach (Guid accountId in _accoun tIds) | |||||
| 165 | { | |||||
| 166 | _service.D elete(Acco unt.Entity LogicalNam e, account Id); | |||||
| 167 | } | |||||
| 168 | Cons ole.WriteL ine("Entit y record(s ) have bee n deleted. "); | |||||
| 169 | } | |||||
| 170 | } | |||||
| 171 | ||||||
| 172 | #e ndregion H ow To Samp le Code | |||||
| 173 | ||||||
| 174 | #r egion Main method | |||||
| 175 | ||||||
| 176 | // / <summary > | |||||
| 177 | // / Standard Main() me thod used by most SD K samples. | |||||
| 178 | // / </summar y> | |||||
| 179 | // / <param n ame="args" ></param> | |||||
| 180 | st atic publi c void Mai n(string[] args) | |||||
| 181 | { | |||||
| 182 | try | |||||
| 183 | { | |||||
| 184 | // O btain the target org anization' s Web addr ess and cl ient logon | |||||
| 185 | // c redentials from the user. | |||||
| 186 | Serv erConnecti on serverC onnect = n ew ServerC onnection( ); | |||||
| 187 | Serv erConnecti on.Configu ration con fig = serv erConnect. GetServerC onfigurati on(); | |||||
| 188 | ||||||
| 189 | Quer yByAttribu teSample a pp = new Q ueryByAttr ibuteSampl e(); | |||||
| 190 | app. Run(config , true); | |||||
| 191 | } | |||||
| 192 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault> ex ) | |||||
| 193 | { | |||||
| 194 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 195 | Cons ole.WriteL ine("Times tamp: {0}" , ex.Detai l.Timestam p); | |||||
| 196 | Cons ole.WriteL ine("Code: {0}", ex. Detail.Err orCode); | |||||
| 197 | Cons ole.WriteL ine("Messa ge: {0}", ex.Detail. Message); | |||||
| 198 | Cons ole.WriteL ine("Plugi n Trace: { 0}", ex.De tail.Trace Text); | |||||
| 199 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 200 | null == ex .Detail.In nerFault ? "No Inner Fault" : "Has Inner Fault"); | |||||
| 201 | } | |||||
| 202 | catch (S ystem.Time outExcepti on ex) | |||||
| 203 | { | |||||
| 204 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 205 | Cons ole.WriteL ine("Messa ge: {0}", ex.Message ); | |||||
| 206 | Cons ole.WriteL ine("Stack Trace: {0 }", ex.Sta ckTrace); | |||||
| 207 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 208 | null == ex .InnerExce ption.Mess age ? "No Inner Faul t" : ex.In nerExcepti on.Message ); | |||||
| 209 | } | |||||
| 210 | catch (S ystem.Exce ption ex) | |||||
| 211 | { | |||||
| 212 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 213 | Cons ole.WriteL ine(ex.Mes sage); | |||||
| 214 | ||||||
| 215 | // D isplay the details o f the inne r exceptio n. | |||||
| 216 | if ( ex.InnerEx ception != null) | |||||
| 217 | { | |||||
| 218 | Console.Wr iteLine(ex .InnerExce ption.Mess age); | |||||
| 219 | ||||||
| 220 | FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault> f e = ex.Inn erExceptio n | |||||
| 221 | as Fau ltExceptio n<Microsof t.Xrm.Sdk. Organizati onServiceF ault>; | |||||
| 222 | if (fe != null) | |||||
| 223 | { | |||||
| 224 | Consol e.WriteLin e("Timesta mp: {0}", fe.Detail. Timestamp) ; | |||||
| 225 | Consol e.WriteLin e("Code: { 0}", fe.De tail.Error Code); | |||||
| 226 | Consol e.WriteLin e("Message : {0}", fe .Detail.Me ssage); | |||||
| 227 | Consol e.WriteLin e("Plugin Trace: {0} ", fe.Deta il.TraceTe xt); | |||||
| 228 | Consol e.WriteLin e("Inner F ault: {0}" , | |||||
| 229 | nu ll == fe.D etail.Inne rFault ? " No Inner F ault" : "H as Inner F ault"); | |||||
| 230 | } | |||||
| 231 | } | |||||
| 232 | } | |||||
| 233 | // Addit ional exce ptions to catch: Sec urityToken Validation Exception, ExpiredSe curityToke nException , | |||||
| 234 | // Secur ityAccessD eniedExcep tion, Mess ageSecurit yException , and Secu rityNegoti ationExcep tion. | |||||
| 235 | ||||||
| 236 | finally | |||||
| 237 | { | |||||
| 238 | Cons ole.WriteL ine("Press <Enter> t o exit."); | |||||
| 239 | Cons ole.ReadLi ne(); | |||||
| 240 | } | |||||
| 241 | } | |||||
| 242 | #e ndregion M ain method | |||||
| 243 | } | |||||
| 244 | } | |||||
| 245 | //</snippe tQueryByAt tribute> |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.