Ejemplo n.º 1
0
        static object CreateMenuItemFromDescriptor(NavItemDescriptor descriptor)
        {
            Codon  codon     = descriptor.Codon;
            string builderid = string.Empty;

            if (codon.Properties.Contains("builderid"))
            {
                builderid = codon.Properties["builderid"];
            }
            else
            {
                throw new Exception(string.Format("BuiderID not found:codonid ={0},condonname = {1}", codon.Id, codon.Name));
            }
            if (builderid == string.Empty)
            {
                throw new Exception(string.Format("BuiderID is empty:codonid ={0},condonname = {1}", codon.Id, codon.Name));
            }

            IPartBuilder builder = RibbonBuilderManager.GetBuider(builderid);
            object       obj     = builder.Build(codon, descriptor.Caller, codon.Conditions);

            if (obj is ModuleNavBarItem)
            {
                ModuleNavBarItem item = obj as ModuleNavBarItem;
                item.ModuleName = codon.Id;
            }
            return(obj);
        }
        public KeyValuePairPartBuilder(Type type, PartDefinition partDefinition, IPartResolver resolver)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            if (!type.IsGenericType || type.GetGenericTypeDefinition() != typeof(KeyValuePair <,>))
            {
                throw new ArgumentException("type must be a KeyValuePair<,>", "type");
            }

            if (type.IsGenericTypeDefinition)
            {
                throw new ArgumentException("The type parameters of type are not defined", "type");
            }

            _type = type;
            var typeArgs = _type.GetGenericArguments();

            _keyType      = typeArgs[0];
            _valueType    = typeArgs[1];
            _keyBuilder   = resolver.GetPartBuilder(_keyType, partDefinition, true);
            _valueBuilder = resolver.GetPartBuilder(_valueType, partDefinition, true);
            _ctor         = _type.GetConstructor(new[] { _keyType, _valueType });
            Debug.Assert(_ctor != null, "Couldn't find KeyValuePair constructor");
        }
Ejemplo n.º 3
0
 public void InnerFill(IPartBuilder innerBuilder, IExpression innerMember)
 {
     Generator.BeginScope();
     _members.Push(innerMember);
     innerBuilder.GenerateFillPart(this);
     _members.Pop();
     Generator.EndScope();
 }
Ejemplo n.º 4
0
 public NullablePartBuilder(Type nullableType, PartDefinition partDefinition, IPartResolver resolver)
 {
     if (nullableType.GetGenericTypeDefinition() != typeof(Nullable <>))
     {
         throw new ArgumentException(string.Format("{0} is not a Nullable<T>", nullableType), "nullableType");
     }
     _type         = nullableType;
     _innerType    = _type.GetGenericArguments()[0];
     _ctor         = _type.GetConstructor(new[] { _innerType });
     _innerBuilder = resolver.GetPartBuilder(_innerType, partDefinition, true);
 }
        public void GenerateInnerAssert(IPartBuilder innerBuilder, IExpression expected, IExpression actual)
        {
            var g = Generator;

            _shortcutStack.Push(new KeyValuePair <IExpression, IExpression>(expected, actual));
            g.BeginScope();
            {
                innerBuilder.GenerateAssertAreEqualPart(this);
            }
            g.EndScope();
            _shortcutStack.Pop();
        }
Ejemplo n.º 6
0
        private void LoadCustomCommand(Codon codon, MenuItemDescriptor descriptor)
        {
            string commandId      = codon.Id;
            string builderid      = string.Empty;
            string checkForViewId = string.Empty;
            string controllerId   = string.Empty;

            //builder
            if (string.IsNullOrEmpty(codon.Properties["builderid"]))
            {
                throw new Exception(string.Format("BuiderID not found:codonid ={0},condonname = {1}", codon.Id, codon.Name));
            }
            else
            {
                builderid = codon.Properties["builderid"];
            }

            if (!string.IsNullOrEmpty(codon.Properties["controllerId"]))
            {
                controllerId = codon.Properties["controllerId"];
            }
            //checkForViewId
            if (!string.IsNullOrEmpty(codon.Properties["checkForViewId"]))
            {
                checkForViewId = codon.Properties["checkForViewId"];
            }


            //build item
            IPartBuilder buider = RibbonBuilderManager.GetBuider(builderid);
            object       item   = buider.Build(codon, this._controllerFinder.FindController(string.Empty), codon.Conditions);

            if (!(item is BarItem))
            {
                throw new Exception(string.Format("Builded Custom Command object is not BarItem:id ={0},name = {1}", codon.Id, codon.Name));
            }
            if (string.IsNullOrEmpty(codon.Properties["class"]))
            {
                throw new Exception(string.Format("Action Command Class not defined in Custom Command:id ={0},name = {1}", codon.Id, codon.Name));
            }
            //build action command
            ICommand command = (ICommand)codon.AddIn.CreateObject(codon.Properties["class"]);

            BarItem       barItem = item as BarItem;
            CommandDrawer drawer  = new CommandDrawer();

            drawer.SetItemGlyph(codon, barItem);
            this._barManager.Items.Add(barItem);
            this.AddCustomCommand(commandId, checkForViewId, barItem, command, descriptor.Conditions, controllerId);
        }
Ejemplo n.º 7
0
        public ArrayPartBuilder(Type arrayType, PartDefinition partDefinition, IPartResolver resolver)
        {
            if (!arrayType.IsArray)
            {
                throw new ArgumentException("arrayType is not an array", "arrayType");
            }

            if (arrayType.GetArrayRank() != 1)
            {
                throw new NotSupportedException("Multi-dimensional arrays are not supported by this class.");
            }

            _elementType    = arrayType.GetElementType();
            _elementBuilder = resolver.GetPartBuilder(_elementType, partDefinition, true);
        }
Ejemplo n.º 8
0
        public EnumPartBuilder(Type type, PartDefinition partDefinition, IPartResolver resolver)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            if (!type.IsEnum)
            {
                throw new ArgumentException("type must be an enumeration", "type");
            }

            _type           = type;
            _underlyingType = Enum.GetUnderlyingType(type);
            _innerBuilder   =
                _underlyingType == typeof(int)
                ? new PrimitivePartBuilder(typeof(int), "ReadVarInt32", "WriteVarInt32")
                                : resolver.GetPartBuilder(_underlyingType, partDefinition, true);
        }
Ejemplo n.º 9
0
        public CollectionPartBuilder(Type collectionType, Type elementType, PartDefinition partDefinition, IPartResolver resolver, Type underlyingType)
        {
            if (collectionType == null)
            {
                throw new ArgumentNullException("collectionType");
            }
            if (elementType == null)
            {
                throw new ArgumentNullException("elementType");
            }
            if (partDefinition == null)
            {
                throw new ArgumentNullException("partDefinition");
            }
            if (resolver == null)
            {
                throw new ArgumentNullException("resolver");
            }

            _collectionType = collectionType;
            _elementType    = elementType;
            _innerBuilder   = resolver.GetPartBuilder(_elementType, partDefinition, true);

            if (_innerBuilder == null)
            {
                throw new NotSupportedException(string.Format("Type '{0}' cannot be serialized", elementType));
            }

            var interfaceType = typeof(ICollection <>).MakeGenericType(elementType);

            if (!interfaceType.IsAssignableFrom(collectionType))
            {
                throw new ArgumentException(string.Format(
                                                "collectionType '{0}' is not assignable to '{1}'",
                                                collectionType.Name,
                                                interfaceType.Name),
                                            "collectionType");
            }

            _getCount = _collectionType.GetBestCallableOverride(interfaceType.ResolveProperty("Count").GetGetMethod());
            _add      = _collectionType.GetBestCallableOverride(interfaceType.ResolveMethod("Add", new[] { elementType }));
            _contains = _collectionType.GetBestCallableOverride(interfaceType.ResolveMethod("Contains", elementType));

            const BindingFlags bindingFlags =
                BindingFlags.CreateInstance
                | BindingFlags.Public
                | BindingFlags.NonPublic
                | BindingFlags.Instance;

            _ctor     = underlyingType.GetConstructor(bindingFlags, null, new[] { typeof(int) }, null);
            _ctorType = CtorType.Capacity;
            if (_ctor == null || _ctor.GetParameters()[0].Name != "capacity")
            {
                _ctor     = underlyingType.GetConstructor(bindingFlags, null, Type.EmptyTypes, null);
                _ctorType = CtorType.Default;
            }

            if (_ctor == null)
            {
                throw new ArgumentException("collectionType='" + collectionType.Name + "' does not define .ctor(int capacity) or .ctor()", "collectionType");
            }
        }
Ejemplo n.º 10
0
        static object CreateMenuItemFromDescriptor(MenuItemDescriptor descriptor, string addinTreePath, ICommandRegister register)
        {
            Codon codon = descriptor.Codon;

            string cmdPath   = addinTreePath + "/" + codon.Id;
            string builderid = string.Empty;

            if (codon.Properties.Contains("builderid"))
            {
                builderid = codon.Properties["builderid"];
            }
            else if (codon.Properties.Contains("cmdId"))
            {
                string cmdId = codon.Properties["cmdId"];
                return(register.GetBarItem(cmdId));
            }
            else
            {
                throw new Exception(string.Format("BuiderID not found:codonid ={0},condonname = {1}", codon.Id, codon.Name));
            }
            if (builderid == string.Empty)
            {
                throw new Exception(string.Format("BuiderID is empty:codonid ={0},condonname = {1}", codon.Id, codon.Name));
            }

            IPartBuilder builder = RibbonBuilderManager.GetBuider(builderid);
            object       obj     = builder.Build(codon, descriptor.Caller, descriptor.Conditions);;

            try
            {
                if (obj is BarButtonItemEx)
                {
                    BarItem cmdBar = obj as BarItem;

                    string formats = "<MenuItem id ={0} checkForViewId =\"\" source =\"Ribbon\" cmdPath =\"{1}\"/>";
                    System.Diagnostics.Debug.WriteLine(string.Format(formats, codon.Id, cmdPath));
                    if (register != null)
                    {
                        //ICommand command = (ICommand)codon.AddIn.CreateObject(codon.Properties["class"]);
                        //command.Owner = register.owner;
                        ICommand command = cmdBar.Tag as ICommand;
                        if (command != null)
                        {
                            if (string.IsNullOrEmpty(codon.Properties["groupName"]))
                            {
                                bool registerSuc = register.RegisterCommand(cmdBar, cmdPath, command, descriptor.Conditions);
                            }
                            else
                            {
                                string groupName   = codon.Properties["groupName"];
                                bool   registerSuc = register.RegisterCommand(cmdBar, codon.Id, cmdPath, command, groupName);
                            }
                        }
                        //Debug.WriteLine("Register =" + registerSuc.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(obj);
        }