public bool DeletePreset(Guid id) { try { AppLogger.Message("CameraControlService.DeletePreset " + id); lock (_userLock) { if (_plugin is IPresetProvider) { return(((IPresetProvider)_plugin).DeletePreset(id)); } else { UserPresetItem item = PresetItems[id]; return(PresetItems.Remove(item)); } } } catch (Exception exc) { AppLogger.Dump(exc); return(false); } }
public void LoadSavedPositions() { XmlTextReader reader = null; try { if (!File.Exists(SavedPositionsFileName)) { throw new FileNotFoundException("The file \"" + SavedPositionsFileName + "\" does not exist."); } XmlSerializer xmlSerializer = new XmlSerializer(typeof(UserPresetStore)); reader = new XmlTextReader(SavedPositionsFileName); PresetItems = (UserPresetStore)xmlSerializer.Deserialize(reader); } catch (Exception exc) { AppLogger.Dump(exc); PresetItems = new UserPresetStore(); } finally { if (reader != null) { reader.Close(); } } }
/// <summary> /// If the plugin is an IPresetProvider /// </summary> /// <returns></returns> public UserPresetItem SavePreset() { lock (_userLock) { AppLogger.Message("CameraControlService.SavePreset"); try { UserPresetItem item = null; if (_plugin is IPresetProvider) { item = ((IPresetProvider)_plugin).SavePreset(); } else { item = new CameraPositionPreset(CurrentPanAngle, CurrentTiltAngle, CurrentZoomPosition); PresetItems.Add(item); } return(item); } catch (IndexOutOfRangeException ex) { AppLogger.Dump(ex); this.StatusMessage = ex.Message; return(null); } catch (Exception exc) { AppLogger.Dump(exc); return(null); } } }
public bool UpdatePreset(UserPresetItem newItem) { try { AppLogger.Message(String.Format("CameraControlService.UpdatePreset {0} = {1}", newItem.ID, newItem)); lock (_userLock) { if (_plugin is IPresetProvider) { return(((IPresetProvider)_plugin).UpdatePreset(newItem)); } else { UserPresetItem oldItem = PresetItems[newItem.ID]; if (oldItem != null) { PresetItems.Remove(oldItem); } else { AppLogger.Message(" Warning! No item with ID " + newItem.ID + " pre-existed!"); } PresetItems.Add(newItem); return(true); } } } catch (Exception exc) { AppLogger.Dump(exc); return(false); } }
public void ZoomAbsolute(double zoomPosition) { lock (_userLock) { double oldValue = CurrentZoomPosition; try { if ((zoomPosition >= CameraControl.Capabilities.ZoomMinLevel) && (zoomPosition <= CameraControl.Capabilities.ZoomMaxLevel)) { Plugin.ZoomAbsolute(zoomPosition); } else { throw new ArgumentOutOfRangeException("zoomPosition", "Expected range is [" + CameraControl.Capabilities.ZoomMinLevel.ToString() + "," + CameraControl.Capabilities.ZoomMaxLevel.ToString() + "]."); } } catch (Exception exc) { AppLogger.Dump(exc); CurrentZoomPosition = oldValue; } } }
public void PanTiltAbsolute(double panAngle, double tiltAngle) { lock (_userLock) { double oldPanValue = CurrentPanAngle; double oldTiltValue = CurrentTiltAngle; try { if (((panAngle >= 0) && (panAngle < 360)) && ((tiltAngle >= CameraControl.Capabilities.TiltMinAngle) && (tiltAngle <= CameraControl.Capabilities.TiltMaxAngle))) { Plugin.PanTiltAbsolute(panAngle, tiltAngle); } else { throw new ArgumentOutOfRangeException("panAngle or tiltAngle", "Expected range is [0,360], [" + CameraControl.Capabilities.TiltMinAngle.ToString() + "," + CameraControl.Capabilities.TiltMaxAngle.ToString() + "]."); } } catch (Exception exc) { AppLogger.Dump(exc); CurrentPanAngle = oldPanValue; CurrentTiltAngle = oldTiltValue; } } }
public void Dispose() { if (resourceAcquired) { try { ResourceManager.Release(this.ResourceID, typeof(CameraControlService), clientRequest.UserName); } catch (Exception ex) { AppLogger.Dump(ex); } } if (PresetItems != null) { PersistSavedPositions(); } if (_plugin != null) { try { _plugin.Dispose(); _plugin = null; } catch (Exception exc) { AppLogger.Dump(exc); } } }
protected void DispatchUpdate(Action <ITVStreamCallback> ClientUpdateMethod) { try { if (State == ServerGraphState.Running) { lock (_clientsCollectionLock) { foreach (IndigoServices.CommonStreamService client in this.Clients) { IndigoServices.TVStreamService tvClient = client as IndigoServices.TVStreamService; if (tvClient != null) { if (tvClient.ClientCallback != null) { try { ClientUpdateMethod(tvClient.ClientCallback); } catch (Exception ex) { AppLogger.Dump(ex); } } } } } } } catch (Exception exc) { AppLogger.Dump(exc); } }
protected override void OnStart(string[] args) { try { AppLogger.ShowAssembly = false; AppLogger.ShowClass = false; AppLogger.ShowDate = false; AppLogger.ShowMethod = false; AppLogger.Message(DateTime.Now.ToString() + " " + Assembly.GetAssembly(typeof(MediaServer)).ToString()); AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); if (ServiceMode) { //this.RequestAdditionalTime(60000); } SetupNativeEnvironment(); // QueryOriginServers.StartBackgroundThread(); IndigoServices.Host.StartServices(); GraphManager.ShutdownInProgress = false; GraphManager.StartPushGraphs(); // _rtspServer = RTSP.RTSPServer.LoadFromFile(); // if (_rtspServer != null) // { // _rtspServer.Start(); // } NetworkChange.NetworkAddressChanged += new NetworkAddressChangedEventHandler(NetworkChange_NetworkAddressChanged); NetworkChange.NetworkAvailabilityChanged += new NetworkAvailabilityChangedEventHandler(NetworkChange_NetworkAvailabilityChanged); AppLogger.Message("MediaServer is READY"); } catch (Exception exc) { AppLogger.Dump(exc); } }
/// <summary> /// fetches the persisted microwave presests /// </summary> private void LoadSavedPresets() { XmlTextReader file = null; try { if (!File.Exists(FrequencyPresetsFilename)) { throw new FileNotFoundException("Presets file \"" + FrequencyPresetsFilename + "\" does not exist!"); } XmlSerializer xmlSerializer = new XmlSerializer(typeof(UserPresetStore)); file = new XmlTextReader(FrequencyPresetsFilename); frequencyPresets = (UserPresetStore)xmlSerializer.Deserialize(file); } catch (Exception exc) { AppLogger.Dump(exc); frequencyPresets = new UserPresetStore(); } finally { if (file != null) { file.Close(); } } }
/// <summary> /// persists the microwave presets /// </summary> private void PersistPresets() { XmlTextWriter file = null; try { string dir = Path.GetDirectoryName(FrequencyPresetsFilename); Directory.CreateDirectory(dir); XmlSerializer xmlSerializer = new XmlSerializer(typeof(UserPresetStore)); file = new XmlTextWriter(FrequencyPresetsFilename, null); xmlSerializer.Serialize(file, frequencyPresets); } catch (Exception exc) { AppLogger.Dump(exc); } finally { if (file != null) { file.Close(); } } }
public List <Channel> GetVirtualChannels() { if (State != ServerGraphState.Running) { throw new InvalidOperationException("Graph must be running to retreive Virtual Channel Table"); } List <Channel> items = new List <Channel>(); try { VirtualChannelTable vct = _vctParser.GetVirtualChannelTable(); foreach (VirtualChannelTable.Entry e in vct.Items) { if ((e.ServiceType == VCTServiceTypes.ATSCDigitalTelevision) || (e.ServiceType == VCTServiceTypes.ATSCAudio)) { items.Add(e.ToChannel()); } } return(items); } catch (Exception ex) { AppLogger.Dump(ex); return(items); } }
private void _eventTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { try { _eventTimer.Enabled = false; IMediaEventEx mediaEvent = _graphBuilder as IMediaEventEx; if (mediaEvent == null) { AppLogger.Message("couldn't get IMediaEventEx from graph builder!"); return; } EventCode eventCode; IntPtr lparam1, lparam2; while (mediaEvent.GetEvent(out eventCode, out lparam1, out lparam2, 10) == 0) { AppLogger.Message("ASFNetSink -- Got Media Event: " + eventCode.ToString() + " 0x" + lparam1.ToString("X") + " 0x" + lparam2.ToString("X")); OnDirectShowEvent(eventCode, lparam1, lparam2); mediaEvent.FreeEventParams(eventCode, lparam1, lparam2); } _eventTimer.Enabled = true; } catch (Exception ex) { AppLogger.Message("ASFNetSink -- Can't get Media Event due to an error"); AppLogger.Dump(ex); } }
/// <summary> /// Loads StreamSources from a specified file. /// </summary> /// <param name="fileName">The filename to load. If you are trying to load multiple distinct files, set bypassCache to true.</param> /// Set to true to always read from the disk and return a distinct copy /// Set to false to use the cached copy if available. /// </param> /// <returns>the RTSPServer from the indicated file</returns> public static RTSPServer LoadFromFile(string fileName) { RTSPServer result = null; FileStream file = null; try { XmlSerializer xmlSerializer = new XmlSerializer(typeof(RTSPServer)); file = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read); result = (RTSPServer)xmlSerializer.Deserialize(file); } catch (Exception e) { AppLogger.Message(String.Format("RTSPServer was not loaded -- the configuration file {0} could not be loaded", PersistFileName)); AppLogger.Dump(e); } finally { if (file != null) { file.Close(); file.Dispose(); } } return(result); }
public void Dispose() { AppLogger.Message("MicrowaveControlService2.Dispose"); if (scanner != null) { scanner.ScanCompleted -= new EventHandler <ScanCompleteEvent>(scanner_ScanCompleted); scanner.CancelScan(); scanner = null; } if (microwaveReceiver != null) { microwaveReceiver.StopPollingLinkQuality(); microwaveReceiver.Dispose(); microwaveReceiver = null; } if (resourceAcquired) { try { ResourceManager.Release(clientRequest.SourceName, typeof(MicrowaveControlService), clientRequest.UserName); } catch (Exception ex) { AppLogger.Dump(ex); } } if (frequencyPresets != null) { PersistPresets(); } }
private void FireChannelScanCompleted(ChannelScanCompleteEventArgs args) { try { clientCallback.ChannelScanComplete(args); } catch (Exception ex) { AppLogger.Dump(ex); } }
private void FireChannelScanProgressUpdate(int progress) { try { clientCallback.ChannelScanProgressUpdate(progress); } catch (Exception ex) { AppLogger.Dump(ex); } }
private void FirePresetsChanged() { try { clientCallback.SavedPresetsChanged(this.frequencyPresets); } catch (Exception ex) { AppLogger.Dump(ex); } }
private void FireLinkQualityChanged(MicrowaveLinkQuality linkQuality) { try { AppLogger.Message(" MicrowaveControlService2.FireLinkQualityChanged"); clientCallback.LinkQualityChanged(linkQuality); } catch (Exception ex) { AppLogger.Dump(ex); } }
private void FireTuningChanged(MicrowaveTuning tuning) { try { AppLogger.Message(" MicrowaveControlService2.FireTuningChanged"); clientCallback.TuningChanged(tuning); } catch (Exception ex) { AppLogger.Dump(ex); } }
private void FireCapabilitiesChanged(MicrowaveCapabilities capabilities) { try { AppLogger.Message(" MicrowaveControlService2.FireCapabilitiesChanged"); clientCallback.CapabilitiesChanged(capabilities); } catch (Exception ex) { AppLogger.Dump(ex); } }
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { if (e.ExceptionObject is Exception) { AppLogger.Dump(e.ExceptionObject as Exception); ErrorLogger.DumpToEventLog(e.ExceptionObject as Exception); } if (e.IsTerminating) { IndigoServices.Host.StopServices(); } }
private void FireFrequencyChanged(int freq) { try { AppLogger.Message(" FireFrequencyChanged " + freq); clientCallback.FrequencyChanged(freq); } catch (Exception ex) { AppLogger.Dump(ex); } }
/// <summary> /// Tunes the microwave receiver to the specified frequency /// </summary> /// <param name="freq">the frequency, in MHz</param> public void SetTuning(MicrowaveTuning tuning) { try { AppLogger.Message("MCS2.SetTuning"); microwaveReceiver.SetTuning(tuning); } catch (Exception ex) { AppLogger.Dump(ex); this.FireTuningChanged(null); } }
/// <summary> /// Saves the KnownChannels collection to disk /// </summary> protected void SaveKnownChannels() { try { string file = GetKnownChannelsStoreFilename(); Directory.CreateDirectory(Path.GetDirectoryName(file)); this.KnownChannels.SaveToFile(file); } catch (Exception ex) { AppLogger.Dump(ex); } }
/// <summary> /// Opens the microwave control service /// </summary> /// <param name="sourceName">source name to open</param> public void Open(ClientConnectRequest request) { try { this.clientRequest = request; AppLogger.Message(request.UserName + " MicrowaveControlService.Open " + request.SourceName); if (!ResourceManager.Acquire <ResourceManager.MutexRule>(request.SourceName, typeof(MicrowaveControlService), request.UserName)) { string owner = ResourceManager.GetOwner(request.SourceName, typeof(MicrowaveControlService)); throw new SourceHasMaxClientsException("The microwave receiver is in use by " + ((owner == null) ? "<unknown>" : owner) + "."); } resourceAcquired = true; StreamSourceInfo sourceConfig = StreamSources.LoadFromFile().FindSource(request.SourceName); if (sourceConfig.MicrowaveControl == null) { throw new SourceConfigException("Source does not have MicrowaveControl section defined!"); } microwaveConfig = sourceConfig.MicrowaveControl; //get client callback clientCallback = OperationContext.Current.GetCallbackChannel <IMicrowaveControl2Callback>(); //create microwave receiver instance microwaveReceiver = MicrowaveControlService2.CreateInstance(microwaveConfig); if (!microwaveReceiver.Connected) { throw new SourceConfigException("Communication with the microwave receiver could not be established."); } microwaveReceiver.ReceiverTuningChange += new EventHandler <MicrowaveReceiver.ReceiverEventArgs>(microwaveReceiver_ReceiverTuningChange); microwaveReceiver.ReceiverLinkQualityChange += new EventHandler <MicrowaveReceiver.ReceiverEventArgs>(microwaveReceiver_ReceiverLinkQualityChange); microwaveReceiver.ReceiverConnectionChange += new EventHandler(microwaveReceiver_ReceiverConnectionChange); scanner = new PeakScan(microwaveReceiver); scanner.ScanCompleted += new EventHandler <ScanCompleteEvent>(scanner_ScanCompleted); //load cached presets LoadSavedPresets(); microwaveReceiver.StartPollingLinkQuality(); } catch (Exception exc) { AppLogger.Dump(exc); throw; } }
public virtual SessionDescription SetProfile(Profile newProfile) { AppLogger.Message("CommonStreamService.SetProfile " + newProfile.Name); #if USE_GLOBAL_GRAPHSERVICELOCK lock (_graphServiceLock) { #endif if (_graph != null) { try { if (newProfile.Name.ToLowerInvariant().Contains("custom")) { CurrentProfile = newProfile; } else { CurrentProfile = _graph.FindProfile(newProfile.Name); } if (CurrentProfile != null) { _graph.ChangeProfile(CurrentProfile); } return(null); } catch (ServerGraphRebuildException exc) { AppLogger.Dump(exc); AppLogger.Message("CommonStreamService.SetProfile() caught ServerGraphRebuildException--opening a new graph"); _graph.Stop(); _graph.State = ServerGraphState.Aborted; _graph.RemoveClient(this); // Save newProfile in the dictionary GraphManager.RemoveAndDisposeGraph(_graph); this.OpenGraphRequest.Profile = CurrentProfile; _graph = OpenGraph(); _graph.AddClient(this); SessionDescription sd = _graph.FillOutSessionDescription(this.OpenGraphRequest); return(sd); } } else { throw new ServiceHasNoGraphException(); } #if USE_GLOBAL_GRAPHSERVICELOCK } #endif }
private void FireSignalStrengthChanged(int strength) { try { if (strength < 0) { strength = 0; } clientCallback.SignalStrengthChanged(strength); } catch (Exception ex) { AppLogger.Dump(ex); } }
/// <summary> /// Tunes the microwave receiver to the specified frequency /// </summary> /// <param name="freq">the frequency, in MHz</param> public void SetFrequency(int freq) { try { microwaveReceiver.SetTuning(new MicrowaveTuning() { FrequencyMHz = (UInt64)freq }); } catch (Exception ex) { AppLogger.Dump(ex); this.FireFrequencyChanged(-1); } }
public void DeleteAllPresets() { lock (_userLock) { try { AppLogger.Message("MicrowaveControlService2.DeleteAllPresets"); frequencyPresets.Clear(); } catch (Exception exc) { AppLogger.Dump(exc); } } }