示例#1
0
        static void Main()
        {
            log4net.Config.XmlConfigurator.Configure(new FileInfo(AppDomain.CurrentDomain.BaseDirectory + "log4net.config"));
            ConsoleHelper.WriteLine(ELogCategory.Info, string.Format("ServiceStack.Redis.Demo.WinForm1 Startup..."), true);

            JsonConvert.DefaultSettings = () =>
            {
                JsonSerializerSettings jss = new JsonSerializerSettings();
                jss.DateFormatHandling = DateFormatHandling.MicrosoftDateFormat;
                jss.DateFormatString   = "yyyy-MM-dd HH:mm:ss";

                return(jss);
            };

            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
            Application.ThreadException += Application_ThreadException;

            ServiceStackRedisUtils.Init();
            MyRedisService.Instance.Init();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Application.Run(new Form1());
        }
        static void Main(string[] args)
        {
            ServiceStackRedisUtils.Init();

            _t.AutoReset = false;
            _t.Interval  = 1000;
            _t.Elapsed  += _t_Elapsed;



            while (true)
            {
                string line = Console.ReadLine();
                if (line != null)
                {
                    if (line.Equals("exit", StringComparison.OrdinalIgnoreCase))
                    {
                        break;
                    }
                    else
                    {
                        if (line.Equals("start", StringComparison.OrdinalIgnoreCase))
                        {
                            _t.Start();
                        }
                    }
                }
                else
                {
                    break;
                }
            }
        }
        private void button3_Click(object sender, EventArgs e)
        {
            string str = "";

            using (var client = ServiceStackRedisUtils.GetReadOnlyClient())
            {
                string info = client.Get <string>("AAtest001");
                str = string.Format("Addr: {0}{1}Info: {2}", client.Host + ":" + client.Port, Environment.NewLine, info);
            }

            MessageBox.Show(str, Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        private static void _t_Elapsed(object sender, ElapsedEventArgs e)
        {
            _t.Stop();

            string str1 = "";

            try
            {
                using (var client = ServiceStackRedisUtils.GetReadOnlyClient())
                {
                    string value = client.Get <string>("AAtest001");
                    str1 = string.Format("Addr: {0}{1}Value: {2}{1}", client.Host + ":" + client.Port, Environment.NewLine, value);
                }
            }
            catch (Exception e1)
            {
                Console.WriteLine("Redis Exception: {0}", e1.Message);
            }

            Console.WriteLine(str1);

            _t.Start();
        }