public void BasicWithIAPSType()
        {
            ImplementsIAPS a = new ImplementsIAPS();

            object value;

            Assert.IsFalse(AttachablePropertyServices.TryGetProperty(a, propertyOne, out value), "We expect the store doesn't have propertyOne for 'a' yet");
            Assert.IsFalse(AttachablePropertyServices.TryGetProperty(a, propertyTwo, out value), "We expect the store doesn't have propertyTwo for 'a' yet");

            IAttachedPropertyStore aAsIAPS = a as IAttachedPropertyStore;

            Assert.IsNotNull(aAsIAPS);
            Assert.IsFalse(aAsIAPS.TryGetProperty(propertyOne, out value), "We expect the type does not have propertyOne yet");
            Assert.IsFalse(aAsIAPS.TryGetProperty(propertyTwo, out value), "We expect the type does not have propertyTwo yet");

            AttachablePropertyServices.SetProperty(a, propertyOne, "Foo Bar");
            Assert.IsTrue(AttachablePropertyServices.GetAttachedPropertyCount(a) == 1);
            var props = new KeyValuePair <AttachableMemberIdentifier, object> [1];

            AttachablePropertyServices.CopyPropertiesTo(a, props, 0);
            Assert.IsTrue((string)props[0].Value == "Foo Bar");
            Assert.IsTrue(AttachablePropertyServices.TryGetProperty(a, propertyOne, out value) && (string)value == "Foo Bar", "We should now find the property");
            Assert.IsTrue(aAsIAPS.TryGetProperty(propertyOne, out value) && (string)value == "Foo Bar", "And it's storage should be local on the instance");

            string valueAsString;

            Assert.IsTrue(AttachablePropertyServices.TryGetProperty(a, propertyOne, out valueAsString) && valueAsString == "Foo Bar");

            Assert.IsTrue(AttachablePropertyServices.RemoveProperty(a, propertyOne), "We should be able to remove the property");
            Assert.IsFalse(AttachablePropertyServices.TryGetProperty(a, propertyOne, out value), "We should not have the property anymore");
            Assert.IsFalse(aAsIAPS.TryGetProperty(propertyOne, out value), "Even the local copy should not have the property anymore");
            Assert.IsTrue(AttachablePropertyServices.GetAttachedPropertyCount(a) == 0);
        }
        public void BasicWithNonIAPSType()
        {
            DoesntImplementIAPS a = new DoesntImplementIAPS();
            DoesntImplementIAPS b = new DoesntImplementIAPS();

            object value;

            Assert.IsFalse(AttachablePropertyServices.TryGetProperty(a, propertyOne, out value), "We expect the store doesn't have propertyOne for 'a' yet");
            Assert.IsFalse(AttachablePropertyServices.TryGetProperty(a, propertyTwo, out value), "We expect the store doesn't have propertyTwo for 'a' yet");
            Assert.IsFalse(AttachablePropertyServices.TryGetProperty(b, propertyOne, out value), "We expect the store doesn't have propertyOne for 'b' yet");
            Assert.IsFalse(AttachablePropertyServices.TryGetProperty(b, propertyTwo, out value), "We expect the store doesn't have propertyTwo for 'b' yet");

            AttachablePropertyServices.SetProperty(a, propertyOne, "Something");
            Assert.IsTrue(AttachablePropertyServices.GetAttachedPropertyCount(a) == 1);
            var props = new KeyValuePair <AttachableMemberIdentifier, object> [1];

            AttachablePropertyServices.CopyPropertiesTo(a, props, 0);
            Assert.IsTrue((string)props[0].Value == "Something");
            Assert.IsTrue(AttachablePropertyServices.GetAttachedPropertyCount(b) == 0);
            Assert.IsTrue(AttachablePropertyServices.TryGetProperty(a, propertyOne, out value) && (string)value == "Something", "We should now find the property");
            Assert.IsFalse(AttachablePropertyServices.TryGetProperty(b, propertyOne, out value), "We should not see the attached property added to 'a' on 'b'");

            string valueAsString;

            Assert.IsTrue(AttachablePropertyServices.TryGetProperty(a, propertyOne, out valueAsString) && valueAsString == "Something");

            Assert.IsTrue(AttachablePropertyServices.RemoveProperty(a, propertyOne), "We should be able to remove the property");
            Assert.IsFalse(AttachablePropertyServices.TryGetProperty(a, propertyOne, out value), "We should not have the property anymore");
            Assert.IsTrue(AttachablePropertyServices.GetAttachedPropertyCount(a) == 0);
        }
        // Get the attached workflow symbol and remove it from the root.
        WorkflowSymbol GetAttachedWorkflowSymbol()
        {
            object         rootInstance = this.GetRootInstance();
            WorkflowSymbol wfSymbol     = null;

            if (rootInstance != null)
            {
                Activity documentRootElement = GetRootWorkflowElement(rootInstance);
                if (documentRootElement != null)
                {
                    string symbolString;
                    if (AttachablePropertyServices.TryGetProperty <string>(documentRootElement, DebugSymbol.SymbolName, out symbolString))
                    {
                        try
                        {
                            wfSymbol = WorkflowSymbol.Decode(symbolString);
                            // Change the name to the currently loaded file.
                            wfSymbol.FileName = this.Context.Items.GetValue <WorkflowFileItem>().LoadedFile;
                        }
                        catch (Exception ex)
                        {
                            if (Fx.IsFatal(ex))
                            {
                                throw;
                            }
                        }
                        finally
                        {
                            AttachablePropertyServices.RemoveProperty(documentRootElement, DebugSymbol.SymbolName);
                        }
                    }
                }
            }
            return(wfSymbol);
        }
Ejemplo n.º 4
0
 public static void SetImplementationMap(Activity targetActivity, DynamicUpdateMap implementationMap)
 {
     if (implementationMap != null)
     {
         AttachablePropertyServices.SetProperty(targetActivity, implementationMapProperty, implementationMap);
     }
     else
     {
         AttachablePropertyServices.RemoveProperty(targetActivity, implementationMapProperty);
     }
 }
Ejemplo n.º 5
0
 public static void SetOriginalActivityBuilder(object instance, ActivityBuilder originalActivityBuilder)
 {
     if (originalActivityBuilder != null)
     {
         AttachablePropertyServices.SetProperty(instance, originalActivityBuilderProperty, originalActivityBuilder);
     }
     else
     {
         AttachablePropertyServices.RemoveProperty(instance, originalActivityBuilderProperty);
     }
 }
Ejemplo n.º 6
0
 // Attached property setter for the compiled expression root for the implementation surface
 // area of an activity
 public static void SetCompiledExpressionRootForImplementation(object target, ICompiledExpressionRoot compiledExpressionRoot)
 {
     if (compiledExpressionRoot == null)
     {
         AttachablePropertyServices.RemoveProperty(target, compiledExpressionRootForImplementationProperty);
     }
     else
     {
         AttachablePropertyServices.SetProperty(target, compiledExpressionRootForImplementationProperty, compiledExpressionRoot);
     }
 }
Ejemplo n.º 7
0
 public static void SetMapItem(object instance, DynamicUpdateMapItem mapItem)
 {
     if (mapItem != null)
     {
         AttachablePropertyServices.SetProperty(instance, mapItemProperty, mapItem);
     }
     else
     {
         AttachablePropertyServices.RemoveProperty(instance, mapItemProperty);
     }
 }
Ejemplo n.º 8
0
 public static void SetOriginalDefinition(object instance, Activity originalDefinition)
 {
     if (originalDefinition != null)
     {
         AttachablePropertyServices.SetProperty(instance, originalDefinitionProperty, originalDefinition);
     }
     else
     {
         AttachablePropertyServices.RemoveProperty(instance, originalDefinitionProperty);
     }
 }
Ejemplo n.º 9
0
 public static void SetCachePeriod(object instance, object value)
 {
     if (value == null)
     {
         AttachablePropertyServices.RemoveProperty(instance, CachePeriodName);
     }
     else
     {
         AttachablePropertyServices.SetProperty(instance, CachePeriodName, value);
     }
 }
Ejemplo n.º 10
0
        public void AttachablePropertySetValueSuccess()
        {
            var xt  = new XamlType(typeof(Attachable), sctx);
            var apl = xt.GetAllAttachableMembers();
            var foo = apl.First(ap => ap.Name == "Foo");

            Assert.IsTrue(foo.IsAttachable, "#7");
            var obj = new object();

            foo.Invoker.SetValue(obj, "xxx");              // obj is non-null, so valid.
            // FIXME: this line should be unnecessary.
            AttachablePropertyServices.RemoveProperty(obj, new AttachableMemberIdentifier(foo.Type.UnderlyingType, foo.Name));
        }
Ejemplo n.º 11
0
            private void UpdateAttachedProperty()
            {
                object target = this.targetObject.Target;

                if (target != null)
                {
                    if (this.singleItemIndex >= 0)
                    {
                        AttachablePropertyServices.SetProperty(target, propertyReferencePropertyID, this[this.singleItemIndex]);
                    }
                    else
                    {
                        AttachablePropertyServices.RemoveProperty(target, propertyReferencePropertyID);
                    }
                }
            }
        private static void SetCollection <T>(object target, AttachableMemberIdentifier property, IList <T> collection)
        {
            if (collection == null)
            {
                AttachablePropertyServices.RemoveProperty(target, property);
            }
            else
            {
                if (collection is Array)
                {
                    collection = new Collection <T>(collection);
                }

                AttachablePropertyServices.SetProperty(target, property, collection);
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Set annotation of an object
        /// </summary>
        /// <param name="instance">instance to set annotation text</param>
        /// <param name="annotationText">annoatation text to be set</param>
        public static void SetAnnotationText(object instance, string annotationText)
        {
            if (instance == null)
            {
                throw FxTrace.Exception.AsError(new ArgumentNullException("instance"));
            }

            if (annotationText != null)
            {
                AttachablePropertyServices.SetProperty(instance, Annotation.AnnotationTextProperty, annotationText);
            }
            else
            {
                AttachablePropertyServices.RemoveProperty(instance, Annotation.AnnotationTextProperty);
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Sets the priority on an item.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="priority">The priority.</param>
        public static void SetPriority(ServerItem item, int?priority)
        {
            var memberIdentifier = new AttachableMemberIdentifier(typeof(Queue), "Priority");

            if (priority.HasValue)
            {
                AttachablePropertyServices.SetProperty(
                    item,
                    memberIdentifier,
                    priority);
            }
            else
            {
                AttachablePropertyServices.RemoveProperty(
                    item,
                    memberIdentifier);
            }
        }
        public override bool Apply()
        {
            if (this.NewValue == null)
            {
                AttachablePropertyServices.RemoveProperty(this.Owner.GetCurrentValue(), this.AttachablePropertyIdentifier);
            }
            else
            {
                AttachablePropertyServices.SetProperty(this.Owner.GetCurrentValue(), this.AttachablePropertyIdentifier, this.NewValue);
            }

            // notify observer
            if (!string.IsNullOrEmpty(this.PropertyName))
            {
                ((IModelTreeItem)this.Owner).OnPropertyChanged(this.PropertyName);
            }

            return(true);
        }
        public override bool RemoveViewState(ModelItem modelItem, string key)
        {
            if (modelItem == null)
            {
                throw FxTrace.Exception.AsError(new ArgumentNullException("modelItem"));
            }
            if (key == null)
            {
                throw FxTrace.Exception.AsError(new ArgumentNullException("key"));
            }
            bool itemRemoved = false;
            Dictionary <string, object> viewState = WorkflowViewStateService.GetViewState(modelItem.GetCurrentValue());

            if (viewState != null && key != null && viewState.ContainsKey(key))
            {
                itemRemoved = viewState.Remove(key);
                if (viewState.Keys.Count == 0)
                {
                    AttachablePropertyServices.RemoveProperty(modelItem.GetCurrentValue(), ViewStateName);
                }
            }
            return(itemRemoved);
        }
Ejemplo n.º 17
0
 /// <summary>
 ///     Removes the entry for the specified attachable member from this
 ///     attachable member store.
 /// </summary>
 /// <param name="attachableMemberIdentifier">
 ///     The XAML type system identifier for
 ///     the attachable member entry to remove.
 /// </param>
 /// <returns>
 ///     <see langword="true" /> if an attachable member entry for
 ///     <paramref name="attachableMemberIdentifier" /> was found in the store
 ///     and
 ///     removed; otherwise, <see langword="false" />.
 /// </returns>
 public bool RemoveProperty(AttachableMemberIdentifier attachableMemberIdentifier)
 {
     return(AttachablePropertyServices.RemoveProperty(this, attachableMemberIdentifier));
 }
        internal string SerializeToString(object obj, string fileName)
        {
            FrameworkName targetFramework = this.FrameworkName;

            string   sourceFile          = null;
            Activity rootWorkflowElement = GetRootWorkflowElement(obj);
            Dictionary <int, object> modelItemObjectSequence = null;

            // If the current target is 4.5 or Higher, let us not write the filename attribute as DebugSymbol eliminates the need for it.
            // We will serialize without the Filename by removing it from the element and adding it back after serialization
            if (targetFramework.Is45OrHigher())
            {
                if (AttachablePropertyServices.TryGetProperty <string>(rootWorkflowElement, XamlDebuggerXmlReader.FileNameName, out sourceFile))
                {
                    AttachablePropertyServices.RemoveProperty(rootWorkflowElement, XamlDebuggerXmlReader.FileNameName);
                }
            }

            TextWriter textWriter = new StringWriter(CultureInfo.InvariantCulture);

            WorkflowDesignerXamlSchemaContext schemaContext = obj is ActivityBuilder ? this.XamlSchemaContext : new WorkflowDesignerXamlSchemaContext(null);

            bool shouldWriteDebugSymbol = true;

            if (targetFramework.IsLessThan45())
            {
                shouldWriteDebugSymbol = false;
            }

            System.Xaml.XamlReader       outerReader;
            XamlObjectReaderWithSequence innerReader;

            using (textWriter)
            {
                UsingXamlWriter(
                    new DesignTimeXamlWriter(textWriter, schemaContext, shouldWriteDebugSymbol),
                    delegate(DesignTimeXamlWriter designTimeXamlWriter)
                {
                    UsingXamlWriter(
                        ActivityXamlServices.CreateBuilderWriter(designTimeXamlWriter),
                        delegate(System.Xaml.XamlWriter activityBuilderWriter)
                    {
                        UsingXamlWriter(
                            new ActivityTemplateFactoryBuilderWriter(activityBuilderWriter, schemaContext),
                            delegate(System.Xaml.XamlWriter writer)
                        {
                            // If ViewStateManager property is attached, remove it. It needs to be regenerated if we target 4.5.
                            // It should be removed if we're targeting 4.0.
                            AttachablePropertyServices.RemoveProperty(obj, WorkflowViewState.ViewStateManagerProperty);

                            this.CreateXamlObjectReaders(obj, schemaContext, out outerReader, out innerReader);

                            using (innerReader)
                            {
                                using (outerReader)
                                {
#if ERROR_TOLERANT_SUPPORT
                                    if (ErrorActivity.GetHasErrorActivities(obj))
                                    {
                                        ErrorTolerantObjectWriter.TransformAndStripErrors(outerReader, writer);
                                    }
                                    else
                                    {
#endif
                                    XamlServices.Transform(outerReader, writer);
#if ERROR_TOLERANT_SUPPORT
                                }
#endif
                                }
                            }

                            modelItemObjectSequence = innerReader.SequenceNumberToObjectMap;
                        });
                    });
                });
            }

            string retVal = textWriter.ToString();

            if (targetFramework.IsLessThan45())
            {
                if (sourceFile != null)
                {
                    XamlDebuggerXmlReader.SetFileName(rootWorkflowElement, sourceFile);
                }
            }

            IList <XamlLoadErrorInfo> loadErrors;
            Dictionary <object, SourceLocation> sourceLocations;
            object deserializedObject = this.DeserializeString(retVal, out loadErrors, out sourceLocations);

            if (!string.IsNullOrEmpty(fileName) && targetFramework.Is45OrHigher())
            {
                this.LastWorkflowSymbol = this.GetWorkflowSymbol(fileName, deserializedObject, sourceLocations);
                if (this.LastWorkflowSymbol != null)
                {
                    retVal = retVal.Replace(DesignTimeXamlWriter.EmptyWorkflowSymbol, this.LastWorkflowSymbol.Encode());
                }
            }

            // The symbol is actually removed in GetAttachedWorkflowSymbol() after deserialization completes.
            System.Xaml.AttachablePropertyServices.RemoveProperty(GetRootWorkflowElement(deserializedObject), DebugSymbol.SymbolName);
            this.CreateXamlObjectReaders(deserializedObject, schemaContext, out outerReader, out innerReader);
            Dictionary <object, object> sourceLocationObjectToModelItemObjectMapping = new Dictionary <object, object>(ObjectReferenceEqualityComparer <object> .Default);
            using (innerReader)
            {
                using (outerReader)
                {
                    while (outerReader.Read())
                    {
                    }

                    Dictionary <int, object> sourceLocationObjectSequence = innerReader.SequenceNumberToObjectMap;
                    foreach (KeyValuePair <int, object> sourceLocationObjectEntry in sourceLocationObjectSequence)
                    {
                        int    key = sourceLocationObjectEntry.Key;
                        object sourceLocationObject = sourceLocationObjectEntry.Value;
                        object modelItemObject;

                        if (modelItemObjectSequence.TryGetValue(key, out modelItemObject))
                        {
                            sourceLocationObjectToModelItemObjectMapping.Add(sourceLocationObject, modelItemObject);
                        }
                    }
                }
            }

            this.OnSerializationCompleted(sourceLocationObjectToModelItemObjectMapping);
            return(retVal);
        }
        static void CutCopyOperation(List <ModelItem> modelItemsToCutCopy, EditingContext context, bool isCutOperation)
        {
            List <object> objectsOnClipboard = null;
            List <object> metaData           = null;

            if (modelItemsToCutCopy.Count > 0)
            {
                objectsOnClipboard = new List <object>(modelItemsToCutCopy.Count);
                metaData           = new List <object>();
                Dictionary <ICompositeView, List <ModelItem> > notifyDictionary = new Dictionary <ICompositeView, List <ModelItem> >();
                UIElement breadCrumbRootView = ((DesignerView)context.Services.GetService <DesignerView>()).RootDesigner;
                foreach (ModelItem modelItem in modelItemsToCutCopy)
                {
                    object currentElement = modelItem.GetCurrentValue();

                    if (typeof(Activity).IsAssignableFrom(currentElement.GetType()))
                    {
                        string fileName;
                        if (AttachablePropertyServices.TryGetProperty(currentElement, XamlDebuggerXmlReader.FileNameName, out fileName))
                        {
                            AttachablePropertyServices.RemoveProperty(currentElement, XamlDebuggerXmlReader.FileNameName);
                        }
                    }

                    if (modelItem.View != null)
                    {
                        //The case where the breadcrumbroot designer is Cut/Copied. We do not delete the root designer, we only copy it.
                        if (breadCrumbRootView.Equals(modelItem.View))
                        {
                            notifyDictionary.Clear();
                            objectsOnClipboard.Add(modelItem.GetCurrentValue());
                            break;
                        }
                        else
                        {
                            ICompositeView container = (ICompositeView)DragDropHelper.GetCompositeView((WorkflowViewElement)modelItem.View);
                            if (container != null)
                            {
                                //If the parent and some of its children are selected and cut/copied, we ignore the children.
                                //The entire parent will be cut/copied.
                                //HashSet parentModelItems contains all the model items in the parent chain of current modelItem.
                                //We use HashSet.IntersectWith operation to determine if one of the parents is set to be cut.
                                HashSet <ModelItem> parentModelItems = CutCopyPasteHelper.GetSelectableParentModelItems(modelItem);
                                parentModelItems.IntersectWith(modelItemsToCutCopy);
                                if (parentModelItems.Count == 0)
                                {
                                    if (!notifyDictionary.ContainsKey(container))
                                    {
                                        notifyDictionary[container] = new List <ModelItem>();
                                    }
                                    notifyDictionary[container].Add(modelItem);
                                }
                            }
                        }
                    }
                }

                foreach (ICompositeView container in notifyDictionary.Keys)
                {
                    object containerMetaData = false;
                    if (isCutOperation)
                    {
                        containerMetaData = container.OnItemsCut(notifyDictionary[container]);
                    }
                    else
                    {
                        containerMetaData = container.OnItemsCopied(notifyDictionary[container]);
                    }
                    if (containerMetaData != null)
                    {
                        metaData.Add(containerMetaData);
                    }
                    //Put the actual activities and not the modelItems in the clipboard.
                    foreach (ModelItem modelItem in notifyDictionary[container])
                    {
                        objectsOnClipboard.Add(modelItem.GetCurrentValue());
                    }
                }
                if (metaData.Count == 0)
                {
                    metaData = null;
                }
            }
            try
            {
                FrameworkName targetFramework = context.Services.GetService <DesignerConfigurationService>().TargetFrameworkName;
                PutOnClipBoard(objectsOnClipboard, metaData, targetFramework);
            }
            catch (XamlObjectReaderException exception)
            {
                if (modelItemsToCutCopy.Count > 0 && ErrorActivity.GetHasErrorActivities(modelItemsToCutCopy[0].Root.GetCurrentValue()))
                {
                    ErrorReporting.ShowErrorMessage(SR.CutCopyErrorActivityMessage);
                }
                else
                {
                    ErrorReporting.ShowErrorMessage(exception.Message);
                }
            }
        }