Produced by Araxis Merge on 2/1/2017 2:56:31 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\DataManagement\DataImport | ImportWithCreate.cs | Tue Dec 20 19:51:43 2016 UTC |
| 2 | Wed Feb 1 19:56:31 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 0 | 0 |
| Changed | 0 | 0 |
| Inserted | 0 | 0 |
| Removed | 1 | 532 |
| 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 ImportWith Create> | |||||
| 17 | using Syst em; | |||||
| 18 | using Syst em.Service Model; | |||||
| 19 | using Syst em.Collect ions.Gener ic; | |||||
| 20 | using Syst em.Linq; | |||||
| 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 | using Micr osoft.Xrm. Sdk.Messag es; | |||||
| 28 | using Micr osoft.Xrm. Sdk.Metada ta; | |||||
| 29 | ||||||
| 30 | // These n amespaces are found in the Mic rosoft.Crm .Sdk.Proxy .dll assem bly | |||||
| 31 | // located in the SD K\bin fold er of the SDK downlo ad. | |||||
| 32 | using Micr osoft.Crm. Sdk.Messag es; | |||||
| 33 | ||||||
| 34 | namespace Microsoft. Crm.Sdk.Sa mples | |||||
| 35 | { | |||||
| 36 | /// <s ummary> | |||||
| 37 | // / This sam ple shows how to def ine a comp lex mappin g for impo rting and then use t he | |||||
| 38 | /// Mi crosoft Dy namics CRM 2011 API to bulk im port recor ds with th at mapping . | |||||
| 39 | // / </summar y> | |||||
| 40 | public class Imp ortWithCre ate | |||||
| 41 | { | |||||
| 42 | #r egion Clas s Level Me mbers | |||||
| 43 | ||||||
| 44 | pr ivate Orga nizationSe rviceProxy _serviceP roxy; | |||||
| 45 | pr ivate Date Time _exec utionDate; | |||||
| 46 | ||||||
| 47 | #e ndregion | |||||
| 48 | ||||||
| 49 | // / <summary > | |||||
| 50 | // / This met hod first connects t o the orga nization s ervice. Af terwards, | |||||
| 51 | // / auditing is enable d on the o rganizatio n, account entity, a nd a coupl e | |||||
| 52 | // / of attri butes. | |||||
| 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 | using (_ servicePro xy = new O rganizatio nServicePr oxy(server Config.Org anizationU ri, server Config.Hom eRealmUri, serverConf ig.Credent ials, serv erConfig.D eviceCrede ntials)) | |||||
| 60 | { | |||||
| 61 | // T his statem ent is req uired to e nable earl y bound ty pe support . | |||||
| 62 | _ser viceProxy. EnableProx yTypes(); | |||||
| 63 | ||||||
| 64 | // L og the sta rt time to ensure de letion of records cr eated duri ng executi on. | |||||
| 65 | _exe cutionDate = DateTim e.Today; | |||||
| 66 | Impo rtRecords( ); | |||||
| 67 | Dele teRequired Records(pr omptforDel ete); | |||||
| 68 | } | |||||
| 69 | } | |||||
| 70 | ||||||
| 71 | // / <summary > | |||||
| 72 | // / Imports records to Microsoft Dynamics CRM from t he specifi ed .csv fi le. | |||||
| 73 | // / </summar y> | |||||
| 74 | pu blic void ImportReco rds() | |||||
| 75 | { | |||||
| 76 | // Creat e an impor t map. | |||||
| 77 | ImportMa p importMa p = new Im portMap() | |||||
| 78 | { | |||||
| 79 | Name = "Import Map " + D ateTime.No w.Ticks.To String(), | |||||
| 80 | Sour ce = "Impo rt Account s.csv", | |||||
| 81 | Desc ription = "Descripti on of data being imp orted", | |||||
| 82 | Enti tiesPerFil e = | |||||
| 83 | new Option SetValue(( int)Import MapEntitie sPerFile.S ingleEntit yPerFile), | |||||
| 84 | Enti tyState = EntityStat e.Created | |||||
| 85 | }; | |||||
| 86 | Guid imp ortMapId = _serviceP roxy.Creat e(importMa p); | |||||
| 87 | ||||||
| 88 | // Creat e column m appings. | |||||
| 89 | ||||||
| 90 | #region Column One Mappings | |||||
| 91 | // Creat e a column mapping f or a 'text ' type fie ld. | |||||
| 92 | ColumnMa pping colM apping1 = new Column Mapping() | |||||
| 93 | { | |||||
| 94 | // S et source properties . | |||||
| 95 | Sour ceAttribut eName = "s rc_name", | |||||
| 96 | Sour ceEntityNa me = "Acco unt_1", | |||||
| 97 | ||||||
| 98 | // S et target properties . | |||||
| 99 | Targ etAttribut eName = "n ame", | |||||
| 100 | Targ etEntityNa me = Accou nt.EntityL ogicalName , | |||||
| 101 | ||||||
| 102 | // R elate this column ma pping with the data map. | |||||
| 103 | Impo rtMapId = | |||||
| 104 | new Entity Reference( ImportMap. EntityLogi calName, i mportMapId ), | |||||
| 105 | ||||||
| 106 | // F orce this column to be process ed. | |||||
| 107 | Proc essCode = | |||||
| 108 | new Option SetValue(( int)Column MappingPro cessCode.P rocess) | |||||
| 109 | }; | |||||
| 110 | ||||||
| 111 | // Creat e the mapp ing. | |||||
| 112 | Guid col MappingId1 = _servic eProxy.Cre ate(colMap ping1); | |||||
| 113 | #endregi on | |||||
| 114 | ||||||
| 115 | #region Column Two Mappings | |||||
| 116 | // Creat e a column mapping f or a 'look up' type f ield. | |||||
| 117 | ColumnMa pping colM apping2 = new Column Mapping() | |||||
| 118 | { | |||||
| 119 | // S et source properties . | |||||
| 120 | Sour ceAttribut eName = "s rc_parent" , | |||||
| 121 | Sour ceEntityNa me = "Acco unt_1", | |||||
| 122 | ||||||
| 123 | // S et target properties . | |||||
| 124 | Targ etAttribut eName = "p arentaccou ntid", | |||||
| 125 | Targ etEntityNa me = Accou nt.EntityL ogicalName , | |||||
| 126 | ||||||
| 127 | // R elate this column ma pping with the data map. | |||||
| 128 | Impo rtMapId = | |||||
| 129 | new Entity Reference( ImportMap. EntityLogi calName, i mportMapId ), | |||||
| 130 | ||||||
| 131 | // F orce this column to be process ed. | |||||
| 132 | Proc essCode = | |||||
| 133 | new Option SetValue(( int)Column MappingPro cessCode.P rocess), | |||||
| 134 | }; | |||||
| 135 | ||||||
| 136 | // Creat e the mapp ing. | |||||
| 137 | Guid col MappingId2 = _servic eProxy.Cre ate(colMap ping2); | |||||
| 138 | ||||||
| 139 | // Becau se we crea ted a colu mn mapping of type l ookup, we need to sp ecify look up details in a look upmapping. | |||||
| 140 | // One l ookupmappi ng will be for the p arent acco unt, and t he other f or the cur rent recor d. | |||||
| 141 | // This lookupmapp ing is imp ortant bec ause witho ut it the current re cord | |||||
| 142 | // canno t be used as the par ent of ano ther recor d. | |||||
| 143 | ||||||
| 144 | // Creat e a lookup mapping t o the pare nt account . | |||||
| 145 | LookUpMa pping pare ntLookupMa pping = ne w LookUpMa pping() | |||||
| 146 | { | |||||
| 147 | // R elate this mapping w ith its pa rent colum n mapping. | |||||
| 148 | Colu mnMappingI d = | |||||
| 149 | new Entity Reference( ColumnMapp ing.Entity LogicalNam e, colMapp ingId2), | |||||
| 150 | ||||||
| 151 | // F orce this column to be process ed. | |||||
| 152 | Proc essCode = | |||||
| 153 | new Option SetValue(( int)LookUp MappingPro cessCode.P rocess), | |||||
| 154 | ||||||
| 155 | // S et the loo kup for an account e ntity by i ts name at tribute. | |||||
| 156 | Look UpEntityNa me = Accou nt.EntityL ogicalName , | |||||
| 157 | Look UpAttribut eName = "n ame", | |||||
| 158 | Look UpSourceCo de = | |||||
| 159 | new Option SetValue(( int)LookUp MappingLoo kUpSourceC ode.System ) | |||||
| 160 | }; | |||||
| 161 | ||||||
| 162 | // Creat e the look up mapping . | |||||
| 163 | Guid par entLookupM appingId = _serviceP roxy.Creat e(parentLo okupMappin g); | |||||
| 164 | ||||||
| 165 | // Creat e a lookup on the cu rrent reco rd's "src_ name" so t hat this r ecord can | |||||
| 166 | // be us ed as the parent acc ount for a nother rec ord being imported. | |||||
| 167 | // Witho ut this lo okup, no r ecord usin g this acc ount as it s parent w ill be imp orted. | |||||
| 168 | LookUpMa pping curr entLookUpM apping = n ew LookUpM apping() | |||||
| 169 | { | |||||
| 170 | // R elate this lookup wi th its par ent column mapping. | |||||
| 171 | Colu mnMappingI d = | |||||
| 172 | new Entity Reference( ColumnMapp ing.Entity LogicalNam e, colMapp ingId2), | |||||
| 173 | ||||||
| 174 | // F orce this column to be process ed. | |||||
| 175 | Proc essCode = | |||||
| 176 | new Option SetValue(( int)LookUp MappingPro cessCode.P rocess), | |||||
| 177 | ||||||
| 178 | // S et the loo kup for th e current record by its src_na me attribu te. | |||||
| 179 | Look UpAttribut eName = "s rc_name", | |||||
| 180 | Look UpEntityNa me = "Acco unt_1", | |||||
| 181 | Look UpSourceCo de = | |||||
| 182 | new Option SetValue(( int)LookUp MappingLoo kUpSourceC ode.Source ) | |||||
| 183 | }; | |||||
| 184 | ||||||
| 185 | // Creat e the look up mapping | |||||
| 186 | Guid cur rentLookup MappingId = _service Proxy.Crea te(current LookUpMapp ing); | |||||
| 187 | #endregi on | |||||
| 188 | ||||||
| 189 | #region Column Thr ee Mapping s | |||||
| 190 | // Creat e a column mapping f or a 'pick list' type field | |||||
| 191 | ColumnMa pping colM apping3 = new Column Mapping() | |||||
| 192 | { | |||||
| 193 | // S et source properties | |||||
| 194 | Sour ceAttribut eName = "s rc_address type", | |||||
| 195 | Sour ceEntityNa me = "Acco unt_1", | |||||
| 196 | ||||||
| 197 | // S et target properties | |||||
| 198 | Targ etAttribut eName = "a ddress1_ad dresstypec ode", | |||||
| 199 | Targ etEntityNa me = Accou nt.EntityL ogicalName , | |||||
| 200 | ||||||
| 201 | // R elate this column ma pping with its paren t data map | |||||
| 202 | Impo rtMapId = | |||||
| 203 | new Entity Reference( ImportMap. EntityLogi calName, i mportMapId ), | |||||
| 204 | ||||||
| 205 | // F orce this column to be process ed | |||||
| 206 | Proc essCode = | |||||
| 207 | new Option SetValue(( int)Column MappingPro cessCode.P rocess) | |||||
| 208 | }; | |||||
| 209 | ||||||
| 210 | // Creat e the mapp ing | |||||
| 211 | Guid col MappingId3 = _servic eProxy.Cre ate(colMap ping3); | |||||
| 212 | ||||||
| 213 | // Becau se we crea ted a colu mn mapping of type p icklist, w e need to specify pi cklist det ails in a picklistMa pping | |||||
| 214 | PickList Mapping pi ckListMapp ing1 = new PickListM apping() | |||||
| 215 | { | |||||
| 216 | Sour ceValue = "bill", | |||||
| 217 | Targ etValue = 1, | |||||
| 218 | ||||||
| 219 | // R elate this column ma pping with its colum n mapping data map | |||||
| 220 | Colu mnMappingI d = | |||||
| 221 | new Entity Reference( ColumnMapp ing.Entity LogicalNam e, colMapp ingId3), | |||||
| 222 | ||||||
| 223 | // F orce this column to be process ed | |||||
| 224 | Proc essCode = | |||||
| 225 | new Option SetValue(( int)PickLi stMappingP rocessCode .Process) | |||||
| 226 | }; | |||||
| 227 | ||||||
| 228 | // Creat e the mapp ing | |||||
| 229 | Guid pic klistMappi ngId1 = _s erviceProx y.Create(p ickListMap ping1); | |||||
| 230 | ||||||
| 231 | // Need a picklist mapping f or every a ddress typ e code exp ected | |||||
| 232 | PickList Mapping pi ckListMapp ing2 = new PickListM apping() | |||||
| 233 | { | |||||
| 234 | Sour ceValue = "ship", | |||||
| 235 | Targ etValue = 2, | |||||
| 236 | ||||||
| 237 | // R elate this column ma pping with its colum n mapping data map | |||||
| 238 | Colu mnMappingI d = | |||||
| 239 | new Entity Reference( ColumnMapp ing.Entity LogicalNam e, colMapp ingId3), | |||||
| 240 | ||||||
| 241 | // F orce this column to be process ed | |||||
| 242 | Proc essCode = | |||||
| 243 | new Option SetValue(( int)PickLi stMappingP rocessCode .Process) | |||||
| 244 | }; | |||||
| 245 | ||||||
| 246 | // Creat e the mapp ing | |||||
| 247 | Guid pic klistMappi ngId2 = _s erviceProx y.Create(p ickListMap ping2); | |||||
| 248 | #endregi on | |||||
| 249 | ||||||
| 250 | // Creat e Import | |||||
| 251 | Import i mport = ne w Import() | |||||
| 252 | { | |||||
| 253 | // I sImport is obsolete; use ModeC ode to dec lare Creat e or Updat e. | |||||
| 254 | Mode Code = new OptionSet Value((int )ImportMod eCode.Crea te), | |||||
| 255 | Name = "Import ing data" | |||||
| 256 | }; | |||||
| 257 | Guid imp ortId = _s erviceProx y.Create(i mport); | |||||
| 258 | ||||||
| 259 | // Creat e Import F ile. | |||||
| 260 | ImportFi le importF ile = new ImportFile () | |||||
| 261 | { | |||||
| 262 | Cont ent = Bulk ImportHelp er.ReadCsv File("Impo rt Account s.csv"), / / Read con tents from disk. | |||||
| 263 | Name = "Accoun t record i mport", | |||||
| 264 | IsFi rstRowHead er = true, | |||||
| 265 | Impo rtMapId = new Entity Reference( ImportMap. EntityLogi calName, i mportMapId ), | |||||
| 266 | UseS ystemMap = false, | |||||
| 267 | Sour ce = "Impo rt Account s.csv", | |||||
| 268 | Sour ceEntityNa me = "Acco unt_1", | |||||
| 269 | Targ etEntityNa me = Accou nt.EntityL ogicalName , | |||||
| 270 | Impo rtId = new EntityRef erence(Imp ort.Entity LogicalNam e, importI d), | |||||
| 271 | Enab leDuplicat eDetection = false, | |||||
| 272 | Fiel dDelimiter Code = | |||||
| 273 | new Option SetValue(( int)Import FileFieldD elimiterCo de.Comma), | |||||
| 274 | Data DelimiterC ode = | |||||
| 275 | new Option SetValue(( int)Import FileDataDe limiterCod e.DoubleQu ote), | |||||
| 276 | Proc essCode = | |||||
| 277 | new Option SetValue(( int)Import FileProces sCode.Proc ess) | |||||
| 278 | }; | |||||
| 279 | ||||||
| 280 | // Get t he current user to s et as reco rd owner. | |||||
| 281 | WhoAmIRe quest syst emUserRequ est = new WhoAmIRequ est(); | |||||
| 282 | WhoAmIRe sponse sys temUserRes ponse = | |||||
| 283 | (Who AmIRespons e)_service Proxy.Exec ute(system UserReques t); | |||||
| 284 | ||||||
| 285 | // Set t he owner I D. | |||||
| 286 | importFi le.Records OwnerId = | |||||
| 287 | new EntityRefe rence(Syst emUser.Ent ityLogical Name, syst emUserResp onse.UserI d); | |||||
| 288 | ||||||
| 289 | Guid imp ortFileId = _service Proxy.Crea te(importF ile); | |||||
| 290 | ||||||
| 291 | //<snipp etImportWi thCreate1> | |||||
| 292 | // Retri eve the he ader colum ns used in the impor t file. | |||||
| 293 | GetHeade rColumnsIm portFileRe quest head erColumnsR equest = n ew GetHead erColumnsI mportFileR equest() | |||||
| 294 | { | |||||
| 295 | Impo rtFileId = importFil eId | |||||
| 296 | }; | |||||
| 297 | GetHeade rColumnsIm portFileRe sponse hea derColumns Response = | |||||
| 298 | (Get HeaderColu mnsImportF ileRespons e)_service Proxy.Exec ute(header ColumnsReq uest); | |||||
| 299 | ||||||
| 300 | // Outpu t the head er columns . | |||||
| 301 | int colu mnNum = 1; | |||||
| 302 | foreach (string he aderName i n headerCo lumnsRespo nse.Column s) | |||||
| 303 | { | |||||
| 304 | Cons ole.WriteL ine("Colum n[" + colu mnNum.ToSt ring() + " ] = " + he aderName); | |||||
| 305 | colu mnNum++; | |||||
| 306 | } | |||||
| 307 | //</snip petImportW ithCreate1 > | |||||
| 308 | ||||||
| 309 | //<snipp etImportWi thCreate2> | |||||
| 310 | // Parse the impor t file. | |||||
| 311 | ParseImp ortRequest parseImpo rtRequest = new Pars eImportReq uest() | |||||
| 312 | { | |||||
| 313 | Impo rtId = imp ortId | |||||
| 314 | }; | |||||
| 315 | ParseImp ortRespons e parseImp ortRespons e = | |||||
| 316 | (Par seImportRe sponse)_se rviceProxy .Execute(p arseImport Request); | |||||
| 317 | Console. WriteLine( "Waiting f or Parse a sync job t o complete "); | |||||
| 318 | //</snip petImportW ithCreate2 > | |||||
| 319 | BulkImpo rtHelper.W aitForAsyn cJobComple tion(_serv iceProxy, parseImpor tResponse. AsyncOpera tionId); | |||||
| 320 | BulkImpo rtHelper.R eportError s(_service Proxy, imp ortFileId) ; | |||||
| 321 | ||||||
| 322 | //<snipp etImportWi thCreate3> | |||||
| 323 | // Retri eve the fi rst two di stinct val ues for co lumn 1 fro m the pars e table. | |||||
| 324 | // NOTE: You must create the parse tab le first u sing the P arseImport message. | |||||
| 325 | // The p arse table is not ac cessible a fter Impor tRecordsIm portRespon se is call ed. | |||||
| 326 | GetDisti nctValuesI mportFileR equest dis tinctValue sRequest = new GetDi stinctValu esImportFi leRequest( ) | |||||
| 327 | { | |||||
| 328 | colu mnNumber = 1, | |||||
| 329 | Impo rtFileId = importFil eId, | |||||
| 330 | page Number = 1 , | |||||
| 331 | reco rdsPerPage = 2, | |||||
| 332 | }; | |||||
| 333 | GetDisti nctValuesI mportFileR esponse di stinctValu esResponse = | |||||
| 334 | (Get DistinctVa luesImport FileRespon se)_servic eProxy.Exe cute(disti nctValuesR equest); | |||||
| 335 | ||||||
| 336 | // Outpu t the dist inct value s. In thi s case: (c olumn 1, r ow 1) and (column 1, row 2). | |||||
| 337 | int cell Num = 1; | |||||
| 338 | foreach (string ce llValue in distinctV aluesRespo nse.Values ) | |||||
| 339 | { | |||||
| 340 | Cons ole.WriteL ine("(1, " + cellNum .ToString( ) + "): " + cellValu e); | |||||
| 341 | Cons ole.WriteL ine(cellVa lue); | |||||
| 342 | cell Num++; | |||||
| 343 | } | |||||
| 344 | //</snip petImportW ithCreate3 > | |||||
| 345 | ||||||
| 346 | //<snipp etImportWi thCreate4> | |||||
| 347 | // Retri eve data f rom the pa rse table. | |||||
| 348 | // NOTE: You must create the parse tab le first u sing the P arseImport message. | |||||
| 349 | // The p arse table is not ac cessible a fter Impor tRecordsIm portRespon se is call ed. | |||||
| 350 | Retrieve ParsedData ImportFile Request pa rsedDataRe quest = ne w Retrieve ParsedData ImportFile Request() | |||||
| 351 | { | |||||
| 352 | Impo rtFileId = importFil eId, | |||||
| 353 | Pagi ngInfo = n ew PagingI nfo() | |||||
| 354 | { | |||||
| 355 | // Specify the numbe r of entit y instance s returned per page. | |||||
| 356 | Count = 2, | |||||
| 357 | // Specify the numbe r of pages returned from the q uery. | |||||
| 358 | PageNumber = 1, | |||||
| 359 | // Specify a total n umber of e ntity inst ances retu rned. | |||||
| 360 | PagingCook ie = "1" | |||||
| 361 | } | |||||
| 362 | }; | |||||
| 363 | ||||||
| 364 | Retrieve ParsedData ImportFile Response p arsedDataR esponse = | |||||
| 365 | (Ret rieveParse dDataImpor tFileRespo nse)_servi ceProxy.Ex ecute(pars edDataRequ est); | |||||
| 366 | ||||||
| 367 | // Outpu t the firs t two rows retrieved . | |||||
| 368 | int rowC ount = 1; | |||||
| 369 | foreach (string[] rows in pa rsedDataRe sponse.Val ues) | |||||
| 370 | { | |||||
| 371 | int colCount = 1; | |||||
| 372 | fore ach (strin g column i n rows) | |||||
| 373 | { | |||||
| 374 | Console.Wr iteLine("( " + rowCou nt.ToStrin g() + "," + colCount .ToString( ) + ") = " + column) ; | |||||
| 375 | colCount++ ; | |||||
| 376 | } | |||||
| 377 | rowC ount++; | |||||
| 378 | } | |||||
| 379 | //</snip petImportW ithCreate4 > | |||||
| 380 | ||||||
| 381 | //<snipp etImportWi thCreate5> | |||||
| 382 | // Trans form the i mport | |||||
| 383 | Transfor mImportReq uest trans formImport Request = new Transf ormImportR equest() | |||||
| 384 | { | |||||
| 385 | Impo rtId = imp ortId | |||||
| 386 | }; | |||||
| 387 | Transfor mImportRes ponse tran sformImpor tResponse = | |||||
| 388 | (Tra nsformImpo rtResponse )_serviceP roxy.Execu te(transfo rmImportRe quest); | |||||
| 389 | Console. WriteLine( "Waiting f or Transfo rm async j ob to comp lete"); | |||||
| 390 | //</snip petImportW ithCreate5 > | |||||
| 391 | BulkImpo rtHelper.W aitForAsyn cJobComple tion(_serv iceProxy, transformI mportRespo nse.AsyncO perationId ); | |||||
| 392 | BulkImpo rtHelper.R eportError s(_service Proxy, imp ortFileId) ; | |||||
| 393 | ||||||
| 394 | //<snipp etImportWi thCreate6> | |||||
| 395 | // Uploa d the reco rds. | |||||
| 396 | ImportRe cordsImpor tRequest i mportReque st = new I mportRecor dsImportRe quest() | |||||
| 397 | { | |||||
| 398 | Impo rtId = imp ortId | |||||
| 399 | }; | |||||
| 400 | ImportRe cordsImpor tResponse importResp onse = | |||||
| 401 | (Imp ortRecords ImportResp onse)_serv iceProxy.E xecute(imp ortRequest ); | |||||
| 402 | Console. WriteLine( "Waiting f or ImportR ecords asy nc job to complete") ; | |||||
| 403 | //</snip petImportW ithCreate6 > | |||||
| 404 | BulkImpo rtHelper.W aitForAsyn cJobComple tion(_serv iceProxy, importResp onse.Async OperationI d); | |||||
| 405 | BulkImpo rtHelper.R eportError s(_service Proxy, imp ortFileId) ; | |||||
| 406 | } | |||||
| 407 | ||||||
| 408 | // / <summary > | |||||
| 409 | // / Deletes any entity records t hat were c reated for this samp le. | |||||
| 410 | // / <param n ame="promp t">Indicat es whether to prompt the user | |||||
| 411 | // / to delet e the reco rds create d in this sample.</p aram> | |||||
| 412 | // / </summar y> | |||||
| 413 | pu blic void DeleteRequ iredRecord s(bool pro mpt) | |||||
| 414 | { | |||||
| 415 | bool toB eDeleted = true; | |||||
| 416 | ||||||
| 417 | if (prom pt) | |||||
| 418 | { | |||||
| 419 | // A sk the use r if the c reated ent ities shou ld be dele ted. | |||||
| 420 | Cons ole.Write( "\nDo you want these entity re cords dele ted? (y/n) [y]: "); | |||||
| 421 | Stri ng answer = Console. ReadLine() ; | |||||
| 422 | if ( answer.Sta rtsWith("y ") || | |||||
| 423 | answer.Sta rtsWith("Y ") || | |||||
| 424 | answer == String.Emp ty) | |||||
| 425 | { | |||||
| 426 | toBeDelete d = true; | |||||
| 427 | } | |||||
| 428 | else | |||||
| 429 | { | |||||
| 430 | toBeDelete d = false; | |||||
| 431 | } | |||||
| 432 | } | |||||
| 433 | ||||||
| 434 | if (toBe Deleted) | |||||
| 435 | { | |||||
| 436 | // R etrieve al l account records cr eated in t his sample . | |||||
| 437 | Quer yExpressio n query = new QueryE xpression( ) | |||||
| 438 | { | |||||
| 439 | EntityName = Account .EntityLog icalName, | |||||
| 440 | Criteria = new Filte rExpressio n() | |||||
| 441 | { | |||||
| 442 | Condit ions = | |||||
| 443 | { | |||||
| 444 | ne w Conditio nExpressio n("created on", Condi tionOperat or.OnOrAft er, _execu tionDate), | |||||
| 445 | } | |||||
| 446 | }, | |||||
| 447 | ColumnSet = new Colu mnSet(fals e) | |||||
| 448 | }; | |||||
| 449 | var accountsCr eated = _s erviceProx y.Retrieve Multiple(q uery).Enti ties; | |||||
| 450 | ||||||
| 451 | // D elete all records cr eated in t his sample . | |||||
| 452 | fore ach (var a ccount in accountsCr eated) | |||||
| 453 | { | |||||
| 454 | _servicePr oxy.Delete (Account.E ntityLogic alName, ac count.Id); | |||||
| 455 | } | |||||
| 456 | ||||||
| 457 | Cons ole.WriteL ine("Entit y record(s ) have bee n deleted. "); | |||||
| 458 | } | |||||
| 459 | } | |||||
| 460 | #r egion Main method | |||||
| 461 | ||||||
| 462 | // / <summary > | |||||
| 463 | // / Standard Main() me thod used by most SD K samples. | |||||
| 464 | // / </summar y> | |||||
| 465 | // / <param n ame="args" ></param> | |||||
| 466 | st atic publi c void Mai n(string[] args) | |||||
| 467 | { | |||||
| 468 | try | |||||
| 469 | { | |||||
| 470 | // O btain the target org anization' s web addr ess and cl ient logon | |||||
| 471 | // c redentials from the user. | |||||
| 472 | Serv erConnecti on serverC onnect = n ew ServerC onnection( ); | |||||
| 473 | Serv erConnecti on.Configu ration con fig = serv erConnect. GetServerC onfigurati on(); | |||||
| 474 | ||||||
| 475 | var app = new ImportWith Create(); | |||||
| 476 | app. Run(config , true); | |||||
| 477 | } | |||||
| 478 | ||||||
| 479 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault> ex ) | |||||
| 480 | { | |||||
| 481 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 482 | Cons ole.WriteL ine("Times tamp: {0}" , ex.Detai l.Timestam p); | |||||
| 483 | Cons ole.WriteL ine("Code: {0}", ex. Detail.Err orCode); | |||||
| 484 | Cons ole.WriteL ine("Messa ge: {0}", ex.Detail. Message); | |||||
| 485 | Cons ole.WriteL ine("Trace : {0}", ex .Detail.Tr aceText); | |||||
| 486 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 487 | null == ex .Detail.In nerFault ? "No Inner Fault" : "Has Inner Fault"); | |||||
| 488 | } | |||||
| 489 | catch (S ystem.Time outExcepti on ex) | |||||
| 490 | { | |||||
| 491 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 492 | Cons ole.WriteL ine("Messa ge: {0}", ex.Message ); | |||||
| 493 | Cons ole.WriteL ine("Stack Trace: {0 }", ex.Sta ckTrace); | |||||
| 494 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 495 | null == ex .InnerExce ption.Mess age ? "No Inner Faul t" : ex.In nerExcepti on.Message ); | |||||
| 496 | } | |||||
| 497 | catch (S ystem.Exce ption ex) | |||||
| 498 | { | |||||
| 499 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 500 | Cons ole.WriteL ine(ex.Mes sage); | |||||
| 501 | ||||||
| 502 | // D isplay the details o f the inne r exceptio n. | |||||
| 503 | if ( ex.InnerEx ception != null) | |||||
| 504 | { | |||||
| 505 | Console.Wr iteLine(ex .InnerExce ption.Mess age); | |||||
| 506 | ||||||
| 507 | FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault> f e = ex.Inn erExceptio n | |||||
| 508 | as Fau ltExceptio n<Microsof t.Xrm.Sdk. Organizati onServiceF ault>; | |||||
| 509 | if (fe != null) | |||||
| 510 | { | |||||
| 511 | Consol e.WriteLin e("Timesta mp: {0}", fe.Detail. Timestamp) ; | |||||
| 512 | Consol e.WriteLin e("Code: { 0}", fe.De tail.Error Code); | |||||
| 513 | Consol e.WriteLin e("Message : {0}", fe .Detail.Me ssage); | |||||
| 514 | Consol e.WriteLin e("Trace: {0}", fe.D etail.Trac eText); | |||||
| 515 | Consol e.WriteLin e("Inner F ault: {0}" , | |||||
| 516 | nu ll == fe.D etail.Inne rFault ? " No Inner F ault" : "H as Inner F ault"); | |||||
| 517 | } | |||||
| 518 | } | |||||
| 519 | } | |||||
| 520 | // Addit ional exce ptions to catch: Sec urityToken Validation Exception, ExpiredSe curityToke nException , | |||||
| 521 | // Secur ityAccessD eniedExcep tion, Mess ageSecurit yException , and Secu rityNegoti ationExcep tion. | |||||
| 522 | ||||||
| 523 | finally | |||||
| 524 | { | |||||
| 525 | Cons ole.WriteL ine("Press <Enter> t o exit."); | |||||
| 526 | Cons ole.ReadLi ne(); | |||||
| 527 | } | |||||
| 528 | } | |||||
| 529 | #e ndregion M ain method | |||||
| 530 | } | |||||
| 531 | } | |||||
| 532 | //</snippe tImportWit hCreate> |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.