コード例 #1
0
        public JMMPluginResult SetPluginOrder(List <Guid> order, JMMPluginTypes type)
        {
            if (!pluginorder.ContainsKey(type))
            {
                return new JMMPluginResult {
                           Error = "There is no plugin of type " + type + " loaded", Ok = false
                }
            }
            ;
            Dictionary <Guid, int> d = pluginorder[type];
            int xx = 0;

            foreach (Guid g in order)
            {
                d[g] = xx;

                JMMPluginPreferences ll = Settings.Default.Preferences.First(a => a.Guid == g);
                if (!ll.Orders.ContainsKey(type))
                {
                    ll.Orders.Add(type, xx);
                }
                else
                {
                    ll.Orders[type] = xx;
                }
                xx++;
            }
            Settings.Default.Save();
            return(new JMMPluginResult()
            {
                Ok = true
            });
        }
    }
コード例 #2
0
        public JMMPluginResult <List <JMMPlugin> > GetPlugins()
        {
            JMMPluginResult <List <JMMPlugin> > result = new JMMPluginResult <List <JMMPlugin> >();

            result.Result = new List <JMMPlugin>();
            try
            {
                foreach (IJMMPluginCommon p in plugins.List)
                {
                    JMMPlugin j = new JMMPlugin();
                    j.Guid = p.Guid;
                    j.Name = p.Name;
                    j.SupportedPluginTypes   = p.SupportedPluginTypes;
                    j.SupportedDownloadTypes = p.SupportedDownloadTypes;
                    JMMPluginPreferences prefs = Settings.Default.Preferences.First(a => a.Guid == p.Guid);
                    j.PluginPreferencesDescriptions = prefs.Preferences;
                    j.PreferencesValid = prefs.Valid;
                    result.Result.Add(j);
                }
                result.Ok = true;
            }
            catch (Exception e)
            {
                result.Result = null;
                result.Error  = e.ToString();
                result.Ok     = false;
            }
            return(result);
        }
コード例 #3
0
        public JMMPluginResult <List <JMMPluginDownloadLink> > News(int limit = 50)
        {
            JMMPluginResult <List <JMMPluginDownloadLink> > res = new JMMPluginResult <List <JMMPluginDownloadLink> >();

            res.Result = new List <JMMPluginDownloadLink>();
            res.Ok     = true;
            Dictionary <Guid, int> d = pluginorder[JMMPluginTypes.News].OrderBy(a => a.Value).ToDictionary(a => a.Key, a => a.Value);

            foreach (Guid g in d.Keys.ToList())
            {
                JMMPluginPreferences prefs = Settings.Default.Preferences.First(a => a.Guid == g);
                if (!prefs.Enabled)
                {
                    d.Remove(g);
                }
            }
            if (d.Count == 0)
            {
                return new JMMPluginResult <List <JMMPluginDownloadLink> > {
                           Error = "There is no news plugins active", Ok = false
                }
            }
            ;
            int[] limits = new int[d.Count];
            int   bs     = limit / d.Count;

            for (int x = 0; x < d.Count; x++)
            {
                limits[x] = bs;
            }
            int left = d.Count - bs;

            for (int x = 0; x < left; x++)
            {
                limits[x]++;
            }
            int cnt = 0;

            foreach (Guid g in d.Keys)
            {
                IJMMPluginNews se = plugins.List.FirstOrDefault(a => a.Guid == g) as IJMMPluginNews;
                if (se != null)
                {
                    JMMPluginResult <List <JMMPluginDownloadLink> > m = se.GetNews(limits[cnt]);
                    if (!m.Ok)
                    {
                        return(m);
                    }
                    res.Result.AddRange(m.Result);
                }
                cnt++;
            }
            res.Result = res.Result.OrderByDescending(a => a.Date).ToList();
            return(res);
        }
コード例 #4
0
 private static void CheckPreferences()
 {
     foreach (IJMMPluginCommon j in plugins.List)
     {
         JMMPluginPreferences pp = Settings.Default.Preferences.FirstOrDefault(a => a.Guid == j.Guid);
         if (pp == null)
         {
             pp             = new JMMPluginPreferences();
             pp.Guid        = j.Guid;
             pp.Orders      = new Dictionary <JMMPluginTypes, int>();
             pp.Preferences = j.GetPreferencesDescriptions();
             pp.Valid       = false;
             pp.Enabled     = true;
             Settings.Default.Preferences.Add(pp);
         }
         foreach (JMMPluginTypes p in EnumerateTypes(j.SupportedPluginTypes))
         {
             AddOrderToPreferences(j.Guid, pp, p);
         }
     }
     foreach (JMMPluginTypes p in Enum.GetValues(typeof(JMMPluginTypes)))
     {
         List <Guid> order = pluginorder[p].OrderBy(a => a.Value).Select(a => a.Key).ToList();
         int         x     = 0;
         foreach (Guid g in order)
         {
             pluginorder[p][g] = x;
             x++;
         }
     }
     foreach (IJMMPluginCommon j in plugins.List)
     {
         JMMPluginPreferences pp = Settings.Default.Preferences.First(a => a.Guid == j.Guid);
         foreach (JMMPluginTypes p in EnumerateTypes(j.SupportedPluginTypes))
         {
             int val = pluginorder[p][j.Guid];
             if (!pp.Orders.ContainsKey(p))
             {
                 pp.Orders.Add(p, val);
             }
             else
             {
                 pp.Orders[p] = val;
             }
         }
         if (pp.Valid)
         {
             List <JMMPluginPreferenceValue> v = pp.Preferences.Cast <JMMPluginPreferenceValue>().ToList();
             pp.Valid = j.SetPreferences(v).Ok;
         }
         Settings.Default.Save();
     }
     Settings.Default.Save();
 }
コード例 #5
0
        public JMMPluginResult <List <JMMPluginDownloadLink> > Search(string text, Guid pluginguid)
        {
            IJMMPluginSearch     se    = plugins.List.FirstOrDefault(a => a.Guid == pluginguid) as IJMMPluginSearch;
            JMMPluginPreferences prefs = Settings.Default.Preferences.First(a => a.Guid == pluginguid);

            if ((se == null) || (!prefs.Enabled))
            {
                return new JMMPluginResult <List <JMMPluginDownloadLink> > {
                           Error = "The search plugin asked is not active", Ok = false
                }
            }
            ;
            return(se.Search(text));
        }
コード例 #6
0
        public JMMPluginResult <List <JMMPluginDownloadLink> > News(Guid pluginguid, int limit = 50)
        {
            IJMMPluginNews       se    = plugins.List.FirstOrDefault(a => a.Guid == pluginguid) as IJMMPluginNews;
            JMMPluginPreferences prefs = Settings.Default.Preferences.First(a => a.Guid == pluginguid);

            if ((se == null) || (!prefs.Enabled))
            {
                return new JMMPluginResult <List <JMMPluginDownloadLink> > {
                           Error = "The news plugin asked is not active", Ok = false
                }
            }
            ;
            return(se.GetNews(limit));
        }
    }
コード例 #7
0
        public JMMPluginResult <List <JMMPluginDownloadLink> > Search(string text, JMMPluginDownloadTypes type)
        {
            JMMPluginResult <List <JMMPluginDownloadLink> > res = new JMMPluginResult <List <JMMPluginDownloadLink> >();

            res.Result = new List <JMMPluginDownloadLink>();
            res.Ok     = true;
            Dictionary <Guid, int> d = pluginorder[JMMPluginTypes.Search].OrderBy(a => a.Value).ToDictionary(a => a.Key, a => a.Value);

            foreach (Guid g in d.Keys.ToList())
            {
                JMMPluginPreferences prefs = Settings.Default.Preferences.First(a => a.Guid == g);

                if (!prefs.Enabled)
                {
                    d.Remove(g);
                }
                IJMMPluginSearch se = plugins.List.FirstOrDefault(a => a.Guid == g) as IJMMPluginSearch;
                if ((se == null) || (se.SupportedDownloadTypes & type) == 0)
                {
                    d.Remove(g);
                }
            }
            if (d.Count == 0)
            {
                return new JMMPluginResult <List <JMMPluginDownloadLink> > {
                           Error = "There is no search plugins active or matching the download types", Ok = false
                }
            }
            ;
            foreach (Guid g in d.Keys)
            {
                IJMMPluginSearch se = plugins.List.FirstOrDefault(a => a.Guid == g) as IJMMPluginSearch;

                if (se != null)
                {
                    JMMPluginResult <List <JMMPluginDownloadLink> > m = se.Search(text);
                    if (!m.Ok)
                    {
                        return(m);
                    }
                    res.Result.AddRange(m.Result);
                }
            }
            return(res);
        }
    }
コード例 #8
0
        public JMMPluginPreferenceResult SetPreferences(Guid pluginguid, List <JMMPluginPreferenceValue> values, bool enabled)
        {
            JMMPluginPreferenceResult res = plugins.List.First(a => a.Guid == pluginguid).SetPreferences(values);

            if (res.Ok)
            {
                JMMPluginPreferences ll = Settings.Default.Preferences.First(a => a.Guid == pluginguid);
                foreach (JMMPluginPreferenceValue v in values)
                {
                    JMMPluginPreferenceDescription pd = ll.Preferences.First(a => a.Name == v.Name);
                    pd.Value = v.Value;
                }
                ll.Valid   = true;
                ll.Enabled = enabled;
                Settings.Default.Save();
            }
            return(res);
        }
コード例 #9
0
        public JMMPluginResult Download(Guid pluginguid, JMMPluginDownloadLink link)
        {
            IJMMPluginDownload   seq   = plugins.List.FirstOrDefault(a => a.Guid == pluginguid) as IJMMPluginDownload;
            JMMPluginPreferences prefs = Settings.Default.Preferences.First(a => a.Guid == pluginguid);

            if ((seq == null) || (!prefs.Enabled))
            {
                return new JMMPluginResult <List <JMMPluginDownloadLink> > {
                           Error = "The download plugin asked is not active", Ok = false
                }
            }
            ;
            IJMMPluginLinkDownload pdownload = plugins.List.FirstOrDefault(a => a.Guid == link.PluginGuid) as IJMMPluginLinkDownload;

            if (pdownload != null)
            {
                JMMPluginPreferences prefss = Settings.Default.Preferences.First(a => a.Guid == link.PluginGuid);

                if (!prefss.Enabled)
                {
                    pdownload = null;
                }
            }
            if (pdownload == null)
            {
                return new JMMPluginResult {
                           Error = "The link originator plugin is not active anymore, unable to download", Ok = false
                }
            }
            ;
            JMMPluginDownload down = pdownload.GetDownload(link);

            if (down.Data == null)
            {
                return new JMMPluginResult {
                           Error = "Unable to download archive", Ok = false
                }
            }
            ;
            return(seq.Download(down));
        }
    }
}
コード例 #10
0
        private static void AddOrderToPreferences(Guid guid, JMMPluginPreferences pp, JMMPluginTypes p)
        {
            int val = Int32.MaxValue;

            if (pp.Orders.ContainsKey(p))
            {
                val = pp.Orders[p];
            }
            if (!pluginorder.ContainsKey(p))
            {
                pluginorder.Add(p, new Dictionary <Guid, int>());
            }
            Dictionary <Guid, int> kk = pluginorder[p];

            if (!kk.ContainsKey(guid))
            {
                kk.Add(guid, val);
            }
            else
            {
                kk[guid] = val;
            }
        }
コード例 #11
0
        public JMMPluginResult Download(JMMPluginDownloadLink link)
        {
            JMMPluginResult res = new JMMPluginResult();

            res.Ok = true;
            Dictionary <Guid, int> d = pluginorder[JMMPluginTypes.Download].OrderBy(a => a.Value).ToDictionary(a => a.Key, a => a.Value);

            foreach (Guid g in d.Keys.ToList())
            {
                JMMPluginPreferences prefs = Settings.Default.Preferences.First(a => a.Guid == g);
                if (!prefs.Enabled)
                {
                    d.Remove(g);
                }

                IJMMPluginDownload se = plugins.List.FirstOrDefault(a => a.Guid == g) as IJMMPluginDownload;
                if ((se == null) || (se.SupportedDownloadTypes & link.Type) == 0)
                {
                    d.Remove(g);
                }
            }
            if (d.Count == 0)
            {
                return new JMMPluginResult {
                           Error = "There is no download plugins active or matching the download types", Ok = false
                }
            }
            ;
            Guid m = d.First().Key;
            IJMMPluginLinkDownload pdownload = plugins.List.FirstOrDefault(a => a.Guid == link.PluginGuid) as IJMMPluginLinkDownload;

            if (pdownload != null)
            {
                JMMPluginPreferences prefss = Settings.Default.Preferences.First(a => a.Guid == link.PluginGuid);

                if (!prefss.Enabled)
                {
                    pdownload = null;
                }
            }
            if (pdownload == null)
            {
                return new JMMPluginResult {
                           Error = "The link originator plugin is not active anymore, unable to download", Ok = false
                }
            }
            ;

            JMMPluginDownload down = pdownload.GetDownload(link);

            if (down.Data == null)
            {
                return new JMMPluginResult {
                           Error = "Unable to download archive", Ok = false
                }
            }
            ;
            IJMMPluginDownload seq = plugins.List.FirstOrDefault(a => a.Guid == m) as IJMMPluginDownload;

            if (seq == null)
            {
                return new JMMPluginResult {
                           Error = "Unable to find download plugin", Ok = false
                }
            }
            ;
            return(seq.Download(down));
        }