public List <string> VerifyContentGroupData([NotNull] bool isUpdating = false) { var errorMessages = new List <string>(); GroupName = GroupName?.Trim(); if (!Helpers.IsProperString(GroupName)) { errorMessages.Add("Please enter the name of Todo Group."); } else if (GroupName?.Length > 50) { errorMessages.Add("Group Name is too long. Max 50 characters."); } Description = Description?.Trim(); if (!Helpers.IsProperString(Description)) { Description = null; } else if (Description?.Length > 150) { errorMessages.Add("Description is too long. Max 150 characters."); } if (errorMessages.Count == 0 && !isUpdating) { CreatedOn = DateTime.UtcNow; } return(errorMessages); }
public void Save(byte[] password) { Name = Name.Trim(); if (Name.Length == 0) { throw new ArgumentException("Nazwa komputera musi zawierać co najmniej 1 znak"); } if (Name.Length > 32) { throw new ArgumentException("Nazwa komputera musi być krótsza niż 32 znaki"); } GroupName = GroupName.Trim(); if (GroupName.Length == 0) { throw new ArgumentException("Nazwa grupy musi zawierać co najmniej 1 znak"); } if (GroupName.Length > 32) { throw new ArgumentException("Nazwa grupy musi być krótsza niż 32 znaki"); } if (password.Length < 5) { throw new ArgumentException("Hasło musi zawierać co najmniej 5 znaków"); } IPFilter = IPFilter.Trim(); if (IPFilter.Length == 0) // pominięcie tego pola spowoduje akcpetację wszystkich adresów IP { IPFilter = ".*"; } if (!RegexValidator.IsValidRegex(IPFilter)) { throw new ArgumentException("Akceptowane adresy IP muszą mieć postać wyrażenia regularnego"); } if (Servers == null || Servers.Count == 0) { throw new ArgumentException("Brak podanych serwerów"); } PasswordHash = CalculateSHA256(password, Encoding.UTF8.GetBytes(GroupName)); if (File.Exists(settingsFilePath)) { File.Delete(settingsFilePath); } XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.IndentChars = "\t"; using (XmlWriter writer = XmlWriter.Create("settings.xml", settings)) { writer.WriteStartDocument(); writer.WriteStartElement("Settings"); writer.WriteElementString("Name", Name); writer.WriteElementString("GroupName", GroupName); writer.WriteElementString("Password", PasswordHash); writer.WriteElementString("AllowedIPsRegex", IPFilter); writer.WriteElementString("Startup", Startup.ToString()); writer.WriteEndElement(); writer.WriteEndDocument(); } File.WriteAllLines(serversListFilePath, GetServerStrings(Servers)); }
private string GetDistinctString(bool ShowPathInfo) { LoadUpperRef(); string str = String.Format(@"{0}/{1}", (UpperRef != null && ShowPathInfo ? UpperRef.GetFullEntityPath("/") : ""), (GroupName != null ? GroupName.Trim() : "")); str = str.Trim(" /".ToCharArray()); return(str); }
private async void ExecuteCreateGroupCommand() { //checking for connectivity var network = Connectivity.NetworkAccess; if (network != NetworkAccess.Internet) { await MaterialDialog.Instance.SnackbarAsync(message : "Error: No internet access", actionButtonText : "OK", msDuration : 3000, configuration : App.snackBarConfiguration); return; } //checking for null if (string.IsNullOrEmpty(GroupName) || string.IsNullOrEmpty(Description)) { await MaterialDialog.Instance.SnackbarAsync(message : "Error: Fill the required fields", actionButtonText : "OK", msDuration : 3000, configuration : App.snackBarConfiguration); return; } IsBusy = true; if (a == "1") { groupPic = await remoteService.UploadFile(mediaFile.GetStream(), Path.GetFileName(mediaFile.Path)); } else { groupPic = "https://firebasestorage.googleapis.com/v0/b/naijaconnect-3b414.appspot.com/o/Naija%20Connect%20Images%2Fgroup_chat_picture.png?alt=media&token=547a5d56-3c2c-4811-849c-14a7f55132ed"; } var group = new Group() { Name = GroupName.Trim(), Description = Description.Trim(), Avatar = groupPic }; var createGroup = await remoteService.CreateGroup(group); if (!string.IsNullOrEmpty(createGroup)) { var final = new Group() { Name = GroupName.Trim(), Description = Description.Trim(), Avatar = groupPic, Id = createGroup }; var create = await remoteService.UpdateGroup(final); IsBusy = false; if (create) { var parameters = new NavigationParameters(); parameters.Add("groupName", final.Name); parameters.Add("groupId", final.Id); parameters.Add("groupAvatar", final.Avatar); await NavigationService.NavigateAsync("GroupChatPage", parameters); } else { await MaterialDialog.Instance.SnackbarAsync(message : "Error occured", actionButtonText : "OK", msDuration : 3000, configuration : App.snackBarConfiguration); return; } } else { IsBusy = false; await MaterialDialog.Instance.SnackbarAsync(message : "Error occured", actionButtonText : "OK", msDuration : 3000, configuration : App.snackBarConfiguration); return; } }
private void CreateGroup() { // 讨论组名不能为空 //if (string.IsNullOrWhiteSpace(GroupName)) //{ // GroupNameBorderBrush = new SolidColorBrush(Colors.Red); // //GroupNameBorderThickness = new Thickness(1, 1, 1, 1); // return; //} //else //{ // GroupNameBorderBrush = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#e0e0e0")); // //GroupNameBorderThickness = new Thickness(0); //} // 讨论组成员不能少于3 if (GroupMemberList == null || GroupMemberList.Count < 3) { MessageBoxWindow.Show("讨论组至少需要包括三个成员", GlobalVariable.WarnOrSuccess.Warn); return; } if (string.IsNullOrWhiteSpace(GroupName.Trim(' ')))//自定义群名为空 取默认值 { GroupName = GetNewGroupName(); } GroupName = GroupName.TrimStart(' '); #region 旧代码 CreateGroupInput input = new CreateGroupInput(); input.token = AntSdkService.AntSdkLoginOutput.token; input.version = GlobalVariable.Version; input.userId = AntSdkService.AntSdkLoginOutput.userId; input.groupName = GroupName; //获取讨论组成员头像 //List<string> picList = new List<string>(); //foreach (ContactInfoViewModel m in GroupMemberList) //{ // picList.Add(m.Photo); //} //input.groupPicture = ImageHandle.GetGroupPicture(picList); //input.groupPicture =; input.userIds = string.Join(",", GroupMemberList.Select(c => c.User.userId).ToArray()); //CreateGroupOutput output = new CreateGroupOutput(); var errCode = 0; var errMsg = string.Empty; //if (!(new HttpService()).CreateGroup(input, ref output, ref errMsg)) //{ // if (output.errorCode != "1004") // { // MessageBoxWindow.Show(errMsg,GlobalVariable.WarnOrSuccess.Warn); // } // return; //} //output.group.groupPicture = ImageHandle.GetGroupPicture(GroupMemberList.Select(c => c.Photo).ToList()); //ThreadPool.QueueUserWorkItem(m => //{ //}); #endregion AntSdkCreateGroupInput newGroupInput = new AntSdkCreateGroupInput(); newGroupInput.userId = AntSdkService.AntSdkLoginOutput.userId; newGroupInput.groupName = GroupName; newGroupInput.userIds = GroupMemberList.Select(c => c.User.userId).ToArray(); //newGroupInput.groupPicture = ImageHandle.GetGroupPicture(GroupMemberList.Select(c => c.Photo).ToList()); //TODO:AntSdk_Modify //DONE:AntSdk_Modify AntSdkCreateGroupOutput createGroupOutput = AntSdkService.CreateGroup(newGroupInput, ref errCode, ref errMsg); if (createGroupOutput == null) { if (!AntSdkService.AntSdkIsConnected) { errMsg = "网络已断开,请检查网络"; } if (!string.IsNullOrEmpty(errMsg)) { MessageBoxWindow.Show(errMsg, GlobalVariable.WarnOrSuccess.Warn); } return; } createGroupOutput.groupPicture = ImageHandle.GetGroupPicture(GroupMemberList.Select(c => c.Photo).ToList()); //异步更新讨论组头像,这里需要用前台线程,因此不能用线程池 string[] ThreadParams = new string[3]; ThreadParams[0] = createGroupOutput.groupId; ThreadParams[1] = createGroupOutput.groupPicture; ThreadParams[2] = string.IsNullOrEmpty(createGroupOutput.groupName) ? "" : createGroupOutput.groupName; Thread UpdateGroupPictureThread = new Thread(GroupPublicFunction.UpdateGroupPicture); UpdateGroupPictureThread.Start(ThreadParams); this.CreateGroupOutput = createGroupOutput; App.Current.Dispatcher.BeginInvoke((Action)(() => { this.close.Invoke(); })); }