public StringBuilder WriteAllOverflowBlocks() { var builder = new StringBuilder(_overflowFile.MaxFileIndex + 3); builder.AppendLine($"Max overflow file block index: {_overflowFile.MaxFileIndex}"); builder.AppendLine($"Max records in one overflow block: {MaxRecordsInOverflow}"); builder.AppendLine("Free overflow blocks: " + _freeBlocksOverflow.ListToString(';')); builder.AppendLine(); _workingBlock1 = new Block <T>(MaxRecordsInOverflow); //just to clear it var validIndex = 0; foreach (var byteData in _overflowFile.BlocksSequence()) { _workingBlock1.FromByteArray(byteData); if (_workingBlock1.ValidCount > 0 && !_freeBlocksOverflow.Contains(validIndex)) { builder.AppendLine($"Current block index: {validIndex}, address: {validIndex * _workingBlock1.GetSize()}"); builder.AppendLine(_workingBlock1.ToString()); } else { builder.AppendLine($"Current block index: {validIndex}, address: {validIndex * _workingBlock1.GetSize()} IS NOT VALID!!"); } validIndex++; } return(builder); }
public void SaveConfData() { var builder = new StringBuilder(); builder.AppendLine(MaxRecords.ToString()); builder.AppendLine(_partiallyFullBlocks.ListToString(';')); builder.AppendLine(_freeBlocks.ListToString(';')); using (StreamWriter sw = new StreamWriter(_fileTreeData, false)) { sw.Write(builder.ToString()); } }
public static string TreePreOrderToString(this Tree <string> t) { var visits = new List <string>(); var s = new Stack <Tree <string> >(); var p = t; while (true) { if (p == null) { if (s.Count == 0) { break; } else { p = s.Pop(); p = p.Right; } } else { s.Push(p); visits.Add(p.Value); // Visit Then Left p = p.Left; } } return(visits.ListToString()); }
public void IMSIInfoList_to_string_test() { var imsiList = new List <IMSIInfo>(); imsiList.Add(new IMSIInfo() { Id = 1, Mobile = "18660127508", IMSI = IMSI_EXAMPLE }); imsiList.Add(new IMSIInfo() { Id = 2, Mobile = "18660127509", IMSI = "12145785422" }); imsiList.Add(new IMSIInfo() { Id = 3, Mobile = "18660127510", IMSI = "12145785423" }); imsiList.Add(new IMSIInfo() { Id = 4, Mobile = "18660127511", IMSI = "12145785424" }); imsiList.Add(new IMSIInfo() { Id = 5, Mobile = "18660127512", IMSI = "12145785425" }); var result = imsiList.ListToString(); Assert.Equal("IMSI:12145785421,Mobile:18660127508;IMSI:12145785422,Mobile:18660127509;IMSI:12145785423,Mobile:18660127510;IMSI:12145785424,Mobile:18660127511;IMSI:12145785425,Mobile:18660127512;", result); }
private void VectorEnter_OnClick(object sender, EventArgs e) { var maxLength = int.Parse(vectorLength.Text); if (maxLength != enterVectorTextBox.Text.Length) { MessageBox.Show($"Vector's length must be {maxLength} digits."); return; } _m = int.Parse(parameterMTextBox.Text); _r = int.Parse(parameterRTextBox.Text); _matrixGenerator = new MatrixGenerator(_m, _r); _encoder = new Encoder(_m, _r); var matrix = _matrixGenerator.GenerateMatrix(); var vectorString = enterVectorTextBox.Text; var vector = vectorString.ToCharArray().Select(x => int.Parse(x.ToString())).ToList(); _encodedVector = _encoder.EncodeVector(vector, matrix); encodedVectorTextBox.Text = _encodedVector.ListToString(); encodedVectorLabel.Visible = true; encodedVectorTextBox.Visible = true; sendVectorButton.Visible = true; probabilityLabel.Visible = true; probabilityTextBox.Visible = true; }
public static ResponseInfo Notify(string instId) { if (!IsShow(instId)) { return(new ResponseInfo() { IsSuccess = false, Des = "只有发起人才能催办" }); } try { List <string> users = WF_Process.ReSendEmailAndGetToDoUsers(instId); OperationLog.Log(new IdentityUser().GetEmployee().Name, string.Format("催办:实例ID:{0},用户:{1}", instId, users.ListToString()), 1); return(new ResponseInfo() { IsSuccess = true, Des = "催办成功" }); } catch { return(new ResponseInfo() { IsSuccess = false, Des = "催办失败" }); } }
public void Run() { var list = new List <string> { "Hej", "Hopp", "Hello" }; Console.WriteLine(list.ListToString()); }
/// <summary> /// 发送短信同步 /// </summary> /// <param name="mobile"></param> /// <param name="content"></param> /// <returns></returns> public static string SendSMS(List <string> mobile, string content) { SMSModel m = new SMSModel { mobile = mobile.ListToString(), sendContents = content }; return(SendInfo_t(m)); }
/// <summary> /// 将XElement集合转换成指定符号分隔的字符串 /// </summary> /// <param name="els">元素列表</param> /// <param name="opr">指定分隔符</param> /// <returns></returns> public static string ElToString(this IList <XElement> els, string opr) { var list = new List <string>(); foreach (var el in els) { list.Add(el.Value); } return(list.ListToString(opr)); }
/// <summary> /// 发送短信异步 群发 /// </summary> /// <param name="mobile"></param> /// <param name="content"></param> /// <returns></returns> public static string SendSMS_ASYN(List <string> mobile, string content) { SMSModel m = new SMSModel { mobile = mobile.ListToString(), sendContents = content }; ThreadPool.QueueUserWorkItem(new WaitCallback(SendInfo), m); return("ok"); }
/// <summary> /// 发送短信异步 群发 /// </summary> /// <param name="mobile"></param> /// <param name="content"></param> /// <returns></returns> public static string SendSMS_ASYN(List<string> mobile, string content) { SMSModel m = new SMSModel { mobile = mobile.ListToString(), sendContents = content }; ThreadPool.QueueUserWorkItem(new WaitCallback(SendInfo), m); return "ok"; }
//[Authorize(Roles = "Supervisor, Repair Person")] public IActionResult UploadFiles(List <IFormFile> files) { if (files is null) { return(Ok(null)); } List <string> listURI = UploadFileToCloudinary.UploadListImage(files); string result = listURI.ListToString(); return(Ok(result)); }
private void btnProcess_Click(object sender, EventArgs e) { try { this.Cursor = Cursors.WaitCursor; this.grdResults.Rows.Clear(); this.btnExport.Enabled = false; List <string> errList = this.ValidateForm(); if (errList.Count != 0) { MessageBox.Show("Please correct the following errors:" + Environment.NewLine + Environment.NewLine + errList.ListToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { CashTransactionImportResult res = this.LoadTransactionData(this.tbInput.Text); //Add successful transactions to the grid. foreach (CashTransactionDTO t in res.ValidTransactions) { DataGridViewRow row = (DataGridViewRow)this.grdResults.RowTemplate.Clone(); row.CreateCells(this.grdResults, new object[] { t.Owed, t.Paid, t.Change, t.Change_Formatted_Verbose }); row.Tag = t; this.grdResults.Rows.Add(row); } if (res.ErrorMessages.Count != 0) { MessageBox.Show("Process complete with errors:" + Environment.NewLine + Environment.NewLine + res.ErrorMessages.ListToString(), "Status", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { MessageBox.Show("Process complete with no errors.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Information); } if (res.ValidTransactions.Count != 0) { this.btnExport.Enabled = true; } } } catch (Exception ex) { //This would be logged in a real scenario. MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { this.Cursor = Cursors.Default; } }
public static string DecryptTextFromImage(string path, int length) { var img = new Bitmap(path); var pixels = DEShelper.GetPixels(img).ToArray(); var binOutput = new List <int>(); for (int i = 0; i < 8 * length; i++) { binOutput.Add(GetLastBit(pixels[i].R)); } return(DEShelper.BinaryToText(binOutput.ListToString())); }
static void Main(string[] args) { var list = new List <int>(); list.AddRange(Enumerable.Range(10, 100));//[10,100) var any = list.Skip(10).Take(10).OrderBy(x => x).ToList(); string result = list.ListToString(); Console.WriteLine(result); Console.WriteLine(list.ToString()); }
/// <summary> /// получить перечень не установленного софта из основной коллекции /// </summary> private static string GetNotInstalledSoftware() { Utils.CheckSofrware(MainData.Programs, Utils.GetProgramNames(MainData.Programs)); var temList = new List <string>(); foreach (var prog in MainData.Programs) { if (!prog.Installed) { temList.Add(prog.TitleName); } } return(temList.ListToString()); }
/// <summary> /// 获取不重复的,隔开的字符串 /// </summary> /// <param name="str"></param> /// <returns></returns> public static string GetNoRepeatString(this string str) { IList <int> lst = new List <int>(); string[] arr = str.Split(','); foreach (string s in arr) { if (!lst.Contains(s.ToInt())) { lst.Add(s.ToInt()); } } return(lst.ListToString()); }
static void Main(string[] args) { DES des = new DES(); StreamReader textFromStream = new StreamReader(@"C:\Users\Sebastian\Desktop\text.txt"); StreamReader keyFromStream = new StreamReader(@"C:\Users\Sebastian\Desktop\key.txt"); List <int> text = textFromStream.ReadLine().ToIntList().ToList(); List <int> key = keyFromStream.ReadLine().ToIntList().ToList(); Console.WriteLine($"Text (64-bit): {text.ListToString()}"); Console.WriteLine($"Key (64-bit): {key.ListToString()}"); var encrypted = des.Encrypt(text, key); Console.WriteLine($"Coded: {encrypted.ListToString()}"); Console.WriteLine($"Encoded: {des.Decrypt(encrypted, key).ListToString()}"); Console.ReadLine(); }
/// <summary> /// The nested loop strategy below is really fast /// </summary> public void Solve() { var t = new List<int>(); for (int a = 1; a < 1000; a++) { for (int b = a + 1; b < 1000; b++) { for (int c = b + 1; c < 1000; c++) { if ((a + b + c == 1000) && (a.Sqr() + b.Sqr() == c.Sqr())) { t.AddRange(new int[] { a, b, c }); break; } } } } Util.WL("The pythagorean triple whose sum equals 1000 is: {0}\nThe product of this triple is: {1}" .FormatWith(t.ListToString(), t.Product())); //LinqStrategy(); }
public static string TreePostOrderToString(this Tree <string> t) { var visits = new List <string>(); var s = new Stack <Tree <string> >(); var p = t; var priorp = p; while (true) { if (p == null) { if (s.Count == 0) { break; } else { p = s.Pop(); // Visit if right visited if (p.Right == null || p.Right == priorp) { visits.Add(p.Value); priorp = p; p = null; } else { s.Push(p); p = p.Right; } } } else { s.Push(p); p = p.Left; } } return(visits.ListToString()); }
public static void GenerateStreamAssetsFileMd5Ver() { List <string> ret = FileUtils.GetAllFileFullPathsInStreamingAssets(Application.dataPath + "/StreamingAssets"); Debug.Log(ret.ListToString()); FileMd5DataDictionary dic = new FileMd5DataDictionary(); int i = 1; foreach (var file in ret) { if (!file.Contains(".meta") && !file.Contains("FilesMd5")) { FileMd5Data data = new FileMd5Data(); data.Id = i; int spliteIndex = file.IndexOf("StreamingAssets") + "StreamingAssets".Length + 1; string subFileName = file.Substring(spliteIndex).Replace("\\", "/"); data.FullPath = subFileName; spliteIndex = subFileName.LastIndexOf('.'); subFileName = subFileName.Substring(0, spliteIndex); spliteIndex = subFileName.LastIndexOf('/'); if (spliteIndex >= 0) { subFileName = subFileName.Substring(spliteIndex + 1); } data.FileName = subFileName; if (data.FullPath.Contains(".dat")) { data.FileName += ".dat"; } data.Md5Code = FileUtils.GetMd5_Path(file); dic.AddData(data); i++; } } dic.UpdateMd5File(Application.dataPath + "/StreamingAssets/FilesMd5.csv"); }
public void Solve() { var nums = GetNums(); var greatest = 0; List<int> glist = new List<int>(); var i = 0; while (i + 5 <= nums.Count()) { var x = nums.Skip(i).Take(5).Aggregate((n, m) => n * m); if (greatest < x) { greatest = x; glist = nums.Skip(i).Take(5).ToList(); } i++; } Util.WL("The five consecutive digits {0} yield the greatest product {1}" .FormatWith(glist.ListToString(), greatest)); //LinqStrategy(); }
/// <summary> /// получение списка нестандартных пользователей /// в формате [user1] [user2]... /// </summary> public static string GetIncorrectUsers() { var incorrectUsers = new List <string>(); foreach (var user in GetUserNamesList()) { switch (user) { case "user": break; case "Центрофинанс": break; case "DefaultAccount": break; case "WDAGUtilityAccount": break; case "defaultuser0": break; case "Администратор": break; case "Гость": break; default: incorrectUsers.Add(user); break; } } return(incorrectUsers.ListToString()); }
static void Main(string[] args) { string s = "Hello"; s.Print(); List <int> ints = new List <int> { 12, 213, 21, 312, 3 }; var str = ints.ListToString(); Console.WriteLine(str); Util.ListToString2(ints); var even = ints.Where(x => x % 2 == 0).OrderByDescending(x => x).ToList(); Console.WriteLine(even.ListToString()); List <Product> products = new List <Product>(); var names = new string[] { "Яблоко", "Груша", "Апельсин", "Морковь" }; Random rand = new Random(1); for (int i = 0; i < 100; i++) { products.Add(new Product { Count = rand.Next(1, 50), Description = "Подробнее о продукте", Name = names[rand.Next(names.Length)], Price = rand.Next(1, 5000) }); } foreach (var item in products.OrderBy(x => x.Name).ThenBy(x => x.Count)) { Console.WriteLine(item); } var p1 = products.Where(x => x.Price > 100 && x.Price < 1000); Console.WriteLine("-------------------"); foreach (var item in p1) { Console.WriteLine(item); } var p2 = products .Where(x => x.Price > 100 && x.Price < 1000) .Select(x => new ProductView { Price = x.Price, Name = $"{x.Name}({x.Count})" }); Console.WriteLine("-------------------"); foreach (var item in p2) { Console.WriteLine(item); } Product p = products.LastOrDefault(x => x.Count == 5); Console.WriteLine("p " + p); double avg = products.Where(x => x.Price > 100 && x.Price < 1000).Average(x => x.Price); double sum = products.Where(x => x.Price > 100 && x.Price < 1000).Sum(x => x.Count); double sumTotal = products.Where(x => x.Price > 100 && x.Price < 1000).Sum(x => x.Count * x.Price); Console.WriteLine("avg " + avg); Console.WriteLine("sum " + sum); Console.WriteLine("sum " + sumTotal); var page1 = products.Take(10); var page2 = products.Skip(10).Take(10); var page3 = products.Skip(20).Take(10); int countP = 20; int numPage = 0; var pageN = products.Skip(countP * numPage).Take(countP); var groupProd = products .GroupBy(x => x.Name) .Select(x => new ProductView { Name = x.Key, Price = x.Sum(y => y.Price * y.Count) }) .OrderByDescending(x => x.Price); Console.WriteLine("-------------------"); foreach (var item in groupProd) { Console.WriteLine(item); } var prod5 = from pr in products where pr.Price > 100 && pr.Price < 1000 orderby pr.Name, pr.Price select new ProductView { Name = pr.Name, Price = pr.Price }; Console.WriteLine("-------------------"); foreach (var item in prod5) { Console.WriteLine(item); } XDocument document = XDocument.Load("prod.xml"); var prod6 = from pr in document .Element("products") .Elements("product") orderby pr.Element("name").Value descending select new Product { Name = pr.Element("name").Value, Description = pr.Element("description").Value, Price = double.Parse(pr.Element("price").Value), Count = int.Parse(pr.Element("count").Value), }; Console.WriteLine("------------"); foreach (var item in prod6) { Console.WriteLine(item); } //document // .Element("products") // .Elements("product").Where(x=>true) // .OrderBy().Select() products .Where(x => x.Count > 10) .ToList() .ForEach(x => Console.WriteLine(x)); }
public void Test_ShowTaskListChecker() { VeerDebug.Log(" TaskListChecker : " + TaskListChecker.ListToString()); VeerDebug.Log(" TaskCountChecker : " + TaskCountChecker.ToString()); }
static void Main(string[] args) { ECB ecb = new ECB(); CBC cbc = new CBC(); List <string> lString = new List <string>(); string line; var textPath = @"C:\Users\Sebastian\Desktop\text2.txt"; var keyPath = @"C:\Users\Sebastian\Desktop\key1.txt"; var vectorPath = @"C:\Users\Sebastian\Desktop\vector.txt"; StreamReader textFromStream = new StreamReader(textPath); StreamReader keyFromStream = new StreamReader(keyPath); StreamReader vectorFromStream = new StreamReader(vectorPath); while ((line = textFromStream.ReadLine()) != null) { lString.Add(line); } List <IEnumerable <int> > textList = lString.ToIntList().ToList(); List <int> key = keyFromStream.ReadToEnd().ToIntList().ToList(); List <int> vector = vectorFromStream.ReadToEnd().ToIntList().ToList(); Console.WriteLine("----------------------ECB----------------------"); Console.WriteLine($"Key (64-bit): {key.ListToString()}"); Console.WriteLine($"Input text (64-bit): "); foreach (var item in textList) { Console.WriteLine(item.ListToString()); } Console.WriteLine(); var encryptedECB = ecb.Encrypt(textList, key); Console.WriteLine($"Coded: "); foreach (var item in encryptedECB) { Console.WriteLine(item.ListToString()); } Console.WriteLine(); var decryptedECB = ecb.Decrypt(encryptedECB, key); Console.WriteLine($"Encoded: "); foreach (var item in decryptedECB) { Console.WriteLine(item.ListToString()); } Console.WriteLine(); Console.WriteLine("----------------------CBC----------------------"); Console.WriteLine($"Key (64-bit): {key.ListToString()}"); Console.WriteLine($"Vector (64-bit): {vector.ListToString()}"); Console.WriteLine($"Input text (64-bit): "); foreach (var item in textList) { Console.WriteLine(item.ListToString()); } Console.WriteLine(); var encryptedCBC = cbc.Encrypt(textList, key, vector); Console.WriteLine($"Coded: "); foreach (var item in encryptedCBC) { Console.WriteLine(item.ListToString()); } Console.WriteLine(); var decryptedCBC = cbc.Decrypt(encryptedCBC, key, vector); Console.WriteLine($"Encoded: "); foreach (var item in decryptedCBC) { Console.WriteLine(item.ListToString()); } Console.ReadLine(); }
/// <summary> /// GMT邮件处理 /// </summary> /// <param name="obj"></param> /// <returns></returns> private async Task <string> OnHandleServerMail(JObject obj) { if (int.TryParse(obj["type"].ToString(), out int userType)) { var title = obj["mail"]["title"].ToString(); var content = obj["mail"]["content"].ToString(); JToken token = obj["mail"]["item"]; var itemList = new List <TLProtocol.Data.ItemSnapData>(); if (token != null) { var item_list = JsonConvert.DeserializeObject <dynamic>(obj["mail"]["item"].ToString()); foreach (var item in item_list) { var id = item.id; var count = item.num; var itemData = new TLProtocol.Data.ItemSnapData { TemplateID = id, Count = count }; itemList.Add(itemData); } } if (userType == (int)UserType.OnlineUser) { return(ResponseResult(true)); } else if (userType == (int)UserType.AllUser) { var groups = obj["group"].ToObject <string[]>(); foreach (var group in groups) { TLGlobalMailData mail = new TLGlobalMailData { title = title, content = content, groupId = group, create_time = System.DateTime.UtcNow, uuid = System.Guid.NewGuid().ToString(), mail_type = TLMailData.TLMailType.Type_GM }; if (itemList.Count > 0) { mail.attachments = itemList; } await new GlobalMailHandler(this).PostGlobalMailAsync(mail); } return(ResponseResult(true)); } else if (userType == (int)UserType.SpecificUser) { var userList = obj["role_list"].ToString().Split(','); var successUsers = new List <string>(); var wrongUsers = new List <string>(); var exceptionUsers = new List <string>(); var uuid_list = await GetManyUUID(userList); var verifiedUsers = await RPGServerPersistenceManager.Instance.GetRoleNameByUUIDAsync(uuid_list, this); for (int i = 0; i < verifiedUsers.Length; i++) { if (verifiedUsers[i].ToString() != null) { var notify = new TLSendGMMailNotify { roleId = uuid_list[i], title = title, content = content }; if (itemList.Count > 0) { notify.attachment = itemList; } try { var cmd = new TLCmdPublisher(this.Provider, uuid_list[i]); await cmd.PostCmdEvtAsync(notify); successUsers.Add(userList[i]); } catch (Exception e) { e.FullStackTrace(); exceptionUsers.Add(userList[i]); } } else { wrongUsers.Add(userList[i]); } } if (successUsers.Count == userList.Length) { return(ResponseResult(true)); } else { var reason = new StringBuilder(); if (successUsers.Count > 0) { reason.AppendFormat("成功用户({0}) : {1}", successUsers.Count, successUsers.ListToString(",")); } if (wrongUsers.Count > 0) { reason.AppendFormat("\n无效用户({0}) : {1}", wrongUsers.Count, wrongUsers.ListToString(",")); } if (exceptionUsers.Count > 0) { reason.AppendFormat("\n失败用户({0}) : {1}", exceptionUsers.Count, exceptionUsers.ListToString(",")); } return(ResponseResult(false, reason.ToString())); } } return(ResponseResult(true)); } return(ResponseResult(false)); }
public static Tuple <bool, string, List <Model.Model.LC_Line_Other> > GetLineList(int LID, string uid = "") { if (LID > 0 | uid.StrIsNotNull()) { if (uid.StrIsNotNull()) { sql = makesql.MakeSelectSql(typeof(Model.Model.LC_Line), "uid=@uid", new System.Data.SqlClient.SqlParameter[] { new System.Data.SqlClient.SqlParameter("@uid", uid) }); } else { sql = makesql.MakeSelectSql(typeof(Model.Model.LC_Line), "id=@id", new System.Data.SqlClient.SqlParameter[] { new System.Data.SqlClient.SqlParameter("@id", LID) }); } } else { sql = makesql.MakeSelectSql(typeof(Model.Model.LC_Line)); } ids = db.Read(sql); //获取线路列表 if (!ids.flag) { return(new Tuple <bool, string, List <Model.Model.LC_Line_Other> >(false, ids.errormsg, null)); } if (!ids.ReadIsOk()) { return(new Tuple <bool, string, List <Model.Model.LC_Line_Other> >(true, "没有任何数据!", new List <Model.Model.LC_Line_Other>())); } //解析表结构 var lcl_list = ids.GetVOList <Model.Model.LC_Line_Other>(); List <Model.Model.LC_Region> lcr_list = new List <Model.Model.LC_Region>(); #region 获取地址列表 //我把所有的地址ID放在一起 List <int> addresslist = new List <int>(); addresslist.AddRange(lcl_list.Select(x => x.Start.ConvertData <int>())); addresslist.AddRange(lcl_list.Select(x => x.End.ConvertData <int>())); //把这些ID获取出来地址数据 sql = makesql.MakeSelectSql(typeof(Model.Model.LC_Region), "ID in (" + addresslist.ListToString() + ")"); ids = db.Read(sql); if (!ids.flag) { return(new Tuple <bool, string, List <Model.Model.LC_Line_Other> >(false, ids.errormsg, null)); } if (ids.ReadIsOk()) { lcr_list = ids.GetVOList <Model.Model.LC_Region>(); } #endregion return(new Tuple <bool, string, List <Model.Model.LC_Line_Other> >(true, string.Empty, lcl_list.Select((x) => { //获取地区名字 x.StartCityName = GetAllAddressToString(x.Start.ConvertData <int>()); x.EndCityName = GetAllAddressToString(x.End.ConvertData <int>()); return x; }).ToList())); }
/// <summary> /// 发送短信同步 /// </summary> /// <param name="mobile"></param> /// <param name="content"></param> /// <returns></returns> public static string SendSMS(List<string> mobile, string content) { SMSModel m = new SMSModel { mobile = mobile.ListToString(), sendContents = content }; return SendInfo_t(m); }
public void OnGUI() { GUI.Label(new Rect(boxWidth + 50, 0, 500, 500), "Dragging String = " + draggingString + "\n strings.Count " + strings.Count + "\n" + strings.ListToString <String>()); accumulatedHeight = gap; // Draw DropAreas for (int i = 0; i < strings.Count; i++) { if (dragNDrop.DropAreaBegin(i.ToString())) { CustomGUIUtils.DrawBox(dragNDrop.ThisDropArea.Rect, XKCDColors.Orangeish); //GUI.Label(dragNDrop.ThisDropArea.Rect, " " + i + ". " + dragNDrop.ThisDropArea.ToString()); GUI.Label(dragNDrop.ThisDropArea.Rect, " " + i); dragNDrop.ThisDropArea.Rect = new Rect(gap, accumulatedHeight, boxWidth, boxHeight); accumulatedHeight += gap + boxHeight; dragNDrop.SetObject(i.ToString(), strings[i]); dragNDrop.DropAreaEnd(i.ToString()); } } accumulatedHeight = gap; List <String> concurrentStrings = new List <string>(strings); int currentItem = 0; foreach (String str in concurrentStrings) { DragObject currentstr = dragNDrop.TryGetDragObject(str); int i = concurrentStrings.IndexOf(str); if (currentstr.IsDragging) { draggingStringOldIndex = i; draggingString = strings[i]; strings.RemoveAt(i); Debug.Log("Dragging String = " + draggingString + "\n" + strings.ListToString <String>()); } if (dragNDrop.DragObjectBegin(concurrentStrings[i])) { CustomGUIUtils.DrawBox(dragNDrop.CurrentDragObject.CurrentRect, myGrey); GUI.Label(dragNDrop.CurrentDragObject.CurrentRect, concurrentStrings[i].ToString()); Rect icon = new Rect(dragNDrop.CurrentDragObject.CurrentRect); icon.width = icon.height; GUI.DrawTexture(icon, DefaultIconSet.Device); dragNDrop.DragObjectEnd(concurrentStrings[i]); } currentItem++; } if (draggingString != null) { for (int i = 0; i < strings.Count; i++) { DropArea dropArea; if (dragNDrop.dropAreas.TryGetValue(i.ToString(), out dropArea)) { dragNDrop.TryCreateDropArea("before" + i, null, new Rect(dropArea.Rect.x, dropArea.Rect.y, dropArea.Rect.width, dropArea.Rect.height / 2f), dropArea.Types.ToArray()); dragNDrop.TryCreateDropArea("after" + i, null, new Rect(dropArea.Rect.x, dropArea.Rect.y + dropArea.Rect.height / 2f, dropArea.Rect.width, dropArea.Rect.height / 2f), dropArea.Types.ToArray()); if (dragNDrop.DropAreaBegin("before" + i)) { if (dragNDrop.ThisDropArea.ContainsMouse()) { CustomGUIUtils.DrawBox(dragNDrop.ThisDropArea.Rect, XKCDColors.Greenish); //GUI.Label(dragNDrop.ThisDropArea.Rect, " " + i + ". " + dragNDrop.ThisDropArea.ToString()); GUI.Label(dragNDrop.ThisDropArea.Rect, "before " + i); } dragNDrop.DropAreaEnd("before" + i); } if (dragNDrop.DropAreaBegin("after" + i)) { //CustomGUIUtils.DrawBox(dragNDrop.ThisDropArea.Rect, XKCDColors.Greenish); ////GUI.Label(dragNDrop.ThisDropArea.Rect, " " + i + ". " + dragNDrop.ThisDropArea.ToString()); //GUI.Label(dragNDrop.ThisDropArea.Rect, "after " + i); if (dragNDrop.ThisDropArea.ContainsMouse()) { CustomGUIUtils.DrawBox(dragNDrop.ThisDropArea.Rect, XKCDColors.Greenish); //GUI.Label(dragNDrop.ThisDropArea.Rect, " " + i + ". " + dragNDrop.ThisDropArea.ToString()); GUI.Label(dragNDrop.ThisDropArea.Rect, "after " + i); } dragNDrop.DropAreaEnd("after" + i); } } } bool newDropArea = false; if (dragNDrop.DragObjectBegin(draggingString)) { CustomGUIUtils.DrawBox(dragNDrop.CurrentDragObject.CurrentRect, myGrey); GUI.Label(dragNDrop.CurrentDragObject.CurrentRect, draggingString.ToString()); Rect icon = new Rect(dragNDrop.CurrentDragObject.CurrentRect); icon.width = icon.height; GUI.DrawTexture(icon, DefaultIconSet.Device); newDropArea = dragNDrop.DragObjectEnd(draggingString); } //if (newDropArea) //{ //} DragObject currentstr = dragNDrop.TryGetDragObject(draggingString); if (!currentstr.IsDragging) { Debug.Log(currentstr.DropArea.Id); if (currentstr.DropArea.Id.StartsWith("before") || currentstr.DropArea.Id.StartsWith("after")) { if (currentstr.DropArea.Id.StartsWith("before")) { int newIndex = int.Parse(currentstr.DropArea.Id.Replace("before", "")); strings.Insert(newIndex, draggingString); } else if (currentstr.DropArea.Id.StartsWith("after")) { int newIndex = int.Parse(currentstr.DropArea.Id.Replace("after", "")) + 1; strings.Insert(newIndex, draggingString); currentstr.t = 0f; currentstr.Ease = true; currentstr.EaseEndRect = dragNDrop.dropAreas[newIndex.ToString()].Rect; } } else { //strings.Capacity += 1; Debug.Log("old Index" + draggingStringOldIndex); strings.Insert(draggingStringOldIndex, draggingString); } draggingString = null; draggingStringOldIndex = -1; } } }
public MessageError(List <string> errors) : base(errors.ListToString()) { this.Errors = errors; }
public async Task <FabricAuthUserSearchResponse> Search(IdentitySearchRequest request) { var searchResults = new List <IdentitySearchResponse>(); if (string.IsNullOrWhiteSpace(request.ClientId)) { throw new BadRequestException <IdentitySearchRequest>("Client ID is required."); } var client = await _clientService.GetClient(request.ClientId); var clientRoles = await _roleService.GetRoles(client); var clientRoleEntities = clientRoles.ToList(); _logger.Debug($"clientRoles = {clientRoleEntities.ListToString()}"); if (clientRoleEntities.Count == 0) { return(new FabricAuthUserSearchResponse { HttpStatusCode = Nancy.HttpStatusCode.OK, Results = new List <IdentitySearchResponse>() }); } // get all groups tied to clientRoles var groupIds = clientRoleEntities.SelectMany(r => r.Groups).Distinct().ToList(); _logger.Debug($"groupIds = {groupIds.ListToString()}"); if (groupIds.Count == 0) { return(new FabricAuthUserSearchResponse { HttpStatusCode = Nancy.HttpStatusCode.OK, Results = new List <IdentitySearchResponse>() }); } var groupEntities = new List <Group>(); foreach (var groupId in groupIds) { var group = await _groupService.GetGroup(groupId, request.ClientId); groupEntities.Add(group); } _logger.Debug($"groupEntities = {groupEntities.ListToString()}"); var groupsMappedToClientRoles = groupEntities.Where(g => g.Roles.Any(r => clientRoleEntities.Contains(r))).ToList(); var nonCustomGroups = groupsMappedToClientRoles.Where(g => !string.Equals(g.Source, GroupConstants.CustomSource, StringComparison.OrdinalIgnoreCase)).ToList(); _logger.Debug($"nonCustomGroups = {nonCustomGroups.ListToString()}"); // add all non-custom groups to the response searchResults.AddRange(nonCustomGroups.Select(g => new IdentitySearchResponse { GroupName = g.Name, Roles = g.Roles.Select(r => r.Name), EntityType = IdentitySearchResponseEntityType.Group.ToString() })); // get all users mapped to groups in client roles var users = groupsMappedToClientRoles .Where(g => g.Users != null && g.Users.Count > 0) .SelectMany(g => g.Users) .DistinctBy(u => u.SubjectId); var userList = new List <IdentitySearchResponse>(); foreach (var user in users) { // get groups for user var userGroups = user.Groups; var userGroupEntities = groupEntities.Where(g => userGroups.Contains(g.Name, StringComparer.OrdinalIgnoreCase)); // get roles for user var userRoles = userGroupEntities.SelectMany(g => g.Roles).Select(r => r.Name); // add user to response userList.Add(new IdentitySearchResponse { SubjectId = user.SubjectId, IdentityProvider = user.IdentityProvider, Roles = userRoles, EntityType = IdentitySearchResponseEntityType.User.ToString() }); } var fabricIdentityUserResponse = await _identityServiceProvider.Search(request.ClientId, userList.Select(u => $"{u.SubjectId}:{u.IdentityProvider}")); if (fabricIdentityUserResponse != null && fabricIdentityUserResponse.HttpStatusCode == System.Net.HttpStatusCode.OK) { // update user details with Fabric.Identity response foreach (var user in fabricIdentityUserResponse.Results) { var userSearchResponse = userList.FirstOrDefault(u => string.Equals(u.SubjectId, user.SubjectId, StringComparison.OrdinalIgnoreCase)); if (userSearchResponse == null) { continue; } userSearchResponse.FirstName = user.FirstName; userSearchResponse.MiddleName = user.MiddleName; userSearchResponse.LastName = user.LastName; userSearchResponse.LastLoginDateTimeUtc = user.LastLoginDate; } } searchResults.AddRange(userList); _logger.Debug($"searchResults = {searchResults.ListToString()}"); var pageSize = request.PageSize ?? 100; var pageNumber = request.PageNumber ?? 1; return(new FabricAuthUserSearchResponse { HttpStatusCode = fabricIdentityUserResponse != null && fabricIdentityUserResponse.HttpStatusCode != System.Net.HttpStatusCode.OK ? Nancy.HttpStatusCode.PartialContent : Nancy.HttpStatusCode.OK, Results = searchResults .Filter(request) .Sort(request) .Skip((pageNumber - 1) * pageSize) .Take(pageSize) }); }