示例#1
0
 public void CreateMashup(VisualizerDialogLauncher visualizerDialog, TypeVisualizerMap typeVisualizerMap)
 {
     if (visualizerDialog != null && Visualizer.Value is DialogMashupVisualizer dialogMashup)
     {
         var dialogMashupType = dialogMashup.GetType();
         var visualizerType   = visualizerDialog.VisualizerType;
         var mashupVisualizer = GetMashupVisualizerType(dialogMashupType, visualizerType, typeVisualizerMap);
         if (mashupVisualizer != null)
         {
             UnloadMashups();
             var visualizerMashup = (MashupTypeVisualizer)Activator.CreateInstance(mashupVisualizer);
             dialogMashup.Mashups.Add(new VisualizerMashup(visualizerDialog.visualizerSource, visualizerMashup));
             ReloadMashups();
         }
     }
 }
示例#2
0
        public static VisualizerDialogLauncher CreateVisualizerLauncher(
            InspectBuilder source,
            VisualizerLayout visualizerLayout,
            TypeVisualizerMap typeVisualizerMap,
            ExpressionBuilderGraph workflow,
            Editor.GraphView.WorkflowGraphView workflowGraphView = null)
        {
            var inspectBuilder = ExpressionBuilder.GetVisualizerElement(source);

            if (inspectBuilder.ObservableType == null || !inspectBuilder.PublishNotifications)
            {
                return(null);
            }

            Type visualizerType        = null;
            var  deserializeVisualizer = false;
            Func <DialogTypeVisualizer> visualizerFactory = null;
            var layoutSettings  = visualizerLayout.GetLayoutSettings(source);
            var visualizerTypes = typeVisualizerMap.GetTypeVisualizers(inspectBuilder);

            if (layoutSettings != null && !string.IsNullOrEmpty(layoutSettings.VisualizerTypeName))
            {
                visualizerType = visualizerTypes.FirstOrDefault(type => type.FullName == layoutSettings.VisualizerTypeName);
                if (visualizerType != null && layoutSettings.VisualizerSettings != null)
                {
                    var root = layoutSettings.VisualizerSettings;
                    root.SetAttributeValue(XsdAttributeName, XsdAttributeValue);
                    root.SetAttributeValue(XsiAttributeName, XsiAttributeValue);
                    var serializer = new XmlSerializer(visualizerType);
                    using (var reader = layoutSettings.VisualizerSettings.CreateReader())
                    {
                        if (serializer.CanDeserialize(reader))
                        {
                            var visualizer = (DialogTypeVisualizer)serializer.Deserialize(reader);
                            visualizerFactory     = () => visualizer;
                            deserializeVisualizer = true;
                        }
                    }
                }
            }

            visualizerType ??= visualizerTypes.FirstOrDefault();
            if (visualizerType == null)
            {
                return(null);
            }

            if (visualizerFactory == null)
            {
                var visualizerActivation = Expression.New(visualizerType);
                visualizerFactory = Expression.Lambda <Func <DialogTypeVisualizer> >(visualizerActivation).Compile();
            }

            var launcher = new VisualizerDialogLauncher(visualizerType, inspectBuilder, visualizerFactory, workflow, source, workflowGraphView);

            launcher.Text = source != null?ExpressionBuilder.GetElementDisplayName(source) : null;

            if (deserializeVisualizer)
            {
                launcher = launcher.Visualizer.Value != null ? launcher : null;
            }
            return(launcher);
        }