/// <summary>
        /// Fires the BioPatML Repository Web service to grab our desire BioPatML pattern.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="type"></param>
        public void GetWebPatternDetail(String id, String type)
        {
            #region Code for the blue "Loading" visual effect

            txtLoading.Visibility = System.Windows.Visibility.Visible;
            BlinkLoading.RepeatBehavior = RepeatBehavior.Forever;
            BlinkLoading.Begin();

            DefinitionInfo definition = new DefinitionInfo()
            {
                MainPatternId = id,
                MainPatternType = type
            };
            #endregion Code for the blue "Loading" visual effect

            #region Code for the background worker to invoke our BioPatML repository service
            bw.DoWork += delegate(object s, DoWorkEventArgs args)
            {
                #region Initialize all the essential variables 

                DefinitionInfo target = (DefinitionInfo)args.Argument;
                bool done = false; 
                string result = string.Empty; 
                BioPatMLDataRepo.BioPatMLDataServiceClient repository = new BioPatMLDataServiceClient();
                
                #endregion

                repository.GetPatternDetailInfoCompleted += delegate
                    (object sender, GetPatternDetailInfoCompletedEventArgs e)
                {
                    //When finish retrieving data we assign the BioPatML String to the result variable
                    result = e.Result.ToString();
                    done = true;
                };

                //Fires the web service and pass in a definition which contains the pattern Id and its type
                repository.GetPatternDetailInfoAsync(target);

                while (!done) { System.Threading.Thread.Sleep(2000); };

                repository.CloseAsync(); //close the service
                repository = null; //clean up resources
                args.Result = result;
            };
            #endregion #region Code for the background worker to invoke our BioPatML repository service

            //When worker has finished its job
            //we want him to remake our repository treeview n end all visual effects
            bw.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs args)
            {
                ReconstructTreeView(currBioPatMLStr = args.Result.ToString());
                #region End the blinking loading  effect
                txtLoading.Visibility = System.Windows.Visibility.Collapsed;
                BlinkLoading.Stop();
                #endregion
            };

            bw.RunWorkerAsync(definition);
        }
        /// <summary>
        /// This method is invoked by the UI when there is a need to populate the 
        /// "available pattern treeview"
        /// </summary>
        public void GetRepositoryStructure()
        {
            //Initialisation
            txtLoading.Visibility = System.Windows.Visibility.Visible;
            BlinkingAction.RepeatBehavior = RepeatBehavior.Forever;
            BlinkingAction.Begin();
            
            //Background worker do work method
            bw.DoWork += delegate(object s, DoWorkEventArgs args)
            {
                bool done = false;
                List<DefinitionPatternInfo> resultTray = new List<DefinitionPatternInfo>();
                BioPatMLDataRepo.BioPatMLDataServiceClient repository = new BioPatMLDataServiceClient();
                repository.GetALLDefPatternInfoCompleted += delegate
                    (object sender, GetALLDefPatternInfoCompletedEventArgs e)
                {
                    //Do something
                    resultTray = e.Result as List<DefinitionPatternInfo>;
                    done = true;
                };

                repository.GetALLDefPatternInfoAsync();

                while (!done) { System.Threading.Thread.Sleep(2000); };

                repository.CloseAsync(); //close the service
                repository = null; //clean up resources
                args.Result = resultTray;

            };

            bw.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs args)
            {
                patterns = args.Result as List<DefinitionPatternInfo>;
                txtLoading.Visibility = System.Windows.Visibility.Collapsed;
                cpiedUnits = RepositoryUnit.CreateRepositoryData(patterns).Copy();
                ConstructTreeView(RepositoryUnit.CreateRepositoryData(patterns));
                BlinkingAction.Stop();
            };

            bw.RunWorkerAsync();
            
        }