Ejemplo n.º 1
0
        /// <summary>
        /// Save program options into file.
        /// <seealso cref="LoadSettingsAsync(string)"/> is called automatically if save is successful
        /// </summary>
        /// <param name="settings">Settings that will be saved</param>
        /// <returns>Returns saved settings. Throws exception if save failed</returns>
        public T SaveSettings(T settings)
        {
            fileSerializer.Serialize(SettingsFilePath, settings);

            // Settings reload will automatically update cache and notify observers
            LoadSettings();

            return(settings);
        }
Ejemplo n.º 2
0
        public void Send(T message)
        {
            string dir      = _options.Folder;
            string filename = Guid.NewGuid().ToString();
            string ext      = "." + _options.FileType;
            string path     = Path.Combine(dir, filename, ext);

            _serializer.Serialize(message, path);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// This function serves to centralize file writes within this class
        /// </summary>
        private void WriteFile(string filePath, FileCacheItem data)
        {
            // Remove current item from cache size calculations
            if (File.Exists(filePath))
            {
                CurrentCacheSize -= new FileInfo(filePath).Length;
            }
            else
            {
                var directoryPath = Path.GetDirectoryName(filePath);
                var di            = new DirectoryInfo(directoryPath);

                if (!di.Exists)
                {
                    di.Create();
                }
            }

            // Write the object payload
            using (FileStream stream = GetStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None))
            {
                _serializer.Serialize(stream, data);
            }

            // Adjust cache size
            CurrentCacheSize += new FileInfo(filePath).Length;

            // Check to see if limit was reached
            if (CurrentCacheSize > MaxCacheSize)
            {
                if (MaxCacheSizeReached != null)
                {
                    MaxCacheSizeReached(this, new FileCacheEventArgs(CurrentCacheSize, MaxCacheSize));
                }
            }
        }
Ejemplo n.º 4
0
 public void WriteFile(IFileSerializer fileSerializer, List <TraceResult.ThreadResult> list)
 {
     Console.WriteLine(fileSerializer.Serialize(list));
 }