static void Main(string[] args) { Console.WriteLine("Starting calculator-demo app..."); var connection = new ConnectionBuilder().WithLogging(minimumLogLevel: LogLevel.Trace).Build(); connection.On <dynamic, double>("sum", numbers => { return(numbers.num1 + numbers.num2); }); connection.On <CalculatorRequest, double>("subtraction", numbers => { return(numbers.Num1 - numbers.Num2); }); connection.On <dynamic, double>("multiplication", numbers => { return(numbers.num1 * numbers.num2); }); connection.On <dynamic, double>("division", numbers => { if (numbers.num2 == 0) { Console.Error.WriteLine("Error: Division by 0"); throw new InvalidOperationException("Division by 0"); } //when using dynamic the real type of num1 and num2 will be JValue because ElectronCGI intrenally uses Newtonsoft.Json for serialisation: https://www.newtonsoft.com/json/help/html/T_Newtonsoft_Json_Linq_JValue.htm return(numbers.num1.ToObject <double>() / numbers.num2.ToObject <double>()); }); connection.Listen(); }
static void Main(string[] args) { var redditClient = new RedditClient(); var connection = new ConnectionBuilder().WithLogging(minimumLogLevel: LogLevel.Trace).Build(); var selectedSubreddit = ""; connection.On("select-subreddit", (string newSubreddit) => { selectedSubreddit = newSubreddit; }); CancellationTokenSource cancelationTokenSource = new CancellationTokenSource(); connection.OnAsync("start", async() => { Console.Error.WriteLine("started"); //this will show up in the node console await Task.Run(async() => { while (true) { if (cancelationTokenSource.Token.IsCancellationRequested) { return; } try { var posts = await redditClient.GetLatestPostsFromSubreddit(selectedSubreddit); connection.Send("show-posts", posts); await Task.Delay(1000); } catch (Exception ex) { Console.Error.WriteLine($"Failed to get posts for {selectedSubreddit} (maybe it does not exist?)"); //this will show up in the node console Console.Error.WriteLine(ex.Message); return; } } }, cancelationTokenSource.Token); }); connection.On("stop", () => { Console.Error.WriteLine("Stop"); if (cancelationTokenSource != null) { cancelationTokenSource.Cancel(); //this will cause the start request to complete } }); connection.Listen(); }
static void Main(string[] args) { // This is a TRIAL token. It will expire at 31/08/2020. PkiConfig.LoadLicense(Convert.FromBase64String("AxAAIIy8jc59Q0q95BZrL57K5hEAUEtJIFN1aXRlIFNhbXBsZXMIAAD0Ze31HdgICACAXwryrU7YCAAAAAAAAAQAfwAAAAABL2+ls7EW5LHD/tEetd49d0JpmU7pXEjhH0pU1ZSp5qjvKxL8c8PZz6ODTf68+lfQtXkKaRlQH6hu7VTSU3fvhCmZovDB5ruKqJPn+MQRDBbS8Wkr/meVo9LBS+3NFOky+EY43ebFoFxTbVZl2lCjb0DuskJiZGuHOBJ1v2XpGdKCmh1c1LmMvpc+OPegzNuMCXoEzSN9DdRtKnDzRxvOnvPglCX9+oV89LWsmVzonRp1a+tluqa8Ron9pFdHI9cWBElcXpmwXbKbmP0Sy5yYbYpE+rYsNgD5sV/FwF8uOxGWA0/mRWLZlO3OcGWoYo7qBBDmCUApAcRmZR3tXqhELQ==")); var connection = new ConnectionBuilder() .WithLogging() .Build(); // "List Certificates" operation. connection.On <string, List <CertificateModel> >("list-certs", _ => { var store = WindowsCertificateStore.LoadPersonalCurrentUser(); return(store.GetCertificatesWithKey().Select(c => new CertificateModel(c.Certificate)).ToList()); }); // "Sign a PDF" operation. connection.On <SignatureRequestModel, string>("sign-pdf", request => { var signer = new PadesSigner(); var store = WindowsCertificateStore.LoadPersonalCurrentUser(); var signingCert = store.GetCertificatesWithKey().First(c => c.Certificate.ThumbprintSHA256.SequenceEqual(request.CertThumb)); signer.SetSigningCertificate(signingCert); signer.SetPdfToSign(request.FileToSign); var trustArbitrator = new LinkedTrustArbitrator(TrustArbitrators.PkiBrazil, TrustArbitrators.Windows); // For development purposes, we also trust in Lacuna Software's test certificates. var lacunaRoot = Lacuna.Pki.PKCertificate.Decode(Convert.FromBase64String("MIIGGTCCBAGgAwIBAgIBATANBgkqhkiG9w0BAQ0FADBfMQswCQYDVQQGEwJCUjETMBEGA1UECgwKSUNQLUJyYXNpbDEdMBsGA1UECwwUTGFjdW5hIFNvZnR3YXJlIC0gTFMxHDAaBgNVBAMME0xhY3VuYSBSb290IFRlc3QgdjEwHhcNMTUwMTE2MTk1MjQ1WhcNMjUwMTE2MTk1MTU1WjBfMQswCQYDVQ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wiO2TnxlIPJqwqBMPc/c8sDAPBgNVHRMBAf8EBTADAQH/MA4GA1UdDwEB/wQEAwIBBjANBgkqhkiG9w0BAQ0FAAOCAgEAN/b8hNGhBrWiuE67A8kmom1iRUl4b8FAA8PUmEocbFv/BjLpp2EPoZ0C+I1xWT5ijr4qcujIMsjOCosmv0M6bzYvn+3TnbzoZ3tb0aYUiX4ZtjoaTYR1fXFhC7LJTkCN2phYdh4rvMlLXGcBI7zA5+Ispm5CwohcGT3QVWun2zbrXFCIigRrd3qxRbKLxIZYS0KW4X2tetRMpX6DPr3MiuT3VSO3WIRG+o5Rg09L9QNXYQ74l2+1augJJpjGYEWPKzHVKVJtf1fj87HN/3pZ5Hr2oqDvVUIUGFRj7BSel9BgcgVaWqmgTMSEvQWmjq0KJpeqWbYcXXw8lunuJoENEItv+Iykv3NsDfNXgS+8dXSzTiV1ZfCdfAjbalzcxGn522pcCceTyc/iiUT72I3+3BfRKaMGMURu8lbUMxd/38Xfut3Kv5sLFG0JclqD1rhI15W4hmvb5bvol+a/WAYT277jwdBO8BVSnJ2vvBUzH9KAw6pAJJBCGw/1dZkegLMFibXdEzjAW4z7wyx2c5+cmXzE/2SFV2cO3mJAtpaO99uwLvj3Y3quMBuIhDGD0ReDXNAniXXXVPfE96NUcDF2Dq2g8kj+EmxPy6PGZ15p1XZO1yiqsGEVreIXqgcU1tPUv8peNYb6jHTHuUyXGTzbsamGZFEDsLG7NRxg0eZWP1w=")); // COMMENT the line below before production release trustArbitrator.Add(new TrustedRoots(lacunaRoot)); signer.SetPolicy(PadesPoliciesForGeneration.GetPadesBasic(trustArbitrator)); signer.ComputeSignature(); byte[] signedPdf = signer.GetPadesSignature(); var tempLocation = Path.GetTempFileName(); File.WriteAllBytes(tempLocation, signedPdf); return(tempLocation); }); // Acknowledges that the connection is running. connection.On <string, string>("ping", argument => "pong"); // wait for incoming requests connection.Listen(); }
static void Main(string[] args) { var connection = new ConnectionBuilder() .WithLogging() .Build(); connection.On <string, string>("greeting", name => "Hello " + name); connection.Listen(); }
static void Main(string[] args) { var connection = new ConnectionBuilder() .WithLogging() .Build(); // <string, string> = <T, T> = <InputDataType, OutputDataType> connection.On <string, string>("greeting", x => x + " World ! (from Core)"); connection.Listen(); }
static void Main(string[] args) { var connection = new ConnectionBuilder() .WithLogging() .Build(); connection.On <string, string>("greeting", (val) => $"Hello {val}"); connection.Listen(); }
static void Main(string[] args) { Assembly myassembly = Assembly.LoadFrom("HelloWorld.dll"); var connection = new ConnectionBuilder() .WithLogging() .Build(); connection.On <string, string>("greeting", name => "The c# part sais hello: " + name); connection.Listen(); }
private static void Main(string[] args) { var connection = new ConnectionBuilder() .WithLogging() .Build(); // expects a request named "greeting" with a string argument and returns a string connection.On <string, string>("greeting", name => "Hello " + name); // wait for incoming requests connection.Listen(); }
static void Main(string[] args) { var connection = new ConnectionBuilder() .WithLogging() .Build(); connection.On <string, string>("ipc-ack", name => "TestEasy-API acknowledges: " + name); Task handler = new Task(() => { }); connection.OnAsync("ipc", async() => { await handler; }); connection.Listen(); }
static void Main(string[] args) { var connection = new ConnectionBuilder() .WithLogging() .Build(); connection.On <string, string>("greeting", (string name) => { return($"Hello, {name}!"); }); connection.Listen(); }
static void Main(string[] args) { NetMqReal nmqr = new NetMqReal(); Thread t = new Thread(NetMqReal.Read); t.Start(); var connection = new ConnectionBuilder().WithLogging().Build(); //NetMqReal.isFaceRes.TryDequeue(out face); System.Threading.Thread.Sleep(2000); connection.On <string, string>("cameraCheck", name => { if (NetMqReal.isFaceRes.TryDequeue(out string face)) { prevState = face; return(face); }
public static void Main(string[] args) { /// Electron IPC connection... var connection = new ConnectionBuilder() .WithLogging() .Build(); connection.On <string, string>("ipc-ack", name => "TestEasy-API acknowledges: " + name); Task handler = new Task(() => { /*Some ipc-related logic*/ }); connection.OnAsync("ipc", async() => { await handler; }); Task.Run(() => connection.Listen()); /// WebApi... CreateHostBuilder(args).Build().Run(); }
static void Main(string[] args) { Discord.Discord discord = new Discord.Discord(477175586805252107, (ulong)Discord.CreateFlags.Default); Connection connection = new ConnectionBuilder().WithLogging().Build(); VoiceManager mgr = discord.GetVoiceManager(); discord.VoiceManagerInstance.SetSelfMute(true); mgr.SetSelfMute(true); UserManager usermgr = discord.GetUserManager(); Console.WriteLine(usermgr.GetCurrentUser().Id); connection.On <bool, bool>("setmute", status => { VoiceManager mgr = discord.GetVoiceManager(); mgr.SetSelfMute(status); return(status); }); connection.Listen(); var timer1 = new Timer(_ => discord.RunCallbacks(), null, 0, 1000 / 60); }
static void Main(string[] args) { Log.Logger = new LoggerConfiguration() .MinimumLevel.Debug() .WriteTo.Console() .CreateLogger(); var connection = new ConnectionBuilder() .WithLogging() .Build(); // var result = NetworkSimulator.Instance.Predict(new PredictionParameters{ // Service = CallSession.Service.Data, // MobileTerminalId = Guid.Parse("9e89f07c-ac04-4e0e-b113-fe418996b5cc") // }); // result.Dump(); connection.On <dynamic, List <Guid> >("getusers", request => { return(NetworkSimulator.Instance.LoadUsers()); }); connection.On <dynamic, dynamic>("predict", request => { Service service = default(Service); switch ((string)request.service) { case "Voice": service = Service.Voice; break; case "Data": service = Service.Data; break; case "Video": service = Service.Video; break; } ; return(NetworkSimulator.Instance.Predict(new PredictionParameters { Service = service, Id = (string)request.mobileTerminalId })); }); connection.On <SimulationParameters, dynamic>("results", request => { HetNet.Instance.GenerateRats((int)request.Capacity.c1, (int)request.Capacity.c2, (int)request.Capacity.c3, (int)request.Capacity.c4); HetNet.Instance.GenerateMobileTerminals(20); NetworkSimulator.Instance.GenerateCalls(500); foreach (var log in HetNet.Instance.MobileTerminals.SelectMany(x => x.CallLogs)) { Utils.CsvUtils._Instance.Write <CallLogMap, CallLog>( log, $"{Environment.CurrentDirectory}/calllogs.csv"); //load history in memory HetNet.Instance.CallerHistory.Add(log); } NetworkSimulator.Instance.Events.Clear(); var list = request.Calls.Split(",").Select(x => int.Parse(x)); var results = new List <SimulationResults>(); foreach (var item in list) { NetworkSimulator.Instance.GenerateCalls(item); NetworkSimulator.Instance.SaveCallLogs = false; //Non Predictive Scheme NetworkSimulator.Instance.Run(false); var nonPredictiveSchemeResults = new { Calls = HetNet.Instance.CallsGenerated, NonPredictiveHandovers = HetNet.Instance.VerticalHandovers, NonPredictiveBlockedCalls = HetNet.Instance.BlockedCalls, TotalSessions = HetNet.Instance.TotalSessions, HetNet.Instance.DataCallsGenerated, HetNet.Instance.DataHandovers, HetNet.Instance.VideoCallsGenerated, HetNet.Instance.VideoHandovers, HetNet.Instance.VoiceCallsGenerated, HetNet.Instance.VoiceHandovers, }; //Predictive Scheme NetworkSimulator.Instance.Run(true); var predictiveSchemeResults = new { PredictiveHandovers = HetNet.Instance.VerticalHandovers, PredictiveBlockedCalls = HetNet.Instance.BlockedCalls, FailedPredictions = HetNet.Instance.FailedPredictions, SuccessfulPredictions = HetNet.Instance.SuccessfulPredictions, PercentageVoiceAvoided = (double)(nonPredictiveSchemeResults.VoiceHandovers - HetNet.Instance.VoiceHandovers) / nonPredictiveSchemeResults.VoiceHandovers, PercentageDataAvoided = (double)(nonPredictiveSchemeResults.DataHandovers - HetNet.Instance.DataHandovers) / nonPredictiveSchemeResults.DataHandovers, PercentageVideoAvoided = (double)(nonPredictiveSchemeResults.VideoHandovers - HetNet.Instance.VideoHandovers) / nonPredictiveSchemeResults.VideoHandovers, PercentageTotalAvoided = (double)(nonPredictiveSchemeResults.NonPredictiveHandovers - HetNet.Instance.VerticalHandovers) / nonPredictiveSchemeResults.NonPredictiveHandovers, }; var simulationResults = new SimulationResults { Calls = nonPredictiveSchemeResults.Calls, TotalSessions = nonPredictiveSchemeResults.TotalSessions, NonPredictiveHandovers = nonPredictiveSchemeResults.NonPredictiveHandovers, NonPredictiveBlockedCalls = nonPredictiveSchemeResults.NonPredictiveBlockedCalls, PredictiveHandovers = predictiveSchemeResults.PredictiveHandovers, PredictiveBlockedCalls = predictiveSchemeResults.PredictiveBlockedCalls, FailedPredictions = predictiveSchemeResults.FailedPredictions, SuccessfulPredictions = predictiveSchemeResults.SuccessfulPredictions, DataAvoided = Math.Round(predictiveSchemeResults.PercentageDataAvoided * 100, 2), VideoAvoided = Math.Round(predictiveSchemeResults.PercentageVideoAvoided * 100, 2), VoiceAvoided = Math.Round(predictiveSchemeResults.PercentageVoiceAvoided * 100, 2), TotalAvoided = Math.Round(predictiveSchemeResults.PercentageTotalAvoided * 100, 2), DataCalls = nonPredictiveSchemeResults.DataCallsGenerated, VoiceCalls = nonPredictiveSchemeResults.VoiceCallsGenerated, VideoCalls = nonPredictiveSchemeResults.VideoCallsGenerated, PredictiveVoiceHandovers = HetNet.Instance.VoiceHandovers, PredictiveVideoHandovers = HetNet.Instance.VideoHandovers, PredictiveDataHandovers = HetNet.Instance.DataHandovers, NonPredictiveVoiceHandovers = nonPredictiveSchemeResults.VoiceHandovers, NonPredictiveVideoHandovers = nonPredictiveSchemeResults.VideoHandovers, NonPredictiveDataHandovers = nonPredictiveSchemeResults.DataHandovers, }; // Utils.CsvUtils._Instance.Write<SimulationResultsMap, SimulationResults>( // simulationResults, $"{Environment.CurrentDirectory}/SimResults.csv" // ); results.Add(simulationResults); HetNet.Instance.Reset(); NetworkSimulator.Instance.Events.Clear(); } //Utils.CsvUtils._Instance.Clear($"{Environment.CurrentDirectory}/SimResults.csv"); //Utils.CsvUtils._Instance.Clear($"{Environment.CurrentDirectory}/calllogs.csv"); return(results); }); connection.Listen(); }
static void Main() { serializer = new RestSharp.Serialization.Json.JsonSerializer(); var connection = new ConnectionBuilder() .WithLogging() .Build(); // expects a request named "greeting" with a string argument and returns a string connection.On <string, string>("login", data => { /** * client_id * client_secret * username * password * path to file * login url * **/ string[] args = JsonConvert.DeserializeObject <string[]>(data); ////check number of arguments passed to applicaiton if (args.Length < 6) { ////Console.WriteLine("You dind't pass all necessary parameters"); throw new ArgumentException(Help()); } String Username = args[0]; String Password = args[1]; String ClientID = args[2]; String ClientSecret = args[3]; String LoginUrl = args[4]; csv = args[5]; //create necessary directories SetupDirs(); if (!File.Exists(csv)) { throw new FileNotFoundException("The file was not found!", csv); } Logger = new FileLogger("logs"); SFDC = new Salesforce.Salesforce(ClientID, ClientSecret, Username, Password, LoginUrl, Logger); SFDC.Login(); parser = new CSVThread(csv, Logger, SFDC); return($"Logged to salesforce instance: {SFDC.InstanceUrl}"); }); connection.On <string, string>("initialize", data => { /** * token * instance_url * file_path **/ string[] args = JsonConvert.DeserializeObject <string[]>(data); //check number of arguments passed to applicaiton if (args.Length < 3) { throw new ArgumentException("Caramba, not enough parameters"); } String Token = args[0]; String InstanceUrl = args[1]; String CSV = args[2]; if (!File.Exists(CSV)) { throw new FileNotFoundException("The file was not found!", CSV); } SetupDirs(); Logger = new FileLogger("logs"); SFDC = new Salesforce.Salesforce(Token, InstanceUrl, Logger); parser = new CSVThread(CSV, Logger, SFDC); return($"Logged to salesforce instance: {SFDC.InstanceUrl}"); }); connection.On <string>("getSFDCObjects", () => { List <Sobject> sobjects = SFDC.RetrieveObjects(); return(serializer.Serialize(sobjects)); }); connection.On <string>("getHeaderRow", () => { return(serializer.Serialize(parser.Header.Values.ToList())); }); connection.On <string, string>("getMetadata", fields => { string[] args = JsonConvert.DeserializeObject <string[]>(fields); foreach (string name in args) { SFDC.RetrieveMetadata(name); } Dictionary <String, List <string> > data = SFDC.getMetadata(); return(serializer.Serialize(data)); }); connection.On <string, string>("parse", mapping => { SFDC.SetMapping(mapping, parser.Header); parser.Parse(); return("{\"x\":" + Salesforce.Salesforce.BatchSize + "}"); }); connection.On <string>("getStatus", () => { bool ready = parser.IsReady(); Dictionary <string, string> response = new Dictionary <string, string>(); //Boolean x = false; //response.Add("isReady", x.ToString()); //response.Add("all", "100"); //response.Add("error", "10"); //response.Add("success", "90"); response.Add("isReady", ready.ToString()); response.Add("all", parser.Size.ToString()); response.Add("processed", parser.Processed.ToString()); return(serializer.Serialize(response)); }); connection.On <string>("saveLogs", () => { Logger.Save(); return("{}"); }); // wait for incoming requests connection.Listen(); }