示例#1
0
        /// <summary>
        /// Deletes a widget.
        /// </summary>
        /// <param name="id"></param>
        public static void Delete(string id)
        {
            Query q = ObjectStore.CreateQuery();
            q.AndWhere(ObjectStore.Columns.Name, id);
            q.AndWhere(ObjectStore.Columns.ContentType, "xml/widget");
            ObjectStoreCollection osc = new ObjectStoreCollection();
            osc.LoadAndCloseReader(q.ExecuteReader());
            if (osc.Count > 1)
                throw new Exception("More than one item matched id/name ");
            else if (osc.Count > 0)
                ObjectStore.Destroy(osc[0].Id);

            Reset();
        }
示例#2
0
        public static void RemoveFeedData()
        {
            ObjectStoreCollection osc = new ObjectStoreCollection();
            Query q = ObjectStore.CreateQuery();

            q.AndWhere(ObjectStore.Columns.ContentType, "feed/xml");
            osc.LoadAndCloseReader(q.ExecuteReader());

            foreach (ObjectStore os in osc)
            {
                ObjectStore.Destroy(os.Id);
            }

            ZCache.RemoveCache("Feed-Objects");
        }
示例#3
0
        /// <summary>
        /// Gets all the widgets from the ObjectStore (match ContentType = "xml/widget"
        /// </summary>
        /// <returns></returns>
        public static List <Widget> FetchAll()
        {
            List <Widget> the_Widgets = ZCache.Get <List <Widget> >(cacheKey);

            if (the_Widgets == null)
            {
                ObjectStoreCollection osc = new ObjectStoreCollection();
                Query oquery = ObjectStore.CreateQuery();
                oquery.AndWhere(ObjectStore.Columns.ContentType, "xml/widget");
                osc.LoadAndCloseReader(oquery.ExecuteReader());

                the_Widgets = new List <Widget>(osc.Count);
                foreach (ObjectStore os in osc)
                {
                    try
                    {
                        Widget widget = ObjectManager.ConvertToObject(os.Data, Type.GetType(os.Type)) as Widget;

                        if (widget != null)
                        {
                            the_Widgets.Add(widget);
                        }
                        else
                        {
                            Log.Warn("Widgets",
                                     "The widget of type {0} (Widget Id:{1}, ObjetStore id: {2}) could not be loaded. Please check with the widget developer for help",
                                     os.Type, os.Name, os.Id);
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Error("Widget",
                                  "An exception was raised invoking the following widget type {0}. Exception: {1} Details: {2}",
                                  os.Type, ex.Message, ex.StackTrace);
                    }
                }

                ZCache.InsertCache(cacheKey, the_Widgets, 120);
            }
            return(the_Widgets);
        }
示例#4
0
        /// <summary>
        /// Deletes a widget.
        /// </summary>
        /// <param name="id"></param>
        public static void Delete(string id)
        {
            Query q = ObjectStore.CreateQuery();

            q.AndWhere(ObjectStore.Columns.Name, id);
            q.AndWhere(ObjectStore.Columns.ContentType, "xml/widget");
            ObjectStoreCollection osc = new ObjectStoreCollection();

            osc.LoadAndCloseReader(q.ExecuteReader());
            if (osc.Count > 1)
            {
                throw new Exception("More than one item matched id/name ");
            }
            else if (osc.Count > 0)
            {
                ObjectStore.Destroy(osc[0].Id);
            }


            Reset();
        }
示例#5
0
        public static Dictionary<Guid, Feed> GetFeeds()
        {
            Dictionary<Guid, Feed> feeds = ZCache.Get<Dictionary<Guid, Feed>>("Feed-Objects");
            if(feeds == null)
            {
                feeds = new Dictionary<Guid, Feed>();
                ObjectStoreCollection osc = new ObjectStoreCollection();
                Query q = ObjectStore.CreateQuery();
                q.AndWhere(ObjectStore.Columns.ContentType, "feed/xml");
                osc.LoadAndCloseReader(q.ExecuteReader());

                foreach(ObjectStore os in osc)
                {
                    Feed feed = ObjectManager.ConvertToObject<Feed>(os.Data);
                    feeds.Add(feed.Id,feed);
                }

                ZCache.InsertCache("Feed-Objects", feeds,300);
            }

            return feeds;
        }
示例#6
0
        public static Dictionary <Guid, Feed> GetFeeds()
        {
            Dictionary <Guid, Feed> feeds = ZCache.Get <Dictionary <Guid, Feed> >("Feed-Objects");

            if (feeds == null)
            {
                feeds = new Dictionary <Guid, Feed>();
                ObjectStoreCollection osc = new ObjectStoreCollection();
                Query q = ObjectStore.CreateQuery();
                q.AndWhere(ObjectStore.Columns.ContentType, "feed/xml");
                osc.LoadAndCloseReader(q.ExecuteReader());

                foreach (ObjectStore os in osc)
                {
                    Feed feed = ObjectManager.ConvertToObject <Feed>(os.Data);
                    feeds.Add(feed.Id, feed);
                }

                ZCache.InsertCache("Feed-Objects", feeds, 300);
            }

            return(feeds);
        }
示例#7
0
        /// <summary>
        ///     Returns a list of all known events based the assemblies in the bin directory
        /// </summary>
        /// <returns></returns>
        public static List <EventDetails> GetEvents()
        {
            var details = ZCache.Get <List <EventDetails> >("EventDetails");

            if (details == null)
            {
                details = new List <EventDetails>();

                ObjectStoreCollection osc =
                    ObjectStoreCollection.FetchByColumn(ObjectStore.Columns.ContentType, "eventdetails/xml");

                // Can't log errors until after Events have been fully loaded
                var warnings = new List <String>();

                var assemblies =
                    Directory.GetFileSystemEntries(HttpRuntime.BinDirectory, "*.dll");
                for (int i = 0; i < assemblies.Length; i++)
                {
                    try
                    {
                        Assembly asm = Assembly.LoadFrom(assemblies[i]);
                        foreach (Type type in asm.GetTypes())
                        {
                            try
                            {
                                if (type.IsClass && !type.IsAbstract && type.IsSubclassOf(typeof(GraffitiEvent)))
                                {
                                    string the_Type = type.AssemblyQualifiedName;
                                    the_Type = the_Type.Substring(0, the_Type.IndexOf(", Version="));
                                    EventDetails ed = null;
                                    foreach (ObjectStore os in osc)
                                    {
                                        if (os.Name == the_Type)
                                        {
                                            ed = LoadEventDetailsFromObjectStore(os);
                                            break;
                                        }
                                    }

                                    if (ed == null)
                                    {
                                        ed = CreateNewEventFromTypeName(the_Type);
                                    }

                                    details.Add(ed);
                                }
                            }
                            catch (Exception exType)
                            {
                                warnings.Add(String.Format("Failed to load type {0}. Reason: {1}", type.FullName, exType.Message));
                            }
                        }
                    }
                    catch (ReflectionTypeLoadException rtle)
                    {
                        if (assemblies[i].IndexOf("DataBuddy") == -1 && assemblies[i].IndexOf("RssToolkit") == -1)
                        {
                            warnings.Add(String.Format("Failed to load assembly {0}. Reason: {1}", assemblies[i], rtle.Message));
                        }
                    }

                    catch (Exception exAssembly)
                    {
                        warnings.Add(String.Format("Failed to load assembly {0}. Reason: {1}", assemblies[i], exAssembly.Message));
                    }
                }

                ZCache.InsertCache("EventDetails", details, 300);

                // Now we can log errors
                foreach (var warning in warnings)
                {
                    Log.Warn("Plugin", warning);
                }
            }

            return(details);
        }
示例#8
0
        public static void RemoveFeedData()
        {
            ObjectStoreCollection osc = new ObjectStoreCollection();
                Query q = ObjectStore.CreateQuery();
                q.AndWhere(ObjectStore.Columns.ContentType, "feed/xml");
                osc.LoadAndCloseReader(q.ExecuteReader());

                foreach (ObjectStore os in osc)
                {
                    ObjectStore.Destroy(os.Id);
                }

                ZCache.RemoveCache("Feed-Objects");
        }
示例#9
0
        /// <summary>
        /// Gets all the widgets from the ObjectStore (match ContentType = "xml/widget"
        /// </summary>
        /// <returns></returns>
        public static List<Widget> FetchAll()
        {
            List<Widget> the_Widgets = ZCache.Get<List<Widget>>(cacheKey);
            if (the_Widgets == null)
            {
                ObjectStoreCollection osc = new ObjectStoreCollection();
                Query oquery = ObjectStore.CreateQuery();
                oquery.AndWhere(ObjectStore.Columns.ContentType, "xml/widget");
                osc.LoadAndCloseReader(oquery.ExecuteReader());

                the_Widgets = new List<Widget>(osc.Count);
                foreach (ObjectStore os in osc)
                {
                    try
                    {
                        Widget widget = ObjectManager.ConvertToObject(os.Data, Type.GetType(os.Type)) as Widget;

                        if (widget != null)
                            the_Widgets.Add(widget);
                        else
                            Log.Warn("Widgets",
                                             "The widget of type {0} (Widget Id:{1}, ObjetStore id: {2}) could not be loaded. Please check with the widget developer for help",
                                             os.Type, os.Name, os.Id);
                    }
                    catch (Exception ex)
                    {
                        Log.Error("Widget",
                                          "An exception was raised invoking the following widget type {0}. Exception: {1} Details: {2}",
                                          os.Type, ex.Message, ex.StackTrace);
                    }
                }

                ZCache.InsertCache(cacheKey, the_Widgets, 120);
            }
            return the_Widgets;
        }