Exemplo n.º 1
0
        /// <summary>
        /// this saves the currently selected addon
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void SaveAddon_Click(object sender, RoutedEventArgs e)
        {
            AddonManager.CurrentAddon = new C3Addon
            {
                Name          = string.Empty,
                Class         = string.Empty,
                Company       = string.Empty,
                Author        = string.Empty,
                Description   = string.Empty,
                AddonCategory = string.Empty,
                Type          = PluginType.SingleGlobalPlugin,
                Effect        = new Effect(),
                ThemeCss      = string.Empty,
                ThemeLangauge = string.Empty,
                IconXml       = ResourceReader.Insatnce.GetResourceText("c3IDE.Templates.Files.icon.svg"),
                CreateDate    = DateTime.Now
            };

            Enum.TryParse <PluginType>(AddonTypeDropdown.SelectedValue.ToString(), out var pluginType);
            var addonCategory = string.IsNullOrWhiteSpace(AddonCategoryDropdown.Text)? "other": AddonCategoryDropdown.Text;

            AddonManager.CurrentAddon.Name          = AddonNameText.Text;
            AddonManager.CurrentAddon.Class         = AddonClassText.Text.Replace(" ", string.Empty).Trim();
            AddonManager.CurrentAddon.Company       = AuthorText.Text.Replace(" ", string.Empty).Trim();
            AddonManager.CurrentAddon.Author        = AuthorText.Text;
            AddonManager.CurrentAddon.AddonId       = IdText.Text.Replace(" ", string.Empty).Trim();
            AddonManager.CurrentAddon.Description   = DescriptionText.Text;
            AddonManager.CurrentAddon.Type          = pluginType;
            AddonManager.CurrentAddon.AddonCategory = addonCategory;
            AddonManager.CurrentAddon.IconXml       = IconXml;
            AddonManager.CurrentAddon.Template      = TemplateFactory.Insatnce.CreateTemplate(pluginType);
            AddonManager.CurrentAddon.LastModified  = DateTime.Now;

            //add version
            AddonManager.CurrentAddon.MajorVersion    = 1;
            AddonManager.CurrentAddon.MinorVersion    = 0;
            AddonManager.CurrentAddon.RevisionVersion = 0;
            AddonManager.CurrentAddon.BuildVersion    = 0;

            //validate addon
            if (!AddonManager.ValidateCurrentAddon())
            {
                NotificationManager.PublishErrorNotification("addon data fields cannot be blank");
                return;
            }

            AddonMetadataGrid.IsEnabled = false;
            await Task.Run(() =>
            {
                IsSaved = true;
                AddonManager.CompileTemplates();
                AddonManager.SaveCurrentAddon();
                AddonManager.LoadAllAddons();
            });

            AddonMetadataGrid.IsEnabled = true;
            AddonManager.LoadAddon(AddonManager.CurrentAddon);
            NotificationManager.PublishNotification($"{AddonManager.CurrentAddon.Name} has been saved successfully");
            WindowManager.ChangeWindow(ApplicationWindows.DashboardWindow);
        }