Exemple #1
0
 //SortedDictionary<Guid, Column> columns = new SortedDictionary<Guid, Column> ();
 //SortedDictionary<int, SortedDictionary<string,Column>> tableColumns = new SortedDictionary<int, SortedDictionary<string, Column>> ();
 ServiceAgent(ServiceAgentMode serviceAgentMode, ObjectBusSession objectBusSession, Action flush, ServiceParameters parameters)
     : base(serviceAgentMode, objectBusSession, flush, false)
 {
     if (serviceAgentMode != ServiceAgentMode.Server)
     {
         throw new Exception("This service agent can only be run in server mode.");
     }
     connectionString = parameters.ConnectionString;
     objectBusSession.RegisterType(typeof(GetTablesRequestMessage), GetTablesRequestMessageReceived);
     objectBusSession.RegisterType(typeof(GetColumnsRequestMessage), GetColumnsRequestMessageReceived);
     objectBusSession.RegisterType(typeof(GetRowsRequestMessage), GetRowsRequestMessageReceived);
     objectBusSession.RegisterType(typeof(GetForeignKeyRelationsRequestMessage), GetForeignKeyRelationsRequestMessageReceived);
     tfqns.Add(48, "System.Byte");
     tfqns.Add(173, "System.Byte[]");
     tfqns.Add(165, "System.Byte[]");
     tfqns.Add(52, "System.Int16");
     tfqns.Add(56, "System.Int32");
     tfqns.Add(127, "System.Int64");
     tfqns.Add(62, "System.Double");
     tfqns.Add(106, "System.Double");
     tfqns.Add(108, "System.Double");
     tfqns.Add(231, "System.String");
     tfqns.Add(239, "System.String");
     tfqns.Add(175, "System.String");
     tfqns.Add(104, "System.Boolean");
     tfqns.Add(34, "System.Byte[]");
     tfqns.Add(36, "System.Guid");
     tfqns.Add(41, "System.DateTime");
     tfqns.Add(42, "System.DateTime");
     tfqns.Add(43, "System.DateTime");
     tfqns.Add(61, "System.DateTime");
 }
        void ServiceRequestReceived(ObjectBusMessage message)
        {
                        #if TRACE
            Console.WriteLine(new System.Diagnostics.StackTrace(true).GetFrame(0));
                        #endif

            if (message == null)
            {
                throw new ArgumentNullException("message");
            }
            if (!(message is ServiceRequestMessage))
            {
                throw new ArgumentException(string.Format("message type is not valid, must be of type {0}", typeof(ServiceRequestMessage).FullName));
            }
            ServiceRequestMessage serviceRequest = (ServiceRequestMessage)message;
            Func <ServiceAgentMode, ObjectBusSession, Action, Byte[], ServiceAgent> agentFunc;
            lock (localServices)
                lock (localServiceAgents)
                    agentFunc = localServiceAgents [localServices [serviceRequest.ServiceID]];
            Guid                   responseID = Guid.NewGuid();
            ObjectBusSession       session    = objectBus.CreateSession(responseID, SessionDisconnected);
            ServiceResponseMessage response   = new ServiceResponseMessage(responseID, serviceRequest.ID, ServiceResponseStatus.Accepted);
            ServiceAgent           agent      = agentFunc.Invoke(ServiceAgentMode.Server, session, objectBus.Flush, serviceRequest.Parameters);
            lock (sessionAgents)
                sessionAgents.Add(session.SessionID, agent);
            objectBus.SendMessage(response);
        }
 public static ServiceAgent CreateAgent(ServiceAgentMode serviceAgentMode, ObjectBusSession objectBusSession, Action flush, byte[] parameters)
 {
                 #if TRACE
     Console.WriteLine(new System.Diagnostics.StackTrace(true).GetFrame(0));
                 #endif
     return(new StreamPairAgent(serviceAgentMode, objectBusSession, flush, true));
 }
Exemple #4
0
        void GetRowsRequestMessageReceived(ObjectBusMessage obj)
        {
            Console.WriteLine("GetRowsRequestMessageReceived()");
            GetRowsRequestMessage  request = (GetRowsRequestMessage)obj;
            GetRowsResponseMessage response;
            Table table;

            lock (tables)
                table = (Table)psc.GetTableByID(request.TableID);
            Console.WriteLine(table.Name);
            try {
                SqlConnection conn_Rows = new SqlConnection(connectionString);
                try {
                    conn_Rows.Open();
                } catch {                                    //retry once
                    conn_Rows.Open();
                }

                SqlCommand cmdSelect = new SqlCommand(string.Format("Select * from [{0}]", table.Name), conn_Rows);
                cmdSelect.CommandTimeout *= 30;
                response = new GetRowsResponseMessage(request.ID, readRowsData(conn_Rows, cmdSelect, cmdSelect.ExecuteReader(), table), null);
            } catch (Exception ex) {
                response = new GetRowsResponseMessage(request.ID, new List <BD2.Conv.Frontend.Table.Row> (), ex);
            }
            ObjectBusSession.SendMessage(response);
            Console.WriteLine("Sent GetRowsResponseMessage.");
        }
Exemple #5
0
 public Agent(ServiceAgentMode serviceAgentMode, ObjectBusSession objectBusSession, Action flush, ChannelControl channelControl)
     : base(serviceAgentMode, objectBusSession, flush, false)
 {
     objectBusSession.RegisterType(typeof(GetPublicKeyRequestMessage), GetPublicKeyRequestMessageReceived);
     objectBusSession.RegisterType(typeof(CreateChannelRequestMessage), CreateChannelRequestMessageReceived);
     this.channelControl = channelControl;
 }
Exemple #6
0
 public static ServiceAgent CreateAgent(ServiceAgentMode serviceAgentMode, ObjectBusSession objectBusSession, Action flush, ChunkRepository repository)
 {
     if (repository == null)
     {
         throw new ArgumentNullException("repository");
     }
     return(new ChunkAgent(serviceAgentMode, objectBusSession, flush, repository));
 }
Exemple #7
0
 public Shell(ObjectBusSession session)
 {
     if (session == null)
     {
         throw new ArgumentNullException("session");
     }
     this.session = session;
 }
Exemple #8
0
 public void SendMessage(ObjectBusMessage message)
 {
     if (message == null)
     {
         throw new ArgumentNullException("message");
     }
     ObjectBusSession.SendMessage(message);
 }
 StreamPairAgent(ServiceAgentMode serviceAgentMode, ObjectBusSession objectBusSession, Action flush, bool run)
     : base(serviceAgentMode, objectBusSession, flush, run)
 {
                 #if TRACE
     Console.WriteLine(new System.Diagnostics.StackTrace(true).GetFrame(0));
                 #endif
     objectBusSession.RegisterType(typeof(StreamPairMessage), StreamPairMessageReceived);
 }
        void SendStreamPairMessage(Stream stream)
        {
                        #if TRACE
            Console.WriteLine(new System.Diagnostics.StackTrace(true).GetFrame(0));
                        #endif

            ObjectBusSession.SendMessage(new StreamPairMessage(CreateStream(stream)));
        }
Exemple #11
0
        void SessionDisconnected(ObjectBusSession session)
        {
                        #if TRACE
            Console.WriteLine(new System.Diagnostics.StackTrace(true).GetFrame(0));
                        #endif

            lock (sessionAgents)
                sessionAgents [session.SessionID].CallSessionDisconnected();
        }
Exemple #12
0
 protected ServiceAgent(ServiceAgentMode serviceAgentMode, ObjectBusSession objectBusSession, Action flush, bool run)
 {
     if (!Enum.IsDefined(typeof(ServiceAgentMode), serviceAgentMode))
     {
         throw new ArgumentException("Invalid value for argument 'serviceAgentMode'", "serviceAgentMode");
     }
     if (objectBusSession == null)
     {
         throw new ArgumentNullException("objectBusSession");
     }
     if (flush == null)
     {
         throw new ArgumentNullException("flush");
     }
     this.serviceAgentMode = serviceAgentMode;
     this.objectBusSession = objectBusSession;
     this.flush            = flush;
     objectBusSession.RegisterType(typeof(TransparentStreamCanReadRequestMessage), TransparentStreamServerMessageReceived);
     objectBusSession.RegisterType(typeof(TransparentStreamCanReadResponseMessage), TransparentStreamMessageReceived);
     objectBusSession.RegisterType(typeof(TransparentStreamCanSeekRequestMessage), TransparentStreamServerMessageReceived);
     objectBusSession.RegisterType(typeof(TransparentStreamCanSeekResponseMessage), TransparentStreamMessageReceived);
     objectBusSession.RegisterType(typeof(TransparentStreamCanTimeoutRequestMessage), TransparentStreamServerMessageReceived);
     objectBusSession.RegisterType(typeof(TransparentStreamCanTimeoutResponseMessage), TransparentStreamMessageReceived);
     objectBusSession.RegisterType(typeof(TransparentStreamCanWriteRequestMessage), TransparentStreamServerMessageReceived);
     objectBusSession.RegisterType(typeof(TransparentStreamCanWriteResponseMessage), TransparentStreamMessageReceived);
     objectBusSession.RegisterType(typeof(TransparentStreamCloseRequestMessage), TransparentStreamServerMessageReceived);
     objectBusSession.RegisterType(typeof(TransparentStreamCloseResponseMessage), TransparentStreamMessageReceived);
     objectBusSession.RegisterType(typeof(TransparentStreamFlushRequestMessage), TransparentStreamServerMessageReceived);
     objectBusSession.RegisterType(typeof(TransparentStreamFlushResponseMessage), TransparentStreamMessageReceived);
     objectBusSession.RegisterType(typeof(TransparentStreamGetLengthRequestMessage), TransparentStreamServerMessageReceived);
     objectBusSession.RegisterType(typeof(TransparentStreamGetLengthResponseMessage), TransparentStreamMessageReceived);
     objectBusSession.RegisterType(typeof(TransparentStreamGetPositionRequestMessage), TransparentStreamServerMessageReceived);
     objectBusSession.RegisterType(typeof(TransparentStreamGetPositionResponseMessage), TransparentStreamMessageReceived);
     objectBusSession.RegisterType(typeof(TransparentStreamGetReadTimeoutRequestMessage), TransparentStreamServerMessageReceived);
     objectBusSession.RegisterType(typeof(TransparentStreamGetReadTimeoutResponseMessage), TransparentStreamMessageReceived);
     objectBusSession.RegisterType(typeof(TransparentStreamGetWriteTimeoutRequestMessage), TransparentStreamServerMessageReceived);
     objectBusSession.RegisterType(typeof(TransparentStreamGetWriteTimeoutResponseMessage), TransparentStreamMessageReceived);
     objectBusSession.RegisterType(typeof(TransparentStreamReadRequestMessage), TransparentStreamServerMessageReceived);
     objectBusSession.RegisterType(typeof(TransparentStreamReadResponseMessage), TransparentStreamMessageReceived);
     objectBusSession.RegisterType(typeof(TransparentStreamSeekRequestMessage), TransparentStreamServerMessageReceived);
     objectBusSession.RegisterType(typeof(TransparentStreamSeekResponseMessage), TransparentStreamMessageReceived);
     objectBusSession.RegisterType(typeof(TransparentStreamSetLengthRequestMessage), TransparentStreamServerMessageReceived);
     objectBusSession.RegisterType(typeof(TransparentStreamSetLengthResponseMessage), TransparentStreamMessageReceived);
     objectBusSession.RegisterType(typeof(TransparentStreamSetPositionRequestMessage), TransparentStreamServerMessageReceived);
     objectBusSession.RegisterType(typeof(TransparentStreamSetPositionResponseMessage), TransparentStreamMessageReceived);
     objectBusSession.RegisterType(typeof(TransparentStreamSetReadTimeoutRequestMessage), TransparentStreamServerMessageReceived);
     objectBusSession.RegisterType(typeof(TransparentStreamSetReadTimeoutResponseMessage), TransparentStreamMessageReceived);
     objectBusSession.RegisterType(typeof(TransparentStreamSetWriteTimeoutRequestMessage), TransparentStreamServerMessageReceived);
     objectBusSession.RegisterType(typeof(TransparentStreamSetWriteTimeoutResponseMessage), TransparentStreamMessageReceived);
     objectBusSession.RegisterType(typeof(TransparentStreamWriteRequestMessage), TransparentStreamServerMessageReceived);
     objectBusSession.RegisterType(typeof(TransparentStreamWriteResponseMessage), TransparentStreamMessageReceived);
     if (run)
     {
         thread = new System.Threading.Thread(Run);
         thread.Start();
     }
 }
 public BD2ServiceAgent(Database database, ServiceAgentMode serviceAgentMode, ObjectBusSession objectBusSession, Action flush)
     : base(serviceAgentMode, objectBusSession, flush, false)
 {
     if (database == null)
     {
         throw new ArgumentNullException("database");
     }
     this.database = database;
 }
Exemple #14
0
 //SortedDictionary<Guid, Column> columns = new SortedDictionary<Guid, Column> ();
 ServiceAgent(ServiceAgentMode serviceAgentMode, ObjectBusSession objectBusSession, Action flush, ServiceParameters parameters)
     : base(serviceAgentMode, objectBusSession, flush, false)
 {
     if (serviceAgentMode != ServiceAgentMode.Server)
         throw new Exception ("This service agent can only be run in server mode.");
     conn = new SqliteConnection (parameters.ConnectionString);
     objectBusSession.RegisterType (typeof(GetTablesRequestMessage), GetTablesRequestMessageReceived);
     objectBusSession.RegisterType (typeof(GetColumnsRequestMessage), GetColumnsRequestMessageReceived);
     objectBusSession.RegisterType (typeof(GetRowsRequestMessage), GetRowsRequestMessageReceived);
     objectBusSession.RegisterType (typeof(GetForeignKeyRelationsRequestMessage), GetForeignKeyRelationsRequestMessageReceived);
 }
Exemple #15
0
 //SortedDictionary<Guid, Column> columns = new SortedDictionary<Guid, Column> ();
 ServiceAgent(ServiceAgentMode serviceAgentMode, ObjectBusSession objectBusSession, Action flush, ServiceParameters parameters)
     : base(serviceAgentMode, objectBusSession, flush, false)
 {
     if (serviceAgentMode != ServiceAgentMode.Server)
     {
         throw new Exception("This service agent can only be run in server mode.");
     }
     conn = new SqliteConnection(parameters.ConnectionString);
     objectBusSession.RegisterType(typeof(GetTablesRequestMessage), GetTablesRequestMessageReceived);
     objectBusSession.RegisterType(typeof(GetColumnsRequestMessage), GetColumnsRequestMessageReceived);
     objectBusSession.RegisterType(typeof(GetRowsRequestMessage), GetRowsRequestMessageReceived);
     objectBusSession.RegisterType(typeof(GetForeignKeyRelationsRequestMessage), GetForeignKeyRelationsRequestMessageReceived);
 }
Exemple #16
0
        void GetRowsRequestMessageReceived(ObjectBusMessage obj)
        {
            GetRowsRequestMessage request = (GetRowsRequestMessage)obj;
            Table t;

            if (tables.TryGetValue(request.TableID, out t))
            {
            }
            else
            {
                ObjectBusSession.SendMessage(new GetRowsResponseMessage(request.ID, new List <Row>(), new KeyNotFoundException()));
            }
        }
Exemple #17
0
        void GetTablesRequestMessageReceived(ObjectBusMessage obj)
        {
            Console.WriteLine("GetTablesRequestMessageReceived()");
            GetTablesRequestMessage  request = (GetTablesRequestMessage)obj;
            GetTablesResponseMessage response;

            try {
                response = new GetTablesResponseMessage(request.ID, (new List <Table> (getTables())).ToArray(), null);
            } catch (Exception ex) {
                response = new GetTablesResponseMessage(request.ID, new Table[0] {
                }, ex);
            }
            ObjectBusSession.SendMessage(response);
        }
Exemple #18
0
        public ChunkAgent(ServiceAgentMode serviceAgentMode, ObjectBusSession objectBusSession, Action flush, ChunkRepository repository)
            : base(serviceAgentMode, objectBusSession, flush, false)
        {
            if (repository == null)
            {
                throw new ArgumentNullException("repository");
            }
            this.repository = repository;
            objectBusSession.RegisterType(typeof(TopLevelChunksRequestMessage), RequestTopLevelChunkDeltaMessageReceived);
//			objectBusSession.RegisterType (typeof(BD2.Chunk.Daemon.Common.PollChunksRequestMessage), );
//			objectBusSession.RegisterType (typeof(BD2.Chunk.Daemon.Common.PollNewChunksRequestMessage), );
//			objectBusSession.RegisterType (typeof(BD2.Chunk.Daemon.Common.PushChunksRequestMessage), );
            //this.repository.Enumerate ();
        }
Exemple #19
0
        void GetColumnsRequestMessageReceived(ObjectBusMessage obj)
        {
            Console.WriteLine("GetColumnsRequestMessageReceived()");
            GetColumnsRequestMessage  request = (GetColumnsRequestMessage)obj;
            GetColumnsResponseMessage response;
            Table table;

            try {
                lock (tables)
                    table = tables [request.TableID];
                response = new GetColumnsResponseMessage(request.ID, (new List <Column> (getColumns(table.Name))).ToArray(), null);
            } catch (Exception ex) {
                response = new GetColumnsResponseMessage(request.ID, new Column[0] {
                }, ex);
            }
            ObjectBusSession.SendMessage(response);
        }
 public TransparentStreamServer(ServiceAgent agent, System.IO.Stream baseStream, ObjectBusSession objectBusSession)
 {
     if (agent == null)
     {
         throw new ArgumentNullException("agent");
     }
     if (baseStream == null)
     {
         throw new ArgumentNullException("baseStream");
     }
     if (objectBusSession == null)
     {
         throw new ArgumentNullException("objectBusSession");
     }
     this.streamID         = Guid.NewGuid();
     this.agent            = agent;
     this.baseStream       = baseStream;
     this.objectBusSession = objectBusSession;
 }
        protected override void Run()
        {
                        #if TRACE
            Console.WriteLine(new System.Diagnostics.StackTrace(true).GetFrame(0));
                        #endif
            ObjectBusSession.AnounceReady();
            ObjectBusSession.WaitForRemoteReady();
            try {
                DateTime t1 = DateTime.UtcNow;
                BD2.Daemon.StreamPair SP = new BD2.Daemon.StreamPair();
                SendStreamPairMessage(SP.GetOStream());
                System.IO.BinaryWriter BW = new BinaryWriter(SP.GetIStream());
                SendObject(BW, "/home/behrooz/The unix haters handbook.pdf");
                SendObject(BW, "/home/behrooz/john_1.7.8.orig.tar.gz");
                SendObject(BW, "/home/behrooz/Flag_Register_of_80386.PNG");
                SendObject(BW, "/home/behrooz/BD2.Arch.odg");

                Flush();
                Console.WriteLine("Done in {0}", (DateTime.UtcNow - t1).TotalMilliseconds);
                //Destroy ();
            } catch (System.Threading.ThreadAbortException) {
            }
        }
Exemple #22
0
 public static ServiceAgent CreateAgent(ServiceAgentMode serviceAgentMode, ObjectBusSession objectBusSession, Action flush, byte[] parameters)
 {
     return new ServiceAgent (serviceAgentMode, objectBusSession, flush, ServiceParameters.Deserialize (parameters));
 }
Exemple #23
0
 ChatAgent(ServiceAgentMode serviceAgentMode, ObjectBusSession objectBusSession, Action flush)
     : base(serviceAgentMode, objectBusSession, flush, false)
 {
     objectBusSession.RegisterType(typeof(ChatMessage), ChatMessageReceived);
 }
Exemple #24
0
 public void RegisterType(Type type, Action <ObjectBusMessage> action)
 {
     ObjectBusSession.RegisterType(type, action);
 }
Exemple #25
0
 public static ServiceAgent CreateAgent(ServiceAgentMode serviceAgentMode, ObjectBusSession objectBusSession, Action flush, Byte[] parameters)
 {
     return(new TransparentAgent(serviceAgentMode, objectBusSession, flush, parameters));
 }
Exemple #26
0
 public void Destroy()
 {
     ObjectBusSession.Destroy();
 }
Exemple #27
0
 public BD2ServiceAgent(KeyValueStorage <byte[]> keyValueStorage, ServiceAgentMode serviceAgentMode, ObjectBusSession objectBusSession, Action flush)
     : base(serviceAgentMode, objectBusSession, flush, false)
 {
     if (keyValueStorage == null)
     {
         throw new ArgumentNullException("keyValueStorage");
     }
     this.keyValueStorage = keyValueStorage;
     objectBusSession.RegisterType(typeof(GetAllRequestMessage), GetAllRequestMessageReceived);
 }
Exemple #28
0
 void SendMessage(string text)
 {
     ObjectBusSession.SendMessage(new ChatMessage(text));
 }
Exemple #29
0
 FileShareAgent(ServiceAgentMode serviceAgentMode, ObjectBusSession objectBusSession, Action flush, bool run)
     : base(serviceAgentMode, objectBusSession, flush, run)
 {
     objectBusSession.RegisterType(typeof(FileShareMessage), FileShareMessageReceived);
 }
Exemple #30
0
 public static ServiceAgent CreateAgent(ServiceAgentMode serviceAgentMode, ObjectBusSession objectBusSession, Action flush, byte[] parameters)
 {
     return(new ServiceAgent(serviceAgentMode, objectBusSession, flush, ServiceParameters.Deserialize(parameters)));
 }
Exemple #31
0
 public static ServiceAgent CreateAgent(ServiceAgentMode serviceAgentMode, ObjectBusSession objectBusSession, Action flush, byte[] parameters)
 {
     return(new FileShareAgent(serviceAgentMode, objectBusSession, flush, true));
 }
Exemple #32
0
 void SendMessage(string text)
 {
     ObjectBusSession.SendMessage(new FileShareMessage(text, CreateStream(File.Open(text, FileMode.Open))));
 }