public bool SetLine(string line) { if (line == null) { return(false); } int rc = 0; // analyza riadku rc = line.IndexOf(' '); if (rc > 0) { Tag = line.Substring(0, rc); p_fields = line.Substring(rc + 1).Split('|'); for (int j = 0; j < p_fields.Length; j++) { p_fields[j] = GCFestivalBase.SafeToString(p_fields[j]); } } else { Tag = string.Empty; p_fields = new string[] {}; } return(true); }
private static int SaveFestivalBook(string folderName, GCFestivalBook book) { int nRet = 0; using (StreamWriter sw = new StreamWriter(Path.Combine(folderName, book.FileName))) { sw.WriteLine("{0}:{1}|{2}|{3}", book.GetType().Name, GCFestivalBase.StringToSafe(book.CollectionName), book.CollectionId, (book.Visible ? 1 : 0)); foreach (GCFestivalBase fb in book.Festivals) { if (fb.nDeleted == 0) { nRet++; sw.WriteLine("{0}:{1}", fb.getToken(), fb.EncodedString); if (fb.EventsCount > 0) { foreach (GCFestivalBase fb2 in fb.Events) { sw.WriteLine("{0}:{1}", fb2.getToken(), fb2.EncodedString); } } if (fb is GCFestivalSpecial) { GCFestivalSpecial se = fb as GCFestivalSpecial; sw.WriteLine(GCFestivalSpecial.InstructionTag); sw.WriteLine(se.Script); sw.WriteLine(GCFestivalSpecial.InstructionEndTag); } } } } return(nRet); }
protected override string[] setEncoded(string[] sa) { sa = base.setEncoded(sa); if (sa.Length > 0) { RasiOfSun = StringToInt(sa[0], 0); } return(GCFestivalBase.Subarray(sa, 1)); }
protected override string[] setEncoded(string[] sa) { sa = base.setEncoded(sa); if (sa.Length > 1) { nMasaMin = StringToInt(sa[0], 0); nMasaMax = StringToInt(sa[1], 11); } return(GCFestivalBase.Subarray(sa, 2)); }
/// <summary> /// Save configuration into file with given name /// </summary> /// <param name="fileName">Full path to file</param> public void Save(string fileName) { FileName = fileName; using (StreamWriter sw = new StreamWriter(fileName)) { sw.WriteLine("3 {0}|{1}", useAcceptLimit, acceptLimit); sw.WriteLine("4 {0}|{1}", useMinPeriodLength, minPeriodLength); sw.WriteLine("5 {0}", GCFestivalBase.StringToSafe(Title)); sw.WriteLine("6 {0}", GCFestivalBase.StringToSafe(Description)); List <ParameterDescriptor> ar = this.ParameterDescriptions; foreach (ParameterDescriptor a in ar) { if (a.Array != null) { for (int i = a.Min; i < a.Max; i++) { sw.WriteLine("1 {0}|{1}|{2}|{3}", a.Key, i, a.Array[i].Rating, GCFestivalBase.StringToSafe(a.Array[i].Note)); for (int k = 0; k < a.Array[i].MarginsCount; k++) { GCConfigRatedMargin m = a.Array[i].Margins[k]; sw.WriteLine("99 {0}|{1}|{2}|{3}|{4}", GCFestivalBase.StringToSafe(m.Title), m.Rating, m.OffsetMinutesStart, m.OffsetMinutesEnd, GCFestivalBase.StringToSafe(m.Note)); } a.Array[i].Modified = false; } } else if (a.Array2 != null) { for (int i = a.Min; i < a.Max; i++) { for (int j = a.Min2; j < a.Max2; j++) { sw.WriteLine("2 {0}|{1}|{2}|{3}|{4}", a.Key, i, j, a.Array2[i, j].Rating, GCFestivalBase.StringToSafe(a.Array2[i, j].Note)); for (int k = 0; k < a.Array2[i, j].MarginsCount; k++) { GCConfigRatedMargin m = a.Array[i].Margins[k]; sw.WriteLine("99 {0}|{1}|{2}|{3}|{4}", GCFestivalBase.StringToSafe(m.Title), m.Rating, m.OffsetMinutesStart, m.OffsetMinutesEnd, GCFestivalBase.StringToSafe(m.Note)); } a.Array2[i, j].Modified = false; } } } } } }
/// <summary> /// Removing related event based on EventID /// </summary> /// <param name="cFestival"></param> public void Remove(GCFestivalBase cFestival) { if (p_events == null) { return; } for (int i = 0; i < p_events.Count; i++) { if (p_events[i].EventID == cFestival.EventID) { p_events.RemoveAt(i); break; } } }
public void Remove(GCFestivalBase ce) { int index = -1; for (int i = 0; i < list.Count; i++) { if (list[i].EventID == ce.EventID) { index = i; break; } } if (index >= 0) { Changed = true; list.RemoveAt(index); } }
public static int OpenEventsFile(string pszFile) { int nMode = 0; int nRet = -1; StringBuilder sb = new StringBuilder(); GCFestivalBase lastFestival = null; using (StreamReader sr = new StreamReader(pszFile)) { nRet++; string line; while ((line = sr.ReadLine()) != null) { string tag = ""; string data = ""; if (nMode == 0) { // preparation if (line.Equals(GCFestivalSpecial.InstructionTag)) { tag = line; } else if (line.IndexOf(':') > 0) { tag = line.Substring(0, line.IndexOf(':')); data = line.Substring(line.IndexOf(':') + 1); } // processing of tag and data if (tag.Equals(typeof(GCFestivalBook).Name)) { string[] p = data.Split('|'); if (p.Length > 2) { GCFestivalBook fb = GCFestivalBookCollection.getSafeBook(GCFestivalBase.StringToInt(p[1], 6)); fb.CollectionName = GCFestivalBase.SafeToString(p[0]); if (pszFile.EndsWith(".ev.rl")) { fb.FileName = Path.GetFileName(pszFile); } fb.Visible = p[2].Equals("1"); nRet++; } } else if (tag.Equals(typeof(GCFestivalTithiMasa).Name)) { nRet++; GCFestivalTithiMasa pce = new GCFestivalTithiMasa(); pce.EncodedString = data; GCFestivalBook book = GCFestivalBookCollection.getSafeBook(pce.BookID); book.Add(pce); lastFestival = pce; } else if (tag.Equals(typeof(GCFestivalSankranti).Name)) { nRet++; GCFestivalSankranti se = new GCFestivalSankranti(); se.EncodedString = data; GCFestivalBook book = GCFestivalBookCollection.getSafeBook(se.BookID); book.Add(se); lastFestival = se; } else if (tag.Equals(typeof(GCFestivalRelated).Name)) { nRet++; GCFestivalRelated re = new GCFestivalRelated(); re.EncodedString = data; if (lastFestival != null) { lastFestival.AddRelatedFestival(re); } } else if (tag.Equals(typeof(GCFestivalEkadasi).Name)) { nRet++; GCFestivalEkadasi fe = new GCFestivalEkadasi(); fe.EncodedString = data; GCFestivalBook book = GCFestivalBookCollection.getSafeBook(fe.BookID); book.Add(fe); lastFestival = fe; } else if (tag.Equals(typeof(GCFestivalMasaDay).Name)) { nRet++; GCFestivalMasaDay me = new GCFestivalMasaDay(); me.EncodedString = data; GCFestivalBook book = GCFestivalBookCollection.getSafeBook(me.BookID); book.Add(me); lastFestival = me; } else if (tag.Equals(typeof(GCFestivalSpecial).Name)) { nRet++; GCFestivalSpecial se = new GCFestivalSpecial(); se.EncodedString = data; GCFestivalBook book = GCFestivalBookCollection.getSafeBook(se.BookID); book.Add(se); lastFestival = se; } else if (tag.Equals(GCFestivalSpecial.InstructionTag)) { nMode = 1; sb.Clear(); } } else if (nMode == 1) { if (line.Equals(GCFestivalSpecial.InstructionEndTag)) { if (lastFestival is GCFestivalSpecial) { GCFestivalSpecial se = lastFestival as GCFestivalSpecial; se.Script = sb.ToString(); } nMode = 0; } else { sb.AppendLine(line); } } } } return(nRet); }
/// <summary> /// /// </summary> /// <param name="exec"></param> /// <param name="offsetWithToday">If value of this parameter is 0, then current day is processed, /// -1 is for yesterday, +1 is for tomorrow</param> /// <param name="currFestTop"></param> /// <param name="fb"></param> /// <returns></returns> private int AddEventToDay(GCFestivalSpecialExecutor exec, int offsetWithToday, int currFestTop, GCFestivalBase fb) { VAISNAVADAY t = exec.day(offsetWithToday); VAISNAVAEVENT md = t.AddEvent(DisplayPriorities.PRIO_FESTIVALS_0 + fb.BookID * 100 + currFestTop, GCDS.CAL_FEST_0 + fb.BookID, fb.Text); currFestTop += 5; if (fb.FastID > 0) { md.fasttype = fb.FastID; md.fastsubject = fb.FastingSubject; } if (GCDisplaySettings.Current.getValue(51) != 2 && fb.StartYear > -7000) { String ss1; int years = t.astrodata.GaurabdaYear - (fb.StartYear - 1496); string appx = "th"; if (years % 10 == 1) { appx = "st"; } else if (years % 10 == 2) { appx = "nd"; } else if (years % 10 == 3) { appx = "rd"; } if (GCDisplaySettings.Current.getValue(51) == 0) { ss1 = string.Format("{0} ({1}{2} anniversary)", md.text, years, appx); } else { ss1 = string.Format("{0} ({1}{2})", md.text, years, appx); } md.text = ss1; } if (fb.EventsCount > 0) { foreach (GCFestivalBase re in fb.Events) { if (re is GCFestivalRelated) { GCFestivalRelated related = re as GCFestivalRelated; AddEventToDay(exec, fb.DayOffset + related.DayOffset, 0, related); } } } return(currFestTop); }
/* OLD STYLE FASTING * * public static int SetOldStyleFasting(int bOldStyle) * { * GCFestivalTithiMasa pce = null; * * int[,] locMatrix = * { * // visnu tattva and sakti tattva * // tithi, masa, fast, new fast, class * { 28, 0, 4, 7, 0}, * { 29, 3, 1, 7, 0}, * { 22, 4, 1, 0, 0}, * { 26, 4, 1, 7, 0}, * { 21, 9, 1, 7, 0}, * { 26, 9, 1, 7, 0}, * { 27, 9, 1, 7, 0}, * { 7, 4, 5, 7, 0}, * { 29, 10, 3, 7, 0}, * { 23, 11, 2, 7, 0}, * // acaryas * { 8, 4, 1, 0, 2}, * { 27, 4, 1, 0, 2}, * { 14, 2, 1, 0, 2}, * { 25, 6, 1, 0, 2}, * { 18, 6, 1, 0, 2}, * { 3, 8, 1, 0, 2}, * { 4, 10, 1, 0, 2}, * {-1,-1,-1,-1, -1} * }; * * int i, idx; * int ret = 0; * if (bOldStyle != 0) idx = 2; * else idx = 3; * * for (i = 0; locMatrix[i, 0] >= 0; i++) * { * foreach (GCFestivalBook book in GCFestivalBookCollection.Books) * { * foreach (GCFestivalBase fb in book.Festivals) * { * if (fb is GCFestivalTithiMasa) * { * pce = fb as GCFestivalTithiMasa; * if (pce.nMasa == locMatrix[i, 1] && * pce.nTithi == locMatrix[i, 0] && * pce.nClass == locMatrix[i, 4]) * { * if (pce.nFastType != locMatrix[i, idx]) * { * ret++; * pce.nFastType = locMatrix[i, idx]; * } * break; * } * } * } * } * } * * return ret; * } */ public GCFestivalBase Add(GCFestivalBase ce) { list.Add(ce); return(ce); }
/// <summary> /// Loading configuration from file /// </summary> /// <param name="fileName"></param> public void Load(string fileName) { FileName = fileName; using (StreamReader sr = new StreamReader(fileName)) { List <ParameterDescriptor> ar = this.ParameterDescriptions; ParameterDescriptor a; GCConfigRatedEntry lastEntry = null; int idx, idx2; GCRichFileLine rf = new GCRichFileLine(); while (rf.SetLine(sr.ReadLine())) { a = GetArrayRef(ar, rf.GetField(0)); try { if (rf.TagInt == 1) { idx = rf.GetFieldInt(1); a.Array[idx].Rating = rf.GetFieldDouble(2); a.Array[idx].Note = rf.GetField(3); lastEntry = a.Array[idx]; } else if (rf.TagInt == 2) { idx = rf.GetFieldInt(1); idx2 = rf.GetFieldInt(2); a.Array2[idx, idx2].Rating = rf.GetFieldDouble(3); a.Array2[idx, idx2].Note = rf.GetField(4); lastEntry = a.Array2[idx, idx2]; } else if (rf.TagInt == 3) { useAcceptLimit = bool.Parse(rf.GetField(0)); acceptLimit = rf.GetFieldDouble(1); } else if (rf.TagInt == 4) { useMinPeriodLength = bool.Parse(rf.GetField(0)); minPeriodLength = rf.GetFieldDouble(1); } else if (rf.TagInt == 5) { Title = GCFestivalBase.SafeToString(rf.GetField(0)); } else if (rf.TagInt == 6) { Description = GCFestivalBase.SafeToString(rf.GetField(0)); } else if (rf.TagInt == 99 && lastEntry != null) { GCConfigRatedMargin m = new GCConfigRatedMargin(); m.Title = GCFestivalBase.SafeToString(rf.GetField(0)); m.Rating = rf.GetFieldDouble(1); m.OffsetMinutesStart = rf.GetFieldInt(2); m.OffsetMinutesEnd = rf.GetFieldInt(3); m.Note = GCFestivalBase.SafeToString(rf.GetField(4)); lastEntry.AddMargin(m); } } catch { } } } }