//Diese Funktion muss gestartet werden, damit eine Verbindung zum Server aufgebaut werden kann. public void StartAmpelsteuerung() { try { _callback = new CallbackClient(_client); DuplexChannelFactory <IAmpelService> factory = new DuplexChannelFactory <IAmpelService>(_callback, new NetNamedPipeBinding(), new EndpointAddress("net.pipe://localhost/Ampelsteuerung")); trafficlight = factory.CreateChannel(); } catch (Exception ex) { ex.ToString(); } }
static void Main(string[] args) { int localdb = 0; CallbackClient callbackclient = new CallbackClient(); callbackclient.Proxy = null; WCFClient proxy = null; NetTcpBinding binding = new NetTcpBinding(); Console.WriteLine("Na koji localDB zelis da se konektujes[0, 1, 2, 3 ... x]:"); while (true) { localdb = Int32.Parse(Console.ReadLine()); string address = "net.tcp://localhost:" + (8888 + localdb).ToString() + "/localdb"; proxy = new WCFClient(callbackclient, binding, new EndpointAddress(new Uri(address))); try { proxy.testServerMessage("Hello from client to server."); } catch (Exception e) { Console.WriteLine("nesto je poslo po zlu probaj opet"); continue; } break; } callbackclient.Proxy = proxy; Database database = new Database(); int opt; while (true) { // Ispis menija i unos zeljene opcije.. opt = Meni(); switch (opt) { case 1: database.InterestRegions = Odaberiregione(); if (database.InterestRegions != null) { proxy.GetEntitiesForRegions(database.InterestRegions); } break; case 2: Region ch = OdaberiRegion(); if (ch != Region.Nazad) { proxy.GetAverageConsumptionForRegion(ch); } break; case 3: string grad = OdaberiGrad(); if (grad != null) { proxy.GetAverageConsumptionForCity(grad); } break; case 4: string package = OdaberiEntitet(); if (package != null) { string[] input = package.Split(','); proxy.UpdateConsumption(input[0], int.Parse(input[1]), float.Parse(input[2])); } break; case 5: LogEntity kreiranEntitet = DodajEntitet(); if (kreiranEntitet != null) { proxy.AddLogEntity(kreiranEntitet); } break; case 6: string identification = IzbrisiEntitet(); if (identification != null) { proxy.DeleteLogEntity(identification); } break; case 7: IzlistajEntitete(); break; case 8: goto labela; default: Console.WriteLine("Nepostojeća opcija je odabrana, molimo pokušajte ponovo."); break; } } labela: proxy.Close(); Console.ReadLine(); }