Exemple #1
0
        public WellEmulator(
            IEmulator emulator,
            IReplicator replicator,
            IPdgtmDbAdapter pdgtmDbAdapter,
            IHistorianAdapter historianAdapter,
            ISettingsManager settingsManager,
            IDatabaseObserver databaseObserver)
        {
            _emulator         = emulator;
            _replicator       = replicator;
            _pdgtmDbAdapter   = pdgtmDbAdapter;
            _historianAdapter = historianAdapter;
            _settingsManager  = settingsManager;
            _databaseObserver = databaseObserver;

            _databaseObserver.OnHistorianDataChanged += OnHistorianDataChanged;
            _databaseObserver.OnPdgtmDataChanged     += OnPdgtmDataChanged;

            try
            {
                LoadSettings();
            }
            catch (LoadSettingsException ex)
            {
                _logger.Error("Error while loading settings", ex);
                throw;
            }

            _logger.Trace("Service object created");
        }
Exemple #2
0
        public static bool TryGetReplicator(int id, out IReplicator replicator)
        {
            var result = Replicators.TryGetValue((ushort)id, out var info);

            replicator = info.Replicator;
            return(result);
        }
Exemple #3
0
        public IReplicator GetReplicatorProxy()
        {
            if (_replicatorFactory == null || _replicatorFactory.State != CommunicationState.Opened)
            {
                NetTcpBinding binding = new NetTcpBinding();
                binding.Security.Mode = SecurityMode.Transport;
                binding.Security.Transport.ProtectionLevel      = ProtectionLevel.EncryptAndSign;
                binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows;

                _replicatorFactory = new ChannelFactory <IReplicator>(binding);
            }

            if (_replicatorProxy == null)
            {
                try
                {
                    _replicatorFactory.CreateChannel();
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Error opening proxy to replicator => {e.Message}");
                    _replicatorProxy = null;
                }
            }

            return(_replicatorProxy);
        }
Exemple #4
0
 public ReplicaResponseDeserializer(
     IReplicator replicator,
     ResponseDeserializer innerDeserializer)
 {
     Replicator        = replicator;
     InnerDeserializer = innerDeserializer;
 }
Exemple #5
0
        public bool RemoveConsumation() //admin-pravo uklanjanja baze podataka (fajl-a)
        {
            if (StateService.stateService != EStateServers.Primarni)
            {
                SecurityException ex = new SecurityException("Error! IS NOT A primary\n");
                throw new FaultException <SecurityException>(ex);
            }
            CustomPrincipal principal = Thread.CurrentPrincipal as CustomPrincipal;

            if (!principal.IsInRole(Permissions.Deleting.ToString()))
            {
                MyException ex = new MyException("Error! IS NOT A READER\n");
                throw new FaultException <MyException>(ex);
            }

            if (!File.Exists(DataBase.FileName))
            {
                return(false);
                //MyException ex = new MyException("Error! File cannot be find\n");
                //throw new FaultException<MyException>(ex);
            }

            lock (DataBase.lockObject)
            {
                File.Delete(DataBase.FileName);
            }

            if (StateService.stateService == EStateServers.Primarni)
            {
                ChannelFactory <IReplicator> cfh2 = new ChannelFactory <IReplicator>("sekundarni");
                IReplicator proxy2 = cfh2.CreateChannel();
                proxy2.RemoveConsumation();
            }
            return(true);
        }
Exemple #6
0
        static void ReplicateThread()
        {
            while (true)
            {
                if (StateService.stateService != EStateServers.Primarni)
                {
                    Thread.Sleep(5000);
                    continue;
                }



                lock (DataBase.lockObject)
                {
                    try
                    {
                        ChannelFactory <IReplicator> cfh2 = new ChannelFactory <IReplicator>("sekundarni");
                        IReplicator proxy2 = cfh2.CreateChannel();
                        proxy2.SendDelta(DataBase.consumersDelta);
                        DataBase.consumersDelta.Clear();
                    }
                    catch (Exception)
                    {
                        //Console.WriteLine("Greska pri replikaciji");
                    }
                }

                Thread.Sleep(2000);
            }
        }
        NativeRuntime.IFabricReplicator NativeRuntime.IFabricStatefulServiceReplica.EndOpen(NativeCommon.IFabricAsyncOperationContext context)
        {
            IReplicator replicator = AsyncTaskCallInAdapter.End <IReplicator>(context);

            // If it is the fabric replicator then return the actual native interface implementation
            // This will prevent going through a broker to translate native and managed code
            FabricReplicator fabricReplicator = replicator as FabricReplicator;

            if (fabricReplicator != null)
            {
                return(fabricReplicator.NativeReplicator);
            }

            // Return the broker that implements the correct native interfaces
            // If IReplicatorCatchupSpecificQuorum is supported return ReplicatorBroker2 (which derives from ReplicatorBroker and also implements IFabricReplicatorCatchupSpecificQuorum)
            // Else return ReplicatorBroker (which implements only IFabricReplicator and IFabricPrimaryReplicator)
            if (replicator is IReplicatorCatchupSpecificQuorum)
            {
                return(new ReplicatorBroker2(replicator));
            }
            else
            {
                return(new ReplicatorBroker(replicator));
            }
        }
Exemple #8
0
        public static void RegisterReplicator(IReplicator replicator, string guid, Action <pDoorState, pDoorState, bool> onStateChanged, out ushort newKey)
        {
            var info = new ReplicatorInfo()
            {
                Replicator     = replicator,
                GUID           = guid,
                OnStateChanged = onStateChanged
            };

            newKey = 0;
            switch (replicator.Type)
            {
            case SNet_ReplicatorType.Manager:
                newKey         = _ManagerIDBuffer++;
                replicator.Key = newKey;
                Replicators.Add(newKey, info);
                break;

            case SNet_ReplicatorType.SelfManaged:
                newKey         = _ManagedIDBuffer++;
                replicator.Key = newKey;
                Replicators.Add(newKey, info);
                break;
            }
        }
Exemple #9
0
        internal FabricReplicatorEx(NativeRuntime.IFabricReplicator nativeReplicator, NativeRuntime.IFabricAtomicGroupStateReplicatorEx nativeStateReplicator, NativeRuntime.IOperationDataFactory operationDataFactory)
        {
            this.internalReplicator = new InternalFabricReplicator(nativeReplicator);

            this.nativeStateReplicator = nativeStateReplicator;

            this.stateReplicator = FabricReplicatorEx.CreateStateReplicator(this.nativeStateReplicator, operationDataFactory);
        }
Exemple #10
0
        public BankTransactionService()
        {
            _bankCache       = ServiceLocator.GetInstance <ICache>();
            _replicatorProxy = ProxyPool.GetProxy <IReplicator>();

            _checkingTimer.Elapsed  += CheckingTimerLogic;
            _checkingTimer.AutoReset = true;
            _checkingTimer.Enabled   = true;
        }
 public ReplicaClientInterceptor(
     Options?options,
     IServiceProvider serviceProvider,
     IReplicator replicator,
     ILoggerFactory?loggerFactory = null)
     : base(options = options.OrDefault(serviceProvider), serviceProvider, loggerFactory)
 {
     Replicator       = replicator;
     VersionGenerator = options.VersionGenerator;
 }
Exemple #12
0
 public ReplicaClientInterceptor(
     Options options,
     IReplicator replicator,
     IMomentClock?clock           = null,
     ILoggerFactory?loggerFactory = null)
     : base(options, clock, loggerFactory)
 {
     Replicator       = replicator;
     VersionGenerator = options.VersionGenerator;
 }
Exemple #13
0
 public ReplicaMethodInterceptor(
     Options?options,
     IServiceProvider services,
     IReplicator replicator,
     ILoggerFactory?loggerFactory = null)
     : base(options ??= new(), services, loggerFactory)
 {
     Replicator       = replicator;
     VersionGenerator = options.VersionGenerator;
 }
        public MyCouchServerClient(ServerConnectionInfo connectionInfo, MyCouchClientBootstrapper bootstrapper = null)
        {
            Ensure.That(connectionInfo, "connectionInfo").IsNotNull();

            IsDisposed   = false;
            bootstrapper = bootstrapper ?? MyCouchClientBootstrappers.Default;

            Connection = bootstrapper.ServerConnectionFn(connectionInfo);
            Serializer = bootstrapper.SerializerFn();
            Databases  = bootstrapper.DatabasesFn(Connection);
            Replicator = bootstrapper.ReplicatorFn(Connection);
        }
 public ReplicaClientFunction(
     InterceptedMethodDescriptor method,
     IReplicator replicator,
     Generator <LTag> versionGenerator,
     ILogger <ReplicaClientFunction <T> >?log = null)
     : base(method, ((IReplicatorImpl)replicator).ServiceProvider)
 {
     Log = log ??= NullLogger <ReplicaClientFunction <T> > .Instance;
     IsLogDebugEnabled = Log.IsEnabled(LogLevel.Debug);
     VersionGenerator  = versionGenerator;
     Replicator        = replicator;
 }
Exemple #16
0
 public ReplicaMethodFunction(
     ComputeMethodDef method,
     IReplicator replicator,
     VersionGenerator <LTag> versionGenerator,
     ILogger <ReplicaMethodFunction <T> >?log = null)
     : base(method, ((IReplicatorImpl)replicator).Services)
 {
     Log              = log ?? NullLogger <ReplicaMethodFunction <T> > .Instance;
     DebugLog         = Log.IsEnabled(LogLevel.Debug) ? Log : null;
     VersionGenerator = versionGenerator;
     Replicator       = replicator;
 }
Exemple #17
0
 public ReplicaClientFunction(
     InterceptedMethod method,
     IReplicator replicator,
     Generator <LTag> versionGenerator,
     ILogger <ReplicaClientFunction <T> >?log = null)
     : base(method)
 {
     Log = log ??= NullLogger <ReplicaClientFunction <T> > .Instance;
     IsLogDebugEnabled = Log.IsEnabled(LogLevel.Debug);
     VersionGenerator  = versionGenerator;
     Replicator        = replicator;
 }
Exemple #18
0
        public bool CreateFile() //ovde treba samo da se kreira fajl, jer ce to raditi admin, a pravo upisa ima samo writter i to se morati u posebnoj metodi
        {
            if (StateService.stateService != EStateServers.Primarni)
            {
                MyException ex = new MyException("Error! IS NOT a primary\n");
                throw new FaultException <MyException>(ex);
            }

            CustomPrincipal principal = Thread.CurrentPrincipal as CustomPrincipal;

            if (!principal.IsInRole(Permissions.Create.ToString()))
            {
                MyException ex = new MyException("Error! IS NOT A Reader\n");
                throw new FaultException <MyException>(ex);
            }
            //   CustomAuditBehavior.AuthenticationSuccess(principal.Identity.Name.ToString());

            if (File.Exists(DataBase.FileName))
            {
                return(false);
            }

            lock (DataBase.lockObject)
            {
                FileStream fs = File.Create(DataBase.FileName);
                fs.Close();
            }
            try
            {
                if (StateService.stateService == EStateServers.Primarni)
                {
                    ChannelFactory <IReplicator> cfh2 = new ChannelFactory <IReplicator>("sekundarni");
                    IReplicator proxy2 = cfh2.CreateChannel();


                    proxy2.CreateFile();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
            //WindowsIdentity identity = WindowsIdentity.GetCurrent();
            //if (!identity.IsAuthenticated)
            //{
            //    MyException ex = new MyException("Neuspela autentifikacija ");
            //    throw new FaultException<MyException>(ex);
            //}


            return(true);
        }
Exemple #19
0
        public BankMasterCardService()
        {
            var caCertificate = CertificateManager.Instance.GetCACertificate();

            if (caCertificate == null)
            {
                throw new Exception("Certificate manager returned null for CA certificate.");
            }

            _bankCache = ServiceLocator.GetInstance <ICache>();
            _arbitrationServiceProvider = ServiceLocator.GetInstance <IArbitrationServiceProvider>();
            _replicatorProxy            = ProxyPool.GetProxy <IReplicator>();
        }
Exemple #20
0
        public MyCouchServerClient(IServerClientConnection connection, MyCouchClientBootstrapper bootstrapper = null)
        {
            Ensure.That(connection, "connection").IsNotNull();

            Connection = connection;

            bootstrapper = bootstrapper ?? new MyCouchClientBootstrapper();

            Serializer = bootstrapper.SerializerFn();
            Databases  = bootstrapper.DatabasesFn(Connection);
            Replicator = bootstrapper.ReplicatorFn(Connection);
            IsDisposed = false;
        }
Exemple #21
0
        public MyCouchServerClient(IServerClientConnection connection, MyCouchClientBootstrapper bootstrapper = null)
        {
            Ensure.That(connection, "connection").IsNotNull();

            Connection = connection;

            bootstrapper = bootstrapper ?? new MyCouchClientBootstrapper();

            Serializer = bootstrapper.SerializerFn();
            Databases = bootstrapper.DatabasesFn(Connection);
            Replicator = bootstrapper.ReplicatorFn(Connection);
            IsDisposed = false;
        }
        public override void SetUp()
        {
            base.SetUp();
            clientWorkDir    = CreateTempDir("httpReplicatorTest");
            handlerIndexDir  = NewDirectory();
            serverIndexDir   = NewDirectory();
            serverReplicator = new LocalReplicator();
            StartServer();

            IndexWriterConfig conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, null);

            conf.IndexDeletionPolicy = new SnapshotDeletionPolicy(conf.IndexDeletionPolicy);
            writer = new IndexWriter(serverIndexDir, conf);
            reader = DirectoryReader.Open(writer, false);
        }
Exemple #23
0
        private void ReplicationWorker(object param)
        {
            var cancelationToken = (CancellationToken)param;

            while (!cancelationToken.IsCancellationRequested)
            {
                if (_arbitrationServiceProvider?.State == ServiceState.Hot)
                {
                    try
                    {
                        if (_replicatorProxy != null)
                        {
                            while (!_replicationQueue.IsEmpty)
                            {
                                // Check connection before replicating to keep replication data
                                // on queue in case backup service fails
                                _replicatorProxy.CheckState();
                                if (_replicationQueue.TryDequeue(out var replicationItem))
                                {
                                    _replicatorProxy.ReplicateData(replicationItem);
                                }
                            }
                        }
                        else
                        {
                            _replicatorProxy = CreateReplicatorProxy();
                            if (_replicatorProxy?.CheckState() == ServiceState.Standby)
                            {
                                Console.WriteLine(
                                    $"Replicator proxy to {_replicatorProxyFactory.Endpoint.Address} opened.");
                            }
                            else
                            {
                                Thread.Sleep(100);
                            }
                        }
                    }
                    catch (SecurityAccessDeniedException secEx)
                    {
                        Console.WriteLine(
                            $"({nameof(BankServiceApp)}) [{nameof(ReplicatorProxy)}] Security exception while trying to replicate: {secEx.Message}");
                        _replicatorProxy = null;

                        // Break on sec exception since replicator probably doesn't have necessary privileges.
                        break;
                    }
                }
            }
Exemple #24
0
        public override void SetUp()
        {
            base.SetUp();

            publishDir       = NewMockDirectory();
            handlerDir       = NewMockDirectory();
            sourceDirFactory = new PerSessionDirectoryFactory(CreateTempDir("replicationClientTest").FullName);
            replicator       = new LocalReplicator();
            callback         = new IndexReadyCallback(handlerDir);
            handler          = new IndexReplicationHandler(handlerDir, callback.Call);
            client           = new ReplicationClient(replicator, handler, sourceDirFactory);

            IndexWriterConfig conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, null);

            conf.IndexDeletionPolicy = new SnapshotDeletionPolicy(conf.IndexDeletionPolicy);
            publishWriter            = new IndexWriter(publishDir, conf);
        }
        public override void SetUp()
        {
            base.SetUp();

            publishIndexDir = NewDirectory();
            publishTaxoDir = NewDirectory();
            handlerIndexDir = NewMockDirectory();
            handlerTaxoDir = NewMockDirectory();
            clientWorkDir = CreateTempDir("replicationClientTest");
            sourceDirFactory = new PerSessionDirectoryFactory(clientWorkDir.FullName);
            replicator = new LocalReplicator();
            callback = new IndexAndTaxonomyReadyCallback(handlerIndexDir, handlerTaxoDir);
            handler = new IndexAndTaxonomyReplicationHandler(handlerIndexDir, handlerTaxoDir, callback.Call);
            client = new ReplicationClient(replicator, handler, sourceDirFactory);

            IndexWriterConfig conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, null);
            conf.IndexDeletionPolicy = new SnapshotDeletionPolicy(conf.IndexDeletionPolicy);
            publishIndexWriter = new IndexWriter(publishIndexDir, conf);
            publishTaxoWriter = new IndexAndTaxonomyRevision.SnapshotDirectoryTaxonomyWriter(publishTaxoDir);
            config = new FacetsConfig();
            config.SetHierarchical("A", true);
        }
Exemple #26
0
        public bool ArchiveConsumation()
        {
            if (StateService.stateService != EStateServers.Primarni)
            {
                MyException ex = new MyException("Error! Not primary\n");
                throw new FaultException <MyException>(ex);
            }
            CustomPrincipal principal = Thread.CurrentPrincipal as CustomPrincipal;


            if (!File.Exists(DataBase.FileName))
            {
                return(false);
                //MyException ex = new MyException("Error! File doesn't exist\n");
                //throw new FaultException<MyException>(ex);
            }
            if (!principal.IsInRole(Permissions.Arhiving.ToString()))
            {
                MyException ex = new MyException("Error! IS NOT A Reader\n");
                throw new FaultException <MyException>(ex);
            }

            string fileNameCopy = DataBase.FileName;

            do
            {
                fileNameCopy += "-copy";
            } while (File.Exists(fileNameCopy));
            File.Copy(DataBase.FileName, fileNameCopy);

            if (StateService.stateService == EStateServers.Primarni)
            {
                ChannelFactory <IReplicator> cfh2 = new ChannelFactory <IReplicator>("sekundarni");
                IReplicator proxy2 = cfh2.CreateChannel();
                proxy2.ArchiveConsumation();
            }
            return(true);
        }
Exemple #27
0
 public ReplicationClientAnonymousInnerClass(IndexReplicationClientTest test, IReplicator replicator, IReplicationHandler handler, ISourceDirectoryFactory factory, AtomicInt32 failures)
     : base(replicator, handler, factory)
 {
     this.test     = test;
     this.failures = failures;
 }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="replicator">The <see cref="IReplicator"/> used for checking for updates</param>
 /// <param name="handler">The <see cref="IReplicationHandler"/> notified when new revisions are ready</param>
 /// <param name="factory">The <see cref="ISourceDirectoryFactory"/> for returning a <see cref="Directory"/> for a given source and session</param>
 public ReplicationClient(IReplicator replicator, IReplicationHandler handler, ISourceDirectoryFactory factory)
 {
     this.replicator = replicator;
     this.handler = handler;
     this.factory = factory;
 }
Exemple #29
0
 public ReplicatorBroker(IReplicator replicator)
 {
     this.replicator = replicator;
 }
Exemple #30
0
 public static IReplica <T> GetOrAdd <T>(this IReplicator replicator,
                                         PublicationRef publicationRef, bool requestUpdate = false)
 {
     var output = new Result <T>(default !, ReplicaHasBeenNeverUpdatedError);
 public LoggingReplicator(IReplicator replicator, ILogger logger)
 {
     _replicator = replicator;
     _logger     = logger;
 }