Esempio n. 1
0
        /// <summary>
        /// Loading the date and time from the text file in the application data directory.
        /// </summary>
        private void LoadLastUpdateCheckFromFile()
        {
            DataFunctions.LoadStringFromFile(this.UpdateFilePath);
            string loadedString = DataFunctions.LoadedString;

            if (string.IsNullOrEmpty(loadedString))
            {
                loadedString = DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss", CultureInfo.InvariantCulture);
            }

            DateTime outputDateTime;
            bool     result = DateTime.TryParse(loadedString, out outputDateTime);

            if (!result)
            {
                return;
            }

            TimeSpan timeDifference = DateTime.Now - outputDateTime;

            if (timeDifference.Hours >= 24)
            {
                this.InformAboutNewVersion();
            }

            DataFunctions.SaveTextDataToFile(this.UpdateFilePath, loadedString, false);
        }
        /// <summary>
        /// Adds a string message to the log.
        /// </summary>
        /// <param name="stringData">The string data that will be added to the log.</param>
        private void AddToLog(string stringData)
        {
            try
            {
                FileInfo fileInfo = new FileInfo(this.logPath);
                long     fileSize = fileInfo.Length;

                if (fileSize >= this.logMaxSize)
                {
                    if (DataFunctions.LoadStringFromFile(this.logPath) > 0)
                    {
                        string loadedString = DataFunctions.LoadedString;
                        int    halfSize     = loadedString.Length / 2;
                        loadedString = StringFunctions.SubstringString(loadedString, halfSize, loadedString.Length - halfSize);

                        DataFunctions.SaveTextDataToFile(this.logPath, loadedString, true);
                    }
                }
            }
            catch (UnauthorizedAccessException unathException)
            {
                LogSystem.Instance.AddToLog(unathException, false);
            }

            string outputString = StringFunctions.GetCurrentTimeString + " - " + stringData + "\r\n";

            DataFunctions.SaveTextDataToFile(this.logPath, outputString, true);
        }