public bool Stop() { if (State != ResourceState.Running && State != ResourceState.Starting) { throw new InvalidOperationException(string.Format("Tried to stop a resource ({0}) that wasn't running.", Name)); } this.Log().Info("Stopping resource {0} (last state: {1}).", Name, State); if (State == ResourceState.Running) { if (!Manager.TriggerEvent("onResourceStop", -1, Name)) { return(false); } } var dependants = Dependants.GetRange(0, Dependants.Count); foreach (var dependant in dependants) { var dependantResource = Manager.GetResource(dependant); dependantResource.Stop(); } Dependants.Clear(); foreach (var dependency in Dependencies) { var dependencyResource = Manager.GetResource(dependency); dependencyResource.RemoveDependant(Name); } // remove the watcher m_watcher.Dispose(); m_watcher = null; // dispose of the script environment m_scriptEnvironment.Dispose(); m_scriptEnvironment = null; if (State == ResourceState.Running) { // broadcast a stop message to all clients var clients = ClientInstances.Clients.Where(c => c.Value.NetChannel != null).Select(c => c.Value); foreach (var client in clients) { client.SendReliableCommand(0x45E855D7, Encoding.UTF8.GetBytes(Name)); // msgResStop } } // done! State = ResourceState.Stopped; return(true); }
public void Clear() { _jumpTable.Clear(); _dynamicTable.Clear(); Targets.Clear(); Dependants.Clear(); Owners.Clear(); }
public void ClearIfNeeded() { if (_jumpTable.Count == 0 && _dynamicTable.Count == 0 && Targets.Count == 0 && Dependants.Count == 0 && Owners.Count == 0) { return; } _jumpTable.Clear(); _jumpTable.TrimExcess(); _dynamicTable.Clear(); _dynamicTable.TrimExcess(); Targets.Clear(); Targets.TrimExcess(); Dependants.Clear(); Dependants.TrimExcess(); Owners.Clear(); Owners.TrimExcess(); }
public void Initialize(JumpTable jumpTable) { Targets.Clear(); foreach (ulong guestAddress in jumpTable.Targets.Keys) { Targets.Add(guestAddress); } Dependants.Clear(); foreach (var kv in jumpTable.Dependants) { Dependants.Add(kv.Key, new List <int>(kv.Value)); } Owners.Clear(); foreach (var kv in jumpTable.Owners) { Owners.Add(kv.Key, new List <int>(kv.Value)); } }