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 | QueryExpressionPagingWithCookie.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 | 329 |
| 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 QueryExpre ssionPagin gWithCooki e> | |||||
| 18 | using Syst em; | |||||
| 19 | using Syst em.Service Model; | |||||
| 20 | using Syst em.Service Model.Desc ription; | |||||
| 21 | using Syst em.Collect ions.Gener ic; | |||||
| 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.Client ; | |||||
| 27 | using Micr osoft.Xrm. Sdk.Query; | |||||
| 28 | using Micr osoft.Xrm. Sdk.Discov ery; | |||||
| 29 | ||||||
| 30 | // This na mespace is found in Microsoft. Crm.Sdk.Pr oxy.dll as sembly | |||||
| 31 | // found i n the SDK\ bin folder . | |||||
| 32 | using Micr osoft.Crm. Sdk.Messag es; | |||||
| 33 | using Micr osoft.Xrm. Sdk.Messag es; | |||||
| 34 | ||||||
| 35 | ||||||
| 36 | namespace Microsoft. Crm.Sdk.Sa mples | |||||
| 37 | { | |||||
| 38 | /// <s ummary> | |||||
| 39 | /// De monstrates how to us e the Quer yExpressio n with a p aging | |||||
| 40 | /// co okie to re trieve a b atch of re cords. | |||||
| 41 | /// If you want to run thi s sample r epeatedly, you have the option to | |||||
| 42 | /// de lete all t he records created a t the end of executi on. | |||||
| 43 | /// </ summary> | |||||
| 44 | class QueryExpre ssionPagin gWithCooki e | |||||
| 45 | { | |||||
| 46 | #r egion Clas s Level Me mbers | |||||
| 47 | ||||||
| 48 | // / <summary > | |||||
| 49 | // / Stores t he organiz ation serv ice proxy. | |||||
| 50 | // / </summar y> | |||||
| 51 | pr ivate Orga nizationSe rviceProxy _serviceP roxy; | |||||
| 52 | pr ivate IOrg anizationS ervice _se rvice; | |||||
| 53 | ||||||
| 54 | // Define th e IDs need ed for thi s sample. | |||||
| 55 | pu blic Guid[ ] _childAc countIds; | |||||
| 56 | pu blic Guid _parentAcc ountId; | |||||
| 57 | ||||||
| 58 | #e ndregion C lass Level Members | |||||
| 59 | ||||||
| 60 | #r egion How To Sample Code | |||||
| 61 | // / <summary > | |||||
| 62 | // / Create a nd configu re the org anization service pr oxy. | |||||
| 63 | // / Create a parent ac count reco rd and sub sequent 10 child acc ount recor ds. | |||||
| 64 | // / Retrieve batch of records us ing Retrie veMultiple message w ith paging cookie. | |||||
| 65 | // / Optional ly delete any entity records t hat were c reated for this samp le. | |||||
| 66 | // / </summar y> | |||||
| 67 | // / <param n ame="serve rConfig">C ontains se rver conne ction info rmation.</ param> | |||||
| 68 | // / <param n ame="promp tForDelete ">When Tru e, the use r will be prompted t o delete a ll | |||||
| 69 | // / created entities.< /param> | |||||
| 70 | pu blic void Run(Server Connection .Configura tion serve rConfig, b ool prompt ForDelete) | |||||
| 71 | { | |||||
| 72 | try | |||||
| 73 | { | |||||
| 74 | ||||||
| 75 | // C onnect to the Organi zation ser vice. | |||||
| 76 | // T he using s tatement a ssures tha t the serv ice proxy will be pr operly dis posed. | |||||
| 77 | 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 )) | |||||
| 78 | { | |||||
| 79 | // This st atement is required to enable early-boun d type sup port. | |||||
| 80 | _servicePr oxy.Enable ProxyTypes (); | |||||
| 81 | ||||||
| 82 | _service = (IOrganiz ationServi ce)_servic eProxy; | |||||
| 83 | ||||||
| 84 | // Call th e method t o create a ny data th at this sa mple requi res. | |||||
| 85 | CreateRequ iredRecord s(); | |||||
| 86 | ||||||
| 87 | //<snippet QueryExpre ssionPagin gWithCooki e1> | |||||
| 88 | // Query u sing the p aging cook ie. | |||||
| 89 | // Define the paging attribute s. | |||||
| 90 | // The num ber of rec ords per p age to ret rieve. | |||||
| 91 | int queryC ount = 3; | |||||
| 92 | ||||||
| 93 | // Initial ize the pa ge number. | |||||
| 94 | int pageNu mber = 1; | |||||
| 95 | ||||||
| 96 | // Initial ize the nu mber of re cords. | |||||
| 97 | int record Count = 0; | |||||
| 98 | ||||||
| 99 | // Define the condit ion expres sion for r etrieving records. | |||||
| 100 | ConditionE xpression pagecondit ion = new ConditionE xpression( ); | |||||
| 101 | pagecondit ion.Attrib uteName = "parentacc ountid"; | |||||
| 102 | pagecondit ion.Operat or = Condi tionOperat or.Equal; | |||||
| 103 | pagecondit ion.Values .Add(_pare ntAccountI d); | |||||
| 104 | ||||||
| 105 | // Define the order expression to retrie ve the rec ords. | |||||
| 106 | OrderExpre ssion orde r = new Or derExpress ion(); | |||||
| 107 | order.Attr ibuteName = "name"; | |||||
| 108 | order.Orde rType = Or derType.As cending; | |||||
| 109 | ||||||
| 110 | // Create the query expression and add c ondition. | |||||
| 111 | QueryExpre ssion page query = ne w QueryExp ression(); | |||||
| 112 | pagequery. EntityName = "accoun t"; | |||||
| 113 | pagequery. Criteria.A ddConditio n(pagecond ition); | |||||
| 114 | pagequery. Orders.Add (order); | |||||
| 115 | pagequery. ColumnSet. AddColumns ("name", " emailaddre ss1"); | |||||
| 116 | ||||||
| 117 | // Assign the pagein fo propert ies to the query exp ression. | |||||
| 118 | pagequery. PageInfo = new Pagin gInfo(); | |||||
| 119 | pagequery. PageInfo.C ount = que ryCount; | |||||
| 120 | pagequery. PageInfo.P ageNumber = pageNumb er; | |||||
| 121 | ||||||
| 122 | // The cur rent pagin g cookie. When retri eving the first page , | |||||
| 123 | // pagingC ookie shou ld be null . | |||||
| 124 | pagequery. PageInfo.P agingCooki e = null; | |||||
| 125 | Console.Wr iteLine("R etrieving sample acc ount recor ds in page s...\n"); | |||||
| 126 | Console.Wr iteLine("# \tAccount Name\t\tEm ail Addres s"); | |||||
| 127 | ||||||
| 128 | while (tru e) | |||||
| 129 | { | |||||
| 130 | // Ret rieve the page. | |||||
| 131 | Entity Collection results = _serviceP roxy.Retri eveMultipl e(pagequer y); | |||||
| 132 | if (re sults.Enti ties != nu ll) | |||||
| 133 | { | |||||
| 134 | // Retrieve all record s from the result se t. | |||||
| 135 | fo reach (Acc ount acct in results .Entities) | |||||
| 136 | { | |||||
| 137 | Console. WriteLine( "{0}.\t{1} \t{2}", ++ recordCoun t, acct.Na me, | |||||
| 138 | acct.EMai lAddress1) ; | |||||
| 139 | } | |||||
| 140 | } | |||||
| 141 | ||||||
| 142 | // Che ck for mor e records, if it ret urns true. | |||||
| 143 | if (re sults.More Records) | |||||
| 144 | { | |||||
| 145 | Co nsole.Writ eLine("\n* ********** *****\nPag e number { 0}\n****** ********** ", pageque ry.PageInf o.PageNumb er); | |||||
| 146 | Co nsole.Writ eLine("#\t Account Na me\t\tEmai l Address" ); | |||||
| 147 | ||||||
| 148 | // Increment the page number to retrieve t he next pa ge. | |||||
| 149 | pa gequery.Pa geInfo.Pag eNumber++; | |||||
| 150 | ||||||
| 151 | // Set the p aging cook ie to the paging coo kie return ed from cu rrent resu lts. | |||||
| 152 | pa gequery.Pa geInfo.Pag ingCookie = results. PagingCook ie; | |||||
| 153 | } | |||||
| 154 | else | |||||
| 155 | { | |||||
| 156 | // If no mor e records are in the result no des, exit the loop. | |||||
| 157 | br eak; | |||||
| 158 | } | |||||
| 159 | } | |||||
| 160 | //</snippe tQueryExpr essionPagi ngWithCook ie1> | |||||
| 161 | ||||||
| 162 | DeleteRequ iredRecord s(promptFo rDelete); | |||||
| 163 | } | |||||
| 164 | } | |||||
| 165 | // Catch any servi ce fault e xceptions that Micro soft Dynam ics CRM th rows. | |||||
| 166 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault>) | |||||
| 167 | { | |||||
| 168 | // Y ou can han dle an exc eption her e or pass it back to the calli ng method. | |||||
| 169 | thro w; | |||||
| 170 | } | |||||
| 171 | return; | |||||
| 172 | } | |||||
| 173 | ||||||
| 174 | // / <summary > | |||||
| 175 | // / This met hod create s any enti ty records that this sample re quires. | |||||
| 176 | // / Create a parent ac count reco rd. | |||||
| 177 | // / Create 1 0 child ac counts to the parent account r ecord. | |||||
| 178 | // / </summar y> | |||||
| 179 | pu blic void CreateRequ iredRecord s() | |||||
| 180 | { | |||||
| 181 | Console. WriteLine( "Creating sample acc ount recor ds...\n"); | |||||
| 182 | ||||||
| 183 | // Insta ntiate a a ccount ent ity record and set i ts propert y values. | |||||
| 184 | // See t he Entity Metadata t opic in th e SDK docu mentation | |||||
| 185 | // to de termine wh ich attrib utes must be set for each enti ty. | |||||
| 186 | // Creat e the pare nt account . | |||||
| 187 | Account parentAcco unt = new Account | |||||
| 188 | { | |||||
| 189 | Name = "Root T est Accoun t", | |||||
| 190 | EMai lAddress1 = "root@ro ot.com" | |||||
| 191 | }; | |||||
| 192 | ||||||
| 193 | _parentA ccountId = _service. Create(par entAccount ); | |||||
| 194 | ||||||
| 195 | // Creat e 10 child accounts. | |||||
| 196 | _childAc countIds = new Guid[ 10]; | |||||
| 197 | int coun t = 1; | |||||
| 198 | while (t rue) | |||||
| 199 | { | |||||
| 200 | Acco unt childA ccount = n ew Account | |||||
| 201 | { | |||||
| 202 | Name = "Ch ild Test A ccount " + count.ToS tring(), | |||||
| 203 | EMailAddre ss1 = "chi ld" + coun t.ToString () + "@roo t.com", | |||||
| 204 | EMailAddre ss2 = "sam e@root.com ", | |||||
| 205 | ParentAcco untId = ne w EntityRe ference(Ac count.Enti tyLogicalN ame, _pare ntAccountI d) | |||||
| 206 | }; | |||||
| 207 | ||||||
| 208 | _chi ldAccountI ds[count - 1] = _ser vice.Creat e(childAcc ount); | |||||
| 209 | ||||||
| 210 | // J ump out of the loop after crea ting 10 ch ild accoun ts. | |||||
| 211 | if ( count == 1 0) | |||||
| 212 | break; | |||||
| 213 | // I ncrement t he count. | |||||
| 214 | coun t++; | |||||
| 215 | } | |||||
| 216 | return; | |||||
| 217 | } | |||||
| 218 | ||||||
| 219 | // / <summary > | |||||
| 220 | // / Deletes any entity records t hat were c reated for this samp le. | |||||
| 221 | // / <param n ame="promp t">Indicat es whether to prompt the user to delete the record s created in this sa mple.</par am> | |||||
| 222 | // / </summar y> | |||||
| 223 | pu blic void DeleteRequ iredRecord s(bool pro mpt) | |||||
| 224 | { | |||||
| 225 | bool del eteRecords = true; | |||||
| 226 | ||||||
| 227 | if (prom pt) | |||||
| 228 | { | |||||
| 229 | Cons ole.WriteL ine("\nDo you want t hese entit y records deleted? ( y/n)"); | |||||
| 230 | Stri ng answer = Console. ReadLine() ; | |||||
| 231 | ||||||
| 232 | dele teRecords = (answer. StartsWith ("y") || a nswer.Star tsWith("Y" )); | |||||
| 233 | } | |||||
| 234 | ||||||
| 235 | if (dele teRecords) | |||||
| 236 | { | |||||
| 237 | Cons ole.WriteL ine("Delti ng entity records... please wa it!"); | |||||
| 238 | ||||||
| 239 | // R emove 10 t est child accounts. | |||||
| 240 | int deleteCoun t = 0; | |||||
| 241 | whil e (deleteC ount < 10) | |||||
| 242 | { | |||||
| 243 | _service.D elete(Acco unt.Entity LogicalNam e, _childA ccountIds[ deleteCoun t]); | |||||
| 244 | ++deleteCo unt; | |||||
| 245 | } | |||||
| 246 | ||||||
| 247 | // R emove the test paren t account. | |||||
| 248 | _ser vice.Delet e(Account. EntityLogi calName, _ parentAcco untId); | |||||
| 249 | ||||||
| 250 | Cons ole.WriteL ine("Entit y records have been deleted.") ; | |||||
| 251 | } | |||||
| 252 | } | |||||
| 253 | ||||||
| 254 | #e ndregion H ow To Samp le Code | |||||
| 255 | ||||||
| 256 | #r egion Main | |||||
| 257 | ||||||
| 258 | // / <summary > | |||||
| 259 | // / Standard Main() me thod used by most SD K samples. | |||||
| 260 | // / </summar y> | |||||
| 261 | // / <param n ame="args" ></param> | |||||
| 262 | st atic publi c void Mai n(string[] args) | |||||
| 263 | { | |||||
| 264 | try | |||||
| 265 | { | |||||
| 266 | // O btain the target org anization' s Web addr ess and cl ient logon | |||||
| 267 | // c redentials from the user. | |||||
| 268 | Serv erConnecti on serverC onnect = n ew ServerC onnection( ); | |||||
| 269 | Serv erConnecti on.Configu ration con fig = serv erConnect. GetServerC onfigurati on(); | |||||
| 270 | ||||||
| 271 | Quer yExpressio nPagingWit hCookie ap p = new Qu eryExpress ionPagingW ithCookie( ); | |||||
| 272 | app. Run(config , true); | |||||
| 273 | } | |||||
| 274 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault> ex ) | |||||
| 275 | { | |||||
| 276 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 277 | Cons ole.WriteL ine("Times tamp: {0}" , ex.Detai l.Timestam p); | |||||
| 278 | Cons ole.WriteL ine("Code: {0}", ex. Detail.Err orCode); | |||||
| 279 | Cons ole.WriteL ine("Messa ge: {0}", ex.Detail. Message); | |||||
| 280 | Cons ole.WriteL ine("Plugi n Trace: { 0}", ex.De tail.Trace Text); | |||||
| 281 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 282 | null == ex .Detail.In nerFault ? "No Inner Fault" : "Has Inner Fault"); | |||||
| 283 | } | |||||
| 284 | catch (S ystem.Time outExcepti on ex) | |||||
| 285 | { | |||||
| 286 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 287 | Cons ole.WriteL ine("Messa ge: {0}", ex.Message ); | |||||
| 288 | Cons ole.WriteL ine("Stack Trace: {0 }", ex.Sta ckTrace); | |||||
| 289 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 290 | null == ex .InnerExce ption.Mess age ? "No Inner Faul t" : ex.In nerExcepti on.Message ); | |||||
| 291 | } | |||||
| 292 | catch (S ystem.Exce ption ex) | |||||
| 293 | { | |||||
| 294 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 295 | Cons ole.WriteL ine(ex.Mes sage); | |||||
| 296 | ||||||
| 297 | // D isplay the details o f the inne r exceptio n. | |||||
| 298 | if ( ex.InnerEx ception != null) | |||||
| 299 | { | |||||
| 300 | Console.Wr iteLine(ex .InnerExce ption.Mess age); | |||||
| 301 | ||||||
| 302 | FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault> f e = ex.Inn erExceptio n | |||||
| 303 | as Fau ltExceptio n<Microsof t.Xrm.Sdk. Organizati onServiceF ault>; | |||||
| 304 | if (fe != null) | |||||
| 305 | { | |||||
| 306 | Consol e.WriteLin e("Timesta mp: {0}", fe.Detail. Timestamp) ; | |||||
| 307 | Consol e.WriteLin e("Code: { 0}", fe.De tail.Error Code); | |||||
| 308 | Consol e.WriteLin e("Message : {0}", fe .Detail.Me ssage); | |||||
| 309 | Consol e.WriteLin e("Plugin Trace: {0} ", fe.Deta il.TraceTe xt); | |||||
| 310 | Consol e.WriteLin e("Inner F ault: {0}" , | |||||
| 311 | nu ll == fe.D etail.Inne rFault ? " No Inner F ault" : "H as Inner F ault"); | |||||
| 312 | } | |||||
| 313 | } | |||||
| 314 | } | |||||
| 315 | // Addit ional exce ptions to catch: Sec urityToken Validation Exception, ExpiredSe curityToke nException , | |||||
| 316 | // Secur ityAccessD eniedExcep tion, Mess ageSecurit yException , and Secu rityNegoti ationExcep tion. | |||||
| 317 | ||||||
| 318 | finally | |||||
| 319 | { | |||||
| 320 | Cons ole.WriteL ine("Press <Enter> t o exit."); | |||||
| 321 | Cons ole.ReadLi ne(); | |||||
| 322 | } | |||||
| 323 | ||||||
| 324 | } | |||||
| 325 | #e ndregion M ain | |||||
| 326 | ||||||
| 327 | } | |||||
| 328 | } | |||||
| 329 | //</snippe tQueryExpr essionPagi ngWithCook ie> |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.