Ejemplo n.º 1
0
        /// <summary>
        /// 增加插件的下载数
        /// </summary>
        public void AddClicks(string pluginName)
        {
            string statisticFile = Path.Combine(PluginGalleryPath, "Statistic.xml");

            pluginStatistics.LoadXML(statisticFile);
            PluginStatistic statistic = pluginStatistics[pluginName];

            if (statistic == null)
            {
                RemotePluginInfoCollection.Clear();
                LoadServerInfo();
                statistic = pluginStatistics[pluginName];
                if (statistic == null)
                {
                    return;
                }
            }

            statistic.Clicks++;
            RemotePluginInfo rinfo = RemotePluginInfoCollection.Find(delegate(RemotePluginInfo info)
            {
                return(info.Directory == pluginName);
            });

            if (rinfo != null)
            {
                rinfo.Clicks = statistic.Clicks;
            }

            pluginStatistics.SaveXML(statisticFile);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 加载远程服务器中的插件信息。如果数据量大的情况下,就不能把数据保存在内存中了。
        /// </summary>
        /// <returns>远程插件信息列表</returns>
        public List <RemotePluginInfo> LoadServerInfo()
        {
            RemotePluginInfo info = null;
            string           statisticFile;
            bool             isFirstTime = true;

            DirectoryInfo dirInfo    = new DirectoryInfo(PluginGalleryPath);
            DirectoryInfo dirSpecial = new DirectoryInfo(Path.Combine(PluginGalleryPath, "Special"));

            if (RemotePluginInfoCollection.Count == 0 || dirInfo.LastWriteTime != LastUpdateTime || dirSpecial.LastWriteTime != SpecialUpdateTime)
            {
                lock (RemotePluginInfoCollection)
                {
                    #region 生成服务器上的插件信息

                    RemotePluginInfoCollection.Clear();

                    statisticFile = Path.Combine(PluginGalleryPath, "Statistic.xml");
                    if (File.Exists(statisticFile))
                    {
                        XmlDocument doc = new XmlDocument();
                        doc.Load(statisticFile);
                        pluginStatistics.LoadXML(doc);
                        isFirstTime = false;
                    }
                    else
                    {
                        pluginStatistics.Clear();
                    }


                    FileInfo[] files = dirInfo.GetFiles("*.zip", SearchOption.AllDirectories);

                    PluginStatistic statistic;
                    List <string>   curPluginList = new List <string>();
                    foreach (FileInfo file in files)
                    {
                        info = new RemotePluginInfo();

                        using (Stream stream = File.OpenRead(file.FullName))
                        {
                            info.LoadXml(ZipUtils.GetFileFromZip(stream, Path.Combine(Path.GetFileNameWithoutExtension(file.Name), "Plugin.xml")));
                            stream.Close();
                            stream.Dispose();
                        }

                        string pluginName = Path.GetFileNameWithoutExtension(file.Name);
                        if (isFirstTime || ((statistic = pluginStatistics[pluginName]) == null))
                        {
                            statistic            = new PluginStatistic();
                            statistic.CreateTime = file.LastWriteTime;
                            statistic.UpdateTime = file.LastWriteTime;
                            statistic.PluginName = pluginName;
                            statistic.Clicks     = 0;
                            pluginStatistics.Add(statistic);
                        }
                        statistic.UpdateTime = file.LastWriteTime;


                        info.UpdateTime = statistic.UpdateTime;
                        info.CreateTime = statistic.CreateTime;

                        info.Clicks    = statistic.Clicks;
                        info.IsSpecial = file.DirectoryName.EndsWith("Special");

                        RemotePluginInfoCollection.Add(info);
                        curPluginList.Add(pluginName);
                    }

                    pluginStatistics.RemoveAll(delegate(PluginStatistic item)
                    {
                        return(!curPluginList.Contains(item.PluginName));
                    });

                    pluginStatistics.ToXml().Save(statisticFile);

                    LastUpdateTime    = dirInfo.LastWriteTime;
                    SpecialUpdateTime = dirSpecial.LastWriteTime;

                    #endregion
                }
            }

            return(RemotePluginInfoCollection);
        }