예제 #1
0
        private static void UpdateTypeArgument(ModelItem modelItem, Int32 argumentIndex, Type newGenericType)
        {
            Type itemType = modelItem.ItemType;

            Type[] genericTypes = itemType.GetGenericArguments();

            // Replace the type being changed
            genericTypes[argumentIndex] = newGenericType;

            Type           newType           = itemType.GetGenericTypeDefinition().MakeGenericType(genericTypes);
            EditingContext editingContext    = modelItem.GetEditingContext();
            Object         instanceOfNewType = Activator.CreateInstance(newType);
            ModelItem      newModelItem      = ModelFactory.CreateItem(editingContext, instanceOfNewType);

            using (ModelEditingScope editingScope = newModelItem.BeginEdit("Change type argument"))
            {
                MorphHelper.MorphObject(modelItem, newModelItem);
                MorphHelper.MorphProperties(modelItem, newModelItem);

                if (itemType.IsSubclassOf(typeof(Activity)) && newType.IsSubclassOf(typeof(Activity)))
                {
                    if (DisplayNameRequiresUpdate(modelItem))
                    {
                        // Update to the new display name
                        String newDisplayName = GetActivityDefaultName(newType);

                        newModelItem.Properties[DisplayName].SetValue(newDisplayName);
                    }
                }

                DesignerUpdater.UpdateModelItem(modelItem, newModelItem);

                editingScope.Complete();
            }
        }
        private static void UpdateTypeArgument(ModelItem modelItem, Type value)
        {
            if (value != null)
            {
                Type oldModelItemType = modelItem.ItemType;

                Type newModelItemType = oldModelItemType.GetGenericTypeDefinition().MakeGenericType(value);

                ModelItem newModelItem = ModelFactory.CreateItem(modelItem.GetEditingContext(), Activator.CreateInstance(newModelItemType));
                MorphHelper.MorphObject(modelItem, newModelItem);
                MorphHelper.MorphProperties(modelItem, newModelItem);

                if (oldModelItemType.IsSubclassOf(typeof(Activity)) && newModelItemType.IsSubclassOf(typeof(Activity)))
                {
                    if (string.Equals((string)modelItem.Properties["DisplayName"].ComputedValue, GetActivityDefaultName(oldModelItemType), StringComparison.Ordinal))
                    {
                        newModelItem.Properties["DisplayName"].SetValue(GetActivityDefaultName(newModelItemType));
                    }
                }

                DesignerView designerView = modelItem.GetEditingContext().Services.GetService <DesignerView>();
                if (designerView != null)
                {
                    Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Render, (Action)(() =>
                    {
                        if (designerView.RootDesigner != null && ((WorkflowViewElement)designerView.RootDesigner).ModelItem == modelItem)
                        {
                            designerView.MakeRootDesigner(newModelItem);
                        }
                        Selection.SelectOnly(modelItem.GetEditingContext(), newModelItem);
                    }));
                }
            }
        }
예제 #3
0
 /// <summary>
 ///     Checks if there is a free unit to move to morph into a the desired unit
 /// </summary>
 /// <param name="unitType">the unit type of the desired unit</param>
 /// <returns>true if there is a free unit, false otherwise</returns>
 public static bool PreMorphUnitAvailable(uint unitType)
 {
     if (MorphHelper.MorpSteps.ContainsKey(unitType))
     {
         if (null != GetAvailableAgent(MorphHelper.GetPreMorphType(unitType)))
         {
             return(true);
         }
         return(false);
     }
     else
     {
         Logger.Info("Calling Controller.PreMorphUnitAvailable() on a unit that isnt in morph list. Unit: {0}, Type: {1}",
                     VBot.Bot.Data.Units[(int)unitType], unitType);
         return(false);
     }
 }
        private static void UpdateTypeArgument(ModelItem modelItem, Type argType, int argIndex)
        {
            if (modelItem == null)
            {
                return;
            }

            var argTypes = modelItem.ItemType.GetGenericArguments();

            argTypes[argIndex] = argType;

            var editingContext = modelItem.GetEditingContext();
            var itemType       = modelItem.ItemType;
            var type           = itemType.GetGenericTypeDefinition().MakeGenericType(argTypes);
            var newModelItem   = ModelFactory.CreateItem(editingContext, Activator.CreateInstance(type));

            MorphHelper.MorphObject(modelItem, newModelItem);
            MorphHelper.MorphProperties(modelItem, newModelItem);

            if (itemType.IsSubclassOf(typeof(Activity)) &&
                type.IsSubclassOf(typeof(Activity)) &&
                string.Equals((string)modelItem.Properties[DisplayName].ComputedValue, GetActivityDefaultName(itemType), StringComparison.Ordinal))
            {
                newModelItem.Properties[DisplayName].SetValue(GetActivityDefaultName(type));
            }

            var service = editingContext.Services.GetService <DesignerView>();

            if (service == null)
            {
                return;
            }

            Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Render, new Action(() =>
            {
                if (service.RootDesigner != null && ((WorkflowViewElement)service.RootDesigner).ModelItem == modelItem)
                {
                    service.MakeRootDesigner(newModelItem);
                }

                Selection.SelectOnly(editingContext, newModelItem);
            }));
        }
        // Called by the designer to register any design-time metadata.
        //
        // Be aware of the accidential performance impact when adding things into this method.
        // In particular, pay attention to calls that will lead to loading extra assemblies.
        //
        public void Register()
        {
            AttributeTableBuilder builder = new AttributeTableBuilder();

            //shared component
            builder.AddCustomAttributes(typeof(Collection <Constraint>), new BrowsableAttribute(false));
            builder.AddCustomAttributes(typeof(string), new EditorReuseAttribute(false));
            builder.AddCustomAttributes(typeof(ActivityAction), new EditorReuseAttribute(false));
            builder.AddCustomAttributes(typeof(XName), new EditorReuseAttribute(false));

            //Flowchart activities
            FlowchartDesigner.RegisterMetadata(builder);
            FlowSwitchDesigner.RegisterMetadata(builder);
            FlowDecisionDesigner.RegisterMetadata(builder);

            // Messaging activities
            ServiceDesigner.RegisterMetadata(builder);

            // Registering inline for designers for InitializeCorrelation, Send, Receive, SendReply, ReceiveReply activities to avoid calling
            // their static constructors. This will avoid instantiating the ResourceDictionary for their PropertyValueEditors during designer load.
            builder.AddCustomAttributes(typeof(Send), new DesignerAttribute(typeof(SendDesigner)));
            builder.AddCustomAttributes(typeof(Send), new ActivityDesignerOptionsAttribute {
                AllowDrillIn = false
            });

            builder.AddCustomAttributes(typeof(Receive), new DesignerAttribute(typeof(ReceiveDesigner)));
            builder.AddCustomAttributes(typeof(Receive), new ActivityDesignerOptionsAttribute {
                AllowDrillIn = false
            });

            builder.AddCustomAttributes(typeof(SendReply), new FeatureAttribute(typeof(SendReplyValidationFeature)));
            builder.AddCustomAttributes(typeof(SendReply), new DesignerAttribute(typeof(SendReplyDesigner)));
            builder.AddCustomAttributes(typeof(SendReply), new ActivityDesignerOptionsAttribute {
                AllowDrillIn = false
            });
            CutCopyPasteHelper.AddDisallowedTypeForCopy(typeof(SendReply));

            builder.AddCustomAttributes(typeof(ReceiveReply), new FeatureAttribute(typeof(ReceiveReplyValidationFeature)));
            builder.AddCustomAttributes(typeof(ReceiveReply), new DesignerAttribute(typeof(ReceiveReplyDesigner)));
            builder.AddCustomAttributes(typeof(ReceiveReply), new ActivityDesignerOptionsAttribute {
                AllowDrillIn = false
            });
            CutCopyPasteHelper.AddDisallowedTypeForCopy(typeof(ReceiveReply));

            builder.AddCustomAttributes(typeof(InitializeCorrelation), new DesignerAttribute(typeof(InitializeCorrelationDesigner)));
            builder.AddCustomAttributes(typeof(InitializeCorrelation), new ActivityDesignerOptionsAttribute {
                AllowDrillIn = false
            });

            TransactedReceiveScopeDesigner.RegisterMetadata(builder);
            CorrelationScopeDesigner.RegisterMetadata(builder);

            //Procedural activities
            AssignDesigner.RegisterMetadata(builder);
            IfElseDesigner.RegisterMetadata(builder);
            InvokeMethodDesigner.RegisterMetadata(builder);
            DoWhileDesigner.RegisterMetadata(builder);
            WhileDesigner.RegisterMetadata(builder);
            ForEachDesigner.RegisterMetadata(builder);
            TryCatchDesigner.RegisterMetadata(builder);
            CatchDesigner.RegisterMetadata(builder);
            ParallelDesigner.RegisterMetadata(builder);
            SequenceDesigner.RegisterMetadata(builder);
            SwitchDesigner.RegisterMetadata(builder);
            CaseDesigner.RegisterMetadata(builder);

            //Compensation/Transaction
            CancellationScopeDesigner.RegisterMetadata(builder);
            CompensableActivityDesigner.RegisterMetadata(builder);
            TransactionScopeDesigner.RegisterMetadata(builder);

            //Misc activities
            PickDesigner.RegisterMetadata(builder);
            PickBranchDesigner.RegisterMetadata(builder);
            WriteLineDesigner.RegisterMetadata(builder);
            NoPersistScopeDesigner.RegisterMetadata(builder);

            InvokeDelegateDesigner.RegisterMetadata(builder);

            // StateMachine
            StateMachineDesigner.RegisterMetadata(builder);
            StateDesigner.RegisterMetadata(builder);
            TransitionDesigner.RegisterMetadata(builder);

            builder.AddCustomAttributes(typeof(AddToCollection <>), new FeatureAttribute(typeof(UpdatableGenericArgumentsFeature)));
            builder.AddCustomAttributes(typeof(RemoveFromCollection <>), new FeatureAttribute(typeof(UpdatableGenericArgumentsFeature)));
            builder.AddCustomAttributes(typeof(ClearCollection <>), new FeatureAttribute(typeof(UpdatableGenericArgumentsFeature)));
            builder.AddCustomAttributes(typeof(ExistsInCollection <>), new FeatureAttribute(typeof(UpdatableGenericArgumentsFeature)));

            builder.AddCustomAttributes(typeof(AddToCollection <>), new DefaultTypeArgumentAttribute(typeof(int)));
            builder.AddCustomAttributes(typeof(RemoveFromCollection <>), new DefaultTypeArgumentAttribute(typeof(int)));
            builder.AddCustomAttributes(typeof(ClearCollection <>), new DefaultTypeArgumentAttribute(typeof(int)));
            builder.AddCustomAttributes(typeof(ExistsInCollection <>), new DefaultTypeArgumentAttribute(typeof(int)));

            MetadataStore.AddAttributeTable(builder.CreateTable());

            MorphHelper.AddPropertyValueMorphHelper(typeof(InArgument <>), MorphHelpers.ArgumentMorphHelper);
            MorphHelper.AddPropertyValueMorphHelper(typeof(OutArgument <>), MorphHelpers.ArgumentMorphHelper);
            MorphHelper.AddPropertyValueMorphHelper(typeof(InOutArgument <>), MorphHelpers.ArgumentMorphHelper);
            MorphHelper.AddPropertyValueMorphHelper(typeof(ActivityAction <>), MorphHelpers.ActivityActionMorphHelper);
            MorphHelper.AddPropertyValueMorphHelper(typeof(ActivityFunc <,>), MorphHelpers.ActivityFuncMorphHelper);

            // There is no need to keep an reference to this delayed worker since the AppDomain event handler will do it.
            RegisterMetadataDelayedWorker delayedWorker = new RegisterMetadataDelayedWorker();

            delayedWorker.RegisterMetadataDelayed("System.Workflow.Runtime", InteropDesigner.RegisterMetadata);
            delayedWorker.RegisterMetadataDelayed("System.ServiceModel", RegisterMetadataForMessagingActivitiesSearchMetadata);
            delayedWorker.RegisterMetadataDelayed("System.ServiceModel", RegisterMetadataForMessagingActivitiesPropertyEditors);
            delayedWorker.WorkNowIfApplicable();
        }
예제 #6
0
 // Methods
 /// <summary>
 /// checks if it is possible to build/research unit/upgrade, then gets an agent and orders it to complete the task.
 /// </summary>
 public override void OnFrame()
 {
     if (UnitType != 0) // make a unit
     {
         if (Controller.CanMakeUnit(UnitType) && FromAgent == null)
         {
             // set the from type and execute the task
             if (MorphHelper.MorpSteps.ContainsKey(UnitType))
             {
                 FromAgent = Controller.GetAvailableAgent(MorphHelper.GetPreMorphType(UnitType));
                 FromAgent.Order(Units.GetAbilityId(UnitType)); // acts as execute()
                 Clear();                                       // only dismissed as it is morph type and eggs are useless and don't need to be busy
             }
             else if (TrainHelper.TrainSteps.ContainsKey(UnitType))
             {
                 FromAgent      = Controller.GetAvailableAgent(TrainHelper.GetTrainingBuildingTypes(UnitType));
                 FromAgent.Busy = true;
                 FromAgent.Order(Units.GetAbilityId(UnitType)); // acts as execute()
             }
             else
             {
                 FromAgent      = Controller.GetAvailableAgent(Units.Workers);
                 FromAgent.Busy = true;
                 Controller.BuildStructure(FromAgent, UnitType); // acts as Execute()
             }
         }
         else if (FromAgent != null)
         {
             if (FromAgent.Unit.Orders.Count == 0)
             {
                 // agent is idle. clear it
                 Clear();
             }
         }
         else
         {
             Clear();
         }
     }
     else
     {
         if (Controller.CanMakeUpgrade(UpgradeType) && FromAgent == null)
         {
             FromAgent      = Controller.GetAvailableAgent(UpgradeHelper.GetUpgradeBuildingTypes(UpgradeType));
             FromAgent.Busy = true;
             FromAgent.Order(Upgrades.GetAbilityId(UpgradeType));
         }
         else if (FromAgent != null)
         {
             if (FromAgent.Unit.Orders.Count == 0)
             {
                 FromAgent.Busy = false;
                 Clear();
             }
         }
         else
         {
             Clear();
         }
     }
 }