939. Araxis Merge File Comparison Report

Produced by Araxis Merge on 2/1/2017 2:57:36 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.

939.1 Files compared

# Location File Last Modified
1 C:\Araxis_Merge_Comprasion\Pub_un\BTSSS_CIF_122016.zip\BTSSS_CIF_12_20_16\clean\CRM\trunk\SDK\Tools\WebResourceUtility\ViewModels MainWindowViewModel.cs Tue Dec 20 19:52:28 2016 UTC
2 Wed Feb 1 19:57:36 2017 UTC

939.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 0 0
Changed 0 0
Inserted 0 0
Removed 1 1336

939.3 Comparison options

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

939.4 Active regular expressions

No regular expressions were active.

939.5 Comparison detail

1   using Syst em;        
2   using Syst em.Collect ions;        
3   using Syst em.Collect ions.Gener ic;        
4   using Syst em.Collect ions.Objec tModel;        
5   using Syst em.IO;        
6   using Syst em.Linq;        
7   using Syst em.Text;        
8   using Syst em.Windows ;        
9   using Syst em.Windows .Data;        
10   using Syst em.Windows .Input;        
11   using Syst em.Xml.Lin q;        
12   using Micr osoft.Crm. Sdk.Messag es;        
13   using Micr osoft.Xrm. Sdk;        
14   using Micr osoft.Xrm. Sdk.Client ;        
15   using Micr osoft.Xrm. Sdk.Query;        
16   using WebR esourceUti lity.Model ;        
17   using Syst em.Text.Re gularExpre ssions;        
18   using Syst em.Compone ntModel;        
19   using Syst em.Windows .Threading ;        
20          
21   namespace  Microsoft. Crm.Sdk.Sa mples        
22   {        
23       public  class Mai nWindowVie wModel : V iewModelBa se        
24       {        
25          
26           #r egion Comm ands        
27          
28          
29           Re layCommand  _hideOutp utWindow;        
30           pu blic IComm and HideOu tputWindow          
31           {        
32                get        
33                {        
34                    if ( _hideOutpu tWindow ==  null)        
35                    {        
36                         _hideOutpu tWindow =  new RelayC ommand(        
37                             param  => { IsOut putWindowD isplayed =  false; }) ;        
38                    }        
39                    retu rn _hideOu tputWindow ;        
40                }        
41           }        
42          
43           Re layCommand  _showOutp utWindow;        
44           pu blic IComm and ShowOu tputWindow        
45           {        
46                get        
47                {        
48                    if ( _showOutpu tWindow ==  null)        
49                    {        
50                         _showOutpu tWindow =  new RelayC ommand(        
51                             param  => { IsOut putWindowD isplayed =  true; });        
52                    }        
53                    retu rn _showOu tputWindow ;        
54                }        
55           }        
56          
57           Re layCommand  _browseFo lderComman d;        
58           pu blic IComm and Browse FolderComm and         
59           {        
60                get        
61                {        
62                    if ( _browseFol derCommand  == null)        
63                    {        
64                         _browseFol derCommand  = new Rel ayCommand(        
65                             param  => this.Sh owBrowseFo lderDialog ());        
66                    }        
67                    retu rn _browse FolderComm and;        
68                }        
69          
70           }        
71          
72           Re layCommand  _activate Connection Command;        
73           pu blic IComm and Activa teConnecti onCommand         
74           {        
75                get        
76                {        
77                    if ( _activateC onnectionC ommand ==  null)        
78                    {        
79                         _activateC onnectionC ommand = n ew RelayCo mmand(        
80                             param  => this.Ac tivateSele ctedConfig uration(),        
81                             param  => this.Ca nActivateS electedCon figuration ());        
82                    }        
83                    retu rn _activa teConnecti onCommand;        
84                }        
85          
86           }        
87          
88           Re layCommand  _createNe wConnectio nCommand;        
89           pu blic IComm and Create NewConnect ionCommand        
90           {        
91                get        
92                {        
93                    if ( _createNew Connection Command ==  null)        
94                    {        
95                         _createNew Connection Command =  new RelayC ommand(        
96                             param  => this.Cr eateNewCon figuration ());        
97                    }        
98                    retu rn _create NewConnect ionCommand ;        
99                }        
100          
101           }        
102                            
103           Re layCommand  _deleteCo nnectionCo mmand;        
104           pu blic IComm and Delete Connection Command        
105           {        
106                get        
107                {        
108                    if ( _deleteCon nectionCom mand == nu ll)        
109                    {        
110                         _deleteCon nectionCom mand = new  RelayComm and(        
111                             param  => this.De leteSelect edConfigur ation());        
112                    }        
113                    retu rn _delete Connection Command;        
114                }        
115          
116           }        
117          
118           Re layCommand  _activate SolutionCo mmand;        
119           pu blic IComm and Activa teSolution Command        
120           {        
121                get        
122                {        
123                    if ( _activateS olutionCom mand == nu ll)        
124                    {        
125                         _activateS olutionCom mand = new  RelayComm and(        
126                             param  => this.Ac tivateSele ctedSoluti on());        
127                    }        
128                    retu rn _activa teSolution Command;        
129                }        
130           }        
131          
132           Re layCommand  _activate SelectedPa ckageComma nd;        
133           pu blic IComm and Activa teSelected PackageCom mand        
134           {        
135                get        
136                {        
137                    if ( _activateS electedPac kageComman d == null)        
138                    {        
139                         _activateS electedPac kageComman d = new Re layCommand (        
140                             param  => this.Ac tivatePack age());        
141                    }        
142                    retu rn _activa teSelected PackageCom mand;        
143                }        
144           }        
145          
146           Re layCommand  _createNe wPackageCo mmand;        
147           pu blic IComm and Create NewPackage Command        
148           {        
149                get        
150                {        
151                    if ( _createNew PackageCom mand == nu ll)        
152                    {        
153                         _createNew PackageCom mand = new  RelayComm and(        
154                             param  => this.Cr eateNewPac kage());        
155                    }        
156                    retu rn _create NewPackage Command;        
157                }        
158           }        
159          
160           Re layCommand  _deleteAc tivePackag eCommand;        
161           pu blic IComm and Delete ActivePack ageCommand        
162           {        
163                get        
164                {        
165                    if ( _deleteAct ivePackage Command ==  null)        
166                    {        
167                         _deleteAct ivePackage Command =  new RelayC ommand(        
168                             param  => this.De leteSelect edPackage( ));        
169                    }        
170                    retu rn _delete ActivePack ageCommand ;        
171                }        
172          
173           }        
174          
175           Re layCommand  _saveActi vePackageC ommand;        
176           pu blic IComm and SaveAc tivePackag eCommand        
177           {        
178                get        
179                {        
180                    if ( _saveActiv ePackageCo mmand == n ull)        
181                    {        
182                         _saveActiv ePackageCo mmand = ne w RelayCom mand(        
183                             param  => SavePac kages());        
184                    }        
185                    retu rn _saveAc tivePackag eCommand;        
186                }        
187           }                      
188          
189           Re layCommand  _refreshF ilesComman d;        
190           pu blic IComm and Refres hFilesComm and        
191           {        
192                get        
193                {        
194                    if ( _refreshFi lesCommand  == null)        
195                    {        
196                         _refreshFi lesCommand  = new Rel ayCommand(        
197                             param  => this.Se archAndPop ulateFiles ());        
198                    }        
199                    retu rn _refres hFilesComm and;        
200                }        
201           }        
202          
203           Re layCommand  _saveConn ectionsCom mand;        
204           pu blic IComm and SaveCo nnectionsC ommand        
205           {        
206                get        
207                {        
208                    if ( _saveConne ctionsComm and == nul l)        
209                    {        
210                         _saveConne ctionsComm and = new  RelayComma nd(        
211                             param  => SaveCon figuration s());        
212                    }        
213                    retu rn _saveCo nnectionsC ommand;        
214                }        
215           }        
216          
217           Re layCommand <IEnumerab le> _conve rtFileToRe sourceComm and;        
218           pu blic IComm and Conver tFileToRes ourceComma nd        
219           {        
220                get        
221                {        
222                    if ( _convertFi leToResour ceCommand  == null)        
223                    {        
224                         _convertFi leToResour ceCommand  = new Rela yCommand<I Enumerable >(AddFiles ToWebResou rces);        
225                    }        
226                    retu rn _conver tFileToRes ourceComma nd;        
227                }        
228           }        
229          
230           Re layCommand <IEnumerab le> _uploa dWebResour cesCommand ;        
231           pu blic IComm and Upload WebResourc esCommand        
232           {        
233                get        
234                {        
235                    if ( _uploadWeb ResourcesC ommand ==  null)        
236                    {        
237                         _uploadWeb ResourcesC ommand = n ew RelayCo mmand<IEnu merable>(U ploadWebRe sources, p aram => Ca nUploadWeb Resource() );        
238                    }        
239                    retu rn _upload WebResourc esCommand;        
240                }        
241           }        
242          
243           Re layCommand  _uploadAl lWebResour cesCommand ;        
244           pu blic IComm and Upload AllWebReso urcesComma nd        
245           {        
246                get        
247                {        
248                    if ( _uploadAll WebResourc esCommand  == null)        
249                    {        
250                         _uploadAll WebResourc esCommand         
251                             new Re layCommand (param =>                      U ploadAllWe bResources (),         
252                                 pa ram => Can UploadWebR esource()) ;        
253                    }        
254                    retu rn _upload AllWebReso urcesComma nd;        
255                }        
256           }        
257          
258           Re layCommand <IEnumerab le> _delet eWebResour cesCommand ;        
259           pu blic IComm and Delete WebResourc esCommand        
260           {        
261                get        
262                {        
263                    if ( _deleteWeb ResourcesC ommand ==  null)        
264                    {        
265                         _deleteWeb ResourcesC ommand = n ew RelayCo mmand<IEnu merable>(D eleteSelec tedWebReso urces);        
266                    }        
267                    retu rn _delete WebResourc esCommand;        
268                }        
269           }        
270                   
271           #e ndregion         
272                   
273           #r egion Prop erties        
274          
275           pu blic const  string CO NFIG_FILEN AME = @"co nfiguratio ns.xml";        
276           pu blic const  string PA CKAGES_FIL ENAME = @" packages.x ml";        
277           pu blic const  string VA LID_NAME_M SG = "ERRO R: Web Res ource name s cannot c ontain spa ces or hyp hens. They  must be a lphanumeri c and cont ain unders core chara cters, per iods, and  non-consec utive forw ard slash  characters ";        
278           pu blic XElem ent XmlPac kageData;        
279           pu blic XElem ent XmlCon figData;        
280          
281           pr ivate Stri ngBuilder  _progressM essage;        
282           pu blic Strin g Progress Message        
283           {        
284                get        
285                {        
286                    retu rn _progre ssMessage. ToString() ;        
287                }        
288                set        
289                {        
290                    _pro gressMessa ge.AppendL ine(value) ;        
291                    OnPr opertyChan ged("Progr essMessage ");        
292                }        
293           }        
294          
295           pr ivate int  _tabContro lSelectedI ndex;        
296           pu blic int T abControlS electedInd ex        
297           {        
298                get        
299                {        
300                    retu rn _tabCon trolSelect edIndex;        
301                }        
302                set        
303                {        
304                    _tab ControlSel ectedIndex  = value;        
305                    OnPr opertyChan ged("TabCo ntrolSelec tedIndex") ;        
306                }        
307           }        
308          
309           pr ivate bool  _areAllBu ttonsEnabl ed = true;        
310           pu blic bool  AreAllButt onsEnabled        
311           {        
312                get        
313                {        
314                    retu rn _areAll ButtonsEna bled;        
315                }        
316                set        
317                {        
318                    _are AllButtons Enabled =  value;        
319                    OnPr opertyChan ged("AreAl lButtonsEn abled");        
320                }        
321           }        
322          
323           pu blic bool  IsActiveCo nnectionSe t        
324           {        
325                get         
326                {        
327                    retu rn (Active Configurat ion != nul l) ? true  : false;        
328                }        
329           }        
330           pu blic bool  IsActiveSo lutionSet        
331           {        
332                get        
333                {        
334                    retu rn (Active Solution ! = null) ?  true : fal se;        
335                }        
336           }        
337           pu blic bool  IsActivePa ckageSet        
338           {        
339                get        
340                {        
341                    retu rn (Active Package !=  null) ? t rue : fals e;        
342                }        
343           }        
344          
345           pr ivate bool  _shouldPu blishAllAf terUpload;        
346           pu blic bool  ShouldPubl ishAllAfte rUpload        
347           {        
348                get        
349                {        
350                    retu rn _should PublishAll AfterUploa d;        
351                }        
352                set         
353                {        
354                    _sho uldPublish AllAfterUp load = val ue;        
355                    OnPr opertyChan ged("Shoul dPublishAl lAfterUplo ad");        
356                }        
357           }        
358          
359           pr ivate bool  _isOutput WindowDisp layed = fa lse;        
360           pu blic bool  IsOutputWi ndowDispla yed        
361           {        
362                get        
363                {        
364                    retu rn _isOutp utWindowDi splayed;        
365                }        
366                set        
367                {        
368                    _isO utputWindo wDisplayed  = value;        
369                    OnPr opertyChan ged("IsOut putWindowD isplayed") ;        
370                    OnPr opertyChan ged("IsWor kstationDi splayed");        
371                }        
372           }        
373          
374           pu blic bool  IsWorkstat ionDisplay ed        
375           {        
376                get        
377                {        
378                    retu rn !(IsOut putWindowD isplayed);        
379                }        
380           }        
381          
382           pr ivate Stri ng _fileSe archText;        
383           pu blic Strin g FileSear chText        
384           {        
385                get { re turn _file SearchText ; }        
386                set { _f ileSearchT ext = valu e; OnPrope rtyChanged ("FileSear chText");  }        
387           }        
388                   
389           // WebResourc es Package s        
390           pu blic Obser vableColle ction<XEle ment> Pack ages { get ; set; }        
391           pr ivate XEle ment _sele ctedPackag e;        
392           pu blic XElem ent Select edPackage        
393           {        
394                get        
395                {        
396                    retu rn _select edPackage;        
397                }        
398                set        
399                {        
400                    _sel ectedPacka ge = value ;        
401                    OnPr opertyChan ged("Selec tedPackage ");        
402                }        
403           }        
404           pr ivate XEle ment _acti vePackage;        
405           pu blic XElem ent Active Package        
406           {        
407                get        
408                {        
409                    retu rn _active Package;        
410                }        
411                set        
412                {        
413                    _act ivePackage  = value;        
414                    OnPr opertyChan ged("Activ ePackage") ;        
415                    OnPr opertyChan ged("IsAct ivePackage Set");        
416                }        
417           }        
418           pr ivate bool  _isActive PackageDir ty = false ;        
419           pu blic bool  IsActivePa ckageDirty        
420           {        
421                get        
422                {        
423                    retu rn _isActi vePackageD irty;        
424                }        
425                set        
426                {        
427                    _isA ctivePacka geDirty =  value;        
428                    OnPr opertyChan ged("IsAct ivePackage Dirty");        
429                }        
430           }        
431          
432           // FileInfos  for all po tential re sources in  a directo ry        
433           pu blic Obser vableColle ction<File Info> Curr entFiles {  get; set;  }        
434           pu blic Obser vableColle ction<File Info> Curr entFilesSe lected { g et; set; }        
435          
436           // Represents  a collect ion of "We bResourceI nfo" node  from XML.        
437           pu blic Obser vableColle ction<XEle ment> WebR esourceInf os { get;  set; }        
438           pu blic Obser vableColle ction<XEle ment> WebR esourceInf osSelected  { get; se t; }        
439                   
440           // Connection s        
441           pu blic Obser vableColle ction<XEle ment> Conf igurations  { get; se t; }        
442           pr ivate XEle ment _sele ctedConfig uration;        
443           pu blic XElem ent Select edConfigur ation         
444           {        
445                get { re turn _sele ctedConfig uration; }        
446                set        
447                {        
448                    _sel ectedConfi guration =  value;        
449                    OnPr opertyChan ged("Selec tedConfigu ration");        
450                }        
451           }        
452           pr ivate XEle ment _acti veConfigur ation;        
453           pu blic XElem ent Active Configurat ion        
454           {        
455                get { re turn _acti veConfigur ation; }        
456                set        
457                {        
458                    _act iveConfigu ration = v alue;        
459                    OnPr opertyChan ged("Activ eConfigura tion");        
460                    OnPr opertyChan ged("IsAct iveConnect ionSet");        
461                }        
462           }        
463          
464           // Solutions        
465           pu blic Obser vableColle ction<Solu tion> Unma nagedSolut ions { get ; set; }        
466           pr ivate Solu tion _sele ctedSoluti on;        
467           pu blic Solut ion Select edSolution          
468           {        
469                get         
470                {         
471                    retu rn _select edSolution        
472                }        
473                set        
474                {        
475                    _sel ectedSolut ion = valu e;        
476                    OnPr opertyChan ged("Selec tedSolutio n");        
477                }        
478           }        
479           pr ivate Solu tion _acti veSolution ;        
480           pu blic Solut ion Active Solution        
481           {        
482                get        
483                {        
484                    retu rn _active Solution;        
485                }        
486                set        
487                {        
488                    _act iveSolutio n = value;        
489                    OnPr opertyChan ged("Activ eSolution" );        
490                    OnPr opertyChan ged("IsAct iveSolutio nSet");        
491                }        
492           }        
493          
494           // Active Pub lisher        
495           pr ivate Publ isher _act ivePublish er;        
496           pu blic Publi sher Activ ePublisher        
497           {        
498                get { re turn _acti vePublishe r; }        
499                set { _a ctivePubli sher = val ue; OnProp ertyChange d("ActiveP ublisher") ; }        
500           }        
501          
502           #e ndregion        
503          
504           #r egion Fiel ds        
505           // CRM Data P rovider        
506           pr ivate Cons olelessSer verConnect ion _serve rConnect;                 
507           pr ivate stat ic Organiz ationServi ceProxy _s erviceProx y;        
508           pr ivate stat ic Organiz ationServi ceContext  _orgContex t;        
509          
510           Ba ckgroundWo rker worke r;        
511                   
512           #e ndregion        
513          
514           #r egion Cons tructor        
515          
516           pu blic MainW indowViewM odel()        
517           {        
518                XDocumen t xmlPacka gesDocumen t = XDocum ent.Load(P ACKAGES_FI LENAME);        
519                XmlPacka geData = x mlPackages Document.E lement("Ut ilityRoot" );        
520          
521                XDocumen t xmlConfi gurationsD ocument =  XDocument. Load(CONFI G_FILENAME );        
522                XmlConfi gData = xm lConfigura tionsDocum ent.Elemen t("Configu rations");        
523          
524                Configur ations = n ew Observa bleCollect ion<XEleme nt>();        
525                Packages  = new Obs ervableCol lection<XE lement>();        
526                Unmanage dSolutions  = new Obs ervableCol lection<So lution>();        
527                CurrentF iles = new  Observabl eCollectio n<FileInfo >();        
528                CurrentF ilesSelect ed = new O bservableC ollection< FileInfo>( );        
529                WebResou rceInfos =  new Obser vableColle ction<XEle ment>();        
530                WebResou rceInfosSe lected = n ew Observa bleCollect ion<XEleme nt>();        
531          
532                //Begin  loading th e XML data        
533                LoadXmlD ata();        
534          
535                TabContr olSelected Index = 0;        
536                _progres sMessage =  new Strin gBuilder() ;        
537                _shouldP ublishAllA fterUpload  = true;        
538          
539                //Set up  the backg round work er to hand le upload  web resour ces. Helps        
540                //preven t the UI f rom lockin g up and c an have a  Console-li ke output  window        
541                //with r eal-time d isplay.        
542                worker =  new Backg roundWorke r();                     
543                worker.W orkerRepor tsProgress  = true;        
544                worker.D oWork += n ew DoWorkE ventHandle r(BeginUpl oad);        
545                worker.R unWorkerCo mpleted +=  delegate( object s,  RunWorkerC ompletedEv entArgs ar gs)        
546                {        
547                    this .BeginInvo ke(() =>        
548                    {        
549                         AreAllButt onsEnabled  = true;        
550                    });        
551                };        
552           }        
553          
554           #e ndregion        
555          
556           #r egion Meth ods         
557          
558           pr ivate void  LoadXmlDa ta()        
559           {        
560                LoadConf igurations ();        
561                LoadPack ages();                    
562           }        
563                
564           // Configurat ion Method s        
565           pr ivate void  LoadConfi gurations( )        
566           {        
567                Configur ations.Cle ar();        
568          
569                var conf igs = XmlC onfigData. Descendant s("Configu ration");        
570                foreach  (var c in  configs)        
571                {        
572                    Conf igurations .Add(c);        
573                }        
574           }        
575           pr ivate void  SaveConfi gurations( )        
576           {        
577                XmlConfi gData.Desc endants("C onfigurati on").Remov e();        
578                XmlConfi gData.Add( Configurat ions.ToArr ay());        
579          
580                XmlConfi gData.Save (CONFIG_FI LENAME);        
581           }        
582           pr ivate void  CreateNew Configurat ion()        
583           {        
584                XElement  newConfig  = new XEl ement("Con figuration ",        
585                    new  XAttribute ("name", " New Connec tion"),        
586                    new  XAttribute ("server",  String.Em pty),        
587                    new  XAttribute ("orgName" , String.E mpty),        
588                    new  XAttribute ("userName ", String. Empty),        
589                    new  XAttribute ("domain",  String.Em pty));        
590          
591                Configur ations.Add (newConfig );        
592                Selected Configurat ion = Conf igurations [Configura tions.Coun t - 1];        
593           }        
594           pr ivate void  DeleteSel ectedConfi guration()        
595           {        
596                if (Sele ctedConfig uration !=  null)        
597                {        
598                    //if  trying to  delete th e configur ation that  is also a ctive alre ady,        
599                    //le t them by  clearing A ctiveConfi guration a nd solutio ns.        
600                    if ( SelectedCo nfiguratio n == Activ eConfigura tion)        
601                    {        
602                         ClearActiv eConfigura tion();        
603                         ClearSolut ions();        
604                    }        
605          
606                    //Fi nally clea r the Sele ctedConfig uration an d remove i t from the  list of C onfigurati ons.        
607                    var  toBeDelete d = Config urations.W here(x =>  x == Selec tedConfigu ration).Fi rstOrDefau lt();        
608                    if ( toBeDelete d != null)        
609                    {        
610                         Configurat ions.Remov e(toBeDele ted);        
611                         SelectedCo nfiguratio n = null;        
612                    }        
613                }        
614           }        
615           pr ivate void  ClearActi veConfigur ation()        
616           {        
617                ActiveCo nfiguratio n = null;        
618           }        
619           pr ivate void  ActivateS electedCon figuration ()        
620           {        
621                //User m ay have al ready been  connected  to anothe r org, dis connect th em.        
622                ClearAct iveConfigu ration();        
623          
624                //Clear  out any So lutions fr om the Sol utions col lection si nce they a re         
625                //Config uration sp ecfic.        
626                ClearSol utions();        
627          
628                //Instan tiate new  proxy. if  it is succ essful, it  will also        
629                //set th e ActiveCo nfiguratio n and retr ieve Solut ions.        
630                Instanti ateService ();        
631           }        
632           pr ivate bool  CanActiva teSelected Configurat ion()        
633           {        
634                if (Sele ctedConfig uration !=  null &&        
635                    !Str ing.IsNull OrWhiteSpa ce(Selecte dConfigura tion.Attri bute("serv er").Value ) &&        
636                    !Str ing.IsNull OrWhiteSpa ce(Selecte dConfigura tion.Attri bute("orgN ame").Valu e))        
637                {        
638                    retu rn true;        
639                }        
640                return f alse;        
641           }        
642               
643           // Solution M ethods        
644           pr ivate void  LoadSolut ions()        
645           {        
646                //Check  whether it  already e xists        
647                QueryExp ression qu eryUnmanag edSolution s = new Qu eryExpress ion        
648                {        
649                    Enti tyName = S olution.En tityLogica lName,        
650                    Colu mnSet = ne w ColumnSe t(true),        
651                    Crit eria = new  FilterExp ression()        
652                };        
653                queryUnm anagedSolu tions.Crit eria.AddCo ndition("i smanaged",  Condition Operator.E qual, fals e);        
654                EntityCo llection q uerySoluti onResults  = _service Proxy.Retr ieveMultip le(queryUn managedSol utions);        
655          
656                if (quer ySolutionR esults.Ent ities.Coun t > 0)        
657                {        
658                    //Th e Where()  is importa nt because  a query f or all sol utions        
659                    //wh ere Type=U nmanaged r eturns 3 s olutions.  The CRM UI  of a         
660                    //va nilla inst ance shows  only 1 un managed so lution: "D efault".         
661                    //As sume "Acti ve" and "B asic" shou ld not be  touched?        
662                    Unma nagedSolut ions = new  Observabl eCollectio n<Solution >(        
663                         querySolut ionResults .Entities        
664                             .Selec t(x => x a s Solution )        
665                             .Where (s => s.Un iqueName ! = "Active"  &&        
666                                          s.Un iqueName ! = "Basic"        
667                             )        
668                         );        
669          
670                    //If  only 1 so lution ret urns just  go ahead a nd default  it.        
671                    if ( UnmanagedS olutions.C ount == 1  && Unmanag edSolution s[0].Uniqu eName == " Default")        
672                    {        
673                         SelectedSo lution = U nmanagedSo lutions[0] ;        
674                         ActiveSolu tion = Sel ectedSolut ion;        
675          
676                         SetActiveP ublisher() ;        
677          
678                         //Advance  the user t o the Pack ages TabIt em        
679                         TabControl SelectedIn dex = 2;        
680                    }        
681                    else        
682                    {        
683                         //Advance  the user t o the Solu tions TabI tem        
684                         TabControl SelectedIn dex = 1;        
685                    }        
686          
687                    OnPr opertyChan ged("Unman agedSoluti ons");        
688                    OnPr opertyChan ged("Selec tedSolutio n");        
689                    OnPr opertyChan ged("Activ eSolution" );        
690                            
691                }        
692           }        
693           pr ivate void  Instantia teService( )        
694           {        
695                try        
696                {        
697                    if ( SelectedCo nfiguratio n == null)        
698                         throw new  Exception( "Please ch oose a con figuration .");        
699          
700                    //Ge t the Pass word        
701                    stri ng passwor d = String .Empty;        
702                    Pass wordWindow  pw = new  PasswordWi ndow();        
703                    pw.O wner = App lication.C urrent.Mai nWindow;        
704                    bool ? submitte d = pw.Sho wDialog();        
705                    if ( submitted. Value)        
706                    {        
707                         password =  pw.GetPas sword();        
708                    }        
709                    else        
710                    {        
711                         ErrorWindo w needPass word = new  ErrorWind ow("You ne ed to supp ly a Passw ord and Su bmit. Try  again.");        
712                         needPasswo rd.Owner =  Applicati on.Current .MainWindo w;        
713                         needPasswo rd.ShowDia log();        
714                         return;        
715                    }        
716                            
717          
718                    _ser verConnect  = new Con solelessSe rverConnec tion();        
719                    Cons olelessSer verConnect ion.Config uration _c onfig = ne w Consolel essServerC onnection. Configurat ion();        
720                    _con fig = _ser verConnect .GetServer Configurat ion(        
721                         SelectedCo nfiguratio n.Attribut e("server" ).Value,        
722                         SelectedCo nfiguratio n.Attribut e("orgName ").Value,        
723                         SelectedCo nfiguratio n.Attribut e("userNam e").Value,          
724                         password,        
725                         SelectedCo nfiguratio n.Attribut e("domain" ).Value);        
726          
727                    _ser viceProxy  = new Orga nizationSe rviceProxy (_config.O rganizatio nUri,        
728                         _config.Ho meRealmUri ,        
729                         _config.Cr edentials,        
730                         _config.De viceCreden tials);        
731          
732                    // T his statem ent is req uired to e nable earl y-bound ty pe support .        
733                    _ser viceProxy. ServiceCon figuration .CurrentSe rviceEndpo int.Behavi ors        
734                         .Add(new P roxyTypesB ehavior()) ;        
735          
736                    // T he Organiz ationServi ceContext  is an obje ct that wr aps the se rvice        
737                    // p roxy and a llows crea ting/updat ing multip le records  simultane ously.        
738                    _org Context =  new Organi zationServ iceContext (_serviceP roxy);        
739          
740                    //Se t the Acti veConnecti on        
741                    Acti veConfigur ation = Se lectedConf iguration;        
742          
743                    //If  all worke d, retriev e the solu tions.        
744                    Load Solutions( );        
745          
746                }        
747                catch (E xception e )        
748                {        
749                    Stri ngBuilder  sb = new S tringBuild er();        
750                    sb.A ppendLine( e.Message) ;        
751                    sb.A ppendLine( );        
752                    sb.A ppendLine( "Please fi x the Conn ection inf ormation a nd try aga in.");        
753                    Erro rWindow er rorWindow  = new Erro rWindow(sb .ToString( ));        
754                    erro rWindow.Ow ner = Appl ication.Cu rrent.Main Window;        
755                    var  x = errorW indow.Show Dialog();        
756                }        
757           }        
758           pr ivate void  ClearSolu tions()        
759           {        
760                //Clear  solutions        
761                Unmanage dSolutions .Clear();        
762                Selected Solution =  null;        
763                ActiveSo lution = n ull;        
764          
765                ActivePu blisher =  null;        
766           }            
767           pr ivate void  ActivateS electedSol ution()        
768           {        
769                if (Sele ctedSoluti on != null )        
770                {        
771                    Acti veSolution  = Selecte dSolution;        
772          
773                    SetA ctivePubli sher();        
774          
775                    OnPr opertyChan ged("Activ eSolution" );        
776          
777                    //Ad vance the  user to th e Packages  TabItem        
778                    TabC ontrolSele ctedIndex  = 2;        
779                }        
780           }        
781           pr ivate void  SetActive Publisher( )        
782           {        
783                if (Acti veSolution  == null)        
784                    retu rn;        
785          
786                var pub  = from p i n _orgCont ext.Create Query<Publ isher>()        
787                             where  p.Publishe rId.Value  == ActiveS olution.Pu blisherId. Id        
788                             select  new Publi sher        
789                             {        
790                                 Cu stomizatio nPrefix =  p.Customiz ationPrefi x        
791                                          
792                             };        
793          
794                ActivePu blisher =  pub.First( );        
795                OnProper tyChanged( "ActivePub lisher");        
796          
797           }        
798          
799           // Package Me thods           
800           pr ivate void  LoadPacka ges()        
801           {        
802                Packages .Clear();        
803                var pack ages = Xml PackageDat a.Element( "Packages" ).Descenda nts("Packa ge");        
804                foreach  (var p in  packages)        
805                {        
806                    Pack ages.Add(p );        
807                }        
808                OnProper tyChanged( "Packages" );        
809           }        
810           pr ivate void  SavePacka ges()        
811           {        
812                //The us er is infl uenced to  believe a  Save event  will only          
813                //save t he ActiveP ackage but  really it  will save  all of th em.        
814                //Code i s in place  to preven t the user  from edit ing one pa ckage then          
815                //trying  to load a nother wit hout savin g the firs t.        
816          
817                //At thi s point th e XmlRootD ata object  is stale  and needs  to be         
818                //repopu lated with  the Packa ges collec tion.        
819                XmlPacka geData.Des cendants(" Package"). Remove();        
820          
821                //But th e ActivePa ckage may  have its W eb Resourc es modifie d and they        
822                //need t o be added  back to t he ActiveP ackage.        
823                if (Acti vePackage  != null)        
824                {        
825                    Acti vePackage. Elements(" WebResourc eInfo").Re move();        
826                    Acti vePackage. Add(WebRes ourceInfos .ToArray() );        
827                }        
828          
829                XmlPacka geData.Ele ment("Pack ages").Add (Packages. ToArray()) ;        
830          
831                XmlPacka geData.Sav e(PACKAGES _FILENAME) ;        
832          
833                IsActive PackageDir ty = false ;        
834          
835           }        
836           pr ivate void  DeleteSel ectedPacka ge()        
837           {        
838                if (Sele ctedPackag e != null)        
839                {        
840                    var  toBeDelete d = Packag es.Where(x  => x == S electedPac kage).Firs tOrDefault ();        
841          
842                    if ( toBeDelete d != null)        
843                    {        
844                         if (Active Package ==  SelectedP ackage)        
845                         {        
846                             Active Package =  null;        
847                             //Also , clear ou t any depe ndencies        
848                             Curren tFiles.Cle ar();        
849                             Curren tFilesSele cted.Clear ();        
850                             WebRes ourceInfos .Clear();        
851                             WebRes ourceInfos Selected.C lear();        
852                         }        
853                         Packages.R emove(toBe Deleted);        
854                         SelectedPa ckage = nu ll;        
855                    }        
856                    Save Packages() ;        
857                }        
858           }        
859           pr ivate void  ActivateP ackage()        
860           {        
861                //Don't  allow them  to load a  package w ithout fir st saving        
862                //the Ac tivePackag e if its d irty.        
863                if (Acti vePackage  != null &&  IsActiveP ackageDirt y)        
864                {        
865                    Erro rWindow di rtyPackage Window =        
866                         new ErrorW indow("You  have unsa ved change s to the A ctive Pack age. Pleas e save bef ore loadin g another  package.") ;        
867                    dirt yPackageWi ndow.Owner  = Applica tion.Curre nt.MainWin dow;        
868                    dirt yPackageWi ndow.ShowD ialog();        
869                    retu rn;                       
870                }        
871          
872                if (Sele ctedPackag e != null)        
873                {        
874                    Acti vePackage  = Selected Package;        
875          
876                    //Re adies the  Files Data Grid         
877                    Sear chAndPopul ateFiles() ;        
878          
879                    //Re adies the  Web Resour ces DataGr id        
880                    Load WebResourc eInfos();        
881                }        
882           }        
883           pr ivate void  CreateNew Package()        
884           {        
885                if (Acti vePackage  != null)        
886                {        
887                    Save Packages() ;        
888                }        
889          
890                XElement  newPackag e = new XE lement("Pa ckage",        
891                    new  XAttribute ("name", " NewPackage "),        
892                    new  XAttribute ("rootPath ", String. Empty),        
893                    new  XAttribute ("isNamePr efix", tru e));        
894          
895                Packages .Add(newPa ckage);        
896                Selected Package =  Packages[P ackages.Co unt - 1];        
897          
898                Activate Package();        
899          
900                SavePack ages();        
901           }        
902           pr ivate void  LoadWebRe sourceInfo s()        
903           {        
904                if (Acti vePackage  == null)        
905                    retu rn;        
906          
907                //As alw ays, clear  the colle ction firs t.        
908                WebResou rceInfos.C lear();        
909                WebResou rceInfosSe lected.Cle ar();        
910          
911                var webR esourceInf os = Activ ePackage.E lements("W ebResource Info");        
912          
913                if (webR esourceInf os != null )        
914                {        
915                    fore ach (var w r in webRe sourceInfo s)        
916                    {        
917                         WebResourc eInfos.Add (wr);        
918                    }        
919                }        
920           }        
921           pr ivate void  SearchAnd PopulateFi les()        
922           {        
923                if (Acti vePackage  == null)        
924                    retu rn;        
925          
926                string s earchText  = FileSear chText; // Find all f iles        
927          
928                string r ootPath =  ActivePack age.Attrib ute("rootP ath").Valu e;        
929                Discover Files(root Path, sear chText);        
930          
931           }        
932          
933           // Misc        
934           pr ivate void  ShowBrows eFolderDia log()        
935           {        
936                System.W indows.For ms.FolderB rowserDial og dlgWRFo lder = new  System.Wi ndows.Form s.FolderBr owserDialo g()        
937                {        
938                    Desc ription =  "Select th e folder c ontaining  the potent ial Web Re source fil es",        
939                    Show NewFolderB utton = fa lse        
940                };        
941                if (dlgW RFolder.Sh owDialog()  == System .Windows.F orms.Dialo gResult.OK )        
942                {                         
943                    IsAc tivePackag eDirty = f alse;        
944          
945                    //Be cause Web  Resources  are relati ve to the  root path,          
946                    //al l the curr ent Web Re sourceInfo s should b e cleared        
947                    WebR esourceInf os.Clear() ;        
948                    WebR esourceInf osSelected .Clear();        
949          
950                    //Ch ange the r ootpath an d notify a ll binding s        
951                    Acti vePackage. Attribute( "rootPath" ).Value =  dlgWRFolde r.Selected Path;        
952                    OnPr opertyChan ged("Activ ePackage") ;        
953          
954                    //Au to-save        
955                    Save Packages() ;        
956          
957                    //Di splay new  files        
958                    Sear chAndPopul ateFiles() ;        
959                }        
960           }        
961           pr ivate void  DiscoverF iles(strin g rootPath , string s earchText)        
962           {        
963                CurrentF iles.Clear ();        
964                CurrentF ilesSelect ed.Clear() ;        
965          
966                if (root Path != St ring.Empty )        
967                {        
968                    Dire ctoryInfo  di = new D irectoryIn fo(rootPat h);        
969          
970                    var  files = di .Enumerate Files("*",  SearchOpt ion.AllDir ectories)        
971                         .Where(f = > Resource Extensions .ValidExte nsions.Con tains(f.Ex tension))        
972                         .Where(f = > f.Name ! = PACKAGES _FILENAME) ;                         
973          
974                    if ( !string.Is NullOrWhit eSpace(sea rchText))        
975                    {        
976                         files = fi les.Where( f => f.Ful lName.Cont ains(searc hText));        
977                    }        
978          
979                    fore ach (FileI nfo f in f iles)        
980                    {        
981                         CurrentFil es.Add(f);                              
982                    }        
983                    OnPr opertyChan ged("Curre ntFiles");        
984                }        
985           }        
986           pr ivate void  AddFilesT oWebResour ces(object  parameter )        
987           {        
988                //Set th e ActivePa ckage as D irty.         
989                IsActive PackageDir ty = true;        
990          
991                //Clear  the collec tion of se lected fil es        
992                CurrentF ilesSelect ed.Clear() ;        
993          
994                //List<F ileInfo> s electedFil es = new L ist<FileIn fo>();        
995                if (para meter != n ull && par ameter is  IEnumerabl e)        
996                {        
997                    fore ach (var f ileInfo in  (IEnumera ble)parame ter)        
998                    {        
999                         CurrentFil esSelected .Add((File Info)fileI nfo);        
1000                    }        
1001                }        
1002          
1003                if (Curr entFilesSe lected.Cou nt > 0)        
1004                {        
1005                    fore ach (FileI nfo fi in  CurrentFil esSelected )        
1006                    {        
1007                         //Add it t o the list  of web re source inf o, if not  already th ere.        
1008                         //The matc hing crite ria will b e the ?        
1009                                
1010                         XElement n ewInfo = C onvertFile InfoToWebR esourceInf o(fi);        
1011          
1012                         if (WebRes ourceInfos .Where(w = > w.Attrib ute("fileP ath").Valu e == newIn fo.Attribu te("filePa th").Value ).Count()  == 0)        
1013                         {        
1014                             WebRes ourceInfos .Add(newIn fo);                                  
1015                         }        
1016                         else        
1017                         {        
1018                             //it's  already i n the list ! do nothi ng.        
1019                         }        
1020                    }                          
1021                }        
1022           }        
1023           pr ivate void  DeleteSel ectedWebRe sources(ob ject param eter)        
1024           {        
1025                //Set th e ActivePa ckage as D irty.         
1026                IsActive PackageDir ty = true;        
1027          
1028                WebResou rceInfosSe lected.Cle ar();        
1029          
1030                if (para meter != n ull && par ameter is  IEnumerabl e)        
1031                {        
1032                    //Li sts allow  the ForEac h extensio n method g ood for        
1033                    //re moving ite ms of a co llection.  Looping th rough an         
1034                    //en umerable c aused inde xing error s after th e first        
1035                    //it eration.        
1036                    List <XElement>  infosToDe lete = new  List<XEle ment>();        
1037          
1038                    fore ach (var w r in (IEnu merable)pa rameter)        
1039                    {        
1040                         infosToDel ete.Add((X Element)wr );        
1041                    }        
1042          
1043                    info sToDelete. ForEach(in fo => WebR esourceInf os.Remove( info));        
1044                }        
1045           }        
1046           pr ivate XEle ment Conve rtFileInfo ToWebResou rceInfo(Fi leInfo fi)        
1047           {        
1048                var x =  fi.Extensi on.Split(' .');        
1049                string t ype = x[x. Length - 1 ].ToLower( );        
1050          
1051                String n ame = fi.F ullName.Re place(Acti vePackage. Attribute( "rootPath" ).Value.Re place("/",  "\\"), St ring.Empty );        
1052          
1053                XElement  newWebRes ourceInfo  = new XEle ment("WebR esourceInf o",        
1054                    new  XAttribute ("name", n ame.Replac e("\\", "/ ")),        
1055                    new  XAttribute ("filePath ", name),        
1056                    new  XAttribute ("displayN ame", fi.N ame),        
1057                    new  XAttribute ("type", t ype),        
1058                    new  XAttribute ("descript ion", Stri ng.Empty)) ;        
1059          
1060                return n ewWebResou rceInfo;        
1061           }        
1062          
1063           pr ivate void  BeginUplo ad(object  s, DoWorkE ventArgs a rgs)        
1064           {        
1065                //Retrie ve all Web  Resources  so we can  determine  if each        
1066                //needs  be created  or update d.        
1067                var crmR esources =  RetrieveW ebResource sForActive Solution() ;        
1068          
1069                //Create  or Update  the WebRe source        
1070                if (WebR esourceInf osSelected .Count > 0 )        
1071                {        
1072                    _pro gressMessa ge.Clear() ;        
1073                    AddM essage(Str ing.Format ("Processi ng {0} Web  Resources ...", WebR esourceInf osSelected .Count.ToS tring()));        
1074                    int  i = 1;        
1075          
1076                    fore ach (XElem ent fi in  WebResourc eInfosSele cted)        
1077                    {        
1078                         string nam e = GetWeb ResourceFu llNameIncl udingPrefi x(fi);        
1079                                
1080                         AddMessage (String.Em pty);        
1081                         AddMessage (i.ToStrin g() + ") "  + name);        
1082          
1083                         if (IsWebR esourceNam eValid(nam e))        
1084                         {        
1085                             //If t he Unmanag ed Solutio n already  contains t he Web Res ource,        
1086                             //do a n Update.        
1087                             var re sourceThat MayExist =  crmResour ces.Where( w => w.Nam e == name) .FirstOrDe fault();        
1088                             if (re sourceThat MayExist ! = null)        
1089                             {        
1090                                 Ad dMessage(" Already ex ists. Upda ting...");        
1091                                 Up dateWebRes ource(fi,  resourceTh atMayExist );        
1092                                 Ad dMessage(" Done.");        
1093                             }        
1094                             //If n ot, create  the Web R esource an d a Soluti on Compone nt.        
1095                             else        
1096                             {        
1097                                 Ad dMessage(" Doesn't ex ist. Creat ing...");        
1098                                 Cr eateWebRes ource(fi);        
1099                                 Ad dMessage(" Done.");        
1100                             }        
1101                         }        
1102                         else        
1103                         {        
1104                             AddMes sage(VALID _NAME_MSG) ;        
1105                         }        
1106          
1107                         i++;        
1108                    }        
1109                            
1110                    AddM essage(Str ing.Empty) ;        
1111                    AddM essage("Do ne process ing files. ");        
1112          
1113                    //Al l WebResou rces shoul d be in. P ublish all .        
1114                    if ( ShouldPubl ishAllAfte rUpload)        
1115                    {        
1116                         AddMessage (String.Em pty);        
1117                         AddMessage ("You chos e to publi sh all cus tomization s. Please  be patient  as it may  take a fe w minutes  to complet e.");        
1118                         PublishAll ();        
1119                    }        
1120                    else        
1121                    {        
1122                         AddMessage (String.Em pty);        
1123                         AddMessage ("You chos e not to p ublish all  customiza tions.");        
1124                    }        
1125                    AddM essage("Pr ocess comp lete!");                          
1126                }        
1127           }        
1128           pr ivate void  UploadWeb Resources( object par ameter)        
1129           {        
1130                IsOutput WindowDisp layed = tr ue;        
1131                AreAllBu ttonsEnabl ed = false ;        
1132          
1133                //Clear  the collec tion of se lected Web  Resources        
1134                WebResou rceInfosSe lected.Cle ar();        
1135          
1136                if (para meter != n ull && par ameter is  IEnumerabl e)        
1137                {        
1138                    fore ach (var w ebResource  in (IEnum erable)par ameter)        
1139                    {        
1140                         WebResourc eInfosSele cted.Add(( XElement)w ebResource );        
1141                    }        
1142                }        
1143                worker.R unWorkerAs ync(WebRes ourceInfos Selected);        
1144           }                 
1145           pr ivate void  UploadAll WebResourc es()        
1146           {        
1147                UploadWe bResources (WebResour ceInfos);                      
1148           }        
1149          
1150           pr ivate bool  CanUpload WebResourc e()        
1151           {        
1152                if (Acti veConfigur ation != n ull &&        
1153                    Acti veSolution  != null & &        
1154                    Acti vePublishe r != null  &&        
1155                    Acti vePackage  != null)        
1156                {        
1157                    retu rn true;        
1158                }        
1159                return f alse;        
1160           }        
1161           pr ivate void  PublishAl l()        
1162           {        
1163                try        
1164                {        
1165                    AddM essage(Str ing.Empty) ;        
1166                    AddM essage("Pu blishing a ll customi zations... ");             
1167                            
1168                    Publ ishAllXmlR equest pub lishReques t = new Pu blishAllXm lRequest() ;        
1169                    var  response =  (PublishA llXmlRespo nse)_servi ceProxy.Ex ecute(publ ishRequest );        
1170          
1171                    AddM essage("Do ne.");        
1172                }        
1173                catch (E xception e )        
1174                {        
1175                    AddM essage("Er ror publis hing: " +  e.Message) ;        
1176                }        
1177           }                 
1178           pr ivate IEnu merable<We bResource>  RetrieveW ebResource sForActive Solution()        
1179           {        
1180                //The fo llowing qu ery finds  all WebRes ources tha t are Solu tionCompon ents for        
1181                //the Ac tiveSoluti on. Simply  querying  WebResourc es does no t retrieve  the desir ed        
1182                //result s. Additio nally, whe n creating  WebResour ces, you m ust create  a Solutio nComponent        
1183                //if att aching to  any unmana ged soluti on other t han the "D efault Sol ution."        
1184                var webR esources =  from wr i n _orgCont ext.Create Query<WebR esource>()        
1185                                     join sc i n _orgCont ext.Create Query<Solu tionCompon ent>()        
1186                                       on wr.W ebResource Id equals  sc.ObjectI d        
1187                                     where wr. IsManaged  == false        
1188                                     where wr. IsCustomiz able.Value  == true        
1189                                     where sc. ComponentT ype.Value  == (int)co mponenttyp e.WebResou rce        
1190                                     where sc. SolutionId .Id == Act iveSolutio n.Solution Id.Value        
1191                                     select ne w WebResou rce        
1192                                     {        
1193                                           Web ResourceTy pe = wr.We bResourceT ype,        
1194                                           Web ResourceId  = wr.WebR esourceId,        
1195                                           Dis playName =  wr.Displa yName,        
1196                                           Nam e = wr.Nam e,        
1197                                           //  Content =  wr.Content , Removed  to improve  performan ce        
1198                                           Des cription =  wr.Descri ption        
1199                                     };        
1200          
1201                return w ebResource s.AsEnumer able();        
1202           }        
1203           pr ivate void  CreateWeb Resource(X Element we bResourceI nfo)        
1204           {        
1205                        
1206                    try        
1207                    {        
1208                         //Create t he Web Res ource.        
1209                         WebResourc e wr = new  WebResour ce()        
1210                         {        
1211                             Conten t = getEnc odedFileCo ntents(Act ivePackage .Attribute ("rootPath ").Value +  webResour ceInfo.Att ribute("fi lePath").V alue),        
1212                             Displa yName = we bResourceI nfo.Attrib ute("displ ayName").V alue,        
1213                             Descri ption = we bResourceI nfo.Attrib ute("descr iption").V alue,        
1214                             Logica lName = We bResource. EntityLogi calName,        
1215                             Name =  GetWebRes ourceFullN ameIncludi ngPrefix(w ebResource Info)        
1216          
1217                         };        
1218          
1219                         wr.WebReso urceType =  new Optio nSetValue( (int)Resou rceExtensi ons.Conver tStringExt ension(web ResourceIn fo.Attribu te("type") .Value));        
1220          
1221                         //Special  cases attr ibutes for  different  web resou rce types.        
1222                         switch (wr .WebResour ceType.Val ue)        
1223                         {        
1224                             case ( int)Resour ceExtensio ns.WebReso urceType.S ilverlight :        
1225                                 wr .Silverlig htVersion  = "4.0";        
1226                                 br eak;        
1227                         }        
1228          
1229                         // ActiveP ublisher.C ustomizati onPrefix +  "_/" + Ac tivePackag e.Attribut e("name"). Value + we bResourceI nfo.Attrib ute("name" ).Value.Re place("\\" , "/"),        
1230                         Guid theGu id = _serv iceProxy.C reate(wr);        
1231          
1232                         //If not t he "Defaul t Solution ", create  a Solution Component  to assure  it gets        
1233                         //associat ed with th e ActiveSo lution. We b Resource s are auto matically  added        
1234                         //as Solut ionCompone nts to the  Default S olution.        
1235                         if (Active Solution.U niqueName  != "Defaul t")        
1236                         {        
1237                             AddSol utionCompo nentReques t scReques t = new Ad dSolutionC omponentRe quest();        
1238                             scRequ est.Compon entType =  (int)compo nenttype.W ebResource ;        
1239                             scRequ est.Soluti onUniqueNa me = Activ eSolution. UniqueName ;        
1240                             scRequ est.Compon entId = th eGuid;        
1241                             var re sponse = ( AddSolutio nComponent Response)_ servicePro xy.Execute (scRequest );        
1242                         }        
1243                    }        
1244                    catc h (Excepti on e)        
1245                    {        
1246                         AddMessage ("Error: "  + e.Messa ge);        
1247                         return;        
1248                    }                     
1249                        
1250           }        
1251           pr ivate void  UpdateWeb Resource(X Element we bResourceI nfo, WebRe source exi stingResou rce)        
1252           {        
1253                try        
1254                {        
1255                    //Th ese are th e only 3 t hings that  should (c an) change .        
1256                    WebR esource wr  = new Web Resource()        
1257                    {        
1258                         Content =  getEncoded FileConten ts(ActiveP ackage.Att ribute("ro otPath").V alue + web ResourceIn fo.Attribu te("filePa th").Value ),        
1259                         DisplayNam e = webRes ourceInfo. Attribute( "displayNa me").Value ,        
1260                         Descriptio n = webRes ourceInfo. Attribute( "descripti on").Value        
1261                    };        
1262                    wr.W ebResource Id = exist ingResourc e.WebResou rceId;        
1263                    _ser viceProxy. Update(wr) ;        
1264          
1265                }        
1266                catch (E xception e )        
1267                {        
1268                    AddM essage("Er ror: " + e .Message);        
1269                    retu rn;        
1270                }        
1271           }        
1272           pr ivate stri ng getEnco dedFileCon tents(Stri ng pathToF ile)        
1273           {        
1274                FileStre am fs = ne w FileStre am(pathToF ile, FileM ode.Open,  FileAccess .Read);        
1275                byte[] b inaryData  = new byte [fs.Length ];        
1276                long byt esRead = f s.Read(bin aryData, 0 , (int)fs. Length);        
1277                fs.Close ();        
1278                return S ystem.Conv ert.ToBase 64String(b inaryData,  0, binary Data.Lengt h);        
1279           }        
1280           pr ivate stri ng GetWebR esourceFul lNameInclu dingPrefix (XElement  webResourc eInfo)        
1281           {        
1282                //The We b Resource  name alwa ys starts  with the P ublisher's  Prefix        
1283                //i.e.,  "new_"        
1284                string n ame = Acti vePublishe r.Customiz ationPrefi x + "_";        
1285          
1286                //Check  to see if  the user h as chosen  to add the  Package N ame as par t of the         
1287                //prefix .        
1288                if (!Str ing.IsNull OrWhiteSpa ce(ActiveP ackage.Att ribute("is NamePrefix ").Value)  &&        
1289                    Bool ean.Parse( ActivePack age.Attrib ute("isNam ePrefix"). Value) ==  true)        
1290                {        
1291                    name  += "/" +  ActivePack age.Attrib ute("name" ).Value;        
1292                }        
1293                             
1294                //Finall y add the  name on to  the prefi x        
1295                name +=  webResourc eInfo.Attr ibute("nam e").Value;        
1296          
1297                return n ame;        
1298           }        
1299           pr ivate bool  IsWebReso urceNameVa lid(string  name)        
1300           {        
1301                Regex in ValidWRNam eRegex = n ew Regex(" [^a-z0-9A- Z_\\./]|[/ ]{2,}",         
1302                    (Reg exOptions. Compiled |  RegexOpti ons.Cultur eInvariant ));        
1303          
1304                bool res ult = true ;        
1305          
1306                //Test v alid chara cters        
1307                if (inVa lidWRNameR egex.IsMat ch(name))        
1308                {        
1309                    AddM essage(VAL ID_NAME_MS G);        
1310                    resu lt = false ;        
1311                }        
1312          
1313                //Test l ength        
1314                //Remove  the custo mization p refix and  leading _         
1315                if (name .Remove(0,  ActivePub lisher.Cus tomization Prefix.Len gth + 1).L ength > 10 0)        
1316                {        
1317                    AddM essage("ER ROR: Web R esource na me must be  <= 100 ch aracters." );        
1318                    resu lt = false ;        
1319                }        
1320             
1321                return r esult;        
1322           }        
1323           pr ivate void  AddMessag e(string m sg)        
1324           {        
1325                //Assure s that thi s happens  on the UI  thread        
1326                this.Beg inInvoke(( ) =>        
1327                {        
1328                    Prog ressMessag e = msg;        
1329                });        
1330           }        
1331          
1332           #e ndregion        
1333          
1334                   
1335       }        
1336   }