コード例 #1
0
        private static void DoCopy(List <ModelItem> modelItemsToCopy, EditingContext context)
        {
            if (modelItemsToCopy == null)
            {
                throw FxTrace.Exception.AsError(new ArgumentNullException("modelItemsToCopy"));
            }

            if (context == null)
            {
                throw FxTrace.Exception.AsError(new ArgumentNullException("context"));
            }

            // copy only works if we have DesignerView up and running so check and throw here
            if (context.Services.GetService <DesignerView>() == null)
            {
                throw FxTrace.Exception.AsError(new InvalidOperationException(SR.CutCopyRequiresDesignerView));
            }
            modelItemsToCopy.RemoveAll((modelItem) => { return(modelItem == null); });
            try
            {
                CutCopyOperation(modelItemsToCopy, context, false);
            }
            catch (ExternalException e)
            {
                ErrorReporting.ShowErrorMessage(e.Message);
            }
        }
コード例 #2
0
        internal static ObservableCollection <DynamicArgumentWrapperObject> ModelItemToWrapperCollection(ModelItem model, out bool isDictionary, out Type underlyingArgumentType)
        {
            string errorMessage = string.Empty;

            underlyingArgumentType = null;
            isDictionary           = false;
            if (model is ModelItemCollection)
            {
                underlyingArgumentType = model.GetCurrentValue().GetType().GetGenericArguments()[0];
                if (!typeof(Argument).IsAssignableFrom(underlyingArgumentType))
                {
                    errorMessage = SR.NonSupportedDynamicArgumentType;
                }
            }
            else if (model is ModelItemDictionary)
            {
                Type underlyingKeyType = model.GetCurrentValue().GetType().GetGenericArguments()[0];
                underlyingArgumentType = model.GetCurrentValue().GetType().GetGenericArguments()[1];
                if (!typeof(Argument).IsAssignableFrom(underlyingArgumentType))
                {
                    errorMessage = SR.NonSupportedDynamicArgumentType;
                }
                if (underlyingKeyType != typeof(string))
                {
                    errorMessage += SR.NonSupportedDynamicArgumentKeyType;
                }
                isDictionary = true;
            }
            else
            {
                errorMessage = SR.NonSupportedModelItemCollectionOrDictionary;
            }
            if (!string.IsNullOrEmpty(errorMessage))
            {
                ErrorReporting.ShowErrorMessage(SR.NonSupportedModelItemCollectionOrDictionary);
                return(null);
            }
            if (isDictionary)
            {
                ObservableCollection <DynamicArgumentWrapperObject> wrappers = new ObservableCollection <DynamicArgumentWrapperObject>();
                foreach (ModelItem item in GetArgumentCollection(model))
                {
                    wrappers.Add(new DynamicArgumentWrapperObject(item.Properties["Key"].ComputedValue as string, item.Properties["Value"].Value));
                }
                return(wrappers);
            }
            else
            {
                ObservableCollection <DynamicArgumentWrapperObject> wrappers = new ObservableCollection <DynamicArgumentWrapperObject>();
                foreach (ModelItem item in GetArgumentCollection(model))
                {
                    wrappers.Add(new DynamicArgumentWrapperObject(null, item));
                }
                return(wrappers);
            }
        }
コード例 #3
0
        internal void ValidateEntry(DynamicArgumentWrapperObject entry, DependencyPropertyChangedEventArgs e)
        {
            if (e.Property == DynamicArgumentWrapperObject.NameProperty)
            {
                if (this.IsDictionary.Value)
                {
                    DataGridRow row     = entry.Row;
                    string      newName = e.NewValue as string;

                    bool duplicates =
                        this.DynamicArguments.Any <DynamicArgumentWrapperObject>(
                            p => string.Equals(p.Name, newName) && p != entry);
                    if (duplicates || string.IsNullOrEmpty(newName))
                    {
                        entry.Name = e.OldValue as string;
                        if (duplicates)
                        {
                            ErrorReporting.ShowErrorMessage(string.Format(CultureInfo.CurrentCulture, SR.DuplicateArgumentName, newName));
                        }
                        else
                        {
                            ErrorReporting.ShowErrorMessage(string.Format(CultureInfo.CurrentCulture, SR.EmptyArgumentName));
                        }
                    }
                    entry.IsValidating = false;
                }
            }
            else
            {
                if (e.Property == DynamicArgumentWrapperObject.DirectionProperty)
                {
                    entry.UseLocationExpression = (entry.Direction != ArgumentDirection.In);
                }
                if ((e.Property != DynamicArgumentWrapperObject.ExpressionProperty) && (entry.Expression != null))
                {
                    ActivityWithResult expression = entry.Expression.GetCurrentValue() as ActivityWithResult;
                    if (expression != null)
                    {
                        ActivityWithResult newExpression;
                        if (ExpressionHelper.TryMorphExpression(expression, entry.UseLocationExpression, entry.Type, this.Context, out newExpression))
                        {
                            entry.Expression = (this.OwnerActivity as IModelTreeItem).ModelTreeManager.WrapAsModelItem(newExpression);
                        }
                        else
                        {
                            //Microsoft

                            entry.Expression = null;
                        }
                    }
                }
                entry.IsValidating = false;
            }
        }
コード例 #4
0
 static ModelItemCollection GetArgumentCollection(ModelItem data)
 {
     if (data is ModelItemCollection)
     {
         return(data as ModelItemCollection);
     }
     else if (data is ModelItemDictionary)
     {
         return((data as ModelItemDictionary).Properties["ItemsCollection"].Collection);
     }
     else
     {
         ErrorReporting.ShowErrorMessage(SR.NonSupportedModelItemCollectionOrDictionary);
         return(null);
     }
 }
コード例 #5
0
 internal bool OnOK()
 {
     if (!this.AllowDuplicate)
     {
         List <TypeWrapper> list = new List <TypeWrapper>();
         foreach (TypeWrapper tw in this.wrapperCollection)
         {
             if (tw.Type != null && list.Any <TypeWrapper>(entry => Type.Equals(entry.Type, tw.Type)))
             {
                 ErrorReporting.ShowErrorMessage(string.Format(CultureInfo.CurrentCulture, (string)this.FindResource("duplicateEntryErrorMessage"), TypeNameHelper.GetDisplayName(tw.Type, true)));
                 return(false);
             }
             list.Add(tw);
         }
     }
     return(true);
 }
コード例 #6
0
ファイル: DesignObjectWrapper.cs プロジェクト: 3566500/mono
        public override void ShowDialog(PropertyValue propertyValue, IInputElement commandSource)
        {
            //get actual value editor
            var editor = DesignObjectWrapperDynamicPropertyEditor.GetEditor(propertyValue);

            Fx.Assert(editor is DialogPropertyValueEditor, "PropertyValueEditor is not assigned or is not derived from DialogPropertyValueEditor");

            //if we are here, the editor must derive from DialogPropertyEditor, if it doesn't user provided wrong template
            if (editor is DialogPropertyValueEditor)
            {
                try
                {
                    ((DialogPropertyValueEditor)editor).ShowDialog(propertyValue, commandSource);
                }
                catch (Exception err)
                {
                    ErrorReporting.ShowErrorMessage(err.ToString());
                }
            }
        }
コード例 #7
0
        //PutCallbackOnClipBoard - tries to put into private (this application only) clipboard a callback
        //to a method. The method will be invoked when user retrieves clipboard content - i.e. by
        //calling a paste command.
        //the callback has to be:
        //- static method
        //- have return value (not void)
        //- takes 2 input parameters:
        //   * 1 parameter is modelitem - this is a target modelitem upon which callback is to be executed
        //   * 2 parameter is user provided context - any object. Since this callback will be executed within
        //    this application only, there is no need for context to be serializable.
        internal static void PutCallbackOnClipBoard(Func <ModelItem, object, object> callbackMethod, Type callbackResultType, object context)
        {
            if (null == callbackMethod || null == context)
            {
                throw FxTrace.Exception.AsError(new ArgumentNullException(null == callbackMethod ? "callbackMethod" : "context"));
            }
            ClipboardData clipboardData = new ClipboardData();
            List <object> data          = new List <object>();

            data.Add(callbackResultType);
            data.Add(callbackMethod);
            clipboardData.Data    = data;
            clipboardData.Version = versionInfo;
            CutCopyPasteHelper.workflowCallbackContext = context;
            try
            {
                RetriableClipboard.SetDataObject(new DataObject(WorkflowCallbackClipboardFormat, clipboardData, false), false);
            }
            catch (ExternalException e)
            {
                ErrorReporting.ShowErrorMessage(e.Message);
            }
        }
コード例 #8
0
 internal static void DoCut(List <ModelItem> modelItemsToCut, EditingContext context)
 {
     if (modelItemsToCut == null)
     {
         throw FxTrace.Exception.AsError(new ArgumentNullException("modelItemsToCut"));
     }
     if (context == null)
     {
         throw FxTrace.Exception.AsError(new ArgumentNullException("context"));
     }
     modelItemsToCut.RemoveAll((modelItem) => { return(modelItem == null); });
     if (modelItemsToCut.Count > 0)
     {
         using (EditingScope es = (EditingScope)modelItemsToCut[0].BeginEdit(SR.CutOperationEditingScopeDescription))
         {
             try
             {
                 CutCopyOperation(modelItemsToCut, context, true);
             }
             catch (ExternalException e)
             {
                 es.Revert();
                 ErrorReporting.ShowErrorMessage(e.Message);
                 return;
             }
             DesignerView view = context.Services.GetService <DesignerView>();
             //Setting the selection to Breadcrumb root.
             Fx.Assert(view != null, "DesignerView Cannot be null during cut");
             WorkflowViewElement rootView = view.RootDesigner as WorkflowViewElement;
             if (rootView != null)
             {
                 Selection.SelectOnly(context, rootView.ModelItem);
             }
             es.Complete();
         }
     }
 }
コード例 #9
0
        void StartDragging()
        {
            try
            {
                using (ModelEditingScope editingScope = this.ModelItem.BeginEdit(SR.MoveEditingScopeDescription, true))
                {
                    HashSet <WorkflowViewElement>          draggedViews     = new HashSet <WorkflowViewElement>();
                    Dictionary <ModelItem, ICompositeView> sourceContainers = new Dictionary <ModelItem, ICompositeView>();
                    HashSet <ICompositeView> compViewSet = new HashSet <ICompositeView>();
                    Selection selection = this.Context.Items.GetValue <Selection>();
                    IEnumerable <ModelItem> selectedObjects  = selection.SelectedObjects;
                    IEnumerable <ModelItem> modelItemsToDrag = DragDropHelper.GetModelItemsToDrag(selectedObjects);

                    // Save the source containers for the dragged items
                    foreach (ModelItem modelItem in modelItemsToDrag)
                    {
                        WorkflowViewElement view = (WorkflowViewElement)modelItem.View;
                        draggedViews.Add(view);
                        ICompositeView container = DragDropHelper.GetCompositeView(view) as ICompositeView;
                        sourceContainers.Add(modelItem, container);
                        // If Add returns true => the container is added the first time, which is always ok
                        // If Add returns false => the container is added more than once
                        //    it must be a IMultipleDragEnabledCompositeView, otherwise, return, because
                        //    we don't support dragging from ICompositeView.
                        if (!compViewSet.Add(container) && !(container is IMultipleDragEnabledCompositeView))
                        {
                            return;
                        }
                    }

                    // Calculate the anchor point for the dragged items
                    Point relativeLocation = GetRelativeLocation(draggedViews);
                    Point referencePoint   = this.lastMouseDownPoint;
                    referencePoint.Offset(relativeLocation.X, relativeLocation.Y);


                    DataObject dataObject = DragDropHelper.DoDragMoveImpl(draggedViews, referencePoint);
                    IEnumerable <WorkflowViewElement> movedViewElements = DragDropHelper.GetDragDropMovedViewElements(dataObject);

                    // once drag drop is done make sure the CompositeView is notified of the change in data
                    if (movedViewElements != null)
                    {
                        Dictionary <ICompositeView, List <ModelItem> > containerMovedModelItemList = new Dictionary <ICompositeView, List <ModelItem> >();

                        // Create containerMovedModelItemList
                        foreach (WorkflowViewElement view in movedViewElements)
                        {
                            ICompositeView compView = DragDropHelper.GetCompositeView(view) as ICompositeView;
                            Fx.Assert(compView != null, "not an ICompositeView");
                            if (!containerMovedModelItemList.ContainsKey(compView))
                            {
                                containerMovedModelItemList.Add(compView, new List <ModelItem>());
                            }
                            containerMovedModelItemList[compView].Add(view.ModelItem);
                        }

                        // Call OnItemsMoved to notify the source container.
                        foreach (KeyValuePair <ICompositeView, List <ModelItem> > pair in containerMovedModelItemList)
                        {
                            if (pair.Key is IMultipleDragEnabledCompositeView)
                            {
                                ((IMultipleDragEnabledCompositeView)pair.Key).OnItemsMoved(pair.Value);
                            }
                            else
                            {
                                if (pair.Value.Count >= 2)
                                {
                                    throw FxTrace.Exception.AsError(
                                              new InvalidOperationException(SR.Error_MovingMoreThanOneItemsFromICompositeView));
                                }
                                pair.Key.OnItemMoved(pair.Value[0]);
                            }
                        }

                        // animation
                        foreach (WorkflowViewElement view in movedViewElements)
                        {
                            BeginDropAnimation(view);
                        }
                    }
                    // the drop target is using old DragDropHelper API and did not set the moved view elements
                    else
                    {
                        DragDropEffects executedDragDropEffect = DragDropHelper.GetDragDropCompletedEffects(dataObject);
                        if (executedDragDropEffect == DragDropEffects.Move)
                        {
                            if (modelItemsToDrag.Count() == 1)
                            {
                                ModelItem movedItem = modelItemsToDrag.First <ModelItem>();
                                sourceContainers[movedItem].OnItemMoved(movedItem);
                                BeginDropAnimation((WorkflowViewElement)movedItem.View);
                            }
                            else
                            {
                                throw FxTrace.Exception.AsError(new InvalidOperationException(SR.DraggingMulitpleItemsError));
                            }
                        }
                    }
                    editingScope.Complete();

                    bool dropHappened = movedViewElements != null ||
                                        DragDropHelper.GetDragDropCompletedEffects(dataObject) == DragDropEffects.Move;
                    if (dropHappened)
                    {
                        // add the selected objects back into selection.
                        this.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, (Action)(() =>
                        {
                            foreach (ModelItem item in selectedObjects)
                            {
                                // We need only the first one
                                IInputElement viewToFocus = item == null ? null : item.View as IInputElement;
                                if (viewToFocus != null)
                                {
                                    Keyboard.Focus(viewToFocus);
                                    break;
                                }
                            }
                            this.Context.Items.SetValue(new Selection(selectedObjects));
                        }));
                    }
                }
            }
            catch (Exception e)
            {
                ErrorReporting.ShowErrorMessage(e.Message);
            }
        }
コード例 #10
0
        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);
                }
            }
        }
コード例 #11
0
 protected virtual void ReportError(string message, string details)
 {
     ErrorReporting.ShowErrorMessage(message, details);
 }
コード例 #12
0
        internal static object GetDroppedObjectInstance(DependencyObject dropTarget, EditingContext context, Type type, IDataObject dataObject)
        {
            if (type != null)
            {
                //check if type is generic
                if (type.IsGenericTypeDefinition)
                {
                    type = ResolveGenericParameters(dropTarget, context, type);
                }
            }

            object droppedObject = null;

            if (null != type)
            {
                try
                {
                    droppedObject = Activator.CreateInstance(type);

                    if (type.IsActivityTemplateFactory() && type.IsClass)
                    {
                        //find parent WorkflowViewElement - in case of mouse drop, current drop target most likely is ISourceContainer
                        if (!(dropTarget is WorkflowViewElement))
                        {
                            dropTarget = VisualTreeUtils.FindVisualAncestor <WorkflowViewElement>(dropTarget);
                        }

                        Type templateFactoryInterface2 = type.GetInterface(typeof(IActivityTemplateFactory <>).FullName);
                        if (templateFactoryInterface2 != null)
                        {
                            droppedObject = templateFactoryInterface2.InvokeMember("Create", BindingFlags.InvokeMethod, null, droppedObject, new object[] { dropTarget, dataObject }, CultureInfo.InvariantCulture);
                        }
                        else if (droppedObject is IActivityTemplateFactory)
                        {
                            droppedObject = ((IActivityTemplateFactory)droppedObject).Create(dropTarget);
                        }
                    }

                    // SQM: Log activity usage count
                    ActivityUsageCounter.ReportUsage(context.Services.GetService <IVSSqmService>(), type);
                }
                catch (Exception ex)
                {
                    if (Fx.IsFatal(ex))
                    {
                        throw;
                    }

                    string details = ex.Message;
                    if (ex is TargetInvocationException && ex.InnerException != null)
                    {
                        details = ex.InnerException.Message;
                    }


                    ErrorReporting.ShowErrorMessage(string.Format(CultureInfo.CurrentUICulture, SR.CannotCreateInstance, TypeNameHelper.GetDisplayName(type, false)), details);
                }
            }

            return(droppedObject);
        }