Пример #1
0
        static async Task Initialize()
        {
            var host = new ServiceHost(typeof(Subscriber));

            host.AddServiceEndpoint(typeof(INotifySubscriberContract),
                                    new NetTcpBinding(),
                                    ServiceDefines.Instance.ServiceNameToServiceUri[MicroserviceNames.SubscriberTester]);
            host.Open();

            var topics = new List <Topic>
            {
                Topic.ACTIVE_OUTAGE,
                Topic.ARCHIVED_OUTAGE,
                Topic.MEASUREMENT,
                Topic.SWITCH_STATUS,
                Topic.OUTAGE_EMAIL,
                Topic.OMS_MODEL,
                Topic.TOPOLOGY,
            };

            var regSub = RegisterSubscriberClient.CreateClient();
            await regSub.SubscribeToTopics(topics, MicroserviceNames.SubscriberTester);

            var subTopics = await regSub.GetAllSubscribedTopics(MicroserviceNames.SubscriberTester);

            Console.WriteLine($"Number of subscribed Topics: {subTopics.Count}");
        }
Пример #2
0
        private async Task Initialize()
        {
            try
            {
                InitializeReliableCollections();
                Logger.LogDebug($"{baseLogString} Initialize => ReliableDictionaries initialized.");
                var topologyProviderClient = TopologyProviderClient.CreateClient();
                using (ITransaction tx = this.StateManager.CreateTransaction())
                {
                    var result = await StateManager.TryGetAsync <IReliableDictionary <string, OutageTopologyModel> >(ReliableDictionaryNames.OutageTopologyModel);

                    if (result.HasValue)
                    {
                        await result.Value.SetAsync(tx, ReliableDictionaryNames.OutageTopologyModel, await topologyProviderClient.GetOMSModel());

                        await tx.CommitAsync();
                    }
                    else
                    {
                        Logger.LogError($"{baseLogString} Initialize => Reliable dictionary {ReliableDictionaryNames.OutageTopologyModel} was not found.");
                    }
                }

                var registerSubscriberClient = RegisterSubscriberClient.CreateClient();
                await registerSubscriberClient.SubscribeToTopic(Topic.SWITCH_STATUS, MicroserviceNames.OmsOutageLifecycleService);

                await registerSubscriberClient.SubscribeToTopic(Topic.OMS_MODEL, MicroserviceNames.OmsOutageLifecycleService);

                Logger.LogDebug($"{baseLogString} Initialize => Successfully subscribed to topics.");
            }
            catch (Exception e)
            {
                Logger.LogError($"{baseLogString} Initialize => Exception: {e.Message}");
            }
        }
Пример #3
0
        /// <summary>
        /// This is the main entry point for your service instance.
        /// </summary>
        /// <param name="cancellationToken">Canceled when Service Fabric needs to shut down this service instance.</param>
        protected override async Task RunAsync(CancellationToken cancellationToken)
        {
            //TEST Subscribe
            try
            {
                IRegisterSubscriberContract registerSubscriberClient = RegisterSubscriberClient.CreateClient();
                var subscriptions = await registerSubscriberClient.GetAllSubscribedTopics("TestService");

                var result = await registerSubscriberClient.SubscribeToTopics(new List <Topic>() { Topic.MEASUREMENT, Topic.SWITCH_STATUS }, MicroserviceNames.TestService);

                subscriptions = await registerSubscriberClient.GetAllSubscribedTopics(MicroserviceNames.TestService);
            }
            catch (Exception e)
            {
            }

            //TEST PUBLISH
            //try
            //{
            //    var data = new AnalogModbusData(1, AlarmType.NO_ALARM, 0, CommandOriginType.OTHER_COMMAND);
            //    var publishableMessage = new SingleAnalogValueSCADAMessage(data);
            //    var publication = new ScadaPublication(Topic.MEASUREMENT, publishableMessage);
            //    await publisherClient.Publish(publication, MicroserviceNames.TestService);
            //}
            //catch (Exception e)
            //{
            //}
        }
        /// <summary>
        /// This is the main entry point for your service replica.
        /// This method executes when this replica of your service becomes primary and has write status.
        /// </summary>
        /// <param name="cancellationToken">Canceled when Service Fabric needs to shut down this service replica.</param>
        protected override async Task RunAsync(CancellationToken cancellationToken)
        {
            try
            {
                InitializeReliableCollections();
                string debugMessage = $"{baseLogString} RunAsync => ReliableDictionaries initialized.";
                Logger.LogDebug(debugMessage);

                var registerSubscriberClient = RegisterSubscriberClient.CreateClient();
                await registerSubscriberClient.SubscribeToTopic(Topic.OUTAGE_EMAIL, MicroserviceNames.OmsCallTrackingService);
            }
            catch (Exception e)
            {
                Logger.LogError($"{baseLogString} RunAsync => Exception: {e.Message}");
            }
        }
        /// <summary>
        /// This is the main entry point for your service replica.
        /// This method executes when this replica of your service becomes primary and has write status.
        /// </summary>
        /// <param name="cancellationToken">Canceled when Service Fabric needs to shut down this service replica.</param>
        protected override async Task RunAsync(CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            try
            {
                InitializeReliableCollections();
                string debugMessage = $"{baseLogString} RunAsync => ReliableDictionaries initialized.";
                Logger.LogDebug(debugMessage);
                ServiceEventSource.Current.ServiceMessage(this.Context, $"[OMS.OutageSimulatorService | Information] {debugMessage}");

                var registerSubscriber = RegisterSubscriberClient.CreateClient();
                await registerSubscriber.SubscribeToTopic(Topic.SWITCH_STATUS, MicroserviceNames.OmsOutageSimulatorService);

                debugMessage = $"{baseLogString} RunAsync => Subscribed to {Topic.SWITCH_STATUS} topic.";
                Logger.LogDebug(debugMessage);
                ServiceEventSource.Current.ServiceMessage(this.Context, $"[OMS.OutageSimulatorService | Information] {debugMessage}");
            }
            catch (Exception e)
            {
                string errorMessage = $"{baseLogString} RunAsync => Exception caught: {e.Message}.";
                Logger.LogInformation(errorMessage, e);
                ServiceEventSource.Current.ServiceMessage(this.Context, $"[OMS.OutageSimulatorService | Error] {errorMessage}");
            }

            while (true)
            {
                try
                {
                    await controlCycle.Start();

                    var message = $"{baseLogString} RunAsync => ControlCycle executed.";
                    Logger.LogVerbose(message);
                }
                catch (Exception e)
                {
                    string errorMessage = $"{baseLogString} RunAsync (while) => Exception caught: {e.Message}.";
                    Logger.LogInformation(errorMessage, e);
                    ServiceEventSource.Current.ServiceMessage(this.Context, $"[OMS.OutageSimulatorService | Error] {errorMessage}");
                }

                await Task.Delay(TimeSpan.FromMilliseconds(2_000), cancellationToken);
            }
        }
Пример #6
0
        public WebAdapterService(StatelessServiceContext context)
            : base(context)
        {
            this.baseLogString = $"{this.GetType()} [{this.GetHashCode()}] =>{Environment.NewLine}";
            Logger.LogDebug($"{baseLogString} Ctor => Logger initialized");

            try
            {
                this.webAdapterProvider       = new WebAdapterProvider();
                this.notifySubscriberProvider = new NotifySubscriberProvider(MicroserviceNames.WebAdapterService);

                this.registerSubscriberClient = RegisterSubscriberClient.CreateClient();
            }
            catch (Exception e)
            {
                string errorMessage = $"{baseLogString} Ctor => exception {e.Message}";
                Logger.LogError(errorMessage, e);
                ServiceEventSource.Current.ServiceMessage(this.Context, $"[WebAdapterService | Error] {errorMessage}");
            }
        }
Пример #7
0
        /// <summary>
        /// This is the main entry point for your service replica.
        /// This method executes when this replica of your service becomes primary and has write status.
        /// </summary>
        /// <param name="cancellationToken">Canceled when Service Fabric needs to shut down this service replica.</param>
        protected override async Task RunAsync(CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            try
            {
                InitializeReliableCollections();
                string debugMessage = $"{baseLogString} RunAsync => ReliableDictionaries initialized.";
                Logger.LogDebug(debugMessage);

                this.registerSubscriberClient = RegisterSubscriberClient.CreateClient();
                await this.registerSubscriberClient.SubscribeToTopic(Topic.MEASUREMENT, MicroserviceNames.CeMeasurementProviderService);

                await this.registerSubscriberClient.SubscribeToTopic(Topic.SWITCH_STATUS, MicroserviceNames.CeMeasurementProviderService);
            }
            catch (Exception e)
            {
                string errorMessage = $"{baseLogString} RunAsync => Exception caught: {e.Message}.";
                Logger.LogInformation(errorMessage, e);
            }
        }
Пример #8
0
 static async Task UnsubscribeAll()
 {
     var regSub = RegisterSubscriberClient.CreateClient();
     await regSub.UnsubscribeFromAllTopics(MicroserviceNames.SubscriberTester);
 }