Ejemplo n.º 1
0
        public void TestMethod1()
        {
            ServeurPlugin sp = new ServeurPlugin();

            PluginModel p = new PluginModel("PluginTest3", "Test3", "7.1.3.5", "Ceci est un test", "/test", true);
            IList<String> l = new List<String>();
            l.Add("contenudufichier");
            File.WriteAllLines("Test3", l);
            sp.AddPlugin(p, File_DAL.getPlugin("Test3"));
        }
Ejemplo n.º 2
0
        public bool AddPlugin(PluginModel plug, MemoryStream memStream)
        {
            bool b;
            //Création du nom de dossier du plugin
            String rep = plug.Name + Path.DirectorySeparatorChar;
            plug.Id = plug.Name + "_" + plug.Version;
            plug.Location = plug.Name+"_"+plug.Version;

            lock (lockPlugins)
            {
                if (plug.Actif)
                {
                    foreach (PluginModel p in plugins)
                    {
                        if (p.Name == plug.Name)
                            p.Actif = false;
                    }
                }

                if (!Directory.Exists(Plugin_path))
                {
                    Directory.CreateDirectory(Plugin_path);
                }

                if (!Directory.Exists(Plugin_path + rep))
                {
                    Directory.CreateDirectory(Plugin_path + rep);
                }

                if (!File.Exists(Plugin_path + rep + plug.Location))
                {
                    plugins.Add(plug);

                    File_DAL.putPlugin(memStream, Plugin_path + rep + plug.Location);

                    XML_DAL.StorePlugins(plugins, XML_path + XML_fileName);
                    b = true;
                }
                else { b = false; }

            }
            return b;
        }
Ejemplo n.º 3
0
        public void TestDownloadPlugin()
        {
            ServeurPlugin sp = new ServeurPlugin();

            PluginModel p = new PluginModel("id", "Test3", "7.1.3.5", "Ceci est un test", "/test", true);
            IList<String> l = new List<String>();
            l.Add("totovaalaplage");
            File.WriteAllLines("testDownload", l);
            MemoryStream initStream = File_DAL.getPlugin("testDownload");
            sp.AddPlugin(p, initStream);

            MemoryStream stream = sp.DownloadPlugin("Test3_7.1.3.5");
            Assert.AreEqual(initStream.Length, stream.Length);
            int count = 0;
            while (count < stream.Length)
            {
                Assert.AreEqual(initStream.ReadByte(), stream.ReadByte());
                count++;
            }
        }
Ejemplo n.º 4
0
        public IEnumerable<PluginModel> GetPluginsInfo()
        {
            return this.ListeMenu.Select<IOgpMenu, PluginModel>(menu =>
            {
                var aih = new AssemblyInfoHelper(menu.GetType());
                PluginModel plugin = new PluginModel();
                plugin.Name = aih.Title;
                plugin.Description = aih.Description;
                plugin.Version = aih.AssemblyVersion;
                plugin.Location = aih.FilePath;

                return plugin;
            });
        }
Ejemplo n.º 5
0
        private void upload()
        {
            // Configure open file dialog box
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            dlg.Title = "Choose the plugin to upload";
            dlg.FileName = "plugin" + PLUGIN_EXTENSION; // Default file name
            dlg.DefaultExt = PLUGIN_EXTENSION; // Default file extension
            dlg.Filter = PLUGIN_TYPE_DESCRIPTION; // Filter files by extension

            // Show open file dialog box
            Nullable<bool> result = dlg.ShowDialog();

            // Process open file dialog box results
            if (result == true)
            {
                // Open document
                string filepath = dlg.FileName;
                string dstFilepath  = Path.GetFullPath(filepath);

                // retrieve assembly info
                AssemblyInfoHelper asm = new AssemblyInfoHelper(dstFilepath);
                PluginModel pm = new PluginModel();
                pm.Name = asm.Title;
                pm.Version = asm.AssemblyVersion;
                pm.Description = asm.Description;
                pm.Actif = true;
                // retrieve dll file
                MemoryStream ms = new MemoryStream(File.ReadAllBytes(dstFilepath));

                // run in background
                var background = new BackgroundWorker();
                background.DoWork += (DoWorkEventHandler)((sender, e) =>
                {
                    Exception error = WcfHelper.Execute<IServicePlugin>(client =>
                    {
                        result = client.AddPlugin(pm, ms);
                    });

                    if (error != null)
                    {
                        throw new OgpPluginException("Erreur de upload", error);
                    }
                });

                background.RunWorkerCompleted += (RunWorkerCompletedEventHandler)((sender, e) =>
                {
                    new WPFMessageBoxService().ShowInformation("Plugin uploaded.");
                });
                background.RunWorkerAsync();
            }
        }
Ejemplo n.º 6
0
 private PluginModel getNewVersion(PluginModel plug)
 {
     return plugins.Where(p => p.Name == plug.Name && p.Actif && p.Version != plug.Version)
         .FirstOrDefault();
 }
Ejemplo n.º 7
0
 public bool UpdatePlugin(PluginModel p, MemoryStream memStream)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 8
0
 public PluginContext(PluginModel plugin)
 {
     RawData = plugin;
     ProgressBarStatus = Visibility.Hidden;
 }