Пример #1
0
        public bool Generate(DateTime dateTime, string name, string msg, int risk)
        {
            bool end = false;

            try
            {
                if (factory.Generate(dateTime, name, msg, risk))
                {
                    Console.WriteLine("{0}", ReadResourceFile.SuccessfullyDoneFunction(Permissions.Generate.ToString()));
                }
                else
                {
                    Console.WriteLine("{0}", ReadResourceFile.UnsuccessfullyDoneFunction(Permissions.Generate.ToString(), Permissions.Generate.ToString()));
                }
                end = true;
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: {0}", e.Message);
            }

            return(end);
        }
Пример #2
0
        static void Main(string[] args)
        {
            NetTcpBinding binding = new NetTcpBinding();

            binding.Security.Mode = SecurityMode.Message;
            binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows;

            string          address  = "net.tcp://localhost:9999/WCFService";
            EndpointAddress ea       = new EndpointAddress(new Uri(address));
            string          name     = WindowsIdentity.GetCurrent().Name;
            string          authType = WindowsIdentity.GetCurrent().AuthenticationType;

            Console.WriteLine("Name: " + name);
            ClientProxy proxy = new ClientProxy(binding, ea);

            Random random = new Random();

            Alarm        a          = new Alarm();
            List <Alarm> listaIspis = new List <Alarm>();
            int          option     = 0;

            do
            {
                Console.WriteLine();
                Console.WriteLine("1. Generate");
                Console.WriteLine("2. Read");
                Console.WriteLine("3. Delete");
                Console.WriteLine("4. DeleteAll");
                Console.WriteLine("5. EXIT");
                Console.WriteLine();
                int.TryParse(Console.ReadLine(), out option);

                switch (option)
                {
                case 1:
                    proxy.Generate(DateTime.Now, name, ReadResourceFile.RandomMessage(), random.Next(1, 1000));
                    break;

                case 2:
                    listaIspis = proxy.Read();
                    foreach (Alarm al in listaIspis)
                    {
                        Console.WriteLine("{0}|{1}|{2}|{3}", al.time, al.name, al.message, al.risk);
                    }
                    break;

                case 3:
                    proxy.Delete();
                    break;

                case 4:
                    proxy.DeleteAll();
                    break;

                case 5:
                    return;

                default:
                    Console.WriteLine("Invalid input. TRY AGAIN!");
                    break;
                }
            } while (option != 5);

            Console.ReadLine();
        }