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); }
public static ResolverResult Resolve(MultiTargetingSupportService multiTargetingService, Type type) { SharedFx.Assert(multiTargetingService != null, "multiTargetingService should not be null"); SharedFx.Assert(type != null, "type should not be null"); if (!multiTargetingService.IsSupportedType(type)) { return(ResolverResult.Unknown); } ResolverResult result; Type reflectionType = multiTargetingService.GetReflectionType(type); PropertyInfo[] properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty); PropertyInfo[] targetProperties = reflectionType.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty); List <string> newProperties = new List <string>(); // Assume we don't remove properties in newer framework // We only compare property name here if (properties.Length > targetProperties.Length) { foreach (PropertyInfo propertyInfo in properties) { bool found = false; foreach (PropertyInfo targetProperty in targetProperties) { if (targetProperty.Name == propertyInfo.Name) { found = true; break; } } if (!found) { newProperties.Add(propertyInfo.Name); } } result = new ResolverResult(newProperties); } else { result = ResolverResult.FullySupported; } return(result); }
protected override XamlType GetXamlType(string xamlNamespace, string name, params XamlType[] typeArguments) { if (!string.IsNullOrEmpty(this.localAssemblyNsPostfix) && IsClrNamespaceWithNoAssembly(xamlNamespace)) { xamlNamespace = AddLocalAssembly(xamlNamespace); } var xamlType = base.GetXamlType(xamlNamespace, name, typeArguments); if (xamlType == null && environmentAssembliesLoaded == false && editingContext != null) { // Failed to find the type, this might because the namespace is a custom namespace // and the dependent assembly hasn't been loaded yet. Load all dependent assemblies // and try to load the same xaml type again. AssemblyContextControlItem assemblyItem = this.editingContext.Items.GetValue <AssemblyContextControlItem>(); var environmentAssemblies = assemblyItem.GetEnvironmentAssemblies(null); if (assemblyItem.LocalAssemblyName != null) { AssemblyContextControlItem.GetAssembly(assemblyItem.LocalAssemblyName, null); } environmentAssembliesLoaded = true; xamlType = base.GetXamlType(xamlNamespace, name, typeArguments); } if (xamlType == null || xamlType.UnderlyingType == null || this.editingContext == null) { return(xamlType); } MultiTargetingSupportService multiTargetingService = editingContext.Services.GetService <IMultiTargetingSupportService>() as MultiTargetingSupportService; DesignerConfigurationService config = editingContext.Services.GetService <DesignerConfigurationService>(); if (multiTargetingService == null || config == null) { return(xamlType); } // do not filter out new types and new properties if targeting to current framework and it's a full SKU if (config.TargetFrameworkName.Version == CurrentFramework.Version && config.TargetFrameworkName.IsFullProfile()) { return(xamlType); } // Filter out new types and new properties if (this.resolverCache == null) { this.resolverCache = new ResolverCache(); } if (supportedTypes.Contains(xamlType.UnderlyingType)) { return(xamlType); } // only check if conversion is needed when target framework is less than 4.5 if (config.TargetFrameworkName.Version < CurrentFramework.Version) { if (conversionRequiredTypes.Contains(xamlType.UnderlyingType)) { this.ContainsConversionRequiredType = true; return(xamlType); } } ResolverResult resolverResult = this.resolverCache.Lookup(xamlType.UnderlyingType); if (resolverResult == null) { resolverResult = MultiTargetingTypeResolver.Resolve(multiTargetingService, xamlType.UnderlyingType); this.resolverCache.Update(xamlType.UnderlyingType, resolverResult); } return(MultiTargetingTypeResolver.GetXamlType(resolverResult, xamlType)); }
public MultiTargetingXamlSchemaContext(MultiTargetingSupportService multiTargetingService) { Fx.Assert(multiTargetingService != null, "multiTargetingService should not be null"); this.multiTargetingService = multiTargetingService; }