C# Class mybox.Common

A class which is used to store common functions common to the client and server
Show file Open project: jonocodes/mybox

Public Properties

Property Type Description
TempDir String
UserHome String

Public Methods

Method Description
BufferToSignal ( byte buffer ) : Signal

Convert a byte array to a single byte signal

CreateLocalDirectory ( String absPath ) : bool

Create a directory on the local filesystem if it does not exist

DateTimeToUnixTimestamp ( System.DateTime dateTime ) : long

Convert DateTime to unix timestamp.

DeleteLocal ( String absPath ) : bool

Delete a local file or directory

EncryptPassword ( string pwd, string salt ) : string

Enrcypt a password with a salt and return the result

EndDirWithSlash ( String absPath ) : string

Make sure the input directory path has a trailing slash.

ExitError ( ) : void

Quit the program when an error occurs.

FileChecksumToBytes ( String absPath ) : byte[]
FileChecksumToString ( String absPath ) : String
GenerateSalt ( int size ) : string

Generates a random salt for password encryption purposes

GetFilesRecursive ( string baseDir ) : List

Gets a recursive listing of files from a directory

GetModTime ( String fullPath ) : long

Get the data modification time of a local file

Md5Hash ( String input ) : String

Md5 digest a string.

ReceiveFile ( Socket socket, string baseDir ) : MyFile

Receive a file over a socket

ReceiveString ( Socket socket ) : String

Get a string from a socket which is sent by SendString

SendString ( Socket socket, String str ) : bool

Send a string along a socket

Sha256Hash ( String input ) : String

Compute Sha256 for a string.

ShowCliHelp ( OptionSet options, Assembly thisAssembly ) : void

Display the command line options and then exit.

SignalToBuffer ( Signal signal ) : byte[]

Convert the signal to a byte array

UnixTimeStampToDateTime ( long unixTimeStamp ) : System.DateTime

Convert UNIX timestamp to a datetime object

Private Methods

Method Description
SendFile ( String relPath, Socket socket, String baseDir ) : MyFile

Method Details

BufferToSignal() public static method

Convert a byte array to a single byte signal
public static BufferToSignal ( byte buffer ) : Signal
buffer byte
return Signal

CreateLocalDirectory() public static method

Create a directory on the local filesystem if it does not exist
public static CreateLocalDirectory ( String absPath ) : bool
absPath String
return bool

DateTimeToUnixTimestamp() public static method

Convert DateTime to unix timestamp.
public static DateTimeToUnixTimestamp ( System.DateTime dateTime ) : long
dateTime System.DateTime /// DateTime ///
return long

DeleteLocal() public static method

Delete a local file or directory
public static DeleteLocal ( String absPath ) : bool
absPath String the absolute path to the item
return bool

EncryptPassword() public static method

Enrcypt a password with a salt and return the result
public static EncryptPassword ( string pwd, string salt ) : string
pwd string
salt string
return string

EndDirWithSlash() public static method

Make sure the input directory path has a trailing slash.
public static EndDirWithSlash ( String absPath ) : string
absPath String
return string

ExitError() public static method

Quit the program when an error occurs.
public static ExitError ( ) : void
return void

FileChecksumToBytes() public static method

public static FileChecksumToBytes ( String absPath ) : byte[]
absPath String
return byte[]

FileChecksumToString() public static method

public static FileChecksumToString ( String absPath ) : String
absPath String
return String

GenerateSalt() public static method

Generates a random salt for password encryption purposes
public static GenerateSalt ( int size ) : string
size int the length in bytes of the salt
return string

GetFilesRecursive() public static method

Gets a recursive listing of files from a directory
public static GetFilesRecursive ( string baseDir ) : List
baseDir string
return List

GetModTime() public static method

Get the data modification time of a local file
public static GetModTime ( String fullPath ) : long
fullPath String
return long

Md5Hash() public static method

Md5 digest a string.
public static Md5Hash ( String input ) : String
input String /// Any string ///
return String

ReceiveFile() public static method

Receive a file over a socket
public static ReceiveFile ( Socket socket, string baseDir ) : MyFile
socket System.Net.Sockets.Socket
baseDir string the base directory the file will live in
return MyFile

ReceiveString() public static method

Get a string from a socket which is sent by SendString
public static ReceiveString ( Socket socket ) : String
socket System.Net.Sockets.Socket
return String

SendString() public static method

Send a string along a socket
public static SendString ( Socket socket, String str ) : bool
socket System.Net.Sockets.Socket
str String
return bool

Sha256Hash() public static method

Compute Sha256 for a string.
public static Sha256Hash ( String input ) : String
input String /// Input. ///
return String

ShowCliHelp() public static method

Display the command line options and then exit.
public static ShowCliHelp ( OptionSet options, Assembly thisAssembly ) : void
options OptionSet
thisAssembly System.Reflection.Assembly
return void

SignalToBuffer() public static method

Convert the signal to a byte array
public static SignalToBuffer ( Signal signal ) : byte[]
signal Signal
return byte[]

UnixTimeStampToDateTime() public static method

Convert UNIX timestamp to a datetime object
public static UnixTimeStampToDateTime ( long unixTimeStamp ) : System.DateTime
unixTimeStamp long /// Unix time stamp. ///
return System.DateTime

Property Details

TempDir public static property

The system temp directory
public static String TempDir
return String

UserHome public static property

The user's system home directory primarialy used for determining where the config directory is
public static String UserHome
return String