Core
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
using Sarand.Core.Base;
|
||||
using Sarand.Core.IO;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Sarand.PatientMgr.Win.Dbas.Utils
|
||||
{
|
||||
//=======================================================================
|
||||
/// <summary>
|
||||
/// Static implementations of fucntions required by FileUtil.
|
||||
/// </summary>
|
||||
public class SpmFileUtil
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Initialise statics.
|
||||
public static void InitStatics ()
|
||||
{
|
||||
FileUtil.DirectoryExists = IsDirectory;
|
||||
FileUtil.DirectoryGetParent = GetParentDirectory;
|
||||
FileUtil.DirectoryCreateDirectory = CreateDirectory;
|
||||
FileUtil.FileExists = IsFile;
|
||||
FileUtil.FileReadAllLines = FileReadAllLines;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// D i r e c t o r y
|
||||
//-------------------------------------------------------------------
|
||||
public static bool IsDirectory (String directoryPath)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Directory.Exists(directoryPath);
|
||||
}
|
||||
catch (Exception exc) { Logger.Debug("SlmFileUtil.IsDirectory " + exc.GetType().Name + ": " + exc.Message); }
|
||||
return false;
|
||||
}
|
||||
public static String GetParentDirectory (String filepath)
|
||||
{
|
||||
try
|
||||
{
|
||||
DirectoryInfo parentDirectoryInfo = Directory.GetParent(filepath);
|
||||
if (parentDirectoryInfo != null)
|
||||
return parentDirectoryInfo.FullName;
|
||||
}
|
||||
catch (Exception exc) { Logger.Debug("SlmFileUtil.GetParentDirectory " + exc.GetType().Name + ": " + exc.Message); }
|
||||
return String.Empty;
|
||||
}
|
||||
public static bool CreateDirectory (String directoryPath)
|
||||
{
|
||||
try
|
||||
{
|
||||
DirectoryInfo info = Directory.CreateDirectory(directoryPath);
|
||||
return info.Exists;
|
||||
}
|
||||
catch (Exception exc) { Logger.Debug("SlmFileUtil.CreateDirectory " + exc.GetType().Name + ": " + exc.Message); }
|
||||
return false;
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
// F i l e
|
||||
//-------------------------------------------------------------------
|
||||
public static bool IsFile (String filePath)
|
||||
{
|
||||
try
|
||||
{
|
||||
return File.Exists(filePath);
|
||||
}
|
||||
catch (Exception exc) { Logger.Debug("SlmFileUtil.IsFile " + exc.GetType().Name + ": " + exc.Message); }
|
||||
return false;
|
||||
}
|
||||
public static String[] FileReadAllLines (String filePath)
|
||||
{
|
||||
try
|
||||
{
|
||||
return File.ReadAllLines(filePath);
|
||||
}
|
||||
catch (Exception exc) { Logger.Debug("SlmFileUtil.FileReadAllLines " + exc.GetType().Name + ": " + exc.Message); }
|
||||
return new String[0];
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
Reference in New Issue
Block a user