- .NET API: add GetFileDirectoryEx function

pull/92/head
Michael Zillgith 7 years ago
parent 28e8831029
commit 66f571f03d

@ -438,6 +438,10 @@ namespace IEC61850
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr IedConnection_getFileDirectory(IntPtr self, out int error, string directoryName); static extern IntPtr IedConnection_getFileDirectory(IntPtr self, out int error, string directoryName);
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr IedConnection_getFileDirectoryEx(IntPtr self, out int error, string directoryName, string continueAfter,
[MarshalAs(UnmanagedType.I1)] out bool moreFollows);
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern void IedConnection_deleteFile(IntPtr self, out int error, string fileName); static extern void IedConnection_deleteFile(IntPtr self, out int error, string fileName);
@ -1204,6 +1208,43 @@ namespace IEC61850
return fileDirectory; return fileDirectory;
} }
/// <summary>Read the content of a file directory. - single request version</summary>
/// <param name="directoryName">The name of the directory.</param>
/// <param name="continueAfter">The last directory when request is a continuation, or null otherwise</param>
/// <param name="moreFollows">true, when more files are available, false otherwise</param>
/// <exception cref="IedConnectionException">This exception is thrown if there is a connection or service error</exception>
public List<FileDirectoryEntry> GetFileDirectoryEx(string directoryName, string continueAfter, out bool moreFollows)
{
int error;
IntPtr fileEntryList = IedConnection_getFileDirectoryEx(connection, out error, directoryName, continueAfter, out moreFollows);
if (error != 0)
throw new IedConnectionException("Reading file directory failed", error);
List<FileDirectoryEntry> fileDirectory = new List<FileDirectoryEntry>();
IntPtr element = LinkedList_getNext(fileEntryList);
while (element != IntPtr.Zero)
{
IntPtr elementData = LinkedList_getData(element);
FileDirectoryEntry entry = new FileDirectoryEntry(elementData);
fileDirectory.Add(entry);
FileDirectoryEntry_destroy(elementData);
element = LinkedList_getNext(element);
}
LinkedList_destroyStatic(fileEntryList);
return fileDirectory;
}
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate bool InternalIedClientGetFileHandler(IntPtr parameter, IntPtr buffer, UInt32 bytesRead); private delegate bool InternalIedClientGetFileHandler(IntPtr parameter, IntPtr buffer, UInt32 bytesRead);

@ -15,7 +15,9 @@ namespace files
{ {
public static void printFiles (IedConnection con, string prefix, string parent) public static void printFiles (IedConnection con, string prefix, string parent)
{ {
List<FileDirectoryEntry> files = con.GetFileDirectory (parent); bool moreFollows = false;
List<FileDirectoryEntry> files = con.GetFileDirectoryEx (parent, null, out moreFollows);
foreach (FileDirectoryEntry file in files) { foreach (FileDirectoryEntry file in files) {
Console.WriteLine (prefix + file.GetFileName () + "\t" + file.GetFileSize () + "\t" + Console.WriteLine (prefix + file.GetFileName () + "\t" + file.GetFileSize () + "\t" +
@ -26,6 +28,8 @@ namespace files
} }
} }
if (moreFollows)
Console.WriteLine("-- MORE FILE AVAILABLE --");
} }
static bool getFileHandler (object parameter, byte[] data) static bool getFileHandler (object parameter, byte[] data)
@ -48,7 +52,7 @@ namespace files
if (args.Length > 0) if (args.Length > 0)
hostname = args [0]; hostname = args [0];
else else
hostname = "10.0.2.2"; hostname = "127.0.0.1";
Console.WriteLine ("Connect to " + hostname); Console.WriteLine ("Connect to " + hostname);

Loading…
Cancel
Save