Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
        }
    }
        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));
        }