/// <summary> /// Inserts activities in specified composite activity designer by creating transaction /// </summary> /// <param name="compositeActivityDesigner">Designer in which to insert the activities</param> /// <param name="insertLocation">Insertion location</param> /// <param name="activitiesToInsert">Array of activities to insert</param> /// <param name="undoTransactionDescription">Text for the designer transaction which will be created</param> public static void InsertActivities(CompositeActivityDesigner compositeActivityDesigner, HitTestInfo insertLocation, ReadOnlyCollection<Activity> activitiesToInsert, string undoTransactionDescription) { if (compositeActivityDesigner == null) throw new ArgumentNullException("compositeActivityDesigner"); if (compositeActivityDesigner.Activity == null || compositeActivityDesigner.Activity.Site == null || !(compositeActivityDesigner.Activity is CompositeActivity)) throw new ArgumentException("compositeActivityDesigner"); if (insertLocation == null) throw new ArgumentNullException("insertLocation"); if (activitiesToInsert == null) throw new ArgumentNullException("activitiesToInsert"); ISite site = compositeActivityDesigner.Activity.Site; // now insert the actual activities IDesignerHost designerHost = site.GetService(typeof(IDesignerHost)) as IDesignerHost; DesignerTransaction trans = null; if (designerHost != null && !string.IsNullOrEmpty(undoTransactionDescription)) trans = designerHost.CreateTransaction(undoTransactionDescription); bool moveCase = false; try { //Detect if the activities are being moved or inserted foreach (Activity activity in activitiesToInsert) { if (activity == null) throw new ArgumentException("activitiesToInsert", SR.GetString(SR.Error_CollectionHasNullEntry)); moveCase = ((IComponent)activity).Site != null; break; } //We purposely create a new instance of activities list so that we do not modify the original one if (moveCase) compositeActivityDesigner.MoveActivities(insertLocation, activitiesToInsert); else compositeActivityDesigner.InsertActivities(insertLocation, activitiesToInsert); if (trans != null) trans.Commit(); } catch (Exception e) { if (trans != null) trans.Cancel(); throw e; } //If we are just moving the activities then we do not need to emit the class //for scopes; only when we are adding the activities the class needs to be emitted for //scope in code beside file if (!moveCase) { // if everything was successful then generate classes correposnding to new scopes // get all the activities underneath the child activities ArrayList allActivities = new ArrayList(); foreach (Activity activity in activitiesToInsert) { allActivities.Add(activity); if (activity is CompositeActivity) allActivities.AddRange(Helpers.GetNestedActivities((CompositeActivity)activity)); } } }
public static void InsertActivities(CompositeActivityDesigner compositeActivityDesigner, System.Workflow.ComponentModel.Design.HitTestInfo insertLocation, ReadOnlyCollection<Activity> activitiesToInsert, string undoTransactionDescription) { if (compositeActivityDesigner == null) { throw new ArgumentNullException("compositeActivityDesigner"); } if (((compositeActivityDesigner.Activity == null) || (compositeActivityDesigner.Activity.Site == null)) || !(compositeActivityDesigner.Activity is CompositeActivity)) { throw new ArgumentException("compositeActivityDesigner"); } if (insertLocation == null) { throw new ArgumentNullException("insertLocation"); } if (activitiesToInsert == null) { throw new ArgumentNullException("activitiesToInsert"); } IDesignerHost service = compositeActivityDesigner.Activity.Site.GetService(typeof(IDesignerHost)) as IDesignerHost; DesignerTransaction transaction = null; if ((service != null) && !string.IsNullOrEmpty(undoTransactionDescription)) { transaction = service.CreateTransaction(undoTransactionDescription); } bool flag = false; try { foreach (Activity activity in activitiesToInsert) { if (activity == null) { throw new ArgumentException("activitiesToInsert", SR.GetString("Error_CollectionHasNullEntry")); } flag = activity.Site != null; break; } if (flag) { compositeActivityDesigner.MoveActivities(insertLocation, activitiesToInsert); } else { compositeActivityDesigner.InsertActivities(insertLocation, activitiesToInsert); } if (transaction != null) { transaction.Commit(); } } catch (Exception exception) { if (transaction != null) { transaction.Cancel(); } throw exception; } if (!flag) { ArrayList list = new ArrayList(); foreach (Activity activity2 in activitiesToInsert) { list.Add(activity2); if (activity2 is CompositeActivity) { list.AddRange(Helpers.GetNestedActivities((CompositeActivity) activity2)); } } } }