Beispiel #1
0
        public void OnDataSyncFromPartner(string ResourceName, string ExchangeData)
        {
            if (Mode != RedundancyMode.Slave) //Dongmin 20191109
            {
                return;
            }

            //LOG.Debug(string.Format("RedundancyServer:从主站资源{0}同步数据",ResourceName));

            try
            {
                /*var sw=new Stopwatch();
                 * sw.Start();*/

                IResource resource = ResourceManager.GetResource(ResourceName);

                if (resource is IRedundancy)
                {
                    IRedundancy res = (IRedundancy)resource;

                    if (res.NeedDataSync)
                    {
                        res.ExtractSyncData(ExchangeData);
                    }
                }

                /*sw.Stop();
                 * LOG.Info($"冗餘数据同步執行時間:{sw.ElapsedMilliseconds}ms");*/
            }
            catch (Exception ex)
            {
                Log.Error(string.Format("获得主站资源:{0}出错:{1}", ResourceName, ex));
            }
        }
Beispiel #2
0
        // 主站调用 Dongmin 20191005
        public void OnDataSyncToPartner(object sender)
        {
            //夏 2019年8月22日 17:46:53  判断host是否为null
            if (_host == null)
            {
                return;
            }

            // David 20191005
            if (!PartnerAlive)
            {
                return;
            }

            PartnerProxy _proxy = (PartnerProxy)_host.GetProxy();

            if (_proxy != null)
            {
                //_proxy.ExchangeData("testresource","testdata"); //测试

                foreach (IResource resource in ResourceManager.GetAllResources())
                {
                    if (resource is IRedundancy)
                    {
                        IRedundancy res = (IRedundancy)resource;

                        if (res.NeedDataSync)
                        {
                            string dataToSend = res.BuildSyncData();

                            //LOG.Debug(string.Format("RedundancyServer:向从站同步数据 resource:{0},data:{1}", resource.ResourceName, dataToSend));
                            _proxy.ExchangeData(resource.ResourceName, dataToSend);
                        }
                    }
                }
            }
        }