Exemplo n.º 1
0
        public StorageActor(IPecanLogger logger)
        {
            this.Logger = logger;
            logger?.Trace(this.GetType().Name, $"{this.GetType().Name} Creating {nameof(StorageReadActor)} .. ");
            //multi reader
            IActorRef actorReadPool = Context.ActorOf(Props.Create(() => new StorageReadActor(logger)).WithRouter(new RoundRobinPool(1000)), TypeOfWrapper.TypeOf(typeof(StorageReadActor)).Name);

            logger?.Trace(this.GetType().Name, $"{this.GetType().Name} Creating {nameof(StorageWriteActor)} .. ");
            //single writer
            IActorRef actorWriteRef = Context.ActorOf(Props.Create(() => new StorageWriteActor(logger)), TypeOfWrapper.TypeOf(typeof(StorageWriteActor)).Name);

            this.Receive <Func <bool> >(
                message =>
            {
                logger?.Trace(this.GetType().Name, $"{this.GetType().Name} forwarding message {message?.GetType().Name} to {actorWriteRef.Path.ToStringWithAddress()}");
                actorWriteRef.Forward(message);
            });
            this.Receive <Func <object> >(
                message =>
            {
                logger?.Trace(this.GetType().Name, $"{this.GetType().Name} forwarding message {message?.GetType().Name} to {actorReadPool.Path.ToStringWithAddress()}");

                actorReadPool.Forward(message);
            });
            this.Receive <Terminated>(
                t =>
            {
                string message = "Actor just got terminated : " + t.ActorRef.Path;
                logger?.Fatal(this.GetType().Name, message);
            });
        }
Exemplo n.º 2
0
 internal Session(DatabaseService databaseService, IPecanLogger logger, string remoteServerAdrress)
 {
     this.RemoteServerAdrress = remoteServerAdrress;
     this.RunAsHttpClient     = !string.IsNullOrEmpty(remoteServerAdrress);
     this.Logger             = logger;
     this.TrackingDictionary = new Dictionary <string, TrackedObject>();
     this.databaseService    = databaseService;
     this.SessionId          = Guid.NewGuid();
 }
Exemplo n.º 3
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);
 }
Exemplo n.º 4
0
 public StorageReadActor(IPecanLogger logger)
 {
     this.Receive <Func <object> >(
         message =>
     {
         if (message == null)
         {
             logger?.Fatal(this.GetType().Name, $"Error null{this.GetType().Name} message {message?.GetType().Name}");
         }
         else
         {
             logger?.Trace(this.GetType().Name, $"{this.GetType().Name} Executing message {message?.GetType().Name}");
             this.Sender.Tell(message());
         }
     });
 }
Exemplo n.º 5
0
        public StorageDatabase(IStorageMechanism storageMechanism, string documentName, DatabaseService dataBaseSettings, IPecanLogger logger)
        {
            this.Logger = logger;

            this.Logger?.Trace(this.GetType().Name, $"Initializing storage database ...");

            this.DataBaseSettings = dataBaseSettings;
            this.storageMechanism = storageMechanism;

            string dname = PecanDatabaseUtilityObj.DetermineDatabaseName <TDocumentWithObject, TObjectOnly>(documentName);

            this.DocumentName = dname;

            CurrentCount = this.storageMechanism.Count <TDocumentWithObject>(this.DocumentName, true);

            this.Logger?.Trace(this.GetType().Name, $"Initialized storage. Document Name {this.DocumentName} and current count {CurrentCount}");
        }
Exemplo n.º 6
0
        public JsonStorageMechanism(IStorageSystem fileSystem, string databaseName, string rootFolder, IPecanLogger logger)
        {
            this.Logger = logger;

            if (string.IsNullOrEmpty(databaseName))
            {
                throw new ArgumentNullException(nameof(databaseName));
            }
            this._rootFolder = rootFolder;
            this.db          = this._rootFolder + "\\" + databaseName;

            this.FileSystem = fileSystem;
            if (!this.FileSystem.DirectoryExists(this.db))
            {
                this.FileSystem.CreateDirectory(this.db);
            }

            this.Logger?.Trace(this.GetType().Name, $"Initialized {this.GetType().Name} {this.GetContextDescription()}");
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
0
 public FileStorageSystem(DataBaseSettings DdtaBaseSettings, IStorageIO fileIO, ISerializationFactory sf, IPecanLogger logger)
 {
     this.Logger               = logger;
     this.DataBaseSettings     = DdtaBaseSettings;
     this._fileIO              = fileIO;
     this.SerializationFactory = sf;
 }
Exemplo n.º 9
0
 public AkkaActorSystemMechanism(IActorRef storageActorRef, IStorageMechanism worker, DataBaseSettings DdtaBaseSettings, IPecanLogger logger)
 {
     this.Logger           = logger;
     this._storageActorRef = storageActorRef;
     this._worker          = worker;
     this.FileSystem       = this._worker?.FileSystem;
     this.DataBaseSettings = DdtaBaseSettings;
 }
Exemplo n.º 10
0
 public DirectDocumentManipulator(IStorageMechanism s, DatabaseService _DatabaseService, IPecanLogger logger)
 {
     this.Logger          = logger;
     this.DatabaseService = _DatabaseService;
     this.sMech           = s ?? throw new ArgumentNullException(nameof(s));
 }
Exemplo n.º 11
0
 private static void LogEvent(IPecanLogger logger, TraceType level, string logSource, Exception exception, string message, params object[] parameters)
 {
     logger.Trace(logger.Name + " > " + logSource, message + " > " + exception?.Message + " > " + exception?.InnerException?.Message, null, level, parameters);
 }
Exemplo n.º 12
0
 private static void LogEvent(IPecanLogger logger, TraceType level, string logSource, string message, params object[] parameters)
 {
     LogEvent(logger, level, logSource, null, message, parameters);
 }
Exemplo n.º 13
0
 public StorageIO(IPecanLogger logger)
 {
     this.Logger = logger;
 }
Exemplo n.º 14
0
 public InMemoryStorageIO(IPecanLogger logger)
 {
     this.Logger = logger;
 }
Exemplo n.º 15
0
 public JsonSerializationFactory(IPecanLogger logger)
 {
     this.Logger = logger;
 }