//------------------------------------------------------------------------------- #region +GetListAndIndexOfCheckFileCircleInfo CheckFileCircleInfo -> ObservableCollection<CheckFileCircleInfo> //------------------------------------------------------------------------------- // public Tuple<ObservableSortedCollection<CheckFileCircleInfo>, int> GetListAndIndexOfCheckFileCircleInfo(CheckFileCircleInfo item) { int index1 = _circleList_d1.IndexOf(item); if (index1 >= 0) { return Tuple.Create(_circleList_d1, index1); } int index2 = _circleList_d2.IndexOf(item); if (index2 >= 0) { return Tuple.Create(_circleList_d2, index2); } int index3 = _circleList_d3.IndexOf(item); if (index3 >= 0) { return Tuple.Create(_circleList_d3, index3); } return null; }
//------------------------------------------------------------------------------- #region -RemoveItem アイテムの削除 //------------------------------------------------------------------------------- // public void RemoveItem(CheckFileCircleInfo item) { var tuple = GetListAndIndexOfCheckFileCircleInfo(item); if (tuple == null) { return; } var list = tuple.Item1; var index = tuple.Item2; list.RemoveAt(index); }
//------------------------------------------------------------------------------- #region +AddCircle サークル追加 //------------------------------------------------------------------------------- // public void AddCircle(CheckFileCircleInfo cinfo, int day) { cinfo.IndexToColorFunc = ColorIndexToColorFunc; cinfo.IndexToColorDescriptionFunc = ColorIndexToColorDescriptionFunc; switch (day) { case 1: _circleList_d1.Add(cinfo); OnPropertyChanged(new PropertyChangedEventArgs("CircleList_Day1")); break; case 2: _circleList_d2.Add(cinfo); OnPropertyChanged(new PropertyChangedEventArgs("CircleList_Day2")); break; case 3: _circleList_d3.Add(cinfo); OnPropertyChanged(new PropertyChangedEventArgs("CircleList_Day3")); break; default: return; } }
//------------------------------------------------------------------------------- #region +RefreshItem 表示のリフレッシュ(by observable collection) //------------------------------------------------------------------------------- // public void RefreshItem(CheckFileCircleInfo checkListItem) { var tuple = GetListAndIndexOfCheckFileCircleInfo(checkListItem); if (tuple == null) { return; } var list = tuple.Item1; var index = tuple.Item2; list.Refresh(index); if (list == _circleList_d1) { OnPropertyChanged(new PropertyChangedEventArgs("CircleList_Day1")); } else if (list == _circleList_d2) { OnPropertyChanged(new PropertyChangedEventArgs("CircleList_Day2")); } else if (list == _circleList_d3) { OnPropertyChanged(new PropertyChangedEventArgs("CircleList_Day3")); } }
//------------------------------------------------------------------------------- #region -ReadCSV csvファイル(行ごとの文字列配列)から初期化 //------------------------------------------------------------------------------- // private async Task<bool> ReadCSV(IEnumerable<string> lines, Func<char, Task<int>> dayToDayIndexFunc, Func<int, Task<ComiketCircleAndLayout>> updateIdToCircle) { char[] SEPARATOR = new char[] { ',' }; _colorList.Clear(); _circleList_d1.Clear(); _circleList_d2.Clear(); _circleList_d3.Clear(); _unknownCircleList.Clear(); bool inComma = false; List<string> continueList = null; foreach (var line in lines) { if (line.Length == 0 && continueList != null) { continueList[continueList.Count - 1] = continueList[continueList.Count - 1] + "\n"; continue; } var elements = line.Split(SEPARATOR, StringSplitOptions.None); List<string> elementsList = new List<string>(); StringBuilder sb = (inComma) ? new StringBuilder() : null; for (int i = 0; i < elements.Length; ++i) { string curr = elements[i]; if (curr.Length > 0) { //bool doubleQuotationExists = curr.Contains("\"\""); int commaCount = curr.Count(c => c == '"'); bool commaExists = (commaCount % 2 == 1); if (commaExists) { if (!inComma) { sb = new StringBuilder(); sb.Append(curr.Replace("\"", "")); inComma = true; } else { sb.Append(curr.Replace("\"", "")); elementsList.Add(sb.ToString()); sb = null; inComma = false; } } else if (inComma) { sb.Append(curr); } else { elementsList.Add(curr); } } else { elementsList.Add(curr); } } if (sb != null) { elementsList.Add(sb.ToString()); } elements = elementsList.ToArray(); if (continueList != null) { continueList[continueList.Count - 1] = continueList[continueList.Count - 1] + "\n" + elements[0]; for (int i = 1; i < elements.Length; ++i) { continueList.Add(elements[i]); } elements = continueList.ToArray(); continueList = null; } if (inComma) { continueList = new List<string>(); continueList.AddRange(elements); continue; } switch (elements[0]) { case "Header": break; case "Color": { string colorStr = elements[2]; var ci = new ColorInfo() { Index = int.Parse(elements[1]), R = byte.Parse(colorStr.Substring(4, 2), System.Globalization.NumberStyles.HexNumber), G = byte.Parse(colorStr.Substring(2, 2), System.Globalization.NumberStyles.HexNumber), B = byte.Parse(colorStr.Substring(0, 2), System.Globalization.NumberStyles.HexNumber), Description = elements[4] }; _colorList.Add(ci); } break; case "Circle": { try { CheckFileCircleInfo ci = new CheckFileCircleInfo() { SerialNo = int.Parse(elements[1]), ColorIndex = int.Parse(elements[2]), PageNo = int.Parse(elements[3]), CutIndex = int.Parse(elements[4]), DayOfWeek = elements[5][0], Area = elements[6][0], Block = elements[7][0], SpaceNo = int.Parse(elements[8]), GenreCode = int.Parse(elements[9]), CircleName = elements[10], CircleKana = elements[11], PenName = elements[12], BookName = elements[13], URL = elements[14], Mail = elements[15], Description = elements[16], Memo = elements[17], IndexToColorFunc = ColorIndexToColorFunc, IndexToColorDescriptionFunc = ColorIndexToColorDescriptionFunc }; if (elements.Length > 23 && !string.IsNullOrWhiteSpace(elements[18])) { ci.MapX = int.Parse(elements[18]); ci.MapY = int.Parse(elements[19]); ci.Layout = int.Parse(elements[20]); ci.SpaceNoSub = int.Parse(elements[21]); ci.UpdateInfo = elements[22]; ci.Url_Circlems = elements[23]; ci.RSS = (elements.Length > 24) ? elements[24] : ""; ci.RSSgetInfo = (elements.Length > 25) ? elements[25] : ""; } else { int serialNo = int.Parse(elements[1]); ComiketCircleAndLayout ccl = await updateIdToCircle(serialNo); ci.MapX = ccl.xpos; ci.MapY = ccl.ypos; ci.Layout = ccl.layout; ci.SpaceNoSub = ccl.spaceNoSub; ci.UpdateInfo = ""; ci.Url_Circlems = ccl.circlems; ci.RSS = ccl.rss; ci.RSSgetInfo = ""; } switch (await dayToDayIndexFunc(ci.DayOfWeek)) { case 1: _circleList_d1.Add(ci); break; case 2: _circleList_d2.Add(ci); break; case 3: _circleList_d3.Add(ci); break; } } catch (Exception) { try { var ci = new CheckFileUnknownCircleInfo() { CircleName = elements[10], CircleKana = elements[11], PenName = elements[12], Memo = elements[17], ColorIndex = int.Parse(elements[2]), BookName = elements[13], URL = elements[14], Mail = elements[15], Description = elements[16], UpdateInfo = elements[22], Url_Circlems = elements[23], RSS = (elements.Length > 24) ? elements[24] : "", IndexToColorFunc = ColorIndexToColorFunc, IndexToColorDescriptionFunc = ColorIndexToColorDescriptionFunc }; _unknownCircleList.Add(ci); } catch (Exception ex) { throw ex; } } } break; case "UnKnown": { CheckFileUnknownCircleInfo ci; try { ci = new CheckFileUnknownCircleInfo() { CircleName = elements[1], CircleKana = elements[2], PenName = elements[3], Memo = elements[4], ColorIndex = int.Parse(elements[5]), BookName = elements[6], URL = elements[7], Mail = elements[8], Description = elements[9], UpdateInfo = elements[10], Url_Circlems = elements[11], RSS = elements[12], IndexToColorFunc = ColorIndexToColorFunc, IndexToColorDescriptionFunc = ColorIndexToColorDescriptionFunc }; } catch (Exception ex) { throw ex; } _unknownCircleList.Add(ci); } break; default: break; } } OnPropertyChanged(new PropertyChangedEventArgs("ColorInfo")); OnPropertyChanged(new PropertyChangedEventArgs("CircleList_Day1")); OnPropertyChanged(new PropertyChangedEventArgs("CircleList_Day2")); OnPropertyChanged(new PropertyChangedEventArgs("CircleList_Day3")); OnPropertyChanged(new PropertyChangedEventArgs("CircleList_Unknown")); return true; }