Esempio n. 1
0
        internal void SaveServersToDirectory(IServerDirectory directory)
        {
            //NOTE: The server tree currently doesn't handle any of the "extended" server data, so we just abstract that part away
            //and only deal with it when we are saving the servers back to the directory.

            //Get all the entries from the directory.
            var serverDirectoryEntries = directory.GetServers(new GetServersRequest()).ServerEntries.ToList();

            //Convert the tree items to data contracts (ApplicationEntity).
            var treeServers = RootServerGroup.GetAllServers().OfType <IServerTreeDicomServer>().Select(a => a.ToDataContract()).ToList();

            //Figure out which entries have been deleted.
            IEnumerable <ServerDirectoryEntry> deletedEntries = from d in serverDirectoryEntries where !treeServers.Any(t => t.Name == d.Server.Name) select d;
            //Figure out which are new.
            IEnumerable <ApplicationEntity> addedServers = (from t in treeServers where !serverDirectoryEntries.Any(d => t.Name == d.Server.Name) select t);
            //Figure out which have changed.
            IEnumerable <ApplicationEntity> changedServers = (from t in treeServers where serverDirectoryEntries.Any(d => t.Name == d.Server.Name && !t.Equals(d.Server)) select t);

            //Most updates are done one server at a time, anyway, so we'll just do this.
            //Could implement bulk update methods on the service, too.
            foreach (var d in deletedEntries)
            {
                try
                {
                    directory.DeleteServer(new DeleteServerRequest {
                        ServerEntry = d
                    });
                }
                catch (Exception e)
                {
                    Platform.Log(LogLevel.Warn, e, "Server being deleted ('{0}') does not exist in directory.", d.Server.Name);
                }
            }

            foreach (var c in changedServers)
            {
                //Find the corresponding entry and update IT because we don't want to lose the "extended" data.
                var changedEntry = serverDirectoryEntries.First(e => e.Server.Name == c.Name);
                changedEntry.Server = c;
                directory.UpdateServer(new UpdateServerRequest {
                    ServerEntry = changedEntry
                });
            }
            foreach (var a in addedServers)
            {
                directory.AddServer(new AddServerRequest {
                    ServerEntry = new ServerDirectoryEntry(a)
                });
            }
        }
Esempio n. 2
0
        private bool IsConflictingServerNameInTree(string name, bool excludeCurrentNode, out string conflictingServerPath)
        {
            var allServers = RootServerGroup.GetAllServers();

            if (excludeCurrentNode)
            {
                allServers = allServers.Where(s => s != CurrentNode).ToList();
            }

            foreach (var server in allServers)
            {
                if (String.Compare(server.Name, name, true) == 0)
                {
                    conflictingServerPath = server.Path;
                    return(true);
                }
            }

            conflictingServerPath = "";
            return(false);
        }