コード例 #1
0
ファイル: TestUtils.cs プロジェクト: Robin--/Warewolf
        public static Mock<ModelItem> CreateModelItem(Guid uniqueID, Guid serviceID, Guid environmentID, params ModelProperty[] modelProperties)
        {
            var startIndex = 0;
            if (modelProperties == null)
            {
                modelProperties = new ModelProperty[3];
            }
            else
            {
                startIndex = modelProperties.Length;
                Array.Resize(ref modelProperties, startIndex + 3);
            }

            modelProperties[startIndex++] = CreateModelProperty("UniqueID", uniqueID.ToString()).Object;
            modelProperties[startIndex++] = CreateModelProperty("ResourceID", serviceID).Object;
            modelProperties[startIndex] = CreateModelProperty("EnvironmentID", new InArgument<Guid>(environmentID)).Object;

            var properties = new Mock<ModelPropertyCollection>();

            foreach (var modelProperty in modelProperties)
            {
                properties.Protected().Setup<ModelProperty>("Find", modelProperty.Name, true).Returns(modelProperty);
            }

            var modelItem = new Mock<ModelItem>();
            modelItem.Setup(mi => mi.Properties).Returns(properties.Object);
            modelItem.Setup(mi => mi.ItemType).Returns(typeof(DsfActivity));
            return modelItem;
        }
コード例 #2
0
        public static object ActivityActionMorphHelper(ModelItem originalValue, ModelProperty newModelProperty)
        {
            Fx.Assert(newModelProperty.PropertyType.GetGenericArguments().Count() == 1, "This should only be applied for ActivityAction<T>");
            Type activityActionTypeArgument = newModelProperty.PropertyType.GetGenericArguments()[0];
            Type activityActionType = typeof(ActivityAction<>).MakeGenericType(activityActionTypeArgument);
            object activityAction = Activator.CreateInstance(activityActionType);
            ModelItem morphed = ModelFactory.CreateItem(originalValue.GetEditingContext(), activityAction);

            ModelItem originalActivityActionArgument = originalValue.Properties[PropertyNames.ActionArgument].Value;
            if (originalActivityActionArgument != null)
            {
                Type variableType = typeof(DelegateInArgument<>).MakeGenericType(activityActionTypeArgument);
                DelegateInArgument iterationDelegateArgument = (DelegateInArgument)Activator.CreateInstance(variableType);
                iterationDelegateArgument.Name = (string)originalActivityActionArgument.Properties[PropertyNames.NameProperty].Value.GetCurrentValue();
                morphed.Properties[PropertyNames.ActionArgument].SetValue(iterationDelegateArgument);
            }

            ModelItem originalActivityActionHandler = originalValue.Properties[PropertyNames.ActionHandler].Value;
            if (originalActivityActionHandler != null)
            {
                morphed.Properties[PropertyNames.ActionHandler].SetValue(originalActivityActionHandler);
                originalValue.Properties[PropertyNames.ActionHandler].SetValue(null);
            }

            return morphed;
        }
コード例 #3
0
        public ModelPropertyEntry(ModelProperty property, ModelPropertyValue parentValue)
            : base(parentValue) 
        {

            _valueCache = new CachedValues(this);
            SetUnderlyingModelPropertyHelper(property, false);
        }
コード例 #4
0
        private static object GetSafeValue(ModelProperty property, bool resolveReferences)
        {
            if (property == null)
            {
                return null;
            }

            object value;

            // We have to special case TextBlock due to IAddChild behavior with Text and Inlines
            if (resolveReferences && !(typeof(System.Windows.Controls.TextBlock).IsAssignableFrom(property.Parent.ItemType) &&
                property.Name.Equals(System.Windows.Controls.TextBlock.TextProperty.Name)))
            {
                value = property.ComputedValue;
            }
            else
            {
                value = property.Value == null ? null : property.Value.GetCurrentValue();
            }

            if (value == null || value.GetType().Equals(typeof(NullExtension)))
            {
                return null;
            }

            return value;
        }
コード例 #5
0
ファイル: ArgHelper.cs プロジェクト: nagyistoce/Neuroflow
        public static IArgHelper Create(ModelProperty property)
        {
            Contract.Requires(property != null);

            var type = property.PropertyType;
            var ga = type.GetGenericArguments()[0];
            var helperType = typeof(ArgHelper<>).MakeGenericType(ga);
            var helper = (IArgHelper)Activator.CreateInstance(helperType);
            return helper;
        }
コード例 #6
0
        private static string GetGroupName(ModelProperty prop)
        {
            // TODO: Cache this
            
            var category = prop.Attributes.OfType<CategoryAttribute>().FirstOrDefault();

            if (category != null && !string.IsNullOrEmpty(category.Category)) return category.Category;

            return "Misc";
        }
コード例 #7
0
        public static void InjectExpression(Dev2Switch ds, ModelProperty activityExpression)
        {
            if(ds == null) return;

            // FetchSwitchData
            string expressionToInject = String.Join("", GlobalConstants.InjectedSwitchDataFetch,
                                                    "(\"", ds.SwitchVariable, "\",",
                                                    GlobalConstants.InjectedDecisionDataListVariable,
                                                    ")");
            if(activityExpression != null)
            {
                activityExpression.SetValue(expressionToInject);
            }
        }
コード例 #8
0
        public static void InjectExpression(Dev2DecisionStack ds, ModelProperty activityExpression)
        {
            if(ds == null) return;

            string modelData = ds.ToVBPersistableModel();
            string expressionToInject = String.Join("", GlobalConstants.InjectedDecisionHandler, "(\"",
                                                    modelData, "\",",
                                                    GlobalConstants.InjectedDecisionDataListVariable, ")");

            if(activityExpression != null)
            {
                activityExpression.SetValue(expressionToInject);
            }
        }
コード例 #9
0
 public ChangeNotificationTracker(TreeViewItemViewModel parent, ModelProperty parentProperty)
 {
     if (parent == null)
     {
         throw FxTrace.Exception.AsError(new ArgumentNullException("parent"));
     }
     if (parentProperty == null)
     {
         throw FxTrace.Exception.AsError(new ArgumentNullException("parentProperty"));
     }
     this.Parent = parent;
     this.ParentProperty = parentProperty;
     this.TrackedModelItem = new Dictionary<ModelItem, HashSet<string>>();
     this.TrackedCollection = new List<INotifyCollectionChanged>();
     this.ChildViewModels = new List<TreeViewItemViewModel>();
 }
コード例 #10
0
 internal Bind(ModelProperty sourceProp, ModelProperty activityArgProp, IArgHelper helper, bool isArg)
 {
     if (this.isArg = isArg)
     {
         sourceModelItem = sourceProp.Value;
         PropertyChangedEventManager.AddListener(sourceModelItem, this, "Name");
         this.helper = helper;
         this.activityArgProp = activityArgProp;
         last = sourceModelItem.Properties["Name"].Value.GetCurrentValue() as string;
     }
     else
     {
         sourceModelItem = sourceProp.Parent;
         PropertyChangedEventManager.AddListener(sourceModelItem, this, "ItemResultName");
         this.helper = helper;
         this.activityArgProp = activityArgProp;
         this.sourceProp = sourceProp;
         last = sourceProp.Value.GetCurrentValue() as string;
     }
 }
コード例 #11
0
        // this updates forward links
        public static void MorphProperties(ModelItem oldModelItem, ModelItem newModelitem)
        {
            if (oldModelItem == null)
            {
                throw FxTrace.Exception.AsError(new ArgumentNullException("oldModelItem"));
            }
            if (newModelitem == null)
            {
                throw FxTrace.Exception.AsError(new ArgumentNullException("newModelitem"));
            }

            foreach (ModelProperty modelProperty in oldModelItem.Properties)
            {
                ModelProperty propertyInNewModelItem = newModelitem.Properties[modelProperty.Name];
                if (propertyInNewModelItem != null)
                {
                    Console.WriteLine(propertyInNewModelItem.Name);
                    if (CanCopyProperty(modelProperty, propertyInNewModelItem))
                    {
                        if (propertyInNewModelItem.PropertyType.Equals(modelProperty.PropertyType))
                        {
                            propertyInNewModelItem.SetValue(modelProperty.Value);
                            modelProperty.SetValue(null);
                        }
                        else // See if there is morph helper for this type.
                        {
                            PropertyValueMorphHelper extension = GetPropertyValueMorphHelper(modelProperty.PropertyType);
                            if (extension != null)
                            {
                                propertyInNewModelItem.SetValue(extension(modelProperty.Value, propertyInNewModelItem));
                                modelProperty.SetValue(null);
                            }
                        }
                    }
                }
            }
        }
コード例 #12
0
        private void SetUnderlyingModelPropertyHelper(ModelProperty property, bool firePropertyValueChangedEvents) 
        {
            if (property == null)
            {
                throw FxTrace.Exception.ArgumentNull("property");
            }

            // Store the value
            ClearUnderlyingModelProperties();
            AddUnderlyingModelProperty(property);

            // Clear any cached values
            RefreshCache();

            if (firePropertyValueChangedEvents) 
            {
                // Update the PropertyValue (always, except when it doesn't exist yet (ctor time))
                this.ModelPropertyValue.OnUnderlyingModelChanged();
            }
        }
コード例 #13
0
        // Adds the property to the internal collection list and hooks into its PropertyChanged event
        private void AddUnderlyingModelProperty(ModelProperty property) 
        {
            if (property == null)
            {
                return;
            }

            property.Parent.PropertyChanged += new PropertyChangedEventHandler(OnUnderlyingPropertyChanged);
            _properties.Add(property);
            _wrapsAroundNameProperty = "Name".Equals(property.Name);
        }
コード例 #14
0
 public void Add(ModelItem modelItem, ModelProperty property)
 {
     this.Add(modelItem, property.Name);
 }
コード例 #15
0
 private void AddEntriesForPropertyReference(string valueText, ModelItem modelItem,
     ModelProperty property, SearchableEntryOption entryType, string propertyPath)
 {
     entries.Add(CreateSearchableEntry(entryType, modelItem, property, valueText, propertyPath));
 }
コード例 #16
0
 internal ModelPropertyDescriptor(ModelProperty itemProperty)
     : base(itemProperty.Name, null)
 {
     this.itemProperty = itemProperty;
 }
コード例 #17
0
 static ServiceDesignerViewModel CreateServiceDesignerViewModel(Guid instanceID, bool resourceRepositoryReturnsNull, ModelProperty[] modelProperties, params IErrorInfo[] resourceErrors)
 {
     return CreateServiceDesignerViewModel(instanceID, resourceRepositoryReturnsNull, new Mock<IEventAggregator>().Object, modelProperties, resourceErrors);
 }
コード例 #18
0
 static bool CanCopyProperty(ModelProperty modelProperty, ModelProperty propertyInNewModelItem)
 {
     bool canCopyProperty = false;
     DesignerSerializationVisibilityAttribute designerSerializationVisibility = ExtensibilityAccessor.GetAttribute<DesignerSerializationVisibilityAttribute>(modelProperty.Attributes);
     if (modelProperty.Value == null)
     {
         canCopyProperty = false;
     }
     else if (designerSerializationVisibility != null && designerSerializationVisibility.Visibility != DesignerSerializationVisibility.Visible)
     {
         canCopyProperty = false;
     }
     else if (propertyInNewModelItem != null && !propertyInNewModelItem.IsAttached && !propertyInNewModelItem.IsReadOnly)
     {
         canCopyProperty = true;
     }
     return canCopyProperty;
 }
コード例 #19
0
 void IModelTreeItem.SetSource(ModelProperty property)
 {
     if (!this.sources.Contains(property))
     {
         // also check if the same parent.property is in the list as a different instance of oldModelProperty
         ModelProperty foundProperty = this.sources.Find((modelProperty) => modelProperty.Name.Equals(property.Name) && property.Parent == modelProperty.Parent);
         if (foundProperty == null)
         {
             this.sources.Add(property);
         }
     }
 }
コード例 #20
0
 // <summary>
 // Gets the underlying computed value object of the specified ModelProperty.  MarkupExtensions
 // (resources and such) will be resolved into their final value.
 // </summary>
 // <param name="property">ModelProperty to ---- open (can be null)</param>
 // <returns>Underlying value object, if any</returns>
 public static object GetSafeComputedValue(ModelProperty property)
 {
     return GetSafeValue(property, true);
 }
コード例 #21
0
        public override TextImage GenerateTextImage()
        {
            RemoveToolTipAdorner();

            // If the modelitem tree was not changed since last time we generated the text image,
            // return the original TextImage and set the StartIndex to StartIndexUnchangeMark
            // means VS should use their own index.
            if (!this.isModelTreeChanged)
            {
                textImage.StartLineIndex = StartIndexUnchangeMark;
                return(textImage);
            }
            this.entries.Clear();
            this.textImageIndexEntryMapping.Clear();
            this.index = 0;
            IEnumerable <ModelItem> itemsToSearch = this.GetItemsOnDesigner(preOrder: true, excludeRoot: true, excludeErrorActivity: true, excludeExpression: true, includeOtherObjects: false);

            foreach (ModelItem item in itemsToSearch)
            {
                this.objectsOnDesinger.Add(item.GetCurrentValue());
            }

            Selection selection  = this.editingContext.Items.GetValue <Selection>();
            int       startIndex = StartIndexUnchangeMark;

            // If and only if root is selected, start search from the beginning.
            if (selection.SelectionCount == 1 && selection.PrimarySelection == modelService.Root)
            {
                startIndex = 0;
            }

            AddEntriesForArguments(selection, ref startIndex);
            foreach (ModelItem modelItem in itemsToSearch)
            {
                // Do this check to make sure we start from the topmost selected item.
                if (startIndex == StartIndexUnchangeMark)
                {
                    if (selection.SelectedObjects.Contains(modelItem) && modelItem != this.lastNavigatedItem)
                    {
                        // set the search start index to the next location of the current focus.
                        startIndex = index;
                    }
                }

                // Add the DisplayName property first.
                ModelProperty displayNameProperty = modelItem.Properties[DisplayNamePropertyName];
                if (displayNameProperty != null)
                {
                    AddEntriesForProperty(displayNameProperty, modelItem, null);
                }
                foreach (ModelProperty modelProperty in modelItem.Properties)
                {
                    if (!ShouldIgnore(modelProperty))
                    {
                        AddEntriesForProperty(modelProperty, modelItem, null);
                    }
                }
                AddEntriesForVariables(modelItem);
            }

            AddBrowsableProperties(this.modelService.Root);

            List <string> searchableTexts = new List <string>();
            int           textImageIndex  = 0;

            foreach (SearchableEntry entry in entries)
            {
                string text = entry.Text;
                if (text == null)
                {
                    text = string.Empty;
                }

                foreach (string line in text.Split(new string[] { Environment.NewLine, "\n", "\r" }, StringSplitOptions.RemoveEmptyEntries))
                {
                    this.textImageIndexEntryMapping.Add(textImageIndex, entry);
                    searchableTexts.Add(line);
                    textImageIndex++;
                }
            }

            textImage = new TextImage()
            {
                StartLineIndex = startIndex,
                Lines          = searchableTexts
            };

            this.isModelTreeChanged = false;
            return(textImage);
        }
コード例 #22
0
 // <summary>
 // Gets the underlying value object of the specified ModelProperty.  MarkupExtensions
 // (resources and such) will be returned as they are, with the exception of NullExtension,
 // which will be returned as null.
 // </summary>
 // <param name="property">ModelProperty to ---- open (can be null)</param>
 // <returns>Underlying value object, if any</returns>
 public static object GetSafeRawValue(ModelProperty property)
 {
     return GetSafeValue(property, false);
 }
コード例 #23
0
 // <summary>
 // Compares the name and Type of the specified ModelProperties,
 // returning true if they are equal.
 // </summary>
 // <param name="a">ModelProperty A</param>
 // <param name="b">ModelProperty B</param>
 // <returns>True if the names and Types of the specified ModelProperties
 // match, false otherwise.</returns>
 public static bool AreEquivalent(ModelProperty a, ModelProperty b)
 {
     return object.Equals(a.Name, b.Name) &&
         object.Equals(a.PropertyType, b.PropertyType);
 }
コード例 #24
0
 internal ModelPropertyDescriptor(ModelProperty itemProperty)
     : base(itemProperty.Name, null)
 {
     this.itemProperty = itemProperty;
 }
コード例 #25
0
 private void AddEntriesForPropertyReference(string valueText, ModelItem modelItem,
                                             ModelProperty property, SearchableEntryOption entryType, string propertyPath)
 {
     entries.Add(CreateSearchableEntry(entryType, modelItem, property, valueText, propertyPath));
 }
コード例 #26
0
        void AddEntriesForProperty(ModelProperty property, ModelItem modelItem, string propertyPath)
        {
            if (!string.IsNullOrEmpty(propertyPath))
            {
                propertyPath += ",";
                propertyPath += property.Name;
            }
            else
            {
                propertyPath = property.Name;
            }

            entries.Add(CreateSearchableEntry(
                SearchableEntryOption.Property, modelItem, property, TypeNameHelper.GetDisplayName(property.PropertyType, false), propertyPath));

            entries.Add(CreateSearchableEntry(
                SearchableEntryOption.Property, modelItem, property, property.Name, propertyPath));

            if (property.ComputedValue != null)
            {
                PropertyValueEditor propertyValueEditor = null;
                try
                {
                    propertyValueEditor = ExtensibilityAccessor.GetSubPropertyEditor(property);
                }
                catch (TargetInvocationException exception)
                {
                    // To workaround 181412.If the current property's property type is a generic type and the activity 
                    // is also a generic type Calling to ExtensibilityAccessor.GetSubPropertyEditor will get this exception. 
                    if (exception.InnerException is ArgumentException)
                    {
                        propertyValueEditor = null;
                    }
                }
                if (propertyValueEditor != null)
                {
                    IList<ModelProperty> properties = ExtensibilityAccessor.GetSubProperties(property);
                    foreach (ModelProperty propertyItem in properties)
                    {
                        AddEntriesForProperty(propertyItem, modelItem, propertyPath);
                    }
                }
                else
                {
                    // We don't search the value of an expandable property.
                    AddEntriesForPropertyValue(property.ComputedValue, modelItem, property, SearchableEntryOption.Property, propertyPath);
                }
            }
            else if (property.Reference != null)
            {
                AddEntriesForPropertyReference(property.Reference, modelItem, property, SearchableEntryOption.Property, propertyPath);
            }
        }
コード例 #27
0
ファイル: CompositeWorkflow.cs プロジェクト: barbarossia/CWF
 private bool ShouldBeAdd(ModelProperty property)
 {
     return ((property.Name == ModelItemService.BodyPropertyName ||
         property.Name == ModelItemService.HandlerPropertyName ||
         property.Name == ModelItemService.ImplementationPropertyName) &&
         property.Value != null);
 }
コード例 #28
0
 void OnPathToArgumentChanged(string pathAsString)
 {
     this.expressionModelProperty = null;
     this.expressionConverter = null;
     if (!string.IsNullOrEmpty(pathAsString) && null != this.OwnerActivity)
     {
         string[] path = pathAsString.Split('.');
         if (path.Length > 0)
         {
             this.expressionModelProperty = this.OwnerActivity.Properties[path[0]];
             for (int i = 1; i < path.Length; ++i)
             {
                 if (null != this.expressionModelProperty && null != this.expressionModelProperty.Value)
                 {
                     this.expressionModelProperty = this.expressionModelProperty.Value.Properties[path[i]];
                 }
                 else
                 {
                     this.expressionModelProperty = null;
                     break;
                 }
             }
         }
     }
     if (null != this.expressionModelProperty)
     {
         this.expressionConverter = ((ModelPropertyImpl)this.expressionModelProperty).PropertyDescriptor.Converter;
     }
     this.InitializeHintText();
 }
コード例 #29
0
 void IModelTreeItem.RemoveSource(ModelProperty oldModelProperty)
 {
     if (this.sources.Contains(oldModelProperty))
     {
         this.sources.Remove(oldModelProperty);
     }
     else
     {
         ((IModelTreeItem)this).RemoveSource(oldModelProperty.Parent, oldModelProperty.Name);
     }
 }
コード例 #30
0
        private static Type GetDefaultItemType(ModelProperty property) 
        {
            if (property == null)
            {
                return null;
            }

            Type propertyType = property.PropertyType;
            if (EditorUtilities.IsConcreteWithDefaultCtor(propertyType))
            {
                return propertyType;
            }

            return null;
        }
コード例 #31
0
 static ServiceDesignerViewModel CreateServiceDesignerViewModel(Guid instanceID, ModelProperty[] modelProperties, params IErrorInfo[] resourceErrors)
 {
     return CreateServiceDesignerViewModel(instanceID, false, modelProperties, resourceErrors);
 }
コード例 #32
0
 private void AddEntriesForPropertyValue(object value, ModelItem modelItem,
     ModelProperty property, SearchableEntryOption entryType, string propertyPath)
 {
     // be ready for recursively visit all sub properties.
     alreadyVisitedObjects.Clear();
     IList<string> texts = GetSearchableStrings(value);
     if (texts != null)
     {
         foreach (string valueText in texts)
         {
             entries.Add(CreateSearchableEntry(entryType, modelItem, property, valueText, propertyPath));
         }
     }
 }
コード例 #33
0
        static ServiceDesignerViewModel CreateServiceDesignerViewModel(Guid instanceID, bool resourceRepositoryReturnsNull, IEventAggregator eventPublisher, ModelProperty[] modelProperties, Mock<IContextualResourceModel> resourceModel, params IErrorInfo[] resourceErrors)
        {
            var rootModel = CreateResourceModel(Guid.NewGuid(), resourceRepositoryReturnsNull, resourceErrors);
            resourceModel.Setup(model => model.DataList).Returns("<DataList><n1/></DataList>");
            var dataListViewModel = new DataListViewModel();
            dataListViewModel.InitializeDataListViewModel(resourceModel.Object);
            dataListViewModel.ScalarCollection.Add(new DataListItemModel("n1"));
            DataListSingleton.SetDataList(dataListViewModel);
            var modelItem = CreateModelItem(instanceID, resourceModel.Object.ID, resourceModel.Object.Environment.ID, modelProperties);

            var envRepository = new Mock<IEnvironmentRepository>();
            envRepository.Setup(r => r.FindSingle(It.IsAny<Expression<Func<IEnvironmentModel, bool>>>())).Returns(resourceModel.Object.Environment);
            envRepository.Setup(r => r.ActiveEnvironment).Returns(resourceModel.Object.Environment);

            return new ServiceDesignerViewModel(modelItem.Object, rootModel.Object, envRepository.Object, eventPublisher);
        }
コード例 #34
0
 bool ShouldIgnore(ModelProperty property)
 {
     // Since we have searched each variable. We can strip out "Variables" property here.
     // It's valid to hardcode "Variables" property. That's the way how variable designer get variables.
     // We should strip out 'DisplayName', since it is searched at the beginning.
     // We strip out 'Id', since it's a property from the Activity Base class, but never used in design time. 
     return string.Equals(property.Name, "Variables", StringComparison.Ordinal)
                 || string.Equals(property.Name, DisplayNamePropertyName, StringComparison.Ordinal)
                 || string.Equals(property.Name, "Id", StringComparison.Ordinal);
 }