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 | UsingExportAndImportMappings.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 | 330 |
| 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 UsingExpor tAndImport Mappings> | |||||
| 17 | using Syst em; | |||||
| 18 | using Syst em.Service Model; | |||||
| 19 | using Syst em.Xml.Lin q; | |||||
| 20 | using Micr osoft.Crm. Sdk.Messag es; | |||||
| 21 | using Micr osoft.Xrm. Sdk; | |||||
| 22 | using Micr osoft.Xrm. Sdk.Client ; | |||||
| 23 | ||||||
| 24 | namespace Microsoft. Crm.Sdk.Sa mples | |||||
| 25 | { | |||||
| 26 | /// <s ummary> | |||||
| 27 | /// Th is sample shows how to define an import mapping, e xport the import map ping | |||||
| 28 | /// re cord and r e-import a modified import map ping. | |||||
| 29 | /// </ summary> | |||||
| 30 | /// <r emarks> | |||||
| 31 | /// At run-time, you will be given t he option to delete all the | |||||
| 32 | /// da tabase rec ords creat ed by this program. | |||||
| 33 | /// </ remarks> | |||||
| 34 | public class Usi ngExportAn dImportMap pings | |||||
| 35 | { | |||||
| 36 | #r egion Clas s Level Me mbers | |||||
| 37 | pr ivate Orga nizationSe rviceProxy _serviceP roxy; | |||||
| 38 | pr ivate Guid ? _importM apId; | |||||
| 39 | pr ivate Stri ng _mappin gXml; | |||||
| 40 | pr ivate Guid ? _newImpo rtMapId; | |||||
| 41 | #e ndregion | |||||
| 42 | ||||||
| 43 | #r egion How To Sample Code | |||||
| 44 | ||||||
| 45 | // / <summary > | |||||
| 46 | // / Creates an import mapping, r etrieves t he xml, mo difies the name, | |||||
| 47 | // / and re-i mports the import ma ppings | |||||
| 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, | |||||
| 53 | bool prom ptforDelet e) | |||||
| 54 | { | |||||
| 55 | 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)) | |||||
| 56 | { | |||||
| 57 | // T his statem ent is req uired to e nable earl y-bound ty pe support . | |||||
| 58 | _ser viceProxy. EnableProx yTypes(); | |||||
| 59 | ||||||
| 60 | Crea teImportMa pping(); | |||||
| 61 | Retr ieveMappin gXml(); | |||||
| 62 | Chan geMappingN ame(); | |||||
| 63 | Impo rtMappings ByXml(); | |||||
| 64 | ||||||
| 65 | Dele teRequired Records(pr omptforDel ete); | |||||
| 66 | } | |||||
| 67 | } | |||||
| 68 | ||||||
| 69 | // / <summary > | |||||
| 70 | // / Creates the import mapping r ecord. | |||||
| 71 | // / </summar y> | |||||
| 72 | pr ivate void CreateImp ortMapping () | |||||
| 73 | { | |||||
| 74 | // Creat e the impo rt map and populate a column | |||||
| 75 | ImportMa p importMa p = new Im portMap() | |||||
| 76 | { | |||||
| 77 | Name = "Origin al Import Mapping" + DateTime .Now.Ticks .ToString( ), | |||||
| 78 | Sour ce = "Impo rt Account s.csv", | |||||
| 79 | Desc ription = "Descripti on of data being imp orted", | |||||
| 80 | Enti tiesPerFil e = | |||||
| 81 | new Option SetValue(( int)Import MapEntitie sPerFile.S ingleEntit yPerFile), | |||||
| 82 | Enti tyState = EntityStat e.Created | |||||
| 83 | }; | |||||
| 84 | ||||||
| 85 | _importM apId = _se rviceProxy .Create(im portMap); | |||||
| 86 | ||||||
| 87 | Console. WriteLine( String.Con cat("Impor t map crea ted: ", _i mportMapId .Value)); | |||||
| 88 | ||||||
| 89 | #region Column One Mappings | |||||
| 90 | // Creat e a column mapping f or a 'text ' type fie ld | |||||
| 91 | ColumnMa pping colM apping1 = new Column Mapping() | |||||
| 92 | { | |||||
| 93 | // S et source properties | |||||
| 94 | Sour ceAttribut eName = "n ame", | |||||
| 95 | Sour ceEntityNa me = "Acco unt_1", | |||||
| 96 | ||||||
| 97 | // S et target properties | |||||
| 98 | Targ etAttribut eName = "n ame", | |||||
| 99 | Targ etEntityNa me = Accou nt.EntityL ogicalName , | |||||
| 100 | ||||||
| 101 | // R elate this column ma pping with the data map | |||||
| 102 | Impo rtMapId = | |||||
| 103 | new Entity Reference( ImportMap. EntityLogi calName, _ importMapI d.Value), | |||||
| 104 | ||||||
| 105 | // F orce this column to be process ed | |||||
| 106 | Proc essCode = | |||||
| 107 | new Option SetValue(( int)Column MappingPro cessCode.P rocess) | |||||
| 108 | }; | |||||
| 109 | ||||||
| 110 | // Creat e the mapp ing | |||||
| 111 | Guid col MappingId1 = _servic eProxy.Cre ate(colMap ping1); | |||||
| 112 | ||||||
| 113 | Console. WriteLine( String.Con cat("Colum n mapping added Sour ceAttribut eName: nam e", | |||||
| 114 | ", T argetAttri buteName: name, Targ etEntityNa me: accoun t")); | |||||
| 115 | #endregi on | |||||
| 116 | } | |||||
| 117 | ||||||
| 118 | // / <summary > | |||||
| 119 | // / Export t he mapping that we c reated | |||||
| 120 | // / </summar y> | |||||
| 121 | pr ivate void RetrieveM appingXml( ) | |||||
| 122 | { | |||||
| 123 | if (!_im portMapId. HasValue) | |||||
| 124 | retu rn; | |||||
| 125 | ||||||
| 126 | // Retri eve the xm l for the mapping | |||||
| 127 | var expo rtRequest = new Expo rtMappings ImportMapR equest | |||||
| 128 | { | |||||
| 129 | Impo rtMapId = _importMap Id.Value, | |||||
| 130 | Expo rtIds = tr ue, | |||||
| 131 | }; | |||||
| 132 | ||||||
| 133 | var expo rtResponse = (Export MappingsIm portMapRes ponse)_ser viceProxy | |||||
| 134 | .Exe cute(expor tRequest); | |||||
| 135 | ||||||
| 136 | _mapping Xml = expo rtResponse .MappingsX ml; | |||||
| 137 | ||||||
| 138 | Console. WriteLine( String.Con cat("Impor t mapping exported f or ", | |||||
| 139 | _imp ortMapId.V alue, "\nM appingsXml :\n", _map pingXml)); | |||||
| 140 | } | |||||
| 141 | ||||||
| 142 | // / <summary > | |||||
| 143 | // / Parse th e XML to c hange the name attri bute | |||||
| 144 | // / </summar y> | |||||
| 145 | pr ivate void ChangeMap pingName() | |||||
| 146 | { | |||||
| 147 | if (stri ng.IsNullO rWhiteSpac e(_mapping Xml)) | |||||
| 148 | retu rn; | |||||
| 149 | ||||||
| 150 | // Load into XElem ent | |||||
| 151 | var xEle ment = XEl ement.Pars e(_mapping Xml); | |||||
| 152 | ||||||
| 153 | // Get t he Name at tribute | |||||
| 154 | var name Attribute = xElement .Attribute ("Name"); | |||||
| 155 | ||||||
| 156 | // Swap the name o ut | |||||
| 157 | if (name Attribute != null) | |||||
| 158 | { | |||||
| 159 | stri ng newName = "New Im port Mappi ng" + Date Time.Now.T icks.ToStr ing(); | |||||
| 160 | Cons ole.WriteL ine(String .Concat("\ nChanging the import name\n\tf rom: ", | |||||
| 161 | nameAttrib ute.Value, ",\n\tto: ", newNam e)); | |||||
| 162 | ||||||
| 163 | name Attribute. Value = ne wName; | |||||
| 164 | _map pingXml = xElement.T oString(); | |||||
| 165 | } | |||||
| 166 | } | |||||
| 167 | ||||||
| 168 | // / <summary > | |||||
| 169 | // / Create a mapping f rom Xml | |||||
| 170 | // / </summar y> | |||||
| 171 | pr ivate void ImportMap pingsByXml () | |||||
| 172 | { | |||||
| 173 | if (stri ng.IsNullO rWhiteSpac e(_mapping Xml)) | |||||
| 174 | retu rn; | |||||
| 175 | ||||||
| 176 | //<snipp etImportMa ppingsImpo rtMap> | |||||
| 177 | // Creat e the impo rt mapping from the XML | |||||
| 178 | var requ est = new ImportMapp ingsImport MapRequest | |||||
| 179 | { | |||||
| 180 | Mapp ingsXml = _mappingXm l, | |||||
| 181 | ||||||
| 182 | Repl aceIds = t rue, | |||||
| 183 | }; | |||||
| 184 | ||||||
| 185 | Console. WriteLine( String.Con cat("\nCre ating mapp ing based on XML:\n" , | |||||
| 186 | _map pingXml)); | |||||
| 187 | ||||||
| 188 | var resp onse = (Im portMappin gsImportMa pResponse) | |||||
| 189 | _ser viceProxy. Execute(re quest); | |||||
| 190 | ||||||
| 191 | _newImpo rtMapId = response.I mportMapId ; | |||||
| 192 | ||||||
| 193 | Console. WriteLine( String.Con cat("\nNew import ma pping crea ted: ", | |||||
| 194 | _new ImportMapI d.Value)); | |||||
| 195 | //</snip petImportM appingsImp ortMap> | |||||
| 196 | ||||||
| 197 | //<snipp etExportMa ppingsImpo rtMap> | |||||
| 198 | // Retri eve the va lue for va lidation | |||||
| 199 | var expo rtRequest = new Expo rtMappings ImportMapR equest | |||||
| 200 | { | |||||
| 201 | Impo rtMapId = _newImport MapId.Valu e, | |||||
| 202 | Expo rtIds = tr ue, | |||||
| 203 | }; | |||||
| 204 | ||||||
| 205 | var expo rtResponse = (Export MappingsIm portMapRes ponse)_ser viceProxy | |||||
| 206 | .Exe cute(expor tRequest); | |||||
| 207 | ||||||
| 208 | var mapp ingXml = e xportRespo nse.Mappin gsXml; | |||||
| 209 | ||||||
| 210 | Console. WriteLine( String.Con cat("\nVal idating ma pping xml for : ", | |||||
| 211 | _new ImportMapI d.Value, " ,\nMapping sXml:\n", mappingXml )); | |||||
| 212 | //</snip petExportM appingsImp ortMap> | |||||
| 213 | } | |||||
| 214 | ||||||
| 215 | // / <summary > | |||||
| 216 | // / Deletes the record s created by this sa mple | |||||
| 217 | // / </summar y> | |||||
| 218 | // / <param n ame="promp t"></param > | |||||
| 219 | pr ivate void DeleteReq uiredRecor ds(bool pr ompt) | |||||
| 220 | { | |||||
| 221 | bool toB eDeleted = true; | |||||
| 222 | ||||||
| 223 | if (prom pt) | |||||
| 224 | { | |||||
| 225 | // A sk the use r if the c reated ent ities shou ld be dele ted. | |||||
| 226 | Cons ole.Write( "\nDo you want these entity re cords dele ted? (y/n) [y]: "); | |||||
| 227 | Stri ng answer = Console. ReadLine() ; | |||||
| 228 | if ( answer.Sta rtsWith("y ") || | |||||
| 229 | answer.Sta rtsWith("Y ") || | |||||
| 230 | answer == String.Emp ty) | |||||
| 231 | { | |||||
| 232 | toBeDelete d = true; | |||||
| 233 | } | |||||
| 234 | else | |||||
| 235 | { | |||||
| 236 | toBeDelete d = false; | |||||
| 237 | } | |||||
| 238 | } | |||||
| 239 | ||||||
| 240 | if (toBe Deleted) | |||||
| 241 | { | |||||
| 242 | if ( _importMap Id.HasValu e) | |||||
| 243 | { | |||||
| 244 | Console.Wr iteLine(St ring.Conca t("Deletin g import m apping: ", _importMa pId.Value) ); | |||||
| 245 | _servicePr oxy.Delete (ImportMap .EntityLog icalName, _importMap Id.Value); | |||||
| 246 | } | |||||
| 247 | ||||||
| 248 | if ( _newImport MapId.HasV alue) | |||||
| 249 | { | |||||
| 250 | Console.Wr iteLine(St ring.Conca t("Deletin g import m apping: ", _newImpor tMapId.Val ue)); | |||||
| 251 | _servicePr oxy.Delete (ImportMap .EntityLog icalName, _newImport MapId.Valu e); | |||||
| 252 | } | |||||
| 253 | ||||||
| 254 | Cons ole.WriteL ine("Entit y records have been deleted.") ; | |||||
| 255 | } | |||||
| 256 | } | |||||
| 257 | ||||||
| 258 | #e ndregion | |||||
| 259 | ||||||
| 260 | #r egion Main method | |||||
| 261 | // / <summary > | |||||
| 262 | // / Standard Main() me thod used by most SD K samples. | |||||
| 263 | // / </summar y> | |||||
| 264 | // / <param n ame="args" ></param> | |||||
| 265 | st atic publi c void Mai n(string[] args) | |||||
| 266 | { | |||||
| 267 | try | |||||
| 268 | { | |||||
| 269 | // O btain the target org anization' s Web addr ess and cl ient logon | |||||
| 270 | // c redentials from the user. | |||||
| 271 | Serv erConnecti on serverC onnect = n ew ServerC onnection( ); | |||||
| 272 | Serv erConnecti on.Configu ration con fig = serv erConnect. GetServerC onfigurati on(); | |||||
| 273 | ||||||
| 274 | var app = new UsingExpor tAndImport Mappings() ; | |||||
| 275 | app. Run(config , true); | |||||
| 276 | } | |||||
| 277 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault> ex ) | |||||
| 278 | { | |||||
| 279 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 280 | Cons ole.WriteL ine("Times tamp: {0}" , ex.Detai l.Timestam p); | |||||
| 281 | Cons ole.WriteL ine("Code: {0}", ex. Detail.Err orCode); | |||||
| 282 | Cons ole.WriteL ine("Messa ge: {0}", ex.Detail. Message); | |||||
| 283 | Cons ole.WriteL ine("Plugi n Trace: { 0}", ex.De tail.Trace Text); | |||||
| 284 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 285 | null == ex .Detail.In nerFault ? "No Inner Fault" : "Has Inner Fault"); | |||||
| 286 | } | |||||
| 287 | catch (S ystem.Time outExcepti on ex) | |||||
| 288 | { | |||||
| 289 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 290 | Cons ole.WriteL ine("Messa ge: {0}", ex.Message ); | |||||
| 291 | Cons ole.WriteL ine("Stack Trace: {0 }", ex.Sta ckTrace); | |||||
| 292 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 293 | null == ex .InnerExce ption.Mess age ? "No Inner Faul t" : ex.In nerExcepti on.Message ); | |||||
| 294 | } | |||||
| 295 | catch (S ystem.Exce ption ex) | |||||
| 296 | { | |||||
| 297 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 298 | Cons ole.WriteL ine(ex.Mes sage); | |||||
| 299 | ||||||
| 300 | // D isplay the details o f the inne r exceptio n. | |||||
| 301 | if ( ex.InnerEx ception != null) | |||||
| 302 | { | |||||
| 303 | Console.Wr iteLine(ex .InnerExce ption.Mess age); | |||||
| 304 | ||||||
| 305 | FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault> f e = ex.Inn erExceptio n | |||||
| 306 | as Fau ltExceptio n<Microsof t.Xrm.Sdk. Organizati onServiceF ault>; | |||||
| 307 | if (fe != null) | |||||
| 308 | { | |||||
| 309 | Consol e.WriteLin e("Timesta mp: {0}", fe.Detail. Timestamp) ; | |||||
| 310 | Consol e.WriteLin e("Code: { 0}", fe.De tail.Error Code); | |||||
| 311 | Consol e.WriteLin e("Message : {0}", fe .Detail.Me ssage); | |||||
| 312 | Consol e.WriteLin e("Plugin Trace: {0} ", fe.Deta il.TraceTe xt); | |||||
| 313 | Consol e.WriteLin e("Inner F ault: {0}" , | |||||
| 314 | nu ll == fe.D etail.Inne rFault ? " No Inner F ault" : "H as Inner F ault"); | |||||
| 315 | } | |||||
| 316 | } | |||||
| 317 | } | |||||
| 318 | // Addit ional exce ptions to catch: Sec urityToken Validation Exception, ExpiredSe curityToke nException , | |||||
| 319 | // Secur ityAccessD eniedExcep tion, Mess ageSecurit yException , and Secu rityNegoti ationExcep tion. | |||||
| 320 | ||||||
| 321 | finally | |||||
| 322 | { | |||||
| 323 | Cons ole.WriteL ine("Press <Enter> t o exit."); | |||||
| 324 | Cons ole.ReadLi ne(); | |||||
| 325 | } | |||||
| 326 | } | |||||
| 327 | #e ndregion | |||||
| 328 | } | |||||
| 329 | } | |||||
| 330 | //</snippe tUsingExpo rtAndImpor tMappings> |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.