Ejemplo n.º 1
0
        private static void ProcessAction(ClientProxy proxy, int actionNum)
        {
            switch (actionNum)
            {
            case 1:
                SendAlarm(proxy);
                break;

            case 2:
                ListAllAlarms(proxy);
                break;

            case 3:
                RemoveClientAlarms(proxy);
                break;

            case 4:
                RemoveAllAlarms(proxy);
                break;

            case 5:
                AlarmRemovealRequests(proxy);
                break;

            case 6:
                exitFlag = true;
                break;

            default:
                Console.WriteLine("Invalid action.");
                break;
            }
        }
Ejemplo n.º 2
0
 private static void RemoveAllAlarms(ClientProxy proxy)
 {
     if (proxy.RemoveAllAlarms())
     {
         Console.WriteLine("Successfully removed all alarms.");
     }
 }
Ejemplo n.º 3
0
        private static void AlarmRemovealRequests(ClientProxy proxy)
        {
            var requests = proxy.GetClientRemovalRequests();

            if (requests.Item2)
            {
                Console.WriteLine("Getting clients removal requests...");
                foreach (string item in requests.Item1)
                {
                    Console.WriteLine($"Request from client: {item}");
                    string response;
                    do
                    {
                        Console.Write($"Allow request? (Y/N): ");
                        response = Console.ReadLine();
                    } while (!(response.Equals("Y", StringComparison.OrdinalIgnoreCase) || response.Equals("N", StringComparison.OrdinalIgnoreCase)));

                    if (response.Equals("Y", StringComparison.OrdinalIgnoreCase))
                    {
                        if (proxy.ApprovedRemoval(item))
                        {
                            Console.WriteLine("Request approved.");
                        }
                    }
                    if (response.Equals("N", StringComparison.OrdinalIgnoreCase))
                    {
                        if (proxy.DeniedRemoval(item))
                        {
                            Console.WriteLine("Request denied.");
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
 private static void SendAlarm(ClientProxy proxy)
 {
     if (proxy.SendAlarm(CreateAlarm()))
     {
         Console.WriteLine("Alarm sent.");
     }
 }
Ejemplo n.º 5
0
 private static void RemoveClientAlarms(ClientProxy proxy)
 {
     if (proxy.RemoveClientAlarms())
     {
         Console.WriteLine("CLient alarms waiting to be approved for removal.");
     }
 }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            using (var client = new ClientProxy())
            {
                Console.WriteLine(client.Test("DLz"));
            }

            Console.ReadKey();
        }
Ejemplo n.º 7
0
        private static void Main(string[] args)
        {
            CLocation myLocation = new CLocation();

            myLocation.GetLocationDataEvent();

            NetTcpBinding binding = new NetTcpBinding();

            binding.CloseTimeout   = new TimeSpan(0, 10, 0);
            binding.OpenTimeout    = new TimeSpan(0, 10, 0);
            binding.ReceiveTimeout = new TimeSpan(0, 10, 0);
            binding.SendTimeout    = new TimeSpan(0, 10, 0);

            string address = "net.tcp://localhost:9999/WcfService";
            string administrationAddress = "net.tcp://localhost:5000/SubjectAdministrationService";

            bool   isAuthenticated = false;
            string userId          = string.Empty;

            using (AuthProxy authProxy = new AuthProxy(binding, new EndpointAddress(new Uri(administrationAddress))))
            {
                isAuthenticated = authProxy.IsAuthenticated();
                if (isAuthenticated)
                {
                    userId = authProxy.AuthenticatedUserId();
                    //Console.WriteLine("User Location: ");
                    //string location = Console.ReadLine();
                    Console.WriteLine("Location: " + CLocation.location);
                    authProxy.SetLocation(userId, CLocation.location);
                }
            }

            if (isAuthenticated)
            {
                using (ClientProxy proxy = new ClientProxy(binding, new EndpointAddress(new Uri(address))))
                {
                    Console.WriteLine("\nRequest for editing student remaining courses.");
                    string ret = proxy.EditRemainingCourses();
                    Console.WriteLine(ret);
                    // Console.ReadKey();

                    Console.WriteLine("\nRequest for student remaining courses.");
                    ret = proxy.ViewRemainingCourses();
                    Console.WriteLine(ret);
                    //Console.ReadKey();

                    Console.WriteLine("\nRequest for exam registration.");
                    ret = proxy.RegisterExam();
                    Console.WriteLine(ret);
                }
            }
            Console.ReadKey();
        }
Ejemplo n.º 8
0
        private static void ListAllAlarms(ClientProxy proxy)
        {
            var allAlarms = proxy.GetAllAlarms();

            if (allAlarms.Item2)
            {
                Console.WriteLine("Listing all alarms ...");
                foreach (var item in allAlarms.Item1)
                {
                    Console.WriteLine(item);
                }
            }
        }
Ejemplo n.º 9
0
        static async Task Main(string[] args)
        {
            //RabbitMQ
            Console.WriteLine("--- Client RabbitMQ  ---");
            var mqF = new RabbitMQClientConnectionFactoryOptions(Helper.GetMQOptions(), NullLoggerFactory.Instance);

            _clientProxy                   = NManager.CreateClientProxy <IService>(mqF);
            _clientProxy.Connected        += (s, e) => Console.WriteLine("[event] Connected");
            _clientProxy.DisConnected     += (s, e) => Console.WriteLine("[event] DisConnected");
            _clientProxy.ExceptionInvoked += (s, e) => Console.WriteLine("[event] ExceptionInvoked");

            //Heartbeat
            _clientProxy.HeartbeatAsync += (s, e) =>
            {
                Console.WriteLine("[event] Heartbeat");
                ((IService)((IClientProxy)s).Proxy).Hearbeat();
                return(Task.CompletedTask);
            };
            //clientProxy.StartHeartbeat(true);

            _proxy      = _clientProxy.Proxy;
            _proxyAsync = NManager.CreateClientProxy <IServiceAsync>(mqF).Proxy;
            RunTest();
            await RunTestAsync();

            //Grpc
            Console.WriteLine("\r\n--- Client Grpc  ---");
            var grpcF = new GrpcClientConnectionFactoryOptions(
                new GrpcClientOptions {
                Host = "localhost", Port = 50001
            });

            _clientProxy = NetRpc.Grpc.NManager.CreateClientProxy <IService>(grpcF);
            _proxy       = _clientProxy.Proxy;
            _proxyAsync  = NetRpc.Grpc.NManager.CreateClientProxy <IServiceAsync>(grpcF).Proxy;

            RunTest();
            await RunTestAsync();

            Console.WriteLine("Test end.");
            Console.Read();
        }
Ejemplo n.º 10
0
        private static void Main()
        {
            var binding = new NetTcpBinding();

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


            using (var proxy = new ClientProxy(binding, new EndpointAddress("net.tcp://localhost:15000/PrimaryService")))
            {
                while (!exitFlag)
                {
                    PrintMenu();
                    int input = GetInput();

                    ProcessAction(proxy, input);
                }
            }

            Console.WriteLine("Press <enter> to exit...");
            Console.ReadKey();
        }
        public void StartComunication(string address)
        {
            if (this.HostAddress.Equals(address))
            {
                return;
            }
            if (clientSessions.ContainsKey(address))
            {
                PrintMessage.Print(string.Format("You are already connected to client: {0}", address));
                return;
            }

            NetTcpBinding binding = new NetTcpBinding();

            binding.SendTimeout    = new TimeSpan(0, 5, 5);
            binding.ReceiveTimeout = new TimeSpan(0, 5, 5);
            binding.OpenTimeout    = new TimeSpan(0, 5, 5);
            binding.CloseTimeout   = new TimeSpan(0, 5, 5);
            IClientContract serverProxy = new ClientProxy(new EndpointAddress(address), binding, this);

            byte[]      sessionKey = RandomGenerateKey();
            SessionData sd         = new SessionData()
            {
                AesAlgorithm = new AES128_ECB(sessionKey), Proxy = serverProxy, Address = address
            };

            CertificateDto serverCert = serverProxy.SendCert(new CertificateDto(myCertificate, false));

            if (!vaProxy.isCertificateValidate(serverCert.GetCert(false)))
            {
                PrintMessage.Print("Starting communication failed!");
                return;
            }

            byte[] encryptedSessionKey = null;
            try
            {
                RSACryptoServiceProvider publicKey = (RSACryptoServiceProvider)serverCert.GetCert(false).PublicKey.Key;

                if (publicKey != null)
                {
                    encryptedSessionKey = publicKey.Encrypt(sessionKey, true);
                }
                else
                {
                    PrintMessage.Print("Error, public key is null");
                    return;
                }
            }
            catch (Exception e)
            {
                PrintMessage.Print(string.Format("Error: {0}", e.Message));
            }
            bool success = serverProxy.SendKey(encryptedSessionKey);

            if (success)
            {
                sqliteWrapper.InsertToTable(sd.Address);

                object sessionInfo = serverProxy.GetSessionInfo(HostAddress);
                if (sessionInfo != null)
                {
                    string   sessionId      = System.Text.Encoding.UTF8.GetString(sd.AesAlgorithm.Decrypt((byte[])sessionInfo)).Trim();
                    string[] sessionIdSplit = sessionId.Split('|');
                    sd.CallbackSessionId = sessionIdSplit[0];
                    sd.ProxySessionId    = sessionIdSplit[1];
                    lock (objLock)
                    {
                        clientSessions.Add(sd.Address, sd);
                        PrintMessage.Print("Session is opened");
                    }
                }
            }
            else
            {
                PrintMessage.Print("Starting communication failed!");
            }
        }
Ejemplo n.º 12
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();
        }
Ejemplo n.º 13
0
        private static void Main(string[] args)
        {
            NetTcpBinding binding    = new NetTcpBinding();
            string        address    = "net.tcp://localhost:9999/FileManager";
            string        signCertCN = Formatter.ParseName(WindowsIdentity.GetCurrent().Name.ToLower()) + "_sign"; //client_sign invalidUser_sign Client invalidUser

            Console.ReadLine();
            try
            {
                using (ClientProxy proxy = new ClientProxy(binding, new EndpointAddress(new Uri(address))))
                {
                    if (signCertCN == "invaliduser_sign")
                    {
                        signCertCN = "invalidUser_sign";
                    }

                    X509Certificate2 clientCERT = CertManager.GetCertificateFromStorage(StoreName.My,
                                                                                        StoreLocation.LocalMachine, signCertCN);
                    Console.WriteLine("Connected to Services");
                    byte[] signature;

                    while (true)
                    {
                        Console.WriteLine("*****************Menu*****************");
                        Console.WriteLine("1. Dodaj fajl\n2. Azuriraj fajl\n3.Exit");
                        Console.Write("Choose option: ");
                        int choice = int.Parse(Console.ReadLine());
                        switch (choice)
                        {
                        case 1:
                            Console.WriteLine("Unesite ime fajla u kom zelite da unesete tekst");
                            string filename = Console.ReadLine();
                            Console.WriteLine("Unesite tekst koji zelite da upisete u fajl koji ste uneli");
                            string text = Console.ReadLine();
                            signature = DigitalSignature.Create(text, HashAlgorithms.SHA1, clientCERT);
                            proxy.AddFile(filename, signature, text);
                            break;

                        case 2:
                            Console.WriteLine("Unesite ime fajla u kom zelite da promenite tekst");
                            filename = Console.ReadLine();
                            Console.WriteLine("Unesite tekst koji zelite da izmenite");
                            text      = Console.ReadLine();
                            signature = DigitalSignature.Create(text, HashAlgorithms.SHA1, clientCERT);
                            proxy.EditFile(filename, signature, text);
                            break;

                        case 3:
                            Console.WriteLine("Press any key to exit the application..");
                            Console.ReadLine();
                            return;

                        default:
                            Console.WriteLine("Niste uneli ispravnu opciju.");
                            break;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Something went wrong while starting Client service");
                Console.WriteLine("[ERROR] {0}", e.Message);
                Console.WriteLine("[StackTrace] {0}", e.StackTrace);
            }
        }
Ejemplo n.º 14
0
        static void Main(string[] args)
        {
            NetTcpBinding binding = new NetTcpBinding();
            //binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Certificate;
            string address = "net.tcp://localhost:5500/DataManagment";

            int    option     = 0;          // Promenljiva option u kojoj se skladisti izabrana opcija.
            string opt        = "";         // Promenljiva opt u kojoj se skladisti string reprezentacija odabrane opcije.
            bool   isOptValid = false;      // Promenljiva isOptValid u kojoj se belezi da je izabrana opcija validna.

            string privateKey = "burek";    // Kljuc za enkripciju i dekripciju podataka.

            byte[] keyb = Encoding.ASCII.GetBytes(privateKey);

            string           clientCertCN = Formatter.ParseName(WindowsIdentity.GetCurrent().Name);
            X509Certificate2 clientCert   = CertificateManager.GetCertificateFromStorage(StoreName.My, StoreLocation.LocalMachine, clientCertCN);

            if (clientCert != null)
            {
                AuthenticationService authService = new AuthenticationService();

                Console.WriteLine("");

                using (ClientProxy clp = new ClientProxy(binding, address))
                {
                    while (option != 3)
                    {
                        Console.WriteLine("\t\t\t\t\t|=====================================|");        // Ispis glavnog menija.
                        Console.WriteLine("\t\t\t\t\t|              MAIN MENU              |");
                        Console.WriteLine("\t\t\t\t\t|-------------------------------------|");
                        Console.WriteLine("\t\t\t\t\t|                                     |");
                        Console.WriteLine("\t\t\t\t\t|              1. Write               |");
                        Console.WriteLine("\t\t\t\t\t|              2. Read                |");
                        Console.WriteLine("\t\t\t\t\t|              3. Exit                |");
                        Console.WriteLine("\t\t\t\t\t|                                     |");
                        Console.WriteLine("\t\t\t\t\t|=====================================|\n\n");

                        do  // Otkrivanje nevalidne vrednosti opcije.
                        {
                            Console.Write("Enter option number: ");
                            opt = Console.ReadLine();

                            isOptValid = int.TryParse(opt, out option);

                            if (isOptValid == false)                // Slucaj kada odabrana opcija nije numericka vrednost.
                            {
                                Console.WriteLine("\n---------------------");
                                Console.WriteLine("Invalid option value.");
                                Console.WriteLine("---------------------\n");
                            }
                            else if (option < 1 || option > 3)      // Odabrana opcija je van opsega. Odabir nepostojece opcije.
                            {
                                Console.WriteLine("\n----------------------------------");
                                Console.WriteLine("The entered option does not exist.");
                                Console.WriteLine("----------------------------------\n");
                            }
                        } while (isOptValid == false || option < 1 || option > 3);

                        switch (option)
                        {
                        case 1:
                        {
                            string id   = "";               // Promenljiva id u kojoj se skladisti vrednost za ID elementa.
                            string name = "";               // Promenljiva name u kojoj se skladisti vrednost za ime elementa.

                            Console.WriteLine("\n=======================================================================================================================");
                            Console.WriteLine("\t\t\t\t\t\t\t WRITE");               // Naznaka korisniku da je program usao u odabranu opciju.
                            Console.WriteLine("-----------------------------------------------------------------------------------------------------------------------\n");

                            do                                              // ID mora da ima najmanje 4 karaktera.
                            {
                                Console.Write("Enter ID: ");                // Unosenje i skladistenje ID-a elementa.
                                id = Console.ReadLine();

                                if (id.Length < 4)
                                {
                                    Console.WriteLine("\n---------------------------------------");
                                    Console.WriteLine("The ID must have at least 4 characters.");
                                    Console.WriteLine("---------------------------------------\n");
                                }
                            } while (id.Length < 4);

                            do                                              // Ime mora da ima najmanje 3 karaktera.
                            {
                                Console.Write("\nEnter name: ");            // Unosenje i skladistenje imena elementa.
                                name = Console.ReadLine();

                                if (name.Length < 3)
                                {
                                    Console.WriteLine("\n-----------------------------------------");
                                    Console.WriteLine("The name must have at least 3 characters.");
                                    Console.WriteLine("-----------------------------------------");
                                }
                            } while (name.Length < 3);

                            byte[] idB   = Encoding.ASCII.GetBytes(id);             // Enkodiranje ID-a i naziva elementa u niz byte-ova.
                            byte[] nameB = Encoding.ASCII.GetBytes(name);

                            byte[] idEnc   = RC4.Encrypt(keyb, idB);                // Enkriptovanje ID-a i naziva elementa.
                            byte[] nameEnc = RC4.Encrypt(keyb, nameB);

                            clp.Write(idEnc, nameEnc);                              // Prosledjivanje enkriptovanih podataka.

                            Console.WriteLine("\n-----------------------------------------------------------------------------------------------------------------------");
                            Console.WriteLine("\t\t\t\t   The specified element has been sucessfully added.");
                            Console.WriteLine("-----------------------------------------------------------------------------------------------------------------------");

                            Console.WriteLine("\n=======================================================================================================================\n\n"); // Naznaka korisniku da je zavrsen rad sa prvom opcijom.

                            break;                                                                                                                                              // Zavrsetak prve opcije.
                        }

                        case 2:                         // Prikazivanje svih elemenata koji se trenutno nalaze u bazi podataka.
                        {
                            Console.WriteLine("\n=======================================================================================================================");
                            Console.WriteLine("\t\t\t\t\t\t\t READ");
                            Console.WriteLine("-----------------------------------------------------------------------------------------------------------------------\n");

                            Dictionary <byte[], byte[]> dic = clp.Read(); // Poziva se metoda za citanje elemenata.

                            if (dic.Count == 0)                           // Ukoliko baza podataka ne postoji korisnik se obavestava o tome.
                            {
                                Console.WriteLine("-----------------------------------------------------------------------------------------------------------------------");
                                Console.WriteLine("\t\t       The data base does not exist. It will be created when an element is added.");
                                Console.WriteLine("-----------------------------------------------------------------------------------------------------------------------\n");
                            }
                            else
                            {
                                foreach (KeyValuePair <byte[], byte[]> kvp in dic)            // Ispis pronadjenih elemenata.
                                {
                                    byte[] keyDecrBytes   = RC4.Decrypt(keyb, kvp.Key);
                                    byte[] valueDecrBytes = RC4.Decrypt(keyb, kvp.Value);

                                    string idDecr    = Encoding.ASCII.GetString(keyDecrBytes);
                                    string valueDecr = Encoding.ASCII.GetString(valueDecrBytes);

                                    Console.WriteLine("------------------------------");
                                    Console.WriteLine("ID: {0}", idDecr);
                                    Console.WriteLine("Name: {0}", valueDecr);
                                    Console.WriteLine("------------------------------\n");
                                }
                            }

                            Console.WriteLine("=======================================================================================================================\n\n");

                            break;
                        }

                        case 3:                         // Izlazak iz programa.
                        {
                            clp.Close();

                            Console.WriteLine("\nPress any key to exit...");
                            Console.ReadLine();

                            break;
                        }
                        }
                    }
                }
            }
            else
            {
                Console.WriteLine("Client authentication falied. No certificate provided. Client can not be started.\n");
                Console.WriteLine("Press ENTER key to exit...");
                Console.ReadLine();
            }
        }
Ejemplo n.º 15
0
        public static void Main(string[] args)
        {
            NetTcpBinding binding = new NetTcpBinding();

            binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Certificate;

            X509Certificate2 srvCert = CertManager.GetCertificateFromStorage(StoreName.TrustedPeople, StoreLocation.LocalMachine, "Server");
            EndpointAddress  address = new EndpointAddress(new Uri("net.tcp://localhost:9999/Service"), new X509CertificateEndpointIdentity(srvCert));

            using (ClientProxy proxy = new ClientProxy(binding, address))
            {
                string cltCertCN = Formatter.ParseName(WindowsIdentity.GetCurrent().Name);

                X509Certificate2 x = CertManager.GetCertificateFromStorage(StoreName.My, StoreLocation.LocalMachine, cltCertCN);

                string ou = Formatter.ParseOU(x.Subject);

                string cn = Formatter.ParseCN(x.Subject);

                int      num;
                string   themeName    = string.Empty;
                string   oldThemeName = string.Empty;
                string   newThemeName = string.Empty;
                string   title        = string.Empty;
                string   content      = string.Empty;
                string   timeStamp    = string.Empty;
                string   error        = string.Empty;
                string[] banned       = null;
                string   answer       = string.Empty;

                while (true)
                {
                    Console.WriteLine("************MENU**************");
                    Console.WriteLine("******************************");
                    Console.WriteLine($"Welcome {cn} from group {ou}\n");
                    Console.WriteLine("1.Ban publisher");
                    Console.WriteLine("2.Check for publisher spam");
                    Console.WriteLine("3.Add theme");
                    Console.WriteLine("4.Modify theme");
                    Console.WriteLine("5.Remove theme");
                    Console.WriteLine("6.Write theme(publisher)");
                    Console.WriteLine("7.Read theme(publisher)");
                    Console.WriteLine("8.Send notifications");
                    Console.WriteLine("9.Subscribe to theme");
                    Console.WriteLine("10.Unsubscribe from theme");
                    Console.WriteLine("11.Read themes(subscriber)");
                    Console.WriteLine("12.Read incoming notifications");
                    Console.WriteLine("13.Update subscriber file");
                    Console.WriteLine("14.Logout");

                    Console.WriteLine("\nEnter number: ");
                    num = Int32.Parse(Console.ReadLine());

                    switch (num)
                    {
                    case 1:
                        if (ou != "Admin")
                        {
                            Console.WriteLine("\nYou don't have rights to access this operation!");
                            Console.ReadLine();
                            Console.Clear();
                            break;
                        }

                        foreach (var item in banned)
                        {
jump:
                            Console.WriteLine($"\nDo you want to ban {item}?");
                            answer = Console.ReadLine();

                            if (answer == "yes")
                            {
                                error = proxy.AdminBan(ou, item);
                                Console.WriteLine(error);
                                Console.ReadLine();
                            }
                            else if (answer == "no")
                            {
                                Console.WriteLine($"\nPublisher {item} won't be banned!");
                                Console.ReadLine();
                            }
                            else
                            {
                                Console.WriteLine("\nYour option was invalid!");
                                Console.ReadLine();
                                goto jump;
                            }
                        }

                        error = string.Empty;

                        Console.Clear();
                        break;

                    case 2:
                        if (ou != "Admin")
                        {
                            Console.WriteLine("\nYou don't have rights to access this operation!");
                            Console.ReadLine();
                            Console.Clear();
                            break;
                        }

                        banned = proxy.CheckPublisherSpam(ou);

                        if (banned == null)
                        {
                            Console.WriteLine("\nThere are no people for banning!");
                        }
                        else
                        {
                            Console.WriteLine("\nThere are people for banning!");
                        }

                        Console.ReadLine();
                        Console.Clear();
                        break;

                    case 3:
                        if (ou != "Publisher")
                        {
                            Console.WriteLine("\nYou don't have rights to access this operation!");
                            Console.ReadLine();
                            Console.Clear();
                            break;
                        }

                        Console.WriteLine("\nInsert theme you want to create: ");
                        themeName = Console.ReadLine();

                        error = proxy.PublisherAddTheme(ou, cn, themeName);
                        Console.WriteLine(error);
                        error     = string.Empty;
                        themeName = string.Empty;

                        Console.ReadLine();
                        Console.Clear();
                        break;

                    case 4:
                        if (ou != "Publisher")
                        {
                            Console.WriteLine("\nYou don't have rights to access this operation!");
                            Console.ReadLine();
                            Console.Clear();
                            break;
                        }

                        Console.WriteLine("\nInsert theme you want to modify: ");
                        oldThemeName = Console.ReadLine();
                        Console.WriteLine("Insert new theme name: ");
                        newThemeName = Console.ReadLine();

                        error = proxy.PublisherModifyTheme(ou, cn, oldThemeName, newThemeName);
                        Console.WriteLine(error);
                        error = string.Empty;

                        Console.ReadLine();
                        Console.Clear();
                        break;

                    case 5:
                        if (ou != "Publisher")
                        {
                            Console.WriteLine("\nYou don't have rights to access this operation!");
                            Console.ReadLine();
                            Console.Clear();
                            break;
                        }

                        Console.WriteLine("\nInsert theme you want to remove: ");
                        themeName = Console.ReadLine();

                        error = proxy.PublisherRemoveTheme(ou, cn, themeName);
                        Console.WriteLine(error);
                        error     = string.Empty;
                        themeName = string.Empty;

                        Console.ReadLine();
                        Console.Clear();
                        break;

                    case 6:
                        if (ou != "Publisher")
                        {
                            Console.WriteLine("\nYou don't have rights to access this operation!");
                            Console.ReadLine();
                            Console.Clear();
                            break;
                        }

                        error = proxy.PublisherWriteTheme(ou, cn);
                        Console.WriteLine(error);
                        error = string.Empty;

                        Console.ReadLine();
                        Console.Clear();
                        break;

                    case 7:
                        if (ou != "Publisher")
                        {
                            Console.WriteLine("\nYou don't have rights to access this operation!");
                            Console.ReadLine();
                            Console.Clear();
                            break;
                        }

                        Console.WriteLine("\nAll themes:");

                        error = proxy.PublisherReadTheme(ou, cn);
                        Console.WriteLine(error);
                        error = string.Empty;

                        Console.ReadLine();
                        Console.Clear();
                        break;

                    case 8:
                        if (ou != "Publisher")
                        {
                            Console.WriteLine("You don't have rights to access this operation!");
                            Console.ReadLine();
                            Console.Clear();
                            break;
                        }

                        Console.WriteLine("\nInsert theme you want to send your notifications to: ");
                        themeName = Console.ReadLine();
                        Console.WriteLine("Insert title of notification: ");
                        title = Console.ReadLine();
                        Console.WriteLine("Insert content of notification: ");
                        content = Console.ReadLine();
                        Console.WriteLine("Insert time stamp of notification: ");
                        timeStamp = Console.ReadLine();


                        error = proxy.PublisherSendNotifications(ou, cn, themeName, title, content, timeStamp);
                        Console.WriteLine(error);
                        error     = string.Empty;
                        themeName = string.Empty;

                        Console.ReadLine();
                        Console.Clear();
                        break;

                    case 9:
                        if (ou != "Subscriber")
                        {
                            Console.WriteLine("You don't have rights to access this operation!");
                            Console.ReadLine();
                            Console.Clear();
                            break;
                        }

                        Console.WriteLine("\nInsert theme you want to subscribe to: ");
                        themeName = Console.ReadLine();

                        error = proxy.Subscribe(ou, cn, themeName);
                        Console.WriteLine(error);
                        error     = string.Empty;
                        themeName = string.Empty;

                        Console.ReadLine();
                        Console.Clear();
                        break;

                    case 10:
                        if (ou != "Subscriber")
                        {
                            Console.WriteLine("You don't have rights to access this operation!");
                            Console.ReadLine();
                            Console.Clear();
                            break;
                        }

                        Console.WriteLine("Insert theme you want to unsubscribe from: ");
                        themeName = Console.ReadLine();

                        error = proxy.Unsubscribe(ou, cn, themeName);
                        Console.WriteLine(error);
                        error     = string.Empty;
                        themeName = string.Empty;

                        Console.ReadLine();
                        Console.Clear();
                        break;

                    case 11:
                        if (ou != "Subscriber")
                        {
                            Console.WriteLine("You don't have rights to access this operation!");
                            Console.ReadLine();
                            Console.Clear();
                            break;
                        }

                        Console.WriteLine("\nThemes you can subscribe to: ");

                        error = proxy.SubscriberReadTheme(ou);
                        Console.WriteLine(error);
                        error = string.Empty;

                        Console.ReadLine();
                        Console.Clear();
                        break;

                    case 12:
                        if (ou != "Subscriber")
                        {
                            Console.WriteLine("You don't have rights to access this operation!");
                            Console.ReadLine();
                            Console.Clear();
                            break;
                        }

                        error = proxy.SubscriberReadNotifications(ou, cn);
                        Console.WriteLine(error);
                        error = string.Empty;

                        Console.ReadLine();
                        Console.Clear();
                        break;

                    case 13:
                        if (ou != "Subscriber")
                        {
                            Console.WriteLine("You don't have rights to access this operation!");
                            Console.ReadLine();
                            Console.Clear();
                            break;
                        }

                        error = proxy.SubscriberCheckUpdates(ou, cn);
                        Console.WriteLine(error);
                        error = string.Empty;

                        Console.ReadLine();
                        Console.Clear();
                        break;

                    case 14:
                        Environment.Exit(0);
                        break;

                    default:
                        Console.WriteLine("Your option was out of bounds!");
                        Console.ReadLine();
                        Console.Clear();
                        break;
                    }
                }
            }
        }
Ejemplo n.º 16
0
        static void Main(string[] args)
        {
            NetTcpBinding binding = new NetTcpBinding();
            string        address = "net.tcp://localhost:9999/SecurityService";

            binding.Security.Mode = SecurityMode.Transport;
            binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows;
            binding.Security.Transport.ProtectionLevel      = System.Net.Security.ProtectionLevel.EncryptAndSign;

            Console.WriteLine("User {0} ", WindowsIdentity.GetCurrent().Name);
            EndpointAddress endpointAdress = new EndpointAddress(new Uri(address));

            using (ClientProxy proxy = new ClientProxy(binding, endpointAdress))
            {
                string input;
                bool   done = false;
                while (!done)
                {
                    input = Meni();
                    Console.WriteLine(Environment.NewLine);
                    switch (input[0])
                    {
                    case '1':
                        double ret = proxy.CalculateElectricEnergy();
                        Console.WriteLine("Calculated : " + ret);
                        break;

                    case '2':
                        int oldId, newId;
                        Console.WriteLine("Old ID : ");

                        if (!int.TryParse(Console.ReadLine(), out oldId))
                        {
                            Console.WriteLine("Greska");
                            break;
                        }
                        Console.WriteLine(Environment.NewLine + "New ID : ");
                        if (!int.TryParse(Console.ReadLine(), out newId))
                        {
                            Console.WriteLine("Greska");
                            break;
                        }
                        proxy.ModifyValueOfId(oldId, newId);
                        break;

                    case '3':
                        int id, newElEnergy;
                        Console.WriteLine("ID : ");
                        if (!int.TryParse(Console.ReadLine(), out id))
                        {
                            Console.WriteLine("Greska");
                            break;
                        }
                        Console.WriteLine(Environment.NewLine + "ElectricEnergy :");
                        if (!int.TryParse(Console.ReadLine(), out newElEnergy))
                        {
                            Console.WriteLine("Greska");
                            break;
                        }
                        proxy.ModifyValueOfElectricEnergy(id, newElEnergy);
                        break;

                    case '4':

                        int    Id;
                        string name;
                        double elEnergy;
                        Console.WriteLine("ID : ");
                        if (!int.TryParse(Console.ReadLine(), out Id))
                        {
                            Console.WriteLine("Greska");
                            break;
                        }
                        Console.WriteLine("Name : ");
                        name = Console.ReadLine();

                        Console.WriteLine("Electrical energy : ");
                        if (!double.TryParse(Console.ReadLine(), out elEnergy))
                        {
                            Console.WriteLine("Greska");
                            break;
                        }

                        proxy.AddNewEntity(Id, name, elEnergy);

                        break;

                    case '5':
                        Console.WriteLine("ID : ");
                        if (!int.TryParse(Console.ReadLine(), out Id))
                        {
                            Console.WriteLine("Greska");
                            break;
                        }

                        proxy.DeleteEntity(Id);

                        break;

                    case '6':
                        proxy.DeleteWholeDatabase();
                        break;

                    case '7':
                        proxy.ArchiveDatabase();
                        break;

                    default:
                        done = true;
                        break;
                    }
                }
            }

            Console.ReadLine();
        }