Ejemplo n.º 1
0
        public void DeactivateCodePackage(string activationContextId)
        {
            this.ThrowIfDisposed();

            AppTrace.TraceSource.WriteInfo("FabricEntryPoint.DeactivateCodePackage", "ActivationContextId: {0}", activationContextId);
            Debug.Assert(!string.IsNullOrEmpty(activationContextId), "activationContextId cannot be null or empty");

            if (!this.activeCodePackages.ContainsKey(activationContextId))
            {
                AppTrace.TraceSource.WriteError("FabricEntryPoint.DeactivateCodePackage", "Cannot deactivate code package that was not activated: {0}", activationContextId);
                throw new InvalidOperationException(StringResources.Error_FabricHostEntryPoint_Package_Not_Activated);
            }

            ActivatedCodePackage activatedCodePackage = this.activeCodePackages[activationContextId];

            try
            {
                activatedCodePackage.EntryPoints.ForEach(ep => ep.InvokeDeactivate());
            }
            finally
            {
                this.activeCodePackages.Remove(activationContextId);
                activatedCodePackage.Dispose();
            }
        }
Ejemplo n.º 2
0
        // internal for test hook
        internal void ActivateCodePackageInternal(
            string activationContextId,
            string codePackageName,
            CodePackageActivationContext activationContext,
            NativeRuntime.IFabricRuntime fabricRuntimePointer)
        {
            this.ThrowIfDisposed();

            CodePackage codePackage;

            try
            {
                codePackage = activationContext.GetCodePackageObject(codePackageName);
            }
            catch (KeyNotFoundException)
            {
                AppTrace.TraceSource.WriteError("FabricHostEntryPoint.ActivateCodePackageInternal", "The code package {0} to activate was not found", codePackageName);
                throw new ArgumentException(StringResources.Error_CodePackageNotFound);
            }

            DllHostEntryPointDescription description = codePackage.Description.EntryPoint as DllHostEntryPointDescription;

            if (description == null)
            {
                AppTrace.TraceSource.WriteError("FabricHostEntryPoint.ActivateCodePackageInternal", "Code package {0} does not have a FabricHostEntryPoint", codePackageName);
                throw new ArgumentException(StringResources.Error_FabricHostEntryPoint_No_EntryPoint_Found);
            }

            AppTrace.TraceSource.WriteNoise("FabricHostEntryPoint.ActivateCodePackageInternal", "Adding assembly resolver path: {0}", codePackage.Path);
            this.assemblyResolver.AddApplicationBinariesPath(codePackage.Path);

            var workerEntryPoints = description.HostedDlls
                                    .Where(i => i.Kind == DllHostHostedDllKind.Managed)
                                    .Select(FabricWorkerEntryPoint.CreateFromAssemblyDescription)
                                    .ToArray();

            var fabricRuntime = new FabricRuntime(fabricRuntimePointer, activationContext);
            ActivatedCodePackage activatedCodePackage = new ActivatedCodePackage(fabricRuntime, workerEntryPoints);

            bool activateSucceeded = false;

            try
            {
                workerEntryPoints.ForEach(wep => wep.InvokeActivate(fabricRuntime, activationContext));

                this.activeCodePackages[activationContextId] = activatedCodePackage;
                activateSucceeded = true;
            }
            finally
            {
                if (!activateSucceeded)
                {
                    activatedCodePackage.Dispose();
                }
            }
        }