- galaxysource.zip
- Galaxy
- Common
- CSharpFileSystem
- Galaxy.sln
- GalaxyExplorer
- GalaxyFilePidl
- GalaxyPIDLManager
- GalaxyToolkit
- GalaxyToolkit.vdproj
- Release
- galaxyjavasrc.zip
- GalaxyJavaSrc
- galaxy
- jars
- log4j.README
- log4j-1.2.8.jar
- oncrpc.jar
|
/*
Copyright 2005 Chad Yoshikawa
http://www.ececs.uc.edu/~yoshikco
yoshikco@ececs.uc.edu
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
using System;
using System.Net.Sockets;
using System.Diagnostics;
using System.IO;
namespace CSharpFileSystem.Commands
{
/// <summary>
/// A factory that will create commands based the opcode read over the wire (otw)
/// </summary>
public class FileSystemCommandFactory
{
enum FILESYSTEM_OPCODES {
LISTFILES_OPCODE=1,
READ_OPCODE=2,
WRITE_OPCODE=3,
STAT_OPCODE=4,
CREATEDIR_OPCODE=5,
DELETE_OPCODE=6,
CREATEFILE_OPCODE=7,
COMMAND_OPCODE=8,
COPY_OPCODE=9
} ;
/// <summary>
/// Cannot create this object -- just use the static methods
/// @see CreateCommand()
/// </summary>
private FileSystemCommandFactory()
{
}
/// <summary>
/// The factory method for creating commands based on the next opcode otw
/// </summary>
/// <param name="reader">The stream representing the wire from the NSE</param>
/// <param name="writer">The stream representing the wire to the NSE</param>
/// <returns>The newly minted command</returns>
public static FileSystemCommand CreateCommand(BinaryReader reader, BinaryWriter writer) {
FileSystemCommand ret = null;
int opcode = IOLibrary.ReadInt(reader); // 4 byte fixed length opcode
switch (opcode) {
case (int)FILESYSTEM_OPCODES.LISTFILES_OPCODE:
// for now, just supply the 'list files command'
ret = new Commands.ListFilesCommand(reader,writer);
break;
case (int)FILESYSTEM_OPCODES.READ_OPCODE:
ret = new Commands.ReadCommand(reader,writer);
break;
case (int)FILESYSTEM_OPCODES.WRITE_OPCODE:
ret = new Commands.WriteCommand(reader,writer);
break;
case (int)FILESYSTEM_OPCODES.STAT_OPCODE:
ret = new Commands.StatCommand(reader,writer);
break;
case (int)FILESYSTEM_OPCODES.CREATEDIR_OPCODE:
ret = new Commands.CreateDirectoryCommand(reader,writer);
break;
case (int)FILESYSTEM_OPCODES.DELETE_OPCODE:
ret = new Commands.DeleteCommand(reader,writer);
break;
case (int)FILESYSTEM_OPCODES.CREATEFILE_OPCODE:
ret = new Commands.CreateFileCommand(reader,writer);
break;
case (int)FILESYSTEM_OPCODES.COMMAND_OPCODE:
ret = new Commands.CommandCommand(reader,writer);
break;
case (int)FILESYSTEM_OPCODES.COPY_OPCODE:
ret = new Commands.CopyCommand(reader,writer);
break;
default:
// error
Debug.WriteLine("Error -- invalid opcode requested "+opcode);
break;
} // end switch
return (ret);
} // end CreateCommand
} // end class
} // end namespace
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.