コード例 #1
0
        private async void ImportScriptsToMaster()
        {
            var scriptsToBeImported = ScriptsCollection.Where(s => s.Value.IsSelected).Select(s => s.Value).ToList();

            if (scriptsToBeImported.Count > 0)
            {
                foreach (var script in scriptsToBeImported)
                {
                    script.IsSelected = false;
                    await _scriptDb.AddNewScript(script);
                }

                var masterScript = await _masterScriptDb.GetMasterScript();

                masterScript.Scripts.AddRange(scriptsToBeImported);
                await _masterScriptDb.UpdateScript(masterScript);

                //write masterscript on the disk
                ProcessScript.ExportScript(Path.Combine(masterScript.Location, masterScript.Name), masterScript.Scripts);
                Message           = "Scripts imported successfully";
                MessageVisibility = "Visible";
            }
            else
            {
                MessageBox.Show("Please select at least one script from the grid to import", "Warning",
                                MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
コード例 #2
0
        private async void ChangePath()
        {
            try
            {
                var folderDialog = new FolderSelectDialog
                {
                    Title = "Select a folder where the master script should be saved"
                };
                var folderPath = string.Empty;
                if (folderDialog.ShowDialog())
                {
                    folderPath = folderDialog.FileName;
                }
                if (!string.IsNullOrEmpty(folderPath))
                {
                    var masterScript = await _masterScriptDb.GetMasterScript();

                    masterScript.Location = folderPath;
                    await _masterScriptDb.UpdateScript(masterScript);

                    ProcessScript.ExportScript(Path.Combine(masterScript.Location, masterScript.Name), masterScript.Scripts);
                }
            }
            catch (Exception ex)
            {
                Log.Logger.Error($"{Constants.ChangePath}: {Constants.Message}: {ex.Message}\n " +
                                 $"{Constants.StackTrace}: {ex.StackTrace}\n {Constants.InnerException}: {ex.InnerException}");
            }
        }
コード例 #3
0
        private async void SaveScript()
        {
            var masterScript = await MasterScriptDb.GetMasterScript();

            var scriptToBeUpdated = masterScript.Scripts.FirstOrDefault(s => s.ScriptId.Equals(_script.ScriptId));

            if (scriptToBeUpdated != null)
            {
                scriptToBeUpdated.Active            = !IsDisabled;
                scriptToBeUpdated.Name              = ScriptName;
                scriptToBeUpdated.Text              = ScriptContent;
                scriptToBeUpdated.Description       = ScriptDescription;
                scriptToBeUpdated.ScriptStateAction = !IsDisabled ? "Disable" : "Enable";
                scriptToBeUpdated.RowColor          = !IsDisabled ? "Black" : "DarkGray";
                await MasterScriptDb.UpdateScript(masterScript);

                //write masterscript on the disk
                ProcessScript.ExportScript(Path.Combine(masterScript.Location, masterScript.Name), masterScript.Scripts);
                var result = MessageBox.Show("Script edited successfully", string.Empty,
                                             MessageBoxButton.OK, MessageBoxImage.Information);
                if (result == MessageBoxResult.OK)
                {
                    _mainWindowViewModel.LoadScriptsPage();
                }
            }
        }
コード例 #4
0
 private void ExportScripts()
 {
     try
     {
         if (ScriptsCollection.Any(s => s.IsSelected))
         {
             var folderDialog = new SaveFileDialog
             {
                 Title      = @"Select a location where the script should be exported",
                 DefaultExt = "ahk"
             };
             if (folderDialog.ShowDialog() == DialogResult.OK)
             {
                 var folderPath      = folderDialog.FileName;
                 var selectedScripts = ScriptsCollection.Where(s => s.IsSelected).ToList();
                 ProcessScript.ExportScript(Path.Combine(folderPath, folderDialog.FileName), selectedScripts);
                 MessageBox.Show("Script was exported successfully to selected location", "",
                                 MessageBoxButton.OK, MessageBoxImage.Information);
                 Helpers.Ui.Select(ScriptsCollection, false);
             }
         }
         else
         {
             MessageBox.Show("Please select at least one script from the grid to export", "Warning",
                             MessageBoxButton.OK, MessageBoxImage.Warning);
         }
     }
     catch (Exception ex)
     {
         Log.Logger.Error($"{Constants.ExportScripts}: {Constants.Message}: {ex.Message}\n " +
                          $"{Constants.StackTrace}: {ex.StackTrace}\n {Constants.InnerException}: {ex.InnerException}");
     }
 }
コード例 #5
0
 private void RemoveScripts()
 {
     if (ScriptsCollection.Any(s => s.IsSelected))
     {
         var messageResult = MessageBox.Show("Are you sure you want to delete selected scripts?", "Confirmation",
                                             MessageBoxButton.OKCancel, MessageBoxImage.Question);
         if (messageResult != MessageBoxResult.OK)
         {
             return;
         }
         var scriptsToBeRemoved = ScriptsCollection.Where(s => s.IsSelected).ToList();
         //remove from UI
         foreach (var script in scriptsToBeRemoved)
         {
             ScriptsCollection.Remove(script);
         }
         //Remove from db
         _scriptsDb.RemoveScripts(scriptsToBeRemoved);
         _masterScriptDb.RemoveScripts(scriptsToBeRemoved);
         //write masterscript on the disk
         var masterScript = _masterScriptDb.GetMasterScript().Result;
         ProcessScript.ExportScript(Path.Combine(masterScript.Location, masterScript.Name), masterScript.Scripts);
     }
     else
     {
         MessageBox.Show("Please select at least one script from the grid to be removed", "Warning",
                         MessageBoxButton.OK, MessageBoxImage.Warning);
     }
 }
コード例 #6
0
        private async void ImportScriptsToMaster()
        {
            var scriptsToBeImported = ScriptsCollection.Where(s => s.Value.IsSelected).Select(s => s.Value).ToList();

            if (scriptsToBeImported.Count > 0)
            {
                foreach (var script in scriptsToBeImported)
                {
                    script.IsSelected        = false;
                    script.ScriptStateAction = script.Active ? "Disable" : "Enable";
                    script.RowColor          = script.Active ? "Black" : "DarkGray";
                    await _scriptDb.AddNewScript(script);

                    RemoveScriptFromGrid(script);
                }

                var masterScript = await _masterScriptDb.GetMasterScript();

                masterScript.Scripts.AddRange(scriptsToBeImported);
                await _masterScriptDb.UpdateScript(masterScript);

                //write masterscript on the disk
                ProcessScript.ExportScript(Path.Combine(masterScript.Location, masterScript.Name), masterScript.Scripts);

                Message           = "Scripts imported successfully";
                MessageVisibility = "Visible";
                Helpers.Ui.Select(GetObservableCollectionOfScripts(), false);
            }
            else
            {
                MessageBox.Show("Please select at least one script from the grid to import", "Warning",
                                MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
コード例 #7
0
        private async void HandlePreviewDrop(object dropedFile)
        {
            var file = dropedFile as IDataObject;

            if (null == file)
            {
                return;
            }
            var documentsPath = (string[])file.GetData(DataFormats.FileDrop);

            if (documentsPath != null)
            {
                foreach (var path in documentsPath)
                {
                    if (ProcessScript.IsGeneratedByAhkPlugin(path))
                    {
                        MessageVisibility = "Collapsed";
                        var pathAlreadyAdded = FilesNameCollection.Any(p => p.FilePath.Equals(path));
                        if (!pathAlreadyAdded)
                        {
                            var scripts = ProcessScript.ReadImportedScript(path);
                            foreach (var script in scripts)
                            {
                                var exist = await ProcessScript.ScriptContentAlreadyExist(script.Value);

                                if (!exist)
                                {
                                    script.Value.ScriptStateAction = script.Value.Active ? "Disable" : "Enable";
                                    script.Value.RowColor          = script.Value.Active ? "Black" : "DarkGray";
                                    ScriptsCollection.Add(script);
                                }
                            }
                            var newFile = new ImportScriptItemTemplate
                            {
                                Content           = Path.GetFileNameWithoutExtension(path),
                                RemoveFileCommand = new RelayCommand(RemoveFile),
                                FilePath          = path
                            };
                            FilesNameCollection.Add(newFile);
                            if (ScriptsCollection.Count.Equals(0))
                            {
                                MessageVisibility = "Visible";
                                Message           = "Imported scripts are already in the master script.";
                            }
                        }
                    }
                    else
                    {
                        MessageVisibility = "Visible";
                        Message           = "Only scripts generated by AHK Plugin are supported.";
                    }
                }
            }
            SetGridVisibility();
        }
コード例 #8
0
        public void IsNotGeneratedByAhk_ReturnsFalse(string scriptName)
        {
            // Arrange
            var scriptPath = GetScript(scriptName);

            // Act
            var isScript = ProcessScript.IsGeneratedByAhkPlugin(scriptPath);

            // Assert
            Assert.False(isScript);
        }
コード例 #9
0
        private void ChangeState(object row)
        {
            var script = (Script)row;

            if (script != null)
            {
                Helpers.Ui.SetStateColors(script);
                ProcessScript.ChangeScriptState(script);
                ProcessScript.SaveScriptToMaster(script);
            }
        }
コード例 #10
0
 private void ChangeState(object row)
 {
     try
     {
         var script = (Script)row;
         if (script != null)
         {
             Helpers.Ui.SetStateColors(script);
             ProcessScript.ChangeScriptState(script);
             ProcessScript.SaveScriptToMaster(script);
         }
     }
     catch (Exception ex)
     {
         Log.Logger.Error($"{Constants.ChangeState}: {Constants.Message}: {ex.Message}\n " +
                          $"{Constants.StackTrace}: {ex.StackTrace}\n {Constants.InnerException}: {ex.InnerException}");
     }
 }
コード例 #11
0
        private void ChangeState(object row)
        {
            var script = ((KeyValuePair <string, Script>)row).Value;

            if (script == null)
            {
                return;
            }
            Helpers.Ui.SetStateColors(script);
            ProcessScript.ChangeScriptState(script);

            var scriptToBeUpdated = ScriptsCollection.FirstOrDefault(s => s.Value.ScriptId.Equals(script.ScriptId)).Value;

            scriptToBeUpdated.Active            = script.Active;
            scriptToBeUpdated.Text              = script.Text;
            scriptToBeUpdated.RowColor          = script.RowColor;
            scriptToBeUpdated.ScriptStateAction = script.ScriptStateAction;
        }
コード例 #12
0
        private void HandlePreviewDrop(object dropedFile)
        {
            var file = dropedFile as IDataObject;

            if (null == file)
            {
                return;
            }
            var documentsPath = (string[])file.GetData(DataFormats.FileDrop);
            var defaultFormat = DataFormats.Text;

            if (documentsPath != null)
            {
                foreach (var path in documentsPath)
                {
                    if (ProcessScript.IsGeneratedByAhkPlugin(path))
                    {
                        MessageVisibility = "Hidden";
                        var pathAlreadyAdded = FilesNameCollection.Any(p => p.FilePath.Equals(path));
                        if (!pathAlreadyAdded)
                        {
                            var scripts = ProcessScript.ReadImportedScript(path);
                            ScriptsCollection.AddRange(scripts);
                            var newFile = new ImportScriptItemTemplate
                            {
                                Content           = Path.GetFileNameWithoutExtension(path),
                                RemoveFileCommand = new RelayCommand(RemoveFile),
                                FilePath          = path
                            };
                            FilesNameCollection.Add(newFile);
                        }
                    }
                    else
                    {
                        MessageVisibility = "Visible";
                        Message           = "Only scripts generated by AHK Plugin are supported.";
                    }
                }
            }
            SetGridVisibility();
        }
コード例 #13
0
 private void ExportScripts()
 {
     if (ScriptsCollection.Any(s => s.IsSelected))
     {
         var folderDialog = new FolderSelectDialog
         {
             Title = "Select a folder where the script should be exported"
         };
         if (folderDialog.ShowDialog())
         {
             var folderPath      = folderDialog.FileName;
             var selectedScripts = ScriptsCollection.Where(s => s.IsSelected).ToList();
             ProcessScript.ExportScript(Path.Combine(folderPath, "exportedScript.ahk"), selectedScripts);
         }
     }
     else
     {
         MessageBox.Show("Please select at least one script from the grid to export", "Warning",
                         MessageBoxButton.OK, MessageBoxImage.Warning);
     }
 }
コード例 #14
0
        private async void InsertScript()
        {
            ValidateForm();
            MessageVisibility = "Visible";
            if (FormIsValid)
            {
                var script = new Script
                {
                    ScriptId    = Guid.NewGuid().ToString(),
                    Active      = !IsDisabled,
                    Description = ScriptDescription,
                    Name        = ScriptName,
                    Text        = ScriptContent
                };
                script.ScriptStateAction = script.Active ? "Disable" : "Enable";
                script.RowColor          = script.Active ? "Black" : "DarkGray";

                //add new script in data base
                await _scriptDb.AddNewScript(script);

                //add the script in master script too
                var masterScript = await _masterScriptDb.GetMasterScript();

                masterScript.Scripts.Add(script);
                await _masterScriptDb.UpdateScript(masterScript);

                //write masterscript on the disk
                ProcessScript.ExportScript(Path.Combine(masterScript.Location, masterScript.Name), masterScript.Scripts);

                Message      = "Script added successfully.";
                MessageColor = "#3EA691";

                ClearForm();
            }
            else
            {
                Message      = "Please fill all the fields.";
                MessageColor = Color.DarkRed.Name;
            }
        }
コード例 #15
0
        private async void ChangePath()
        {
            var folderDialog = new FolderSelectDialog
            {
                Title = "Select a folder where the master script should be saved"
            };
            var folderPath = string.Empty;

            if (folderDialog.ShowDialog())
            {
                folderPath = folderDialog.FileName;
            }
            if (!string.IsNullOrEmpty(folderPath))
            {
                var masterScript = await _masterScriptDb.GetMasterScript();

                masterScript.Location = folderPath;
                await _masterScriptDb.UpdateScript(masterScript);

                ProcessScript.ExportScript(Path.Combine(masterScript.Location, masterScript.Name), masterScript.Scripts);
            }
        }
コード例 #16
0
        private void ChangeState(object row)
        {
            try
            {
                var script = ((KeyValuePair <string, Script>)row).Value;
                if (script == null)
                {
                    return;
                }
                Helpers.Ui.SetStateColors(script);
                ProcessScript.ChangeScriptState(script);

                var scriptToBeUpdated = ScriptsCollection.FirstOrDefault(s => s.Value.ScriptId.Equals(script.ScriptId)).Value;
                scriptToBeUpdated.Active            = script.Active;
                scriptToBeUpdated.Text              = script.Text;
                scriptToBeUpdated.RowColor          = script.RowColor;
                scriptToBeUpdated.ScriptStateAction = script.ScriptStateAction;
            }
            catch (Exception ex)
            {
                Log.Logger.Error($"{Constants.ChangeState}: {Constants.Message}: {ex.Message}\n " +
                                 $"{Constants.StackTrace}: {ex.StackTrace}\n {Constants.InnerException}: {ex.InnerException}");
            }
        }