internal DebugController(WorkflowRuntime serviceContainer, string hostName)
 {
     if (serviceContainer == null)
     {
         throw new ArgumentNullException("serviceContainer");
     }
     try
     {
         this.programPublisher = new ProgramPublisher();
     }
     catch
     {
         return;
     }
     this.serviceContainer  = serviceContainer;
     this.programId         = Guid.Empty;
     this.controllerConduit = null;
     this.channel           = null;
     this.isZombie          = false;
     this.hostName          = hostName;
     AppDomain.CurrentDomain.ProcessExit  += new EventHandler(this.OnDomainUnload);
     AppDomain.CurrentDomain.DomainUnload += new EventHandler(this.OnDomainUnload);
     this.serviceContainer.Started        += new EventHandler <WorkflowRuntimeEventArgs>(this.Start);
     this.serviceContainer.Stopped        += new EventHandler <WorkflowRuntimeEventArgs>(this.Stop);
 }
 internal DebugController(WorkflowRuntime serviceContainer, string hostName)
 {
     if (serviceContainer == null)
     {
         throw new ArgumentNullException("serviceContainer");
     }
     try
     {
         this.programPublisher = new ProgramPublisher();
     }
     catch
     {
         return;
     }
     this.serviceContainer = serviceContainer;
     this.programId = Guid.Empty;
     this.controllerConduit = null;
     this.channel = null;
     this.isZombie = false;
     this.hostName = hostName;
     AppDomain.CurrentDomain.ProcessExit += new EventHandler(this.OnDomainUnload);
     AppDomain.CurrentDomain.DomainUnload += new EventHandler(this.OnDomainUnload);
     this.serviceContainer.Started += new EventHandler<WorkflowRuntimeEventArgs>(this.Start);
     this.serviceContainer.Stopped += new EventHandler<WorkflowRuntimeEventArgs>(this.Stop);
 }
 private void Detach()
 {
     using (new DebuggerThreadMarker())
     {
         lock (this.syncRoot)
         {
             AppDomain.CurrentDomain.AssemblyLoad -= new AssemblyLoadEventHandler(this.OnAssemblyLoad);
             if (!this.isZombie && this.isAttached)
             {
                 this.isAttached = false;
                 this.programId  = Guid.Empty;
                 if (this.debugControllerThread != null)
                 {
                     this.debugControllerThread.StopThread();
                     this.debugControllerThread = null;
                 }
                 if (this.attachTimer != null)
                 {
                     this.attachTimer.Change(-1, -1);
                     this.attachTimer = null;
                 }
                 RemotingServices.Disconnect(this);
                 if (this.channel != null)
                 {
                     ChannelServices.UnregisterChannel(this.channel);
                     this.channel = null;
                 }
                 this.controllerConduit = null;
                 this.eventConduitAttached.Reset();
                 this.instanceTable  = null;
                 this.typeToGuid     = null;
                 this.xomlHashToGuid = null;
                 if (!this.serviceContainer.IsZombie)
                 {
                     foreach (WorkflowInstance instance in this.serviceContainer.GetLoadedWorkflows())
                     {
                         WorkflowExecutor workflowResourceUNSAFE = instance.GetWorkflowResourceUNSAFE();
                         using (workflowResourceUNSAFE.ExecutorLock.Enter())
                         {
                             if (workflowResourceUNSAFE.IsInstanceValid)
                             {
                                 workflowResourceUNSAFE.WorkflowExecutionEvent -= new EventHandler <WorkflowExecutor.WorkflowExecutionEventArgs>(this.OnInstanceEvent);
                             }
                         }
                     }
                     this.serviceContainer.WorkflowExecutorInitializing -= new EventHandler <WorkflowRuntime.WorkflowExecutorInitializingEventArgs>(this.InstanceInitializing);
                     this.serviceContainer.DefinitionDispenser.WorkflowDefinitionLoaded -= new EventHandler <WorkflowDefinitionEventArgs>(this.ScheduleTypeLoaded);
                 }
             }
         }
     }
 }
Ejemplo n.º 4
0
        public void AttachToConduit(Uri url)
        {
            if (url == null)
                throw new ArgumentNullException("url");

            try
            {
                using (new DebuggerThreadMarker())
                {
                    try
                    {
                        RegistryKey debugEngineSubKey = Registry.LocalMachine.OpenSubKey(RegistryKeys.DebuggerSubKey);
                        if (debugEngineSubKey != null)
                        {
                            string controllerConduitTypeName = debugEngineSubKey.GetValue(ControllerConduitTypeName, String.Empty) as string;
                            if (!String.IsNullOrEmpty(controllerConduitTypeName) && Type.GetType(controllerConduitTypeName) != null)
                                this.controllerConduit = Activator.GetObject(Type.GetType(controllerConduitTypeName), url.AbsolutePath) as IWorkflowDebugger;
                        }
                    }
                    catch { }

                    if (this.controllerConduit == null)
                    {
                        const string controllerConduitTypeFormat = "Microsoft.Workflow.DebugEngine.ControllerConduit, Microsoft.Workflow.DebugController, Version={0}.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

                        // Try versions 12.0.0.0, 11.0.0.0, 10.0.0.0
                        Type controllerConduitType = null;
                        for (int version = 12; controllerConduitType == null && version >= 10; --version)
                        {
                            try
                            {
                                controllerConduitType = Type.GetType(string.Format(CultureInfo.InvariantCulture, controllerConduitTypeFormat, version));
                            }
                            catch (TypeLoadException)
                            {
                                // Fall back to next-lower version
                            }
                        }

                        if (controllerConduitType != null)
                        {
                            this.controllerConduit = Activator.GetObject(controllerConduitType, url.AbsolutePath) as IWorkflowDebugger;
                        }
                    }
                    Debug.Assert(this.controllerConduit != null, "Failed to create Controller Conduit");
                    if (this.controllerConduit == null)
                        return;

                    this.eventLock = new object();

                    // Race Condition:
                    // We hook up to the AssemblyLoad event, the Schedule events and Instance events handler 
                    // before we iterate over all loaded assemblies. This means that we need to deal with duplicates in the 
                    // debugee.

                    // Race Condition:
                    // Further the order in which we hook up handlers/iterate is important to avoid ----s if the events fire
                    // before the iterations complete. We need to hook and iterate over the assemblies, then the schedule 
                    // types and finally the instances. This guarantees that we always have all the assemblies when we load
                    // schedules types and we always have all the schedule types when we load instances.

                    AppDomain.CurrentDomain.AssemblyLoad += OnAssemblyLoad;
                    foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
                    {
                        if (!assembly.IsDynamic
                            && !(assembly is System.Reflection.Emit.AssemblyBuilder)
                            && !(string.IsNullOrEmpty(assembly.Location)))
                        {
                            this.controllerConduit.AssemblyLoaded(this.programId, assembly.Location, assembly.GlobalAssemblyCache);
                        }
                    }
                    this.serviceContainer.DefinitionDispenser.WorkflowDefinitionLoaded += ScheduleTypeLoaded;

                    // In here we load all schedule types defined as they are - with no dynamic updates
                    ReadOnlyCollection<Type> types;
                    ReadOnlyCollection<Activity> values;
                    this.serviceContainer.DefinitionDispenser.GetWorkflowTypes(out types, out values);
                    for (int i = 0; i < types.Count; i++)
                    {
                        Type scheduleType = types[i];
                        Activity rootActivity = values[i];
                        LoadExistingScheduleType(GetScheduleTypeId(scheduleType), scheduleType, false, rootActivity);
                    }

                    ReadOnlyCollection<byte[]> keys;
                    this.serviceContainer.DefinitionDispenser.GetWorkflowDefinitions(out keys, out values);
                    for (int i = 0; i < keys.Count; i++)
                    {
                        byte[] scheduleDefHash = keys[i];
                        Activity rootActivity = values[i];
                        Activity workflowDefinition = (Activity)rootActivity.GetValue(Activity.WorkflowDefinitionProperty);
                        ArrayList changeActions = null;
                        if (workflowDefinition != null)
                            changeActions = (ArrayList)workflowDefinition.GetValue(WorkflowChanges.WorkflowChangeActionsProperty);
                        LoadExistingScheduleType(GetScheduleTypeId(scheduleDefHash), rootActivity.GetType(), (changeActions != null && changeActions.Count != 0), rootActivity);
                    }

                    this.serviceContainer.WorkflowExecutorInitializing += InstanceInitializing;

                    foreach (WorkflowInstance instance in this.serviceContainer.GetLoadedWorkflows())
                    {
                        WorkflowExecutor executor = instance.GetWorkflowResourceUNSAFE();
                        using (executor.ExecutorLock.Enter())
                        {
                            LoadExistingInstance(instance, true);
                        }
                    }

                    this.eventConduitAttached.Set();
                }
            }
            catch (Exception e)
            {
                // Don't throw exceptions to the Runtime. Ignore exceptions that may occur if the debugger detaches 
                // and closes the remoting channel.
                Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "WDE: Failure in DebugController.AttachToConduit: {0}, Call stack:{1}", e.Message, e.StackTrace));
            }

        }
Ejemplo n.º 5
0
        private void Detach()
        {
            Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "WDE: DebugController.Detach():"));

            using (new DebuggerThreadMarker())
            {
                lock (this.syncRoot)
                {

                    AppDomain.CurrentDomain.AssemblyLoad -= OnAssemblyLoad;

                    // See comments in Attach().
                    if (this.isZombie || !this.isAttached)
                        return;

                    this.isAttached = false;

                    // Undone: AkashS - At this point wait for all event handling to complete to avoid exceptions.

                    this.programId = Guid.Empty;

                    if (this.debugControllerThread != null)
                    {
                        this.debugControllerThread.StopThread();
                        this.debugControllerThread = null;
                    }

                    if (this.attachTimer != null)
                    {
                        this.attachTimer.Change(Timeout.Infinite, Timeout.Infinite);
                        this.attachTimer = null;
                    }

                    RemotingServices.Disconnect(this);
                    if (this.channel != null)
                    {
                        ChannelServices.UnregisterChannel(this.channel);
                        this.channel = null;
                    }

                    this.controllerConduit = null;

                    this.eventConduitAttached.Reset();
                    this.instanceTable = null;
                    this.typeToGuid = null;
                    this.xomlHashToGuid = null;

                    // Do this only after we perform the previous cleanup! Otherwise
                    // we may get exceptions from the runtime that may cause the cleanup
                    // to not happen.

                    if (!this.serviceContainer.IsZombie)
                    {
                        foreach (WorkflowInstance instance in this.serviceContainer.GetLoadedWorkflows())
                        {
                            WorkflowExecutor executor = instance.GetWorkflowResourceUNSAFE();
                            using (executor.ExecutorLock.Enter())
                            {
                                if (executor.IsInstanceValid)
                                    executor.WorkflowExecutionEvent -= OnInstanceEvent;
                            }
                        }

                        this.serviceContainer.WorkflowExecutorInitializing -= InstanceInitializing;
                        this.serviceContainer.DefinitionDispenser.WorkflowDefinitionLoaded -= ScheduleTypeLoaded;
                    }
                }
            }
        }
Ejemplo n.º 6
0
        internal DebugController(WorkflowRuntime serviceContainer, string hostName)
        {
            if (serviceContainer == null)
                throw new ArgumentNullException("serviceContainer");

            try
            {
                this.programPublisher = new ProgramPublisher();
            }
            catch
            {
                // If we are unable to create the ProgramPublisher, this means that VS does not exist on this machine, so we can't debug.
                return;
            }

            this.serviceContainer = serviceContainer;
            this.programId = Guid.Empty;
            this.controllerConduit = null;
            this.channel = null;
            this.isZombie = false;
            this.hostName = hostName;

            AppDomain.CurrentDomain.ProcessExit += OnDomainUnload;
            AppDomain.CurrentDomain.DomainUnload += OnDomainUnload;

            this.serviceContainer.Started += this.Start;
            this.serviceContainer.Stopped += this.Stop;
        }
 public void AttachToConduit(Uri url)
 {
     if (url == null)
     {
         throw new ArgumentNullException("url");
     }
     try
     {
         using (new DebuggerThreadMarker())
         {
             try
             {
                 RegistryKey key = Registry.LocalMachine.OpenSubKey(RegistryKeys.DebuggerSubKey);
                 if (key != null)
                 {
                     string str = key.GetValue(ControllerConduitTypeName, string.Empty) as string;
                     if (!string.IsNullOrEmpty(str) && (Type.GetType(str) != null))
                     {
                         this.controllerConduit = Activator.GetObject(Type.GetType(str), url.AbsolutePath) as IWorkflowDebugger;
                     }
                 }
             }
             catch
             {
             }
             finally
             {
                 if (this.controllerConduit == null)
                 {
                     this.controllerConduit = Activator.GetObject(Type.GetType("Microsoft.Workflow.DebugEngine.ControllerConduit, Microsoft.Workflow.DebugController, Version=10.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"), url.AbsolutePath) as IWorkflowDebugger;
                 }
             }
             if (this.controllerConduit != null)
             {
                 ReadOnlyCollection <Type>     onlys;
                 ReadOnlyCollection <Activity> onlys2;
                 ReadOnlyCollection <byte[]>   onlys3;
                 this.eventLock = new object();
                 AppDomain.CurrentDomain.AssemblyLoad += new AssemblyLoadEventHandler(this.OnAssemblyLoad);
                 foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
                 {
                     if ((!assembly.IsDynamic && !(assembly is AssemblyBuilder)) && !string.IsNullOrEmpty(assembly.Location))
                     {
                         this.controllerConduit.AssemblyLoaded(this.programId, assembly.Location, assembly.GlobalAssemblyCache);
                     }
                 }
                 this.serviceContainer.DefinitionDispenser.WorkflowDefinitionLoaded += new EventHandler <WorkflowDefinitionEventArgs>(this.ScheduleTypeLoaded);
                 this.serviceContainer.DefinitionDispenser.GetWorkflowTypes(out onlys, out onlys2);
                 for (int i = 0; i < onlys.Count; i++)
                 {
                     Type     scheduleType = onlys[i];
                     Activity rootActivity = onlys2[i];
                     this.LoadExistingScheduleType(this.GetScheduleTypeId(scheduleType), scheduleType, false, rootActivity);
                 }
                 this.serviceContainer.DefinitionDispenser.GetWorkflowDefinitions(out onlys3, out onlys2);
                 for (int j = 0; j < onlys3.Count; j++)
                 {
                     byte[]    scheduleDefHashCode = onlys3[j];
                     Activity  activity2           = onlys2[j];
                     Activity  activity3           = (Activity)activity2.GetValue(Activity.WorkflowDefinitionProperty);
                     ArrayList list = null;
                     if (activity3 != null)
                     {
                         list = (ArrayList)activity3.GetValue(WorkflowChanges.WorkflowChangeActionsProperty);
                     }
                     this.LoadExistingScheduleType(this.GetScheduleTypeId(scheduleDefHashCode), activity2.GetType(), (list != null) && (list.Count != 0), activity2);
                 }
                 this.serviceContainer.WorkflowExecutorInitializing += new EventHandler <WorkflowRuntime.WorkflowExecutorInitializingEventArgs>(this.InstanceInitializing);
                 foreach (WorkflowInstance instance in this.serviceContainer.GetLoadedWorkflows())
                 {
                     using (instance.GetWorkflowResourceUNSAFE().ExecutorLock.Enter())
                     {
                         this.LoadExistingInstance(instance, true);
                     }
                 }
                 this.eventConduitAttached.Set();
             }
         }
     }
     catch (Exception)
     {
     }
 }
 private void Detach()
 {
     using (new DebuggerThreadMarker())
     {
         lock (this.syncRoot)
         {
             AppDomain.CurrentDomain.AssemblyLoad -= new AssemblyLoadEventHandler(this.OnAssemblyLoad);
             if (!this.isZombie && this.isAttached)
             {
                 this.isAttached = false;
                 this.programId = Guid.Empty;
                 if (this.debugControllerThread != null)
                 {
                     this.debugControllerThread.StopThread();
                     this.debugControllerThread = null;
                 }
                 if (this.attachTimer != null)
                 {
                     this.attachTimer.Change(-1, -1);
                     this.attachTimer = null;
                 }
                 RemotingServices.Disconnect(this);
                 if (this.channel != null)
                 {
                     ChannelServices.UnregisterChannel(this.channel);
                     this.channel = null;
                 }
                 this.controllerConduit = null;
                 this.eventConduitAttached.Reset();
                 this.instanceTable = null;
                 this.typeToGuid = null;
                 this.xomlHashToGuid = null;
                 if (!this.serviceContainer.IsZombie)
                 {
                     foreach (WorkflowInstance instance in this.serviceContainer.GetLoadedWorkflows())
                     {
                         WorkflowExecutor workflowResourceUNSAFE = instance.GetWorkflowResourceUNSAFE();
                         using (workflowResourceUNSAFE.ExecutorLock.Enter())
                         {
                             if (workflowResourceUNSAFE.IsInstanceValid)
                             {
                                 workflowResourceUNSAFE.WorkflowExecutionEvent -= new EventHandler<WorkflowExecutor.WorkflowExecutionEventArgs>(this.OnInstanceEvent);
                             }
                         }
                     }
                     this.serviceContainer.WorkflowExecutorInitializing -= new EventHandler<WorkflowRuntime.WorkflowExecutorInitializingEventArgs>(this.InstanceInitializing);
                     this.serviceContainer.DefinitionDispenser.WorkflowDefinitionLoaded -= new EventHandler<WorkflowDefinitionEventArgs>(this.ScheduleTypeLoaded);
                 }
             }
         }
     }
 }
 public void AttachToConduit(Uri url)
 {
     if (url == null)
     {
         throw new ArgumentNullException("url");
     }
     try
     {
         using (new DebuggerThreadMarker())
         {
             try
             {
                 RegistryKey key = Registry.LocalMachine.OpenSubKey(RegistryKeys.DebuggerSubKey);
                 if (key != null)
                 {
                     string str = key.GetValue(ControllerConduitTypeName, string.Empty) as string;
                     if (!string.IsNullOrEmpty(str) && (Type.GetType(str) != null))
                     {
                         this.controllerConduit = Activator.GetObject(Type.GetType(str), url.AbsolutePath) as IWorkflowDebugger;
                     }
                 }
             }
             catch
             {
             }
             finally
             {
                 if (this.controllerConduit == null)
                 {
                     this.controllerConduit = Activator.GetObject(Type.GetType("Microsoft.Workflow.DebugEngine.ControllerConduit, Microsoft.Workflow.DebugController, Version=10.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"), url.AbsolutePath) as IWorkflowDebugger;
                 }
             }
             if (this.controllerConduit != null)
             {
                 ReadOnlyCollection<Type> onlys;
                 ReadOnlyCollection<Activity> onlys2;
                 ReadOnlyCollection<byte[]> onlys3;
                 this.eventLock = new object();
                 AppDomain.CurrentDomain.AssemblyLoad += new AssemblyLoadEventHandler(this.OnAssemblyLoad);
                 foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
                 {
                     if ((!assembly.IsDynamic && !(assembly is AssemblyBuilder)) && !string.IsNullOrEmpty(assembly.Location))
                     {
                         this.controllerConduit.AssemblyLoaded(this.programId, assembly.Location, assembly.GlobalAssemblyCache);
                     }
                 }
                 this.serviceContainer.DefinitionDispenser.WorkflowDefinitionLoaded += new EventHandler<WorkflowDefinitionEventArgs>(this.ScheduleTypeLoaded);
                 this.serviceContainer.DefinitionDispenser.GetWorkflowTypes(out onlys, out onlys2);
                 for (int i = 0; i < onlys.Count; i++)
                 {
                     Type scheduleType = onlys[i];
                     Activity rootActivity = onlys2[i];
                     this.LoadExistingScheduleType(this.GetScheduleTypeId(scheduleType), scheduleType, false, rootActivity);
                 }
                 this.serviceContainer.DefinitionDispenser.GetWorkflowDefinitions(out onlys3, out onlys2);
                 for (int j = 0; j < onlys3.Count; j++)
                 {
                     byte[] scheduleDefHashCode = onlys3[j];
                     Activity activity2 = onlys2[j];
                     Activity activity3 = (Activity) activity2.GetValue(Activity.WorkflowDefinitionProperty);
                     ArrayList list = null;
                     if (activity3 != null)
                     {
                         list = (ArrayList) activity3.GetValue(WorkflowChanges.WorkflowChangeActionsProperty);
                     }
                     this.LoadExistingScheduleType(this.GetScheduleTypeId(scheduleDefHashCode), activity2.GetType(), (list != null) && (list.Count != 0), activity2);
                 }
                 this.serviceContainer.WorkflowExecutorInitializing += new EventHandler<WorkflowRuntime.WorkflowExecutorInitializingEventArgs>(this.InstanceInitializing);
                 foreach (WorkflowInstance instance in this.serviceContainer.GetLoadedWorkflows())
                 {
                     using (instance.GetWorkflowResourceUNSAFE().ExecutorLock.Enter())
                     {
                         this.LoadExistingInstance(instance, true);
                     }
                 }
                 this.eventConduitAttached.Set();
             }
         }
     }
     catch (Exception)
     {
     }
 }