Beispiel #1
0
        /// <summary>
        /// initialize the compilation and test of the loaded addon
        /// </summary>
        public async Task <bool> Test()
        {
            LogText.Text = string.Empty;

            var isValid = await AddonCompiler.Insatnce.CompileAddon(AddonManager.CurrentAddon);

            //there was an error detected in complication
            if (!isValid)
            {
                return(false);
            }

            Update();
            UrlTextBox.Text = $"http://localhost:{WebServerManager.WebServerPort}/{AddonManager.CurrentAddon.Class.ToLower()}/addon.json";

            try
            {
                Clipboard.SetText(UrlTextBox.Text);
            }
            catch (Exception ex)
            {
                LogManager.AddErrorLog(ex);
            }

            return(true);
        }
Beispiel #2
0
        /// <summary>
        /// adds a new third party file
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void AddFile_OnClick(object sender, RoutedEventArgs e)
        {
            var filename = await WindowManager.ShowInputDialog("New File Name?", "please enter the name for the new javascript file", "javascriptFile.js");

            if (string.IsNullOrWhiteSpace(filename))
            {
                return;
            }

            var tpf = new ThirdPartyFile
            {
                Content    = string.Empty,
                FileName   = filename,
                C3Folder   = true,
                C2Folder   = false,
                Rootfolder = false,
                FileType   = "inline-script",
                Compress   = false,
                PlainText  = true,
                Domfolder  = false
            };

            tpf.PluginTemplate = TemplateHelper.ThirdPartyFile(tpf);

            tpf.Extention = Path.GetExtension(tpf.FileName);
            if (string.IsNullOrWhiteSpace(tpf.Extention))
            {
                tpf.Extention = ".txt";
                tpf.FileName  = tpf.FileName + tpf.Extention;
            }

            _files.Add(tpf);

            try
            {
                var addon    = JObject.Parse(AddonTextEditor.Text);
                var fileList = JArray.Parse(addon["file-list"].ToString());

                if (tpf.C3Folder)
                {
                    fileList.Add("c3runtime/" + tpf.FileName);
                }
                if (tpf.C2Folder)
                {
                    fileList.Add("c2runtime/" + tpf.FileName);
                }
                if (tpf.Rootfolder)
                {
                    fileList.Add(tpf.FileName);
                }

                addon["file-list"]   = fileList;
                AddonTextEditor.Text = addon.ToString(Formatting.Indented);
            }
            catch (Exception ex)
            {
                LogManager.AddErrorLog(ex);
                NotificationManager.PublishErrorNotification($"error parseing json, addon.json not updated => {ex.Message}");
            }
        }
Beispiel #3
0
        /// <summary>
        /// handles the web server state
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void StartWebServerButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (!WebServerManager.WebServerStarted)
                {
                    int.TryParse(OptionsManager.CurrentOptions.Port, out var port);
                    if (port == 0)
                    {
                        port = 8080;
                        LogManager.AddLogMessage("invalid port, fallback to port 8080");
                    }
                    WebServerManager.StartWebServer(port);
                    //AddonCompiler.Insatnce.WebServer = new WebServerClient();
                    //AddonCompiler.Insatnce.WebServer.Start();
                }
                else
                {
                    AddonCompiler.Insatnce.WebServer.Stop();
                }
            }
            catch (Exception ex)
            {
                LogManager.AddErrorLog(ex);
                WebServerManager.WebServerStarted = false;
            }

            WebServerButton.Content = WebServerManager.WebServerStarted ? "Stop Web Server" : "Start Web Server";
            ApplicationWindows.TestWidnow.Update();
        }
Beispiel #4
0
 /// <summary>
 /// window constructor, loads all addons from storage, setups up default values
 /// </summary>
 public DashboardWindow()
 {
     InitializeComponent();
     try
     {
         //load addon if it was passed through cmd args
         if (AddonManager.CurrentAddon != null && AddonManager.CurrentAddon.Id != Guid.Empty)
         {
             for (int i = 0; i < AddonManager.AllAddons.Count; i++)
             {
                 if (AddonManager.AllAddons[i].Equals(AddonManager.CurrentAddon))
                 {
                     AddonListBox.SelectedIndex = i;
                 }
             }
         }
         else
         {
             AddonManager.CurrentAddon = null;
         }
     }
     catch (Exception ex)
     {
         LogManager.AddErrorLog(ex);
         throw;
     }
 }
Beispiel #5
0
        /// <summary>
        /// removes the selected file
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void RemoveFile_OnClick(object sender, RoutedEventArgs e)
        {
            if (FileListBox.SelectedIndex == -1)
            {
                NotificationManager.PublishErrorNotification("failed to remove file, no file selected");
                return;
            }

            _selectedFile = FileListBox.SelectedItem as ThirdPartyFile;
            if (_selectedFile != null)
            {
                var file = _selectedFile;
                _files.Remove(_selectedFile);
                FileListBox.ItemsSource = _files;
                FileListBox.Items.Refresh();

                //clear editors
                FileTextEditor.Text = string.Empty;

                try
                {
                    var addon    = JObject.Parse(AddonTextEditor.Text);
                    var fileList = JArray.Parse(addon["file-list"].ToString());

                    //remove all checks
                    foreach (var item in fileList.Children().ToList())
                    {
                        if (item.ToString().Equals("c3runtime/" + file.FileName) ||
                            item.ToString().Equals("c2runtime/" + file.FileName) ||
                            item.ToString().Equals(file.FileName))
                        {
                            fileList.Remove(item);
                        }
                    }

                    addon["file-list"]   = fileList;
                    AddonTextEditor.Text = addon.ToString(Formatting.Indented);
                }
                catch (Exception ex)
                {
                    LogManager.AddErrorLog(ex);
                    NotificationManager.PublishErrorNotification($"error parseing json, addon.json not updated => {ex.Message}");
                }

                _selectedFile             = null;
                C3RuntimeFolder.IsChecked = false;
                C2RuntimeFolder.IsChecked = false;
                RootFolder.IsChecked      = false;
                PlainText.IsChecked       = false;
                CompressFile.IsChecked    = false;
                DomScript.IsChecked       = false;
            }
            else
            {
                NotificationManager.PublishErrorNotification("failed to remove action, no 3rd party files selected");
            }
        }
Beispiel #6
0
 /// <summary>
 /// handles formatting the ace as json
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void FormatJsonAce_OnClick(object sender, RoutedEventArgs e)
 {
     try
     {
         AceTextEditor.Text = FormatHelper.Insatnce.Json(AceTextEditor.Text);
     }
     catch (Exception ex)
     {
         LogManager.AddErrorLog(ex);
         NotificationManager.PublishErrorNotification($"failed to format json => {ex.Message}");
     }
 }
Beispiel #7
0
 public void StartProcess(string process, string args)
 {
     try
     {
         Process.Start(process, args);
     }
     catch (Exception ex)
     {
         LogManager.AddErrorLog(ex);
         NotificationManager.PublishErrorNotification(ex.Message);
     }
 }
Beispiel #8
0
 private void OpenImportLogButton_OnClick(object sender, RoutedEventArgs e)
 {
     try
     {
         ProcessHelper.Insatnce.StartProcess("notepad.exe", Path.Combine(DataPathText.Text, "import.log"));
     }
     catch (Exception ex)
     {
         LogManager.AddErrorLog(ex);
         NotificationManager.PublishErrorNotification($"error opening import log, {ex.Message}");
     }
 }
Beispiel #9
0
 public void WriteFile(string path, string content)
 {
     try
     {
         System.IO.File.WriteAllText(path, content);
     }
     catch (Exception ex)
     {
         LogManager.AddErrorLog(ex);
         NotificationManager.PublishErrorNotification(ex.Message);
     }
 }
Beispiel #10
0
 /// <summary>
 /// opens c3addon folder
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void OpenAddonButton_OnClick(object sender, RoutedEventArgs e)
 {
     try
     {
         ProcessHelper.Insatnce.StartProcess(C3AddonPathText.Text);
     }
     catch (Exception ex)
     {
         LogManager.AddErrorLog(ex);
         NotificationManager.PublishErrorNotification($"error opening c3addon folder, {ex.Message}");
     }
 }
Beispiel #11
0
 /// <summary>
 /// execute action, if error is thrown log and throw
 /// </summary>
 /// <param name="action"></param>
 /// <returns></returns>
 public string WrapLogger(Func <string> action)
 {
     try
     {
         return(action());
     }
     catch (Exception ex)
     {
         LogManager.AddErrorLog(ex);
         Insert($"error message => {ex.Message}", "Error");
         throw;
     }
 }
Beispiel #12
0
 /// <summary>
 /// generate properties json from configured configured properties
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void GeneratePropertyText(object sender, RoutedEventArgs e)
 {
     try
     {
         var propLang = TemplateHelper.GeneratePropertyLang(AddonManager.CurrentAddon.PluginEditTime,
                                                            PropertyLanguageTextEditor.Text);
         PropertyLanguageTextEditor.Text = propLang;
     }
     catch (Exception ex)
     {
         LogManager.AddErrorLog(ex);
         NotificationManager.PublishErrorNotification($"failed to generate properties => {ex.Message}");
     }
 }
Beispiel #13
0
 /// <summary>
 /// generate category json from configured categories
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void GenerateCategoryText(object sender, RoutedEventArgs e)
 {
     try
     {
         var category = TemplateHelper.GenerateCategoryLang(AddonManager.CurrentAddon.Categories,
                                                            CategoryLanguageTextEditor.Text);
         CategoryLanguageTextEditor.Text = category;
     }
     catch (Exception ex)
     {
         LogManager.AddErrorLog(ex);
         NotificationManager.PublishErrorNotification($"failed to generate category => {ex.Message}");
     }
 }
Beispiel #14
0
 public bool TryAction(Action act)
 {
     try
     {
         act();
         return(true);
     }
     catch (Exception ex)
     {
         LogManager.AddErrorLog(ex);
         LogManager.CompilerLog.Insert(ex.Message, "Error");
         return(false);
     }
 }
Beispiel #15
0
 private void UpdateConstructVersionButton_OnClick(object sender, RoutedEventArgs e)
 {
     try
     {
         ConstructLauncher.Insatnce.UpdateVersions();
         C3StableUrl.Text = OptionsManager.CurrentOptions.StableUrl;
         C3BetaUrl.Text   = OptionsManager.CurrentOptions.BetaUrl;
         NotificationManager.PublishNotification("construct version links updated successfully");
     }
     catch (Exception ex)
     {
         LogManager.AddErrorLog(ex);
         NotificationManager.PublishErrorNotification($"failed to update construct 3 version => {ex.Message}");
     }
 }
Beispiel #16
0
 /// <summary>
 /// change the icon on drop
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void AddonIcon_OnDrop(object sender, DragEventArgs e)
 {
     try
     {
         var file = ((string[])e.Data.GetData(DataFormats.FileDrop))?.FirstOrDefault();
         if (!string.IsNullOrWhiteSpace(file))
         {
             IconXml          = File.ReadAllText(file);
             AddonIcon.Source = ImageHelper.Insatnce.XmlToBitmapImage(IconXml);
         }
     }
     catch (Exception exception)
     {
         LogManager.AddErrorLog(exception);
         NotificationManager.PublishErrorNotification($"error reading icon file, {exception.Message}");
     }
 }
Beispiel #17
0
        /// <summary>
        /// main window constructor
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();
            try
            {
                //set application callbacks
                AddonManager.AddLoadedCallback((s) =>
                {
                    Title = $"C3IDE - {s.AddonId} - {s.Id}";
                    AddonLoadDelegate();
                });

                //setup callback
                NotificationManager.SetInfoCallback(OpenNotification);
                NotificationManager.SetErrorCallback(OpenErrorNotification);
                OptionsManager.OptionChangedCallback = OptionChanged;

                //load data
                AddonManager.LoadAllAddons();

                //setup window manager
                WindowManager.MainWindow         = this;
                WindowManager.OpenFindAndReplace = OpenFindAndReplace;
                WindowManager.SetWindowChangeCallback(NavigateToWindow);
                WindowManager.ShowDialog         = ShowDialogBox;
                WindowManager.ShowInputDialog    = ShowInputDialogBox;
                WindowManager.ShowLoadingOverlay = ShowLoadingOverlay;
                WindowManager.CurrentWindow      = ApplicationWindows.DashboardWindow;

                //setup themes and menu
                ThemeManager.SetupTheme();
                MenuManager.SetupMainMenu();

                //setup default view
                SetupMenus(PluginType.SingleGlobalPlugin);
                ActiveItem.Content = ApplicationWindows.DashboardWindow;
                ApplicationWindows.DashboardWindow.OnEnter();
                OptionChanged(OptionsManager.CurrentOptions);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                LogManager.AddErrorLog(ex);
                throw;
            }
        }
Beispiel #18
0
 /// <summary>
 /// handles the test window losing focus
 /// </summary>
 public void OnExit()
 {
     if (AddonManager.CurrentAddon != null)
     {
         try
         {
             AddonManager.CurrentAddon.MajorVersion    = int.Parse(Major.Text.Trim());
             AddonManager.CurrentAddon.MinorVersion    = int.Parse(Minor.Text.Trim());
             AddonManager.CurrentAddon.RevisionVersion = int.Parse(Revision.Text.Trim());
             AddonManager.CurrentAddon.BuildVersion    = int.Parse(Build.Text.Trim());
         }
         catch (Exception ex)
         {
             LogManager.AddErrorLog(ex);
             NotificationManager.PublishErrorNotification("invalid version number");
         }
     }
 }
Beispiel #19
0
        /// <summary>
        /// stops the web server
        /// </summary>
        public void Stop()
        {
            _httpServer.Dispose();
            _httpServer = null;
            WebServerManager.TcpListener.Stop();
            WebServerManager.WebServerUrl = string.Empty;
            WebServerManager.WebServiceUrlChanged?.Invoke(WebServerManager.WebServerUrl);
            WebServerManager.WebServerStarted = false;
            WebServerManager.WebServerStateChanged?.Invoke(false);

            try
            {
                LogManager.CompilerLog.Insert("server stopped...");
            }
            catch (Exception ex)
            {
                LogManager.AddErrorLog(ex);
            }
        }
Beispiel #20
0
 private void ChangedVersion(object sender, TextChangedEventArgs e)
 {
     if (Major != null && Minor != null && Revision != null && Build != null)
     {
         if (AddonManager.CurrentAddon != null)
         {
             try
             {
                 AddonManager.CurrentAddon.MajorVersion    = int.Parse(Major.Text.Trim());
                 AddonManager.CurrentAddon.MinorVersion    = int.Parse(Minor.Text.Trim());
                 AddonManager.CurrentAddon.RevisionVersion = int.Parse(Revision.Text.Trim());
                 AddonManager.CurrentAddon.BuildVersion    = int.Parse(Build.Text.Trim());
             }
             catch (Exception ex)
             {
                 LogManager.AddErrorLog(ex);
             }
         }
     }
 }
Beispiel #21
0
        /// <summary>
        /// handles selecting all text when the url text box is in focus
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SelectUrl(object sender, RoutedEventArgs e)
        {
            var tb = (sender as TextBox);

            tb?.SelectAll();
            var url = UrlTextBox.Text;

            if (string.IsNullOrWhiteSpace(url))
            {
                try
                {
                    Clipboard.SetText(url);
                    NotificationManager.PublishNotification($"{url} copied to clipboard.");
                }
                catch (Exception ex)
                {
                    LogManager.AddErrorLog(ex);
                }
            }
        }
Beispiel #22
0
        /// <summary>
        /// opens construct from the web or desktop
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OpenConstructButton_Click(object sender, RoutedEventArgs e)
        {
            if (OptionsManager.CurrentOptions.OpenC3InWeb)
            {
                ConstructLauncher.Insatnce.LaunchConstruct(false);
            }
            else
            {
                try
                {
                    if (string.IsNullOrEmpty(OptionsManager.CurrentOptions.C3DesktopPath))
                    {
                        throw new InvalidOperationException("Construct 3 Desktop Path is Invalid");
                    }

                    ProcessHelper.Insatnce.StartProcess(OptionsManager.CurrentOptions.C3DesktopPath);
                }
                catch (Exception ex)
                {
                    LogManager.AddErrorLog(ex);
                    NotificationManager.PublishErrorNotification("Invalid C3 desktop path, please check plath in options");
                }
            }
        }
Beispiel #23
0
        /// <summary>
        /// imports a thrird party file
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FileListBox_OnDrop(object sender, DragEventArgs e)
        {
            try
            {
                var file = ((string[])e.Data.GetData(DataFormats.FileDrop))?.FirstOrDefault();
                if (!string.IsNullOrWhiteSpace(file))
                {
                    var info      = new FileInfo(file);
                    var filename  = info.Name;
                    var content   = File.ReadAllText(file);
                    var bytes     = File.ReadAllBytes(file);
                    var compress  = false;
                    var plainText = true;

                    switch (info.Extension)
                    {
                    case ".js":
                        content   = FormatHelper.Insatnce.FixMinifiedFiles(content);
                        compress  = true;
                        plainText = true;
                        break;

                    case ".html":
                    case ".css":
                    case ".txt":
                    case ".json":
                    case ".xml":
                        plainText = true;
                        compress  = false;
                        break;

                    default:
                        content   = $"BINARY FILE => {filename}\nBYTE LENGTH : ({bytes.Length})";
                        plainText = false;
                        compress  = false;
                        break;
                    }

                    var tpf = new ThirdPartyFile
                    {
                        Content   = content,
                        FileName  = filename,
                        Bytes     = bytes,
                        Extention = info.Extension.ToLower(),
                        FileType  = "inline-script",
                        Compress  = compress,
                        PlainText = plainText
                    };

                    tpf.PluginTemplate = TemplateHelper.ThirdPartyFile(tpf);
                    _files.Add(tpf);

                    CodeCompletionFactory.Insatnce.PopulateUserDefinedTokens(filename, content);
                    FileListBox.ItemsSource = _files;
                    FileListBox.Items.Refresh();
                }
            }
            catch (Exception exception)
            {
                LogManager.AddErrorLog(exception);
                NotificationManager.PublishErrorNotification($"error adding third party file, {exception.Message}");
            }
        }
Beispiel #24
0
        private void Tab_ChangedEvent(object sender, SelectionChangedEventArgs e)
        {
            if (AddonJsTab.IsSelected)
            {
                ////save current selection
                if (_selectedFile != null)
                {
                    //only update content for readable text files
                    switch (_selectedFile.Extention?.ToLower() ?? ".txt")
                    {
                    case ".js":
                    case ".html":
                    case ".css":
                    case ".txt":
                    case ".json":
                    case ".xml":
                        _selectedFile.Content = FileTextEditor.Text;
                        break;

                    default:
                        _selectedFile.Content = $"BINARY FILE => {_selectedFile.FileName}\nBYTE LENGTH : ({_selectedFile.Bytes.Length})";
                        break;
                    }
                    _selectedFile.C2Folder   = C2RuntimeFolder.IsChecked != null && C2RuntimeFolder.IsChecked.Value;
                    _selectedFile.C3Folder   = C3RuntimeFolder.IsChecked != null && C3RuntimeFolder.IsChecked.Value;
                    _selectedFile.Rootfolder = RootFolder.IsChecked != null && RootFolder.IsChecked.Value;
                    _selectedFile.Domfolder  = DomScript.IsChecked != null && DomScript.IsChecked.Value;
                    //_selectedFile.Bytes = Encoding.ASCII.GetBytes(FileTextEditor.Text);
                    _selectedFile.FileType       = FileTypeDropDown.Text;
                    _selectedFile.PluginTemplate = TemplateHelper.ThirdPartyFile(_selectedFile);
                    _selectedFile.Compress       = CompressFile.IsChecked != null && CompressFile.IsChecked.Value;
                    _selectedFile.PlainText      = PlainText.IsChecked != null && PlainText.IsChecked.Value;
                }

                //update addon.json
                try
                {
                    var addon    = JObject.Parse(AddonTextEditor.Text);
                    var fileList = JArray.Parse(addon["file-list"].ToString());

                    foreach (var thirdPartyFile in _files)
                    {
                        //remove all checks
                        foreach (var item in fileList.Children().ToList())
                        {
                            if (item.ToString().Equals("c3runtime/" + thirdPartyFile.FileName.Replace("\\", "/")) ||
                                item.ToString().Equals("c2runtime/" + thirdPartyFile.FileName.Replace("\\", "/")) ||
                                item.ToString().Equals(thirdPartyFile.FileName.Replace("\\", "/")))
                            {
                                fileList.Remove(item);
                            }
                        }

                        if (thirdPartyFile.C3Folder)
                        {
                            fileList.Add("c3runtime/" + thirdPartyFile.FileName.Replace("\\", "/"));
                        }
                        if (thirdPartyFile.C2Folder)
                        {
                            fileList.Add("c2runtime/" + thirdPartyFile.FileName.Replace("\\", "/"));
                        }
                        if (thirdPartyFile.Rootfolder)
                        {
                            fileList.Add(thirdPartyFile.FileName.Replace("\\", "/"));
                        }

                        addon["file-list"] = fileList;
                    }

                    AddonTextEditor.Text = addon.ToString(Formatting.Indented);
                }
                catch (Exception ex)
                {
                    LogManager.AddErrorLog(ex);
                    NotificationManager.PublishErrorNotification($"error parseing json, addon.json not updated => {ex.Message}");
                }
            }
        }
Beispiel #25
0
        /// <summary>
        /// handles the save button in the add new parameter window
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SaveParamButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var id           = ParamIdText.Text.ToLower().Replace(" ", "-");
                var type         = ParamTypeDropdown.Text;
                var value        = ParamValueText.Text;
                var name         = ParamNameText.Text;
                var desc         = ParamDescText.Text.Replace("\"", "\\\"");
                var expressionId = _selectedExpression.Id;

                //there is at least one param defined
                if (AceTextEditor.Text.Contains("\"params\": ["))
                {
                    //ace param
                    var aceTemplate = TemplateHelper.AceParam(id, type, value);

                    //lang param
                    var langTemplate = TemplateHelper.AceLang(id, type, name, desc);
                    var newProperty  = JObject.Parse(langTemplate);
                    var langJson     = JObject.Parse($"{{ {LanguageTextEditor.Text} }}")[expressionId];
                    var langParams   = langJson["params"];
                    langParams.Last.AddAfterSelf(newProperty.Property(id));
                    langJson["params"] = langParams;


                    //code param
                    var func         = Regex.Match(CodeTextEditor.Text, @"(?:\()(?<param>.*)(?:\))");
                    var declaration  = Regex.Match(CodeTextEditor.Text, @".*(?:\()(?<param>.*)(?:\))").Value;
                    var paramList    = func.Groups["param"].Value.Split(',');
                    var codeTemplate = TemplateHelper.AceCode(id, _selectedExpression.ScriptName, paramList);

                    //updates
                    LanguageTextEditor.Text = $"\"{expressionId}\": {langJson.ToString(formatting: Formatting.Indented)} ";
                    AceTextEditor.Text      = FormatHelper.Insatnce.Json(Regex.Replace(AceTextEditor.Text, @"}(\r\n?|\n|\s*)]", $"{aceTemplate}\r\n]"));
                    CodeTextEditor.Text     = CodeTextEditor.Text.Replace(declaration, codeTemplate);
                }
                //this will be the first param
                else
                {
                    //ace param
                    var aceTemplate = TemplateHelper.AceParamFirst(id, type, value);

                    //language param
                    var langTemplate = TemplateHelper.AceLangFirst(id, type, name, desc);

                    //code param
                    var codeTemplate = TemplateHelper.AceCodeFirst(id, _selectedExpression.ScriptName);

                    //updates
                    LanguageTextEditor.Text = LanguageTextEditor.Text.Replace(@"""
}", langTemplate);
                    AceTextEditor.Text      = FormatHelper.Insatnce.Json(AceTextEditor.Text.Replace("}", aceTemplate));
                    CodeTextEditor.Text     = CodeTextEditor.Text.Replace($"{_selectedExpression.ScriptName}()", codeTemplate);
                }
            }
            catch (Exception ex)
            {
                LogManager.AddErrorLog(ex);
            }

            NewParamWindow.IsOpen = false;
        }
Beispiel #26
0
        //todo: we want to use the same guid, to overwrite existing addon.
        //todo: we want to parse a different version of the .c3ide file with relative paths
        //todo: abstract this functionaility out to a helper class

        /// <summary>
        /// when a file is dropped into the list box, if the file is a .c3ide file parse the file and load the addon
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void AddonFile_OnDrop(object sender, DragEventArgs e)
        {
            try
            {
                var     file = ((string[])e.Data.GetData(DataFormats.FileDrop))?.FirstOrDefault();
                var     info = new FileInfo(file);
                C3Addon c3addon;

                if (info.Extension.Contains("c3ide"))
                {
                    var addonInfo = File.ReadAllLines(info.FullName)[0];
                    if (addonInfo == "@@METADATA")
                    {
                        c3addon = ProjectManager.ReadProject(info.FullName);
                    }
                    else
                    {
                        var data = File.ReadAllText(info.FullName);
                        c3addon = JsonConvert.DeserializeObject <C3Addon>(data);
                    }

                    //when you import the project, it should not overwrite any other project
                    if (OptionsManager.CurrentOptions.OverwriteGuidOnImport)
                    {
                        c3addon.Id = Guid.NewGuid();
                    }

                    c3addon.LastModified = DateTime.Now;

                    //get the plugin template
                    c3addon.Template = TemplateFactory.Insatnce.CreateTemplate(c3addon.Type);

                    var addonIndex = AddonManager.AllAddons.Count - 1;
                    AddonManager.CurrentAddon = c3addon;
                    AddonManager.SaveCurrentAddon();
                    AddonManager.LoadAllAddons();
                    AddonListBox.ItemsSource = AddonManager.AllAddons;
                    AddonManager.LoadAddon(c3addon);
                }
                else if (info.Extension.Contains("c3addon"))
                {
                    var result = await WindowManager.ShowDialog("(EXPERIMENTAL) Importing C3Addon File", "Importing a C3addon file is an experimental feature. Please verify your file was improted correctly. If you encounter an issue please open a Github Issue Ticket");

                    if (result)
                    {
                        c3addon = await C3AddonImporter.Insatnce.Import(info.FullName);

                        AddonManager.LoadAddon(c3addon);
                        AddonManager.SaveCurrentAddon();
                        AddonManager.LoadAllAddons();
                        AddonListBox.ItemsSource = AddonManager.AllAddons;
                        AddonManager.LoadAddon(c3addon);
                    }
                }
                else if (info.Extension.Contains("c2addon"))
                {
                    var result = await WindowManager.ShowDialog("(VERY EXPERIMENTAL) Importing C2Addon File", "Importing a C2addon file is an very experimental feature and expected to have BUGS. THIS DOES NOT FULLY CONVERT YOUR ADDON, it will attempt to generate stubs for the ACES. if you run into any issue importing please file Github Issue Ticket, please include the c2addon your trying to convert to help identify the issues, NOT ALL ISSUE WILL BE RESOLVED but i will do my best!!!");

                    if (result)
                    {
                        c3addon = await C2AddonImporter.Insatnce.Import2Addon(info.FullName);

                        AddonManager.LoadAddon(c3addon);
                        AddonManager.SaveCurrentAddon();
                        AddonManager.LoadAllAddons();
                        AddonListBox.ItemsSource = AddonManager.AllAddons;
                        AddonManager.LoadAddon(c3addon);
                    }
                }
                //else if (info.Extension.Contains("svg"))
                //{
                //    //todo: need to find a way to drag items into list box item
                //}
                else
                {
                    throw new InvalidOperationException("invalid file type, for import");
                }
            }
            catch (Exception exception)
            {
                LogManager.AddErrorLog(exception);
                NotificationManager.PublishErrorNotification($"error importing file, check import.log => {Path.Combine(OptionsManager.CurrentOptions.DataPath, "import.log")}");
            }
        }
Beispiel #27
0
        /// <summary>
        /// compiles an addon and starts the web server
        /// </summary>
        /// <param name="addon"></param>
        /// <param name="startWebServer"></param>
        /// <returns></returns>
        public async Task <bool> CompileAddon(C3Addon addon, bool startWebServer = true)
        {
            if (!ValidateFiles(addon))
            {
                IsCompilationValid = false;
                return(false);
            }
            IsCompilationValid = true;

            try
            {
                LogManager.CompilerLog.Insert($"compilation starting...");

                //generate unique folder for specific addon class
                var folderName = addon.Class.ToLower();
                addon.AddonFolder = Path.Combine(OptionsManager.CurrentOptions.CompilePath, folderName);

                //check for addon id
                if (string.IsNullOrWhiteSpace(addon.AddonId))
                {
                    addon.AddonId = $"{addon.Author}_{addon.Class}";
                }

                //clear out compile path
                if (Directory.Exists(addon.AddonFolder))
                {
                    LogManager.CompilerLog.Insert($"compile directory exists => { addon.AddonFolder}");
                    System.IO.Directory.Delete(addon.AddonFolder, true);
                    LogManager.CompilerLog.Insert($"removed compile directory...");
                }

                //create main compile directory
                LogManager.CompilerLog.Insert($"recreating compile directory => { addon.AddonFolder}");
                if (!Directory.Exists(OptionsManager.CurrentOptions.CompilePath))
                {
                    System.IO.Directory.CreateDirectory(OptionsManager.CurrentOptions.CompilePath);
                }

                //create addon compile directory and addon specific paths
                System.IO.Directory.CreateDirectory(addon.AddonFolder);
                System.IO.Directory.CreateDirectory(Path.Combine(addon.AddonFolder, "lang"));
                if (addon.Type != PluginType.Effect && addon.Type != PluginType.Theme)
                {
                    System.IO.Directory.CreateDirectory(Path.Combine(addon.AddonFolder, "c3runtime"));
                }
                if (!string.IsNullOrWhiteSpace(addon.C2RunTime) || (addon.ThirdPartyFiles != null && addon.ThirdPartyFiles.Any(x => x.Value.C2Folder)))
                {
                    System.IO.Directory.CreateDirectory(Path.Combine(addon.AddonFolder, "c2runtime"));
                }
                LogManager.CompilerLog.Insert($"compile directory created successfully => { addon.AddonFolder}");


                if (addon.Type == PluginType.Effect)
                {
                    //todo: effect validator http://shdr.bkcore.com/
                    CreateEffectFiles(addon, folderName);
                }
                else if (addon.Type == PluginType.Theme)
                {
                    CreateThemeFiles(addon, folderName);
                }
                else
                {
                    CreateAddonFiles(addon, folderName);
                }
            }
            catch (Exception ex)
            {
                IsCompilationValid = false;
                LogManager.AddErrorLog(ex);
                LogManager.CompilerLog.Insert($"compilation terminated due to error...");
                LogManager.CompilerLog.Insert($"error => {ex.Message}");
                NotificationManager.PublishErrorNotification("There was an error generating the addon, please check the log.");
                return(false);
            }

            //try and start the web server
            try
            {
                if (startWebServer && IsCompilationValid)
                {
                    //start web server installation
                    await Task.Run(() =>
                    {
                        int.TryParse(OptionsManager.CurrentOptions.Port, out var port);
                        if (port == 0)
                        {
                            port = 8080;
                            LogManager.AddLogMessage("invalid port, fallback to port 8080");
                        }
                        WebServerManager.StartWebServer(port);
                        //WebServer = new WebServerClient();
                        //WebServer.Start();
                    });
                }
            }
            catch (Exception ex)
            {
                IsCompilationValid = false;
                LogManager.AddErrorLog(ex);
                LogManager.CompilerLog.Insert($"web server failed to start...");
                NotificationManager.PublishErrorNotification("The web server failed to start... check that the port 8080, is not being used by another application.");
                WebServerManager.WebServerStarted = false;
                return(false);
            }

            return(true);
        }
Beispiel #28
0
        public void App_Startup(object sender, StartupEventArgs e)
        {
            try
            {
                //check for oneclick args
                if (AppDomain.CurrentDomain?.SetupInformation?.ActivationArguments?.ActivationData != null)
                {
                    var path = new Uri(AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData[0]).LocalPath;
                    if (string.IsNullOrWhiteSpace(path))
                    {
                        return;
                    }
                    var     info = new FileInfo(path);
                    C3Addon c3addon;

                    //check if file is json or project
                    var addonInfo = File.ReadAllLines(info.FullName)[0];
                    if (addonInfo == "@@METADATA")
                    {
                        c3addon = ProjectManager.ReadProject(info.FullName);
                    }
                    else
                    {
                        var data = File.ReadAllText(info.FullName);
                        c3addon = JsonConvert.DeserializeObject <C3Addon>(data);
                    }

                    var currAddon = DataAccessFacade.Insatnce.AddonData.Get(x => x.Id.Equals(c3addon.Id));
                    if (currAddon != null)
                    {
                        var results = MessageBox.Show(
                            "Addon currently exists do you want to overwrite addon? \n(YES) will overwrite, \n(NO) will assign new addon id.",
                            "Overwrite?", MessageBoxButton.YesNo, MessageBoxImage.Exclamation);

                        if (results == MessageBoxResult.Yes)
                        {
                            c3addon.LastModified = DateTime.Now;
                            DataAccessFacade.Insatnce.AddonData.Upsert(c3addon);
                        }
                        else if (results == MessageBoxResult.No)
                        {
                            c3addon.Id           = Guid.NewGuid();
                            c3addon.LastModified = DateTime.Now;
                            DataAccessFacade.Insatnce.AddonData.Upsert(c3addon);
                        }
                        else
                        {
                            //do not open new addon
                            return;
                        }
                    }
                    else
                    {
                        c3addon.LastModified = DateTime.Now;
                        DataAccessFacade.Insatnce.AddonData.Upsert(c3addon);
                    }

                    //get the plugin template
                    c3addon.Template          = TemplateFactory.Insatnce.CreateTemplate(c3addon.Type);
                    AddonManager.CurrentAddon = c3addon;
                }

                //process command line args
                var args = e.Args;
                if (args.Any())
                {
                    //checked if string is guid
                    if (Guid.TryParse(args[0], out var guid))
                    {
                        var addon = DataAccessFacade.Insatnce.AddonData.Get(x => x.Id == guid).FirstOrDefault();
                        if (addon != null)
                        {
                            AddonManager.CurrentAddon = addon;
                        }
                    }
                    else
                    {
                        MessageBox.Show($"invalid arg => {args[0]}");
                    }
                }
            }
            catch (Exception ex)
            {
                LogManager.AddErrorLog(ex);
            }

            //always start main window
            //MainWindow main = new MainWindow();
            //main.Show();
        }