Beispiel #1
0
        static void ReferToService(string serviceAddress)
        {
            try
            {
                if (prev == null)
                {
                    prev = Emulator.GetRandom(_terminalId);
                }
                List <IMetering> data = new List <IMetering>();
                for (int i = 0; i < points; i++)
                {
                    prev = Emulator.GetNext(prev, new TimeSpan(0, 0, 0, 0, timeout / points), (float)new Random().NextDouble() * 60);
                    data.Add(prev);
                }

                AuthorizationServiceProxy authorizationProxy = new AuthorizationServiceProxy();
                authorizationProxy.Login(_terminalId);
                DataServiceProxy dataProxy = new DataServiceProxy();
                dataProxy.SendData(_terminalId, data.Select(x => new MeteringDto(x)).ToList());
                logger.Info("Data sent");
            }
            catch (Exception e)
            {
                logger.Warn("Can't call method: {0}", e.Message);
            }
        }
Beispiel #2
0
        /// <summary>
        /// 测试 智能引用代理.
        /// </summary>
        private static void TestSmartReference()
        {
            // 创建代理.
            IDataService dataService = new DataServiceProxy();

            // 调用代理类的方法.
            dataService.DoSomething();
        }
        static void Main(string[] args)
        {
            User         user        = new User(17, "Neil");
            IDataService dataService = new DataServiceProxy(user);
            Stream       result      = dataService.GetData();

            if (result == Stream.Null)
            {
                user.Age = 18;
                result   = dataService.GetData();
                if (result != Stream.Null)
                {
                    using (StreamReader streamReader = new StreamReader(result))
                    {
                        Console.WriteLine(streamReader.ReadToEnd());
                    }
                }
            }

            Console.ReadKey();
        }