Esempio n. 1
0
        /// <summary>
        /// Loads the temporary uptime.
        /// </summary>
        /// <returns></returns>
        public TemporaryUptime LoadTemporaryUptime()
        {
            try
            {
                if (!Directory.Exists(WsapmTools.GetCommonApplicationDataFolder()) || !File.Exists(this.temporaryUptimeFile))
                {
                    return(null);
                }

                using (FileStream fs = new FileStream(this.temporaryUptimeFile, FileMode.Open, FileAccess.Read))
                {
                    TemporaryUptime temporaryUptime = this.serializer.Deserialize(fs) as TemporaryUptime;
                    return(temporaryUptime);
                }
            }
            catch (IOException ex)
            {
                throw new WsapmException(Resources.Wsapm_Core.TemporaryUptimeManager_LoadTemporaryUptimeError, ex);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Saves the given DateTime as temporary uptime file.
        /// </summary>
        /// <param name="temporaryUptime"></param>
        public void SaveTemporaryUptime(TemporaryUptime temporaryUptime)
        {
            try
            {
                if (!Directory.Exists(this.settingsFolder))
                {
                    Directory.CreateDirectory(this.settingsFolder);
                }

                if (File.Exists(this.temporaryUptimeFile))
                {
                    File.Delete(this.temporaryUptimeFile);
                }

                using (FileStream fs = new FileStream(this.temporaryUptimeFile, FileMode.Create, FileAccess.Write))
                {
                    this.serializer.Serialize(fs, (object)temporaryUptime);
                }
            }
            catch (Exception ex)
            {
                throw new WsapmException(Resources.Wsapm_Core.TemporaryUptimeManager_SaveTemporaryUptimeError, ex);
            }
        }