Exemplo n.º 1
0
        public static Feed AddFeed(Feed feed)
        {
            if (feed.Name == null)
                throw new Exception("Must give the feed a name");

            if (feed.Id == Guid.Empty)
                feed.Id = Guid.NewGuid();

            if (feed.RequestInterval == 0)
                feed.RequestInterval = 60;

               if(feed.Document == null)
               feed.ReLoad();

            ObjectStore os = new ObjectStore();
            os.UniqueId = feed.Id;
            os.Name = "Feed: " + feed.Name;
            os.Data = ObjectManager.ConvertToString(feed);
            os.ContentType = "feed/xml";
            os.Type = typeof (Feed).FullName;
            os.Save();

            ZCache.RemoveCache("Feed-Objects");

            return feed;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates an empty Widget for the given type
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static Widget Create(Type type)
        {
            Widget widget = Activator.CreateInstance(type) as Widget;
            widget.Id = Guid.NewGuid();
            widget.Order = Widgets.FetchByLocation(WidgetLocation.Queue).Count + 1;

            // Get default values if any were configured.
            NameValueCollection defaultValues = widget.GetDefaults();
            if (defaultValues != null && defaultValues.Count > 0)
                widget.SetValues(HttpContext.Current, widget.GetDefaults());

            ObjectStore os = new ObjectStore();
            os.ContentType = "xml/widget";

            string the_Type = type.AssemblyQualifiedName;
            os.Type = the_Type.Substring(0, the_Type.IndexOf(", Version="));
            os.Data = ObjectManager.ConvertToString(widget);
            os.Name = widget.Id.ToString();
            os.UniqueId = widget.Id;
            os.Save();

            Reset();

            return widget;
        }