Exemple #1
0
        //Upload the plugin
        private void BT_Upload_Click(object sender, RoutedEventArgs e)
        {
            if (installer == null)
            {
                return;
            }

            LocalZipFile = this.TB_ZipFile.Text;

            if (!File.Exists(LocalZipFile))
            {
                return;
            }

            if (string.IsNullOrEmpty(this.TB_Version.Text))
            {
                System.Windows.Forms.MessageBox.Show("Entrer tout les champs !", "Agenda-Virtuel", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            string pluginUrl = LocalZipFile.SplitAndGetLastPart(@"\").Replace(" ", "");

            StoreItem = new PluginStoreItem(installer.ThePlugin.name, this.TB_Description.Text, pluginUrl, userAccount, userAccount, true, this.TB_Version.Text);

            switch (mode)
            {
            case UploadMode.Normal:
                PluginStoreManager.InsertPlugin(StoreItem, LocalZipFile);
                break;
            }

            this.DialogResult = true;
            this.Close();
        }
        /// <summary>
        /// Get available plugins from the store. This function is asynchronous
        /// </summary>
        /// <returns>Task object</returns>
        public static async Task LoadAllStoreAsync()
        {
            if (Plugins == null)
            {
                Plugins = new List <PluginStoreItem>();
            }
            else
            {
                Plugins.Clear();
            }

            FormUrlEncodedContent elements = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair <string, string>("mode", "select")
            });

            XElement json = await Functions.SendPostRequest(elements, PHPpluginstoreURL);

            foreach (XElement xe in json.Elements())
            {
                string name        = xe.Element("Name")?.Value;
                string description = xe.Element("Description")?.Value;
                string url         = xe.Element("Url")?.Value;
                string developer   = xe.Element("Developer")?.Value;
                bool   isVirus     = Convert.ToBoolean(Convert.ToInt32(xe.Element("IsVirus")?.Value));
                string version     = xe.Element("Version")?.Value;

                PluginStoreItem currPlugin = new PluginStoreItem(name, description, url, developer, developer, isVirus, version);
                Plugins.Add(currPlugin);
            }

            Plugins.Reverse();
        }
        /// <summary>
        /// Upload a plugin in the store
        /// </summary>
        /// <param name="plugin">Plugin (store item) to upload</param>
        /// <param name="localZipPath">Zip file of plugin to upload</param>
        public static void InsertPlugin(PluginStoreItem plugin, string localZipPath)
        {
            if (!IsUploadable(plugin, localZipPath))
            {
                return;
            }

            StoreRequest("insert", plugin, localZipPath);
            Plugins.Add(plugin);
        }
 /// <summary>
 /// Delete a plugin from the store.
 /// </summary>
 /// <param name="plugin">Plugin to delete</param>
 public static void DeletePlugin(PluginStoreItem plugin)
 {
     RequestHelper.PostMultipart
     (
         PHPpluginstoreURL,
         new Dictionary <string, object>()
     {
         { "mode", "delete" },
         { "Name", plugin.Name }
     });
 }
        /// <summary>
        /// Determine if there is no error or any problem to upload plugin in the store
        /// </summary>
        /// <param name="plugin">Plugin store item to test</param>
        /// <param name="localZipPath">Zip file of plugin to test</param>
        /// <returns>Return true if there is no problem to upload this plugin</returns>
        private static bool IsUploadable(PluginStoreItem plugin, string localZipPath)
        {
            if (plugin == null || string.IsNullOrEmpty(plugin.DownloadUrl) || !File.Exists(localZipPath))
            {
                return(false);
            }

            if (Plugins.Find(x => x.Name == plugin.Name) != null)
            {
                System.Windows.Forms.MessageBox.Show("Un plugin du même nom éxiste déjà dans le store.", plugin.Name, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
                return(false);
            }

            return(true);
        }
        private static string StoreRequest(string mode, PluginStoreItem plugin, string localZipPath)
        {
            string zipName = localZipPath.SplitAndGetLastPart(@"\");
            string result  = RequestHelper.PostMultipart
                             (
                PHPpluginstoreURL,
                new Dictionary <string, object>()
            {
                { "mode", mode },
                { "user", UserID },
                { "Name", plugin.Name },
                { "Description", plugin.Description },
                { "Version", plugin.Version },
                { "zipFile", new FormFile()
                  {
                      Name = zipName, ContentType = "application/zip", FilePath = localZipPath
                  } },
            });

            return(result);
        }
        /// <summary>
        /// Update a plugin.
        /// </summary>
        /// <param name="oldItem">Old version of plugin</param>
        /// <param name="newItem">New version of plugin</param>
        /// <param name="_localZipFile">Zip file of new version of plugin</param>
        public static void UpdatePlugin(PluginStoreItem oldItem, PluginStoreItem newItem, string _localZipFile)
        {
            PluginStoreItem plugin = new PluginStoreItem(oldItem.Name, newItem.Description, oldItem.DownloadUrl, newItem.DeveloperName, newItem.UserAccount, true, newItem.Version);

            StoreRequest("update", plugin, _localZipFile);
        }