private async Task <FrameworkElement> GetWiringDiagramUI(string customerId)
        {
            FrameworkElement wiringDiagramUI = null;

            var wiringDiagramConfig = _wiringDiagramService.GetWiringDiagramConfig(customerId);
            var displayDiagramList  = wiringDiagramConfig.Where(d => d.isDisplay == 1);
            var mainDiagram         = wiringDiagramConfig.FirstOrDefault(d => d.isMain == 1);

            if (!Directory.Exists(WIRING_DIAGRAM_PATH))
            {
                Directory.CreateDirectory(WIRING_DIAGRAM_PATH);
            }

            IEnumerable <Task <bool> > downloadFileTasksQuery =
                from diagram in displayDiagramList
                select DownloadMediaFileAsync(diagram.filePath.Replace('\\', '/'), Path.Combine(WIRING_DIAGRAM_PATH, GetFileName(diagram.filePath)));

            Task <bool>[] downloadTasks       = downloadFileTasksQuery.ToArray();
            bool[]        downloadFileResults = await Task.WhenAll(downloadTasks);

            string targetMainFileName = Path.Combine(WIRING_DIAGRAM_PATH, GetFileName(mainDiagram.filePath));

            //bool downloadResult = await DownloadMediaFileAsync(mainDiagram.filePath, targetFileName);

            if (downloadFileResults.Any())
            {
                //Uri uri = new Uri(mainDiagram.filePath);
                //var fileName = uri.Segments[uri.Segments.Length - 1];
                //var dataBuffer = GetWiringDiagram(uri);
                XamlUI xamlUI = null;
                xamlUI = _uiManager.Load(targetMainFileName);
                if (xamlUI != null)
                {
                    Application.Current.Dispatcher.Invoke(new Action(() =>
                    {
                        var viewBox     = new Viewbox();
                        viewBox.Stretch = System.Windows.Media.Stretch.Fill;
                        if (xamlUI.UI.Parent != null)
                        {
                            (xamlUI.UI.Parent as Viewbox).Child = null;
                        }
                        viewBox.Child = xamlUI.UI;
                        xamlUI.UI.MouseLeftButtonUp   += UI_MouseLeftButtonUp;
                        xamlUI.UI.MouseLeftButtonDown += UI_MouseLeftButtonDown;
                        xamlUI.UI.MouseWheel          += UI_MouseWheel;
                        wiringDiagramUI = viewBox;
                    }));
                    foreach (var item in xamlUI.Identities)
                    {
                        if (!_keys.Contains(item))
                        {
                            _keys.Add(item);
                        }
                    }
                }
            }
            return(wiringDiagramUI);
        }
        private void UI_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            var targetElement = e.OriginalSource as TextBlock;

            if (targetElement != null && !string.IsNullOrEmpty(targetElement.Text))
            {
                string targetFileName = Path.Combine(WIRING_DIAGRAM_PATH, targetElement.Text.Trim() + ".xml");
                XamlUI xamlUI         = null;
                Application.Current.Dispatcher.Invoke(new Action(() =>
                {
                    xamlUI = _uiManager.Load(targetFileName);
                    if (xamlUI != null)
                    {
                        var viewBox     = new Viewbox();
                        viewBox.Stretch = System.Windows.Media.Stretch.Fill;
                        if (xamlUI.UI.Parent != null)
                        {
                            (xamlUI.UI.Parent as Viewbox).Child = null;
                        }
                        viewBox.Child = xamlUI.UI;
                        xamlUI.UI.MouseLeftButtonUp   += UI_MouseLeftButtonUp;
                        xamlUI.UI.MouseLeftButtonDown += UI_MouseLeftButtonDown;
                        xamlUI.UI.MouseWheel          += UI_MouseWheel;
                        foreach (var item in xamlUI.Identities)
                        {
                            if (!_keys.Contains(item))
                            {
                                _keys.Add(item);
                            }
                        }
                        SubscriberToCurrentData();
                        WiringDiagramUI = viewBox;
                    }
                }));
            }
            //throw new NotImplementedException();
        }