Error_m.h #1

  • //
  • guest/
  • robert_cowham/
  • perforce/
  • API/
  • P4.Net/
  • main/
  • src/
  • p4dn/
  • Error_m.h
  • View
  • Commits
  • Open Download .zip Download (4 KB)
/*
 * P4.Net *
Copyright (c) 2007 Shawn Hladky

Permission is hereby granted, free of charge, to any person obtaining a copy of this software 
and associated documentation files (the "Software"), to deal in the Software without 
restriction, including without limitation the rights to use, copy, modify, merge, publish, 
distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the 
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or 
substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
 */


#pragma once

#include "StdAfx.h"
#include <vcclr.h>
#include "error.h"

namespace p4dn {

	public ref class ManagedErrorID
	{
	public:
		int		code;		// ErrorOf
		System::String^ fmt;

		int	SubCode() 		{ return (code >> 0) & 0x3ff; }
		int	Subsystem()		{ return (code >> 10) & 0x3f; }
		int	Generic()		{ return (code >> 16) & 0xff; }
		int	ArgCount()		{ return (code >> 24) & 0x0f; }
		int	Severity()		{ return (code >> 28) & 0x0f; }
		int	UniqueCode()	{ return code & 0xffff; }

		System::Collections::Hashtable^ GetArgs()
		{
			return _vars;
		}

	internal:
		ManagedErrorID(::ErrorId *e, System::Text::Encoding^ encoding)
		{
			code = e->code;
			fmt = P4String::CharArrToString(e->fmt, encoding);
			_vars = gcnew System::Collections::Hashtable();
		}
		
		void AddVar(StrPtr* var, StrPtr* val, System::Text::Encoding^ encoding)
		{
			System::String^ mvar = P4String::StrPtrToString(var, encoding);
			System::String^ mval = P4String::StrPtrToString(val, encoding);
			_vars->Add(mvar, mval);
		}
		
	private:
		System::Collections::Hashtable^ _vars;

	} ;

	public ref class Error : public System::IDisposable 
    {

    public:

		Error( System::Text::Encoding^ encoding);

		/*
			From error.h:
			E_EMPTY = 0,	// nothing yet
			E_INFO = 1,	// something good happened
			E_WARN = 2,	// something not good happened
			E_FAILED = 3,	// user did somthing wrong
			E_FATAL = 4	// system broken -- nothing can continue

		*/
		enum class ErrorSeverity {
			Empty = 0,
			Info = 1,
			Warning = 2,
			Failed = 3,
			Fatal = 4
		};

		~Error();	 // : System::IDisposable::Dispose();
        void Clear();
				
        bool Test();
        bool IsInfo();
        bool IsWarning();
		bool IsFailed();
        bool IsFatal();

		int  GetID();
		//array<System::String^>^ GetVars();
		void			GetVariables(System::Collections::Hashtable^ ht);
		ManagedErrorID^ GetErrorID();
        
        System::String^ Fmt();

        property ErrorSeverity Severity {
            ErrorSeverity get() {
                return static_cast< ErrorSeverity >( _err->GetSeverity() );
			}
        }

		property int GenericCode {
			int get() { return  _err->GetGeneric(); }
		}

    private:          
        ::Error* _err;
        bool _requiresFree;
		bool _Disposed;
		System::String^ _Instance;
		System::Text::Encoding^ _encoding;
		void CleanUp();

    internal:        
        Error( ::Error* e, System::Text::Encoding^ encoding);
		property ::Error* InternalError {
			::Error* get();
        }
    };

} // end namespace




# Change User Description Committed
#1 6414 Robert Cowham Initial branch
//guest/shawn_hladky/P4.Net/main/src/p4dn/Error_m.h
#6 6387 Shawn Hladky P4.net: Upgrade to C++/CLI.
 Changes merged from Jim Gomes.
#5 6182 Shawn Hladky P4.Net.
 First stab at a callback interface for real-time handling of perforce output.  Upgrade to VS 2008.
#4 5878 Shawn Hladky P4.Net:  1.0, support for raw spec processing.
 Update copyright.  Fix build script.  Bugs found along the way.
#3 5874 Shawn Hladky P4.Net:  v1.0 WIP.
 Upgrade API to 2006.2.  Fixes/tests for print and unicode servers.  Changed ConvertDate to use client's timezone... old logic trying to use server's timezone didn't account for daylight savings time.
#2 5838 Shawn Hladky P4.Net: WIP support for unicode server
#1 5830 Shawn Hladky P4.Net: reorg to support release branches
//guest/shawn_hladky/P4.Net/src/p4dn/Error_m.h
#3 5798 Shawn Hladky P4.Net...  still not ready for beta
Added license to all files
Added several doc files
Misc bugs
#2 5447 Shawn Hladky refactor, and added options class
#1 5348 Shawn Hladky Re-organizing, for the improved API
//guest/shawn_hladky/PerforceDotNet/p4dn/Error_m.h
#2 4545 Shawn Hladky Several Fixes:
Updated solution to Visual Studio 2003
Implemented InputData
Implemented OutPutBinary
Changed ClientAPI and Error objects to implement the IDisposable interface to improve Garbage Collection
Changed header files so you don't need to add #pragma once to the p4 api headers.
Refactored the ClientUserDelagate class
Fixed a few minor memory leaks
#1 4328 Shawn Hladky Branching from //guest/jacob_gladish/PerforceDotNet/...
//guest/jacob_gladish/PerforceDotNet/p4dn/Error_m.h
#1 3787 Jacob Gladish initial code submission