Exemplo n.º 1
0
 public void RemoveFolder(XenRef <Folder> path)
 {
     lock (_folders)
     {
         _folders.Remove(path);
     }
     foldersChanged = true;
 }
Exemplo n.º 2
0
 private void Clear_ <T>(ChangeableDictionary <XenRef <T>, T> o) where T : XenObject <T>
 {
     // explicitly remove each element so change events are fired
     XenRef <T>[] keys = new XenRef <T> [o.Keys.Count];
     o.Keys.CopyTo(keys, 0);
     foreach (XenRef <T> key in keys)
     {
         lock (o)
         {
             o.Remove(key);
         }
     }
 }
Exemplo n.º 3
0
        private void UpdateFrom_ <T>(Network.IXenConnection connection, ChangeableDictionary <XenRef <T>, T> target, ObjectChange source) where T : XenObject <T>, new()
        {
            XenRef <T> xenref = source.xenref as XenRef <T>;

            if (xenref == null)
            {
                xenref = new XenRef <T>((string)source.xenref);
            }

            if (source.value != null)
            {
                T to_update = null;
                lock (target)
                {
                    if (!target.TryGetValue(xenref, out to_update))
                    {
                        // add
                        T obj = new T();
                        obj.Connection = connection;
                        obj.UpdateFrom((T)source.value);
                        obj.opaque_ref = xenref.opaque_ref;
                        target.Add(xenref, obj);
                    }
                }

                // Update the object that we found above.  Note that this needs to be done out of the
                // scope of the lock(target), as UpdateFrom is going to fire events.
                if (to_update != null)
                {
                    to_update.UpdateFrom((T)source.value);
                }
            }
            else
            {
                // delete the source object from our model
                lock (target)
                {
                    target.Remove(xenref);
                }
            }
        }
Exemplo n.º 4
0
        public void UpdateDockerContainersForVM(IList <DockerContainer> containers, VM vm)
        {
            Trace.Assert(vm != null);

            //updating existing, adding new containers
            dockerContainersChanged = dockerContainersChanged || containers.Count > 0;
            foreach (var c in containers)
            {
                _dockerContainers[new XenRef <DockerContainer>(c)] = c;
            }

            List <KeyValuePair <XenRef <DockerContainer>, DockerContainer> > containersGoneFromThisVM = null;

            //removing the ones that are not there anymore on this VM
            lock (_dockerContainers)
            {
                containersGoneFromThisVM = _dockerContainers.Where(c => c.Value != null && c.Value.Parent.uuid == vm.uuid && !containers.Any(cont => cont.uuid == c.Value.uuid)).ToList();
                dockerContainersChanged  = dockerContainersChanged || containersGoneFromThisVM.Count > 0;
                foreach (var c in containersGoneFromThisVM)
                {
                    _dockerContainers.Remove(new XenRef <DockerContainer>(c.Value));
                }
            }
        }