private static List <object> GetFromClipboard(out List <object> metaData, EditingContext editingContext)
        {
            Fx.Assert(editingContext != null, "editingContext should not be null");

            MultiTargetingSupportService multiTargetingService = editingContext.Services.GetService <IMultiTargetingSupportService>() as MultiTargetingSupportService;
            DesignerConfigurationService config = editingContext.Services.GetService <DesignerConfigurationService>();
            DataObject    dataObject            = RetriableClipboard.GetDataObject() as DataObject;
            List <object> workflowData          = null;

            metaData = null;

            if (dataObject != null)
            {
                if (dataObject.GetDataPresent(WorkflowClipboardFormat))
                {
                    bool isCopyingFromHigherFrameworkToLowerFramework = false;

                    if (multiTargetingService != null && config != null)
                    {
                        isCopyingFromHigherFrameworkToLowerFramework = GetTargetFrameworkFromClipboard(dataObject).Version > config.TargetFrameworkName.Version;
                    }

                    string clipBoardString = (string)TryGetData(dataObject, WorkflowClipboardFormat);
                    using (StringReader stringReader = new StringReader(clipBoardString))
                    {
                        try
                        {
                            XamlSchemaContext schemaContext;
                            if (isCopyingFromHigherFrameworkToLowerFramework)
                            {
                                schemaContext = new MultiTargetingXamlSchemaContext(multiTargetingService);
                            }
                            else
                            {
                                schemaContext = new XamlSchemaContext();
                            }

                            using (XamlXmlReader xamlXmlReader = new XamlXmlReader(stringReader, schemaContext))
                            {
                                ClipboardData clipboardData = (ClipboardData)XamlServices.Load(xamlXmlReader);
                                metaData     = clipboardData.Metadata;
                                workflowData = clipboardData.Data;
                            }
                        }
                        catch (Exception e)
                        {
                            Trace.WriteLine(e.Message);
                        }
                    }
                }
                else if (dataObject.GetDataPresent(WorkflowCallbackClipboardFormat))
                {
                    ClipboardData localData = (ClipboardData)TryGetData(dataObject, WorkflowCallbackClipboardFormat);
                    metaData     = null;
                    workflowData = localData.Data;
                    workflowData.Add(CutCopyPasteHelper.workflowCallbackContext);
                }
            }
            return(workflowData);
        }
        private static void PutOnClipBoard(List <object> selectedData, List <object> metaData, FrameworkName targetFramework)
        {
            CutCopyPasteHelper.workflowCallbackContext = null;
            if (selectedData != null)
            {
                ClipboardData clipboardData = new ClipboardData();
                clipboardData.Data     = selectedData;
                clipboardData.Metadata = metaData;
                clipboardData.Version  = versionInfo;

                XamlReader   reader       = ViewStateXamlHelper.RemoveIdRefs(new XamlObjectReader(clipboardData));
                StringWriter stringWriter = new StringWriter(CultureInfo.InvariantCulture);
                XamlServices.Transform(reader, new XamlXmlWriter(stringWriter, reader.SchemaContext), true);
                string clipBoardString = stringWriter.ToString();

                DataObject dataObject = new DataObject(WorkflowClipboardFormat, clipBoardString);
                dataObject.SetData(DataFormats.Text, clipBoardString);
                dataObject.SetData(WorkflowClipboardFormat_TargetFramework, targetFramework);
                RetriableClipboard.SetDataObject(dataObject, true);
            }
        }
        //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);
            }
        }
 //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);
     }
 }
        private static void PutOnClipBoard(List<object> selectedData, List<object> metaData, FrameworkName targetFramework)
        {
            CutCopyPasteHelper.workflowCallbackContext = null;
            if (selectedData != null)
            {
                ClipboardData clipboardData = new ClipboardData();
                clipboardData.Data = selectedData;
                clipboardData.Metadata = metaData;
                clipboardData.Version = versionInfo;

                XamlReader reader = ViewStateXamlHelper.RemoveIdRefs(new XamlObjectReader(clipboardData));
                StringWriter stringWriter = new StringWriter(CultureInfo.InvariantCulture);
                XamlServices.Transform(reader, new XamlXmlWriter(stringWriter, reader.SchemaContext), true);
                string clipBoardString = stringWriter.ToString();

                DataObject dataObject = new DataObject(WorkflowClipboardFormat, clipBoardString);
                dataObject.SetData(DataFormats.Text, clipBoardString);
                dataObject.SetData(WorkflowClipboardFormat_TargetFramework, targetFramework);
                RetriableClipboard.SetDataObject(dataObject, true);
            }
        }