Produced by Araxis Merge on 2/1/2017 2:56:28 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\Client\Outlook | RetrieveDataFilters.cs | Tue Dec 20 19:51:45 2016 UTC |
| 2 | Wed Feb 1 19:56:28 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 0 | 0 |
| Changed | 0 | 0 |
| Inserted | 0 | 0 |
| Removed | 1 | 279 |
| 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 RetrieveDa taFilters> | |||||
| 17 | using Syst em; | |||||
| 18 | using Syst em.Linq; | |||||
| 19 | using Syst em.Service Model; | |||||
| 20 | ||||||
| 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.Client ; | |||||
| 25 | using Micr osoft.Xrm. Sdk.Query; | |||||
| 26 | ||||||
| 27 | // This na mespace is found in Microsoft. Crm.Outloo k.Sdk.dll assembly | |||||
| 28 | // found i n the SDK\ bin folder . | |||||
| 29 | using Micr osoft.Crm. Sdk.Messag es; | |||||
| 30 | ||||||
| 31 | namespace Microsoft. Crm.Sdk.Sa mples | |||||
| 32 | { | |||||
| 33 | /// <s ummary> | |||||
| 34 | /// Sh ows how to use the a dvanced ca pabilities of the Cr mOutlookSe rvice: | |||||
| 35 | /// fi lters and templates< /summary> | |||||
| 36 | /// <r emarks> | |||||
| 37 | /// NO TE: Before running t his sample , you shou ld start t he Outlook client.</ remarks> | |||||
| 38 | public class Ret rieveDataF ilters | |||||
| 39 | { | |||||
| 40 | #r egion Clas s Level Me mbers | |||||
| 41 | ||||||
| 42 | pr ivate Guid _offlineF ilter; | |||||
| 43 | pr ivate Guid _offlineT emplate; | |||||
| 44 | ||||||
| 45 | pr ivate Orga nizationSe rviceProxy _serviceP roxy; | |||||
| 46 | ||||||
| 47 | #e ndregion C lass Level Members | |||||
| 48 | ||||||
| 49 | #r egion How To Sample Code | |||||
| 50 | // / <summary > | |||||
| 51 | // / This met hod first connects t o the Outl ook servic e. Afterwa rds, | |||||
| 52 | // / client i nformation is retrie ved and th e client s tate is ch anged. | |||||
| 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 | try | |||||
| 60 | { | |||||
| 61 | ||||||
| 62 | // C onnect to the Organi zation ser vice. | |||||
| 63 | // T he using s tatement a ssures tha t the serv ice proxy will be pr operly dis posed. | |||||
| 64 | 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 )) | |||||
| 65 | { | |||||
| 66 | // This st atement is required to enable early-boun d type sup port. | |||||
| 67 | _servicePr oxy.Enable ProxyTypes (); | |||||
| 68 | ||||||
| 69 | //<snippet RetrieveDa taFilters1 > | |||||
| 70 | ||||||
| 71 | // Create and Retrie ve Offline Filter | |||||
| 72 | // In your Outlook c lient, thi s will app ear in the System Fi lters tab | |||||
| 73 | // under F ile | CRM | Synchron ize | Outl ook Filter s. | |||||
| 74 | Console.Wr ite("Creat ing offlin e filter") ; | |||||
| 75 | String con tactName = String.Fo rmat("offl ineFiltere dContact { 0}", | |||||
| 76 | DateTi me.Now.ToL ongTimeStr ing()); | |||||
| 77 | String fet chXml = St ring.Forma t("<fetch version=\" 1.0\" outp ut-format= \"xml-plat form\" map ping=\"log ical\"><en tity name= \"contact\ "><attribu te name=\" contactid\ " /><filte r type=\"a nd\">" + | |||||
| 78 | "<cond ition attr ibute=\"ow nerid\" op erator=\"e q-userid\" /><condit ion attrib ute=\"desc ription\" operator=\ "eq\" valu e=\"{0}\" />" + | |||||
| 79 | "<cond ition attr ibute=\"st atecode\" operator=\ "eq\" valu e=\"0\" /> </filter>< /entity></ fetch>", c ontactName ); | |||||
| 80 | SavedQuery filter = new SavedQ uery(); | |||||
| 81 | filter.Fet chXml = fe tchXml; | |||||
| 82 | filter.IsQ uickFindQu ery = fals e; | |||||
| 83 | filter.Que ryType = S avedQueryQ ueryType.O fflineFilt ers; | |||||
| 84 | filter.Ret urnedTypeC ode = Cont act.Entity LogicalNam e; | |||||
| 85 | filter.Nam e = "ReadO nlyFilter_ " + contac tName; | |||||
| 86 | filter.Des cription = "Sample o ffline fil ter for Co ntact enti ty"; | |||||
| 87 | _offlineFi lter = _se rviceProxy .Create(fi lter); | |||||
| 88 | ||||||
| 89 | Console.Wr iteLine(" and retrie ving offli ne filter" ); | |||||
| 90 | SavedQuery result = (SavedQuer y)_service Proxy.Retr ieve( | |||||
| 91 | SavedQ uery.Entit yLogicalNa me, | |||||
| 92 | _offli neFilter, | |||||
| 93 | new Co lumnSet("n ame", "des cription") ); | |||||
| 94 | Console.Wr iteLine("N ame: {0}", result.Na me); | |||||
| 95 | Console.Wr iteLine("D escription : {0}", re sult.Descr iption); | |||||
| 96 | Console.Wr iteLine(); | |||||
| 97 | ||||||
| 98 | // Create and Retrie ve Offline Template | |||||
| 99 | // In your Outlook c lient, thi s will app ear in the User Filt ers tab | |||||
| 100 | // under F ile | CRM | Synchron ize | Outl ook Filter s. | |||||
| 101 | Console.Wr ite("Creat ing offlin e template "); | |||||
| 102 | String acc ountName = String.Fo rmat("offl ineFiltere dAccount { 0}", | |||||
| 103 | DateTi me.Now.ToL ongTimeStr ing()); | |||||
| 104 | fetchXml = String.Fo rmat("<fet ch version =\"1.0\" o utput-form at=\"xml-p latform\" mapping=\" logical\"> <entity na me=\"accou nt\"><attr ibute name =\"account id\" /><fi lter type= \"and\">" + | |||||
| 105 | "<cond ition attr ibute=\"ow nerid\" op erator=\"e q-userid\" /><condit ion attrib ute=\"name \" operato r=\"eq\" v alue=\"{0} \" />" + | |||||
| 106 | "<cond ition attr ibute=\"st atecode\" operator=\ "eq\" valu e=\"0\" /> </filter>< /entity></ fetch>", a ccountName ); | |||||
| 107 | SavedQuery template = new Save dQuery(); | |||||
| 108 | template.F etchXml = fetchXml; | |||||
| 109 | template.I sQuickFind Query = fa lse; | |||||
| 110 | template.Q ueryType = SavedQuer yQueryType .OfflineTe mplate; | |||||
| 111 | template.R eturnedTyp eCode = Ac count.Enti tyLogicalN ame; | |||||
| 112 | template.N ame = "Rea dOnlyFilte r_" + acco untName; | |||||
| 113 | template.D escription = "Sample offline t emplate fo r Account entity"; | |||||
| 114 | _offlineTe mplate = _ servicePro xy.Create( template); | |||||
| 115 | ||||||
| 116 | Console.Wr iteLine(" and retrie ving offli ne templat e"); | |||||
| 117 | result = ( SavedQuery )_serviceP roxy.Retri eve( | |||||
| 118 | SavedQ uery.Entit yLogicalNa me, | |||||
| 119 | _offli neTemplate , | |||||
| 120 | new Co lumnSet("n ame", "des cription") ); | |||||
| 121 | Console.Wr iteLine("N ame: {0}", result.Na me); | |||||
| 122 | Console.Wr iteLine("D escription : {0}", re sult.Descr iption); | |||||
| 123 | Console.Wr iteLine(); | |||||
| 124 | //</snippe tRetrieveD ataFilters 1> | |||||
| 125 | ||||||
| 126 | //<snippet RetrieveDa taFilters2 > | |||||
| 127 | ||||||
| 128 | // Call In stantiateF iltersRequ est | |||||
| 129 | Console.Wr iteLine("R etrieving user's ID and creati ng the tem plate coll ection"); | |||||
| 130 | WhoAmIRequ est whoAmI = new Who AmIRequest (); | |||||
| 131 | Guid id = ((WhoAmIRe sponse)_se rviceProxy .Execute(w hoAmI)).Us erId; | |||||
| 132 | EntityRefe renceColle ction temp lates = ne w EntityRe ferenceCol lection(); | |||||
| 133 | templates. Add(new En tityRefere nce( | |||||
| 134 | SavedQ uery.Entit yLogicalNa me, | |||||
| 135 | _offli neTemplate )); | |||||
| 136 | ||||||
| 137 | Console.Wr iteLine("A ctivating the select ed offline templates for this user"); | |||||
| 138 | Instantiat eFiltersRe quest requ est = new Instantiat eFiltersRe quest | |||||
| 139 | { | |||||
| 140 | UserId = id, | |||||
| 141 | Templa teCollecti on = templ ates | |||||
| 142 | }; | |||||
| 143 | Instantiat eFiltersRe sponse res ponse = | |||||
| 144 | (Insta ntiateFilt ersRespons e)_service Proxy.Exec ute(reques t); | |||||
| 145 | Console.Wr iteLine(); | |||||
| 146 | //</snippe tRetrieveD ataFilters 2> | |||||
| 147 | ||||||
| 148 | //<snippet RetrieveDa taFilters3 > | |||||
| 149 | // Call Re setUserFil tersReques t | |||||
| 150 | Console.Wr iteLine("R esetting t he user's offline te mplates to the defau lts"); | |||||
| 151 | ResetUserF iltersRequ est resetR equest = n ew ResetUs erFiltersR equest | |||||
| 152 | { | |||||
| 153 | QueryT ype = Save dQueryQuer yType.Offl ineFilters | |||||
| 154 | }; | |||||
| 155 | ResetUserF iltersResp onse reset Response = | |||||
| 156 | (Reset UserFilter sResponse) _servicePr oxy.Execut e(resetReq uest); | |||||
| 157 | Console.Wr iteLine(); | |||||
| 158 | //</snippe tRetrieveD ataFilters 3> | |||||
| 159 | ||||||
| 160 | DeleteRequ iredRecord s(promptfo rDelete); | |||||
| 161 | } | |||||
| 162 | ||||||
| 163 | ||||||
| 164 | } | |||||
| 165 | ||||||
| 166 | // Catch any servi ce fault e xceptions that Micro soft Dynam ics CRM th rows. | |||||
| 167 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault>) | |||||
| 168 | { | |||||
| 169 | // Y ou can han dle an exc eption her e or pass it back to the calli ng method. | |||||
| 170 | thro w; | |||||
| 171 | } | |||||
| 172 | } | |||||
| 173 | ||||||
| 174 | pu blic void DeleteRequ iredRecord s(bool pro mpt) | |||||
| 175 | { | |||||
| 176 | bool toB eDeleted = true; | |||||
| 177 | ||||||
| 178 | if (prom pt) | |||||
| 179 | { | |||||
| 180 | // A sk the use r if the c reated ent ities shou ld be dele ted. | |||||
| 181 | Cons ole.Write( "\nDo you want these entity re cords dele ted? (y/n) [y]: "); | |||||
| 182 | Stri ng answer = Console. ReadLine() ; | |||||
| 183 | if ( answer.Sta rtsWith("y ") || | |||||
| 184 | answer.Sta rtsWith("Y ") || | |||||
| 185 | answer == String.Emp ty) | |||||
| 186 | { | |||||
| 187 | toBeDelete d = true; | |||||
| 188 | } | |||||
| 189 | else | |||||
| 190 | { | |||||
| 191 | toBeDelete d = false; | |||||
| 192 | } | |||||
| 193 | } | |||||
| 194 | ||||||
| 195 | if (toBe Deleted) | |||||
| 196 | { | |||||
| 197 | // D elete all records cr eated in t his sample . | |||||
| 198 | Cons ole.WriteL ine("Delet ing the of fline filt er and off line templ ate"); | |||||
| 199 | _ser viceProxy. Delete(Sav edQuery.En tityLogica lName, _of flineFilte r); | |||||
| 200 | _ser viceProxy. Delete(Sav edQuery.En tityLogica lName, _of flineTempl ate); | |||||
| 201 | ||||||
| 202 | Cons ole.WriteL ine("Entit y record(s ) have bee n deleted. "); | |||||
| 203 | } | |||||
| 204 | } | |||||
| 205 | ||||||
| 206 | #e ndregion H ow To Samp le Code | |||||
| 207 | ||||||
| 208 | #r egion Main method | |||||
| 209 | ||||||
| 210 | // / <summary > | |||||
| 211 | // / Standard Main() me thod used by most SD K samples. | |||||
| 212 | // / </summar y> | |||||
| 213 | // / <param n ame="args" ></param> | |||||
| 214 | st atic publi c void Mai n(string[] args) | |||||
| 215 | { | |||||
| 216 | try | |||||
| 217 | { | |||||
| 218 | // O btain the target org anization' s Web addr ess and cl ient logon | |||||
| 219 | // c redentials from the user. | |||||
| 220 | Serv erConnecti on serverC onnect = n ew ServerC onnection( ); | |||||
| 221 | Serv erConnecti on.Configu ration con fig = serv erConnect. GetServerC onfigurati on(); | |||||
| 222 | ||||||
| 223 | Retr ieveDataFi lters app = new Retr ieveDataFi lters(); | |||||
| 224 | app. Run(config , true); | |||||
| 225 | } | |||||
| 226 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault> ex ) | |||||
| 227 | { | |||||
| 228 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 229 | Cons ole.WriteL ine("Times tamp: {0}" , ex.Detai l.Timestam p); | |||||
| 230 | Cons ole.WriteL ine("Code: {0}", ex. Detail.Err orCode); | |||||
| 231 | Cons ole.WriteL ine("Messa ge: {0}", ex.Detail. Message); | |||||
| 232 | Cons ole.WriteL ine("Plugi n Trace: { 0}", ex.De tail.Trace Text); | |||||
| 233 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 234 | null == ex .Detail.In nerFault ? "No Inner Fault" : "Has Inner Fault"); | |||||
| 235 | } | |||||
| 236 | catch (S ystem.Time outExcepti on ex) | |||||
| 237 | { | |||||
| 238 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 239 | Cons ole.WriteL ine("Messa ge: {0}", ex.Message ); | |||||
| 240 | Cons ole.WriteL ine("Stack Trace: {0 }", ex.Sta ckTrace); | |||||
| 241 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 242 | null == ex .InnerExce ption.Mess age ? "No Inner Faul t" : ex.In nerExcepti on.Message ); | |||||
| 243 | } | |||||
| 244 | catch (S ystem.Exce ption ex) | |||||
| 245 | { | |||||
| 246 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 247 | Cons ole.WriteL ine(ex.Mes sage); | |||||
| 248 | ||||||
| 249 | // D isplay the details o f the inne r exceptio n. | |||||
| 250 | if ( ex.InnerEx ception != null) | |||||
| 251 | { | |||||
| 252 | Console.Wr iteLine(ex .InnerExce ption.Mess age); | |||||
| 253 | ||||||
| 254 | FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault> f e = ex.Inn erExceptio n | |||||
| 255 | as Fau ltExceptio n<Microsof t.Xrm.Sdk. Organizati onServiceF ault>; | |||||
| 256 | if (fe != null) | |||||
| 257 | { | |||||
| 258 | Consol e.WriteLin e("Timesta mp: {0}", fe.Detail. Timestamp) ; | |||||
| 259 | Consol e.WriteLin e("Code: { 0}", fe.De tail.Error Code); | |||||
| 260 | Consol e.WriteLin e("Message : {0}", fe .Detail.Me ssage); | |||||
| 261 | Consol e.WriteLin e("Plugin Trace: {0} ", fe.Deta il.TraceTe xt); | |||||
| 262 | Consol e.WriteLin e("Inner F ault: {0}" , | |||||
| 263 | nu ll == fe.D etail.Inne rFault ? " No Inner F ault" : "H as Inner F ault"); | |||||
| 264 | } | |||||
| 265 | } | |||||
| 266 | } | |||||
| 267 | // Addit ional exce ptions to catch: Sec urityToken Validation Exception, ExpiredSe curityToke nException , | |||||
| 268 | // Secur ityAccessD eniedExcep tion, Mess ageSecurit yException , and Secu rityNegoti ationExcep tion. | |||||
| 269 | ||||||
| 270 | finally | |||||
| 271 | { | |||||
| 272 | Cons ole.WriteL ine("Press <Enter> t o exit."); | |||||
| 273 | Cons ole.ReadLi ne(); | |||||
| 274 | } | |||||
| 275 | } | |||||
| 276 | #e ndregion M ain method | |||||
| 277 | } | |||||
| 278 | } | |||||
| 279 | //</snippe tRetrieveD ataFilters > |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.