コード例 #1
0
        /// <summary>
        /// Protects the given object from GCing
        /// </summary>
        /// <param name="obj">Object.</param>
        public void Protect(object obj)
        {
            // send request
            var req = new CLRProtectMessage(obj);

            CLRMessage.Write(_cout, req);
        }
コード例 #2
0
        /// <summary>
        /// Releases object for GCing
        /// </summary>
        /// <param name="obj">Object.</param>
        public void Release(object obj)
        {
            // send request
            var req = new CLRReleaseMessage(obj);

            CLRMessage.Write(_cout, req);
        }
コード例 #3
0
        /// <summary>
        /// Gets the named property
        /// </summary>
        /// <param name='type'>
        /// Type.
        /// </param>
        /// <param name='name'>
        /// Name.
        /// </param>
        public object GetProperty(object obj, string name)
        {
            // send request
            var req = new CLRGetPropertyMessage(obj, name);

            CLRMessage.Write(_cout, req);

            // get response
            return(CLRMessage.ReadValue(_cin));
        }
コード例 #4
0
        /// <summary>
        /// Gets the ith element of collection
        /// </summary>
        /// <param name='type'>
        /// Type.
        /// </param>
        /// <param name='ith'>
        /// Index.
        /// </param>
        public object GetIndexed(object obj, int ith)
        {
            // send request
            var req = new CLRGetIndexedMessage(obj, ith);

            CLRMessage.Write(_cout, req);

            // get response
            return(CLRMessage.ReadValue(_cin));
        }
コード例 #5
0
        /// <summary>
        /// Gets the named property
        /// </summary>
        /// <param name='classname'>
        /// class name
        /// </param>
        /// <param name='name'>
        /// Name.
        /// </param>
        public object GetStaticProperty(string classname, string name)
        {
            // send request
            var req = new CLRGetStaticPropertyMessage(classname, name);

            CLRMessage.Write(_cout, req);

            // get response
            return(CLRMessage.ReadValue(_cin));
        }
コード例 #6
0
        /// <summary>
        /// Sets the named property
        /// </summary>
        /// <param name='classname'>
        /// class name
        /// </param>
        /// <param name='name'>
        /// Name.
        /// </param>
        /// <param val='value'>
        /// property value
        /// </param>
        public void SetStaticProperty(string classname, string name, object val)
        {
            // send request
            var req = new CLRSetStaticPropertyMessage(classname, name, val);

            CLRMessage.Write(_cout, req);

            // get response (to make sure is not an exception)
            CLRMessage.ReadValue(_cin);
        }
コード例 #7
0
        // Operations


        /// <summary>
        /// Creates a new object of given classname
        /// </summary>
        /// <param name="classname">Classname.</param>
        /// <param name="parameters">Parameters.</param>
        public object Create(string classname, params object[] parameters)
        {
            // send request
            var req = new CLRCreateMessage(classname, parameters);

            CLRMessage.Write(_cout, req);

            // get response
            return(CLRMessage.ReadValue(_cin));
        }
コード例 #8
0
        /// <summary>
        /// Calls the named method, finding the one with the best match
        /// </summary>
        /// <returns>
        /// The return of static method call
        /// </returns>
        /// <param name='type'>
        /// Type.
        /// </param>
        /// <param name='name'>
        /// Name.
        /// </param>
        /// <param name='parameters'>
        /// Parameters.
        /// </param>
        public object CallMethod(object obj, string name, params object[] parameters)
        {
            // send request
            var req = new CLRCallMethodMessage(obj, name, parameters);

            CLRMessage.Write(_cout, req);

            // get response
            return(CLRMessage.ReadValue(_cin));
        }
コード例 #9
0
        /// <summary>
        /// Calls the named static method.
        /// </summary>
        /// <returns>
        /// The return of static method call
        /// </returns>
        /// <param name='classname'>
        /// class name.
        /// </param>
        /// <param name='method'>
        /// Method name.
        /// </param>
        /// <param name='parameters'>
        /// Parameters.
        /// </param>
        public object CallStaticMethodByName(string classname, string method, params object[] parameters)
        {
            // send request
            var req = new CLRCallStaticMethodMessage(classname, method, parameters);

            CLRMessage.Write(_cout, req);

            // get response
            return(CLRMessage.ReadValue(_cin));
        }
コード例 #10
0
 /// <summary>
 /// Handles the template request
 /// </summary>
 /// <param name="req">Req.</param>
 private void HandleTemplate(CLRTemplateReqMessage req)
 {
     try
     {
         var type = ReflectUtils.FindType(req.ClassName);
         CLRMessage.Write(_cout, new CLRTemplateReplyMessage(type));
     }
     catch (Exception e)
     {
         CLRMessage.WriteValue(_cout, e);
     }
 }
コード例 #11
0
 /// <summary>
 /// Calls a static method.
 /// </summary>
 /// <param name="req">Req.</param>
 private void HandleCallStaticMethod(CLRCallStaticMethodMessage req)
 {
     try
     {
         var obj = _api.CallStaticMethodByName(req.ClassName, req.MethodName, req.Parameters);
         CLRMessage.WriteValue(_cout, obj);
     }
     catch (TargetInvocationException te)
     {
         CLRMessage.WriteValue(_cout, te.GetBaseException());
     }
     catch (Exception e)
     {
         CLRMessage.WriteValue(_cout, e);
     }
 }
コード例 #12
0
 /// <summary>
 /// Gets static property on class.
 /// </summary>
 /// <param name="req">Req.</param>
 private void HandleGetStaticProperty(CLRGetStaticPropertyMessage req)
 {
     try
     {
         // invoke
         var result = _api.GetStaticProperty(req.ClassName, req.PropertyName);
         CLRMessage.WriteValue(_cout, result);
     }
     catch (TargetInvocationException te)
     {
         CLRMessage.WriteValue(_cout, te.GetBaseException());
     }
     catch (Exception e)
     {
         CLRMessage.WriteValue(_cout, e);
     }
 }
コード例 #13
0
 /// <summary>
 /// Sets static property on class.
 /// </summary>
 /// <param name="req">Req.</param>
 private void HandleSetStaticProperty(CLRSetStaticPropertyMessage req)
 {
     try
     {
         // invoke
         _api.SetProperty(req.ClassName, req.PropertyName, req.Value);
         CLRMessage.WriteValue(_cout, null);
     }
     catch (TargetInvocationException te)
     {
         CLRMessage.WriteValue(_cout, te.GetBaseException());
     }
     catch (Exception e)
     {
         CLRMessage.WriteValue(_cout, e);
     }
 }
コード例 #14
0
 /// <summary>
 /// Calls a method.
 /// </summary>
 /// <param name="req">Req.</param>
 private void HandleCallMethod(CLRCallMethodMessage req)
 {
     try
     {
         // get object
         var obj = ToLocalObject(req.Obj);
         // invoke
         var result = _api.CallMethod(obj, req.MethodName, req.Parameters);
         CLRMessage.WriteValue(_cout, result);
     }
     catch (TargetInvocationException te)
     {
         CLRMessage.WriteValue(_cout, te.GetBaseException());
     }
     catch (Exception e)
     {
         CLRMessage.WriteValue(_cout, e);
     }
 }
コード例 #15
0
 /// <summary>
 /// Sets property on object.
 /// </summary>
 /// <param name="req">Req.</param>
 private void HandleSetProperty(CLRSetPropertyMessage req)
 {
     try
     {
         // get object
         var obj = ToLocalObject(req.Obj);
         // invoke
         _api.SetProperty(obj, req.PropertyName, req.Value);
         CLRMessage.WriteValue(_cout, null);
     }
     catch (TargetInvocationException te)
     {
         CLRMessage.WriteValue(_cout, te.GetBaseException());
     }
     catch (Exception e)
     {
         CLRMessage.WriteValue(_cout, e);
     }
 }
コード例 #16
0
 /// <summary>
 /// Gets the indexed value on an object
 /// </summary>
 /// <param name="req">Req.</param>
 private void HandleGetIndexed(CLRGetIndexedMessage req)
 {
     try
     {
         // get object
         var obj = ToLocalObject(req.Obj);
         // invoke
         var result = _api.GetIndexed(obj, req.Index);
         CLRMessage.WriteValue(_cout, result);
     }
     catch (TargetInvocationException te)
     {
         CLRMessage.WriteValue(_cout, te.GetBaseException());
     }
     catch (Exception e)
     {
         CLRMessage.WriteValue(_cout, e);
     }
 }
コード例 #17
0
        /// <summary>
        /// Serlializes a value.
        /// </summary>
        /// <param name="cout">Cout.</param>
        /// <param name="val">Value.</param>
        internal static void SerializeValue(IBinaryWriter cout, object val)
        {
            CLRMessage msg = null;

            switch (TypeOf(val))
            {
            case TypeNull:
                msg = new CLRNullMessage();
                break;

            case TypeBool:
                msg = new CLRBoolMessage(Convert.ToBoolean(val));
                break;

            case TypeByte:
                msg = new CLRByteMessage(Convert.ToByte(val));
                break;

            case TypeInt32:
                msg = new CLRInt32Message(Convert.ToInt32(val));
                break;

            case TypeInt64:
                msg = new CLRInt64Message(Convert.ToInt64(val));
                break;

            case TypeReal64:
                msg = new CLRReal64Message(Convert.ToDouble(val));
                break;

            case TypeString:
                msg = new CLRStringMessage((string)val);
                break;

            case TypeObject:
                msg = new CLRObjectMessage(val);
                break;

            case TypeBoolArray:
                msg = new CLRBoolArrayMessage((bool[])val);
                break;

            case TypeByteArray:
                msg = new CLRByteArrayMessage((byte[])val);
                break;

            case TypeInt32Array:
                msg = new CLRInt32ArrayMessage((int[])val);
                break;

            case TypeInt64Array:
                msg = new CLRInt64ArrayMessage((long[])val);
                break;

            case TypeReal64Array:
                msg = new CLRReal64ArrayMessage((double[])val);
                break;

            case TypeStringArray:
                msg = new CLRStringArrayMessage((string[])val);
                break;

            case TypeObjectArray:
                msg = new CLRObjectArrayMessage((object[])val);
                break;

            case TypeVector:
                msg = new CLRVectorMessage((Vector <double>)val);
                break;

            case TypeMatrix:
                msg = new CLRMatrixMessage((Matrix <double>)val);
                break;

            case TypeException:
                msg = new CLRExceptionMessage(val);
                break;

            default:
                throw new ArgumentException("do not know how to serialize: " + val.GetType());
            }

            msg.Serialize(cout);
        }
コード例 #18
0
        /// <summary>
        /// Service loop.
        /// </summary>
        private void Service()
        {
            CLRMessage msg = null;

            try
            {
                while ((msg = CLRMessage.Read(_cin)) != null)
                {
                    switch (msg.MessageType)
                    {
                    case CLRMessage.TypeCreate:
                        HandleCreate(msg as CLRCreateMessage);
                        break;

                    case CLRMessage.TypeCallStaticMethod:
                        HandleCallStaticMethod(msg as CLRCallStaticMethodMessage);
                        break;

                    case CLRMessage.TypeCallMethod:
                        HandleCallMethod(msg as CLRCallMethodMessage);
                        break;

                    case CLRMessage.TypeGetProperty:
                        HandleGetProperty(msg as CLRGetPropertyMessage);
                        break;

                    case CLRMessage.TypeSetProperty:
                        HandleSetProperty(msg as CLRSetPropertyMessage);
                        break;

                    case CLRMessage.TypeGetStaticProperty:
                        HandleGetStaticProperty(msg as CLRGetStaticPropertyMessage);
                        break;

                    case CLRMessage.TypeSetStaticProperty:
                        HandleSetStaticProperty(msg as CLRSetStaticPropertyMessage);
                        break;

                    case CLRMessage.TypeGetIndexedProperty:
                        HandleGetIndexedProperty(msg as CLRGetIndexedPropertyMessage);
                        break;

                    case CLRMessage.TypeGetIndexed:
                        HandleGetIndexed(msg as CLRGetIndexedMessage);
                        break;

                    case CLRMessage.TypeProtect:
                        HandleProtect(msg as CLRProtectMessage);
                        break;

                    case CLRMessage.TypeRelease:
                        HandleRelease(msg as CLRReleaseMessage);
                        break;

                    case CLRMessage.TypeTemplateReq:
                        HandleTemplate(msg as CLRTemplateReqMessage);
                        break;

                    default:
                        throw new ArgumentException("unknown request message: " + msg);
                    }
                }
            }
            catch (Exception e)
            {
                _log.Warn("receipt of messsage failed: " + e.ToString() + ", stack: " + e.StackTrace);
            }
        }
コード例 #19
0
 /// <summary>
 /// Write a message to the stream
 /// </summary>
 /// <param name="stream">Stream.</param>
 public static void Write(IBinaryWriter stream, CLRMessage msg)
 {
     msg.Serialize(stream);
     stream.Flush();
 }