Пример #1
0
 public static void EnsureLibraryRegistered(Program program, Schema.LibraryReference libraryReference, bool withReconciliation)
 {
     Schema.LoadedLibrary loadedLibrary = program.CatalogDeviceSession.ResolveLoadedLibrary(libraryReference.Name, false);
     if (loadedLibrary == null)
     {
         Schema.LoadedLibrary currentLibrary = program.ServerProcess.ServerSession.CurrentLibrary;
         try
         {
             Schema.Library library = program.Catalog.Libraries[libraryReference.Name];
             if (!VersionNumber.Compatible(libraryReference.Version, library.Version))
             {
                 throw new Schema.SchemaException(Schema.SchemaException.Codes.LibraryVersionMismatch, libraryReference.Name, libraryReference.Version.ToString(), library.Version.ToString());
             }
             RegisterLibrary(program, library.Name, withReconciliation);
         }
         finally
         {
             program.ServerProcess.ServerSession.CurrentLibrary = currentLibrary;
         }
     }
     else
     {
         Schema.Library library = program.Catalog.Libraries[libraryReference.Name];
         if (!VersionNumber.Compatible(libraryReference.Version, library.Version))
         {
             throw new Schema.SchemaException(Schema.SchemaException.Codes.LibraryVersionMismatch, libraryReference.Name, libraryReference.Version.ToString(), library.Version.ToString());
         }
     }
 }
Пример #2
0
 public static void CheckCircularLibraryReference(Program program, Schema.Library library, string requiredLibraryName)
 {
     if (IsCircularLibraryReference(program, library, requiredLibraryName))
     {
         throw new Schema.SchemaException(Schema.SchemaException.Codes.CircularLibraryReference, library.Name, requiredLibraryName);
     }
 }
Пример #3
0
 /// <summary>Attaches the library given by ALibraryName from ALibraryDirectory. AIsAttached indicates whether this library is being attached as part of catalog startup.</summary>
 public static void AttachLibrary(Program program, string libraryName, string libraryDirectory, bool isAttached)
 {
     Schema.Library library = GetAvailableLibrary(((Server.Server)program.ServerProcess.ServerSession.Server).InstanceDirectory, libraryName, libraryDirectory);
     if ((library != null) && !program.Catalog.Libraries.ContainsName(library.Name))
     {
         AttachLibrary(program, library, isAttached);
     }
 }
Пример #4
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);
                        }
                    }
                }
            }
        }
Пример #5
0
        protected string GetDefaultDeviceName(Schema.Library library, bool shouldThrow)
        {
            if (library.DefaultDeviceName != String.Empty)
            {
                return(library.DefaultDeviceName);
            }

            Schema.Libraries libraries = new Schema.Libraries();
            libraries.Add(library);
            return(GetDefaultDeviceName(libraries, shouldThrow));
        }
Пример #6
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;
                }
            }
        }
Пример #7
0
 private static void EnsureLibraryUnregistered(Program program, Schema.Library library, bool withReconciliation)
 {
     Schema.LoadedLibrary loadedLibrary = program.CatalogDeviceSession.ResolveLoadedLibrary(library.Name, false);
     if (loadedLibrary != null)
     {
         while (loadedLibrary.RequiredByLibraries.Count > 0)
         {
             EnsureLibraryUnregistered(program, program.Catalog.Libraries[loadedLibrary.RequiredByLibraries[0].Name], withReconciliation);
         }
         UnregisterLibrary(program, library.Name, withReconciliation);
     }
 }
Пример #8
0
        public static Schema.Library GetAvailableLibrary(string instanceDirectory, string libraryName, string libraryDirectory)
        {
            string libraryFileName = Path.Combine(libraryDirectory, GetFileName(libraryName));

            if (File.Exists(libraryFileName))
            {
                Schema.Library library = LoadFromFile(libraryFileName, instanceDirectory);
                library.Directory = libraryDirectory;
                return(library);
            }
            return(null);
        }
Пример #9
0
 public override object InternalExecute(Program program, object[] arguments)
 {
                 #if NILPROPOGATION
     if (arguments[0] == null || arguments[1] == null)
     {
         return(null);
     }
                 #endif
     Schema.Library library = (Schema.Library)arguments[0];
     library.Version = (VersionNumber)arguments[1];
     return(library);
 }
Пример #10
0
 public override object InternalExecute(Program program, object[] arguments)
 {
                 #if NILPROPOGATION
     if ((arguments[0] == null) || arguments[1] == null)
     {
         return(null);
     }
                 #endif
     Schema.Library library = (Schema.Library)arguments[0];
     library.DefaultDeviceName = (string)arguments[1];
     return(library);
 }
Пример #11
0
 public override object InternalExecute(Program program, object[] arguments)
 {
                 #if NILPROPOGATION
     if ((arguments[0] == null) || arguments[1] == null)
     {
         return(null);
     }
                 #endif
     Schema.Library library = (Schema.Library)arguments[0];
     library.Name = Schema.Object.EnsureUnrooted((string)arguments[1]);
     return(library);
 }
Пример #12
0
 public string GetFullFileName(Schema.Library library, string fileName)
 {
                 #if LOADFROMLIBRARIES
     return
         (Path.IsPathRooted(fileName)
                                 ? fileName
                                 :
          library.Name == Engine.SystemLibraryName
                                                 ? PathUtility.GetFullFileName(fileName)
                                                 : Path.Combine(Schema.LibraryUtility.GetLibraryDirectory(library, LibraryDirectory), fileName));
                 #else
     return(PathUtility.GetFullFileName(AFileName));
                 #endif
 }
Пример #13
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);
                }
            }
        }
Пример #14
0
 public override object InternalExecute(Program program, object[] arguments)
 {
                 #if NILPROPOGATION
     if ((arguments[0] == null))
     {
         return(null);
     }
                 #endif
     Schema.Library library    = (Schema.Library)arguments[0];
     ListValue      requisites = new ListValue(program.ValueManager, (Schema.IListType)_dataType);
     foreach (Schema.LibraryReference reference in library.Libraries)
     {
         requisites.Add(reference.Clone());
     }
     return(requisites);
 }
Пример #15
0
        public virtual void LoadAvailableLibraries()
        {
            lock (_catalog.Libraries)
            {
                _catalog.UpdateTimeStamp();
                InternalLoadAvailableLibraries();

                // Create the implicit system library
                Schema.Library systemLibrary = new Schema.Library(SystemLibraryName);
                systemLibrary.Files.Add(new Schema.FileReference("Alphora.Dataphor.DAE.dll", true));
                Version version = AssemblyNameUtility.GetVersion(typeof(Engine).Assembly.FullName);                 // HACK: Have to use this instead of Assembly.GetName() to work around Silverlight security
                systemLibrary.Version           = new VersionNumber(version.Major, version.Minor, version.Build, version.Revision);
                systemLibrary.DefaultDeviceName = TempDeviceName;
                _catalog.Libraries.Add(systemLibrary);
            }
        }
Пример #16
0
 public override object InternalExecute(Program program, object[] arguments)
 {
                 #if NILPROPOGATION
     if ((arguments[0] == null) || arguments[1] == null)
     {
         return(null);
     }
                 #endif
     Schema.Library library    = (Schema.Library)arguments[0];
     ListValue      requisites = (ListValue)arguments[1];
     library.Libraries.Clear();
     for (int index = 0; index < requisites.Count(); index++)
     {
         library.Libraries.Add((Schema.LibraryReference)((Schema.LibraryReference)requisites[index]).Clone());
     }
     return(library);
 }
Пример #17
0
        public static bool IsCircularLibraryReference(Program program, Schema.Library library, string requiredLibraryName)
        {
            Schema.Library requiredLibrary = program.Catalog.Libraries[requiredLibraryName];
            if (Schema.Object.NamesEqual(library.Name, requiredLibraryName))
            {
                return(true);
            }

            foreach (Schema.LibraryReference reference in requiredLibrary.Libraries)
            {
                if (IsCircularLibraryReference(program, library, reference.Name))
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #18
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);
            }
        }
Пример #19
0
 public override object InternalExecute(Program program, object[] arguments)
 {
                 #if NILPROPOGATION
     if ((arguments[0] == null) || arguments[1] == null)
     {
         return(null);
     }
                 #endif
     Schema.Library library = (Schema.Library)arguments[0];
     if (arguments[1] == null)
     {
         library.Directory = null;
     }
     else
     {
         library.Directory = (string)arguments[1];
     }
     return(library);
 }
Пример #20
0
        internal ServerFileInfos GetFileNames(Schema.Library library, string environment)
        {
            ServerFileInfos fileInfos = new ServerFileInfos();

            Schema.Libraries libraries = new Schema.Libraries();
            libraries.Add(library);

            while (libraries.Count > 0)
            {
                Schema.Library localLibrary = libraries[0];
                libraries.RemoveAt(0);

                foreach (Schema.FileReference reference in library.Files)
                {
                    if (reference.Environments.Contains(environment) && !fileInfos.Contains(reference.FileName))
                    {
                        string fullFileName = GetFullFileName(library, reference.FileName);
                        fileInfos.Add
                        (
                            new ServerFileInfo
                        {
                            LibraryName      = library.Name,
                            FileName         = reference.FileName,
                            FileDate         = File.GetLastWriteTimeUtc(fullFileName),
                            IsDotNetAssembly = FileUtility.IsAssembly(fullFileName),
                            ShouldRegister   = reference.IsAssembly
                        }
                        );
                    }
                }

                foreach (Schema.LibraryReference reference in localLibrary.Libraries)
                {
                    if (!libraries.Contains(reference.Name))
                    {
                        libraries.Add(Catalog.Libraries[reference.Name]);
                    }
                }
            }

            return(fileInfos);
        }
Пример #21
0
        protected string GetDefaultDeviceName(Schema.Libraries libraries, bool shouldThrow)
        {
            while (libraries.Count > 0)
            {
                Schema.Library library = libraries[0];
                libraries.RemoveAt(0);

                string         defaultDeviceName = String.Empty;
                Schema.Library requiredLibrary;
                foreach (Schema.LibraryReference libraryReference in library.Libraries)
                {
                    requiredLibrary = Catalog.Libraries[libraryReference.Name];
                    if (requiredLibrary.DefaultDeviceName != String.Empty)
                    {
                        if (defaultDeviceName != String.Empty)
                        {
                            if (shouldThrow)
                            {
                                throw new Schema.SchemaException(Schema.SchemaException.Codes.AmbiguousDefaultDeviceName, library.Name);
                            }
                            else
                            {
                                return(String.Empty);
                            }
                        }
                        defaultDeviceName = requiredLibrary.DefaultDeviceName;
                    }
                    else
                    if (!libraries.Contains(requiredLibrary))
                    {
                        libraries.Add(requiredLibrary);
                    }
                }

                if (defaultDeviceName != String.Empty)
                {
                    return(defaultDeviceName);
                }
            }

            return(String.Empty);
        }
Пример #22
0
 public override void LoadAvailableLibraries()
 {
     base.LoadAvailableLibraries();
     lock (Catalog.Libraries)
     {
         // Ensure the general library exists
         if (!Catalog.Libraries.Contains(GeneralLibraryName))
         {
             Schema.Library generalLibrary = new Schema.Library(GeneralLibraryName);
             generalLibrary.Libraries.Add(new Schema.LibraryReference(SystemLibraryName, new VersionNumber(-1, -1, -1, -1)));
             Catalog.Libraries.Add(generalLibrary);
             string libraryDirectory = Path.Combine(Schema.LibraryUtility.GetDefaultLibraryDirectory(LibraryDirectory), generalLibrary.Name);
             if (!Directory.Exists(libraryDirectory))
             {
                 Directory.CreateDirectory(libraryDirectory);
             }
             Schema.LibraryUtility.SaveToFile(generalLibrary, Path.Combine(libraryDirectory, Schema.LibraryUtility.GetFileName(generalLibrary.Name)));
         }
     }
 }
Пример #23
0
        public static void GetAvailableLibraries(string instanceDirectory, string libraryDirectory, Libraries libraries, bool setLibraryDirectory)
        {
            string libraryName;
            string libraryFileName;

            string[] localLibraries = System.IO.Directory.GetDirectories(libraryDirectory);
            for (int index = 0; index < localLibraries.Length; index++)
            {
                libraryName     = Path.GetFileName(localLibraries[index]);
                libraryFileName = Path.Combine(localLibraries[index], GetFileName(libraryName));
                if (File.Exists(libraryFileName))
                {
                    Schema.Library library = LoadFromFile(libraryFileName, instanceDirectory);
                    if (setLibraryDirectory)
                    {
                        library.Directory = localLibraries[index];
                    }
                    libraries.Add(library);
                }
            }
        }
Пример #24
0
        public ServerFileInfo[] GetFileNames(string className, string environment)
        {
            Schema.RegisteredClass classValue = _serverProcess.ServerSession.Server.Catalog.ClassLoader.Classes[className];

            List <string> libraryNames      = new List <string>();
            List <string> fileNames         = new List <string>();
            List <string> assemblyFileNames = new List <string>();
            ArrayList     fileDates         = new ArrayList();

            // Build the list of all files required to load the assemblies in all libraries required by the library for the given class
            Schema.Library  library   = _serverProcess.ServerSession.Server.Catalog.Libraries[classValue.Library.Name];
            ServerFileInfos fileInfos = _session.Server.Server.GetFileNames(library, environment);

            // Return the results in reverse order to ensure that dependencies are loaded in the correct order
            ServerFileInfo[] results = new ServerFileInfo[fileInfos.Count];
            for (int index = fileInfos.Count - 1; index >= 0; index--)
            {
                results[fileInfos.Count - index - 1] = fileInfos[index];
            }

            return(results);
        }
Пример #25
0
        public override object InternalExecute(Program program, object[] arguments)
        {
                        #if NILPROPOGATION
            if ((arguments[0] == null) || (arguments[1] == null))
            {
                return(null);
            }
                        #endif
            Schema.Library leftLibrary    = (Schema.Library)arguments[0];
            Schema.Library rightLibrary   = (Schema.Library)arguments[1];
            bool           librariesEqual =
                (leftLibrary.Name == rightLibrary.Name) &&
                (leftLibrary.Directory == rightLibrary.Directory) &&
                (leftLibrary.Files.Count == rightLibrary.Files.Count) &&
                (leftLibrary.Libraries.Count == rightLibrary.Libraries.Count);

            if (librariesEqual)
            {
                for (int index = 0; index < leftLibrary.Files.Count; index++)
                {
                    if (!(leftLibrary.Files[index].Equals(rightLibrary.Files[index])))
                    {
                        librariesEqual = false;
                        break;
                    }
                }

                for (int index = 0; index < leftLibrary.Libraries.Count; index++)
                {
                    if (!(leftLibrary.Libraries[index].Equals(rightLibrary.Libraries[index])))
                    {
                        librariesEqual = false;
                        break;
                    }
                }
            }

            return(librariesEqual);
        }
Пример #26
0
        private static void LoadLibrary(Program program, string libraryName, bool isKnown)
        {
            lock (program.Catalog.Libraries)
            {
                try
                {
                    Schema.Library library        = program.Catalog.Libraries[libraryName];
                    VersionNumber  currentVersion = ((ServerCatalogDeviceSession)program.CatalogDeviceSession).GetCurrentLibraryVersion(libraryName);

                    if (program.Catalog.LoadedLibraries.Contains(library.Name))
                    {
                        throw new Schema.SchemaException(Schema.SchemaException.Codes.LibraryAlreadyLoaded, libraryName);
                    }

                    bool isLoaded = false;
                    bool areAssembliesRegistered       = false;
                    Schema.LoadedLibrary loadedLibrary = null;
                    try
                    {
                        loadedLibrary       = new Schema.LoadedLibrary(libraryName);
                        loadedLibrary.Owner = program.CatalogDeviceSession.ResolveUser(((ServerCatalogDeviceSession)program.CatalogDeviceSession).GetLibraryOwner(libraryName));

                        //	Ensure that each required library is loaded
                        foreach (Schema.LibraryReference reference in library.Libraries)
                        {
                            Schema.Library requiredLibrary = program.Catalog.Libraries[reference.Name];
                            if (!VersionNumber.Compatible(reference.Version, requiredLibrary.Version))
                            {
                                throw new Schema.SchemaException(Schema.SchemaException.Codes.LibraryVersionMismatch, reference.Name, reference.Version.ToString(), requiredLibrary.Version.ToString());
                            }

                            if (!program.Catalog.LoadedLibraries.Contains(reference.Name))
                            {
                                if (!requiredLibrary.IsSuspect)
                                {
                                    LoadLibrary(program, reference.Name, isKnown);
                                }
                                else
                                {
                                    throw new Schema.SchemaException(Schema.SchemaException.Codes.RequiredLibraryNotLoaded, libraryName, reference.Name);
                                }
                            }

                            loadedLibrary.RequiredLibraries.Add(program.CatalogDeviceSession.ResolveLoadedLibrary(reference.Name));
                            program.Catalog.OperatorResolutionCache.Clear(loadedLibrary.GetNameResolutionPath(program.ServerProcess.ServerSession.Server.SystemLibrary));
                            loadedLibrary.ClearNameResolutionPath();
                        }

                        program.ServerProcess.ServerSession.Server.DoLibraryLoading(library.Name);
                        try
                        {
                            // RegisterAssemblies
                            RegisterLibraryFiles(program, library, loadedLibrary);

                            areAssembliesRegistered = true;

                            program.CatalogDeviceSession.InsertLoadedLibrary(loadedLibrary);
                            loadedLibrary.AttachLibrary();
                            try
                            {
                                ((ServerCatalogDeviceSession)program.CatalogDeviceSession).SetLibraryOwner(loadedLibrary.Name, loadedLibrary.Owner.ID);
                            }
                            catch (Exception registerException)
                            {
                                loadedLibrary.DetachLibrary();
                                throw registerException;
                            }

                            isLoaded = true;                             // If we reach this point, a subsequent exception must unload the library
                            if (library.IsSuspect)
                            {
                                library.IsSuspect = false;
                                library.SaveInfoToFile(Path.Combine(library.GetInstanceLibraryDirectory(((Server.Server)program.ServerProcess.ServerSession.Server).InstanceDirectory), Schema.LibraryUtility.GetInfoFileName(library.Name)));
                            }
                        }
                        finally
                        {
                            program.ServerProcess.ServerSession.Server.DoLibraryLoaded(library.Name);
                        }
                    }
                    catch (Exception exception)
                    {
                        program.ServerProcess.ServerSession.Server.LogError(exception);
                        library.IsSuspect     = true;
                        library.SuspectReason = ExceptionUtility.DetailedDescription(exception);
                        library.SaveInfoToFile(Path.Combine(library.GetInstanceLibraryDirectory(((Server.Server)program.ServerProcess.ServerSession.Server).InstanceDirectory), Schema.LibraryUtility.GetInfoFileName(library.Name)));

                        if (isLoaded)
                        {
                            UnregisterLibrary(program, libraryName, false);
                        }
                        else if (areAssembliesRegistered)
                        {
                            UnregisterLibraryAssemblies(program, loadedLibrary);
                        }

                        throw;
                    }

                    ((ServerCatalogDeviceSession)program.CatalogDeviceSession).SetCurrentLibraryVersion(library.Name, currentVersion);                     // Once a library has loaded, record the version number

                    program.Catalog.Libraries.DoLibraryLoaded(program, library.Name);
                }
                catch
                {
                    if (program.ServerProcess.ServerSession.Server.State == ServerState.Started)
                    {
                        throw;
                    }
                }
            }
        }
Пример #27
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);
            }
        }
Пример #28
0
        public override object InternalExecute(Program program, object[] arguments)
        {
                        #if NILPROPOGATION
            if (arguments[0] == null)
            {
                return(null);
            }
                        #endif
            Schema.Library library = new Schema.Library(Schema.Object.EnsureUnrooted((string)arguments[0]));
            if (arguments.Length >= 2)
            {
                                #if NILPROPOGATION
                if (arguments[1] == null)
                {
                    return(null);
                }
                                #endif
                library.Version = (VersionNumber)arguments[1];
            }
            else
            {
                library.Version = new VersionNumber(-1, -1, -1, -1);
            }

            if (arguments.Length >= 3)
            {
                                #if NILPROPOGATION
                if (arguments[2] == null)
                {
                    return(null);
                }
                                #endif
                library.DefaultDeviceName = (string)arguments[2];
            }

            if (arguments.Length >= 4)
            {
                                #if NILPROPOGATION
                if (arguments[3] == null || arguments[4] == null)
                {
                    return(null);
                }
                                #endif
                ListValue files      = (ListValue)arguments[3];
                ListValue requisites = (ListValue)arguments[4];

                for (int index = 0; index < files.Count(); index++)
                {
                    library.Files.Add((Schema.FileReference)files[index]);
                }

                for (int index = 0; index < requisites.Count(); index++)
                {
                    library.Libraries.Add((Schema.LibraryReference)requisites[index]);
                }
            }

            if (arguments.Length >= 6)
            {
                                #if NILPROPOGATION
                if (arguments[5] == null)
                {
                    return(null);
                }
                                #endif
                library.Directory = (string)arguments[5];
            }

            return(library);
        }
Пример #29
0
 private static void RemoveLibrary(Program program, Schema.Library library)
 {
     // Ensure that the library and any dependencies of it are unregistered
     EnsureLibraryUnregistered(program, library, false);
     DetachLibrary(program, library.Name);
 }