// These methods are not used, but they are very useful when developing the Design experience
#if Development

        /// <summary>
        ///     Adds a default column for each property in the data source
        /// </summary>
        public static void GenerateColumns(ModelItem dataGridModelItem, EditingContext context)
        {
            using (ModelEditingScope scope = dataGridModelItem.BeginEdit(Properties.Resources.Generate_Columns))
            {

                // Set databinding related properties
                DataGridDesignHelper.SparseSetValue(dataGridModelItem.Properties[MyPlatformTypes.DataGrid.AutoGenerateColumnsProperty], false);

                // Get the datasource 
                object dataSource = dataGridModelItem.Properties[MyPlatformTypes.DataGrid.ItemsSourceProperty].ComputedValue;
                if (dataSource != null)
                {

                    foreach (ColumnInfo columnGenerationInfo in DataGridDesignHelper.GetColumnGenerationInfos(dataSource))
                    {

                        ModelItem dataGridColumn = null;

                        dataGridColumn = DataGridDesignHelper.CreateDefaultDataGridColumn(context, columnGenerationInfo);

                        if (dataGridColumn != null)
                        {
                            dataGridModelItem.Properties[MyPlatformTypes.DataGrid.ColumnsProperty].Collection.Add(dataGridColumn);
                        }
                    }
                }
                scope.Complete();
            }
        }
        /// <summary>
        ///     Creates a DataGridColumn derived ModelItem
        /// </summary>
        internal static ModelItem CreateColumnFromColumnType(EditingContext context, TypeIdentifier dataGridColumnTypeId, ColumnInfo columnGenerationInfo)
        {
            ModelItem dataGridColumn = ModelFactory.CreateItem(context, dataGridColumnTypeId);
            if (columnGenerationInfo.HeaderFromAttribute == null)
            {
                // Default the Header to the property name if there's no attribute tied to it
                dataGridColumn.Properties[PlatformTypes.DataGridColumn.HeaderProperty].SetValue(columnGenerationInfo.PropertyInfo.Name);
            }

            if (dataGridColumnTypeId == PlatformTypes.DataGridTemplateColumn.TypeId)
            {
                return CreateTemplateColumn(context, columnGenerationInfo, dataGridColumn);
            }

            ModelItem binding = ModelFactory.CreateItem(context, PlatformTypes.Binding.TypeId);
            binding.Properties[PlatformTypes.Binding.PathProperty].SetValue(columnGenerationInfo.PropertyInfo.Name);

            // ReadOnly Properties are handled by the runtime so we don't need to alter the Binding here
            // to account for them.

            // Whether or not a column can sort is handled by the runtime as well

            dataGridColumn.Properties[PlatformTypes.DataGridBoundColumn.BindingProperty].SetValue(binding);

            return dataGridColumn;
        }
 /// <summary>
 ///     Removes all columns from the DataGrid
 /// </summary>
 public static void RemoveColumns(ModelItem dataGridModelItem, EditingContext editingContext)
 {
     using (ModelEditingScope scope = dataGridModelItem.BeginEdit(Properties.Resources.Remove_Columns))
     {
         dataGridModelItem.Properties[MyPlatformTypes.DataGrid.ColumnsProperty].Collection.Clear();
         scope.Complete();
     }
 }
 public bool Initialize(ModelItem modelItem)
 {
     this.baseModelItem = modelItem;
     if (null != modelItem)
     {
         this.context = modelItem.GetEditingContext();
     }
     return (null != this.baseModelItem);
 }
 /// <summary>
 ///     Create a DataTemplate for the given control bound to the given data source property
 /// </summary>
 internal static ModelItem CreateDataTemplate(EditingContext context, TypeIdentifier controlToTemplateTypeId, PropertyIdentifier controlPropertyId, string datasourcePropertyName)
 {
     ModelItem controlToTemplate = ModelFactory.CreateItem(context, controlToTemplateTypeId);
     ModelItem controlBinding = ModelFactory.CreateItem(context, PlatformTypes.Binding.TypeId);
     controlBinding.Properties[PlatformTypes.Binding.PathProperty].SetValue(datasourcePropertyName);
     controlToTemplate.Properties[controlPropertyId].SetValue(controlBinding);
     ModelItem dataTemplate = ModelFactory.CreateItem(context, PlatformTypes.DataTemplate.TypeId);
     dataTemplate.Content.SetValue(controlToTemplate);
     return dataTemplate;
 }
        /// <summary>
        ///     Creates a DataGridTemplateColumn ModelItem with default templates for this property
        /// </summary>
        internal static ModelItem CreateTemplateColumn(EditingContext context, ColumnInfo columnGenerationInfo, ModelItem dataGridColumn)
        {
            ModelItem displayDataTemplate = CreateDataTemplate(context, PlatformTypes.TextBlock.TypeId, PlatformTypes.TextBlock.TextProperty, columnGenerationInfo.PropertyInfo.Name);
            dataGridColumn.Properties[PlatformTypes.DataGridTemplateColumn.CellTemplateProperty].SetValue(displayDataTemplate);

            ModelItem editingDataTemplate = CreateDataTemplate(context, PlatformTypes.TextBox.TypeId, PlatformTypes.TextBox.TextProperty, columnGenerationInfo.PropertyInfo.Name);
            dataGridColumn.Properties[PlatformTypes.DataGridTemplateColumn.CellEditingTemplateProperty].SetValue(editingDataTemplate);

            return dataGridColumn;
        }
 public ErrorsMarkedEventArgs(ICollection<ValidationError> errors,
     ValidationReason reason,
     ModelTreeManager modelTreeManager,
     EditingContext context)
 {
     this.errors = errors;
     this.reason = reason;
     this.modelTreeManager = modelTreeManager;
     this.context = context;
 }
        /// <summary>
        /// TabControl initializer.
        /// </summary>
        /// <param name="item">Model item for a TabControl.</param>
        /// <param name="context">Editing context.</param>
        public override void InitializeDefaults(ModelItem item, EditingContext context)
        {
            // Use SparseSetValue to avoid setting values to their defaults
            Util.SparseSetValue(item.Properties[MyPlatformTypes.FrameworkElement.WidthProperty], 200d);
            Util.SparseSetValue(item.Properties[MyPlatformTypes.FrameworkElement.HeightProperty], 100d);

            // Add a default TabItem
            ModelItem newTabItem = ModelFactory.CreateItem(context, MyPlatformTypes.TabItem.TypeId, CreateOptions.InitializeDefaults);
            item.Content.Collection.Add(newTabItem);
        }
 internal static bool DoesParentAlwaysCollapseChildren(ModelItem modelItem, EditingContext context)
 {
     bool parentAlwaysCollapsesChild = false;
     Type parentDesignerType = GetParentDesignerType(modelItem, context);
     if (typeof(WorkflowViewElement).IsAssignableFrom(parentDesignerType))
     {
         ActivityDesignerOptionsAttribute options = WorkflowViewService.GetAttribute<ActivityDesignerOptionsAttribute>(parentDesignerType);
         parentAlwaysCollapsesChild = (options != null && options.AlwaysCollapseChildren);
     }
     return parentAlwaysCollapsesChild;
 }
        internal EditDataGridColumnsUserInterface(EditingContext context, DataGridColumnModel dataGridColumnModel, DataSourcePropertyModelCollection dataSourceProperties)
            : this() 
        {
            _dataSourceProperties = dataSourceProperties;
            _dataGridColumnModel = dataGridColumnModel;
            _context = context;

            this.DataContext = dataGridColumnModel;

            bindingComboBox.ItemsSource = _dataSourceProperties;
            clipboardContentBindingComboBox.ItemsSource = _dataSourceProperties;
        }
        public override void Initialize(EditingContext context, Type modelType)
        {
            Fx.Assert(
                modelType.IsGenericType && (modelType.GetGenericTypeDefinition() == VisualBasicReferenceType),
                "This Feature should only apply to VisualBasicReference<>");

            ValidationService validationService = context.Services.GetService<ValidationService>();
            if (validationService != null && WorkflowDesigner.GetTargetFramework(context).IsLessThan45())
            {                
                validationService.Settings.AdditionalConstraints.Add(VisualBasicReferenceType, new List<Constraint> { VisualBasicDesignerHelper.NameShadowingConstraint });
            }
        }
        /// <summary>
        /// Initialize a TabItem instance.
        /// </summary>
        /// <param name="item">The item to initialize. This should not be a null reference.</param>
        /// <param name="context">The editing context.</param>
        public override void InitializeDefaults(ModelItem item, EditingContext context)
        {
            // Set the default Header text and add a Grid
            Util.SparseSetValue(item.Properties[MyPlatformTypes.TabItem.HeaderProperty], item.Name);
            ModelItem grid = ModelFactory.CreateItem(context, MyPlatformTypes.Grid.TypeId, CreateOptions.None);
            item.Content.SetValue(grid);

            // Clear FrameworkElement defaults
            item.Properties[MyPlatformTypes.FrameworkElement.HeightProperty].ClearValue();
            item.Properties[MyPlatformTypes.FrameworkElement.WidthProperty].ClearValue();
            item.Properties[MyPlatformTypes.FrameworkElement.HorizontalAlignmentProperty].ClearValue();
            item.Properties[MyPlatformTypes.FrameworkElement.VerticalAlignmentProperty].ClearValue();
        }
        // Get the first parent ModelItem that has a view
        internal static ModelItem GetParentModelItemWithView(ModelItem modelItem, EditingContext context, bool allowDrillIn)
        {
            if (modelItem == null || modelItem.Parent == null)
            {
                return null;
            }

            WorkflowViewService viewService = GetViewService(context);

            return ModelUtilities.ReverseFindFirst(modelItem.Parent, (ModelItem current) =>
                {
                    return HasView(current, viewService, allowDrillIn);
                });
        }
        internal void Initialize(EditingContext editingContext, ScrollViewer scrollViewer)
        {
            this.scrollViewer = scrollViewer;
            this.enabled = editingContext.Services.GetService<DesignerConfigurationService>().AnnotationEnabled;

            if (!this.enabled)
            {
                return;
            }

            AttachedPropertiesService attachedPropertiesService = editingContext.Services.GetService<AttachedPropertiesService>();
            AttachedProperty<string> attachedProperty = new AttachedProperty<string>
            {
                IsBrowsable = false,
                IsVisibleToModelItem = true,
                Name = Annotation.AnnotationTextPropertyName,
                OwnerType = typeof(object),
                Getter = (modelItem) =>
                {
                    string annotation = null;
                    AttachablePropertyServices.TryGetProperty<string>(modelItem.GetCurrentValue(), Annotation.AnnotationTextProperty, out annotation);
                    return annotation;
                },
                Setter = (modelItem, value) =>
                {
                    string oldValue = null;
                    AttachablePropertyServices.TryGetProperty<string>(modelItem.GetCurrentValue(), Annotation.AnnotationTextProperty, out oldValue);
                    if (oldValue == value)
                    {
                        return;
                    }

                    ModelTreeManager treeManager = modelItem.GetEditingContext().Services.GetService<ModelTreeManager>();

                    AttachablePropertyChange change = new AttachablePropertyChange()
                    {
                        Owner = modelItem,
                        AttachablePropertyIdentifier = Annotation.AnnotationTextProperty,
                        OldValue = oldValue,
                        NewValue = value,
                        PropertyName = Annotation.AnnotationTextPropertyName
                    };

                    treeManager.AddToCurrentEditingScope(change);
                }
            };

            attachedPropertiesService.AddProperty(attachedProperty);
        }
 public void EnsureInitialized(EditingContext context)
 {
     if (!initialized)
     {
         ModelService modelService = context.Services.GetService<ModelService>();                
         Fx.Assert(modelService != null, "ModelService shouldn't be null in EditingContext.");
         Fx.Assert(modelService.Root != null, "model must have a root");
         ModelItemCollection importsModelItem = modelService.Root.Properties[NamespaceListPropertyDescriptor.ImportCollectionPropertyName].Collection;
         Fx.Assert(importsModelItem != null, "root must have imports");                
         foreach (ModelItem import in importsModelItem)
         {
             this.ImportedNamespaces.Add(import.Properties[NamespaceListPropertyDescriptor.NamespacePropertyName].ComputedValue as string);
         }
     }
 }
        /// <summary>
        ///     Creates a DataGridColumn derived ModelItem based on the PropertyDescriptor's PropertyType.
        /// </summary>
        internal static ModelItem CreateDefaultDataGridColumn(EditingContext context, ColumnInfo columnGenerationInfo)
        {
            TypeIdentifier dataGridColumnTypeId;

            if (columnGenerationInfo.PropertyInfo.PropertyType == typeof(bool))
            {
                dataGridColumnTypeId = PlatformTypes.DataGridCheckBoxColumn.TypeId;
            }
            else
            {
                dataGridColumnTypeId = PlatformTypes.DataGridTextColumn.TypeId;
            }
            // Add checks here for other column types when they come online

            return CreateColumnFromColumnType(context, dataGridColumnTypeId, columnGenerationInfo);
        }
        public ModelSearchServiceImpl(WorkflowDesigner designer)
        {
            if (designer == null)
            {
                throw FxTrace.Exception.AsError(new ArgumentNullException("designer"));
            }
            this.designer = designer;
            this.editingContext = this.designer.Context;

            this.editingContext.Services.Subscribe<ModelService>(new SubscribeServiceCallback<ModelService>(this.OnModelServiceAvailable));
            this.editingContext.Services.Subscribe<DesignerView>(new SubscribeServiceCallback<DesignerView>(this.OnDesignerViewAvailable));
            this.editingContext.Services.Subscribe<ModelTreeManager>(new SubscribeServiceCallback<ModelTreeManager>(this.OnModelTreeManagerAvailable));
            this.editingContext.Items.Subscribe<Selection>(this.OnSelectionChanged);

            // At the first time, we should generate the TextImage.
            this.isModelTreeChanged = true;
        }
        /// <summary>
        ///     Opens the Edit Property-Bound Columns dialog for the given DataGrid
        /// </summary>
        public static void EditPropertyBoundColumns(ModelItem dataGridModelItem, EditingContext editingContext)
        {
            using (ModelEditingScope scope = dataGridModelItem.BeginEdit(Properties.Resources.ColumnsChanged))
            {
                PropertyColumnEditor ui = new PropertyColumnEditor(editingContext, dataGridModelItem);

                // Use Windows Forms to show the design time because Windows Forms knows about the VS message pump
                System.Windows.Forms.DialogResult result = DesignerDialog.ShowDesignerDialog(Properties.Resources.Edit_Property_Bound_Columns_Dialog_Title, ui);
                if (result == System.Windows.Forms.DialogResult.OK)
                {
                    scope.Complete();
                }
                else
                {
                    scope.Revert();
                }
            }
        }
        internal static void TryCreateImmediateEditingScopeAndExecute(EditingContext context, string editingScopeDescription, Action<EditingScope> modelEditingWork)
        {
            Fx.Assert(context != null, "context should not be null.");
            Fx.Assert(modelEditingWork != null, "modelEditingWork should not be null.");

            ModelTreeManager manager = context.Services.GetRequiredService<ModelTreeManager>();

            if (manager.CanCreateImmediateEditingScope())
            {
                using (EditingScope editingScope = manager.CreateEditingScope(editingScopeDescription, true))
                {
                    modelEditingWork(editingScope);
                }
            }
            else
            {
                modelEditingWork(null);
            }
        }
 public DisplayNameUpdater(EditingContext context)
 {
     activityBuilderDisplayNameProperty = new AttachedProperty<string>
     {
         Name = "DisplayName",
         OwnerType = typeof(ActivityBuilder),
         Getter = (modelItem) => ViewUtilities.GetActivityBuilderDisplayName(modelItem)
     };
     activityTemplateFactoryBuilderDisplayNameProperty = new AttachedProperty<string>
     {
         Name = "DisplayName",
         OwnerType = typeof(ActivityTemplateFactoryBuilder),
         Getter = (modelItem) => ViewUtilities.GetActivityBuilderDisplayName(modelItem)
     };
     AttachedPropertiesService attachedPropertiesService = context.Services.GetService<AttachedPropertiesService>();
     attachedPropertiesService.AddProperty(activityBuilderDisplayNameProperty);
     attachedPropertiesService.AddProperty(activityTemplateFactoryBuilderDisplayNameProperty);
     context.Services.GetService<ModelService>().ModelChanged += new EventHandler<ModelChangedEventArgs>(ModelChanged);
 }
            public EditorDialog(DependencyObject owner, PropertyValue propertyValue, EditingContext context, DataTemplate dialogTemplate, string title)
            {
                //setup properties
                this.MinWidth = 350;
                this.MinHeight = 185;
                this.WindowResizeMode = ResizeMode.CanResize;
                this.WindowSizeToContent = SizeToContent.Manual;

                this.Owner = owner;
                this.Context = context;
                this.Title = title;
                ContentPresenter contentPresenter = new ContentPresenter()
                {
                    Content = propertyValue,
                    //get default editor template for content presenter 
                    ContentTemplate = dialogTemplate
                };

                this.Content = contentPresenter;
                this.Loaded += OnWindowLoaded;
            }
        public TypeBrowser(AssemblyContextControlItem assemblyContext, EditingContext context, Func<Type, bool> filter)
        {
            this.assemblyContext = assemblyContext;
            this.Context = context;
            this.filter = filter;
            SetValue(GenericTypeMappingProperty, new ObservableCollection<TypeKeyValue>());
            GenericTypeMapping.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(GenericTypeMappingCollectionChanged);
            InitializeComponent();
            this.typeEntryTextBox.Focus();

            if (!size.IsEmpty)
            {
                this.Height = size.Height;
                this.Width = size.Width;
            }

            this.SizeChanged += new SizeChangedEventHandler(TypeBrowser_SizeChanged);

            this.HelpKeyword = HelpKeywords.TypeBrowser;
            this.perfEventProvider = new DesignerPerfEventProvider();
        }
        // Determines whether a particular ModelItem's view will be visible for a given breadcrumb root. 
        //It depends on whether the intermediate designers are expanded or collapsed.
        internal static bool IsViewVisible(ModelItem child, ModelItem root, EditingContext context)
        {
            if (child == root)
            {
                return !IsDefaultDesigner(context, root);
            }

            if (child.Parent == null)
            {
                return false;
            }

            WorkflowViewService viewService = GetViewService(context);
            ModelItem parent = ModelUtilities.ReverseFindFirst(child.Parent, (ModelItem current) =>
            {
                return object.Equals(current, root) ||
                    HasView(current, viewService, false) &&
                    (!IsViewExpanded(current, context) || IsDefaultDesigner(context, current));
            });

            return object.Equals(parent, root) && !IsDefaultDesigner(context, root);
        }
        public PropertyColumnEditor(EditingContext context, ModelItem dataGrid)
        {
            _dataGrid = dataGrid;
            this.EditingContext = context;

            this.Columns = new PropertyColumnDataModelCollection(this, _dataGrid);

            this.PropertyColumnsCVS = new CollectionViewSource();
            this.PropertyColumnsCVS.Source = Columns;
            this.PropertyColumnsCVS.Filter += new FilterEventHandler(PropertyColumnsCVS_Filter);

            this.DataContext = this;
            InitializeComponent();

            EnsureSelectAllChecked();
            LoadStringResources();

// WPF does not use the Display Attribute metadata
#if WPF
            MetadataCheckBox.Visibility = Visibility.Collapsed;
            MetadataTextBlock.Visibility = Visibility.Collapsed;
#endif
        }
        internal static FunctionImport CreateFunctionImport(
            EditingContext editingContext,
            EFArtifact artifact,
            Function selectedSproc,
            StorageEntityModel sModel,
            ConceptualEntityModel cModel,
            ConceptualEntityContainer cContainer,
            EntityType entityType,
            string originatingId)
        {
            FunctionImport functionImportResult = null;

            Debug.Assert(editingContext != null, "editingContext should not be null");
            Debug.Assert(artifact != null, "artifact should not be null");
            Debug.Assert(!string.IsNullOrEmpty(originatingId), "originatingId should not be null or empty");

            // show dialog appropriate to framework version
            var result = ShowNewFunctionImportDialog(
                selectedSproc,
                null /* selectedSprocName Parameter */,
                sModel,
                cModel,
                cContainer,
                DialogsResource.NewFunctionImportDialog_AddFunctionImportTitle,
                entityType);

            // if user selected OK on the dialog then create the FunctionImport
            if (DialogResult.OK == result.DialogResult)
            {
                var commands = new Collection <Command>();

                CreateComplexTypeCommand createComplexTypeCommand = null;

                // Make the decision based on what is returned by the dialog.
                // If return type is a string and result schema is not null, that means the user would like create a new complex type for the function import return.
                if (result.ReturnType is string &&
                    result.Schema != null)
                {
                    createComplexTypeCommand = CreateMatchingFunctionImportCommand.AddCreateComplexTypeCommands(
                        sModel, result.ReturnType as string, result.Schema.RawColumns, commands);
                }
                // If ReturnType is a complex type and result schema is not null, the complex type needs to be updated to be in sync with schema columns.
                else if (result.ReturnType is ComplexType &&
                         result.Schema != null)
                {
                    var complexType          = result.ReturnType as ComplexType;
                    var propertiesDictionary = complexType.Properties().ToDictionary(p => p.LocalName.Value);
                    CreateMatchingFunctionImportCommand.AddChangeComplexTypePropertiesCommands(
                        complexType, propertiesDictionary, result.Schema.RawColumns, commands);
                }

                CreateFunctionImportCommand cmdFuncImp;
                if (createComplexTypeCommand == null)
                {
                    cmdFuncImp = new CreateFunctionImportCommand(cContainer, result.Function, result.FunctionName, result.ReturnType);
                }
                else
                {
                    // Pass in the pre-req command to create complex type to the command.
                    cmdFuncImp = new CreateFunctionImportCommand(cContainer, result.Function, result.FunctionName, createComplexTypeCommand);
                }

                commands.Add(cmdFuncImp);

                // now add a FunctionImport and a FunctionImportMapping (if appropriate)
                if (artifact.MappingModel() != null &&
                    artifact.MappingModel().FirstEntityContainerMapping != null)
                {
                    var cmdFuncImpMapping = new CreateFunctionImportMappingCommand(
                        artifact.MappingModel().FirstEntityContainerMapping, result.Function, cmdFuncImp.Id);
                    cmdFuncImpMapping.AddPreReqCommand(cmdFuncImp);
                    commands.Add(cmdFuncImpMapping);

                    IDictionary <string, string> mapPropertyNameToColumnName = null;
                    if (result.Schema != null)
                    {
                        mapPropertyNameToColumnName =
                            ModelHelper.ConstructComplexTypePropertyNameToColumnNameMapping(
                                result.Schema.Columns.Select(c => c.Name).ToList());
                    }

                    // Create explicit function-import result type mapping if the return type is a complex type.
                    if (createComplexTypeCommand != null)
                    {
                        commands.Add(
                            new CreateFunctionImportTypeMappingCommand(cmdFuncImpMapping, createComplexTypeCommand)
                        {
                            CreateDefaultScalarProperties = true,
                            PropertyNameToColumnNameMap   = mapPropertyNameToColumnName
                        });
                    }
                    else if (result.ReturnType is ComplexType)
                    {
                        commands.Add(
                            new CreateFunctionImportTypeMappingCommand(cmdFuncImpMapping, result.ReturnType as ComplexType)
                        {
                            CreateDefaultScalarProperties = true,
                            PropertyNameToColumnNameMap   = mapPropertyNameToColumnName
                        });
                    }
                }

                var cp = new CommandProcessor(editingContext, originatingId, Resources.Tx_CreateFunctionImport, commands);
                cp.Invoke();

                functionImportResult = cmdFuncImp.FunctionImport;
                NavigateToFunction(functionImportResult);
            }

            return(functionImportResult);
        }
Example #26
0
 internal static Vector GetZoomRounding(EditingContext context)
 {
     return(DesignerUtilities.GetZoomRounding(DesignerView.FromContext(context)));
 }
Example #27
0
        private DrawingBrush GetIconByVisualValue()
        {
            if (this.VisualValue != null)
            {
                DrawingBrush icon          = null;
                Type         modelItemType = this.VisualValue.ItemType;
                if (modelItemType.IsGenericType)
                {
                    // If Type is generic type, whatever T, it should display same icon, so use generic type instead.
                    modelItemType = this.VisualValue.ItemType.GetGenericTypeDefinition();
                }

                // If the user specifies the attribute, then the Designer would be providing the icon,
                // bypassing the pipeline of retrieving the icons via reflection and attached properties.
                ActivityDesignerOptionsAttribute attr = ExtensibilityAccessor.GetAttribute <ActivityDesignerOptionsAttribute>(modelItemType);
                if (attr != null && attr.OutlineViewIconProvider != null)
                {
                    icon = attr.OutlineViewIconProvider(this.VisualValue);
                }

                if (icon == null && !TreeViewItemViewModel.IconCache.TryGetValue(modelItemType, out icon))
                {
                    EditingContext      context             = this.VisualValue.GetEditingContext();
                    ViewService         service             = context.Services.GetService <ViewService>();
                    WorkflowViewService workflowViewService = service as WorkflowViewService;
                    ActivityDesigner    designer            = null;

                    // first try to create an detached view element that won't participate in the designer,
                    // if the view service is WorkflowViewService
                    if (workflowViewService != null)
                    {
                        designer = workflowViewService.CreateDetachedViewElement(this.VisualValue) as ActivityDesigner;
                        icon     = GetIconFromUnInitializedDesigner(designer);
                    }
                    else
                    {
                        // fall back if the view service is not the default implementation
                        // We only need to get the icon from the designer, so we don't need to make sure the view is parented.
                        designer = this.VisualValue.View as ActivityDesigner;
                        if (designer == null && service != null)
                        {
                            designer = service.GetView(this.VisualValue) as ActivityDesigner;
                        }

                        if (designer != null)
                        {
                            if (designer.Icon != null || designer.IsLoaded)
                            {
                                icon = designer.Icon;
                            }
                            else
                            {
                                icon = GetIconFromUnInitializedDesigner(designer);
                            }
                        }
                    }

                    // Cache even a null icon since answers found above won't change within this AppDomain
                    TreeViewItemViewModel.IconCache.Add(modelItemType, icon);
                }

                return(icon);
            }
            else
            {
                return(null);
            }
        }
Example #28
0
 public static ModelItem CreateItem(EditingContext context, TypeIdentifier typeIdentifier, params object[] arguments)
 {
     return(ModelFactory.CreateItem(context, typeIdentifier, CreateOptions.None, arguments));
 }
Example #29
0
 internal MappingViewModel(EditingContext editingContext, MappingEFElement rootNode)
 {
     EditingContext = editingContext;
     _rootNode      = rootNode;
 }
 public MappingFunctionMappingRoot(EditingContext context, EFElement modelItem, MappingEFElement parent)
     : base(context, modelItem, parent)
 {
 }
Example #31
0
 internal static ExplorerEFElement GetNewOrExisting(
     EditingContext context, EFElement efElement, ExplorerEFElement parent, Type viewModelType)
 {
     return(GetNewOrExisting(context, efElement, parent, viewModelType, false));
 }
Example #32
0
        /// <summary>
        /// Performs the data processing associated with this editing operation.
        /// </summary>
        /// <param name="ctx">The context in which the geometry is being calculated.</param>
        internal override void CalculateGeometry(EditingContext ctx)
        {
            // Get the rotation & scale factor to apply.
            PathInfo pd = new PathInfo(this);

            // Go through each leg, creating the geometry for each span...
            // (the following is based on the logic of PathInfo.Render)

            // Initialize position to the start of the path.
            IPosition gotend = m_From;

            // Initial bearing is whatever the desired rotation is.
            double bearing = pd.RotationInRadians;
            double sfac    = pd.ScaleFactor;

            for (int i = 0; i < m_Legs.Count; i++)
            {
                Leg leg = m_Legs[i];

                // Include any angle specified at the start of the leg
                StraightLeg sLeg = (leg as StraightLeg);
                if (sLeg != null)
                {
                    bearing = sLeg.AddStartAngle(bearing);
                }

                // Determine exit bearing for circular leg (do it now, in case an extra leg complicates matters below)
                double      exitBearing = bearing;
                CircularLeg cLeg        = (leg as CircularLeg);
                if (cLeg != null)
                {
                    IPosition center, ec;
                    double    bear2bc;
                    cLeg.GetPositions(gotend, bearing, sfac, out center, out bear2bc, out ec, out exitBearing);

                    // The circle should have been created already, but with an undefined radius
                    Circle circle = cLeg.Circle;
                    Debug.Assert(circle != null);
                    circle.Radius = cLeg.RadiusInMeters * sfac;
                    circle.CenterPoint.ApplyPointGeometry(ctx, PointGeometry.Create(center));
                }

                // Obtain geometry for each span and assign to attached features
                SpanInfo[]      spans    = leg.PrimaryFace.Spans;
                ILineGeometry[] sections = leg.GetSpanSections(gotend, bearing, sfac, spans);
                AttachGeometry(ctx, spans, sections);

                // Note the position at the end of the leg
                IPointGeometry legEnd = sections[sections.Length - 1].End;

                // If we're dealing with the first face of a staggered leg, process the second face
                if (leg.AlternateFace != null)
                {
                    // If this is the very last leg, make sure we use the path end point (there could
                    // conceivably be some roundoff).
                    if (i == m_Legs.Count - 1)
                    {
                        legEnd = m_To.PointGeometry;
                    }

                    spans    = leg.AlternateFace.Spans;
                    sections = leg.GetSpanSections(gotend, legEnd, spans);
                    AttachGeometry(ctx, spans, sections);
                }

                // Get to the end of the leg
                gotend  = legEnd;
                bearing = exitBearing;
            }
        }
 public MappingFunctionImportScalarProperty(EditingContext context, FunctionImportScalarProperty sp, MappingEFElement parent)
     : base(context, sp, parent)
 {
     Debug.Assert(sp != null, "FunctionImportScalarProperty shouldn't be null");
 }
Example #34
0
 public void SetDocument(EditingContext editingContext, ViewingContext viewingContext)
 {
     m_editingContext = editingContext;
     m_viewingContext = viewingContext;
     SetDefaultPrinterSettings();
 }
Example #35
0
 internal virtual void Initialize(EFObject obj, EditingContext editingContext)
 {
     Initialize(obj, editingContext, true);
 }
Example #36
0
 internal abstract void Initialize(EFObject obj, EditingContext editingContext, bool runningInVS);
Example #37
0
        /// <summary>
        /// Performs the data processing associated with this editing operation.
        /// </summary>
        /// <param name="ctx">The context in which the geometry is being calculated.</param>
        internal override void CalculateGeometry(EditingContext ctx)
        {
            // Get the rotation & scale factor to apply.
            PathInfo pd = new PathInfo(this);

            // Go through each leg, creating the geometry for each span...
            // (the following is based on the logic of PathInfo.Render)

            // Initialize position to the start of the path.
            IPosition gotend = m_From;

            // Initial bearing is whatever the desired rotation is.
            double bearing = pd.RotationInRadians;
            double sfac = pd.ScaleFactor;

            for (int i = 0; i < m_Legs.Count; i++)
            {
                Leg leg = m_Legs[i];

                // Include any angle specified at the start of the leg
                StraightLeg sLeg = (leg as StraightLeg);
                if (sLeg != null)
                    bearing = sLeg.AddStartAngle(bearing);

                // Determine exit bearing for circular leg (do it now, in case an extra leg complicates matters below)
                double exitBearing = bearing;
                CircularLeg cLeg = (leg as CircularLeg);
                if (cLeg != null)
                {
                    IPosition center, ec;
                    double bear2bc;
                    cLeg.GetPositions(gotend, bearing, sfac, out center, out bear2bc, out ec, out exitBearing);

                    // The circle should have been created already, but with an undefined radius
                    Circle circle = cLeg.Circle;
                    Debug.Assert(circle != null);
                    circle.Radius = cLeg.RadiusInMeters * sfac;
                    circle.CenterPoint.ApplyPointGeometry(ctx, PointGeometry.Create(center));
                }

                // Obtain geometry for each span and assign to attached features
                SpanInfo[] spans = leg.PrimaryFace.Spans;
                ILineGeometry[] sections = leg.GetSpanSections(gotend, bearing, sfac, spans);
                AttachGeometry(ctx, spans, sections);

                // Note the position at the end of the leg
                IPointGeometry legEnd = sections[sections.Length - 1].End;

                // If we're dealing with the first face of a staggered leg, process the second face
                if (leg.AlternateFace != null)
                {
                    // If this is the very last leg, make sure we use the path end point (there could
                    // conceivably be some roundoff).
                    if (i == m_Legs.Count - 1)
                        legEnd = m_To.PointGeometry;

                    spans = leg.AlternateFace.Spans;
                    sections = leg.GetSpanSections(gotend, legEnd, spans);
                    AttachGeometry(ctx, spans, sections);
                }

                // Get to the end of the leg
                gotend = legEnd;
                bearing = exitBearing;
            }
        }
 // TODO:  enter a bug to remove this ctor.
 internal CommandProcessorContext(EditingContext editingContext, string originatorId, string transactionName)
     : this(editingContext, originatorId, transactionName, null, null)
 {
 }
        internal static void EditFunctionImport(
            EditingContext editingContext,
            FunctionImport functionImport,
            StorageEntityModel sModel,
            ConceptualEntityModel cModel,
            ConceptualEntityContainer cContainer,
            object selectedObject,
            string originatingId)
        {
            Debug.Assert(editingContext != null, "editingContext should not be null");
            Debug.Assert(!string.IsNullOrEmpty(originatingId), "originatingId should not be null or empty");

            // show dialog appropriate to framework version
            var result = ShowNewFunctionImportDialog(
                functionImport.Function,
                functionImport.LocalName.Value,
                sModel,
                cModel,
                cContainer,
                DialogsResource.NewFunctionImportDialog_EditFunctionImportTitle,
                selectedObject);

            // if user selected OK on the dialog then create the FunctionImport
            if (DialogResult.OK == result.DialogResult)
            {
                var commands = new List <Command>();
                var cp       = new CommandProcessor(editingContext, originatingId, Resources.Tx_UpdateFunctionImport);
                CreateComplexTypeCommand createComplexTypeCommand = null;

                // Make the decision based on what is returned by the dialog.
                // If return type is a string and result schema is not null, that means the user would like to create a new complex type for the function import return.
                if (result.ReturnType is string &&
                    result.Schema != null)
                {
                    createComplexTypeCommand = CreateMatchingFunctionImportCommand.AddCreateComplexTypeCommands(
                        sModel, result.ReturnType as string, result.Schema.RawColumns, commands);
                }
                // If ReturnType is a complex type and result schema is not null, the complex type needs to be updated to be in sync with schema columns.
                else if (result.ReturnType is ComplexType &&
                         result.Schema != null)
                {
                    var complexType = result.ReturnType as ComplexType;
                    // Create Column properties dictionary. The keys will be either property's type-mapping column name if availabe or property's name.
                    var propertiesDictionary =
                        complexType.Properties().ToDictionary(p => EdmUtils.GetFunctionImportResultColumnName(functionImport, p));
                    CreateMatchingFunctionImportCommand.AddChangeComplexTypePropertiesCommands(
                        complexType, propertiesDictionary, result.Schema.RawColumns, commands);
                }

                // construct Dictionary mapping property name to column name for FunctionImportMapping
                IDictionary <string, string> mapPropertyNameToColumnName = null;
                if (result.Schema != null)
                {
                    mapPropertyNameToColumnName =
                        ModelHelper.ConstructComplexTypePropertyNameToColumnNameMapping(result.Schema.Columns.Select(c => c.Name).ToList());
                }

                // change the FunctionImport and FunctionImportMapping to match
                ChangeFunctionImportCommand cmdFuncImpSproc = null;
                // if result.IsComposable is true then set to True, but if false then use None if existing value is None, otherwise False
                var resultIsComposable = (result.IsComposable
                                              ? BoolOrNone.TrueValue
                                              : (BoolOrNone.NoneValue == functionImport.IsComposable.Value
                                                     ? BoolOrNone.NoneValue
                                                     : BoolOrNone.FalseValue));
                if (createComplexTypeCommand == null)
                {
                    cmdFuncImpSproc = new ChangeFunctionImportCommand(
                        cContainer, functionImport, result.Function, result.FunctionName, resultIsComposable, true, result.ReturnType);
                    // Create explicit function-import result type mapping if the return type is a complex type.
                    if (result.ReturnType is ComplexType)
                    {
                        cmdFuncImpSproc.PostInvokeEvent += (o, eventArgs) =>
                        {
                            if (functionImport != null &&
                                functionImport.FunctionImportMapping != null)
                            {
                                // CreateFunctionImportTypeMappingCommand will be no op function-import's return is unchanged.
                                CommandProcessor.InvokeSingleCommand(
                                    cp.CommandProcessorContext
                                    ,
                                    new CreateFunctionImportTypeMappingCommand(
                                        functionImport.FunctionImportMapping, result.ReturnType as ComplexType)
                                {
                                    CreateDefaultScalarProperties = true,
                                    PropertyNameToColumnNameMap   = mapPropertyNameToColumnName
                                });
                            }
                        };
                    }
                }
                else
                {
                    // Pass in the pre-req command to create complex type to the command.
                    cmdFuncImpSproc = new ChangeFunctionImportCommand(
                        cContainer, functionImport, result.Function, result.FunctionName,
                        resultIsComposable, createComplexTypeCommand);
                    // Create explicit function-import result type mapping if the return type is a complex type.
                    cmdFuncImpSproc.PostInvokeEvent += (o, eventArgs) =>
                    {
                        if (functionImport != null &&
                            functionImport.FunctionImportMapping != null)
                        {
                            CommandProcessor.InvokeSingleCommand(
                                cp.CommandProcessorContext,
                                new CreateFunctionImportTypeMappingCommand(
                                    functionImport.FunctionImportMapping, createComplexTypeCommand)
                            {
                                CreateDefaultScalarProperties = true,
                                PropertyNameToColumnNameMap   = mapPropertyNameToColumnName
                            });
                        }
                    };
                }
                commands.Add(cmdFuncImpSproc);
                commands.ForEach(x => cp.EnqueueCommand(x));
                cp.Invoke();
            }
        }
Example #40
0
 protected ExplorerEntityModel(EditingContext context, BaseEntityModel entityModel, ExplorerEFElement parent)
     : base(context, entityModel, parent)
 {
 }
Example #41
0
 public MappingCondition(EditingContext context, Condition condition, MappingEFElement parent)
     : base(context, condition, parent)
 {
 }
Example #42
0
 /// <summary>
 ///     Processes a Create or Delete change.
 /// </summary>
 /// <returns>
 ///     true if more model changes should be processed; otherwise, false;
 /// </returns>
 protected abstract bool ProcessCreateOrDeleteChange(EditingContext ctx, ModelToExplorerModelXRef xref, EfiChange change);
Example #43
0
 public DragGestureData(EditingContext context, ModelItem sourceModel, ModelItem targetModel, Visual coordinateReference, Point startPosition, Point currentPosition, DragDropEffects allowedEffects, IDataObject data)
     : this(context, sourceModel, targetModel, coordinateReference, startPosition, currentPosition, allowedEffects, data, (DependencyObject)null, (DependencyObject)null)
 {
 }
Example #44
0
        internal ExplorerEFElement GetExplorerEFElementForEFObject(EditingContext editingContext, EFObject targetEFObject)
        {
            if (targetEFObject == null)
            {
                return(null);
            }

            //
            //  Find the EFObject we want to navigate to for the given EFObject
            //
            var targetEFElement = GetNavigationTarget(targetEFObject);

            //
            // get all EFElement nodes on the path from our target node to the root.
            //
            var elementStack = new LinkedList <EFElement>();
            var e            = targetEFElement;

            while (e != null)
            {
                elementStack.AddLast(e);
                e = e.Parent as EFElement;
            }

            //
            // unwind the stack, making sure that each element's explorer model node exists.
            //
            var explorerElement = ViewModel.RootNode;

            while (elementStack.Count > 0)
            {
                var e2 = elementStack.Last.Value;
                elementStack.RemoveLast();
                var viewModelType = ModelToExplorerModelXRef.GetViewModelTypeForEFElement(editingContext, e2);
                // if viewModelType is null then that kind of EFElement is not displayed
                // in the Explorer (e.g. S-side StorageEntityContainer and children)
                if (null != viewModelType)
                {
                    var nextElement = ModelToExplorerModelXRef.GetNewOrExisting(editingContext, e2, explorerElement, viewModelType);

                    // There are "dummy-nodes" in the view-model that don't correspond to a node in the model.
                    // We need to skip over them here.
                    if (nextElement != null &&
                        elementStack.Count > 0)
                    {
                        nextElement = nextElement.GetParentNodeForElement(elementStack.Last.Value);
                        Debug.Assert(nextElement != null, "GetParentNodeForElement returned null");
                    }

                    if (nextElement != null)
                    {
                        explorerElement = nextElement;
                    }
                }
            }
            Debug.Assert(explorerElement != null, "no explorer element found for targetEFObject");

            if (explorerElement != null)
            {
                //
                // now make sure that our target node in the explorer tree is visible.
                //
                explorerElement.ExpandTreeViewToMe();
            }

            return(explorerElement);
        }
Example #45
0
        internal static Type GetViewModelTypeForEFElement(EditingContext context, EFElement efElement)
        {
            var xref = GetModelToBrowserModelXRef(context);

            return(xref.GetViewModelTypeForEFElement(efElement));
        }
Example #46
0
 internal static double GetInvertZoom(EditingContext context)
 {
     return(DesignerUtilities.GetInvertZoom(DesignerView.FromContext(context)));
 }
 protected ModelItem ArgumentToModelItem(InArgument arg, EditingContext editingContext)
 {
     return(arg != null?ModelFactory.CreateItem(editingContext, arg) : null);
 }
 public MappingConceptualEntityType(EditingContext context, EntityType entityType, MappingEFElement parent)
     : base(context, entityType, parent)
 {
 }
Example #49
0
 /// <summary>
 ///     Creates a new IExplorerViewModel and sets it on this ExplorerViewModelHelper.
 /// </summary>
 public abstract void CreateViewModel(EditingContext ctx);
Example #50
0
 internal void InvokeActivate(EditingContext context, ModelItem item)
 {
     this._context = context;
     this.Activate(item);
 }
 public ExplorerAssociation(EditingContext context, Association assoc, ExplorerEFElement parent)
     : base(context, assoc, parent)
 {
     // do nothing
 }
 internal CommandProcessorContext(
     EditingContext editingContext, string originatorId, string transactionName, EFArtifact artifact,
     EfiTransactionContext transactionContext)
     : this(editingContext, originatorId, transactionName, artifact, transactionContext, false)
 {
 }
        internal static ExpressionReplacement ComputeExpressionReplacement(ActivityWithResult expression, Activity parentActivity, EditingContext context, ArgumentAccessorWrapperCache argumentAccessorWrapperCache, Type preferredReturnType = null)
        {
            Fx.Assert(expression != null, "expressions cannot be null.");
            Fx.Assert(parentActivity != null, "parentActivity cannot be null.");
            Fx.Assert(context != null, "context cannot be null.");
            Fx.Assert(argumentAccessorWrapperCache != null, "argumentAccessorWrapperCache cannot be null.");

            IEnumerable<ArgumentAccessorWrapper> argumentAccessorWrappers = argumentAccessorWrapperCache.GetArgumentAccessorWrappers(parentActivity);
            if (argumentAccessorWrappers != null)
            {
                ArgumentAccessorWrapper argumentAccessorWrapper = argumentAccessorWrappers.FirstOrDefault(wrapper => object.ReferenceEquals(wrapper.Argument.Expression, expression));
                if (argumentAccessorWrapper != null)
                {
                    bool isLocationExpression = ExpressionHelper.IsGenericLocationExpressionType(expression);
                    bool canInferType = true;
                    Type expectedReturnType;
                    ActivityWithResult morphedExpression;
                    if (preferredReturnType != null)
                    {
                        expectedReturnType = preferredReturnType;
                    }
                    else
                    {
                        canInferType = ExpressionHelper.TryInferReturnType(expression, context, out expectedReturnType);
                    }

                    if (canInferType && expectedReturnType != null && ExpressionHelper.TryMorphExpression(expression, isLocationExpression, expectedReturnType, context, out morphedExpression))
                    {
                        Type expressionResultType = isLocationExpression ? expression.ResultType.GetGenericArguments()[0] : expression.ResultType;
                        if (expressionResultType != expectedReturnType)
                        {
                            Argument newArgument = Argument.Create(expectedReturnType, argumentAccessorWrapper.Argument.Direction);
                            newArgument.Expression = morphedExpression;
                            return new ExpressionReplacement(expression, argumentAccessorWrapper.Argument, newArgument, argumentAccessorWrapper.ArgumentAccessor);
                        }
                    }
                }
            }

            return null;
        }
 public static bool ShowDialog(ModelItem activity, EditingContext context, DependencyObject owner)
 {
     return(new SendContentDialog(activity, context, owner).ShowOkCancel());
 }
Example #55
0
        /// <summary>
        /// Attaches geometry to the spans along a leg.
        /// </summary>
        /// <param name="ctx">The context in which the geometry is being defined.</param>
        /// <param name="spans">Information about each observed span</param>
        /// <param name="sections">The geometry that corresponds to each span</param>
        void AttachGeometry(EditingContext ctx, SpanInfo[] spans, ILineGeometry[] sections)
        {
            Debug.Assert(spans.Length == sections.Length);

            for (int i = 0; i < spans.Length; i++)
            {
                SpanInfo data = spans[i];
                Feature feat = data.CreatedFeature;
                PointFeature endPoint = null;

                if (feat is PointFeature)
                    endPoint = (PointFeature)feat;
                else if (feat is LineFeature)
                    endPoint = (feat as LineFeature).EndPoint;

                if (endPoint != null && endPoint.PointGeometry == null)
                {
                    PointGeometry pg = PointGeometry.Create(sections[i].End);
                    endPoint.ApplyPointGeometry(ctx, pg);
                }
            }
        }
Example #56
0
 public abstract bool TryMorphExpression(ActivityWithResult expression, bool isLocationExpression, Type newType,
                                         EditingContext context, out ActivityWithResult newExpression);
        /// <summary>
        /// Performs the data processing associated with this editing operation.
        /// </summary>
        /// <param name="ctx">The context in which the geometry is being calculated.</param>
        internal override void CalculateGeometry(EditingContext ctx)
        {
            // Get the radius, in meters on the ground.
            double rad = m_Radius.GetDistance(m_Center).Meters;
            if (rad < Constants.TINY)
                throw new Exception("NewCircleOperation.CalculateGeometry - Radius is too close to zero.");

            // If the closing point was created by this edit, define it's position
            ArcFeature arc = (ArcFeature)this.Line;
            PointFeature p = arc.StartPoint;
            if (p.Creator == this)
            {
                PointGeometry pg = new PointGeometry(m_Center.X, m_Center.Y+rad);
                p.ApplyPointGeometry(ctx, pg);
            }

            // Define the radius of the circle and include in the map model
            Circle circle = arc.Circle;
            Debug.Assert(circle != null);
            circle.Radius = rad;

            // Refer the center point to the circle.
            circle.AddReferences();
        }
Example #58
0
 //By default expression cannot infer the type.
 public virtual bool TryInferReturnType(ActivityWithResult expression, EditingContext context, out Type returnType)
 {
     returnType = null;
     return(false);
 }
        /// <summary>
        ///     Add Columns based on the datasource
        /// </summary>
        private void AddColumns(ModelItem selectedDataGrid, EditingContext context) 
        {
            using (ModelEditingScope scope = selectedDataGrid.BeginEdit("Generate Columns")) 
            {
                // Set databinding related properties
                DataGridHelper.SparseSetValue(selectedDataGrid.Properties[DataGrid.AutoGenerateColumnsProperty], false);

                // Get the datasource 
                object dataSource = selectedDataGrid.Properties[ItemsControl.ItemsSourceProperty].ComputedValue;
                if (dataSource != null) 
                {
                    // Does WPF expose something like ListBindingHelper?
                    PropertyDescriptorCollection dataSourceProperties = System.Windows.Forms.ListBindingHelper.GetListItemProperties(dataSource);

                    foreach (PropertyDescriptor pd in dataSourceProperties) 
                    {
                        ModelItem dataGridColumn = null;
                        
                        dataGridColumn = DataGridHelper.CreateDefaultDataGridColumn(context, pd);

                        if (dataGridColumn != null) 
                        {
                            selectedDataGrid.Properties["Columns"].Collection.Add(dataGridColumn);
                        }
                    }
                }

                scope.Complete();
            }
        }
 public ExplorerViewModel(EditingContext editingContext, ExplorerRootNode edmRootNode)
 {
     EditingContext = editingContext;
     EDMRootNode    = edmRootNode;
 }