public Form1() { InitializeComponent(); var coreConfig = new AVClient.Configuration { ApplicationId = appId, ApplicationKey = appId, }; AVClient.Initialize(coreConfig); AVClient.HttpLog(AppendLogs); var realtimeConfig = new AVRealtime.Configuration() { ApplicationId = appId, ApplicationKey = appkey, OfflineMessageStrategy = AVRealtime.OfflineMessageStrategy.UnreadAck, }; Websockets.Net.WebsocketConnection.Link(); AVRealtime.WebSocketLog(AppendLogs); realtime = new AVRealtime(realtimeConfig); lbx_messages.DisplayMember = "Content"; lbx_messages.ValueMember = "Id"; lbx_messages.DataSource = data; realtime.OnOfflineMessageReceived += Realtime_OnOfflineMessageReceived; }
public virtual void SetUp() { string appId = "cfpwdlo41ujzbozw8iazd8ascbpoirt2q01c4adsrlntpvxr"; string appkey = "lmar9d608v4qi8rvc53zqir106h0j6nnyms7brs9m082lnl7"; //string appId = "EB23wEzd6WPhGlwjMVgEPxg6-gzGzoHsz"; //string appkey = "6jEGd98CIOUyH6LQrotQSNVb"; Websockets.Net.WebsocketConnection.Link(); var coreConfig = new AVClient.Configuration { ApplicationId = appId, ApplicationKey = appId, }; AVClient.Initialize(coreConfig); AVClient.HttpLog(AppendLogs); var realtimeConfig = new AVRealtime.Configuration() { ApplicationId = appId, ApplicationKey = appkey, RealtimeServer = new Uri("wss://rtm51.leancloud.cn"), OfflineMessageStrategy = AVRealtime.OfflineMessageStrategy.Default }; AVRealtime.WebSocketLog(AppendLogs); realtime = new AVRealtime(realtimeConfig); }
private Task <AVCommand> PrepareCommand(AVCommand command) { AVCommand newCommand = new AVCommand(command); Task <AVCommand> installationIdTask = installationIdController.GetAsync().ContinueWith(t => { newCommand.Headers.Add(new KeyValuePair <string, string>("X-LC-Installation-Id", t.Result.ToString())); return(newCommand); }); // TODO (richardross): Inject configuration instead of using shared static here. AVClient.Configuration configuration = AVClient.CurrentConfiguration; newCommand.Headers.Add(new KeyValuePair <string, string>("X-LC-Id", configuration.ApplicationId)); newCommand.Headers.Add(new KeyValuePair <string, string>("X-LC-Client-Version", AVClient.VersionString)); if (configuration.AdditionalHTTPHeaders != null) { foreach (var header in configuration.AdditionalHTTPHeaders) { newCommand.Headers.Add(header); } } if (!string.IsNullOrEmpty(configuration.VersionInfo.BuildVersion)) { newCommand.Headers.Add(new KeyValuePair <string, string>("X-LC-App-Build-Version", configuration.VersionInfo.BuildVersion)); } if (!string.IsNullOrEmpty(configuration.VersionInfo.DisplayVersion)) { newCommand.Headers.Add(new KeyValuePair <string, string>("X-LC-App-Display-Version", configuration.VersionInfo.DisplayVersion)); } if (!string.IsNullOrEmpty(configuration.VersionInfo.OSVersion)) { newCommand.Headers.Add(new KeyValuePair <string, string>("X-LC-OS-Version", configuration.VersionInfo.OSVersion)); } // TODO (richardross): I hate the idea of having this super tightly coupled static variable in here. // Lets eventually get rid of it. if (!string.IsNullOrEmpty(AVClient.MasterKey)) { newCommand.Headers.Add(new KeyValuePair <string, string>("X-LC-Key", AVClient.MasterKey + ",master")); } else { newCommand.Headers.Add(new KeyValuePair <string, string>("X-LC-Key", configuration.ApplicationKey)); } // TODO (richardross): Inject this instead of using static here. if (AVUser.IsRevocableSessionEnabled) { newCommand.Headers.Add(new KeyValuePair <string, string>("X-LeanCloud-Revocable-Session", revocableSessionTokenTrueValue)); } return(installationIdTask); }
public AVCommand(string relativeUri, string method, string sessionToken = null, IList <KeyValuePair <string, string> > headers = null, Stream stream = null, string contentType = null) { var state = AVPlugins.Instance.AppRouterController.Get(); var urlTemplate = "https://{0}/{1}/{2}"; AVClient.Configuration configuration = AVClient.CurrentConfiguration; var apiVersion = "1.1"; if (relativeUri.StartsWith("push") || relativeUri.StartsWith("installations")) { Uri = new Uri(string.Format(urlTemplate, state.PushServer, apiVersion, relativeUri)); } else if (relativeUri.StartsWith("stats") || relativeUri.StartsWith("always_collect") || relativeUri.StartsWith("statistics")) { Uri = new Uri(string.Format(urlTemplate, state.StatsServer, apiVersion, relativeUri)); } else if (relativeUri.StartsWith("functions") || relativeUri.StartsWith("call")) { Uri = new Uri(string.Format(urlTemplate, state.EngineServer, apiVersion, relativeUri)); if (configuration.EngineServer != null) { Uri = new Uri(string.Format("{0}/{1}/{2}", configuration.EngineServer, apiVersion, relativeUri)); } } else { Uri = new Uri(string.Format(urlTemplate, state.ApiServer, apiVersion, relativeUri)); } Method = method; Data = stream; Headers = new List <KeyValuePair <string, string> >(headers ?? Enumerable.Empty <KeyValuePair <string, string> >()); string useProduction = AVClient.UseProduction ? "1" : "0"; Headers.Add(new KeyValuePair <string, string>("X-LC-Prod", useProduction)); if (!string.IsNullOrEmpty(sessionToken)) { Headers.Add(new KeyValuePair <string, string>("X-LC-Session", sessionToken)); } if (!string.IsNullOrEmpty(contentType)) { Headers.Add(new KeyValuePair <string, string>("Content-Type", contentType)); } }