public static void Run(string identityFile, bool isServer) { if (isServer) { ZitiIdentity.InitOptions opts = new ZitiIdentity.InitOptions() { EventFlags = ZitiEventFlags.ZitiContextEvent | ZitiEventFlags.ZitiServiceEvent, IdentityFile = identityFile, ApplicationContext = server, }; opts.OnZitiContextEvent += Opts_OnZitiContextEvent; opts.OnZitiServiceEvent += Opts_OnZitiServiceEvent; ZitiIdentity zid = new ZitiIdentity(opts); zid.Run(); Console.WriteLine("=================LOOP IS COMPLETE================="); } else { ZitiIdentity.InitOptions opts = new ZitiIdentity.InitOptions() { EventFlags = ZitiEventFlags.ZitiContextEvent | ZitiEventFlags.ZitiServiceEvent, IdentityFile = identityFile, ApplicationContext = client, }; opts.OnZitiContextEvent += Opts_OnZitiContextEvent; opts.OnZitiServiceEvent += Opts_OnZitiServiceEvent; ZitiIdentity zid = new ZitiIdentity(opts); zid.Run(); Console.WriteLine("=================LOOP IS COMPLETE================="); } }
private async static Task RunAsync2(string identityFile, HostedContext context) { ZitiIdentity.InitOptions opts = new ZitiIdentity.InitOptions() { EventFlags = ZitiEventFlags.ZitiContextEvent | ZitiEventFlags.ZitiServiceEvent, IdentityFile = identityFile, ApplicationContext = context, }; opts.OnZitiContextEvent += Opts_OnZitiContextEvent; opts.OnZitiServiceEvent += Opts_OnZitiServiceEvent; ZitiIdentity zid = new ZitiIdentity(opts); zid.Loop = API.NewLoop(); await zid.RunAsync().ConfigureAwait(false); }
static MemoryStream ms = new MemoryStream(2 << 16); //a big bucket to hold bytes to display contiguously at the end of the program public static void Run(string identityFile) { ZitiIdentity.InitOptions opts = new ZitiIdentity.InitOptions() { EventFlags = ZitiEventFlags.ZitiContextEvent | ZitiEventFlags.ZitiServiceEvent, IdentityFile = identityFile, ApplicationContext = "weather-svc", ConfigurationTypes = new[] { "weather-config-type" }, }; opts.OnZitiContextEvent += Opts_OnZitiContextEvent; opts.OnZitiServiceEvent += Opts_OnZitiServiceEvent; ZitiIdentity zid = new ZitiIdentity(opts); zid.Run(); Console.WriteLine("=================LOOP IS COMPLETE================="); }
public static async Task Run(string identityFile) { Logging.SimpleConsoleLogging(LogLevel.Info); //uncomment this line to see the logs from the c-sdk //API.NativeLogger = API.DefaultNativeLogFunction; ZitiIdentity.InitOptions opts1 = new ZitiIdentity.InitOptions() { EventFlags = ZitiEventFlags.ZitiContextEvent | ZitiEventFlags.ZitiServiceEvent, IdentityFile = identityFile, ApplicationContext = "weather-svc", ConfigurationTypes = new[] { "weather-config-type" }, }; ZitiIdentity zid1 = new ZitiIdentity(opts1); zid1.InitializeAndRun(); //ziti is initialized - now wait for services/identity to be ready await zid1.WaitForServices(); byte[] wttrRequestAsBytes = Encoding.UTF8.GetBytes("GET / HTTP/1.0\r\n" + "Accept: *-/*\r\n" + "Connection: close\r\n" + "User-Agent: curl/7.59.0\r\n" + "Host: wttr.in\r\n" + "\r\n"); //makes the output pretty - and not jumbly Console.OutputEncoding = Encoding.UTF8; using (var zitiStream = new ZitiStream(zid1.NewConnection("weather-svc"))) { //write the request await zitiStream.WriteAsync(wttrRequestAsBytes, 0, wttrRequestAsBytes.Length); //pump the response to the console's standard out await zitiStream.PumpAsync(Console.OpenStandardOutput()); } zid1.Stop(); zid1.Shutdown(); }
static MemoryStream ms = new MemoryStream(2 << 16); //a big bucket to hold bytes to display contiguously at the end of the program public static void Run(string identityFile) { var dnsHandler = new DnsHandler(new CustomDnsResolver()); var client = new HttpClient(dnsHandler); var html = client.GetStringAsync("http://eth0mfa").Result; ZitiIdentity.InitOptions opts = new ZitiIdentity.InitOptions() { EventFlags = ZitiEventFlags.ZitiContextEvent | ZitiEventFlags.ZitiServiceEvent, IdentityFile = identityFile, ApplicationContext = "eth0.ziti", }; opts.OnZitiContextEvent += Opts_OnZitiContextEvent; opts.OnZitiServiceEvent += Opts_OnZitiServiceEvent; ZitiIdentity zid = new ZitiIdentity(opts); zid.Run(); Console.WriteLine("=================LOOP IS COMPLETE================="); }