void ReserveURLForPort() { URLReserver reserver = new URLReserver(); int ResultCode = reserver.ReserveUrl(Convert.ToInt32(Settings.Default.RPPort), "/", true); if (ResultCode == 0) { Functions.WriteLineToLogFile("URLReserver: 0 OK"); Settings.Default.LastSetSecurityForPort = Convert.ToInt32(Settings.Default.RPPort); } else { Functions.WriteLineToLogFile("URLReserver: NOT OK"); RPMessageBox.ShowAlert("Could not reserve a Url for Remote Potato server - error code " + ResultCode.ToString()); } }
public static void WriteCacheInfoToLog() { Functions.WriteLineToLogFile("Displaying Cache...."); Functions.WriteLineToLogFile("Text Files:"); foreach (string txtFN in CachedTextFiles.Keys) { Functions.WriteLineToLogFile(txtFN); } Functions.WriteLineToLogFile("Binary Files:"); foreach (string txtFN in CachedBinaryFiles.Keys) { Functions.WriteLineToLogFile(txtFN); } Functions.WriteLineToLogFile("Cache display done."); }
public static List <TVService> ChannelListFromString(string txtChannelList) { List <TVService> theChannels = new List <TVService>(); try { XmlSerializer serializer = new XmlSerializer(theChannels.GetType()); StringReader sr = new StringReader(txtChannelList); theChannels = (List <TVService>)serializer.Deserialize(sr); } catch (Exception e) { Functions.WriteLineToLogFile("Error de-serialising channel list:"); Functions.WriteExceptionToLogFile(e); } return(theChannels); }
public void Initialize() { Monitor.Enter(initLock); if (IsInitialized) { Functions.WriteLineToLogFile("ErrorHandler: Bailing out of Init, already initialized."); return; } // Hook up error handling events for static classes RecTV.Default.DebugReport += new EventHandler <DebugReportEventArgs>(RecTV_DebugReport); EPGManager.EPGDebugReport += new EventHandler <DebugReportEventArgs>(Object_DebugReport); Functions.WriteLineToLogFile("ErrorHandler: Initialised."); IsInitialized = true; Monitor.Exit(initLock); }
public static string EncodeToBase64(string strToEncode, Encoding _encoding) { string returnValue = ""; try { byte[] encodedData = _encoding.GetBytes(strToEncode); returnValue = Convert.ToBase64String(encodedData); } catch (Exception ex) { Functions.WriteLineToLogFile("Couldn't encode base64 string " + strToEncode); Functions.WriteExceptionToLogFile(ex); } return(returnValue); }
internal bool UnInitialize() { Monitor.Enter(uninitLock); // DNS CLIENT if (Settings.Default.DynDNSClientEnabled) { Functions.WriteLineToLogFile("Init: UnInitializing Dynamic DNS Client..."); DNSHelper.Default.Stop(); Functions.WriteLineToLogFile("Init: UnInitialized Dynamic DNS Client..."); } IsInitialized = false; Monitor.Exit(uninitLock); return(false); }
public void DeleteAllBackgroundTranscodedStreamingFiles() { try { Directory.Delete(Functions.BackgroundStreamBaseFolder, true); string rppath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "remotepotato"); string MSRFile = Path.Combine(rppath, "settings\\transcodedmsr.xml"); File.Delete(MSRFile); } catch (Exception e) { if (Settings.Default.DebugStreaming) { Functions.WriteLineToLogFile("StreamingManager: " + e.ToString()); } } }
public static int DurationMinutes(this CommonEPG.TVProgramme tvp) { try { long lDuration = tvp.StopTime - tvp.StartTime; TimeSpan tDuration = new TimeSpan(lDuration); return(Convert.ToInt32(tDuration.TotalMinutes)); } catch { if (Settings.Default.DebugAdvanced) { Functions.WriteLineToLogFile("Error [extension method error DurationMinutes] - could not get duration for show " + tvp.Title + " starts:" + tvp.StartTime.ToString() + " stops:" + tvp.StopTime.ToString()); } } return(0); }
public int IdsAndInputFilesContains(string InputFile) { int uit = 0; if (Settings.Default.DebugStreaming) { Functions.WriteLineToLogFile("StreamingManager: " + "select STREAMID from IDANDINPUTFILE where INPUTFILE='" + InputFile + "';"); } //var command = new SqlCommand("select STREAMID from IDANDINPUTFILE where INPUTFILE = @inputfile;"); //SqlParameter param = new SqlParameter(); //param.ParameterName = "@inputfile"; //param.Value = InputFile; //command.Parameters.Add(param); InputFile = InputFile.Replace("'", "''"); // escape single quotes Int32.TryParse(db.ExecuteScalar(String.Format("select STREAMID from IDANDINPUTFILE where INPUTFILE = '{0}';", InputFile)), out uit); return(uit); }
public static List <string> StringListFromXML(string theXML) { List <string> output = new List <string>(); XmlSerializer serializer = new XmlSerializer(output.GetType()); StringReader sr = new StringReader(theXML); try { return((List <string>)serializer.Deserialize(sr)); } catch (Exception ex) { Functions.WriteLineToLogFile("Could not deserialise list of strings."); Functions.WriteExceptionToLogFile(ex); } return(output); }
public static string DecodeFromBase64(string encodedData, Encoding _encoding) { string returnValue = ""; try { byte[] encodedDataAsBytes = Convert.FromBase64String(encodedData); returnValue = _encoding.GetString(encodedDataAsBytes); } catch (Exception ex) { Functions.WriteLineToLogFile("Couldn't decode base64 string " + encodedData); Functions.WriteExceptionToLogFile(ex); } return(returnValue); }
public static bool WriteTextFileToDisk(string filePath, string txtContent) { filePath = ConvertRelativePathToAbsolute(filePath); try { TextWriter tw = new StreamWriter(filePath); tw.Write(txtContent); tw.Close(); return(true); } catch (Exception e) { Functions.WriteLineToLogFile("Could not write file " + filePath + " to disk:"); Functions.WriteExceptionToLogFile(e); return(false); } }
static bool StartorStopRemotePotatoService(bool start) { // Services bool isRunning; ServiceController svcRP = null; try { svcRP = new ServiceController("Remote Potato Service"); isRunning = (svcRP.Status == ServiceControllerStatus.Running); if (start) { if (!isRunning) { svcRP.Start(); svcRP.WaitForStatus(ServiceControllerStatus.Running, TimeSpan.FromSeconds(10)); return(svcRP.Status == ServiceControllerStatus.Running); // return false if didn't start } } else { if (isRunning) { svcRP.Stop(); svcRP.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromSeconds(10)); return(svcRP.Status == ServiceControllerStatus.Stopped); // return false if didn't stop } } } catch (Exception ex) { Functions.WriteLineToLogFile("Service: Could not start or stop service:"); Functions.WriteExceptionToLogFile(ex); return(false); } finally { svcRP = null; } return(false); }
public static void GetThemeNamesFromFolderStructure() { ThemeNames.Clear(); MobileThemeNames.Clear(); DirectoryInfo themeFolder = new DirectoryInfo(Functions.SkinFolder); if (!themeFolder.Exists) { Functions.WriteLineToLogFile("Themes Folder does not exist: " + Functions.SkinFolder); return; } foreach (DirectoryInfo di in themeFolder.GetDirectories()) { ThemeNames.Add(CultureInfo.CurrentCulture.TextInfo.ToTitleCase(di.Name)); MobileThemeNames.Add(CultureInfo.CurrentCulture.TextInfo.ToTitleCase(di.Name)); } }
public int ReserveUrl(int port, string path, bool addSecurity) { Port = port; AddingSecurity = addSecurity; string action = AddingSecurity ? "set" : "removed"; string result = ""; if (!ChangeUrlReservation(Port, path, AddingSecurity, out result)) { string logEntry = "The required Url Reservation for port " + Port.ToString() + " has NOT been " + action + ":" + result; Functions.WriteLineToLogFile(logEntry); return(99); } Console.WriteLine("The required Url Reservation for port " + Port.ToString() + " has been " + action + " for the Remote Potato webserver."); Functions.WriteLineToLogFile("URLReserver: Url was " + action + " OK."); return(0); }
// IO public static string ReadTextFile(string filePath) { filePath = ConvertRelativePathToAbsolute(filePath); // Exception? FileInfo f = new FileInfo(filePath); if (!File.Exists(filePath)) { if (Settings.Default.DebugAdvanced) { Functions.WriteLineToLogFile("FileCache: Text File Not Found: " + filePath); } return(""); } string input = ReadTextFileFromDisk(filePath); return(input); }
public List <RPMusicGenre> GetAllGenres() { MusicHelper helper = new MusicHelper(); bool failed = false; string txtError = ""; List <RPMusicGenre> output = helper.RetrieveAllGenres(ref failed, ref txtError); if (failed) { Functions.WriteLineToLogFile("Failed to get genres from music library: " + txtError); } else { // Sort output A-Z CommonEPG.Comparers.RPMusicGenreTitleComparer myComparer = new CommonEPG.Comparers.RPMusicGenreTitleComparer(); output.Sort(myComparer); } return(output); }
/// <summary> /// Stop a streamer and remove it from the local list of streamers /// </summary> /// <param name="streamerID"></param> /// <returns></returns> public bool StopStreamer(int streamerID) { if (Settings.Default.DebugStreaming) { Functions.WriteLineToLogFile("DSStreamingManager: Received stop command for streamer " + streamerID.ToString()); } DSStreamer mediaStreamer = GetStreamerByID(streamerID); if (mediaStreamer == null) { return(false); } mediaStreamer.Cancel(); // Remove from streamers RemoveStreamer(mediaStreamer); return(true); }
public byte[] ThumbnailForWMPItemAsByte(string WMPMatchAttribute, string itemID, bool useFolderArtIfFound, Thumbnail_Sizes size, out string MimeType) { Bitmap bmp = ThumbnailForWMPItem(WMPMatchAttribute, itemID, useFolderArtIfFound, size, out MimeType); if (bmp == null) { return(null); } try { byte[] bytes = (byte[])TypeDescriptor.GetConverter(bmp).ConvertTo(bmp, typeof(byte[])); return(bytes); } catch (Exception ex) { Functions.WriteLineToLogFile("Exception converting WMP item thumbnail to bytes:"); Functions.WriteExceptionToLogFile(ex); } return(null); }
public void Start() { if (!Settings.Default.DynDNSClientEnabled) { if (Settings.Default.DebugAdvanced) { Functions.WriteLineToLogFile("DNSHelper: Not starting, not enabled."); } return; } Functions.WriteLineToLogFile("DNSHelper: Starting Dynamic DNS Client"); if (tmCheckDNS != null) { StopAndRemoveTimer(); } CreateAndStartTimer(); IsRunning = true; }
public string FileNameForWMPItem(string itemTrackingID) { WindowsMediaPlayer WMPlayer = new WindowsMediaPlayer(); IWMPPlaylist pl = WMPlayer.mediaCollection.getByAttribute("TrackingID", itemTrackingID); if (pl.count == 0) { Functions.WriteLineToLogFile("Warning - no item found in library with ID " + itemTrackingID); return(null); } if (pl.count != 1) { Functions.WriteLineToLogFile("Warning - more than one item found in library with ID " + itemTrackingID); } IWMPMedia mItem = pl.get_Item(0); WMPlayer.close(); return(mItem.sourceURL); }
void RemoveStreamer(DSStreamer ms) { if (ms != null) { CleanupDSStreamerFiles(ms); mediaStreamers.Remove(ms.ID); try { ms.Dispose(); ms = null; } catch (Exception ex) { Functions.WriteLineToLogFile("Couldn't dispose DSStreamer:"); Functions.WriteExceptionToLogFile(ex); } } // Power options SetPowerOptions(); }
public static bool CreateZipFileFromFiles(List<string> inputFiles, string outputFile) { try { using (ZipFile zip = new ZipFile()) { zip.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression; zip.FlattenFoldersOnExtract = true; zip.AddFiles(inputFiles, false, ""); zip.Save(outputFile); } } catch (Exception ex) { Functions.WriteLineToLogFile("Could not create zip file."); Functions.WriteExceptionToLogFile(ex); return false; } return true; }
public static string ReadTextFileFromDisk(string filePath) { filePath = ConvertRelativePathToAbsolute(filePath); string input; try { StreamReader sr; sr = File.OpenText(filePath); input = sr.ReadToEnd(); sr.Close(); return(input); } catch (Exception e) { Functions.WriteLineToLogFile("Could not read file " + filePath + " from disk:"); Functions.WriteExceptionToLogFile(e); } return(""); }
void CleanupDSStreamerFiles(DSStreamer ms) { if (string.IsNullOrEmpty(ms.StreamingRequest.FileName)) { return; } // Cleanup file string fileName = ms.StreamingRequest.FileName + ".wmv"; if (File.Exists(fileName)) { if (Settings.Default.DebugAdvanced) { Functions.WriteLineToLogFile("Cleaning up old streaming file " + fileName); } try { File.Delete(fileName); } catch { } } }
void SetPowerOptions() { if (Settings.Default.DebugStreaming) { Functions.WriteLineToLogFile("StreamingManager: nr of mediastreamers=" + mediaStreamers.Count); } if (mediaStreamers.Count > 0) { if (Settings.Default.DebugStreaming) { Functions.WriteLineToLogFile("StreamingManager: so preventing standby"); } PowerHelper.PreventStandby(); } else { if (Settings.Default.DebugStreaming) { Functions.WriteLineToLogFile("StreamingManager: so allowing standby"); } PowerHelper.AllowStandby(); } }
// Filters public static List <RPRecording> AllRecordingsOnDate(DateTime localDate) { List <RPRecording> output = new List <RPRecording>(); foreach (RPRecording rec in AllRecordings.Values) { TVProgramme tvp = rec.TVProgramme(); if (tvp == null) { Functions.WriteLineToLogFile("Could not find a TV Programme for the recording: " + rec.Title); continue; } if (rec.TVProgramme().StartTimeDT().ToLocalTime().Date == localDate.Date) { output.Add(rec); } } // Sort by start time ascending output.Sort(new RPRecordingStartTimeComparer()); return(output); }
public static bool ResizePicture(string inputFilename, Size size, out byte[] outputData, ImageFormat format, bool allowGrowth) { outputData = new byte[] { }; try { Image imgLogo = Image.FromFile(inputFilename); Image imgLogoResized = resizeImage(imgLogo, size, allowGrowth); outputData = ImageToByteArray(imgLogoResized, format); return(true); } catch (FileNotFoundException) { Functions.WriteLineToLogFile("Error resizing image " + inputFilename + ": File Not Found"); return(false); } catch (Exception ex) { Functions.WriteLineToLogFile("Error resizing image " + inputFilename + ":"); Functions.WriteExceptionToLogFile(ex); return(false); } }
// ProcessHttpRequest is the async handler for new http requests // This function should do what it needs to do and then exit public static void ProcessHttpRequest(IAsyncResult result) { RequestProcessor rp = null; try // (IAsyncResult)result will be invalid if we've killed the listener { HttpListener listener = (HttpListener)result.AsyncState; HttpListenerContext context = listener.EndGetContext(result); // Call EndGetContext to complete the asynchronous operation. // Obtain a response object. HttpListenerResponse response = context.Response; // Create a new request processor rp = new RequestProcessor(context); rp.Run(); } catch (System.ObjectDisposedException) { // Do nothing } catch (Exception ex) { Functions.WriteLineToLogFile("Process HttpRequest Exception:"); Functions.WriteExceptionToLogFile(ex); } finally { if (rp != null) { rp.Dispose(); rp = null; } } }
public static byte[] ZipStringToBytes(string inString) { if (string.IsNullOrEmpty(inString)) return null; try { if (Settings.Default.DebugServer) Functions.WriteLineToLogFile("Zipping up string of length " + inString.Length + ". Begins:" + inString.Substring(0, 5) + "|Ends:" + inString.Substring(inString.Length - 5)); // Place string contents into byte array buffer[] byte[] buffer = Encoding.Unicode.GetBytes(inString); // buffer => memorystream MemoryStream ms = new MemoryStream(); using (Ionic.Zlib.ZlibStream Zip = new Ionic.Zlib.ZlibStream(ms, Ionic.Zlib.CompressionMode.Compress, Ionic.Zlib.CompressionLevel.BestCompression, true)) { Zip.Write(buffer, 0, buffer.Length); } // Read from memorystream => byte array compressed[] byte[] compressed = new byte[ms.Length - 1]; ms.Position = 0; MemoryStream outStream = new MemoryStream(); ms.Read(compressed, 0, compressed.Length); ms.Close(); return compressed; } catch (Exception ex) { Functions.WriteLineToLogFile("ZipHelper: Error zipping string:"); Functions.WriteExceptionToLogFile(ex); } return null; }