protected override bool Initialize()
        {
            _archiveServiceList.Clear();


            // Force a read context to be opened.  When developing the retry mechanism
            // for startup when the DB was down, there were problems when the type
            // initializer for enumerated values were failng first.  For some reason,
            // when the database went back online, they would still give exceptions.
            // changed to force the processor to open a dummy DB connect and cause an
            // exception here, instead of getting to the enumerated value initializer.

            IList <PartitionArchive> partitionArchiveList = LoadEnabledPartitionArchives();


            ImageServerArchiveExtensionPoint ep = new ImageServerArchiveExtensionPoint();

            ExtensionInfo[] extensionInfoList = ep.ListExtensions();

            foreach (PartitionArchive partitionArchive in partitionArchiveList)
            {
                ServerPartition partition = ServerPartition.Load(partitionArchive.ServerPartitionKey);


                if (!partition.Enabled)
                {
                    Platform.Log(LogLevel.Info, "Server Partition '{0}' is disabled, not starting PartitionArchive '{1}'", partition.Description,
                                 partitionArchive.Description);
                    continue;
                }

                if (!partitionArchive.Enabled)
                {
                    Platform.Log(LogLevel.Info, "PartitionArchive '{0}' is disabled, not starting", partitionArchive.Description);
                    continue;
                }

                foreach (ExtensionInfo extensionInfo in extensionInfoList)
                {
                    IImageServerArchivePlugin archive =
                        (IImageServerArchivePlugin)ep.CreateExtension(new ClassNameExtensionFilter(extensionInfo.FormalName));

                    if (archive.ArchiveType.Equals(partitionArchive.ArchiveTypeEnum))
                    {
                        _archiveServiceList.Add(new PartitionArchiveService(archive, partitionArchive, partition));
                        break;
                    }
                }
            }
            return(true);
        }
예제 #2
0
			public PartitionArchiveService(IImageServerArchivePlugin archive, PartitionArchive partitionArchive, ServerPartition partition)
			{
				_archive = archive;
				_partitionArchive = partitionArchive;
				_serverPartition = partition;
			}
 public PartitionArchiveService(IImageServerArchivePlugin archive, PartitionArchive partitionArchive, ServerPartition partition)
 {
     _archive          = archive;
     _partitionArchive = partitionArchive;
     _serverPartition  = partition;
 }
        /// <summary>
        /// Check the currently configured archives and plugins to see if any have been disabled.
        /// </summary>
        private void CheckConfiguredArchives()
        {
            IList <ServerPartition> partitionList = LoadPartitions();

            lock (_syncLock)
            {
                IList <PartitionArchiveService> partitionsToDelete = new List <PartitionArchiveService>();

                foreach (PartitionArchiveService archiveService in _archiveServiceList)
                {
                    archiveService.PartitionArchive = PartitionArchive.Load(archiveService.PartitionArchive.GetKey());
                    if (!archiveService.PartitionArchive.Enabled)
                    {
                        Platform.Log(LogLevel.Info, "PartitionArchive {0} has been disabled, stopping plugin.", archiveService.PartitionArchive.Description);
                        archiveService.ArchivePlugin.Stop();
                        partitionsToDelete.Add(archiveService);
                    }
                    else
                    {
                        bool bFound = false;
                        foreach (ServerPartition serverPartition in partitionList)
                        {
                            if (serverPartition.GetKey().Equals(archiveService.ServerPartition.GetKey()) && serverPartition.Enabled)
                            {
                                bFound = true;
                                break;
                            }
                        }

                        if (!bFound)
                        {
                            Platform.Log(LogLevel.Info, "Partition was deleted or disabled, shutting down archive server {0}",
                                         archiveService.ServerPartition.Description);
                            archiveService.ArchivePlugin.Stop();
                            partitionsToDelete.Add(archiveService);
                        }
                    }
                }

                // Remove the services from our internal list.
                foreach (PartitionArchiveService archivePlugin in partitionsToDelete)
                {
                    _archiveServiceList.Remove(archivePlugin);
                }

                // Load the current extension list
                ImageServerArchiveExtensionPoint ep = new ImageServerArchiveExtensionPoint();
                ExtensionInfo[] extensionInfoList   = ep.ListExtensions();


                // Scan the current list of enabled partition archives to see if any
                // new archives have been added
                foreach (PartitionArchive partitionArchive in LoadEnabledPartitionArchives())
                {
                    ServerPartition newPartition = ServerPartition.Load(partitionArchive.ServerPartitionKey);

                    if (!newPartition.Enabled)
                    {
                        continue;
                    }

                    bool bFound = false;
                    foreach (PartitionArchiveService service in _archiveServiceList)
                    {
                        if (!partitionArchive.GetKey().Equals(service.PartitionArchive.GetKey()))
                        {
                            continue;
                        }

                        // Reset the context partition, incase its changed.
                        service.PartitionArchive = partitionArchive;

                        bFound = true;
                        break;
                    }

                    if (!bFound)
                    {
                        // No match, scan the current extensions for a matching extension
                        // to run the service
                        foreach (ExtensionInfo extensionInfo in extensionInfoList)
                        {
                            IImageServerArchivePlugin archive =
                                (IImageServerArchivePlugin)ep.CreateExtension(new ClassNameExtensionFilter(extensionInfo.FormalName));

                            if (archive.ArchiveType.Equals(partitionArchive.ArchiveTypeEnum))
                            {
                                PartitionArchiveService service = new PartitionArchiveService(archive, partitionArchive, newPartition);
                                Platform.Log(LogLevel.Info, "Detected PartitionArchive was added, starting archive {0}", partitionArchive.Description);
                                service.ArchivePlugin.Start(partitionArchive);
                                _archiveServiceList.Add(service);
                                break;
                            }
                        }
                    }
                }
            }
        }