master
Harald Wolff 2020-02-04 09:00:22 +01:00
parent 54dc579195
commit ee46186da5
6 changed files with 86 additions and 0 deletions

View File

@ -110,6 +110,7 @@ namespace ln.types
public bool Contains(string longName)
{
if (longName != null)
foreach (Argument argument in arguments)
{
if (longName.Equals(argument.Long))

View File

@ -96,6 +96,12 @@ namespace ln.types
}
public static byte[] ReadToEnd(this Stream stream)
{
MemoryStream memoryStream = new MemoryStream();
stream.CopyTo(memoryStream);
return memoryStream.ToArray();
}
public static void WriteBytes(this Stream stream, byte[] bytes)
{

View File

@ -0,0 +1,8 @@
using System;
namespace ln.types.io
{
public interface ContentSource
{
byte[] Content { get; }
}
}

19
io/FileStorage.cs 100644
View File

@ -0,0 +1,19 @@
using System;
using System.IO;
namespace ln.types.io
{
public abstract class FileStorage
{
public FileStorage(string path)
{
}
public abstract string[] ListFiles();
public abstract string[] ListDirectories();
public abstract bool ContainsFile(string path);
public abstract bool ContainsDirectory(string path);
public virtual bool Contains(string path) => ContainsDirectory(path) || ContainsFile(path);
}
}

48
io/WatchedFile.cs 100644
View File

@ -0,0 +1,48 @@
using System;
using System.IO;
namespace ln.types.io
{
public class WatchedFile : IDisposable, ContentSource
{
public string FileName { get; private set; }
public event FileSystemEventHandler Changed;
FileSystemWatcher fileSystemWatcher;
public WatchedFile(String filename)
{
FileName = filename;
fileSystemWatcher = new FileSystemWatcher(filename);
fileSystemWatcher.Changed += FileSystemWatcher_Changed;
}
public byte[] Content
{
get
{
using (FileStream fs = new FileStream(FileName,FileMode.Open))
{
return fs.ReadBytes((int)fs.Length);
}
}
set
{
using (FileStream fs = new FileStream(FileName, FileMode.OpenOrCreate, FileAccess.Write))
{
fs.Position = 0;
fs.WriteBytes(value);
}
}
}
void FileSystemWatcher_Changed(object sender, FileSystemEventArgs e)
{
Changed?.Invoke(sender, e);
}
public void Dispose()
{
fileSystemWatcher.Dispose();
}
}
}

View File

@ -132,6 +132,9 @@
<Compile Include="Promise.cs" />
<Compile Include="test\PromiseTests.cs" />
<Compile Include="threads\TaskQueue.cs" />
<Compile Include="io\WatchedFile.cs" />
<Compile Include="io\ContentSource.cs" />
<Compile Include="io\FileStorage.cs" />
<Compile Include="threads\SchedulingPool.cs" />
<Compile Include="test\SchedulingPoolTests.cs" />
</ItemGroup>
@ -156,6 +159,7 @@
<Folder Include="cache\" />
<Folder Include="collections\" />
<Folder Include="odb\ng\diff\" />
<Folder Include="io\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ln.logging\ln.logging.csproj">