private void AddUser(string modelName, bool quickStart = false) { // Normalising name modelName = NormaliseModelName(modelName).ToLower(); // Checking input validity if (string.IsNullOrWhiteSpace(modelName)) { // MessageBox.Show(this, "Invalid model name, cannot be empty or whitespace.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Logger.Log(modelName, "Added"); // Checking if the model is already being listened to if (modelsBox.Items.Cast <object>().Contains(modelName)) { return; // TODO restart stream instead } // Create process and add listener to lists LivestreamerProcess proc = new LivestreamerProcess(this, modelName); modelsBox.Items.Add(modelName); _listeners.AddOrUpdate(modelName, proc, (s, listener) => listener); // Quick start functionality (i.e. start listener immediately) proc.Start(quickStart); }
private void ListenerProcess() { while (true) { Thread.Sleep(ListenerSleepDelay); // Skip iteration if no listeners are attached if (_listeners.Count == 0) { continue; } // Update cached time TimeNow = DateTime.Now; // Handling each listener foreach (KeyValuePair <string, LivestreamerProcess> valuePair in _listeners) { string modelName = valuePair.Key; LivestreamerProcess proc = valuePair.Value; // Checking if a (re)start is required if (proc.CanRestart) { proc.Start(); } } } }
public void AddModel(string modelName, bool immediate = false) { // Normalising name modelName = NormaliseModelName(modelName).ToLower(); // Check input validity if (string.IsNullOrWhiteSpace(modelName)) { return; } // Check if the model is already being listened to if (_models.Contains(modelName)) { return; } // Create process and add listener to lists IDownloaderProcess process = new LivestreamerProcess(_parent, modelName); _models.AddModel(modelName); _listeners.AddOrUpdate(modelName, process, (s, listener) => listener); // Quick start functionality (i.e. start listener immediately) process.Start(immediate); Log.Info($"Added {modelName}"); }
private void restartToolStripMenuItem_Click(object sender, EventArgs e) { string modelName = GetSelectedModelName(); if (modelName == null) { return; } // Fetching process LivestreamerProcess listener = _listeners[modelName]; // Cancel restart if the listener is already running if (listener.Running) { return; } // Otherwise, continue with the manual start listener.Start(true); Logger.Log(modelName, "Manual restart"); }