Пример #1
0
        public static void DropLibrary(Program program, string libraryName, bool updateCatalogTimeStamp)
        {
            lock (program.Catalog.Libraries)
            {
                Schema.Library library = program.Catalog.Libraries[libraryName];
                if (program.CatalogDeviceSession.IsLoadedLibrary(library.Name))
                {
                    throw new Schema.SchemaException(Schema.SchemaException.Codes.CannotDropRegisteredLibrary, library.Name);
                }

                string libraryDirectory = library.GetLibraryDirectory(((Server.Server)program.ServerProcess.ServerSession.Server).LibraryDirectory);

                program.Catalog.Libraries.DoLibraryRemoved(program, library.Name);
                program.Catalog.Libraries.DoLibraryDeleted(program, library.Name);
                try
                {
                    program.Catalog.Libraries.Remove(library);
                    try
                    {
                        if (updateCatalogTimeStamp)
                        {
                            program.Catalog.UpdateTimeStamp();
                        }
                        if (Directory.Exists(libraryDirectory))
                        {
                                                        #if !RESPECTREADONLY
                            PathUtility.EnsureWriteable(libraryDirectory, true);
                                                        #endif
                            Directory.Delete(libraryDirectory, true);
                        }

                        ((ServerCatalogDeviceSession)program.CatalogDeviceSession).ClearLibraryOwner(libraryName);
                        ((ServerCatalogDeviceSession)program.CatalogDeviceSession).ClearCurrentLibraryVersion(libraryName);
                    }
                    catch
                    {
                        if (Directory.Exists(libraryDirectory))
                        {
                            program.Catalog.Libraries.Add(library);
                        }
                        throw;
                    }
                }
                catch
                {
                    if (Directory.Exists(libraryDirectory))
                    {
                        program.Catalog.Libraries.DoLibraryCreated(program, library.Name);
                        program.Catalog.Libraries.DoLibraryAdded(program, library.Name);
                    }
                    throw;
                }
            }
        }
Пример #2
0
        public static void AttachLibrary(Program program, Schema.Library library, bool isAttached)
        {
            lock (program.Catalog.Libraries)
            {
                string libraryDirectory = library.GetLibraryDirectory(((Server.Server)program.ServerProcess.ServerSession.Server).LibraryDirectory);

                program.Catalog.Libraries.Add(library);
                program.Catalog.UpdateTimeStamp();
                program.Catalog.Libraries.DoLibraryAdded(program, library.Name);
                if ((library.Directory != String.Empty) && !isAttached)
                {
                    ((ServerCatalogDeviceSession)program.CatalogDeviceSession).SetLibraryDirectory(library.Name, libraryDirectory);
                }
            }
        }
Пример #3
0
        public static void DetachLibrary(Program program, string libraryName)
        {
            lock (program.Catalog.Libraries)
            {
                Schema.Library library = program.Catalog.Libraries[libraryName];
                if (program.CatalogDeviceSession.IsLoadedLibrary(library.Name))
                {
                    throw new Schema.SchemaException(Schema.SchemaException.Codes.CannotDetachRegisteredLibrary, library.Name);
                }

                string libraryDirectory = library.GetLibraryDirectory(((Server.Server)program.ServerProcess.ServerSession.Server).LibraryDirectory);

                program.Catalog.Libraries.DoLibraryRemoved(program, library.Name);
                program.Catalog.Libraries.Remove(library);
                program.Catalog.UpdateTimeStamp();
                ((ServerCatalogDeviceSession)program.CatalogDeviceSession).DeleteLibraryDirectory(library.Name);
            }
        }
Пример #4
0
        public static void RegisterLibrary(Program program, string libraryName, bool withReconciliation)
        {
            int saveReconciliationState = program.ServerProcess.SuspendReconciliationState();

            try
            {
                if (!withReconciliation)
                {
                    program.ServerProcess.DisableReconciliation();
                }
                try
                {
                    lock (program.Catalog.Libraries)
                    {
                        Schema.Library library = program.Catalog.Libraries[libraryName];

                        Schema.LoadedLibrary loadedLibrary = program.CatalogDeviceSession.ResolveLoadedLibrary(library.Name, false);
                        if (loadedLibrary != null)
                        {
                            throw new Schema.SchemaException(Schema.SchemaException.Codes.LibraryAlreadyRegistered, libraryName);
                        }

                        loadedLibrary       = new Schema.LoadedLibrary(libraryName);
                        loadedLibrary.Owner = program.Plan.User;

                        //	Ensure that each required library is registered
                        foreach (Schema.LibraryReference reference in library.Libraries)
                        {
                            CheckCircularLibraryReference(program, library, reference.Name);
                            EnsureLibraryRegistered(program, reference, withReconciliation);
                            loadedLibrary.RequiredLibraries.Add(program.CatalogDeviceSession.ResolveLoadedLibrary(reference.Name));
                            program.Catalog.OperatorResolutionCache.Clear(loadedLibrary.GetNameResolutionPath(program.ServerProcess.ServerSession.Server.SystemLibrary));
                            loadedLibrary.ClearNameResolutionPath();
                        }

                        ((Server.Server)program.ServerProcess.ServerSession.Server).DoLibraryLoading(library.Name);
                        try
                        {
                            // Register the assemblies
                            RegisterLibraryFiles(program, library, loadedLibrary);
                            program.CatalogDeviceSession.InsertLoadedLibrary(loadedLibrary);
                            loadedLibrary.AttachLibrary();
                            try
                            {
                                // Set the current library to the newly registered library
                                Schema.LoadedLibrary currentLibrary = program.Plan.CurrentLibrary;
                                program.ServerProcess.ServerSession.CurrentLibrary = loadedLibrary;
                                try
                                {
                                    //	run the register.d4 script if it exists in the library
                                    //		catalog objects created in this script are part of this library
                                    string registerFileName = Path.Combine(library.GetLibraryDirectory(((Server.Server)program.ServerProcess.ServerSession.Server).LibraryDirectory), RegisterFileName);
                                    if (File.Exists(registerFileName))
                                    {
                                        try
                                        {
                                            using (StreamReader reader = new StreamReader(registerFileName))
                                            {
                                                program.ServerProcess.ServerSession.Server.RunScript
                                                (
                                                    program.ServerProcess,
                                                    reader.ReadToEnd(),
                                                    libraryName,
                                                    new DAE.Debug.DebugLocator(String.Format(RegisterDocumentLocator, libraryName), 1, 1)
                                                );
                                            }
                                        }
                                        catch (Exception exception)
                                        {
                                            throw new RuntimeException(RuntimeException.Codes.LibraryRegistrationFailed, exception, libraryName);
                                        }
                                    }

                                    ((ServerCatalogDeviceSession)program.CatalogDeviceSession).SetCurrentLibraryVersion(library.Name, library.Version);
                                    ((ServerCatalogDeviceSession)program.CatalogDeviceSession).SetLibraryOwner(loadedLibrary.Name, loadedLibrary.Owner.ID);
                                    if (library.IsSuspect)
                                    {
                                        library.IsSuspect = false;
                                        library.SaveInfoToFile(Path.Combine(library.GetInstanceLibraryDirectory(((Server.Server)program.ServerProcess.ServerSession.Server).InstanceDirectory), GetInfoFileName(library.Name)));
                                    }
                                }
                                catch
                                {
                                    program.ServerProcess.ServerSession.CurrentLibrary = currentLibrary;
                                    throw;
                                }
                            }
                            catch
                            {
                                loadedLibrary.DetachLibrary();
                                throw;
                            }
                            program.Catalog.Libraries.DoLibraryLoaded(program, library.Name);
                        }
                        finally
                        {
                            ((Server.Server)program.ServerProcess.ServerSession.Server).DoLibraryLoaded(libraryName);
                        }
                    }
                }
                finally
                {
                    if (!withReconciliation)
                    {
                        program.ServerProcess.EnableReconciliation();
                    }
                }
            }
            finally
            {
                program.ServerProcess.ResumeReconciliationState(saveReconciliationState);
            }
        }
Пример #5
0
        public static void RegisterLibraryFiles(Program program, Schema.Library library, Schema.LoadedLibrary loadedLibrary)
        {
            // Register each assembly with the DAE
                        #if !LOADFROMLIBRARIES
            foreach (Schema.FileReference file in ALibrary.Files)
            {
                if ((file.Environments.Count == 0) || file.Environments.Contains(Environments.WindowsServer))
                {
                    string sourceFile = Path.IsPathRooted(file.FileName) ? file.FileName : Path.Combine(ALibrary.GetLibraryDirectory(((Server.Server)AProgram.ServerProcess.ServerSession.Server).LibraryDirectory), file.FileName);
                    string targetFile = Path.Combine(PathUtility.GetBinDirectory(), Path.GetFileName(file.FileName));

                    if (!File.Exists(sourceFile))
                    {
                        throw new System.IO.IOException(String.Format("File \"{0}\" not found.", sourceFile));
                    }
                    try
                    {
                                                #if !RESPECTREADONLY
                        FileUtility.EnsureWriteable(targetFile);
                                                #endif
                        if ((File.GetLastWriteTimeUtc(sourceFile) > File.GetLastWriteTimeUtc(targetFile)))                         // source newer than target
                        {
                            File.Copy(sourceFile, targetFile, true);
                        }
                    }
                    catch (IOException)
                    {
                        // Ignore this exception so that assembly copying does not fail if the assembly is already loaded
                    }
                }
            }
                        #endif

            // Load assemblies after all files are copied in so that multi-file assemblies and other dependencies are certain to be present
            foreach (Schema.FileReference file in library.Files)
            {
                if ((file.Environments.Count == 0) || file.Environments.Contains(Environments.WindowsServer))
                {
                                        #if LOADFROMLIBRARIES
                    string sourceFile = Path.IsPathRooted(file.FileName) ? file.FileName : Path.Combine(library.GetLibraryDirectory(((Server.Server)program.ServerProcess.ServerSession.Server).LibraryDirectory), file.FileName);
                    if (FileUtility.IsAssembly(sourceFile))
                    {
                        Assembly assembly = Assembly.LoadFrom(sourceFile);
                                        #else
                    string targetFile = Path.Combine(PathUtility.GetBinDirectory(), Path.GetFileName(file.FileName));
                    if (FileUtility.IsAssembly(targetFile))
                    {
                        Assembly assembly = Assembly.LoadFrom(targetFile);
                    #endif
                        if (file.IsAssembly)
                        {
                            program.CatalogDeviceSession.RegisterAssembly(loadedLibrary, assembly);
                        }
                    }
                }
            }
        }