public static int UpdateExistingDayEntry(DayEntry updateDayEntry) { using (var context = new VoedingsstoffenContext()) { try { DayEntry dayEntry = context.DayEntrys.Include("Result").Include("SavedProducts").FindOne(w => w.DayEntryId == updateDayEntry.DayEntryId); if (dayEntry != null) { dayEntry.SavedProducts.AddRange(updateDayEntry.SavedProducts); dayEntry.Result = updateDayEntry.Result; return(context.DayEntrys.Update(dayEntry) ? 1 : 0); } return(0); } catch (ArgumentNullException e) { Console.WriteLine(e); throw; } catch (Exception e) { Console.WriteLine(e); throw; } } }
void LoadDirectory(DirectoryInfo dir) { if (dir.Name.EndsWith("drafts")) { return; } if (Verbose) { Console.WriteLine("dir:" + dir); } foreach (DirectoryInfo subdir in dir.GetDirectories()) { LoadDirectory(subdir); } foreach (FileInfo file in dir.GetFiles()) { if (!(file.Name.EndsWith(".html") || file.Name.EndsWith(".txt") || file.Name.EndsWith(".md"))) { continue; } DayEntry de = DayEntry.Load(this, file.FullName); if (de != null) { entries.Add(de); if (de.Date > pubDate) { pubDate = de.Date; } } } }
string GetEntryNavigation(IList entries, int idx, string blog_base) { DayEntry prev = (DayEntry)(idx > 0 ? entries [idx - 1] : null); DayEntry next = (DayEntry)(idx + 1 < entries.Count ? entries [idx + 1] : null); StringBuilder nav = new StringBuilder(); if (prev != null) { nav.Append(string.Format("<a href=\"{0}{1}\">« {2}</a> | \n", blog_base, prev.PermaLink, prev.Caption)); } nav.Append(string.Format("<a href=\"{0}{1}\">Main</a>\n", blog_base, config.BlogFileName)); if (next != null) { nav.Append(string.Format(" | <a href=\"{0}{1}\">{2} »</a> \n", blog_base, next.PermaLink, next.Caption)); } #if false nav.Append(string.Format("<h3><a href=\"{2}{0}\" class=\"entryTitle\">{3}</a></h3>", d.PermaLink, d.DateCaption, blog_base, d.Caption)); nav.Append("<div class='blogentry'>" + d.Body + "</div>"); nav.Append(string.Format("<div class='footer'>Posted by {2} on <a href=\"{0}{1}\">{3}</a></div><p>", blog_base, d.PermaLink, config.Copyright, d.DateCaption)); #endif return(nav.ToString()); }
void FillEntrySubstitutions(Hashtable substitutions, DayEntry d, string blog_base, bool single_entry) { string category_paths = GetCategoryPaths(d, blog_base); string entry_path = LB.GetEntryPath(blog_base, d); substitutions.Add("@ENTRY_ID@", d.Id); substitutions.Add("@ENTRY_PATH@", entry_path); substitutions.Add("@ENTRY_PERMALINK@", d.PermaLink); substitutions.Add("@ENTRY_CAPTION@", d.Caption); substitutions.Add("@ENTRY_CAPTION_ENC@", HttpUtility.UrlEncode(d.Caption)); substitutions.Add("@BASEDIR@", config.BlogWebDirectory); substitutions.Add("@BASEIMAGES@", config.BlogImageBasedir); substitutions.Add("@COPYRIGHT@", config.Copyright); substitutions.Add("@ENTRY_CATEGORY@", d.Category); substitutions.Add("@ENTRY_DATECAPTION@", d.DateCaption); substitutions.Add("@ENTRY_CATEGORY_PATHS@", category_paths); substitutions.Add("@BLOGWEBDIR@", config.BlogWebDirectory); substitutions.Add("@ENTRY_URL_PERMALINK@", Path.Combine(config.BlogWebDirectory, d.PermaLink)); if (d.Comments && single_entry) { StringWriter rendered_comment = new StringWriter(new StringBuilder(comments.Length)); Translate(comments, rendered_comment, substitutions); substitutions.Add("@COMMENTS@", rendered_comment.ToString()); d.RenderedComment = rendered_comment.ToString(); } else { substitutions.Add("@COMMENTS@", ""); } }
private void LoadDayEntryFromCurrentDay() { _currentDayEntry = Repository.SearchDayEntryOnDate(_currentDateTime); if (_currentDayEntry != null) { CheckForEmptyProList(); List <Result> result = new List <Result>(); ListViewDagOverzicht.DataContext = _currentDayEntry.SavedProducts; var resultOne = _currentDayEntry.Result; result.Add(resultOne); ListViewResult.DataContext = result; } else { MessageBoxResult result = MessageBox.Show("Voor de huidige datum worden nu nieuwe gegevens aangemaakt", "Gegevens aanmaken voor " + _currentDateTime.ToShortDateString(), MessageBoxButton.OK, MessageBoxImage.Exclamation); if (result == MessageBoxResult.OK) { DayEntry defaultDayEntry = new DayEntry() { CurentDate = Convert.ToDateTime(_currentDateTime.ToShortDateString()), Result = new Result(), SavedProducts = new List <SavedProduct>() }; if (Repository.AddNewDayEntry(defaultDayEntry) != 0) { MessageBox.Show("Nieuw dag overzicht aangemaakt"); LoadDayEntryFromCurrentDay(); } else { MessageBox.Show("Nieuw dag overzicht niet aangemaakt"); } } } }
private void ButtonUpdate_Click(object sender, RoutedEventArgs e) { List <SavedProduct> savedProducts = new List <SavedProduct>(); savedProducts = _currentDayEntry.SavedProducts; savedProducts.AddRange(_currentProductList); foreach (var t in savedProducts) { t.DayEntryId = _currentDayEntry.DayEntryId; } DayEntry dayEntryUpdate = new DayEntry() { DayEntryId = _currentDayEntry.DayEntryId, CurentDate = _currentDayEntry.CurentDate, Result = Calculator.CalculateDayTotal(savedProducts), SavedProducts = _currentProductList }; if (Repository.UpdateExistingDayEntry(dayEntryUpdate) != 0) { MessageBox.Show("Het dag overzicht is bijgewerkt"); } else { MessageBox.Show("Het dag overzicht is niet bijgewerkt"); } ButtonUpdate.IsEnabled = false; ListViewAdding.DataContext = null; LoadDayEntryFromCurrentDay(); }
public void TestMultiplePoints() { // Arrange var day = new DayEntry(_userId, DateTime.Now); var point1 = new TimeEntry(day.Id, new DateTime(2020, 10, 17, 9, 1, 0)); var point2 = new TimeEntry(day.Id, new DateTime(2020, 10, 17, 16, 42, 0)); var point3 = new TimeEntry(day.Id, new DateTime(2020, 10, 17, 16, 44, 0)); var point4 = new TimeEntry(day.Id, new DateTime(2020, 10, 17, 16, 48, 0)); var point5 = new TimeEntry(day.Id, new DateTime(2020, 10, 17, 17, 49, 0)); var point6 = new TimeEntry(day.Id, new DateTime(2020, 10, 17, 18, 2, 0)); var lunchTime = new TimeSpan(1, 0, 0); var toleranceTime = new TimeSpan(0, 10, 0); var workingTime = new TimeSpan(8, 0, 0); var config = new Configuration(_userId, lunchTime, toleranceTime, workingTime); // Act day.AddPoint(point1, config); day.AddPoint(point2, config); day.AddPoint(point3, config); day.AddPoint(point4, config); day.AddPoint(point5, config); day.AddPoint(point6, config); // Test Assert.Equal(new TimeSpan(0, 0, 0), day.MissingTime); Assert.Equal(new TimeSpan(0, 0, 0), day.ExtraTime); }
public async Task <bool> Handle(CreatePointCommand request, CancellationToken cancellationToken) { var config = await _configurationRepository.FindByUser(request.UserId); if (config == null) { await _mediator.Publish(new DomainNotification(request.MessageType, "User doesn't have a configuration")); return(false); } var day = await _dayEntryRepository.FindByDay(request.UserId, request.Date); if (day == null) { day = new DayEntry(request.UserId, request.Date); _dayEntryRepository.CreateDay(day); } var time = new TimeEntry(day.Id, request.Date); day.AddPoint(time, config); _dayEntryRepository.CreatePoint(time); return(await _dayEntryRepository.UnitOfWork.Commit()); }
private void downloadMenu_Click(object sender, System.EventArgs e) { ResolveFileCallback old = BlogXData.Resolver; BlogXData.Resolver = new ResolveFileCallback(ResolvePathToCache); Debug.WriteLine("Begin GetDaysWithEntries"); DateTime[] dates = browse.GetDaysWithEntries(); Debug.WriteLine("End GetDaysWithEntries"); foreach (DateTime date in dates) { Debug.WriteLine("Begin GetDayEntry"); DayEntry dayEntry = browse.GetDayEntry(date); Debug.WriteLine("End GetDayEntry"); dayEntry.Save(); Debug.WriteLine("Begin GetDayExtra"); DayExtra dayExtra = browse.GetDayExtra(date); Debug.WriteLine("End GetDayExtra"); if (dayExtra.Comments.Count > 0) { dayExtra.Save(); } } BlogXData.Resolver = old; }
public void RenderArchive() { for (int i = 0; i < Entries; i++) { DayEntry d = (DayEntry)entries [i]; string parent_dir = "../.."; if (d.Category.Length > 0) { parent_dir += Regex.Replace(d.Category, "[^/]+", ".."); } RenderHtml(Path.Combine(config.Prefix, d.PermaLink), entries.Count - i - 1, entries.Count - i, parent_dir, false); if (d.Images == null) { continue; } foreach (string filename in d.Images) { string file = Path.GetFileName(filename); string thumbnail = Path.Combine(LB.GetEntryPath(config.Prefix + "/", d), LB.GetThumbnailName(file)); string thumbnail_target = Path.Combine( LB.GetEntryPath(config.Prefix + "/", d), file); file = Path.Combine(config.ImageDirectory, filename); if (!File.Exists(file)) { Console.Error.WriteLine("lb: Missing file for #thumbnail {0}, ({1}).", filename, file); continue; } if (!File.Exists(thumbnail_target)) { File.Copy(file, thumbnail_target); } if (!File.Exists(thumbnail)) { ProcessStartInfo psi = new ProcessStartInfo(config.ThumbnailCommandFileName); psi.Arguments = string.Format(config.ThumbnailCommandArguments, file, thumbnail); Process p = Process.Start(psi); p.WaitForExit(); if (p.ExitCode != 0) { Console.Error.WriteLine("lb: error running command: {0} {1}", psi.FileName, psi.Arguments); } } } } foreach (DictionaryEntry de in category_entries) { string category = de.Key.ToString(); IList entries = (IList)de.Value; string parent_dir = ".." + Regex.Replace(category, "[^/]+", ".."); RenderHtml(Path.Combine(config.Prefix, "archive" + category + config.BlogFileName), parent_dir, entries, 0, entries.Count, false); } }
public void Execute(HolidayEntryCommand command) { for (var date = command.DateFrom.Value; date <= command.DateTo; date = date.AddDays(1)) { var entry = new DayEntry(_userId, date, 0, SystemTime.UtcNow()); _session.Store(entry); } }
private void DatePickerDatum_SelectedDateChanged(object sender, SelectionChangedEventArgs e) { if (DatePickerDatum.SelectedDate != null) { _currentDateTime = (DateTime)DatePickerDatum.SelectedDate; } _currentDayEntry = null; LoadDayEntryFromCurrentDay(); }
public static void FixDays(string path) { ContentPath = path; IBlogDataService dataService = BlogDataServiceFactory.GetService(ContentPath, null); EntryCollection entries = dataService.GetEntriesForDay( DateTime.MaxValue.AddDays(-2), TimeZone.CurrentTimeZone, String.Empty, int.MaxValue, int.MaxValue, String.Empty); Hashtable DayEntries = new Hashtable(); foreach (Entry entry in entries) { DayEntry dayEntry = new DayEntry(); dayEntry.DateUtc = entry.CreatedUtc; if (DayEntries.ContainsKey(entry.CreatedUtc.Date)) { dayEntry = DayEntries[entry.CreatedUtc.Date] as DayEntry; } dayEntry.Entries.Add(entry); DayEntries[entry.CreatedUtc.Date] = dayEntry; } DirectoryInfo directoryInfo = new DirectoryInfo(path); foreach (FileInfo fileInfo in directoryInfo.GetFiles("*.dayentry.xml")) { // backup the old file try { DirectoryInfo backup = new DirectoryInfo(Path.Combine(directoryInfo.FullName, "backup")); if (!backup.Exists) { backup.Create(); } fileInfo.MoveTo(Path.Combine(backup.FullName, fileInfo.Name)); } catch (Exception e) { ErrorTrace.Trace(TraceLevel.Error, e); } } foreach (DayEntry dayEntry in DayEntries.Values) { Save(dayEntry, path); } }
public async Task CreateDailyAsync_CreatesAnEntry() { var result = await Api.CreateDailyAsync(DateTime.Now.Date, GetTestId(TestId.ProjectId), GetTestId(TestId.TaskId), 2); _todelete = result.DayEntry; Assert.Equal(2m, result.DayEntry.Hours); Assert.Equal(GetTestId(TestId.ProjectId), result.DayEntry.ProjectId); Assert.Equal(GetTestId(TestId.TaskId), result.DayEntry.TaskId); }
public void CreateDaily_CreatesAnEntry() { var result = Api.CreateDaily(DateTime.Now.Date, GetTestId(TestId.ProjectId), GetTestId(TestId.TaskId), 2); _todelete = result.DayEntry; Assert.Equal(2m, result.DayEntry.Hours); Assert.Equal(GetTestId(TestId.ProjectId), result.DayEntry.ProjectId); Assert.Equal(GetTestId(TestId.TaskId), result.DayEntry.TaskId); }
public MountEntry() { for (int i = 0; i < dayEntries.Length; i++) { List <string> demo = new List <string>(); demo.Add("Activity 1"); dayEntries[i] = new DayEntry(demo); } }
void RenderHtml(string output, string blog_base, IList entries, int start, int end, bool include_page_navigation) { using (FileStream o = CreateFile(output)){ StreamWriter w = new StreamWriter(o, GetOutputEncoding()); StringWriter blog_entries = new StringWriter(); Render(blog_entries, entries, start, end, blog_base, Path.GetFileName(output) == "all.html"); StringWriter blog_articles = new StringWriter(); RenderArticleList(blog_articles); string page_navigation = ""; string title; if (Math.Abs(start - end) == 1) { DayEntry d = (DayEntry)entries [entries.Count - start - 1]; title = String.Format("{0} - {1}", d.Caption, config.Title); } else { title = config.Title; if (include_page_navigation) { page_navigation = GetPageNavigation(start, end); } } Hashtable substitutions = new Hashtable(); substitutions.Add("@BLOG_ENTRIES@", blog_entries.ToString()); substitutions.Add("@ANALYTICS@", analytics); substitutions.Add("@BLOG_ENTRY_INDEX@", CreateEntryIndex(entries, start, end)); substitutions.Add("@BLOG_ARTICLES@", blog_articles.ToString()); substitutions.Add("@BASEDIR@", blog_base); substitutions.Add("@TITLE@", title); substitutions.Add("@DESCRIPTION@", config.Description); substitutions.Add("@RSSFILENAME@", config.RSSFileName); substitutions.Add("@EDITOR@", config.ManagingEditor); substitutions.Add("@BLOGWEBDIR@", config.BlogWebDirectory); substitutions.Add("@ARCHIVE_NAVIGATOR@", archive_navigator); substitutions.Add("@PAGE_NAVIGATION@", page_navigation); var processed_widgets = new StringWriter(); Translate(config.Widgets, processed_widgets, substitutions); substitutions.Add("@WIDGETS@", processed_widgets.ToString()); Translate(template, w, substitutions); w.Flush(); } }
public void EnterHoursForDay(string hours, string dayOfWeek, DayEntry entry) { var p = new TimeCardPageDriver(_ie); p.Hours.TypeText(hours); p.WeekDateList.Select(dayOfWeek); p.EarningCodes.Select(entry.EarningCode); p.ContractLines.Select(entry.ContractLine); p.ContractNumbers.Select(entry.ContractNumber); p.ActivityIDs.Select(entry.ActivityID); p.ProjectIDs.Select(entry.ProjectID); p.SaveDetailsButton.Click(); }
public static DayEntry Load(Blog blog, string file) { DayEntry de = null; try { de = new DayEntry(blog, file); } catch (Exception e) { if (blog.Verbose) { Console.WriteLine("Failed to load file: {0}. Reason: {1}", file, e.Message); } } return(de); }
private static ICollection <DayEntryEntry> ReadIndasBlogEntries(string path) { var files = Directory.GetFiles(path).Where(name => name.EndsWith("dayentry.xml")); var dayEntries = new List <DayEntryEntry>(); foreach (string filePath in files) { var serializer = new XmlSerializer(typeof(DayEntry)); DayEntry entry = (DayEntry)serializer.Deserialize(new XmlTextReader(filePath)); dayEntries.AddRange(entry.Entries.Select(item => item)); } return(dayEntries); }
public static int AddNewDayEntry(DayEntry dayEntryNew) { using (var context = new VoedingsstoffenContext()) { try { return(context.DayEntrys.Insert(dayEntryNew) != null ? 1 : 0); } catch (Exception e) { Console.WriteLine(e); throw; } } }
public void TestDefaultTime_NoExtraNoMissing() { // Arrange var day = new DayEntry(_userId, DateTime.Now); var point1 = new TimeEntry(day.Id, new DateTime(2020, 10, 1, 8, 0, 0)); var point2 = new TimeEntry(day.Id, new DateTime(2020, 10, 1, 11, 56, 0)); // Act day.AddPoint(point1, configuration); day.AddPoint(point2, configuration); // Test Assert.Equal(new TimeSpan(0, 0, 0), day.MissingTime); Assert.Equal(new TimeSpan(0, 0, 0), day.ExtraTime); }
public DayEntryModel Create(DateTime input) { var entryId = DayEntry.GenerateId(_userId, input); var entry = _session.Load <DayEntry>(entryId); var model = new DayEntryModel(input); if (entry != null) { model.PreviousAnswer = new DayEntryModel.Previous(entry.HoursWorked, UserTime.FromUtc(entry.Timestamp)); model.Command.HoursWorked = entry.HoursWorked; } return(model); }
private void save_Click(object sender, System.EventArgs e) { if (SiteSecurity.IsInRole("admin")) { BlogXData data = new BlogXData(); bool added = false; Entry entry = new Entry(); entry.Initialize(); entry.Title = entryTitle.Text; entry.Description = entryAbstract.Text; entry.Content = entryContent.Text; entry.Categories = entryCategories.Text; foreach (DayEntry day in data.Days) { if (day.Date == entry.Created.Date) { added = true; day.Load(); day.Entries.Add(entry); day.Save(); data.IncrementEntryChange(); BlogXUtils.PingWeblogsCom(); break; } } if (!added) { DayEntry newDay = new DayEntry(); newDay.Date = entry.Created.Date; newDay.Entries.Add(entry); newDay.Save(); data.IncrementEntryChange(); BlogXUtils.PingWeblogsCom(); } entryTitle.Text = ""; entryAbstract.Text = ""; entryContent.Text = ""; entryCategories.Text = ""; Response.Redirect("default.aspx", false); } }
public void RenderRSS(string output, IList entries, int start, int end) { RssChannel channel = MakeChannel(); for (int i = start; i < end; i++) { int idx = entries.Count - i - 1; if (idx < 0) { continue; } DayEntry d = (DayEntry)entries [idx]; Hashtable substitutions = new Hashtable(); FillEntrySubstitutions(substitutions, d, config.BlogWebDirectory, false); StringWriter description = new StringWriter(new StringBuilder(d.Body.Length)); Translate(d.Body, description, substitutions); StringWriter sw = new StringWriter(new StringBuilder(d.Body.Length)); Render(sw, entries, idx, "", false, false); RssItem item = new RssItem(); item.Author = config.Author; item.Description = description.ToString(); item.Guid = new RssGuid(); item.Guid.Name = config.BlogWebDirectory + d.PermaLink; item.Link = new Uri(item.Guid.Name); item.Guid.PermaLink = DBBool.True; item.PubDate = d.Date.ToUniversalTime(); if (d.Caption == "") { Console.WriteLine("No caption for: " + d.DateCaption); d.Caption = d.DateCaption; } item.Title = d.Caption; channel.Items.Add(item); } FileStream o = CreateFile(output); XmlTextWriter xtw = new XmlTextWriter(o, new UTF8Encoding(false)); Rss20Writer w = new Rss20Writer(xtw); w.Write(channel); w.Close(); }
string GetCategoryPaths(DayEntry d, string blog_base) { string[] paths = d.Category.Split('/'); // It'll be more common for no category to be used -- the "/" category -- // which requires 24 characters. Optimize for the common case. StringBuilder cat_paths = new StringBuilder(32); // Skip the last paths entry, as it's the "" string for (int i = 0; i < paths.Length - 1; ++i) { string parent = string.Join("/", paths, 0, i + 1) + "/"; cat_paths.AppendFormat("<a href=\"{0}archive{1}\">{2}/</a>", blog_base, parent, paths [i]); } return(cat_paths.ToString()); }
public void SerializeNewEntry() { FileStream fileStream = null; Entry entry = new Entry(); entry.Initialize(); entry.Title = "The Title"; entry.Content = "Content"; entry.EntryId = Guid.NewGuid().ToString(); DayEntry dayEntry = new DayEntry(); dayEntry.Initialize(); dayEntry.Entries.Add(entry); try { fileStream = FileUtils.OpenForWrite( Path.Combine(CONTENT_DIRECTORY_PATH, dayEntry.FileName)); if (fileStream == null) { Assert.Fail("Unable to create stream {0}", Path.Combine(CONTENT_DIRECTORY_PATH, dayEntry.FileName)); } else { XmlSerializer ser = new XmlSerializer(typeof(DayEntry), new Type[] { typeof(Entry) }); using (StreamWriter writer = new StreamWriter(fileStream)) { ser.Serialize(writer, dayEntry); } using (StreamReader reader = new StreamReader(Path.Combine(CONTENT_DIRECTORY_PATH, dayEntry.FileName))) { Console.WriteLine(reader.ReadToEnd()); } } } finally { if (fileStream != null) { fileStream.Close(); } } }
public void SerializeNewEntry() { FileStream fileStream = null; Entry entry = new Entry(); entry.Initialize(); entry.Title = "The Title"; entry.Content = "Content"; entry.EntryId = Guid.NewGuid().ToString(); DayEntry dayEntry = new DayEntry(); dayEntry.Initialize(); dayEntry.Entries.Add(entry); try { fileStream = FileUtils.OpenForWrite( Path.Combine(CONTENT_DIRECTORY_PATH, dayEntry.FileName)); if(fileStream == null) { Assert.Fail("Unable to create stream {0}", Path.Combine(CONTENT_DIRECTORY_PATH, dayEntry.FileName)); } else { XmlSerializer ser = new XmlSerializer(typeof(DayEntry), new Type[]{typeof(Entry)}); using (StreamWriter writer = new StreamWriter(fileStream)) { ser.Serialize(writer, dayEntry); } using(StreamReader reader = new StreamReader(Path.Combine(CONTENT_DIRECTORY_PATH, dayEntry.FileName))) { Console.WriteLine(reader.ReadToEnd()); } } } finally { if(fileStream != null) { fileStream.Close(); } } }
// A category is always of the form "/((.+)/)*", e.g. /, /foo/, /foo/bar/ // Add the DayEntry to its category and all parent categories void AddCategory(Hashtable hash, DayEntry day) { string category = day.Category; do { IList entries = (IList)hash [category]; if (entries == null) { entries = new ArrayList(); hash [category] = entries; } entries.Add(day); int n = category.Length > 2 ? category.LastIndexOf('/', category.Length - 2) : -1; category = (n == -1) ? null : category.Substring(0, n + 1); } while (category != null && category.Length > 0); }
string CreateEntryIndex(IList entries, int start, int end) { StringBuilder sb = new StringBuilder(); sb.Append("<ul class=\"blog-index\">\n"); for (int i = start; i < end; ++i) { int idx = entries.Count - i - 1; if (idx < 0) { break; } DayEntry d = (DayEntry)entries [idx]; sb.AppendFormat(" <li class=\"blog-index-item\"><a href=\"#{0}\">{1}</a></li>\n", d.Id, d.Caption); } sb.Append("</ul>\n"); return(sb.ToString()); }
public string CreateEntry(Entry entry, string username, string password) { if (SiteSecurity.Login(username, password).Role != "admin") { throw new Exception("Invalid Password"); } bool added = false; // ensure that the entryId was filled in // if (entry.EntryId == null || entry.EntryId.Length == 0) { entry.EntryId = Guid.NewGuid().ToString(); } foreach (DayEntry day in data.Days) { if (day.Date == entry.Created.Date) { added = true; day.Load(); day.Entries.Add(entry); day.Save(); data.IncrementEntryChange(); BlogXUtils.PingWeblogsCom(); break; } } if (!added) { DayEntry newDay = new DayEntry(); newDay.Date = entry.Created.Date; newDay.Entries.Add(entry); newDay.Save(); data.IncrementEntryChange(); BlogXUtils.PingWeblogsCom(); } return(entry.EntryId); }
void CreateEntries() { //figure how many days System.DateTime today = System.DateTime.Today.Date; int totalDays = (int)(today - releaseDate).TotalDays;//does not include today (today's sales won't be final, so ignore) salesData = new DayEntry[totalDays]; //set date value for each entry for(int i = 0; i < salesData.Length; i++) { salesData[i] = new DayEntry(); salesData[i].date = System.DateTime.Today.Date.AddDays(0 - (i + 1)); //set date from newest to oldest (ending with release date) } }
public static string GetEntryPath(string blog_base, DayEntry d) { return string.Format ("{0}archive{1}{2:yyyy}/", blog_base, d.Category, d.Date); }
public static DayEntry Load(Blog blog, string file) { DayEntry de = null; try { de = new DayEntry (blog, file); } catch (Exception e) { if (blog.Verbose) Console.WriteLine ("Failed to load file: {0}. Reason: {1}", file, e.Message); } return de; }
string GetCategoryPaths(DayEntry d, string blog_base) { string[] paths = d.Category.Split ('/'); // It'll be more common for no category to be used -- the "/" category -- // which requires 24 characters. Optimize for the common case. StringBuilder cat_paths = new StringBuilder (32); // Skip the last paths entry, as it's the "" string for (int i = 0; i < paths.Length-1; ++i) { string parent = string.Join ("/", paths, 0, i+1) + "/"; cat_paths.AppendFormat ("<a href=\"{0}archive{1}\">{2}/</a>", blog_base, parent, paths [i]); } return cat_paths.ToString (); }
void FillEntrySubstitutions(Hashtable substitutions, DayEntry d, string blog_base, bool single_entry) { string category_paths = GetCategoryPaths (d, blog_base); string entry_path = LB.GetEntryPath (blog_base, d); substitutions.Add ("@ENTRY_ID@", d.Id); substitutions.Add ("@ENTRY_PATH@", entry_path); substitutions.Add ("@ENTRY_PERMALINK@", d.PermaLink); substitutions.Add ("@ENTRY_CAPTION@", d.Caption); substitutions.Add ("@ENTRY_CAPTION_ENC@", HttpUtility.UrlEncode (d.Caption)); substitutions.Add ("@BASEDIR@", config.BlogWebDirectory); substitutions.Add ("@BASEIMAGES@", config.BlogImageBasedir); substitutions.Add ("@COPYRIGHT@", config.Copyright); substitutions.Add ("@ENTRY_CATEGORY@", d.Category); substitutions.Add ("@ENTRY_DATECAPTION@", d.DateCaption); substitutions.Add ("@ENTRY_CATEGORY_PATHS@", category_paths); substitutions.Add ("@BLOGWEBDIR@", config.BlogWebDirectory); substitutions.Add ("@ENTRY_URL_PERMALINK@", Path.Combine (config.BlogWebDirectory, d.PermaLink)); if (d.Comments && single_entry){ StringWriter rendered_comment = new StringWriter (new StringBuilder (comments.Length)); Translate (comments, rendered_comment, substitutions); substitutions.Add ("@COMMENTS@", rendered_comment.ToString ()); d.RenderedComment = rendered_comment.ToString (); } else substitutions.Add ("@COMMENTS@", ""); }
// A category is always of the form "/((.+)/)*", e.g. /, /foo/, /foo/bar/ // Add the DayEntry to its category and all parent categories void AddCategory(Hashtable hash, DayEntry day) { string category = day.Category; do { IList entries = (IList) hash [category]; if (entries == null) { entries = new ArrayList (); hash [category] = entries; } entries.Add (day); int n = category.Length > 2 ? category.LastIndexOf ('/', category.Length-2) : -1; category = (n == -1) ? null : category.Substring (0, n+1); } while (category != null && category.Length > 0); }