[Solved] How to use RegisterOperation method ? :?

KEMBL
edited September 2011 in Photon Server
Hello all!

Can some one describe on example how to link single operation with one method by this construction:
OperationCache.RegisterOperation(MethodInfo method);

:?:

I cant understand :? and did not found in tutorial examples how to handle with MethodInfo class to reach success results.

For now I use registration by type:
OperationCache.RegisterOperations(typeof(GameStateOperationHandler));

but I have got several operations which can reach server from many gamestates. If I add equal operation to several diffirent IOperationHandler class examples I have this error:
2011-09-02 10:33:38,492 [11] ERROR EX.Server.PhotonApplication - System.ArgumentException: An operation with the same code has already been added. Code 120; Methods GameOperationHandler.OperationGetContent vs PrimaryOperationHandler.OperationGetContent
   â Photon.SocketServer.Rpc.Reflection.OperationMethodInfoCache.RegisterOperation(MethodInfo method) â c:\svncontent\photon-socketserver-sdk\src\Photon.SocketServer\Rpc\Reflection\OperationMethodInfoCache.cs:ñòðîêà 178
   â Photon.SocketServer.Rpc.Reflection.OperationMethodInfoCache.RegisterOperations(Type targetType) â c:\svncontent\photon-socketserver-sdk\src\Photon.SocketServer\Rpc\Reflection\OperationMethodInfoCache.cs:ñòðîêà 214
   â EX.Server.MmoPeer..cctor() â D:\dmo\project\Ex\Server\MmoPeer.cs:ñòðîêà 113

So I needs to use other method described in class OperationMethodInfoCache:
public bool RegisterOperation(Func<Peer, OperationRequest, OperationResponse> method);
or
public bool RegisterOperation(MethodInfo method);

who can droop small example how to proper use it? Especialy second method.

Comments

  • As usual, I sudenly understand the answer while press to submit question :)

    For using RegisterOperation, no needs to use some special "MethodInfo method", the argument may be any real OperationResponse method. This my checked example:
    public static OperationMethodInfoCache OperationCache { get; private set; }
    
    OperationCache = new OperationMethodInfoCache();
    OperationCache.RegisterOperation(OperationGetSome);
    
    [Operation(OperationCode = (byte)OperationCode.GetGetSome)]
    public static OperationResponse OperationGetSome(Peer peer, OperationRequest request)
    {
      // do some
    }