public bool AddRecord(object data) { bool result = false; try { JObject jo = restConnection.Post("api/ClassRoomInfoMaint/CreatClassRoom", data); if (null != jo) { ClassRoom classroom = jo.Value <JObject>("data").ToObject <ClassRoom>(); SelectedItem.Id = classroom.Id; result = true; } } catch (Exception e) { RadWindow.Alert(new DialogParameters { OkButtonContent = "确定", Content = e.Message, Owner = App.Current.MainWindow, Header = "错误" }); } return(result); }
/// <summary> /// Register a new user in the system. At minimum the email address, the full name and the password is required at registration. /// If the system is configured not to require user activation after registration the function also logs in the user just registered. /// However if activation is required the <see cref="ActivationRequiredException" /> exeption will be thrown with the following message /// "Activation needed, please confirm your account by clicking the link you received by email" but the user will be registered. /// It meens that the user registration happened but the system cannot be used unless clicking the activation link. /// /// Send POST request to APIROOT/users/register /// </summary> /// <param name="register">Registration parameters</param> /// <exception cref="ActivationRequiredException">This exception indicates that the registration succeeded but activation is required before using the system</exception> /// <exception cref="WebException">This exception will be thrown in case of service side registration error. Please refer to the HTTP error code for more information</exception> public void Register(Register register) { var response = RestConnection.Post("users/register", JsonSerializer.Serialize(register)); var registrationResult = JsonSerializer.Deserialize <RegistrationResult>(response); if (registrationResult.NeedsActivation) { throw new ActivationRequiredException( "Activation needed, please confirm your account by clicking the link you received by email"); } _isLoggedIn = true; }
/// <summary> /// Send email about forgotten password to the user having the email address in the parameter /// /// Send POST request to APIROOT/users/sendForgotPasswordEmail /// </summary> /// <param name="email">Email address to send forgot password email for</param> public void SendForgotPasswordEmail(EmailWrapper email) { RestConnection.Post("users/sendForgotPasswordEmail", JsonSerializer.Serialize(email)); }
/// <summary> /// Resend activation email for the given email address /// /// Send POST request to APIROOT/users/resendActivationEmail /// </summary> /// <param name="email">Email address to send activation email for</param> public void ResendActivationEmail(EmailWrapper email) { RestConnection.Post("users/resendActivationEmail", JsonSerializer.Serialize(email)); }
/// <summary> /// Log in the current user. On successfull login all subsequent management operations will run in the context of the logged in user. /// /// Send POST request to APIROOT/users/login /// </summary> /// <param name="login">The user's email address and password</param> /// <exception cref="WebException">In case of any service side error an exception will be thrown. Please refer to the HTTP error code for more information</exception> public void Login(Login login) { RestConnection.Post("users/login", JsonSerializer.Serialize(login)); _isLoggedIn = true; }
/// <summary> /// Logs off the user. Any subsequent management operations will fail that require authentication. /// </summary> public void Logoff() { RestConnection.Post("users/logoff", ""); _isLoggedIn = false; }
/// <summary> /// Change password of the currently logged in /// You must specify the current and the new passwords /// /// Send POST request to APIROOT/users/changePassword /// </summary> /// <param name="changePassword">Change password parameters</param> public void ChangePassword(ChangePassword changePassword) { RestConnection.Post("users/changePassword", JsonSerializer.Serialize(changePassword)); }
/// <summary> /// Reset the password specifid by the resetPassword dto. It will contain the userid, the confirmation code and the new password /// The first two parameters are sent out by the sendForgotPasswordEmail operation /// /// Send POST request to APIROOT/users/resetPassword /// </summary> /// <param name="resetPassword">Parameters for resetting password</param> public void ResetPassword(ResetPassword resetPassword) { RestConnection.Post("users/resetPassword", JsonSerializer.Serialize(resetPassword)); }
/// <summary> /// Create a new device /// /// Send POST request to the APIROOT/devices Url /// </summary> /// <param name="device">New device instance</param> /// <returns>Unique id of the device</returns> /// <exception cref="WebException">This exception indicates some service level error. Please refer to the HTTP error code for more information</exception> public string Create(Device device) { var response = RestConnection.Post("devices", JsonSerializer.Serialize(device)); return(JsonSerializer.Deserialize <string>(response)); }
/// <summary> /// Create a new network /// /// Send POST request to the APIROOT/networks Url /// </summary> /// <param name="network">New network instance</param> /// <returns>Unique id of the network</returns> /// <exception cref="WebException">This exception indicates some service level error. Please refer to the HTTP error code for more information</exception> public string Create(Network network) { var response = RestConnection.Post("networks", JsonSerializer.Serialize(network)); return(JsonSerializer.Deserialize <string>(response)); }
/// <summary> /// Update the telemetry data sinks for the network. These telemetry data sinks can be overriden at child network level /// by the <see cref="NetworkManagementClient.UpdateIncomingTelemetryDataSinks"/> method. If there is no override then all the devices under the network will use the telemetry data /// sinks configured by this method. /// /// Send POST request to the APIROOT/networks/id/incomingTelmetryDataSinks Url /// </summary> /// <param name="id">Unique identifier of the network</param> /// <param name="telemetryDataSinkParameters">List of telemetry data sinks</param> /// <exception cref="WebException">This exception indicates some service level error. Please refer to the HTTP error code for more information</exception> public void UpdateIncomingTelemetryDataSinks(string id, IEnumerable <TelemetryDataSinkParameters> telemetryDataSinkParameters) { RestConnection.Post("networks/" + id + "/incomingTelemetryDataSinks", JsonSerializer.Serialize(telemetryDataSinkParameters, true)); }
//更新设备状态信息 private void QueryTerminalInfos(ICollection <ClassRoom> classrooms) { ICollection <ClassroomBuilding> classroomBuildings = new List <ClassroomBuilding>(); foreach (var classroom in classrooms) { classroomBuildings.Add(classroom.ClassroomBuilding); classroom.ClassroomBuilding = null; } //JsonSerializerSettings settings = new JsonSerializerSettings(); //settings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; //settings.MissingMemberHandling = MissingMemberHandling.Ignore; //string jClassrooms = JsonConvert.SerializeObject(classrooms, settings); //JArray j = JArray.Parse(jClassrooms); //object cls = j.ToObject<ICollection<ClassRoom>>(); JObject jo = restConnection.Post("api/TerminalInfo/QueryLastTerminalInfos", classrooms); foreach (var classroom in classrooms) { classroom.ClassroomBuilding = classroomBuildings.ElementAt(classrooms.ToList().IndexOf(classroom)); } if (jo.Value <bool>("success")) { JArray ja = jo.Value <JArray>("data"); if (null != ja) { Collection <TerminalInfo> terminalInfos = ja.ToObject <Collection <TerminalInfo> >(); foreach (var terminalInfo in terminalInfos) { ClassRoom classroom = classrooms.Where(p => p.TerminalId.Equals(terminalInfo.TerminalId)).FirstOrDefault(); if (null != classroom) { terminalInfo.Name = classroom.ClassroomBuilding.BuildingName + "_" + classroom.RoomNum; } } //删除未选择的教室 ICollection <TerminalInfo> removeItems = TerminalInfos.Where(p => !terminalInfos.Select(o => o.TerminalId).Contains(p.TerminalId)).ToList(); foreach (var item in removeItems) { TerminalInfos.Remove(item); } //更新原选择教室的信息 PropertyInfo[] properties = typeof(TerminalInfo).GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance); foreach (var item in TerminalInfos) { TerminalInfo terminalInfo = terminalInfos.Where(p => p.TerminalId == item.TerminalId).FirstOrDefault(); if (null != terminalInfo) { foreach (PropertyInfo property in properties) { property.SetValue(item, property.GetValue(terminalInfo, null), null); } } } //增加新选择的教室 ICollection <TerminalInfo> addItems = terminalInfos.Where(p => !TerminalInfos.Select(o => o.TerminalId).Contains(p.TerminalId)).ToList(); foreach (var item in addItems) { TerminalInfos.Add(item); } } } }
/// <summary> /// Create a new company /// /// Send POST request to the APIROOT/companies Url /// </summary> /// <param name="company">New company instance</param> /// <returns>Unique id of the company</returns> /// <exception cref="WebException">This exception indicates some service level error. Please refer to the HTTP error code for more information</exception> public string Create(Company company) { var response = RestConnection.Post("companies", JsonSerializer.Serialize(company)); return(JsonSerializer.Deserialize <string>(response)); }
/// <summary> /// Add user to the company to provide access to the company for a given user. /// Use the <see cref="UserManagementClient.FindUser"/> method to find the user by email address. /// /// Send POST request to the APIROOT/companies/adduser Url /// </summary> /// <param name="companyUser">Company-user pair</param> /// <exception cref="WebException">This exception indicates some service level error. Please refer to the HTTP error code for more information</exception> public void AddUser(CompanyUser companyUser) { RestConnection.Post("companies/adduser", JsonSerializer.Serialize(companyUser)); }