コード例 #1
0
        /// <summary>
        /// Creates a new <see cref="FactType"/> with the specified <paramref name="arity"/>.
        /// </summary>
        /// <param name="store">
        /// The <see cref="Store"/> in which the new <see cref="FactType"/> should be created.
        /// </param>
        /// <param name="group">
        /// The <see cref="ElementGroup"/> to which the new <see cref="FactType"/> and its <see cref="Role"/>s should
        /// be added.
        /// </param>
        /// <param name="arity">
        /// The number of <see cref="Role"/>s that the new <see cref="FactType"/> should contain.
        /// </param>
        /// <returns>
        /// The newly created <see cref="FactType"/>.
        /// </returns>
        /// <remarks>
        /// The new <see cref="FactType"/> is added to <paramref name="group"/> as a root element.
        /// </remarks>
        private static FactType AddFactType(Store store, ElementGroup group, int arity)
        {
            FactType factType = new FactType(store, null);

            group.AddGraph(factType, true);
            LinkedElementCollection <RoleBase> roles = factType.RoleCollection;

            for (int i = 0; i < arity; i++)
            {
                Role role = new Role(store);
                roles.Add(role);
                group.AddGraph(role);
            }
            return(factType);
        }
コード例 #2
0
        private static ElementGroupPrototype MakePrototype(GadgeteerHardware element)
        {
            var elementGroup = new ElementGroup(element.Store.DefaultPartition);

            elementGroup.AddGraph(element, true);
            return(elementGroup.CreatePrototype());
        }
コード例 #3
0
        /* There are two versions of CreateElementToolPrototype here.
         * One deals with each Component subtype separately: if you add a new subtype, you need to add more here.
         * The other automatically deals with eacn Component subtype, using DSL reflection info.
         *
         * See http://msdn.microsoft.com/library/bb126279.aspx#groups
         */

        /*
         * /// <summary>
         * /// Toolbox initialization, called for each element tool on the toolbox.
         * /// This version deals with each Component subtype separately.
         * /// </summary>
         * /// <param name="store"></param>
         * /// <param name="domainClassId">Identifies the domain class this tool should instantiate.</param>
         * /// <returns>prototype of the object or group of objects to be created by tool</returns>
         * protected override ElementGroupPrototype CreateElementToolPrototype(Store store, Guid domainClassId)
         * {
         *
         *  if (domainClassId == Resistor.DomainClassId)
         *  {
         *      Resistor resistor = new Resistor(store);
         *
         *      // Must initialize these in order of initialization:
         *      // DSLT v1 bug affecting derived relationships.
         *      resistor.T1 = new ComponentTerminal(store);
         *      resistor.T2 = new ComponentTerminal(store);
         *
         *      resistor.T1.Name = "t1";
         *      resistor.T2.Name = "t2";
         *
         *      ElementGroup elementGroup = new ElementGroup(store.DefaultPartition);
         *      elementGroup.AddGraph(resistor, true);
         *      // AddGraph includes the embedded parts.
         *
         *      return elementGroup.CreatePrototype();
         *  }
         *  else if (domainClassId == Capacitor.DomainClassId)
         *  {
         *      Capacitor capacitor = new Capacitor(store);
         *
         *      // Must initialize these in order of initialization:
         *      // DSLT v1 bug affecting derived relationships.
         *      capacitor.T1 = new ComponentTerminal(store);
         *      capacitor.T2 = new ComponentTerminal(store);
         *
         *      capacitor.T1.Name = "t1";
         *      capacitor.T2.Name = "t2";
         *
         *      ElementGroup elementGroup = new ElementGroup(store.DefaultPartition);
         *      elementGroup.AddGraph(capacitor, true);
         *      // AddGraph includes the embedded parts.
         *
         *      return elementGroup.CreatePrototype();
         *  }
         *
         *  else if (domainClassId == Transistor.DomainClassId)
         *  {
         *      Transistor transistor = new Transistor(store);
         *
         *      // Must initialize these in order of initialization:
         *      // DSLT v1 bug affecting derived relationships.
         *      transistor.Base = new ComponentTerminal(store);
         *      transistor.Collector = new ComponentTerminal(store);
         *      transistor.Emitter = new ComponentTerminal(store);
         *
         *      transistor.Base.Name = "base";
         *      transistor.Collector.Name = "collector";
         *      transistor.Emitter.Name = "emitter";
         *
         *      // Create an ElementGroup for the Toolbox.
         *      ElementGroup elementGroup = new ElementGroup(store.DefaultPartition);
         *      elementGroup.AddGraph(transistor, true);
         *      // AddGraph includes the embedded parts
         *
         *      return elementGroup.CreatePrototype();
         *  }
         *
         *  else
         *  {
         *      return base.CreateElementToolPrototype(store, domainClassId);
         *  }
         *
         *
         * }
         *
         */

        /// <summary>
        /// Toolbox initialization for components with fixed embedded parts.
        /// This deals with all the subclasses of Component, adding an instance for each relationship derived from ComponentHasTerminals.
        /// The benefit of this approach is that it does not need to be adjusted for each new Component subclass.
        /// Called for each element tool on the toolbox.
        /// </summary>
        /// <param name="store"></param>
        /// <param name="domainClassId">Identifies the domain class this tool should instantiate.</param>
        /// <returns>prototype of the object or group of objects to be created by tool</returns>
        protected override ElementGroupPrototype CreateElementToolPrototype(Store store, Guid domainClassId)
        {
            // Called for each element tool on the toolbox.
            // Get the class meta info for this class.
            DomainClassInfo thisClassInfo = store.DomainDataDirectory.FindDomainClass(domainClassId);

            if (!thisClassInfo.IsDerivedFrom(Component.DomainClassId))
            {
                // Not one of those we're interested in: defer to base method.
                return(base.CreateElementToolPrototype(store, domainClassId));
            }
            else
            {
                // Construct an instance of this type. Use the constructor that takes a store and a variable number of property bindings.
                Component component = (Component)thisClassInfo.ImplementationClass. // get the actual class from the meta info
                                      InvokeMember(                                 // method in System.Reflection.Type
                    "",
                    System.Reflection.BindingFlags.CreateInstance                   // invoke the constructor
                    | System.Reflection.BindingFlags.OptionalParamBinding,          // which has a params binding
                    null,                                                           // no special binder
                    null,                                                           //no target object since we want the constructor
                    new object[] { store });                                        // Called like "new Resistor(store)"

                // Now add whatever ComponentTerminals it has.
                // Each Component subtype sources several subrelationships of ComponentHasComponentTerminal.
                // Go through the metainfo about each role the class plays in relationships.
                foreach (DomainRoleInfo role in thisClassInfo.LocalDomainRolesPlayed)
                {
                    // Pick out the roles that are one end of a relationship to a Terminal.
                    if (role.DomainRelationship.IsDerivedFrom(ComponentHasComponentTerminal.DomainClassId) &&
                        !role.DomainRelationship.ImplementationClass.IsAbstract)
                    {
                        ComponentTerminal terminal = new ComponentTerminal(store);
                        // Fill in the instance name with the name of the role - just a convenience.
                        // The role at the Terminal end of the relationship is the one called "T1" or "collector" or some such.
                        terminal.Name = role.OppositeDomainRole.Name.ToLowerInvariant();
                        // Instantiate the relationship with the constructor that takes the component and terminal.
                        role.DomainRelationship.ImplementationClass.InvokeMember("", System.Reflection.BindingFlags.CreateInstance,
                                                                                 null, null,
                                                                                 new object[] { component, terminal });
                    }
                }
                // Create an Element Group Prototype containing this tree.
                ElementGroup elementGroup = new ElementGroup(store.DefaultPartition);
                elementGroup.AddGraph(component, true, true); // AddGraph includes the embedded elements.
                elementGroup.AddRange(component.ComponentTerminals, true);
                ElementGroupPrototype egp = elementGroup.CreatePrototype();
                return(egp);
            }
        }
コード例 #4
0
        /// <summary>
        /// Create a serialized prototype for Activity to attach to the toolbox.
        /// </summary>
        /// <param name="toolboxItem"></param>
        /// <returns>The prototype</returns>
        public override ElementGroupPrototype InitializeToolboxItem(ModelingToolboxItem toolboxItem)
        {
            ElementGroup          elementGroup = new ElementGroup(this.Store);
            ElementGroupPrototype proto        = null;

            Debug.Assert(this.Store.TransactionManager.InTransaction, "Must be in transaction");

            ISpySoft.SFSchemaLanguage.DomainModel.Activity instance = ISpySoft.SFSchemaLanguage.DomainModel.Activity.CreateActivity(this.Store);

            if (instance != null)
            {
                elementGroup.AddGraph(instance);

                proto = elementGroup.CreatePrototype(instance);
            }
            return(proto);
        }
コード例 #5
0
ファイル: CopyCommand.cs プロジェクト: malain/candle
        /// <summary>
        /// Execute the command
        /// </summary>
        public void Exec()
        {
            ElementGroup elementGroup = new ElementGroup(_store);
            bool         foundSome    = false;

            foreach (object o in _elements)
            {
                // Pick out shapes representing Component model elements.
                ShapeElement element = o as ShapeElement;
                if (element != null && element.ModelElement != null || o is ModelElement)
                {
                    ModelElement mel = element != null ? element.ModelElement : o as ModelElement;
                    if (mel is Entity ||
                        mel is Operation ||
                        mel is Enumeration ||
                        mel is ClassImplementation ||
                        mel is ServiceContract ||
                        mel is Property)
                    {
                        // add the element and its embedded children to the group
                        elementGroup.AddGraph(mel, true);
                        foundSome = true;
                    }
                }
            }
            if (!foundSome)
            {
                return;
            }

            // A DataObject carries a serialized version.
            System.Windows.Forms.IDataObject data = new System.Windows.Forms.DataObject();
            data.SetData(elementGroup.CreatePrototype());
            System.Windows.Forms.Clipboard.SetDataObject
                (data,     // serialized clones of our selected model elements
                false,     // we don’t want to export outside this application
                10,        // retry 10 times on failure
                50);       // waiting 50ms between retries
        }
コード例 #6
0
        /// <summary>See <see cref="ORMShapeToolboxHelperBase.CreateElementToolPrototype"/>.</summary>
        protected sealed override ElementGroupPrototype CreateElementToolPrototype(Store store, Guid domainClassId)
        {
            // WARNING: This method is _extremely_ order-sensitive. If the order that the toolbox items are listed
            // in the .dsl file changes, or if the DSL Tools text template that is used to generate ORMShapeModelToolboxHelperBase
            // changes, this method will most likely need to be changed as well.

            ElementGroup group       = null;
            bool         unknownItem = false;

            if (domainClassId.Equals(ObjectType.DomainClassId))
            {
                group = new ElementGroup(store);
                ObjectType objectType = new ObjectType(store);
                group.AddGraph(objectType, true);
                switch (myObjectTypeCount++)
                {
                case 0:
                    // EntityType - We don't need to do anything else...
                    break;

                case 1:
                    // ValueType
                    // Do not try to set the IsValueType property here. IsValueType picks
                    // up the default data type for the model, which can only be done
                    // when the model is known. Instead, flag the element so that it
                    // can be set during MergeRelate on the model.
                    group.UserData = ORMModel.ValueTypeUserDataKey;
                    break;

                case 2:
                    // ObjectifiedFactType
                    group.AddGraph(new Objectification(objectType, AddFactType(store, group, 2)), false);
                    break;

                default:
                    unknownItem = true;
                    break;
                }
            }
            else if (domainClassId.Equals(FactType.DomainClassId))
            {
                group = new ElementGroup(store);
                Debug.Assert(myFactTypeCount < 3);
                AddFactType(store, group, ++myFactTypeCount);
            }
            else if (domainClassId.Equals(ExclusiveOrConstraintCoupler.DomainClassId))
            {
                group = new ElementGroup(store);
                MandatoryConstraint mandatory = new MandatoryConstraint(store, null);
                group.AddGraph(mandatory, true);
                ExclusionConstraint exclusion = new ExclusionConstraint(store, null);
                group.AddGraph(exclusion, true);
                group.AddGraph(new ExclusiveOrConstraintCoupler(mandatory, exclusion), false);
            }
            else if (domainClassId.Equals(UniquenessConstraint.DomainClassId))
            {
                group = new ElementGroup(store);
                if (myUniquenessConstraintCount == 0)
                {
                    // Add this here so that we can distinguish between internal and external uniqueness
                    // constraints without unpacking the model. We want to merge internals into a fact
                    // and externals into the model.
                    group.UserData = ORMModel.InternalUniquenessConstraintUserDataKey;
                    group.AddGraph(UniquenessConstraint.CreateInternalUniquenessConstraint(store.DefaultPartition), true);
                }
                else
                {
                    Debug.Assert(myUniquenessConstraintCount == 1);
                    group.AddGraph(new UniquenessConstraint(store), true);
                }
                myUniquenessConstraintCount++;
            }
            return((group == null || unknownItem) ? base.CreateElementToolPrototype(store, domainClassId) : group.CreatePrototype());
        }
コード例 #7
0
ファイル: ORMToolboxHelper.cs プロジェクト: cjheath/NORMA
		/// <summary>See <see cref="ORMShapeToolboxHelperBase.CreateElementToolPrototype"/>.</summary>
		protected sealed override ElementGroupPrototype CreateElementToolPrototype(Store store, Guid domainClassId)
		{
			// WARNING: This method is _extremely_ order-sensitive. If the order that the toolbox items are listed
			// in the .dsl file changes, or if the DSL Tools text template that is used to generate ORMShapeModelToolboxHelperBase
			// changes, this method will most likely need to be changed as well.

			ElementGroup group = null;
			bool unknownItem = false;

			if (domainClassId.Equals(ObjectType.DomainClassId))
			{
				group = new ElementGroup(store);
				ObjectType objectType = new ObjectType(store);
				group.AddGraph(objectType, true);
				switch (myObjectTypeCount++)
				{
					case 0:
						// EntityType - We don't need to do anything else...
						break;
					case 1:
						// ValueType
						// Do not try to set the IsValueType property here. IsValueType picks
						// up the default data type for the model, which can only be done
						// when the model is known. Instead, flag the element so that it
						// can be set during MergeRelate on the model.
						group.UserData = ORMModel.ValueTypeUserDataKey;
						break;
					case 2:
						// ObjectifiedFactType
						group.AddGraph(new Objectification(objectType, AddFactType(store, group, 2)), false);
						break;
					default:
						unknownItem = true;
						break;
				}
			}
			else if (domainClassId.Equals(FactType.DomainClassId))
			{
				group = new ElementGroup(store);
				Debug.Assert(myFactTypeCount < 3);
				AddFactType(store, group, ++myFactTypeCount);
			}
			else if (domainClassId.Equals(ExclusiveOrConstraintCoupler.DomainClassId))
			{
				group = new ElementGroup(store);
				MandatoryConstraint mandatory = new MandatoryConstraint(store, null);
				group.AddGraph(mandatory, true);
				ExclusionConstraint exclusion = new ExclusionConstraint(store, null);
				group.AddGraph(exclusion, true);
				group.AddGraph(new ExclusiveOrConstraintCoupler(mandatory, exclusion), false);
			}
			else if (domainClassId.Equals(UniquenessConstraint.DomainClassId))
			{
				group = new ElementGroup(store);
				if (myUniquenessConstraintCount == 0)
				{
					// Add this here so that we can distinguish between internal and external uniqueness
					// constraints without unpacking the model. We want to merge internals into a fact
					// and externals into the model.
					group.UserData = ORMModel.InternalUniquenessConstraintUserDataKey;
					group.AddGraph(UniquenessConstraint.CreateInternalUniquenessConstraint(store), true);
				}
				else
				{
					Debug.Assert(myUniquenessConstraintCount == 1);
					group.AddGraph(new UniquenessConstraint(store), true);
				}
				myUniquenessConstraintCount++;
			}
			return (group == null || unknownItem) ? base.CreateElementToolPrototype(store, domainClassId) : group.CreatePrototype();
		}
コード例 #8
0
ファイル: ORMToolboxHelper.cs プロジェクト: cjheath/NORMA
		/// <summary>
		/// Creates a new <see cref="FactType"/> with the specified <paramref name="arity"/>.
		/// </summary>
		/// <param name="store">
		/// The <see cref="Store"/> in which the new <see cref="FactType"/> should be created.
		/// </param>
		/// <param name="group">
		/// The <see cref="ElementGroup"/> to which the new <see cref="FactType"/> and its <see cref="Role"/>s should
		/// be added.
		/// </param>
		/// <param name="arity">
		/// The number of <see cref="Role"/>s that the new <see cref="FactType"/> should contain.
		/// </param>
		/// <returns>
		/// The newly created <see cref="FactType"/>.
		/// </returns>
		/// <remarks>
		/// The new <see cref="FactType"/> is added to <paramref name="group"/> as a root element.
		/// </remarks>
		private static FactType AddFactType(Store store, ElementGroup group, int arity)
		{
			FactType factType = new FactType(store, null);
			group.AddGraph(factType, true);
			LinkedElementCollection<RoleBase> roles = factType.RoleCollection;
			for (int i = 0; i < arity; i++)
			{
				Role role = new Role(store);
				roles.Add(role);
				group.AddGraph(role);
			}
			return factType;
		}