Ejemplo n.º 1
0
        private bool TryApplyTransaction()
        {
            try
            {
                Thread.Sleep(TimeSpan.FromSeconds(20));
                TransactionManagerServiceProxy proxyForTM = new TransactionManagerServiceProxy(ConfigurationManager.AppSettings["TM"]);
                bool pom = false;
                while (!pom)
                {
                    pom = proxyForTM.StartEnlist().GetAwaiter().GetResult();
                }

                proxyForTM.Enlist().GetAwaiter().GetResult();
                NDSModelProxy proxyForScada = new NDSModelProxy(ConfigurationManager.AppSettings["SCADAM"]);
                CEModelProxy  proxyForCE    = new CEModelProxy(ConfigurationManager.AppSettings["CEM"]);

                bool success = false;
                if (proxyForScada.ModelUpdate(affectedEntities).GetAwaiter().GetResult())
                {
                    success = true;
                }

                if (proxyForCE.ModelUpdate(affectedEntities).GetAwaiter().GetResult())
                {
                    success = true;
                }

                proxyForTM.EndEnlist(success).GetAwaiter().GetResult();
                try
                {
                    var subscription = new Subscription();
                    var publisher    = new Publisher(subscription.Topic, subscription.ConnectionString);
                    var dtos         = DtoConverter.Convert(networkDataModelCopy);
                    var json         = JsonTool.Serialize(new ModelUpdateEvent(dtos));
                    var msg          = new PubSubMessage()
                    {
                        Content     = json,
                        ContentType = ContentType.NMS_UPDATE,
                        Sender      = Sender.NMS
                    };
                    publisher.SendMessage(msg).ConfigureAwait(false).GetAwaiter().GetResult();
                }
                catch { }

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
        public void EnList()
        {
            TransactionManagerServiceProxy proxyForTM = new TransactionManagerServiceProxy(ConfigurationReader.ReadValue(_context, "Settings", "TM") ?? "fabric:/ServiceFabricApp/TransactionManagerService");

            proxyForTM.Enlist().GetAwaiter().GetResult();
        }