void AddEntriesForVariables(ModelItem modelItem)
        {
            ModelItemCollection variables = VariableHelper.GetVariableCollection(modelItem);

            if (variables != null)
            {
                foreach (ModelItem variable in variables)
                {
                    entries.Add(CreateSearchableEntry(SearchableEntryOption.Variable, variable, null,
                                                      TypeNameHelper.GetDisplayName(variable.Properties[DesignTimeVariable.VariableTypeProperty].ComputedValue as Type, false), null));

                    entries.Add(CreateSearchableEntry(SearchableEntryOption.Variable, variable, null,
                                                      variable.Properties[DesignTimeVariable.VariableNameProperty].ComputedValue.ToString(), null));

                    object propertyValue = variable.Properties[DesignTimeVariable.VariableDefaultProperty].ComputedValue;

                    if (propertyValue != null)
                    {
                        entries.Add(CreateSearchableEntry(SearchableEntryOption.Variable, variable, null,
                                                          ExpressionToString(propertyValue), null));
                    }

                    if (this.editingContext.Services.GetService <DesignerConfigurationService>().AnnotationEnabled)
                    {
                        string annotationText = (string)variable.Properties[Annotation.AnnotationTextPropertyName].ComputedValue;
                        if (!string.IsNullOrEmpty(annotationText))
                        {
                            entries.Add(CreateSearchableEntry(SearchableEntryOption.Variable, variable, null, annotationText, null));
                        }
                    }
                }
            }
        }
Exemple #2
0
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            string displayName = string.Empty;

            if (values[0] != DependencyProperty.UnsetValue)
            {
                displayName = values[0] as string;
            }

            if (string.IsNullOrEmpty(displayName) && values[1] != DependencyProperty.UnsetValue)
            {
                ModelItem modelItem = values[1] as ModelItem;
                if (modelItem != null)
                {
                    ModelProperty nameProperty = modelItem.Properties["Name"];
                    if (nameProperty != null && nameProperty.Value != null)
                    {
                        displayName = nameProperty.Value.GetCurrentValue() as string;
                    }

                    if (string.IsNullOrEmpty(displayName))
                    {
                        Fx.Assert(modelItem.ItemType != null && modelItem.ItemType.Name != null, "ModelItem should always have a name");
                        displayName = TypeNameHelper.GetDisplayName(modelItem.ItemType, false);
                    }
                }
            }

            return(displayName);
        }
Exemple #3
0
        void OnEditTypeAssigned()
        {
            if (null != this.EditedType && this.EditedType.IsGenericTypeDefinition)
            {
                this.typeName.Text = TypeNameHelper.GetDisplayName(this.EditedType, false);

                Type[] generics = this.EditedType.GetGenericArguments();
                foreach (Type type in generics)
                {
                    Type         temp = type; // reference this temp variable instead of reference type in the anonymous delegate
                    TypeKeyValue tkv  = new TypeKeyValue(type, new Action <TypeKeyValue>(NotifyTypeChanged))
                    {
                        IsSelected = false,
                        Filter     = delegate(Type t)
                        {
                            if (!TypeUtilities.CanSubstituteGenericParameter(temp, t))
                            {
                                return(false);
                            }

                            return(this.Options == null ||
                                   this.Options.Filter == null ||
                                   this.Options.Filter(t));
                        },
                        MostRecentlyUsedTypes = this.Options != null ? this.Options.MostRecentlyUsedTypes : null,
                    };
                    string hintText = null;
                    if (this.Options != null && this.Options.HintTextMap.TryGetValue(type.Name, out hintText))
                    {
                        tkv.HintText = hintText;
                    }

                    this.GenericTypeMapping.Add(tkv);

                    if (this.Options == null || !this.Options.BrowseTypeDirectly)
                    {
                        tkv.BrowseTypeDirectly = false;
                        //this has to happen after the tkv is added GenericTypeMapping because:
                        //when TargetType is set, TypeResolver will try to resolve the generic type with this TargetType as type argument,
                        //and when resolvig the type, TypeResolver needs to know all the mappings
                        if (tkv.MostRecentlyUsedTypes == null)
                        {
                            if (tkv.Filter == null || tkv.Filter(typeof(int)))
                            {
                                tkv.TargetType = typeof(int);
                            }
                        }
                        else if (tkv.MostRecentlyUsedTypes.Contains(typeof(int)))
                        {
                            tkv.TargetType = typeof(int);
                        }
                        else if (tkv.MostRecentlyUsedTypes.Count > 0)
                        {
                            tkv.TargetType = tkv.MostRecentlyUsedTypes[0];
                        }
                    }
                }
            }
        }
        public void GetDisplayName_ReturnsEmptyString()
        {
            // act
            string result = TypeNameHelper.GetDisplayName(null, false);

            // assert
            Assert.AreEqual("", result);
        }
Exemple #5
0
        public void BroadCastData(object target, Stream outgoingData)
        {
            //configure once the vs version
            string vsVersion = VisualStudioVersionHelper.FindCurrentVisualStudioVersion();

            RavenWrapper.VisualStudioVersion = vsVersion;
            Log.VisualStudioVersion          = vsVersion;

            try
            {
                Type   targetType         = GetInterfaceTypeIfIsIterator(target);
                string targetTypeFullName = TypeNameHelper.GetDisplayName(targetType, fullName: true);
                string targetTypeName     = TypeNameHelper.GetDisplayName(targetType, fullName: false);
                //I'm lazy I know...
                Regex pattern1 = new Regex("[<]");
                Regex pattern2 = new Regex("[>]");
                Regex pattern3 = new Regex("[,]");
                Regex pattern4 = new Regex("[`]");
                Regex pattern5 = new Regex("[ ]");

                string fileName = pattern1.Replace(targetTypeFullName, "(");
                fileName = pattern2.Replace(fileName, ")");

                string typeName = pattern1.Replace(targetTypeName, string.Empty);
                typeName = pattern2.Replace(typeName, string.Empty);
                typeName = pattern3.Replace(typeName, string.Empty);
                typeName = pattern4.Replace(typeName, string.Empty);
                typeName = pattern5.Replace(typeName, string.Empty);

                fileName = TypeNameHelper.RemoveSystemNamespaces(fileName);

                Message message = new Message
                {
                    FileName              = string.Format(FileNameFormat, fileName),
                    TypeName              = typeName.Trim(),
                    TypeFullName          = targetTypeFullName,
                    TypeNamespace         = targetType.Namespace,
                    AssemblyQualifiedName = targetType.AssemblyQualifiedName,
                    AssemblyName          = targetType.Assembly.GetName().Name
                };

                BinaryFormatter binaryFormatter = new BinaryFormatter();
                binaryFormatter.Serialize(outgoingData, message);

                Log.Write("BroadCastData to LINQBridgeVsTruck");
                SerializationOption serializationOption = CommonRegistryConfigurations.GetSerializationOption(vsVersion);
                Truck truck = new Truck("LINQBridgeVsTruck", serializationOption);
                truck.LoadCargo(target);
                bool res = truck.DeliverTo(typeName);
                Log.Write("Data Succesfully Shipped to Grapple");
            }
            catch (Exception exception)
            {
                Log.Write(exception, "Error in BroadCastData");
                RavenWrapper.Instance.Capture(exception, message: "Error broadcasting the data to linqpad");
                throw;
            }
        }
        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);
            }
        }
Exemple #7
0
        public static void BroadCastData(object target, Stream outgoingData)
        {
            Log.Configure("LINQBridgeVs", "DynamicCore");

            try
            {
                var targetType         = GetInterfaceTypeIfIsIterator(target);
                var targetTypeFullName = TypeNameHelper.GetDisplayName(targetType, true);
                var targetTypeName     = TypeNameHelper.GetDisplayName(targetType, false);
                //I'm lazy I know it...
                var pattern1 = new Regex("[<]");
                var pattern2 = new Regex("[>]");
                var pattern3 = new Regex("[,]");
                var pattern4 = new Regex("[`]");
                var pattern5 = new Regex("[ ]");

                var fileName = pattern1.Replace(targetTypeFullName, "(");
                fileName = pattern2.Replace(fileName, ")");

                var typeName = pattern1.Replace(targetTypeName, string.Empty);
                typeName = pattern2.Replace(typeName, string.Empty);
                typeName = pattern3.Replace(typeName, string.Empty);
                typeName = pattern4.Replace(typeName, string.Empty);
                typeName = pattern5.Replace(typeName, string.Empty);

                fileName = TypeNameHelper.RemoveSystemNamespaces(fileName);

                var message = new Message
                {
                    FileName     = string.Format(FileNameFormat, fileName),
                    TypeName     = typeName.Trim(),
                    TypeFullName = targetTypeFullName,
                    //TypeLocation = GetAssemblyLocation(vsVersion, targetType.Name),
                    TypeNamespace         = targetType.Namespace,
                    AssemblyQualifiedName = targetType.AssemblyQualifiedName
                };

                var binaryFormatter = new BinaryFormatter();
                binaryFormatter.Serialize(outgoingData, message);

                Log.Write("BroadCastData to LINQBridgeVsTruck");

                var truck = new Truck("LINQBridgeVsTruck");
                truck.LoadCargo(target);
                var res = truck.DeliverTo(typeName);
                Log.Write("Data Succesfully Shipped to Grapple");
            }
            catch (Exception e)
            {
                Log.Write(e, "Error in BroadCastData");
            }
        }
        internal static string ResolveTypeName(Type type)
        {
            Fx.Assert(type != null, "parameter type is null!");
            string typeName;

            if (TypePresenter.DefaultTypes.Contains(type))
            {
                typeName = type.Name;
            }
            else
            {
                typeName = TypeNameHelper.GetDisplayName(type, true);
            }
            return(typeName);
        }
        private void OnSelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e)
        {
            TypeNode entry = ((System.Windows.Controls.TreeView)sender).SelectedItem as TypeNode;

            if (entry != null && this.SelectedType != entry.Data as Type)
            {
                UpdateSelectedItem(entry);
                if (null != this.SelectedType)
                {
                    typeEntryTextBox.TextChanged -= new TextChangedEventHandler(OnTypeSearchTextChanged);
                    typeEntryTextBox.Text         = TypeNameHelper.GetDisplayName(this.SelectedType, true);
                    typeEntryTextBox.TextChanged += new TextChangedEventHandler(OnTypeSearchTextChanged);
                }
            }
        }
Exemple #10
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            Type type = value as Type;

            if (type == null)
            {
                ModelItem modelItem = value as ModelItem;
                if (modelItem != null)
                {
                    type = modelItem.GetCurrentValue() as Type;
                }
            }

            bool fullName = bool.Parse(parameter.ToString());

            return(TypeNameHelper.GetDisplayName(type, fullName));
        }
Exemple #11
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            DynamicActivityProperty property = value as DynamicActivityProperty;

            if (property == null)
            {
                return(null);
            }

            if (property.Type == null)
            {
                return(string.Format(CultureInfo.CurrentUICulture, SR.PropertyReferenceNotResolved, property.Name));
            }
            else
            {
                return(TypeNameHelper.GetDisplayName(property.Type, false));
            }
        }
        void AddEntriesForArguments(Selection selection, ref int startIndex)
        {
            ModelProperty argumentsProperty = this.modelService.Root.Properties["Properties"];

            if (argumentsProperty == null)
            {
                return;
            }
            ModelItemCollection arguments = argumentsProperty.Collection;

            if (arguments != null)
            {
                ModelItem selectedArgument = this.GetTopmostSelectedArgument(selection, arguments);
                foreach (ModelItem argument in arguments)
                {
                    // Do this check to make sure we start from the topmost selected item.
                    if (startIndex == StartIndexUnchangeMark && argument == selectedArgument && argument != lastNavigatedItem)
                    {
                        startIndex = index;
                    }
                    entries.Add(CreateSearchableEntry(SearchableEntryOption.Argument, argument, null,
                                                      TypeNameHelper.GetDisplayName(argument.Properties["Type"].ComputedValue as Type, false), null));

                    entries.Add(CreateSearchableEntry(SearchableEntryOption.Argument, argument, null,
                                                      argument.Properties[DesignTimeArgument.ArgumentNameProperty].ComputedValue.ToString(), null));

                    IList <string> argumentValues = GetSearchableStrings(argument.Properties[DesignTimeArgument.ArgumentDefaultValueProperty].ComputedValue);
                    if (argumentValues.Count == 1)
                    {
                        AddEntriesForPropertyValue(argumentValues[0],
                                                   argument, null, SearchableEntryOption.Argument, null);
                    }

                    if (this.editingContext.Services.GetService <DesignerConfigurationService>().AnnotationEnabled)
                    {
                        string annotationText = (string)argument.Properties[Annotation.AnnotationTextPropertyName].ComputedValue;
                        if (!string.IsNullOrEmpty(annotationText))
                        {
                            entries.Add(CreateSearchableEntry(SearchableEntryOption.Argument, argument, null, annotationText, null));
                        }
                    }
                }
            }
        }
Exemple #13
0
        private void AppendResolutionPath(StringBuilder builder, Type currentlyResolving = null)
        {
            foreach (var pair in _callSiteChain.OrderBy(p => p.Value.Order))
            {
                var serviceType        = pair.Key;
                var implementationType = pair.Value.ImplementationType;
                if (implementationType == null || serviceType == implementationType)
                {
                    builder.Append(TypeNameHelper.GetDisplayName(serviceType));
                }
                else
                {
                    builder.AppendFormat("{0}({1})",
                                         TypeNameHelper.GetTypeDisplayName(serviceType),
                                         TypeNameHelper.GetTypeDisplayName(implementationType));
                }
                builder.Append(" -> ");
            }

            builder.Append(TypeNameHelper.GetTypeDisplayName(currentlyResolving));
        }
        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);
        }
Exemple #15
0
 public TypeNode(Type type)
 {
     this.type        = type;
     this.displayName = TypeNameHelper.GetDisplayName(type, false);
     this.fullName    = TypeNameHelper.GetDisplayName(type, true);
 }
        private void OnHandlerChanged()
        {
            if (!this.isSetInternally)
            {
                if (this.Handler == null)
                {
                    this.ActivityDelegate = null;
                }
                else
                {
                    if (this.Factory != null && this.EditingContext != null)
                    {
                        try
                        {
                            ActivityDelegate instance = this.Factory.Create();
                            Fx.Assert(instance != null, "Factory should not return null");
                            ModelItem modelItem = this.EditingContext.Services.GetService <ModelTreeManager>().WrapAsModelItem(instance);
                            modelItem.Properties["Handler"].SetValue(this.Handler);
                            this.ActivityDelegate = modelItem;
                        }
                        catch (Exception ex)
                        {
                            if (Fx.IsFatal(ex))
                            {
                                throw;
                            }

                            string details = ex.Message;

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

                            this.ReportError(string.Format(CultureInfo.CurrentUICulture, SR.CannotCreateInstance, TypeNameHelper.GetDisplayName(this.Factory.DelegateType, false)), details);

                            this.isSetInternally = true;
                            this.Handler         = null;
                            this.isSetInternally = false;
                        }
                    }
                }
            }
        }
 static string GetStringRepresentation(Type type)
 {
     return(TypeNameHelper.GetDisplayName(type, true));
 }
 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);
 }