Produced by Araxis Merge on 2/1/2017 2:56:29 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\CrmSvcUtilExtensions\GeneratePicklistEnums | NamingService.cs | Tue Dec 20 19:51:44 2016 UTC |
| 2 | Wed Feb 1 19:56:29 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 0 | 0 |
| Changed | 0 | 0 |
| Inserted | 0 | 0 |
| Removed | 1 | 224 |
| 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 nline docu mentation. See thes e 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 NamingServ ice> | |||||
| 18 | using Syst em; | |||||
| 19 | using Syst em.Collect ions.Gener ic; | |||||
| 20 | using Syst em.Diagnos tics; | |||||
| 21 | using Syst em.Linq; | |||||
| 22 | using Syst em.Text.Re gularExpre ssions; | |||||
| 23 | using Micr osoft.Crm. Services.U tility; | |||||
| 24 | using Micr osoft.Xrm. Sdk; | |||||
| 25 | using Micr osoft.Xrm. Sdk.Metada ta; | |||||
| 26 | ||||||
| 27 | namespace Microsoft. Crm.Sdk.Sa mples | |||||
| 28 | { | |||||
| 29 | /// <s ummary> | |||||
| 30 | /// Im plement th is class i f you want to provid e your own logic for building names that | |||||
| 31 | /// wi ll appear in the gen erated cod e. | |||||
| 32 | /// </ summary> | |||||
| 33 | public sealed cl ass Naming Service : INamingSer vice | |||||
| 34 | { | |||||
| 35 | pr ivate INam ingService DefaultNa mingServic e { get; s et; } | |||||
| 36 | ||||||
| 37 | // / <summary > | |||||
| 38 | // / This fie ld keeps t rack of th e number o f times th at options with the same | |||||
| 39 | // / name wou ld have be en defined . | |||||
| 40 | // / </summar y> | |||||
| 41 | pr ivate Dict ionary<Opt ionSetMeta dataBase, Dictionary <String, i nt>> Optio nNames; | |||||
| 42 | ||||||
| 43 | pu blic Namin gService(I NamingServ ice naming Service) | |||||
| 44 | { | |||||
| 45 | DefaultN amingServi ce = namin gService; | |||||
| 46 | OptionNa mes = new Dictionary <OptionSet MetadataBa se, | |||||
| 47 | Dict ionary<Str ing, int>> (); | |||||
| 48 | } | |||||
| 49 | ||||||
| 50 | // / <summary > | |||||
| 51 | // / Provide a new impl ementation for findi ng a name for an Opt ionSet. If the | |||||
| 52 | // / OptionSe t is not g lobal, we want the n ame to be the concat enation of the Entit y's | |||||
| 53 | // / name and the Attri bute's nam e. Otherw ise, we ca n use the default im plementati on. | |||||
| 54 | // / </summar y> | |||||
| 55 | pu blic Strin g GetNameF orOptionSe t( | |||||
| 56 | EntityMe tadata ent ityMetadat a, OptionS etMetadata Base optio nSetMetada ta, | |||||
| 57 | IService Provider s ervices) | |||||
| 58 | { | |||||
| 59 | // Ensur e that the OptionSet is not gl obal befor e using th e custom | |||||
| 60 | // imple mentation. | |||||
| 61 | if (opti onSetMetad ata.IsGlob al.HasValu e && !opti onSetMetad ata.IsGlob al.Value) | |||||
| 62 | { | |||||
| 63 | // F ind the at tribute wh ich uses t he specifi ed OptionS et. | |||||
| 64 | var attribute = | |||||
| 65 | (from a in entityMet adata.Attr ibutes | |||||
| 66 | where a.A ttributeTy pe == Attr ibuteTypeC ode.Pickli st | |||||
| 67 | && ((Enum AttributeM etadata)a) .OptionSet .MetadataI d | |||||
| 68 | == op tionSetMet adata.Meta dataId | |||||
| 69 | select a) .FirstOrDe fault(); | |||||
| 70 | ||||||
| 71 | // C heck for n ull, since statuscod e attribut es on cust om entitie s are not | |||||
| 72 | // g lobal, but their opt ionsets ar e not incl uded in th e attribut e | |||||
| 73 | // m etadata of the entit y, either. | |||||
| 74 | if ( attribute != null) | |||||
| 75 | { | |||||
| 76 | // Concate nate the n ame of the entity an d the name of the at tribute | |||||
| 77 | // togethe r to form the Option Set name. | |||||
| 78 | return Str ing.Format ("{0}{1}", | |||||
| 79 | Defaul tNamingSer vice.GetNa meForEntit y(entityMe tadata, se rvices), | |||||
| 80 | Defaul tNamingSer vice.GetNa meForAttri bute( | |||||
| 81 | en tityMetada ta, attrib ute, servi ces)); | |||||
| 82 | } | |||||
| 83 | } | |||||
| 84 | ||||||
| 85 | return D efaultNami ngService. GetNameFor OptionSet( | |||||
| 86 | enti tyMetadata , optionSe tMetadata, services) ; | |||||
| 87 | } | |||||
| 88 | ||||||
| 89 | #r egion othe r INamingS ervice Met hods | |||||
| 90 | ||||||
| 91 | pu blic Strin g GetNameF orAttribut e( | |||||
| 92 | EntityMe tadata ent ityMetadat a, Attribu teMetadata attribute Metadata, | |||||
| 93 | IService Provider s ervices) | |||||
| 94 | { | |||||
| 95 | return D efaultNami ngService. GetNameFor Attribute( | |||||
| 96 | enti tyMetadata , attribut eMetadata, services) ; | |||||
| 97 | } | |||||
| 98 | ||||||
| 99 | pu blic Strin g GetNameF orEntity( | |||||
| 100 | EntityMe tadata ent ityMetadat a, IServic eProvider services) | |||||
| 101 | { | |||||
| 102 | return D efaultNami ngService. GetNameFor Entity(ent ityMetadat a, service s); | |||||
| 103 | } | |||||
| 104 | ||||||
| 105 | pu blic Strin g GetNameF orEntitySe t( | |||||
| 106 | EntityMe tadata ent ityMetadat a, IServic eProvider services) | |||||
| 107 | { | |||||
| 108 | return D efaultNami ngService. GetNameFor EntitySet( entityMeta data, serv ices); | |||||
| 109 | } | |||||
| 110 | ||||||
| 111 | pu blic Strin g GetNameF orMessageP air( | |||||
| 112 | SdkMessa gePair mes sagePair, IServicePr ovider ser vices) | |||||
| 113 | { | |||||
| 114 | return D efaultNami ngService. GetNameFor MessagePai r(messageP air, servi ces); | |||||
| 115 | } | |||||
| 116 | ||||||
| 117 | // / <summary > | |||||
| 118 | // / Handles building t he name fo r an Optio n of an Op tionSet. | |||||
| 119 | // / </summar y> | |||||
| 120 | pu blic strin g GetNameF orOption(O ptionSetMe tadataBase optionSet Metadata, | |||||
| 121 | OptionMe tadata opt ionMetadat a, IServic eProvider services) | |||||
| 122 | { | |||||
| 123 | var name = Default NamingServ ice.GetNam eForOption (optionSet Metadata, | |||||
| 124 | opti onMetadata , services ); | |||||
| 125 | Trace.Tr aceInforma tion(Strin g.Format(" The name o f this opt ion is {0} ", | |||||
| 126 | name )); | |||||
| 127 | name = E nsureValid Identifier (name); | |||||
| 128 | name = E nsureUniqu eOptionNam e(optionSe tMetadata, name); | |||||
| 129 | return n ame; | |||||
| 130 | } | |||||
| 131 | ||||||
| 132 | // / <summary > | |||||
| 133 | // / Checks t o make sur e that the name begi ns with a valid char acter. If the name | |||||
| 134 | // / does not begin wit h a valid character, then add an undersc ore to the | |||||
| 135 | // / beginnin g of the n ame. | |||||
| 136 | // / </summar y> | |||||
| 137 | pr ivate stat ic String EnsureVali dIdentifie r(String n ame) | |||||
| 138 | { | |||||
| 139 | // Check to make s ure that t he option set begins with a wo rd charact er | |||||
| 140 | // or un derscore. | |||||
| 141 | var patt ern = @"^[ A-Za-z_][A -Za-z0-9_] *$"; | |||||
| 142 | if (!Reg ex.IsMatch (name, pat tern)) | |||||
| 143 | { | |||||
| 144 | // P repend an underscore to the na me if it i s not vali d. | |||||
| 145 | name = String. Format("_{ 0}", name) ; | |||||
| 146 | Trac e.TraceInf ormation(S tring.Form at("Name o f the opti on changed to {0}", | |||||
| 147 | name)); | |||||
| 148 | } | |||||
| 149 | return n ame; | |||||
| 150 | } | |||||
| 151 | ||||||
| 152 | // / <summary > | |||||
| 153 | // / Checks t o make sur e that the name does not alrea dy exist f or the Opt ionSet | |||||
| 154 | // / to be ge nerated. | |||||
| 155 | // / </summar y> | |||||
| 156 | pr ivate Stri ng EnsureU niqueOptio nName(Opti onSetMetad ataBase me tadata, St ring name) | |||||
| 157 | { | |||||
| 158 | if (Opti onNames.Co ntainsKey( metadata)) | |||||
| 159 | { | |||||
| 160 | if ( OptionName s[metadata ].Contains Key(name)) | |||||
| 161 | { | |||||
| 162 | // Increme nt the num ber of tim es that an option wi th this na me has | |||||
| 163 | // been fo und. | |||||
| 164 | ++OptionNa mes[metada ta][name]; | |||||
| 165 | ||||||
| 166 | // Append the number to the na me to crea te a new, unique nam e. | |||||
| 167 | var newNam e = String .Format("{ 0}_{1}", | |||||
| 168 | name, OptionName s[metadata ][name]); | |||||
| 169 | ||||||
| 170 | Trace.Trac eInformati on(String. Format( | |||||
| 171 | "The { 0} OptionS et already contained a definit ion for {1 }. Changed to {2}", | |||||
| 172 | metada ta.Name, n ame, newNa me)); | |||||
| 173 | ||||||
| 174 | // Call th is functio n again to make sure that our new name i s unique. | |||||
| 175 | return Ens ureUniqueO ptionName( metadata, newName); | |||||
| 176 | } | |||||
| 177 | } | |||||
| 178 | else | |||||
| 179 | { | |||||
| 180 | // T his is the first tim e this Opt ionSet has been enco untered. A dd it to | |||||
| 181 | // t he diction ary. | |||||
| 182 | Opti onNames[me tadata] = new Dictio nary<strin g, int>(); | |||||
| 183 | } | |||||
| 184 | ||||||
| 185 | // This is the fir st time th is name ha s been enc ountered. Begin keep ing track | |||||
| 186 | // of th e times we 've run ac ross it. | |||||
| 187 | OptionNa mes[metada ta][name] = 1; | |||||
| 188 | ||||||
| 189 | return n ame; | |||||
| 190 | } | |||||
| 191 | ||||||
| 192 | pu blic Strin g GetNameF orRelation ship( | |||||
| 193 | EntityMe tadata ent ityMetadat a, Relatio nshipMetad ataBase re lationship Metadata, | |||||
| 194 | EntityRo le? reflex iveRole, I ServicePro vider serv ices) | |||||
| 195 | { | |||||
| 196 | return D efaultNami ngService. GetNameFor Relationsh ip( | |||||
| 197 | enti tyMetadata , relation shipMetada ta, reflex iveRole, s ervices); | |||||
| 198 | } | |||||
| 199 | ||||||
| 200 | pu blic Strin g GetNameF orRequestF ield( | |||||
| 201 | SdkMessa geRequest request, S dkMessageR equestFiel d requestF ield, | |||||
| 202 | IService Provider s ervices) | |||||
| 203 | { | |||||
| 204 | return D efaultNami ngService. GetNameFor RequestFie ld( | |||||
| 205 | requ est, reque stField, s ervices); | |||||
| 206 | } | |||||
| 207 | ||||||
| 208 | pu blic Strin g GetNameF orResponse Field( | |||||
| 209 | SdkMessa geResponse response, SdkMessag eResponseF ield respo nseField, | |||||
| 210 | IService Provider s ervices) | |||||
| 211 | { | |||||
| 212 | return D efaultNami ngService. GetNameFor ResponseFi eld( | |||||
| 213 | resp onse, resp onseField, services) ; | |||||
| 214 | } | |||||
| 215 | ||||||
| 216 | pu blic Strin g GetNameF orServiceC ontext(ISe rviceProvi der servic es) | |||||
| 217 | { | |||||
| 218 | return D efaultNami ngService. GetNameFor ServiceCon text(servi ces); | |||||
| 219 | } | |||||
| 220 | ||||||
| 221 | #e ndregion | |||||
| 222 | } | |||||
| 223 | } | |||||
| 224 | //</snippe tNamingSer vice> |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.