/// <summary> /// 发布一条新微博 /// </summary> /// <param name="channelName"></param> /// <param name="channelUrl"></param> /// <param name="message"></param> protected override void SocialSharePublish(string channelName, string channelUrl, string message, SocialBase.SocialShareHandler callBack) { var social = SocialViewModel.Instance.DataInfos[SocialType.TENCENT]; OAuthConfigruation.AccessToken = new AccessToken(social.AcessToken); var share = new TService(); var arg = new ServiceArgument() { Content = message, Url = channelUrl }; try { share.AddVideo(arg, obj => { if (obj.Succeed) callBack(true, string.Empty); else callBack(false, obj.InnerException.Message); }); } catch (Exception ex) { callBack(false, ex.Message); } }
protected override void SocialSharePublish(string channelName, string channelUrl, string message, SocialBase.SocialShareHandler callBack) { var social = SocialViewModel.Instance.GetRecord(SocialType.TENCENT); OAuthConfigruation.AccessToken = new AccessToken(social.AcessToken); var share = new TService(); var arg = new ServiceArgument() { Content = message //Url = channelUrl }; try { share.Add(arg, obj => { if (obj.Succeed) { callBack(true, string.Empty); } else { callBack(false, obj.InnerException.Message); } }); } catch (Exception ex) { callBack(false, ex.Message); } }
/// <summary> /// Connect to the registry /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void connectToolStripMenuItem_Click(object sender, EventArgs e) { var form = new ConnectForm(); if (form.ShowDialog() == DialogResult.OK) { try { argGrid.Rows.Clear(); respGrid.Rows.Clear(); address = form.Address; port = form.Port; serviceTag = form.ServiceTag; teamName = form.TeamName; connection = new ServiceConnection(Program.Logger, teamName, IPAddress.Parse(address), port); var registerResponse = connection.Register(); teamId = registerResponse.TeamId; if (connection.IsRegistered()) { runToolStripMenuItem1.Enabled = true; queriedService = connection.QueryService(serviceTag).Service; var args = from a in queriedService.Args orderby a.Position select a; foreach (var arg in args) { argGrid.Rows.Add(new object[] { arg.Name, ServiceArgument.TypeToString(arg.DataType), arg.Mandatory, arg.Value }); } var resps = from r in queriedService.Returns orderby r.Position select r; foreach (var resp in resps) { respGrid.Rows.Add(new object[] { resp.Name, ServiceArgument.TypeToString(resp.DataType), resp.Value }); } toolStripStatusLabel.Text = String.Format("Service IP: {0}, Port: {1}, ServiceName: {2}, Description: {3}", queriedService.Ip.ToString(), queriedService.Port, queriedService.Name, queriedService.Description); } else { MessageBox.Show("Failure to register with registry"); } } catch (Exception ex) { MessageBox.Show("Failure to register with registry, because: " + ex.Message); } } }
protected async Task Get(ServiceArgument args, RestCallback <string> callBack) { StringBuilder sb = new StringBuilder(); foreach (var i in args.Dic) { sb.Append(i.Key); sb.Append("="); sb.Append(i.Value); sb.Append("&"); } await Get(string.Concat(args.Uri, sb.ToString().TrimEnd('&')), callBack); }
/// <summary> /// Register the service with the registry /// </summary> public void RegisterService() { var registerResponse = registryConnection.Register(); teamId = registerResponse.TeamId; try { var serviceDescriptor = new RemoteService(serviceIp, servicePort, serviceName, tagName, 2, "Tax calculator for Canada"); var provinceArg = new ServiceArgument(1, ProvinceCode, ServiceDataType.Tstring, true); serviceDescriptor.Args.Add(provinceArg); var subTotalArg = new ServiceArgument(2, SubTotal, ServiceDataType.Tdouble, true); serviceDescriptor.Args.Add(subTotalArg); serviceDescriptor.Returns.Add(PurchaseTotallerResponse.SubTotalReturn); serviceDescriptor.Returns.Add(PurchaseTotallerResponse.PstReturn); serviceDescriptor.Returns.Add(PurchaseTotallerResponse.HstReturn); serviceDescriptor.Returns.Add(PurchaseTotallerResponse.GstReturn); serviceDescriptor.Returns.Add(PurchaseTotallerResponse.TotalReturn); registryConnection.Publish(serviceDescriptor); } catch (FailureResponseException ex) { if (ex.ErrorCode == "-4" && ex.ErrorMessage.Contains("already published service")) { // Ignore... } else { throw; } } }
/// <summary> /// Execute the service /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void runToolStripMenuItem1_Click(object sender, EventArgs e) { try { // Re-register the client every time, incase it's kicked connection.Register(); var ip = queriedService.Ip; var port = queriedService.Port; try { queriedService = connection.QueryService(serviceTag).Service; } catch (Exception) { throw new Exception("Service is no longer registered"); } var serviceConnection = new ServiceConnection(Program.Logger, teamName, ip, port, false, connection.TeamId); var call = new RemoteServiceCall(queriedService.Name, teamName, (int)connection.TeamId); int i = 1; foreach (DataGridViewRow row in argGrid.Rows) { var argName = row.Cells[0].Value.ToString(); var argDataType = ServiceArgument.TypeFromString(row.Cells[1].Value.ToString()); var argMandatory = row.Cells[2].Value.ToString().Equals("true", StringComparison.CurrentCultureIgnoreCase); var argValue = row.Cells[3].Value.ToString(); // Are we mandatory or do we have a value? if (argMandatory || !String.IsNullOrWhiteSpace(argValue)) { if (String.IsNullOrWhiteSpace(argValue)) { throw new FormatException("Please enter a value for: " + argName); } try { switch (argDataType) { case ServiceDataType.Tint: int.Parse(argValue); break; case ServiceDataType.Tdouble: double.Parse(argValue); break; case ServiceDataType.Tfloat: float.Parse(argValue); break; case ServiceDataType.Tchar: if (argValue.Length > 1) { throw new FormatException("Char field must be 1 character"); } break; case ServiceDataType.Tshort: short.Parse(argValue); break; case ServiceDataType.Tlong: long.Parse(argValue); break; default: break; } } catch (Exception) { throw new FormatException("Please enter a proper value for: " + argName); } } var arg = new ServiceArgument(i++, argName, argDataType, argMandatory); arg.Value = argValue; call.Args.Add(arg); } i = 1; foreach (DataGridViewRow row in respGrid.Rows) { var respName = row.Cells[0].Value.ToString(); var respDataType = ServiceArgument.TypeFromString(row.Cells[1].Value.ToString()); var respValue = ""; var ret = new ServiceReturn(i++, respName, respDataType, respValue); call.Returns.Add(ret); } var executeResponse = serviceConnection.ExecuteService(call); foreach (var ret in executeResponse.Returned.Returns) { foreach (DataGridViewRow row in respGrid.Rows) { var respName = row.Cells[0].Value.ToString(); if (respName == ret.Name) { var respDataType = ServiceArgument.TypeFromString(row.Cells[1].Value.ToString()); row.Cells[2].Value = ret.Value; break; } } } } catch (Exception ex) { MessageBox.Show("Error executing service, because: " + ex.Message); } }