Пример #1
0
        /// <summary>
        /// Sends the command core.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="factory">The factory.</param>
        /// <param name="database">The database.</param>
        /// <param name="rootType">Type of serialization root.</param>
        /// <param name="command">The spec.</param>
        /// <returns></returns>
        private T SendCommandCore <T>(ISerializationFactory factory, string database, Type rootType, object command)
            where T : class
        {
            var writerSettings = factory.GetBsonWriterSettings(rootType);

            var query = new QueryMessage(writerSettings)
            {
                FullCollectionName = database + ".$cmd",
                NumberToReturn     = -1,
                Query = command
            };

            var readerSettings = factory.GetBsonReaderSettings(typeof(T));

            try
            {
                var reply = SendTwoWayMessageCore <T>(query, readerSettings);

                if (reply.CursorId > 0)
                {
                    SendMessage(new KillCursorsMessage(reply.CursorId), database);
                }

                return(reply.Documents.FirstOrDefault());
            }
            catch (IOException exception)
            {
                throw new MongoConnectionException("Could not read data, communication failure", this, exception);
            }
        }
Пример #2
0
 /// <summary>
 ///   Initializes a new instance of the <see cref = "MongoConfiguration" /> class.
 /// </summary>
 public MongoConfiguration()
 {
     IsModifiable          = true;
     _connectionString     = string.Empty;
     _mappingStore         = new AutoMappingStore();
     _serializationFactory = new SerializationFactory(this);
     _readLocalTime        = true;
 }
 /// <summary>
 ///   Initializes a new instance of the <see cref = "MongoConfiguration" /> class.
 /// </summary>
 public MongoConfiguration()
 {
     IsModifiable = true;
     _connectionString = string.Empty;
     _mappingStore = new AutoMappingStore();
     _serializationFactory = new SerializationFactory(this);
     _readLocalTime = true;
 }
Пример #4
0
 public static ISerializationFactory GetInstance()
 {
     if (_instance is null)
     {
         _instance = new JsonSerializationFactoryImpl();
     }
     return(_instance);
 }
Пример #5
0
 public DatabaseService(string databaseDirectory, string databaseName, ISerializationFactory serializationFactory, IStorageIO fileIo, IPecanLogger logger, bool useInMemoryStorage = false, string storageName = null)
 {
     this.Logger = logger;
     if (useInMemoryStorage)
     {
         fileIo = new InMemoryStorageIO(this.Logger);
     }
     this.DataBaseSettings          = new DataBaseSettings(databaseName, serializationFactory, fileIo, storageName, logger, databaseDirectory);
     this.DirectDocumentManipulator = new DirectDocumentManipulator(this.DataBaseSettings.StorageMechanismMech, this, logger);
 }
Пример #6
0
 public RemotingHandler(ILoggerFactory loggerFactory
     , IClientChannelSelector channelSelector
     , ISerializationFactory serializationFactory)
 {
     this._log = loggerFactory.Create(this);
     this._channelSelector = channelSelector;
     this._serializationFactory = serializationFactory;
     this._callbacks = new Dictionary<int, RemotingCallback>();
     this.PrepareEventHandler();
 }
Пример #7
0
        public void JsonTest()
        {
            serializationFactory = new CrossLanguageSerializationFactory();

            var testService = new DynamicProxy(typeof(TestService), URI
                , new RemotingHandler(DefaultLoggerFactory.Default
                , new ClientChannelSharedSelector()
                , serializationFactory)).GetTransparentProxy() as TestService;
            Assert.AreEqual("hi", testService.Echo("hi"));
        }
Пример #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Cursor&lt;T&gt;"/> class.
 /// </summary>
 /// <param name="serializationFactory">The serialization factory.</param>
 /// <param name="mappingStore">The mapping store.</param>
 /// <param name="connection">The conn.</param>
 /// <param name="databaseName">Name of the database.</param>
 /// <param name="collectionName">Name of the collection.</param>
 internal Cursor(ISerializationFactory serializationFactory, IMappingStore mappingStore, Connection connection, string databaseName, string collectionName)
 {
     //Todo: add public constrcutor for users to call
     IsModifiable          = true;
     _connection           = connection;
     _databaseName         = databaseName;
     FullCollectionName    = databaseName + "." + collectionName;
     _serializationFactory = serializationFactory;
     _mappingStore         = mappingStore;
 }
Пример #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Cursor&lt;T&gt;"/> class.
 /// </summary>
 /// <param name="serializationFactory">The serialization factory.</param>
 /// <param name="mappingStore">The mapping store.</param>
 /// <param name="connection">The conn.</param>
 /// <param name="databaseName">Name of the database.</param>
 /// <param name="collectionName">Name of the collection.</param>
 /// <param name="spec">The spec.</param>
 /// <param name="limit">The limit.</param>
 /// <param name="skip">The skip.</param>
 /// <param name="fields">The fields.</param>
 internal Cursor(ISerializationFactory serializationFactory, IMappingStore mappingStore, Connection connection, string databaseName, string collectionName, object spec, int limit, int skip, object fields)
     : this(serializationFactory, mappingStore, connection, databaseName, collectionName)
 {
     //Todo: add public constrcutor for users to call
     if (spec == null)
     {
         spec = new Document();
     }
     _spec   = spec;
     _limit  = limit;
     _skip   = skip;
     _fields = fields;
 }
Пример #10
0
        /// <summary>
        /// Sends the command.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="factory">The factory.</param>
        /// <param name="database">The database.</param>
        /// <param name="rootType">Type of serialization root.</param>
        /// <param name="command">The spec.</param>
        /// <param name="throw">if set to <c>true</c> [@throw].</param>
        /// <returns></returns>
        public T SendCommand <T>(ISerializationFactory factory, string database, Type rootType, object command, bool @throw)
            where T : CommandResultBase
        {
            AuthenticateIfRequired(database);

            var result = SendCommandCore <T>(factory, database, rootType, command);

            if (@throw && !result.Success)
            {
                throw new MongoCommandException(result.ErrorMessage, null, null);
            }

            return(result);
        }
Пример #11
0
        public TypeCollector(ModuleDefinition module, bool useMapMode)
        {
            this.module = module;

            classFactory  = useMapMode ? (ISerializationFactory <ClassSerializationInfo>) new ClassSerializationInfoFactoryMapMode() : new ClassSerializationInfoFactory();
            structFactory = useMapMode ? (ISerializationFactory <StructSerializationInfo>) new StructSerializationInfoFactoryMapMode() : new StructSerializationInfoFactory();
            var genericVariationFinder = new GenericInstanceVariationFinder();

            genericClassFactory   = useMapMode ? (ISerializationFactory <GenericClassSerializationInfo>) new GenericClassSerializationInfoFactoryMapMode(genericVariationFinder) : new GenericClassSerializationInfoFactory(genericVariationFinder);
            genericStructFactory  = useMapMode ? (ISerializationFactory <GenericStructSerializationInfo>) new GenericStructSerializationInfoFactoryMapMode(genericVariationFinder) : new GenericStructSerializationInfoFactory(genericVariationFinder);
            unionInterfaceFactory = new UnionInterfaceSerializationInfoFactory();
            unionClassFactory     = new UnionClassSerializationInfoFactory();

            foreach (var typeDefinition in module.Types)
            {
                Visit(typeDefinition);
            }
        }
Пример #12
0
        /// <summary>
        /// Sends the command.
        /// </summary>
        /// <param name="factory">The factory.</param>
        /// <param name="database">The database.</param>
        /// <param name="rootType">Type of the command.</param>
        /// <param name="command">The command.</param>
        /// <returns></returns>
        public Document SendCommand(ISerializationFactory factory, string database, Type rootType, Document command)
        {
            AuthenticateIfRequired(database);

            var result = SendCommandCore <Document>(factory, database, rootType, command);

            if (!Convert.ToBoolean(result["ok"]))
            {
                var msg = string.Empty;
                if (result.ContainsKey("msg"))
                {
                    msg = (string)result["msg"];
                }
                else if (result.ContainsKey("errmsg"))
                {
                    msg = (string)result["errmsg"];
                }
                throw new MongoCommandException(msg, result, command);
            }

            return(result);
        }
Пример #13
0
        public DataBaseSettings(string databaseName, ISerializationFactory serializationFactory, IStorageIO fileio, string storageName, IPecanLogger logger, string baseDirectory)
        {
            if (databaseName == null)
            {
                throw new ArgumentNullException(nameof(databaseName));
            }

            this.FileIo = fileio ?? new StorageIO(logger);

            if (baseDirectory != null)
            {
                baseDirectory = baseDirectory.TrimEnd('/').TrimEnd('\\').TrimEnd('/').TrimEnd('\\');
                if (!this.FileIo.DirectoryExists(baseDirectory))
                {
                    this.FileIo.CreateDirectory(baseDirectory);
                }
            }

            DbStorageLocation = (string.IsNullOrEmpty(baseDirectory) ? AppDomain.CurrentDomain.BaseDirectory : baseDirectory) + "\\" + (string.IsNullOrEmpty(storageName) ? "pecan" : storageName);

            this.StorageMechanismMech = new JsonStorageMechanism(
                new FileStorageSystem(this, this.FileIo, serializationFactory ?? new JsonSerializationFactory(logger), logger),
                databaseName,
                DbStorageLocation,
                logger
                );
            Type pecanDbLoggerType = typeof(PecanDbLogger);

            PecanDbLogger.DefaultPecanLogger = logger;
            Config akkaConfig =
                $@"akka.loglevel = DEBUG
                    akka.loggers=[""{pecanDbLoggerType.FullName}, {pecanDbLoggerType.GetTypeInfo().Assembly.GetName().Name}""]";

            this.AppActorSystemystem        = ActorSystem.Create("StorageActorSystem-" + Guid.NewGuid().ToString(), akkaConfig);
            this.StorageActor               = this.AppActorSystemystem.ActorOf(Props.Create(() => new StorageActor(logger)), TypeOfWrapper.TypeOf(typeof(StorageActor)).Name);
            this.AkkaCommonStorageMechanism = new AkkaActorSystemMechanism(this.StorageActor, this.StorageMechanismMech, this, logger);
        }
Пример #14
0
 public void RemotingServiceTest()
 {
     serializationFactory = new CrossLanguageSerializationFactory();
     Assert.AreEqual("hi", RemotingServices.Connect<TestService>(URI.ToString()).Echo("hi"));
 }
Пример #15
0
 public FileStorageSystem(DataBaseSettings DdtaBaseSettings, IStorageIO fileIO, ISerializationFactory sf, IPecanLogger logger)
 {
     this.Logger               = logger;
     this.DataBaseSettings     = DdtaBaseSettings;
     this._fileIO              = fileIO;
     this.SerializationFactory = sf;
 }
Пример #16
0
 public void SetUp()
 {
     serializationFactory = new TestSerializationFactory();
 }
Пример #17
0
 /// <summary>
 /// Creates a new persisted object space using the specified serialization factory used to serialize and deserialize state.
 /// </summary>
 /// <param name="serializationFactory">The serialization factory to use to serialize and deserialize state.</param>
 public PersistedObjectSpace(ISerializationFactory serializationFactory)
 {
     _serializationFactory = serializationFactory ?? throw new ArgumentNullException(nameof(serializationFactory));
     _items = new Registry(this);
 }
Пример #18
0
 /// <summary>
 /// Sends the command.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="factory">The factory.</param>
 /// <param name="database">The database.</param>
 /// <param name="rootType">Type of serialization root.</param>
 /// <param name="command">The spec.</param>
 /// <returns></returns>
 public T SendCommand <T>(ISerializationFactory factory, string database, Type rootType, object command)
     where T : CommandResultBase
 {
     return(SendCommand <T>(factory, database, rootType, command, true));
 }