Exemplo n.º 1
0
        public void writefile_when_file_does_not_exist_without_overwrite_succeeds()
        {
            string fullFilePath  = @"C:\temp\filename.txt";
            string content       = "content";
            bool   overwriteFile = false;

            DeleteTestFile(fullFilePath);

            _fileIO.WriteFile(fullFilePath, content, overwriteFile);
            bool fileExistsAfter = FileIO.GetFileInfo(fullFilePath).Exists;

            Assert.IsTrue(fileExistsAfter);
        }
Exemplo n.º 2
0
        public void Flush()
        {
            try
            {
                lock (PadLock)
                {
                    string[] keys = CachedFiles.Keys.ToArray();

                    foreach (string key in keys)
                    {
                        CachedFile cachedFile = CachedFiles[key];

                        if (!cachedFile.Flushed)
                        {
                            FileIO.CreateDirectory(Path.GetDirectoryName(cachedFile.FileName));

                            FileIO.WriteFile(cachedFile.FileName, cachedFile.MemoryStream.ToArray());
                            cachedFile.Flushed = true;
                        }

                        if (!cachedFile.Permanent &&
                            DateTime.Now.Subtract(cachedFile.LastAccessed).TotalHours > 24)
                        {
                            CachedFiles.Remove(key);
                        }
                    }
                }
            }
            catch
            {
                GlobalReference.GlobalValues.Logger.Log(Logging.LogSettings.LogLevel.INFO, "File system is down");
            }
        }
Exemplo n.º 3
0
        public void SaveCollection(string fullFilePath, bool overwriteFile)
        {
            if (_homeCollection == null)
            {
                throw new CollectionException("Unable to save a null collection");
            }
            string jsonCollection = null;

            try
            {
                jsonCollection = ConvertCollectionToJson(_homeCollection);
            }
            catch (CollectionParseException ex)
            {
                throw new CollectionException($"Unable to parse collection to Json", ex);
            }

            _fileIO.WriteFile(fullFilePath, jsonCollection, overwriteFile);
        }