ToUInt64() 공개 메소드

public ToUInt64 ( ) : ulong
리턴 ulong
예제 #1
0
		public void SetDateTime (OciHandle handle, OciErrorHandle errorHandle,
					short year, byte month, byte day,
					byte hour, byte min, byte sec, uint fsec, string timezone)
		{
			// Get size of buffer
			ulong rsize = 0;
			UIntPtr rsizep = new UIntPtr (rsize);
			int status = OciCalls.OCIUnicodeToCharSet (handle, null, timezone, ref rsizep);

			// Fill buffer
			rsize = rsizep.ToUInt64 ();
			byte[] bytes = new byte[rsize];
			if (status == 0 && rsize > 0)
				OciCalls.OCIUnicodeToCharSet (handle, bytes, timezone, ref rsizep);

			if (fsec > 0)
				fsec = fsec * 1000000;

			uint timezoneSize = (uint) bytes.Length;
			OciCalls.OCIDateTimeConstruct (handle,
				errorHandle, this.Handle,
				year, month, day,
				hour, min, sec, fsec,
				bytes, timezoneSize);

			//uint valid = 0;
			//int result = OciCalls.OCIDateTimeCheck (handle,
			//	errorHandle, this.Handle, out valid);
		}
        private NativeScoreEntry GetElement(UIntPtr index)
        {
            if (index.ToUInt64() >= Length().ToUInt64())
            {
                throw new ArgumentOutOfRangeException();
            }

            return new NativeScoreEntry(
                ScorePage.ScorePage_Entries_GetElement(SelfPtr(), index));
        }
        internal static void InternalOnDataReceived(
            IntPtr room, IntPtr participant, IntPtr data, UIntPtr dataLength, bool isReliable,
            IntPtr userData)
        {
            GooglePlayGames.OurUtils.Logger.d("Entering InternalOnDataReceived: " + userData.ToInt64());

            var callback = Callbacks.IntPtrToPermanentCallback
            <Action<NativeRealTimeRoom, MultiplayerParticipant, byte[], bool>>(userData);

            using (var nativeRoom = NativeRealTimeRoom.FromPointer(room))
            {
                using (var nativeParticipant = MultiplayerParticipant.FromPointer(participant))
                {
                    if (callback == null)
                    {
                        return;
                    }

                    byte[] convertedData = null;

                    if (dataLength.ToUInt64() != 0)
                    {
                        convertedData = new byte[dataLength.ToUInt32()];
                        Marshal.Copy(data, convertedData, 0, (int)dataLength.ToUInt32());
                    }

                    try
                    {
                        callback(nativeRoom, nativeParticipant, convertedData, isReliable);
                    }
                    catch (Exception e)
                    {
                        GooglePlayGames.OurUtils.Logger.e("Error encountered executing InternalOnDataReceived. " +
                            "Smothering to avoid passing exception into Native: " + e);
                    }
                }
            }
        }
예제 #4
0
파일: Eval.cs 프로젝트: GreenDamTan/dnSpy
		public IDebuggerValue Create(UIntPtr value) {
			return debugger.Dispatcher.UI(() => {
				var res = CreateNoConstructorUI(appDomain.UIntPtr).CorValue;
				Keep(res);
				Debug.Assert(res.DereferencedValue != null && res.DereferencedValue.BoxedValue != null);
				res = res.DereferencedValue.BoxedValue;
				if (value != UIntPtr.Zero) {
					var bytes = UIntPtr.Size == 4 ?
							BitConverter.GetBytes(value.ToUInt32()) :
							BitConverter.GetBytes(value.ToUInt64());
					res.WriteGenericValue(bytes);
				}
				return new DebuggerValue(debugger, res);
			});
		}
예제 #5
0
            private static unsafe int Write(
                ref GitOid oid,
                IntPtr backend,
                IntPtr data,
                UIntPtr len,
                Core.GitObjectType type)
            {
                OdbBackend odbBackend = GCHandle.FromIntPtr(Marshal.ReadIntPtr(backend, GitOdbBackend.GCHandleOffset)).Target as OdbBackend;

                ObjectType objectType = type.ToObjectType();

                if (odbBackend != null &&
                    len.ToUInt64() < long.MaxValue)
                {
                    try
                    {
                        using (UnmanagedMemoryStream stream = new UnmanagedMemoryStream((byte*)data, (long)len.ToUInt64()))
                        {
                            byte[] finalOid;

                            int toReturn = odbBackend.Write(oid.Id, stream, (long)len.ToUInt64(), objectType, out finalOid);

                            if (0 == toReturn)
                            {
                                oid.Id = finalOid;
                            }

                            return toReturn;
                        }
                    }
                    catch (Exception ex)
                    {
                        Proxy.giterr_set_str(GitErrorCategory.Odb, ex);
                    }
                }

                return (int)GitErrorCode.Error;
            }
            private unsafe static int Read(
                IntPtr stream,
                IntPtr buffer,
                UIntPtr buf_size,
                out UIntPtr bytes_read)
            {
                bytes_read = UIntPtr.Zero;

                SmartSubtransportStream transportStream = GCHandle.FromIntPtr(Marshal.ReadIntPtr(stream, GitSmartSubtransportStream.GCHandleOffset)).Target as SmartSubtransportStream;

                if (transportStream != null &&
                    buf_size.ToUInt64() < (ulong)long.MaxValue)
                {
                    using (UnmanagedMemoryStream memoryStream = new UnmanagedMemoryStream((byte*)buffer, 0, (long)buf_size.ToUInt64(), FileAccess.ReadWrite))
                    {
                        try
                        {
                            long longBytesRead;

                            int toReturn = transportStream.Read(memoryStream, (long)buf_size.ToUInt64(), out longBytesRead);

                            bytes_read = new UIntPtr((ulong)Math.Max(0, longBytesRead));

                            return toReturn;
                        }
                        catch (Exception ex)
                        {
                            Proxy.giterr_set_str(GitErrorCategory.Net, ex);
                        }
                    }
                }

                return (int)GitErrorCode.Error;
            }
예제 #7
0
		internal string GetOracleVersion ()
		{
			byte[] buffer = new Byte[256];
			uint bufflen = (uint) buffer.Length;

			IntPtr sh = oci.ServiceContext;
			IntPtr eh = oci.ErrorHandle;

			OciCalls.OCIServerVersion (sh, eh, ref buffer,  bufflen, OciHandleType.Service);
			
			// Get length of returned string
			ulong 	rsize = 0;
			UIntPtr rsizep = new UIntPtr (rsize);
			IntPtr	env = oci.Environment;
			OciCalls.OCICharSetToUnicode (env, null, buffer, ref rsizep);
			
			// Get string
			rsize = rsizep.ToUInt64 ();
			StringBuilder ret = new StringBuilder((int)rsize);
			OciCalls.OCICharSetToUnicode (env, ret, buffer, ref rsizep);

			return ret.ToString ();
		}
예제 #8
0
        private ReturnCode OnAiFileSeekProc(IntPtr file, UIntPtr offset, Origin seekOrigin)
        {
            if(m_filePtr != file)
                return ReturnCode.Failure;

            ReturnCode code = ReturnCode.Failure;

            try
            {
                code = Seek((long) offset.ToUInt64(), seekOrigin);
            }
            catch(Exception) { /*Assimp will report an IO error*/ }

            return code;
        }
예제 #9
0
 public override void ParseScriptText(string code, string itemName, object context, string delimiter, UIntPtr sourceContext, uint startingLineNumber, ScriptTextFlags flags, IntPtr pVarResult, out EXCEPINFO excepInfo)
 {
     activeScriptParse.ParseScriptText(code, itemName, context, delimiter, sourceContext.ToUInt64(), startingLineNumber, flags, pVarResult, out excepInfo);
 }
예제 #10
0
		public static OciErrorInfo HandleError (OciHandle hwnd, int status) 
		{		
			OciErrorInfo info;
			info.ErrorCode = status;
			info.ErrorMessage = OciGlue.ReturnCodeToString (status);

			if (status == OciGlue.OCI_ERROR || status == OciGlue.OCI_SUCCESS_WITH_INFO) {
				OciHandle h = hwnd;
				if (h == null)
					throw new Exception ("Internal driver error: handle is null.");
	
				ulong errbufSize = 4096;
				UIntPtr errbufSizep = new UIntPtr (errbufSize);
				IntPtr errbuf = OciCalls.AllocateClear ((int)errbufSize);

				OciCalls.OCIErrorGet (hwnd,
					1,
					IntPtr.Zero,
					out info.ErrorCode,
					errbuf,
					(uint) errbufSize,
					OciHandleType.Error);

				byte[] bytea = new byte[errbufSize];
				Marshal.Copy (errbuf, bytea, 0, (int)errbufSize);
				errbufSize = 0;

				// first call to OCICharSetToUnicode gets the size
				OciCalls.OCICharSetToUnicode (h, null, bytea, ref errbufSizep);
				errbufSize = errbufSizep.ToUInt64 ();
				StringBuilder str = new StringBuilder ((int)errbufSize);

				// second call to OCICharSetToUnicode gets the string
				OciCalls.OCICharSetToUnicode (h, str, bytea, ref errbufSizep);

				string errmsg = String.Empty;
				if (errbufSize > 0) {
					errmsg = str.ToString ();
					info.ErrorMessage = String.Copy (errmsg);
				}
				Marshal.FreeHGlobal (errbuf);
			}
			return info;
		}
예제 #11
0
		private void GetOutValue (OracleCommand cmd)
		{
			// used to update the parameter value
			// for Output, the output of InputOutput, and Return parameters
			value = DBNull.Value;
			if (indicator == -1)
				return;

			ulong rsize = 0;
			UIntPtr rsizep = new UIntPtr (rsize);
			IntPtr env = IntPtr.Zero;
			StringBuilder ret = null;

			// FIXME: redo all types - see how Char, Number, and Date are done
			// here and in Bind()

			switch (ociType) {
			case OciDataType.VarChar2:
			case OciDataType.String:
			case OciDataType.VarChar:
			case OciDataType.Char:
			case OciDataType.CharZ:
			case OciDataType.OciString:
			case OciDataType.RowIdDescriptor:
				// Get length of returned string
				rsize = 0;
				env = cmd.Connection.Environment;
				OciCalls.OCICharSetToUnicode (env, null, bytes, ref rsizep);

				// Get string
				rsize = rsizep.ToUInt64 ();
				ret = new StringBuilder((int)rsize);
				OciCalls.OCICharSetToUnicode (env, ret, bytes, ref rsizep);

				value = ret.ToString ();
				break;
			case OciDataType.Long:
			case OciDataType.LongVarChar:
				int longSize = 0;
				if (BitConverter.IsLittleEndian)
					longSize = BitConverter.ToInt32 (new byte [] {bytes [0], bytes [1], bytes [2], bytes [3]}, 0);
				else
					longSize = BitConverter.ToInt32 (new byte [] {bytes [3], bytes [2], bytes [1], bytes [0]}, 0);

				ASCIIEncoding encoding = new ASCIIEncoding ();
				value = encoding.GetString (bytes, 4, longSize);
				encoding = null;
				break;
			case OciDataType.LongRaw:
			case OciDataType.LongVarRaw:
				int longrawSize = 0;
				if (BitConverter.IsLittleEndian)
					longrawSize = BitConverter.ToInt32 (new byte [] {bytes [0], bytes [1], bytes [2], bytes [3]}, 0);
				else
					longrawSize = BitConverter.ToInt32 (new byte [] {bytes [3], bytes [2], bytes [1], bytes [0]}, 0);

				byte[] longraw_buffer = new byte [longrawSize];
				Array.ConstrainedCopy (bytes, 4, longraw_buffer, 0, longrawSize);
				value = longraw_buffer;
				break;
			case OciDataType.Raw:
			case OciDataType.VarRaw:
				int rawSize = 0;
				if (BitConverter.IsLittleEndian)
					rawSize = (int) BitConverter.ToInt16 (new byte [] {bytes [0], bytes [1]}, 0);
				else
					rawSize = (int) BitConverter.ToInt16 (new byte [] {bytes [1], bytes [0]}, 0);

				byte[] raw_buffer = new byte [rawSize];
				Array.ConstrainedCopy (bytes, 2, raw_buffer, 0, rawSize);
				value = raw_buffer;
				break;
			case OciDataType.Integer:
			case OciDataType.Number:
			case OciDataType.Float:
				rsize = 0;
				env = cmd.Connection.Environment;
				OciCalls.OCICharSetToUnicode (env, null, bytes, ref rsizep);

				// Get string
				rsize = rsizep.ToUInt64 ();
				ret = new StringBuilder((int)rsize);
				OciCalls.OCICharSetToUnicode (env, ret, bytes, ref rsizep);

				// if not empty, parse string as a decimal using session format
				if (ret.Length > 0) {
					switch (dbType) {
					case DbType.UInt16: 
						value = UInt16.Parse (ret.ToString (), cmd.Connection.SessionFormatProvider);
						break;
					case DbType.UInt32: 
						value = UInt32.Parse (ret.ToString (), cmd.Connection.SessionFormatProvider);
						break;
					case DbType.Int16:
						value = Int16.Parse (ret.ToString (), cmd.Connection.SessionFormatProvider);
						break;							
					case DbType.Int32:
						value = Int32.Parse (ret.ToString (), cmd.Connection.SessionFormatProvider);
						break;
					default:
						value = Decimal.Parse (ret.ToString (), cmd.Connection.SessionFormatProvider);
						break;
					}
				}
				break;
			case OciDataType.TimeStamp:
				value = dateTimeDesc.GetDateTime (connection.Environment, dateTimeDesc.ErrorHandle);
				break;
			case OciDataType.Date:
				value = UnpackDate (bytes);
				break;
			case OciDataType.Blob:
			case OciDataType.Clob:
				if (value != null && value is OracleLob && value != OracleLob.Null) {
					OracleLob lob2 = (OracleLob) value;
					lob2.connection = connection;
				}
				else {
					OracleLob lob = new OracleLob (lobLocator, ociType);
					lob.connection = connection;
					value = lob;
				}
				break;
			case OciDataType.RSet: // REF CURSOR				
				OciStatementHandle cursorStatement = GetOutRefCursor (cmd);
				value = new OracleDataReader (cursorStatement.Command, cursorStatement, true, CommandBehavior.Default);
				break;
			default:
				throw new NotImplementedException ("Data Type not implemented: " + ociType.ToString() + ".");
			}
		}
예제 #12
0
        private static void VerifyPointer(UIntPtr ptr, ulong expected)
        {
            Assert.Equal(expected, ptr.ToUInt64());

            uint expected32 = (uint)expected;
            if (expected32 != expected)
            {
                Assert.Throws<OverflowException>(() => ptr.ToUInt32());
                return;
            }

            Assert.Equal(expected32, ptr.ToUInt32());

            Assert.Equal(expected.ToString(), ptr.ToString());

            Assert.Equal(ptr, new UIntPtr(expected));
            Assert.True(ptr == new UIntPtr(expected));
            Assert.False(ptr != new UIntPtr(expected));

            Assert.NotEqual(ptr, new UIntPtr(expected + 1));
            Assert.False(ptr == new UIntPtr(expected + 1));
            Assert.True(ptr != new UIntPtr(expected + 1));
        }
예제 #13
0
        private static bool[] GetBooleanArrayFromPtr(IntPtr ptr, UIntPtr size)
        {
            int iSize = (int)size.ToUInt64();

            bool[] bArr = new bool[iSize];
            for (int i = 0; i < iSize; i++)
            {
                IntPtr data = new IntPtr(ptr.ToInt64() + sizeof(int) * i);
                bArr[i] = (int)Marshal.PtrToStructure(data, typeof(int)) != 0;
            }
            return bArr;
        }
예제 #14
0
 //Must be null terminated
 internal static byte[] ReadUTF8StringToByteArray(IntPtr str, UIntPtr size)
 {
     int iSize = (int)size.ToUInt64();
     byte[] data = new byte[iSize];
     Marshal.Copy(str, data, 0, iSize);
     return data;
 }
예제 #15
0
 /// <summary>
 /// Get the free and total amount of GPU memory on the current devide
 /// </summary>
 /// <param name="free">The free amount of GPU memory</param>
 /// <param name="total">The total amount of GPU memory</param>
 public static void GetGpuMemInfo(out ulong free, out ulong total)
 {
     UIntPtr f = new UIntPtr(), t = new UIntPtr();
      getGpuMemInfo(ref f, ref t);
      free = f.ToUInt64();
      total = t.ToUInt64();
 }
예제 #16
0
                internal object GetValue (IFormatProvider formatProvider, OracleConnection conn)
		{
			object tmp;

			byte [] buffer = null;

			switch (DataType) {
			case OciDataType.VarChar2:
			case OciDataType.String:
			case OciDataType.VarChar:
			case OciDataType.Char:
			case OciDataType.CharZ:
			case OciDataType.OciString:
			case OciDataType.RowIdDescriptor:
				buffer = new byte [Size];
				Marshal.Copy (Value, buffer, 0, Size);

				// Get length of returned string
				ulong 	rsize = 0;
				UIntPtr rsizep = new UIntPtr (rsize);
				//IntPtr	env = Parent.Parent;	// Parent is statement, grandparent is environment
				IntPtr env = conn.Environment;
				int status = OciCalls.OCICharSetToUnicode (env, null, buffer, ref rsizep);
				OciErrorHandle.ThrowExceptionIfError (ErrorHandle, status);

				// Get string
				rsize = rsizep.ToUInt64 ();
				StringBuilder ret = new StringBuilder((int)rsize);
				status = OciCalls.OCICharSetToUnicode (env, ret, buffer, ref rsizep);
				OciErrorHandle.ThrowExceptionIfError (ErrorHandle, status);

				return ret.ToString ();
			case OciDataType.LongVarChar:
			case OciDataType.Long:
				buffer = new byte [LongVarCharMaxValue];
				Marshal.Copy (Value, buffer, 0, buffer.Length);

				int longSize = 0;
				if (BitConverter.IsLittleEndian)
					longSize = BitConverter.ToInt32 (new byte[]{buffer[0], buffer[1], buffer[2], buffer[3]}, 0);
				else
					longSize = BitConverter.ToInt32 (new byte[]{buffer[3], buffer[2], buffer[1], buffer[0]}, 0);

				ASCIIEncoding encoding = new ASCIIEncoding ();
				string e = encoding.GetString (buffer, 4, longSize);
				return e;
			case OciDataType.Integer:
			case OciDataType.Number:
			case OciDataType.Float:
			case OciDataType.VarNum:
			case OciDataType.UnsignedInt:
				tmp = Marshal.PtrToStringAnsi (Value, Size);
				if (tmp != null)
					return Decimal.Parse (String.Copy ((string) tmp), formatProvider);
				break;
			case OciDataType.TimeStamp:
				return dateTimeDesc.GetDateTime (conn.Environment, dateTimeDesc.ErrorHandle);
			case OciDataType.Date:
				return UnpackDate ();
			case OciDataType.Raw:
			case OciDataType.VarRaw:
				byte [] raw_buffer = new byte [Size];
				Marshal.Copy (Value, raw_buffer, 0, Size);
				return raw_buffer;
			case OciDataType.LongRaw:
			case OciDataType.LongVarRaw:
				buffer = new byte [LongVarRawMaxValue];
				Marshal.Copy (Value, buffer, 0, buffer.Length);

				int longrawSize = 0;
				if (BitConverter.IsLittleEndian)
					longrawSize = BitConverter.ToInt32 (new byte[]{buffer[0], buffer[1], buffer[2], buffer[3]}, 0);
				else
					longrawSize = BitConverter.ToInt32 (new byte[]{buffer[3], buffer[2], buffer[1], buffer[0]}, 0);

				byte[] longraw_buffer = new byte [longrawSize];
				Array.ConstrainedCopy (buffer, 4, longraw_buffer, 0, longrawSize);
				return longraw_buffer;
			case OciDataType.Blob:
			case OciDataType.Clob:
				return GetOracleLob ();
			case OciDataType.IntervalDayToSecond:
				return new OracleTimeSpan (intervalDesc.GetDayToSecond (conn.Environment, intervalDesc.ErrorHandle));
			case OciDataType.IntervalYearToMonth:
				return new OracleMonthSpan (intervalDesc.GetYearToMonth (conn.Environment, intervalDesc.ErrorHandle));
			default:
				throw new Exception("OciDataType not implemented: " + DataType.ToString ());
			}

			return DBNull.Value;
		}
예제 #17
0
		public static OciErrorInfo HandleError (OciHandle hand)
		{
			OciErrorInfo info;
			info.ErrorCode = 0;
			info.ErrorMessage = String.Empty;

			ulong errbufSize = 4096;
			UIntPtr errbufSizep = new UIntPtr (errbufSize);
			IntPtr errbuf = OciCalls.AllocateClear ((int)errbufSize);

			OciCalls.OCIErrorGet (hand,
				1,
				IntPtr.Zero,
				out info.ErrorCode,
				errbuf,
				(uint) errbufSize,
				OciHandleType.Error);

			byte[] bytea = new byte[errbufSize];
			Marshal.Copy (errbuf, bytea, 0, (int)errbufSize);
			errbufSize = 0;

			OciHandle h = hand.Parent;
			if (h == null)
				h = hand;
			if (h == null)
				throw new Exception ("Internal driver error: handle is null.");

			// first call to OCICharSetToUnicode gets the size
			OciCalls.OCICharSetToUnicode (h, null, bytea, ref errbufSizep);
			errbufSize = errbufSizep.ToUInt64 ();
			StringBuilder str = new StringBuilder ((int)errbufSize);

			// second call to OCICharSetToUnicode gets the string
			OciCalls.OCICharSetToUnicode (h, str, bytea, ref errbufSizep);

			string errmsg = String.Empty;
			if (errbufSize > 0)
				errmsg = str.ToString ();
			else
				errmsg = "Internal driver error. Could not retrieve error message.";

			info.ErrorMessage = String.Copy (errmsg);
			Marshal.FreeHGlobal (errbuf);

			return info;
		}
예제 #18
0
		internal void Bind (OciStatementHandle statement, OracleConnection con, uint pos)
		{
			connection = con;

			if (bindHandle == null)
				bindHandle = new OciBindHandle ((OciHandle) statement);

			IntPtr tmpHandle = bindHandle.Handle;

			if (Direction != ParameterDirection.Input)
				AssertSizeIsSet ();
			if (!sizeSet)
				size = InferSize ();

			bindSize = size;
			object v = value;
			int status = 0;
			bindType = ociType;
			ulong rsize = 0;
			UIntPtr rsizep = new UIntPtr (rsize);
			
			string svalue;
			string sDate;
			DateTime dt;
			bool isnull = false;
			int byteCount;
			byte[] byteArrayLen;

			if (direction == ParameterDirection.Input || direction == ParameterDirection.InputOutput) {
				if (v == null)
					isnull = true;
				else if (v is DBNull)
					isnull = true;
				else {
					INullable mynullable = v as INullable;
					if (mynullable != null)
						isnull = mynullable.IsNull;
				}					
			} 

			if (isnull == true && direction == ParameterDirection.Input) {
				indicator = 0;
				bindType = OciDataType.VarChar2;
				bindSize = 0;
			} else {
				switch(ociType) {
				case OciDataType.VarChar2:
				case OciDataType.String:
				case OciDataType.VarChar:
				case OciDataType.Char:
				case OciDataType.CharZ:
				case OciDataType.OciString:
					bindType = OciDataType.String;
					indicator = 0;
					svalue = "\0";
					// convert value from managed type to type to marshal
					if (direction == ParameterDirection.Input || 
						direction == ParameterDirection.InputOutput) {

						svalue = v.ToString ();

						if (direction == ParameterDirection.Input && size > 0 && svalue.Length > size)
							svalue = svalue.Substring(0, size);

						svalue = svalue.ToString () + '\0';
						
						// convert managed type to memory allocated earlier
						// in this case using OCIUnicodeToCharSet
						rsize = 0;
						// Get size of buffer
						status = OciCalls.OCIUnicodeToCharSet (statement.Parent, null, svalue, ref rsizep);
						rsize = rsizep.ToUInt64 ();
						if (direction == ParameterDirection.Input)
							bindSize = (int)rsize;
						else {
							// this cannot be rsize because you need room for the output after the execute
							bindSize = Encoding.UTF8.GetMaxByteCount (Size + 1);
						}

						// allocate memory based on bind size
						bytes = new byte [bindSize];

						// Fill buffer
						status = OciCalls.OCIUnicodeToCharSet (statement.Parent, bytes, svalue, ref rsizep);
					} else {
						// for Output and ReturnValue parameters, get size in bytes 					
						bindSize = Encoding.UTF8.GetMaxByteCount (size + 1);
						// allocate memory for oracle to place the results for the Return or Output param						
						bytes = new byte [bindSize];
					}
					break;
				case OciDataType.Date:
					bindType = OciDataType.Date;
					bindSize = 7;
					// convert value from managed type to type to marshal
					if (direction == ParameterDirection.Input || 
						direction == ParameterDirection.InputOutput) {

						if (isnull)
							bytes = new byte [7];
						else {
							sDate = "";
							dt = DateTime.MinValue;
							if (v is String) {
								sDate = (string) v;
								dt = DateTime.Parse (sDate);
							}
							else if (v is DateTime)
								dt = (DateTime) v;
							else if (v is OracleString) {
								sDate = v.ToString ();
								dt = DateTime.Parse (sDate);
							}
							else if (v is OracleDateTime) {
								OracleDateTime odt = (OracleDateTime) v;
								dt = (DateTime) odt.Value;
							}
							else
								throw new NotImplementedException ("For OracleType.DateTime, data type not implemented: " + v.GetType().ToString() + ".");

							// for Input and InputOuput, create byte array and pack DateTime into it
							bytes = PackDate (dt);
						}
					} else	{
						// allocate 7-byte array for Output and ReturnValue to put date
						bytes = new byte [7];
					}
					break;
				case OciDataType.TimeStamp:
					dateTimeDesc = (OciDateTimeDescriptor) connection.Environment.Allocate (OciHandleType.TimeStamp);
					if (dateTimeDesc == null) {
						OciErrorInfo info = connection.ErrorHandle.HandleError ();
						throw new OracleException (info.ErrorCode, info.ErrorMessage);
					}
					dateTimeDesc.ErrorHandle = connection.ErrorHandle;
					bindSize = 11;
					bindType = OciDataType.TimeStamp;
					bindOutValue = dateTimeDesc.Handle;
					bindValue = dateTimeDesc.Handle;
					useRef = true;
					if (direction == ParameterDirection.Input || 
						direction == ParameterDirection.InputOutput) {

						dt = DateTime.MinValue;
						sDate = "";
						if (isnull)
							indicator = -1;
						else if (v is String) {
							sDate = (string) v;
							dt = DateTime.Parse (sDate);
						}
						else if (v is DateTime)
							dt = (DateTime) v;
						else if (v is OracleString) {
							sDate = (string) v;
							dt = DateTime.Parse (sDate);
						}
						else if (v is OracleDateTime) {
							OracleDateTime odt = (OracleDateTime) v;
							dt = (DateTime) odt.Value;
						}
						else
							throw new NotImplementedException ("For OracleType.Timestamp, data type not implemented: " + v.GetType().ToString()); // ?

						short year = (short) dt.Year;
						byte month = (byte) dt.Month;
						byte day = (byte) dt.Day;
						byte hour = (byte) dt.Hour;
						byte min = (byte) dt.Minute;
						byte sec = (byte) dt.Second;
						uint fsec = (uint) dt.Millisecond;
						string timezone = "";
						dateTimeDesc.SetDateTime (connection.Session,
							connection.ErrorHandle,
							year, month, day, hour, min, sec, fsec,
							timezone);
					}
					break;
				case OciDataType.Integer:
				case OciDataType.Float:
				case OciDataType.Number:
					bindType = OciDataType.String;
					indicator = 0;
					svalue = "\0";
					// convert value from managed type to type to marshal
					if (direction == ParameterDirection.Input || 
						direction == ParameterDirection.InputOutput) {

						svalue = null;
						if(v is IFormattable)
							svalue = ((IFormattable)v).ToString (null, con.SessionFormatProvider);
						else if (v is OracleNumber)
							svalue = ((OracleNumber)v).ToString(con.SessionFormatProvider);
						else
							svalue = v.ToString();

						svalue = svalue + "\0";

						rsize = 0;
						// Get size of buffer
						OciCalls.OCIUnicodeToCharSet (statement.Parent, null, svalue, ref rsizep);

						// Fill buffer 
						rsize = rsizep.ToUInt64 ();
						if (direction == ParameterDirection.Input)
							bindSize = (int)rsize;
						else
							bindSize = 30; // need room for output possibly being bigger than the input
						
						bytes = new byte [bindSize];
						OciCalls.OCIUnicodeToCharSet (statement.Parent, bytes, svalue, ref rsizep);
					} else {
						// Output and ReturnValue parameters allocate memory
						bindSize = 30;
						bytes = new byte [bindSize];
					} 
					break;
				case OciDataType.Long:
				case OciDataType.LongVarChar:
					bindType = OciDataType.LongVarChar;

					// FIXME: use piecewise fetching for Long, Clob, Blob, and Long Raw
					// See http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14250/oci05bnd.htm#sthref724
					
					bindSize = Size + 5; // 4 bytes prepended for length, bytes, 1 byte NUL character

					indicator = 0;
					svalue = "\0";
					// convert value from managed type to type to marshal
					if (direction == ParameterDirection.Input || 
						direction == ParameterDirection.InputOutput) {

						svalue = v.ToString () + '\0';
					}

					bytes = new byte [bindSize];
					// LONG is only ANSI 
					ASCIIEncoding enc = new ASCIIEncoding ();
					
					if (direction == ParameterDirection.Input || 
						direction == ParameterDirection.InputOutput) {
						if (svalue.Length > 0) {	
							byteCount = enc.GetBytes (svalue, 4, svalue.Length, bytes, 0);
							// LONG VARCHAR prepends a 4-byte length
							if (byteCount > 0) {
								byteArrayLen = BitConverter.GetBytes ((uint) byteCount);
								bytes[0] = byteArrayLen[0];
								bytes[1] = byteArrayLen[1];
								bytes[2] = byteArrayLen[2];
								bytes[3] = byteArrayLen[3];
							}
						}
					}
					break;
				case OciDataType.Clob:
					if (direction == ParameterDirection.Input) {
						svalue = v.ToString();
						rsize = 0;

						// Get size of buffer
						OciCalls.OCIUnicodeToCharSet (statement.Parent, null, svalue, ref rsizep);

						// Fill buffer
						rsize = rsizep.ToUInt64 ();
						bytes = new byte[rsize];
						OciCalls.OCIUnicodeToCharSet (statement.Parent, bytes, svalue, ref rsizep);

						bindType = OciDataType.Long;
						bindSize = bytes.Length;
					} 
					else if (direction == ParameterDirection.InputOutput) {
						// not the exact error that .net 2.0 throws, but this is better
						throw new NotImplementedException ("Parameters of OracleType.Clob with direction of InputOutput are not supported.");
					}
					else {
						// Output and Return parameters
						bindSize = -1;
						lobLocator = (OciLobLocator) connection.Environment.Allocate (OciHandleType.LobLocator);
						if (lobLocator == null) {
							OciErrorInfo info = connection.ErrorHandle.HandleError ();
							throw new OracleException (info.ErrorCode, info.ErrorMessage);
						}
						bindOutValue = lobLocator.Handle;
						bindValue = lobLocator.Handle;
						lobLocator.ErrorHandle = connection.ErrorHandle;
						lobLocator.Service = statement.Service;
						lobLocator.Environment = connection.Environment;
						useRef = true;
					}
					break;
				case OciDataType.Blob:
					if (direction == ParameterDirection.Input) {
						if (v is byte[]) {
							bytes = (byte[]) v;
							bindType = OciDataType.LongRaw;
							bindSize = bytes.Length;
						}
						else if (v is OracleLob) {
							OracleLob lob = (OracleLob) v;
							if (lob.LobType == OracleType.Blob) {
								lobLocator = lob.Locator;
								bindOutValue = lobLocator.Handle;
								bindValue = lobLocator.Handle;
								lobLocator.ErrorHandle = connection.ErrorHandle;
								lobLocator.Service = connection.ServiceContext;
								useRef = true;
							}
							else
								throw new NotImplementedException("For OracleType.Blob, data type OracleLob of LobType Clob/NClob is not implemented.");
						}
						else
							throw new NotImplementedException ("For OracleType.Blob, data type not implemented: " + v.GetType().ToString()); // ?
					}
					else if (direction == ParameterDirection.InputOutput) {
						// not the exact error that .net 2.0 throws, but this is better
						throw new NotImplementedException ("Parameters of OracleType.Blob with direction of InputOutput are not supported.");
					}
					else {
						bindSize = -1;
						if (value != null && value is OracleLob) {
							OracleLob blob = (OracleLob) value;
							if (blob.LobType == OracleType.Blob)
								if (value != OracleLob.Null) {
									lobLocator = blob.Locator;
									byte[] bs = (byte[]) blob.Value;
									bindSize = bs.Length;
								}
						}
						if (lobLocator == null) {
							lobLocator = (OciLobLocator) connection.Environment.Allocate (OciHandleType.LobLocator);
							if (lobLocator == null) {
								OciErrorInfo info = connection.ErrorHandle.HandleError ();
								throw new OracleException (info.ErrorCode, info.ErrorMessage);
							}
						}
						bindOutValue = lobLocator.Handle;
						bindValue = lobLocator.Handle;
						lobLocator.ErrorHandle = connection.ErrorHandle;
						lobLocator.Service = connection.ServiceContext;
						lobLocator.Environment = connection.Environment;
						useRef = true;
					}
					break;
				case OciDataType.Raw:
				case OciDataType.VarRaw:
					bindType = OciDataType.VarRaw;
					bindSize = Size + 2; // include 2 bytes prepended to hold the length
					indicator = 0;
					bytes = new byte [bindSize];
					if (direction == ParameterDirection.Input || 
						direction == ParameterDirection.InputOutput) {
						byteCount = 0;
						byte[] val;
						if (dbType == DbType.Guid)
							val = ((Guid)v).ToByteArray();
						else
							val = v as byte[];
						if (val.Length > 0) {	
							byteCount = val.Length;
							// LONG VARRAW prepends a 4-byte length
							if (byteCount > 0) {
								byteArrayLen = BitConverter.GetBytes ((ushort) byteCount);
								bytes[0] = byteArrayLen[0];
								bytes[1] = byteArrayLen[1];
								Array.ConstrainedCopy (val, 0, bytes, 2, byteCount);
							}
						}
					}
					break;
				case OciDataType.LongRaw:
				case OciDataType.LongVarRaw:
					bindType = OciDataType.LongVarRaw;
					bindSize = Size + 4; // include 4 bytes prepended to hold the length
					indicator = 0;
					bytes = new byte [bindSize];
					if (direction == ParameterDirection.Input || 
						direction == ParameterDirection.InputOutput) {
						byteCount = 0;
						byte[] val = v as byte[];
						if (val.Length > 0) {	
							byteCount = val.Length;
							// LONG VARRAW prepends a 4-byte length
							if (byteCount > 0) {
								byteArrayLen = BitConverter.GetBytes ((uint) byteCount);
								bytes[0] = byteArrayLen[0];
								bytes[1] = byteArrayLen[1];
								bytes[2] = byteArrayLen[2];
								bytes[3] = byteArrayLen[3];
								Array.ConstrainedCopy (val, 0, bytes, 4, byteCount);
							}
						}
					}
					break;
				case OciDataType.RowIdDescriptor:
					if (direction == ParameterDirection.Output || 
						direction == ParameterDirection.InputOutput || 
						direction == ParameterDirection.ReturnValue) {

					size = 10;
					bindType = OciDataType.Char;
					bindSize = size * 2;
					bindOutValue = OciCalls.AllocateClear (bindSize);
					bindValue = bindOutValue;
					} else
						throw new NotImplementedException("data type RowIdDescriptor as Intput parameters");
					break;
				case OciDataType.RSet: // REF CURSOR
					if (direction == ParameterDirection.Output || 
						direction == ParameterDirection.InputOutput || 
						direction == ParameterDirection.ReturnValue) {

						cursor = IntPtr.Zero;
						OciCalls.OCIHandleAlloc (connection.Environment,
							out cursor,
							OciHandleType.Statement,
							0,
							IntPtr.Zero);
							bindSize = 0;
						bindType = OciDataType.RSet;
					} else
						throw new NotImplementedException ("data type Ref Cursor not implemented for Input parameters");
					break;
				default:
					throw new NotImplementedException ("Data Type not implemented: " + ociType.ToString() + ".");
				}			
			}
			
			// Now, call the appropriate OCI Bind function;

			if (useRef == true) {
				if (bindType == OciDataType.TimeStamp) {
					bindValue = dateTimeDesc.Handle;
					status = OciCalls.OCIBindByNameRef (statement,
						out tmpHandle,
						connection.ErrorHandle,
						ParameterName,
						ParameterName.Length,
						ref bindValue,
						bindSize,
						bindType,
						ref indicator,
						IntPtr.Zero,
						IntPtr.Zero,
						0,
						IntPtr.Zero,
						0);
				}
				else {
					status = OciCalls.OCIBindByNameRef (statement,
						out tmpHandle,
						connection.ErrorHandle,
						ParameterName,
						ParameterName.Length,
						ref bindValue,
						bindSize,
						bindType,
						ref indicator,
						IntPtr.Zero,
						IntPtr.Zero,
						0,
						IntPtr.Zero,
						0);
				}
			}
			else if (bindType == OciDataType.RSet) {
				status = OciCalls.OCIBindByNameRef (statement,
					out tmpHandle,
					connection.ErrorHandle,
					ParameterName,
					ParameterName.Length,
					ref cursor,
					bindSize,
					bindType,
					ref indicator,
					IntPtr.Zero,
					IntPtr.Zero,
					0,
					IntPtr.Zero,
					0);
			}
			else if (bytes != null) {
				status = OciCalls.OCIBindByNameBytes (statement,
					out tmpHandle,
					connection.ErrorHandle,
					ParameterName,
					ParameterName.Length,
					bytes,
					bindSize,
					bindType,
					ref indicator,
					IntPtr.Zero,
					IntPtr.Zero,
					0,
					IntPtr.Zero,
					0);
			}
			else {
				status = OciCalls.OCIBindByName (statement,
					out tmpHandle,
					connection.ErrorHandle,
					ParameterName,
					ParameterName.Length, // FIXME: this should be in bytes!
					bindValue,
					bindSize,
					bindType,
					ref indicator,
					IntPtr.Zero,
					IntPtr.Zero,
					0,
					IntPtr.Zero,
					0);
			}
			OciErrorHandle.ThrowExceptionIfError (connection.ErrorHandle, status);

			bindHandle.SetHandle (tmpHandle);
		}
예제 #19
0
        public static IEnumerable<_Disasm> Disassemble(byte[] data, UIntPtr address, Architecture architecture)
        {
            GCHandle h = GCHandle.Alloc(data, GCHandleType.Pinned);
            UInt64 EndCodeSection = (UInt64)h.AddrOfPinnedObject().ToInt64() + (ulong)data.Length;

            _Disasm d = new _Disasm();
            d.InstructionPointer = (UIntPtr)h.AddrOfPinnedObject().ToInt64();
            d.VirtualAddr = address.ToUInt64();
            d.Architecture = architecture;
            bool error = false;
            while (!error)
            {
                d.SecurityBlock = (uint)(EndCodeSection - d.InstructionPointer.ToUInt64());

                d.Length = BeaEngine.Disassemble(ref d);
                if (d.Length == BeaEngine.OutOfBlock)
                {
                    Console.WriteLine("disasm engine is not allowed to read more memory.");
                    error = true;
                }
                else if (d.Length == BeaEngine.UnknownOpcode)
                {
                    _Disasm yieldedInst = d;
                    d.InstructionPointer = d.InstructionPointer + 1;
                    d.VirtualAddr = d.VirtualAddr + 1;
                    yield return yieldedInst;
                }
                else
                {
                    _Disasm yieldedInst = d;
                    d.InstructionPointer = d.InstructionPointer + d.Length;
                    d.VirtualAddr = d.VirtualAddr + (ulong)d.Length;
                    if (d.InstructionPointer.ToUInt64() >= EndCodeSection)
                    {
                        error = true;
                    }

                    yield return yieldedInst;
                }
            }

            yield break;
        }
예제 #20
0
        internal static long ConverToLong(UIntPtr len)
        {
            if (len.ToUInt64() > long.MaxValue)
            {
                throw new InvalidOperationException(
                    string.Format(
                        CultureInfo.InvariantCulture,
                        "Provided length ({0}) exceeds long.MaxValue ({1}).",
                        len.ToUInt64(), long.MaxValue));
            }

            return (long)len.ToUInt64();
        }
예제 #21
0
 public override void EnumCodeContextsOfPosition(UIntPtr sourceContext, uint offset, uint length, out IEnumDebugCodeContexts enumContexts)
 {
     var del = RawCOMHelpers.GetMethodDelegate<RawEnumCodeContextsOfPosition>(pActiveScriptDebug, 5);
     RawCOMHelpers.HResult.Check(del(pActiveScriptDebug, sourceContext.ToUInt64(), offset, length, out enumContexts));
 }
예제 #22
0
 internal static byte[] GetRawDataFromPtr(IntPtr ptr, UIntPtr size)
 {
     int len = (int)size.ToUInt64();
     byte[] data = new byte[len];
     Marshal.Copy(ptr, data, 0, len);
     return data;
 }
예제 #23
0
        private UIntPtr OnAiFileWriteProc(IntPtr file, IntPtr dataToWrite, UIntPtr sizeOfElemInBytes, UIntPtr numElements)
        {
            if(m_filePtr != file)
                return UIntPtr.Zero;

            long longSize = (long) sizeOfElemInBytes.ToUInt64();
            long longNum = (long) numElements.ToUInt64();
            long count = longSize * longNum;

            byte[] byteBuffer = GetByteBuffer(longSize, longNum);
            MemoryHelper.Read<byte>(dataToWrite, byteBuffer, 0, (int) count);

            long actualCount = 0;

            try
            {
                actualCount = Write(byteBuffer, count);
            }
            catch(Exception) { /*Assimp will report an IO error*/ }

            return new UIntPtr((ulong) actualCount);
        }
예제 #24
0
 //Must be null terminated
 internal static string ReadUTF8String(IntPtr str, UIntPtr size)
 {
     int iSize = (int)size.ToUInt64();
     byte[] data = new byte[iSize];
     Marshal.Copy(str, data, 0, iSize);
     return Encoding.UTF8.GetString(data);
 }
예제 #25
0
		// Get NLS Info
		//
		// handle = OciEnvironmentHandle or OciSessionHandle
		// bufflen = Length of byte buffer to allocate to retrieve the NLS info
		// item = OciNlsServiceType enum value
		//
		// if unsure how much you need, use OciNlsServiceType.MAXBUFSZ
		internal string GetNlsInfo (OciHandle handle, uint bufflen, OciNlsServiceType item)
		{
			byte[] buffer = new Byte[bufflen];

			OciCalls.OCINlsGetInfo (handle, ErrorHandle, 
				ref buffer, bufflen, (ushort) item);

			// Get length of returned string
			ulong rsize = 0;
			UIntPtr rsizep = new UIntPtr (rsize);
			OciCalls.OCICharSetToUnicode (Environment, null, buffer, ref rsizep);
			
			// Get string
			rsize = rsizep.ToUInt64 ();
			StringBuilder ret = new StringBuilder ((int)rsize);
			OciCalls.OCICharSetToUnicode (Environment, ret, buffer, ref rsizep);

			return ret.ToString ();
		}
예제 #26
0
        private static bool[] GetBooleanArrayFromPtr(IntPtr ptr, UIntPtr size)
        {
            int iSize = (int)size.ToUInt64();

            bool[] bArr = new bool[iSize];
            for (int i = 0; i < iSize; i++)
            {
                bArr[i] = Marshal.ReadInt32(ptr, sizeof(int) * i) != 0;
            }
            return bArr;
        }
예제 #27
0
            private static unsafe int Write(
                IntPtr stream,
                IntPtr buffer,
                UIntPtr len)
            {
                OdbBackendStream odbBackendStream = GCHandle.FromIntPtr(Marshal.ReadIntPtr(stream, GitOdbBackendStream.GCHandleOffset)).Target as OdbBackendStream;

                if (odbBackendStream != null &&
                    len.ToUInt64() < long.MaxValue)
                {
                    long length = (long)len.ToUInt64();

                    using (UnmanagedMemoryStream dataStream = new UnmanagedMemoryStream((byte*)buffer, length))
                    {
                        try
                        {
                            return odbBackendStream.Write(dataStream, length);
                        }
                        catch (Exception ex)
                        {
                            Proxy.giterr_set_str(GitErrorCategory.Odb, ex);
                        }
                    }
                }

                return (int)GitErrorCode.Error;
            }
예제 #28
0
 private static double[] GetDoubleArrayFromPtr(IntPtr ptr, UIntPtr size)
 {
     double[] arr = new double[size.ToUInt64()];
     Marshal.Copy(ptr, arr, 0, arr.Length);
     return arr;
 }
예제 #29
0
            private static int WriteStream(
                out IntPtr stream_out,
                IntPtr backend,
                UIntPtr length,
                Core.GitObjectType type)
            {
                stream_out = IntPtr.Zero;

                OdbBackend odbBackend = GCHandle.FromIntPtr(Marshal.ReadIntPtr(backend, GitOdbBackend.GCHandleOffset)).Target as OdbBackend;

                ObjectType objectType = type.ToObjectType();

                if (odbBackend != null &&
                    length.ToUInt64() < long.MaxValue)
                {
                    OdbBackendStream stream;

                    try
                    {
                        int toReturn = odbBackend.WriteStream((long)length.ToUInt64(), objectType, out stream);

                        if (0 == toReturn)
                        {
                            stream_out = stream.GitOdbBackendStreamPointer;
                        }

                        return toReturn;
                    }
                    catch (Exception ex)
                    {
                        Proxy.giterr_set_str(GitErrorCategory.Odb, ex);
                    }
                }

                return (int)GitErrorCode.Error;
            }
예제 #30
0
        private static string[] GetStringArrayFromPtr(IntPtr ptr, UIntPtr size)
        {
            int ntStringSize = Marshal.SizeOf(typeof(NtStringRead));
            int arraySize = (int)size.ToUInt64();
            string[] strArray = new string[arraySize];

            for (int i = 0; i < arraySize; i++)
            {
                IntPtr data = new IntPtr(ptr.ToInt64() + ntStringSize * i);
                strArray[i] = Marshal.PtrToStructure(data, typeof(NtStringRead)).ToString();
            }
            return strArray;
        }