コード例 #1
0
ファイル: CreateFolder.cs プロジェクト: greeduomacro/annox
		public override BoxMessage Perform()
		{
			BoxMessage msg = null;

			if ( RemoteExplorerConfig.AllowAccess( Username, m_Folder ) )
			{
				try
				{
					string path = System.IO.Path.Combine( BoxUtil.RunUOFolder, m_Folder );

					System.IO.Directory.CreateDirectory( path );
					msg = new GenericOK();
				}
				catch ( Exception err )
				{
					msg = new ErrorMessage( "An error occurred when creating the folder:\n\n{0}", err.ToString() );
				}
			}
			else
			{
				msg = new ErrorMessage( "You can't create folders there" );
			}

			return msg;
		}
コード例 #2
0
ファイル: FileTransport.cs プロジェクト: greeduomacro/annox
		public override BoxMessage Perform()
		{
			BoxMessage msg = null;

			if ( RemoteExplorerConfig.AllowAccess( Username, Path.GetDirectoryName( m_Filename ) ) )
			{
				if ( RemoteExplorerConfig.VeirfyExtension( m_Filename ) )
				{
					try
					{
						StreamWriter writer = new StreamWriter( FullPath, false );
						writer.Write( m_Text );
						writer.Close();

						msg = new GenericOK();
					}
					catch ( Exception err )
					{
						msg = new ErrorMessage( "An I/O error occurred when writing the file.\n\n{0}", err.ToString() );
					}
				}
				else
				{
					// Extension not supported
					msg = new ErrorMessage( "File type not allowed." );
				}
			}
			else
			{
				// Trying to upload to a folder that isn't registered for the user
				msg = new ErrorMessage( "You aren't allowed to manipulate that folder." );
			}

			return msg;
		}
コード例 #3
0
ファイル: DownloadRequest.cs プロジェクト: greeduomacro/annox
		public override BoxMessage Perform()
		{
			string folder = Path.GetDirectoryName( m_Filename );
			BoxMessage msg = null;

			if ( RemoteExplorerConfig.AllowAccess( Username, folder ) )
			{
				if ( File.Exists( FullPath ) )
				{
					FileInfo info = new FileInfo( FullPath );

					if ( info.Length <= RemoteExplorerConfig.MaxFileSize )
					{
						try
						{
							msg = new FileTransport();

							StreamReader reader = new StreamReader( info.FullName );
							( msg as FileTransport ).Text = reader.ReadToEnd();
							reader.Close();
						}
						catch ( Exception err )
						{
							msg = new ErrorMessage( "An I/O error occurred when reading the file:\n\n", err.ToString() );
						}
					}
					else
					{
						// File is too big
						msg = new ErrorMessage( "The requested file is too big." );
					}
				}
				else
				{
					// File not found
					msg = new ErrorMessage( "The requested file could not be found" );
				}
			}
			else
			{
				// Trying to request a file from a folder that isn't registered
				msg = new ErrorMessage( "The requested resource isn't available to you." );
			}

			return msg;
		}
コード例 #4
0
ファイル: DeleteRequest.cs プロジェクト: greeduomacro/annox
		public override BoxMessage Perform()
		{
			BoxMessage msg = null;

			if ( RemoteExplorerConfig.AllowAccess( Username, System.IO.Path.GetDirectoryName( m_Path ) ) )
			{
				if ( Directory.Exists( FullPath ) )
				{
					try
					{
						Directory.Delete( FullPath, true );
						msg = new GenericOK();
					}
					catch ( Exception err )
					{
						msg = new ErrorMessage( "Couldn't delete the directory {0}. The following error occurred:\n\n{1}", m_Path, err.ToString() );
					}
				}
				else if ( File.Exists( FullPath ) )
				{
					try
					{
						File.Delete( FullPath );
						msg = null;
					}
					catch ( Exception err )
					{
						msg = new ErrorMessage( "Couldn't delete the file {0}. The following error occurred:\n\n{1}", m_Path, err.ToString() );
					}
				}
				else
				{
					// Not found
					msg = new ErrorMessage( "The requested resource could not be found on the server, please refresh your view." );
				}
			}
			else
			{
				// Can't manipulate that folder
				msg = new ErrorMessage( "You aren't allowed to manipulate the folder : {0}", m_Path );
			}

			return msg;
		}
コード例 #5
0
ファイル: MoveRequest.cs プロジェクト: greeduomacro/annox
		public override BoxMessage Perform()
		{
			BoxMessage msg = null;
			
			string folderOld = Path.GetDirectoryName( m_OldPath );
			string folderNew = Path.GetDirectoryName( m_NewPath );

			string from = Path.Combine( BoxUtil.RunUOFolder, m_OldPath );
			string to = Path.Combine( BoxUtil.RunUOFolder, m_NewPath );

			if ( RemoteExplorerConfig.AllowAccess( Username, folderOld ) && RemoteExplorerConfig.AllowAccess( Username, folderNew ) )
			{
				try
				{
					if ( File.Exists( from ) )
					{
						File.Move( from, to );
						msg = null;
					}
					else if ( Directory.Exists( from ) )
					{
						Directory.Move( from, to );
						msg = new GenericOK();
					}
					else
					{
						msg = new ErrorMessage( "The requested object could not be found ({0})", m_OldPath );
					}
				}
				catch ( Exception err )
				{
					msg = new ErrorMessage( "An error occurred while processing the move request :\n\n{0}", err.ToString() );
				}
			}
			else
			{
				msg = new ErrorMessage( "You aren't allowed to access that." );
			}

			return msg;
		}
コード例 #6
0
ファイル: BoxServer.cs プロジェクト: aj9251/pandorasbox3
		/// <summary>
		/// Handles incoming messages
		/// </summary>
		/// <param name="typeName">The name of the type of the message</param>
		/// <param name="data">The byte array representing the message</param>
		/// <param name="answerType">Will hold the name of the type of the answer message</param>
		/// <returns>A stream of bytes</returns>
		private byte[] BoxRemote_OnMessage( string typeName, byte[] data, out string answerType )
		{
			answerType = null;
			BoxMessage inMsg = null;
			BoxMessage outMsg = null;

			Type type = Type.GetType( typeName );

			if ( type != null )
			{
				inMsg = BoxMessage.Decompress( data, type );

				if ( inMsg != null )
				{
					// Authenticate
					AuthenticationResult auth = Authentication.Authenticate( inMsg );

					if ( auth == AuthenticationResult.Success )
					{
						// Perform message
						outMsg = inMsg.Perform();
					}
					else
					{
						// Return authentication error
						outMsg = new LoginError( auth );
					}
				}
				else
				{
					// Send generic server error
					outMsg = new ErrorMessage( "An error occurred when decompressing the incoming message." );
				}
			}
			else
			{
				outMsg = new FeatureNotSupported();
			}

			if ( outMsg != null )
			{
				answerType = outMsg.GetType().FullName;
				return outMsg.Compress();
			}
			else
			{
				// Actions that don't require an answer
				answerType = null;
				return null;
			}
		}