public void AddOperation(ServiceOperationListItem operation)
        {
            if (operation == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("operation");
            }
            // Dont add operation if operation.Name is broken
            if (String.IsNullOrEmpty(operation.Name))
            {
                return;
            }
            ServiceOperationListItem cachedItem = this.operations.Find(operation.Name);

            if (cachedItem != null)
            {
                foreach (Activity activity in operation.ImplementingActivities)
                {
                    if (!cachedItem.ImplementingActivities.Contains(activity))
                    {
                        cachedItem.ImplementingActivities.Add(activity);
                    }
                }
            }
            else
            {
                this.operations.Add(operation);
                int positionToAddAt = this.container.Items.IndexOf(this) + 1;
                if (this.operations.Count > 1)
                {
                    positionToAddAt = this.container.Items.IndexOf(lastItemAdded) + 1;
                }
                lastItemAdded = operation;
                this.container.Items.Insert(positionToAddAt, operation);
            }
        }
        private void SelectServiceOperation(OperationInfoBase operationInfo)
        {
            Fx.Assert(operationInfo != null, "operationInfo cannot be null");
            ServiceContractListItem serviceContract = this.serviceContracts.Find(operationInfo.GetContractFullName(null));

            // Dont select operation if the contract cannot be found in the serviceContracts list
            if (serviceContract == null)
            {
                return;
            }
            ServiceOperationListItem operationItem = null;

            if (operationInfo is OperationInfo)
            {
                operationItem             = new WorkflowServiceOperationListItem();
                operationItem.Validating += new CancelEventHandler(ServiceOperationValidating);

                operationItem.Name = operationInfo.Name;
                ((WorkflowServiceOperationListItem)operationItem).Operation = operationInfo as OperationInfo;
            }
            else if (operationInfo is TypedOperationInfo)
            {
                operationItem             = new TypedServiceOperationListItem();
                operationItem.Validating += new CancelEventHandler(ServiceOperationValidating);
                operationItem.Name        = operationInfo.Name;
                ((TypedServiceOperationListItem)operationItem).Operation = operationInfo as TypedOperationInfo;
            }

            serviceContract.SelectionOperation(operationItem);
        }
        private void UpdateImplementingActivities()
        {
            ServiceOperationListItem         operationListItem          = this.Item as ServiceOperationListItem;
            WorkflowServiceOperationListItem workflowOperationListItem  = this.Item as WorkflowServiceOperationListItem;
            TypedServiceOperationListItem    reflectedOperationListItem = this.Item as TypedServiceOperationListItem;
            OperationInfoBase operation = null;

            if (workflowOperationListItem != null)
            {
                operation = workflowOperationListItem.Operation;
            }
            else if (reflectedOperationListItem != null)
            {
                operation = reflectedOperationListItem.Operation;
            }
            Fx.Assert(operation != null, "operation should not be null at this point");
            // workflow operations list item will complain if some operationInfo objects have different signature than others
            // for the same operation name. This will happen when we are updating the activities, since they already have  a operation
            // object for that operation name, but with a different signature. so make them all point to null first ,then update.
            if (workflowOperationListItem != null)
            {
                foreach (Activity activity in operationListItem.ImplementingActivities)
                {
                    PropertyDescriptorUtils.SetPropertyValue(this.ServiceProvider, ServiceOperationHelpers.GetServiceOperationInfoPropertyDescriptor(activity), activity, null);
                }
            }
            foreach (Activity activity in operationListItem.ImplementingActivities)
            {
                PropertyDescriptorUtils.SetPropertyValue(this.ServiceProvider, ServiceOperationHelpers.GetServiceOperationInfoPropertyDescriptor(activity), activity, operation.Clone());
            }
        }
 public void AddOperation(ServiceOperationListItem operation)
 {
     if (operation == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("operation");
     }
     // Dont add operation if operation.Name is broken
     if (String.IsNullOrEmpty(operation.Name))
     {
         return;
     }
     ServiceOperationListItem cachedItem = this.operations.Find(operation.Name);
     if (cachedItem != null)
     {
         foreach (Activity activity in operation.ImplementingActivities)
         {
             if (!cachedItem.ImplementingActivities.Contains(activity))
             {
                 cachedItem.ImplementingActivities.Add(activity);
             }
         }
     }
     else
     {
         this.operations.Add(operation);
         int positionToAddAt = this.container.Items.IndexOf(this) + 1;
         if (this.operations.Count > 1)
         {
             positionToAddAt = this.container.Items.IndexOf(lastItemAdded) + 1;
         }
         lastItemAdded = operation;
         this.container.Items.Insert(positionToAddAt, operation);
     }
 }
        private void AddServiceOperation(ServiceOperationListItem serviceOperation)
        {
            if (serviceOperation == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("serviceOperation");
            }
            String key = serviceOperation.ContractName;
            ServiceContractListItem serviceContract = this.serviceContracts.Find(key);

            serviceContract.AddOperation(serviceOperation);
            serviceContract.SelectionOperation(serviceOperation);
        }
        void operationNameTextBox_Validating(object sender, CancelEventArgs e)
        {
            ServiceOperationListItem operationListItem = (ServiceOperationListItem)this.Item;
            string oldName = operationListItem.Name;

            operationListItem.Name = this.operationNameTextBox.Text;
            if (operationListItem.Validating != null)
            {
                operationListItem.Validating.Invoke(operationListItem, e);
            }
            if (e.Cancel)
            {
                this.operationNameTextBox.Text = oldName;
                operationListItem.Name         = oldName;
                e.Cancel = false;
            }
        }
        public void SelectionOperation(ServiceOperationListItem operation)
        {
            if (operation == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("operation");
            }
            // Dont select if operation.Name is broken
            if (String.IsNullOrEmpty(operation.Name))
            {
                return;
            }
            ServiceOperationListItem operationListItem = this.operations.Find(operation.Name);

            if (operationListItem != null)
            {
                this.container.SetSelected(container.Items.IndexOf(operationListItem), true);
            }
        }
        void ServiceOperationValidating(object sender, CancelEventArgs e)
        {
            ServiceOperationListItem serviceOperationListItem = (ServiceOperationListItem)sender;
            string newOperationName = serviceOperationListItem.Name;
            string contractName     = serviceOperationListItem.ContractName;

            if (string.IsNullOrEmpty(newOperationName))
            {
                e.Cancel = true;
                string errorString = SR2.GetString(SR2.OperationNameCannotBeEmpty);
                DesignerHelpers.ShowMessage(this.serviceProvider, errorString, System.Workflow.ComponentModel.Design.DR.GetString(System.Workflow.ComponentModel.Design.DR.WorkflowDesignerTitle), MessageBoxButtons.OK,
                                            MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
            }

            Fx.Assert(!string.IsNullOrEmpty(contractName), "contract name should be valid to run this check");
            ServiceContractListItem contractListItem = serviceContracts.Find(contractName);

            Fx.Assert(contractListItem != null, "contract should be present in the list to run this check");

            // operation names must be unique inside a contract
            bool duplicatesFound = false;

            foreach (ServiceOperationListItem foundOperation in contractListItem.Operations)
            {
                if (foundOperation == serviceOperationListItem)
                {
                    continue;
                }
                if (foundOperation.Name.Equals(newOperationName))
                {
                    duplicatesFound = true;
                    break;
                }
            }
            if (duplicatesFound)
            {
                e.Cancel = true;
                string errorString = SR2.GetString(SR2.OperationNameMustBeUnique);
                DesignerHelpers.ShowMessage(this.serviceProvider, errorString, System.Workflow.ComponentModel.Design.DR.GetString(System.Workflow.ComponentModel.Design.DR.WorkflowDesignerTitle), MessageBoxButtons.OK,
                                            MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
            }
        }
 private void AddServiceOperation(ServiceOperationListItem serviceOperation)
 {
     if (serviceOperation == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("serviceOperation");
     }
     String key = serviceOperation.ContractName;
     ServiceContractListItem serviceContract = this.serviceContracts.Find(key);
     serviceContract.AddOperation(serviceOperation);
     serviceContract.SelectionOperation(serviceOperation);
 }
 public void SelectionOperation(ServiceOperationListItem operation)
 {
     if (operation == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("operation");
     }
     // Dont select if operation.Name is broken
     if (String.IsNullOrEmpty(operation.Name))
     {
         return;
     }
     ServiceOperationListItem operationListItem = this.operations.Find(operation.Name);
     if (operationListItem != null)
     {
         this.container.SetSelected(container.Items.IndexOf(operationListItem), true);
     }
 }