Produced by Araxis Merge on 2/1/2017 2:56:47 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\Metadata\MetadataQuery | RetrieveParentalRelationships.cs | Tue Dec 20 19:51:47 2016 UTC |
| 2 | Wed Feb 1 19:56:47 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 0 | 0 |
| Changed | 0 | 0 |
| Inserted | 0 | 0 |
| Removed | 1 | 254 |
| 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 | //<snippet RetrievePa rentalRela tionships> | |||||
| 16 | using Syst em; | |||||
| 17 | using Syst em.Service Model; | |||||
| 18 | using Syst em.Service Model.Desc ription; | |||||
| 19 | using Syst em.IO; | |||||
| 20 | using Syst em.Collect ions.Gener ic; | |||||
| 21 | // These n amespaces are found in the Mic rosoft.Xrm .Sdk.dll a ssembly | |||||
| 22 | // located in the SD K\bin fold er of the SDK downlo ad. | |||||
| 23 | using Micr osoft.Xrm. Sdk; | |||||
| 24 | using Micr osoft.Xrm. Sdk.Query; | |||||
| 25 | using Micr osoft.Xrm. Sdk.Client ; | |||||
| 26 | using Micr osoft.Crm. Sdk.Messag es; | |||||
| 27 | using Micr osoft.Xrm. Sdk.Messag es; | |||||
| 28 | using Micr osoft.Xrm. Sdk.Metada ta; | |||||
| 29 | using Micr osoft.Xrm. Sdk.Metada ta.Query; | |||||
| 30 | ||||||
| 31 | ||||||
| 32 | namespace Microsoft. Crm.Sdk.Sa mples | |||||
| 33 | { | |||||
| 34 | public cl ass Retrie veParental Relationsh ips | |||||
| 35 | { | |||||
| 36 | #region Class Leve l Members | |||||
| 37 | ||||||
| 38 | private Organizati onServiceP roxy _serv iceProxy; | |||||
| 39 | private IOrganizat ionService _service; | |||||
| 40 | private Guid _user Id; | |||||
| 41 | private int _langu ageCode; | |||||
| 42 | ||||||
| 43 | ||||||
| 44 | ||||||
| 45 | #endregi on Class L evel Membe rs | |||||
| 46 | ||||||
| 47 | ||||||
| 48 | /// <sum mary> | |||||
| 49 | /// This method co nnects to the Organi zation _se rvice. | |||||
| 50 | /// </su mmary> | |||||
| 51 | /// <par am name="s erverConfi g">Contain s server c onnection informatio n.</param> | |||||
| 52 | ||||||
| 53 | public v oid Run(Se rverConnec tion.Confi guration s erverConfi g) | |||||
| 54 | { | |||||
| 55 | try | |||||
| 56 | { | |||||
| 57 | ||||||
| 58 | // Con nect to th e Organiza tion _serv ice. | |||||
| 59 | // The using sta tement ass ures that the _servi ce proxy w ill be pro perly disp osed. | |||||
| 60 | usi ng (_servi ceProxy = new Organi zationServ iceProxy(s erverConfi g.Organiza tionUri, s erverConfi g.HomeReal mUri, serv erConfig.C redentials , serverCo nfig.Devic eCredentia ls)) | |||||
| 61 | { | |||||
| 62 | // Th is stateme nt is requ ired to en able early -bound typ e support. | |||||
| 63 | _serv iceProxy.E nableProxy Types(); | |||||
| 64 | ||||||
| 65 | _serv ice = (IOr ganization Service)_s erviceProx y; | |||||
| 66 | ||||||
| 67 | _user Id = ((Who AmIRespons e)_service .Execute(n ew WhoAmIR equest())) .UserId; | |||||
| 68 | _lang uageCode = RetrieveU serUILangu ageCode(_u serId); | |||||
| 69 | ||||||
| 70 | ||||||
| 71 | ||||||
| 72 | //A f ilter expr ession to limit enti ties retur ned to non -intersect entities | |||||
| 73 | Metad ataFilterE xpression EntityFilt er = new M etadataFil terExpress ion(Logica lOperator. And); | |||||
| 74 | Entit yFilter.Co nditions.A dd(new Met adataCondi tionExpres sion("IsIn tersect", MetadataCo nditionOpe rator.Equa ls, false) ); | |||||
| 75 | ||||||
| 76 | ||||||
| 77 | //A p roperties expression to limit the proper ties to be included with entit ies | |||||
| 78 | Metad ataPropert iesExpress ion Entity Properties = new Met adataPrope rtiesExpre ssion() | |||||
| 79 | { | |||||
| 80 | AllP roperties = false | |||||
| 81 | }; | |||||
| 82 | Entit yPropertie s.Property Names.AddR ange(new s tring[] { "OneToMany Relationsh ips", "Log icalName", "DisplayN ame" }); | |||||
| 83 | ||||||
| 84 | ||||||
| 85 | ||||||
| 86 | ||||||
| 87 | //A f ilter expr ession to only retur n system e ntity rela tionships | |||||
| 88 | Metad ataFilterE xpression relationsh ipFilter = new Metad ataFilterE xpression( LogicalOpe rator.And) ; | |||||
| 89 | relat ionshipFil ter.Condit ions.Add(n ew Metadat aCondition Expression ("IsCustom Relationsh ip", Metad ataConditi onOperator .Equals, f alse)); | |||||
| 90 | ||||||
| 91 | //A P roperties expression to limit the proper ties to be included with relat ionships | |||||
| 92 | Metad ataPropert iesExpress ion relati onshipProp erties = n ew Metadat aPropertie sExpressio n() { AllP roperties = false }; | |||||
| 93 | relat ionshipPro perties.Pr opertyName s.Add("Cas cadeConfig uration"); | |||||
| 94 | relat ionshipPro perties.Pr opertyName s.Add("Sch emaName"); | |||||
| 95 | relat ionshipPro perties.Pr opertyName s.Add("IsC ustomizabl e"); | |||||
| 96 | ||||||
| 97 | ||||||
| 98 | //A l abel query expressio n to limit the label s returned to only t hose for t he user's preferred language | |||||
| 99 | Label QueryExpre ssion labe lQuery = n ew LabelQu eryExpress ion(); | |||||
| 100 | label Query.Filt erLanguage s.Add(_lan guageCode) ; | |||||
| 101 | ||||||
| 102 | ||||||
| 103 | //An entity que ry express ion to com bine the f ilter expr essions an d property expressio ns for the query. | |||||
| 104 | Entit yQueryExpr ession ent ityQueryEx pression = new Entit yQueryExpr ession() | |||||
| 105 | { | |||||
| 106 | ||||||
| 107 | Crit eria = Ent ityFilter, | |||||
| 108 | Prop erties = E ntityPrope rties, | |||||
| 109 | Rela tionshipQu ery = new Relationsh ipQueryExp ression() { Criteria = relatio nshipFilte r, Propert ies = rela tionshipPr operties } , | |||||
| 110 | Labe lQuery = l abelQuery | |||||
| 111 | ||||||
| 112 | }; | |||||
| 113 | ||||||
| 114 | //Def ine the re quest | |||||
| 115 | Retri eveMetadat aChangesRe quest requ est = new RetrieveMe tadataChan gesRequest () { Query = entityQ ueryExpres sion }; | |||||
| 116 | ||||||
| 117 | //Ret rieve the data | |||||
| 118 | Retri eveMetadat aChangesRe sponse res ponse = (R etrieveMet adataChang esResponse )_service. Execute(re quest); | |||||
| 119 | ||||||
| 120 | ||||||
| 121 | //Pro cess the d ata | |||||
| 122 | forea ch (Entity Metadata e ntity in r esponse.En tityMetada ta) | |||||
| 123 | { | |||||
| 124 | if ( entity.One ToManyRela tionships != null) | |||||
| 125 | { | |||||
| 126 | for each (OneT oManyRelat ionshipMet adata rela tionship i n entity.O neToManyRe lationship s) | |||||
| 127 | { | |||||
| 128 | va r cascadeC onfig = re lationship .CascadeCo nfiguratio n; | |||||
| 129 | // When all o f the Casc adeConfigu ration pro perties us e the Casc ade behavi or the rel ationship is conside red parent al | |||||
| 130 | if (cascadeC onfig.Assi gn == Casc adeType.Ca scade && | |||||
| 131 | c ascadeConf ig.Delete == Cascade Type.Casca de && | |||||
| 132 | c ascadeConf ig.Merge = = CascadeT ype.Cascad e && | |||||
| 133 | c ascadeConf ig.Reparen t == Casca deType.Cas cade && | |||||
| 134 | c ascadeConf ig.Share = = CascadeT ype.Cascad e && | |||||
| 135 | c ascadeConf ig.Unshare == Cascad eType.Casc ade) | |||||
| 136 | { | |||||
| 137 | / /Only show results f or relatio nships tha t can be c ustomized | |||||
| 138 | i f (relatio nship.IsCu stomizable .Value) | |||||
| 139 | { | |||||
| 140 | //Write th e entity n ame and th e name of the relati onship. | |||||
| 141 | Console.Wr iteLine(en tity.Displ ayName.Use rLocalized Label.Labe l + "," + relationsh ip.SchemaN ame); | |||||
| 142 | } | |||||
| 143 | } | |||||
| 144 | } | |||||
| 145 | } | |||||
| 146 | } | |||||
| 147 | } | |||||
| 148 | } | |||||
| 149 | ||||||
| 150 | // Catc h any _ser vice fault exception s that Mic rosoft Dyn amics CRM throws. | |||||
| 151 | catch ( FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault>) | |||||
| 152 | { | |||||
| 153 | // You can handl e an excep tion here or pass it back to t he calling method. | |||||
| 154 | throw; | |||||
| 155 | } | |||||
| 156 | } | |||||
| 157 | ||||||
| 158 | ||||||
| 159 | protecte d int Retr ieveUserUI LanguageCo de(Guid us erId) | |||||
| 160 | { | |||||
| 161 | QueryEx pression u serSetting sQuery = n ew QueryEx pression(" usersettin gs"); | |||||
| 162 | userSet tingsQuery .ColumnSet .AddColumn s("uilangu ageid", "s ystemuseri d"); | |||||
| 163 | userSet tingsQuery .Criteria. AddConditi on("system userid", C onditionOp erator.Equ al, userId ); | |||||
| 164 | EntityC ollection userSettin gs = _serv ice.Retrie veMultiple (userSetti ngsQuery); | |||||
| 165 | if (use rSettings. Entities.C ount > 0) | |||||
| 166 | { | |||||
| 167 | return (int)user Settings.E ntities[0] ["uilangua geid"]; | |||||
| 168 | } | |||||
| 169 | return 0; | |||||
| 170 | } | |||||
| 171 | ||||||
| 172 | ||||||
| 173 | ||||||
| 174 | ||||||
| 175 | #region Main metho d | |||||
| 176 | ||||||
| 177 | /// <sum mary> | |||||
| 178 | /// Base d on the M ain() meth od used by most SDK samples. | |||||
| 179 | /// </su mmary> | |||||
| 180 | /// <par am name="a rgs"></par am> | |||||
| 181 | static p ublic void Main(stri ng[] args) | |||||
| 182 | { | |||||
| 183 | try | |||||
| 184 | { | |||||
| 185 | // Obt ain the ta rget organ ization's Web addres s and clie nt logon | |||||
| 186 | // cre dentials f rom the us er. | |||||
| 187 | Server Connection serverCon nect = new ServerCon nection(); | |||||
| 188 | Server Connection .Configura tion confi g = server Connect.Ge tServerCon figuration (); | |||||
| 189 | ||||||
| 190 | Retrie veParental Relationsh ips app = new Retrie veParental Relationsh ips(); | |||||
| 191 | app.Ru n(config); | |||||
| 192 | } | |||||
| 193 | ||||||
| 194 | catch ( FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault> e x) | |||||
| 195 | { | |||||
| 196 | Consol e.WriteLin e("The app lication t erminated with an er ror."); | |||||
| 197 | Consol e.WriteLin e("Timesta mp: {0}", ex.Detail. Timestamp) ; | |||||
| 198 | Consol e.WriteLin e("Code: { 0}", ex.De tail.Error Code); | |||||
| 199 | Consol e.WriteLin e("Message : {0}", ex .Detail.Me ssage); | |||||
| 200 | Consol e.WriteLin e("Trace: {0}", ex.D etail.Trac eText); | |||||
| 201 | Consol e.WriteLin e("Inner F ault: {0}" , | |||||
| 202 | nu ll == ex.D etail.Inne rFault ? " Has Inner Fault" : " No Inner F ault"); | |||||
| 203 | } | |||||
| 204 | catch ( System.Tim eoutExcept ion ex) | |||||
| 205 | { | |||||
| 206 | Consol e.WriteLin e("The app lication t erminated with an er ror."); | |||||
| 207 | Consol e.WriteLin e("Message : {0}", ex .Message); | |||||
| 208 | Consol e.WriteLin e("Stack T race: {0}" , ex.Stack Trace); | |||||
| 209 | Consol e.WriteLin e("Inner F ault: {0}" , | |||||
| 210 | nu ll == ex.I nnerExcept ion.Messag e ? "Has I nner Fault " : "No In ner Fault" ); | |||||
| 211 | } | |||||
| 212 | catch ( System.Exc eption ex) | |||||
| 213 | { | |||||
| 214 | Consol e.WriteLin e("The app lication t erminated with an er ror."); | |||||
| 215 | Consol e.WriteLin e(ex.Messa ge); | |||||
| 216 | ||||||
| 217 | // Dis play the d etails of the inner exception. | |||||
| 218 | if (ex .InnerExce ption != n ull) | |||||
| 219 | { | |||||
| 220 | Conso le.WriteLi ne(ex.Inne rException .Message); | |||||
| 221 | ||||||
| 222 | Fault Exception< Microsoft. Xrm.Sdk.Or ganization ServiceFau lt> fe = e x.InnerExc eption | |||||
| 223 | a s FaultExc eption<Mic rosoft.Xrm .Sdk.Organ izationSer viceFault> ; | |||||
| 224 | if (f e != null) | |||||
| 225 | { | |||||
| 226 | Cons ole.WriteL ine("Times tamp: {0}" , fe.Detai l.Timestam p); | |||||
| 227 | Cons ole.WriteL ine("Code: {0}", fe. Detail.Err orCode); | |||||
| 228 | Cons ole.WriteL ine("Messa ge: {0}", fe.Detail. Message); | |||||
| 229 | Cons ole.WriteL ine("Trace : {0}", fe .Detail.Tr aceText); | |||||
| 230 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 231 | null == fe .Detail.In nerFault ? "Has Inne r Fault" : "No Inner Fault"); | |||||
| 232 | } | |||||
| 233 | } | |||||
| 234 | } | |||||
| 235 | ||||||
| 236 | //Addi tional exc eptions to catch: Se curityToke nValidatio nException , ExpiredS ecurityTok enExceptio n, | |||||
| 237 | //Secur ityAccessD eniedExcep tion, Mess ageSecurit yException , and Secu rityNegoti ationExcep tion. | |||||
| 238 | ||||||
| 239 | finally | |||||
| 240 | { | |||||
| 241 | Consol e.WriteLin e("Press < Enter> to exit."); | |||||
| 242 | Consol e.ReadLine (); | |||||
| 243 | } | |||||
| 244 | } | |||||
| 245 | #endregi on Main me thod | |||||
| 246 | ||||||
| 247 | } | |||||
| 248 | ||||||
| 249 | ||||||
| 250 | ||||||
| 251 | ||||||
| 252 | } | |||||
| 253 | //</snippe tRetrieveP arentalRel ationships > | |||||
| 254 |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.