示例#1
0
        public override bool LoadDll(string folder, PluginDll dll, IList <PluginDll> expandingDlls)
        {
            try
            {
                byte[] buffer = DownloadFromRemoteServer(folder, dll.Name);
                if (buffer == null || buffer.Length == 0)
                {
                    return(false);
                }

                string path = GetPluginPath(folder, dll.Name);
                string ext  = Path.GetExtension(path).ToLower();
                if (!(ext == ".zip" || ext == ".dll" || ext == ".exe"))
                {
                    path = path + ".dll";
                }
                CreateFile(buffer, path);

                if (IsZip(dll.Name) || IsZip(buffer))
                {
                    ParseZipFile(folder, dll, expandingDlls, path);
                }

                return(true);
            }
            catch (Exception ex)
            {
                LogUtils.LogError(ex);
                return(false);
            }
        }
示例#2
0
        protected void ParseZipFile(string folder, PluginDll dll, IList <PluginDll> expandingDlls, string path)
        {
            string zipFolder = GetPluginFolder(folder) + "_zip";

            ZipHelper.UnpackFiles(path, zipFolder);
            foreach (string file in Directory.GetFiles(zipFolder))
            {
                string newFile = Path.Combine(GetPluginFolder(folder), Path.GetFileName(file));
                try
                {
                    File.Copy(file, newFile, true);
                    string    fn     = Path.GetFileNameWithoutExtension(newFile);
                    PluginDll theDll = new PluginDll();
                    theDll.Name    = fn;
                    theDll.Version = dll.Version;
                    if (!PluginLocatorBase.IsInPluginDlls(theDll, expandingDlls))
                    {
                        expandingDlls.Add(theDll);
                    }
                }
                catch { }
            }
            try { Directory.Delete(zipFolder, true); }
            catch { }
        }
示例#3
0
        public static void SavePluginDllVersion(IList <PluginDll> dlls)
        {
            string      nowFile = GetNowConfigPath();
            XmlDocument doc     = new XmlDocument();

            doc.Load(nowFile);
            for (int i = 0; i < dlls.Count; i++)
            {
                PluginDll dll     = dlls[i];
                XmlNode   dllNode = doc.SelectSingleNode(string.Format("Plugins/Plugin/Dlls/add[@name='{0}']",
                                                                       dll.Name));
                if (dllNode != null)
                {
                    XmlAttribute xa = dllNode.Attributes["newVersion"];
                    if (xa == null)
                    {
                        xa = dllNode.OwnerDocument.CreateAttribute("newVersion");
                        dllNode.Attributes.Append(xa);
                    }
                    xa.Value = dll.NewVersion.ToString();
                }
            }
            doc.Save(nowFile);

            string lastFile = GetLastConfigPath();

            try { File.Delete(lastFile); }
            catch { }
            doc.Save(lastFile);
        }
示例#4
0
        public override bool LoadDll(string folder, PluginDll dll, IList<PluginDll> expandingDlls)
        {
            try
            {
                byte[] buffer = DownloadFromRemoteServer(folder, dll.Name);
                if (buffer == null || buffer.Length == 0)
                    return false;

                string path = GetPluginPath(folder, dll.Name);
                string ext = Path.GetExtension(path).ToLower();
                if (!(ext == ".zip" || ext == ".dll" || ext == ".exe"))
                    path = path + ".dll";
                CreateFile(buffer, path);

                if (IsZip(dll.Name) || IsZip(buffer))
                {
                    ParseZipFile(folder, dll, expandingDlls, path);
                }

                return true;
            }
            catch (Exception ex)
            {
                LogUtils.LogError(ex);
                return false;
            }
        }
示例#5
0
 public static bool IsInPluginDlls(PluginDll dll, IList<PluginDll> dlls)
 {
     foreach (PluginDll theDll in dlls)
     {
         if (dll.Name == theDll.Name)
             return true;
     }
     return false;
 }
示例#6
0
 public static bool IsInPluginDlls(PluginDll dll, IList <PluginDll> dlls)
 {
     foreach (PluginDll theDll in dlls)
     {
         if (dll.Name == theDll.Name)
         {
             return(true);
         }
     }
     return(false);
 }
示例#7
0
 public virtual bool LoadDll(string folder, PluginDll dllName, IList <PluginDll> expandingDlls)
 {
     try
     {
         return(true);
     }
     catch (Exception ex)
     {
         LogUtils.LogError(ex);
         return(false);
     }
 }
示例#8
0
        private IList <PluginDll> ParsePluginDlls(XmlNode node)
        {
            List <PluginDll> theDllList = new List <PluginDll>();

            foreach (XmlNode theDll in node.SelectNodes("Dlls/add"))
            {
                PluginDll dll = new PluginDll();
                dll.Name    = theDll.Attributes["name"].Value;
                dll.Version = theDll.Attributes["version"].Value;
                XmlAttribute xa = theDll.Attributes["newVersion"];
                if (xa != null)
                {
                    dll.NewVersion = Convert.ToBoolean(xa.Value.Trim());
                }
                else
                {
                    dll.NewVersion = false;
                }
                theDllList.Add(dll);
            }
            return(theDllList);
        }
示例#9
0
        public override bool LoadDll(string folder, PluginDll dll, IList <PluginDll> expandingDlls)
        {
            try
            {
                string path = GetPluginPath(folder, dll.Name);
                //if (!File.Exists(path))
                //{
                //    path = path + ".dll";
                //}
                if (IsZip(dll.Name))
                {
                    ParseZipFile(folder, dll, expandingDlls, path);
                }

                return(true);
            }
            catch (Exception ex)
            {
                LogUtils.LogError(ex);
                return(false);
            }
        }
示例#10
0
        public override bool LoadDll(string folder, PluginDll dll, IList<PluginDll> expandingDlls)
        {
            try
            {
                string path = GetPluginPath(folder, dll.Name);
                //if (!File.Exists(path))
                //{
                //    path = path + ".dll";
                //}
                if (IsZip(dll.Name))
                {
                    ParseZipFile(folder, dll, expandingDlls, path);
                }

                return true;
            }
            catch (Exception ex)
            {
                LogUtils.LogError(ex);
                return false;
            }
        }
示例#11
0
        private void LoadPluginDll(PluginConfigItem configItem)
        {
            IPluginLocator    theLocator    = PluginLocatorFactory.GetLocator(configItem.QualifiedName.LoadProtocol);
            IList <PluginDll> expandingDlls = new List <PluginDll>();
            IList <PluginDll> _changedList  = new List <PluginDll>();

            for (int i = 0; i < configItem.PluginDlls.Count; i++)
            {
                PluginDll theDll = configItem.PluginDlls[i];
                if (theDll.NewVersion)
                {
                    bool loaded = theLocator.LoadDll(this._pluginContext.PluginContainer.Name, theDll, expandingDlls);

                    if (!loaded)
                    {
                        configItem.Status = PluginConfigItemStatus.LoadPluginDllFailure;
                        break;
                    }
                    else
                    {
                        theDll.NewVersion = false;
                        _changedList.Add(theDll);
                    }
                }
            }

            if (_changedList.Count > 0)
            {
                PluginLocatorBase.SavePluginDllVersion(_changedList);
            }
            foreach (PluginDll expandingDll in expandingDlls)
            {
                if (!PluginLocatorBase.IsInPluginDlls(expandingDll, configItem.PluginDlls))
                {
                    configItem.PluginDlls.Add(expandingDll);
                }
            }
        }
示例#12
0
 protected void ParseZipFile(string folder, PluginDll dll, IList<PluginDll> expandingDlls, string path)
 {
     string zipFolder = GetPluginFolder(folder) + "_zip";
     ZipHelper.UnpackFiles(path, zipFolder);
     foreach (string file in Directory.GetFiles(zipFolder))
     {
         string newFile = Path.Combine(GetPluginFolder(folder), Path.GetFileName(file));
         try
         {
             File.Copy(file, newFile, true);
             string fn = Path.GetFileNameWithoutExtension(newFile);
             PluginDll theDll = new PluginDll();
             theDll.Name = fn;
             theDll.Version = dll.Version;
             if (!PluginLocatorBase.IsInPluginDlls(theDll, expandingDlls))
                 expandingDlls.Add(theDll);
         }
         catch { }
     }
     try { Directory.Delete(zipFolder, true); }
     catch { }
 }
示例#13
0
 public virtual bool LoadDll(string folder, PluginDll dllName, IList<PluginDll> expandingDlls)
 {
     try
     {
         return true;
     }
     catch (Exception ex)
     {
         LogUtils.LogError(ex);
         return false;
     }
 }
示例#14
0
 private IList<PluginDll> ParsePluginDlls(XmlNode node)
 {
     List<PluginDll> theDllList = new List<PluginDll>();
     foreach (XmlNode theDll in node.SelectNodes("Dlls/add"))
     {
         PluginDll dll = new PluginDll();
         dll.Name = theDll.Attributes["name"].Value;
         dll.Version = theDll.Attributes["version"].Value;
         XmlAttribute xa = theDll.Attributes["newVersion"];
         if (xa != null)
         {
             dll.NewVersion = Convert.ToBoolean(xa.Value.Trim());
         }
         else
         {
             dll.NewVersion = false;
         }
         theDllList.Add(dll);
     }
     return theDllList;
 }