WIP
parent
54dc579195
commit
ee46186da5
|
@ -110,6 +110,7 @@ namespace ln.types
|
||||||
|
|
||||||
public bool Contains(string longName)
|
public bool Contains(string longName)
|
||||||
{
|
{
|
||||||
|
if (longName != null)
|
||||||
foreach (Argument argument in arguments)
|
foreach (Argument argument in arguments)
|
||||||
{
|
{
|
||||||
if (longName.Equals(argument.Long))
|
if (longName.Equals(argument.Long))
|
||||||
|
|
|
@ -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)
|
public static void WriteBytes(this Stream stream, byte[] bytes)
|
||||||
{
|
{
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
using System;
|
||||||
|
namespace ln.types.io
|
||||||
|
{
|
||||||
|
public interface ContentSource
|
||||||
|
{
|
||||||
|
byte[] Content { get; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -132,6 +132,9 @@
|
||||||
<Compile Include="Promise.cs" />
|
<Compile Include="Promise.cs" />
|
||||||
<Compile Include="test\PromiseTests.cs" />
|
<Compile Include="test\PromiseTests.cs" />
|
||||||
<Compile Include="threads\TaskQueue.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="threads\SchedulingPool.cs" />
|
||||||
<Compile Include="test\SchedulingPoolTests.cs" />
|
<Compile Include="test\SchedulingPoolTests.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -156,6 +159,7 @@
|
||||||
<Folder Include="cache\" />
|
<Folder Include="cache\" />
|
||||||
<Folder Include="collections\" />
|
<Folder Include="collections\" />
|
||||||
<Folder Include="odb\ng\diff\" />
|
<Folder Include="odb\ng\diff\" />
|
||||||
|
<Folder Include="io\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\ln.logging\ln.logging.csproj">
|
<ProjectReference Include="..\ln.logging\ln.logging.csproj">
|
||||||
|
|
Loading…
Reference in New Issue