예제 #1
0
        public static int GetDaysOld(string filePath)
        {
            try
            {
                if (!File.Exists(filePath))
                {
                    return(0);
                }

                var fileCreation = File.GetCreationTime(filePath);
                var now          = DateTime.Now;
                var days         = (int)(now - fileCreation).TotalDays +
                                   1; //adding one ensures if it was created on the same day it counts as one day passed

                LoggingHelpers.RecordCacheEvent($"Requested XML record is {days} day(s) old", $"file://{filePath}");

                return(days);
                //default value
            }
            catch (Exception ex)
            {
                LoggingHelpers.RecordException(ex.Message, "CacheAgeChkError");
                return(0);
            }
        }
예제 #2
0
        public static bool XmlToCache(XmlDocument doc, string sourceUrl)
        {
            try
            {
                if (ObjectProvider.Settings.CacheSettings.Mode.EnableXmlCaching)
                {
                    if (!XmlInCache(sourceUrl))
                    {
                        var fqPath = XmlCachePath(sourceUrl);
                        doc.Save(fqPath);
                        LoggingHelpers.RecordCacheEvent("Successfully cached URL", sourceUrl);
                    }
                    else
                    {
                        LoggingHelpers.RecordCacheEvent("URL is already cached", sourceUrl);
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                LoggingHelpers.RecordException(ex.Message, "XmlCacheWrtError");
                LoggingHelpers.RecordCacheEvent("Couldn't create cached file (an error occurred)", sourceUrl);
                return(false);
            }
        }
예제 #3
0
        /// <summary>
        /// Attempts to load PlexDL's '.default' file and apply the settings contained within
        /// </summary>
        public static void TryLoadDefaultSettings()
        {
            try
            {
                //check if default settings have been created
                if (DefaultSettingsManager.SettingsExist)
                {
                    //try and load it with no messages
                    var defaultProfile = DefaultSettingsManager.LoadDefaultSettings();

                    //if it isn't null, then assign it to the global settings
                    if (defaultProfile != null)
                    {
                        ObjectProvider.Settings = defaultProfile;
                    }
                }
                else
                {
                    //create the file with no messages
                    new ApplicationOptions().CommitDefaultSettings();
                }
            }
            catch (Exception ex)
            {
                //log and ignore the error
                LoggingHelpers.RecordException(ex.Message, @"LoadDefaultProfileError");
            }
        }
예제 #4
0
        private static void DoDataBind(DataGridView target, DataTable bindData, GenericRenderStruct info)
        {
            try
            {
                //check if the DataGridView needs to be invoked first
                if (target.InvokeRequired)
                {
                    //invoke the DataGridView so we don't thread-lock
                    target.BeginInvoke((MethodInvoker) delegate { DoDataBind(target, bindData, info); });
                }
                else
                {
                    //we don't need to invoke, so just continue without it.
                    //bind the data to the grid ("render" the data)
                    target.DataSource = bindData;

                    //set the captions
                    Methods.SetHeaderText(target, info.Data);

                    //re-render the control
                    target.Refresh();
                }
            }
            catch (Exception ex)
            {
                //log and do nothing
                LoggingHelpers.RecordException(ex.Message, @"GenericViewRendererBindError");
            }
        }
예제 #5
0
        public static string GetContentAttribute(XmlDocument metadata, string tableName, string attributeName,
                                                 string defaultValue = @"Unknown")
        {
            var attributeValue = defaultValue;

            try
            {
                var sections = new DataSet();
                sections.ReadXml(new XmlNodeReader(metadata));

                DataTable data = null;

                //check if the table we want is actually present
                if (sections.Tables.Contains(tableName))
                {
                    data = sections.Tables[tableName];
                }

                attributeValue = GetContentAttribute(data, attributeName, defaultValue);
            }
            catch (Exception ex)
            {
                LoggingHelpers.RecordException(ex.Message, "GetAttrError");
            }

            return(attributeValue);
        }
예제 #6
0
파일: Cast.cs 프로젝트: mitchscobell/PlexDL
        private async void BtnPlayPause_Click(object sender, EventArgs e)
        {
            try
            {
                if (PlayState)
                {
                    //send pause command
                    await Controller.Pause();

                    //set UI
                    btnPlayPause.Text = @"Play";

                    //set flag
                    PlayState = false;
                }
                else
                {
                    //send play command
                    await Controller.Play();

                    //set UI
                    btnPlayPause.Text = @"Pause";

                    //set flag
                    PlayState = true;
                }
            }
            catch (Exception ex)
            {
                LoggingHelpers.RecordException(ex.Message, @"CastPlayStateError");
                UIMessages.Error($"An error occurred whilst trying to play/pause your media:\n\n{ex}");
            }
        }
예제 #7
0
        public static Bitmap GetImageFromUrl(string url, bool forceNoCache = false)
        {
            try
            {
                CachingHelpers.CacheStructureBuilder();
                if (string.IsNullOrEmpty(url))
                {
                    return(Resources.unavailable);
                }

                if (!forceNoCache)
                {
                    if (ThumbCaching.ThumbInCache(url))
                    {
                        return(ThumbCaching.ThumbFromCache(url));
                    }
                }
            }
            catch (UnauthorizedAccessException ex)
            {
                LoggingHelpers.RecordException(ex.Message, "ThumbIOAccessError");
            }
            catch (Exception ex)
            {
                LoggingHelpers.RecordException(ex.Message, "ImageFetchError");
                return(Resources.unavailable);
            }

            return(ForceImageFromUrl(url));
        }
예제 #8
0
        public static string GetSectionKey(XmlDocument doc)
        {
            var key = "";

            LoggingHelpers.RecordGeneralEntry("Parsing XML Reply");
            using (XmlReader reader = new XmlNodeReader(doc))
            {
                while (reader.Read())
                {
                    if (reader.IsStartElement())
                    {
                        LoggingHelpers.RecordGeneralEntry("Checking for directories");

                        switch (reader.Name)
                        {
                        case "Directory":
                            if (reader.GetAttribute("title") == "Library Sections")
                            {
                                var localKey = reader.GetAttribute("key");
                                key = localKey;
                                LoggingHelpers.RecordGeneralEntry("Found " + key);
                            }

                            break;
                        }
                    }
                }

                return(key);
            }
        }
예제 #9
0
        /// <summary>
        /// This method ensures the directory structure required is created and ready for use
        /// </summary>
        public static void CacheStructureBuilder()
        {
            //root caching directory for the current user
            var rootUserDir = $@"{CachingFileDir.RootCacheDirectory}\" +
                              $@"{MD5Helper.CalculateMd5Hash(ObjectProvider.Settings.ConnectionInfo.PlexAccountToken)}\" +
                              $@"{MD5Helper.CalculateMd5Hash(ObjectProvider.Settings.ConnectionInfo.PlexAddress)}";

            //root directory where all images are stored
            var thumbDir = $@"{rootUserDir}\{CachingFileDir.ThumbRelativeDirectory}";

            //root directory where all XML files are stored
            var xmlDir = $@"{rootUserDir}\{CachingFileDir.XmlRelativeDirectory}";

            try
            {
                //ensure the images directory has been created
                if (!Directory.Exists(thumbDir))
                {
                    Directory.CreateDirectory(thumbDir);
                }

                //ensure the XML directory has been created
                if (!Directory.Exists(xmlDir))
                {
                    Directory.CreateDirectory(xmlDir);
                }
            }
            catch (Exception ex)
            {
                //log the error and exit
                LoggingHelpers.RecordException(ex.Message, "CacheDirBuildError");
            }
        }
예제 #10
0
        public static void SetRawTable(this DataSet data, DataTable RawData)
        {
            try
            {
                //if the dataset is null, then initialise it
                if (data == null)
                {
                    data = new DataSet(@"AutoFill");
                }

                //remove it if it already exists
                if (data.Tables.Contains(@"RawData"))
                {
                    data.Tables.Remove(@"RawData");
                }

                //copy the structure to avoid inheritance problems
                var toAdd = RawData.Copy();

                //table name fix
                toAdd.TableName = @"RawData";
                toAdd.Namespace = @"DataProvider";

                //commit the new table to the DataSet
                data.Tables.Add(toAdd);
            }
            catch (Exception ex)
            {
                LoggingHelpers.RecordException(ex.Message, @"SetRawDataError");
            }
        }
예제 #11
0
        private void BtnCopy_Click(object sender, EventArgs e)
        {
            try
            {
                //update the button text
                btnCopy.Text = @"Copied!";

                //change the state for the timer
                CopyState = true;

                //save it to the clipboard, but only if the link is valid
                //i.e. not whitespace/null
                if (!string.IsNullOrWhiteSpace(Link))
                {
                    Clipboard.SetText(Link);
                }

                //restart the text change timer
                tmrBtnTxtUpdate.Stop();
                tmrBtnTxtUpdate.Start();
            }
            catch (Exception ex)
            {
                //log the error and then ignore it
                LoggingHelpers.RecordException(ex.Message, @"LinkCopyError");
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void MakoLogger__onProgressUpdate(object sender, ProgressChangedEventArgs e)
        {
            //
            _listLog.Add((string)e.UserState);

            //
            LoggingHelpers.InsertIntoLog(_logRunTy, CompanySettingsForId, ConnectString, _logCompanyId, _logQueueId, (string)e.UserState);

            //
            var message = new SocketMessage
            {
                CompanyId   = _logCompanyId,
                QueueId     = _logQueueId,
                PeriodType  = _logPeriodType,
                PeriodId    = _logPeriodId,
                Information = (string)e.UserState,
                IsRun       = _logPeriodType != 4,
                Percentage  = e.ProgressPercentage
            };

            // If the socket is not null, send a message.
            MakoSocket?.SendMessage(message);

            //
            Console.WriteLine((string)e.UserState);
        }
예제 #13
0
        public static PlexObject MetadataFromFile(string fileName, bool waitWindow = true, bool silent = false)
        {
            try
            {
                //there are two file-types: the legacy PMXML format and the new PXZ format
                var ext = Path.GetExtension(fileName);

                //decide which is which
                switch (ext)
                {
                case @".pxz":     //must be decompressed and processed first
                    return(MetadataFromFile(LoadMetadataArchive(fileName, waitWindow), waitWindow, silent));

                case @".pmxml":     //can be directly loaded and deserialised
                    var doc = new XmlDocument();
                    doc.LoadXml(File.ReadAllText(fileName));
                    return(FromXml(doc));

                default:
                    return(null);
                }
            }
            catch (Exception ex)
            {
                LoggingHelpers.RecordException(ex.Message, @"XmlMetadataLoadError");
            }

            //default
            return(null);
        }
예제 #14
0
        public static bool CheckCacheExpiry(string filePath, int interval)
        {
            try
            {
                if (File.Exists(filePath))
                {
                    var days = GetDaysOld(filePath);
                    //DEBUG ONLY
                    //UIMessages.Info(days.ToString());
                    var result     = days >= interval;
                    var logMessage = $"XML record {(result ? @"has" : @"has not")} expired [{days}/{interval}]";
                    LoggingHelpers.RecordCacheEvent(logMessage, $"file://{filePath}");
                    return(result);
                }

                LoggingHelpers.RecordException(@"Specified cache file doesn't exist", @"CacheExpiryChkError");
                //default is true; this signifies that it has expired, so PlexDL will try and get a new copy.
                return(true);
            }
            catch (Exception ex)
            {
                LoggingHelpers.RecordException(ex.Message, @"CacheExpiryChkError");
                //default is true; this signifies that it has expired, so PlexDL will try and get a new copy.
                return(true);
            }
        }
예제 #15
0
        private void SetInterfaceViewingStatus()
        {
            try
            {
                //check for nulls
                if (ObjectProvider.PlexServers != null && dgvServers.DataSource != null)
                {
                    //data length counters
                    var gridCount  = dgvServers.Rows.Count;
                    var totalCount = ObjectProvider.PlexServers.Count;

                    //the total can't exceed the current amount
                    lblViewingValue.Text = totalCount < gridCount
                        ? $@"{gridCount}/{totalCount}"
                        : $@"{totalCount}/{totalCount}";
                }
                else
                {
                    //set the viewing values to 0
                    lblViewingValue.Text = @"0/0";
                }
            }
            catch (Exception ex)
            {
                //log the error but don't inform the user
                LoggingHelpers.RecordException(ex.Message, @"ServerManagerViewingStatusError");
            }
        }
예제 #16
0
        private void BtnStartSearch_Click(object sender, EventArgs e)
        {
            try
            {
                if (!string.IsNullOrEmpty(txtSearchTerm.Text) &&
                    cbxSearchColumn.SelectedItem != null &&
                    cbxSearchRule.SelectedIndex >= 0)
                {
                    //the result is OK, close the form
                    DialogResult = DialogResult.OK;
                    Close();
                }
                else
                {
                    //alert the user to the validation error
                    UIMessages.Error(@"Please enter all required values or exit the search",
                                     @"Validation Error");
                }
            }
            catch (Exception ex)
            {
                //log the error
                LoggingHelpers.RecordException(ex.Message, @"SearchFormStartSearchError");

                //alert the user
                UIMessages.Error(ex.ToString());
            }
        }
예제 #17
0
파일: Cast.cs 프로젝트: mitchscobell/PlexDL
        private async Task StopApplication()
        {
            try
            {
                //set UI
                btnCast.Enabled      = false;
                btnCast.Text         = @"Stopping";
                btnDiscover.Enabled  = true;
                btnPlayPause.Enabled = false;
                btnPlayPause.Text    = @"Play";

                //kill the application
                await Controller.StopApplication();

                //disconnect
                if (Service.ConnectedChromecast != null)
                {
                    await Client.DisconnectChromecast();
                }

                //restore UI
                btnCast.Enabled = true;
                btnCast.Text    = @"Cast";

                //set flags
                ConnectState = false;
                PlayState    = false;
            }
            catch (Exception ex)
            {
                LoggingHelpers.RecordException(ex.Message, @"CastStopError");
            }
        }
예제 #18
0
        private static void DoCommitDefault()
        {
            try
            {
                //null validation
                if (ObjectProvider.Settings != null)
                {
                    //returns true if the commit operation succeeded
                    if (ObjectProvider.Settings.CommitDefaultSettings())
                    {
                        //alert user
                        UIMessages.Info(@"Successfully saved settings");
                    }
                    else
                    {
                        //alert user
                        UIMessages.Error(@"An unknown error occurred whilst saving settings");
                    }
                }
                else
                {
                    //alert user
                    UIMessages.Error(@"Couldn't export settings because they were null");
                }
            }
            catch (Exception ex)
            {
                //record error
                LoggingHelpers.RecordException(ex.Message, @"SaveDefaultError");

                //alert user
                UIMessages.Error($"Error exporting to default\n\n{ex}");
            }
        }
예제 #19
0
        public static string FpsFromPlexStd(string std, bool includeSuffix = true)
        {
            var fps = "29.97"; //default NTSC

            try
            {
                foreach (var s in PlexFramerates)
                {
                    if (!string.Equals(s[0], std))
                    {
                        continue;
                    }

                    fps = s[1];
                    break;
                }

                if (includeSuffix)
                {
                    fps = FullFpsSuffix(fps);
                }
            }
            catch (Exception ex)
            {
                LoggingHelpers.RecordException(ex.Message, "FpsFromStdError");
            }

            return(fps);
        }
예제 #20
0
        private void DoReset()
        {
            try
            {
                //query user
                if (UIMessages.Question(@"Are you sure? This will clear all settings in the current session."))
                {
                    //do the reset
                    ObjectProvider.Settings = new ApplicationOptions();

                    //refresh PropertyGrid on this form
                    settingsGrid.SelectedObject = ObjectProvider.Settings;
                    settingsGrid.Refresh();

                    //show alert
                    UIMessages.Info(@"Settings reset");
                }
            }
            catch (Exception ex)
            {
                //record error
                LoggingHelpers.RecordException(ex.Message, @"ResetSettingsError");

                //alert user
                UIMessages.Error($"Error while resetting\n\n{ex}");
            }
        }
예제 #21
0
        private void Cast_Load(object sender, EventArgs e)
        {
            try
            {
                //setup service events
                if (Service != null)
                {
                    Service.ChromeCastClient.ConnectedChanged += Client_Connected;
                }

                //setup form title
                lblTitle.Text = StreamingContent.StreamInformation.ContentTitle;

                //setup the poster
                picPoster.BackgroundImage = ImageHandler.GetPoster(StreamingContent);
            }
            catch (Exception ex)
            {
                //log the error
                LoggingHelpers.RecordException(ex.Message, @"CastUILoadError");

                //alert the user
                UIMessages.Error($"Error occurred during cast load:\n\n{ex}");
            }
        }
예제 #22
0
        private void DoCancel()
        {
            try
            {
                if (!AlreadyClosing && !ChangesApplied)
                {
                    //revert changes by assigning the snapshot taken at the start to the main setting
                    //provider.
                    ObjectProvider.Settings = Snapshot;

                    //return of 'Cancel'
                    DialogResult = DialogResult.Cancel;

                    //disable further calls
                    AlreadyClosing = true;

                    //close the form
                    Close();
                }
            }
            catch (Exception ex)
            {
                //record error
                LoggingHelpers.RecordException(ex.Message, @"SettingsDialogCancelError");
            }
        }
예제 #23
0
        private void InitialSetup()
        {
            try
            {
                //metrics information must be valid to proceed
                if (Metrics != null)
                {
                    //caching data location
                    UpdateCachingDirectory();

                    //apply data
                    dgvMain.DataSource = GetMetrics();
                }
                else
                {
                    UIMessages.Warning(@"Metrics information was not configured on launch; data failed to load.");
                }
            }
            catch (Exception ex)
            {
                //log the error
                LoggingHelpers.RecordException(ex.Message, "CacheMetricsLoadError");

                //inform the user
                UIMessages.Error("There was an error whilst loading caching metrics:\n\n" + ex,
                                 @"Load Error");

                //exit the form
                Close();
            }
        }
예제 #24
0
        private void SetInterfaceCurrentLog(string currentLog)
        {
            try
            {
                //null check encompasses the validity
                var isValid = !string.IsNullOrWhiteSpace(currentLog);

                //just the file name (in-case we get given a path)
                var fileName = Path.GetFileName(currentLog);

                //set the fore colour dependent on status
                lblCurrentLogFileValue.ForeColor = isValid
                    ? Color.Black
                    : Color.DarkRed;

                //set text dependent on status
                lblCurrentLogFileValue.Text = isValid
                    ? fileName
                    : @"Not Loaded";
            }
            catch (Exception ex)
            {
                //log the error but don't inform the user
                LoggingHelpers.RecordException(ex.Message, @"LogViewerCurrentLogStatusError");
            }
        }
예제 #25
0
        public static string GetContentAttribute(DataTable tableObject, string attributeName,
                                                 string defaultValue = @"Unknown")
        {
            var attributeValue = defaultValue;

            try
            {
                //return the default value above if the data (table) is null
                if (tableObject == null)
                {
                    return(attributeValue);
                }

                //the first row is the only information we will need
                var row = tableObject.Rows[0];

                //first, check if the specified attribute exists in the row data
                if (row[attributeName] != null)
                {
                    if (!Equals(row[attributeName], string.Empty))
                    {
                        attributeValue = row[attributeName].ToString();
                    }
                }
            }
            catch (Exception ex)
            {
                LoggingHelpers.RecordException(ex.Message, "GetAttrError");
            }

            return(attributeValue);
        }
예제 #26
0
        private void DoLoad()
        {
            try
            {
                //validate queue
                if (QueueProvider != null)
                {
                    //go through each QueueElement
                }
                else
                {
                    //log the error
                    LoggingHelpers.RecordException(@"Null HTTP Queue provider", @"DownloadManagerLoadError");

                    //alert user
                    UIMessages.Warning(@"Null HTTP Queue provider was specified to the Download Manager; couldn't load the form correctly.");

                    //close the form
                    Close();
                }
            }
            catch (Exception ex)
            {
                //log the error
                LoggingHelpers.RecordException(ex.Message, @"DownloadManagerLoadError");

                //alert the user
                UIMessages.Error($"Error in download manager load:\n\n{ex}");

                //close the form
                Close();
            }
        }
예제 #27
0
        public static bool XmlRemoveCache(string sourceUrl)
        {
            try
            {
                //ensure we're allowed to perform caching operations on XML files
                if (ObjectProvider.Settings.CacheSettings.Mode.EnableXmlCaching)
                {
                    //ensure the URL requested is already cached
                    if (XmlInCache(sourceUrl))
                    {
                        //delete the cached XML file
                        File.Delete(XmlCachePath(sourceUrl));

                        //log event
                        LoggingHelpers.RecordCacheEvent("Removed URL from cache", sourceUrl);
                    }
                }

                //default
                return(true);
            }
            catch (Exception ex)
            {
                //log the error
                LoggingHelpers.RecordException(ex.Message, "XmlCacheDelError");
                LoggingHelpers.RecordCacheEvent("Couldn't remove existing cached file (an error occurred)", sourceUrl);

                //deletion didn't succeed
                return(false);
            }
        }
예제 #28
0
        private void BtnTranslate_Click(object sender, EventArgs e)
        {
            try
            {
                //are both LogDel file name storage locations valid?
                if (!string.IsNullOrWhiteSpace(txtLogdel.Text) && !string.IsNullOrWhiteSpace(ofdLogdel.FileName))
                {
                    //reset progress bar
                    pbMain.Maximum = TotalCount;
                    pbMain.Value   = 0;

                    //setup background worker event handlers
                    bwTranslate.RunWorkerCompleted += BwTranslate_RunWorkerCompleted;
                    bwTranslate.ProgressChanged    += BwTranslate_ProgressChanged;

                    //start processing in the background
                    bwTranslate.RunWorkerAsync();
                }
                else
                {
                    //alert the user
                    UIMessages.Error(@"Incorrect value(s)");
                }
            }
            catch (Exception ex)
            {
                //log the error
                LoggingHelpers.RecordException(ex.Message, @"TokenTranslatorProcessingError");

                //alert the user
                UIMessages.Error(ex.ToString());
            }
        }
예제 #29
0
        /// <summary>
        /// Attempts to run PlexDL in 'Open With' mode
        /// </summary>
        /// <param name="file"></param>
        /// <param name="appRun"></param>
        public static void OpenWith(string file, bool appRun = true)
        {
            //Windows has passed a file; we need to check what type it is
            var ext = Path.GetExtension(file);

            //check if it's a supported file-type
            if (CheckAgainstSupportedFiles(file))
            {
                //try the metadata import and then show it if successful
                try
                {
                    var metadata = MetadataIO.MetadataFromFile(file);
                    if (metadata != null)
                    {
                        UIUtils.RunMetadataWindow(metadata, appRun);
                    }
                    else
                    {
                        UIMessages.Error(@"Metadata parse failed; null result.");
                    }
                }
                catch (Exception ex)
                {
                    LoggingHelpers.RecordException(ex.Message, @"StartupLoadPxz");
                    UIMessages.Error($"Error occurred whilst loading PXZ file:\n\n{ex}");
                }
            }
            else
            {
                UIMessages.Error(@"PlexDL doesn't recognise this file-type: '" + ext + @"'",
                                 @"Validation Error");
            }
        }
예제 #30
0
        private void Startup()
        {
            try
            {
                //reset counter
                RefreshCount = 0;

                //poll rate GUI setup
                UpdatePollRate();

                //initial value refresh
                DoRefresh();

                //start the automatic refresh timer
                tmrAutoRefresh.Start();
            }
            catch (Exception ex)
            {
                //log the error
                LoggingHelpers.RecordException(ex.Message, @"DebugStartupError");

                //inform the user
                UIMessages.Error($@"Debug monitor startup error: {ex.Message}");
            }
        }