示例#1
0
        public string UpdateEntry(Entry entry, string username, string password)
        {
            if (SiteSecurity.Login(username, password).Role != "admin")
            {
                throw new Exception("Invalid Password");
            }
            foreach (DayEntry day in data.Days)
            {
                if (day.Date == entry.Created.Date)
                {
                    day.Load();

                    foreach (Entry found in day.Entries)
                    {
                        if (found.EntryId == entry.EntryId)
                        {
                            found.Categories  = entry.Categories;
                            found.Content     = entry.Content;
                            found.Title       = entry.Title;
                            found.Description = entry.Description;
                            found.Modify();

                            day.Save();
                            data.IncrementEntryChange();
                            BlogXUtils.PingWeblogsCom();

                            return(entry.EntryId);
                        }
                    }
                }
            }

            return("not found");
        }
示例#2
0
        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);
            }
        }
示例#3
0
        static int Main(string[] args)
        {
            Console.WriteLine("Radio Data Importer");
            Console.WriteLine("");

            foreach (string arg in args)
            {
                if (arg.Length > 6 && arg.ToLower().StartsWith("/from:"))
                {
                    from = arg.Substring(6).Trim();
                    if (from[0] == '\"' && from[from.Length] == '\"')
                    {
                        from = from.Substring(1, from.Length - 2);
                    }
                }
                else if (arg.Length > 4 && arg.ToLower().StartsWith("/to:"))
                {
                    to = arg.Substring(4).Trim();
                    if (to[0] == '\"' && to[from.Length] == '\"')
                    {
                        to = to.Substring(1, to.Length - 2);
                    }
                }
                else
                {
                    break;
                }
            }

            if (from == null || to == null || from.Length == 0 || to.Length == 0)
            {
                Console.WriteLine("Usage: blogcmd /from:<radio directory> /to:<output directory>");
                Console.WriteLine("");
                return(-1);
            }


            BlogXData.Resolver = new ResolveFileCallback(FileSystemResolver);

            Console.WriteLine("Importing entries...");

            ArrayList tables = new ArrayList();

            XmlDocument   masterDoc = new XmlDocument();
            StringBuilder sb        = new StringBuilder();

            sb.Append("<tables>");

            foreach (FileInfo file in new DirectoryInfo(from).GetFiles("*.xml"))
            {
                XmlDocument entry = new XmlDocument();
                entry.Load(file.FullName);
                sb.Append(entry.FirstChild.NextSibling.OuterXml);
            }
            sb.Append("</tables>");

            masterDoc.Load(new StringReader(sb.ToString()));

            foreach (XmlNode node in masterDoc.FirstChild)
            {
                RadioTable table = new RadioTable();
                table.Name = node.Attributes["name"].Value;
                foreach (XmlNode child in node)
                {
                    switch (child.Name)
                    {
                    case "date":
                        table.Data[child.Attributes["name"].Value] = DateTime.Parse(child.Attributes["value"].Value);
                        break;

                    case "boolean":
                        table.Data[child.Attributes["name"].Value] = bool.Parse(child.Attributes["value"].Value);
                        break;

                    case "string":
                        table.Data[child.Attributes["name"].Value] = child.Attributes["value"].Value;
                        break;

                    case "table":
                        if (child.Attributes["name"].Value == "categories")
                        {
                            foreach (XmlNode catNode in child)
                            {
                                if (catNode.Name == "boolean" && catNode.Attributes["value"].Value == "true")
                                {
                                    if (table.Data.Contains("categories"))
                                    {
                                        table.Data["categories"] = (string)table.Data["categories"] + ";" + catNode.Attributes["name"].Value;
                                    }
                                    else
                                    {
                                        table.Data["categories"] = catNode.Attributes["name"].Value;
                                    }
                                }
                            }
                        }
                        break;
                    }
                }
                tables.Add(table);
            }

            BlogXData data = new BlogXData();

            foreach (RadioTable table in tables)
            {
                DateTime date     = table.When.Date;
                DayEntry dayEntry = null;
                foreach (DayEntry target in data.Days)
                {
                    if (target.Date == date)
                    {
                        dayEntry = target;
                        break;
                    }
                }
                if (dayEntry == null)
                {
                    dayEntry      = new DayEntry();
                    dayEntry.Date = date;
                    data.Days.Add(dayEntry);
                }

                Entry entry = new Entry();
                entry.Created    = table.When;
                entry.Title      = table.Title;
                entry.Content    = table.Text;
                entry.Categories = table.Categories;
                entry.EntryId    = table.UniqueId;
                dayEntry.Entries.Add(entry);
                data.IncrementEntryChange();
            }

            Console.WriteLine("Saving entries...");
            foreach (DayEntry day in data.Days)
            {
                day.Save();
            }

            Console.WriteLine("Creating comment cache...");
            CategoryCache cache = new CategoryCache();

            cache.Ensure(data);

            Console.WriteLine("Creating entry cache...");
            EntryIdCache ecache = new EntryIdCache();

            ecache.Ensure(data);

            return(0);
        }