Example #1
0
        public HitsoundPreviewHelperVm()
        {
            _items = new ObservableCollection <HitsoundZone>();

            RhythmGuideCommand = new CommandImplementation(
                _ => {
                try {
                    if (_rhythmGuideWindow == null)
                    {
                        _rhythmGuideWindow         = new RhythmGuideWindow();
                        _rhythmGuideWindow.Closed += RhythmGuideWindowOnClosed;
                        _rhythmGuideWindow.Show();
                    }
                    else
                    {
                        _rhythmGuideWindow.Focus();
                    }
                } catch (Exception ex) { ex.Show(); }
            });
            AddCommand = new CommandImplementation(
                _ => {
                try {
                    var newZone = new HitsoundZone();
                    if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
                    {
                        var editor = EditorReaderStuff.GetBeatmapEditor(EditorReaderStuff.GetFullEditorReader(),
                                                                        out var selected);
                        if (selected.Count > 0)
                        {
                            newZone.XPos = selected[0].Pos.X;
                            newZone.YPos = editor.Beatmap.General["Mode"].IntValue == 3 ? -1 : selected[0].Pos.Y;
                        }
                        else
                        {
                            MessageBox.Show("Please select a hit object to fetch the coordinates.");
                        }
                    }
                    Items.Add(newZone);
                } catch (Exception ex) { ex.Show(); }
            });
            CopyCommand = new CommandImplementation(
                _ => {
                try {
                    int initialCount = Items.Count;
                    for (int i = 0; i < initialCount; i++)
                    {
                        if (Items[i].IsSelected)
                        {
                            Items.Add(Items[i].Copy());
                        }
                    }
                } catch (Exception ex) { ex.Show(); }
            });
            RemoveCommand = new CommandImplementation(
                _ => {
                try {
                    Items.RemoveAll(o => o.IsSelected);
                } catch (Exception ex) { ex.Show(); }
            });
        }
        public MainPage(bool server, string endpoint = null, int port = 10156, string username = null)
        {
            InitializeComponent();

            DataContext = this;

            CreateMatch          = new CommandImplementation(CreateMatch_Executed, CreateMatch_CanExecute);
            AddAllPlayersToMatch = new CommandImplementation(AddAllPlayersToMatch_Executed, AddAllPlayersToMatch_CanExecute);
            DestroyMatch         = new CommandImplementation(DestroyMatch_Executed, (_) => true);

            if (server)
            {
                Connection = new SystemServer();
                (Connection as SystemServer).Start();
            }
            else
            {
                Connection = new SystemClient(endpoint, port, username, TournamentAssistantShared.Models.Packets.Connect.ConnectTypes.Coordinator);
                (Connection as SystemClient).Start();
            }

            /*Connection.PlayerConnected += RefreshPlayerListBox;
             * Connection.PlayerDisconnected += RefreshPlayerListBox;
             * Connection.MatchCreated += RefreshPlayerListBox;
             * Connection.MatchDeleted += RefreshPlayerListBox;*/
        }
Example #3
0
        public ColourPoint(double time, IEnumerable <SpecialColour> colourSequence, ColourPointMode mode, ComboColourProject parentProject)
        {
            Time           = time;
            ColourSequence = new ObservableCollection <SpecialColour>(colourSequence);
            Mode           = mode;
            ParentProject  = parentProject;


            AddCommand = new CommandImplementation(sender => {
                var cm             = GetContextMenu(ParentProject);
                cm.PlacementTarget = sender as Button;
                cm.IsOpen          = true;
            });

            RemoveCommand = new CommandImplementation(item => {
                if (ColourSequence.Count == 0)
                {
                    return;
                }
                if (item == null)
                {
                    ColourSequence.RemoveAt(ColourSequence.Count - 1);
                }
                else
                {
                    ColourSequence.Remove(item as SpecialColour);
                }
            });
        }
        internal static bool ShowCompletion(ITextView view)
        {
            bool result = false;

            if (ISESnippetSessionManager.activeSession != null)
            {
                ISESnippetSessionManager.activeSession.Dismiss();
            }
            EditorImports.CompletionBroker.DismissAllSessions(view);
            if (!CommandImplementation.CanShowSnippet())
            {
                return(result);
            }
            ISESnippetSessionManager.activeSession = EditorImports.CompletionBroker.TriggerCompletion(view);
            if (ISESnippetSessionManager.activeSession == null)
            {
                return(result);
            }
            ISESnippetSessionManager.activeSession.Committed += ISESnippetSessionManager.eventHandlerSessionCommitted;
            ISESnippetSessionManager.activeSession.Dismissed += ISESnippetSessionManager.eventHandlerSessionDismissed;
            ISESnippetSessionManager.activeSession.SelectedCompletionSet.SelectionStatusChanged += ISESnippetSessionManager.eventHandlerSelectionChanged;
            ISESnippetSessionManager.activeSession.SelectedCompletionSet.SelectionStatus         = new CompletionSelectionStatus(ISESnippetSessionManager.activeSession.SelectedCompletionSet.Completions[0], true, true);
            ISESnippetSessionManager.selectedSnippet = (ISESnippetSessionManager.activeSession.SelectedCompletionSet.SelectionStatus.Completion.Properties["SnippetInfo"] as ISESnippet);
            ISESnippetSessionManager.insertSpan      = ISESnippetSessionManager.activeSession.SelectedCompletionSet.ApplicableTo;
            ISESnippetSessionManager.canFilter       = true;
            return(true);
        }
Example #5
0
        private void InvokeCommand(CommandImplementation commandImpl, CommandDefinition commandDefinition)
        {
            //argument from outiside can be aliased. now are normalized. (TODO: this can done once or is different command per command?)
            var localArgument = new Dictionary <string, object>();

            foreach (var item in this.config.programDefinition.State)
            {
                var localKey = item.Key;
                if (localKey.Length == 1)
                {
                    var par = commandImpl.Params.FirstOrDefault(x => x.Alias.ToString().Equals(localKey, StringComparison.InvariantCultureIgnoreCase));
                    if (par != null)
                    {
                        localKey = par.Name;
                    }
                }
                localArgument[localKey] = item.Value;
            }


            object instance = null;

            if (!commandImpl.Method.IsStatic)
            {
                instance = this.sp.GetService(commandImpl.Method.DeclaringType);
            }
            var args = new List <object>();

            //merge with data

            foreach (var par in commandImpl.Method.GetParameters())
            {
                object strValue = null;
                object val      = null;

                if (commandDefinition.Args != null && commandDefinition.Args.TryGetValue(par.Name, out strValue))
                {
                    val = TryGetValueFromString(args, par, strValue);
                }
                else if (localArgument.TryGetValue(par.Name, out strValue))
                {
                    val = TryGetValueFromString(args, par, strValue);
                }
                else if (commandImpl.DefaultArgs.TryGetValue(par.Name, out strValue))
                {
                    val = TryGetValueFromString(args, par, strValue);
                }
                else
                {
                    val = par.DefaultValue ?? null;
                }
                args.Add(val);
            }

            commandImpl.Method.Invoke(instance, args.ToArray());
        }
        public ComboColourProject()
        {
            ColourPoints = new ObservableCollection <ColourPoint>();
            ComboColours = new ObservableCollection <SpecialColour>();

            MaxBurstLength = 1;

            AddColourPointCommand = new CommandImplementation(_ => {
                double time = ColourPoints.Count > 1 ?
                              ColourPoints.Count(o => o.IsSelected) > 0 ? ColourPoints.Where(o => o.IsSelected).Max(o => o.Time) :
                              ColourPoints.Last().Time
                    : 0;
                if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
                {
                    try {
                        time = EditorReaderStuff.GetEditorTime();
                    } catch (Exception ex) {
                        ex.Show();
                    }
                }

                ColourPoints.Add(GenerateNewColourPoint(time));
            });

            RemoveColourPointCommand = new CommandImplementation(_ => {
                if (ColourPoints.Any(o => o.IsSelected))
                {
                    ColourPoints.RemoveAll(o => o.IsSelected);
                    return;
                }
                if (ColourPoints.Count > 0)
                {
                    ColourPoints.RemoveAt(ColourPoints.Count - 1);
                }
            });

            AddComboCommand = new CommandImplementation(_ => {
                if (ComboColours.Count >= 8)
                {
                    return;
                }
                ComboColours.Add(ComboColours.Count > 0
                    ? new SpecialColour(ComboColours[ComboColours.Count - 1].Color, $"Combo{ComboColours.Count + 1}")
                    : new SpecialColour(Colors.White, $"Combo{ComboColours.Count + 1}"));
            });

            RemoveComboCommand = new CommandImplementation(_ => {
                if (ComboColours.Count > 0)
                {
                    ComboColours.RemoveAt(ComboColours.Count - 1);
                }
            });
        }
Example #7
0
        public TimingCopierVm()
        {
            _importPath = "";
            _exportPath = "";
            _resnapMode = "Number of beats between objects stays the same";
            _snap1      = 16;
            _snap2      = 12;

            ImportLoadCommand = new CommandImplementation(
                _ => {
                try {
                    string path = IOHelper.GetCurrentBeatmap();
                    if (path != "")
                    {
                        ImportPath = path;
                    }
                } catch (Exception ex) {
                    ex.Show();
                }
            });

            ImportBrowseCommand = new CommandImplementation(
                _ => {
                string[] paths = IOHelper.BeatmapFileDialog(restore: !SettingsManager.Settings.CurrentBeatmapDefaultFolder);
                if (paths.Length != 0)
                {
                    ImportPath = paths[0];
                }
            });

            ExportLoadCommand = new CommandImplementation(
                _ => {
                try {
                    string path = IOHelper.GetCurrentBeatmap();
                    if (path != "")
                    {
                        ExportPath = path;
                    }
                } catch (Exception ex) {
                    ex.Show();
                }
            });

            ExportBrowseCommand = new CommandImplementation(
                _ => {
                string[] paths = IOHelper.BeatmapFileDialog(true, !SettingsManager.Settings.CurrentBeatmapDefaultFolder);
                if (paths.Length != 0)
                {
                    ExportPath = string.Join("|", paths);
                }
            });
        }
        protected RelevantObjectsGenerator()
        {
            Settings = new GeneratorSettings(this);

            // Make command
            GeneratorSettingsCommand = new CommandImplementation(
                e => {
                try {
                    var settingsWindow = new GeneratorSettingsWindow(Settings);
                    settingsWindow.ShowDialog();
                } catch (Exception ex) { MessageBox.Show(ex.Message); }
            });
        }
Example #9
0
        protected RelevantObjectsGenerator(GeneratorSettings settings)
        {
            Settings = settings;

            // Make command
            GeneratorSettingsCommand = new CommandImplementation(
                e => {
                try {
                    var settingsWindow = new GeneratorSettingsWindow(Settings);
                    settingsWindow.ShowDialog();
                } catch (Exception ex) { ex.Show(); }
            });
        }
Example #10
0
        public RhythmGuideVm()
        {
            GuideGeneratorArgs = new RhythmGuide.RhythmGuideGeneratorArgs();

            ImportLoadCommand = new CommandImplementation(
                _ => {
                try {
                    var path = IOHelper.GetCurrentBeatmap();
                    if (path != "")
                    {
                        GuideGeneratorArgs.Paths = new[] { path };
                    }
                }
                catch (Exception ex) {
                    ex.Show();
                }
            });

            ImportBrowseCommand = new CommandImplementation(
                _ => {
                var paths = IOHelper.BeatmapFileDialog(true, !SettingsManager.Settings.CurrentBeatmapDefaultFolder);
                if (paths.Length != 0)
                {
                    GuideGeneratorArgs.Paths = paths;
                }
            });

            ExportLoadCommand = new CommandImplementation(
                _ => {
                try {
                    var path = IOHelper.GetCurrentBeatmap();
                    if (path != "")
                    {
                        GuideGeneratorArgs.ExportPath = path;
                    }
                }
                catch (Exception ex) {
                    ex.Show();
                }
            });

            ExportBrowseCommand = new CommandImplementation(
                _ => {
                var paths = IOHelper.BeatmapFileDialog(restore: !SettingsManager.Settings.CurrentBeatmapDefaultFolder);
                if (paths.Length != 0)
                {
                    GuideGeneratorArgs.ExportPath = paths[0];
                }
            });
        }
Example #11
0
        /// <summary>
        /// Dereferences cursors returned by a stored procedure.
        /// </summary>
        /// <param name="cmd">The command.</param>
        /// <param name="implementation">The implementation.</param>
        protected static int?DereferenceCursors(NpgsqlCommand cmd, CommandImplementation <NpgsqlCommand> implementation)
        {
            if (cmd == null)
            {
                throw new ArgumentNullException(nameof(cmd), $"{nameof(cmd)} is null.");
            }
            if (cmd.Connection == null)
            {
                throw new ArgumentNullException($"{nameof(cmd)}.{nameof(cmd.Connection)}", $"{nameof(cmd)}.{nameof(cmd.Connection)} is null.");
            }
            if (implementation == null)
            {
                throw new ArgumentNullException(nameof(implementation), $"{nameof(implementation)} is null.");
            }

            var closeTransaction = false;

            try
            {
                if (cmd.Transaction == null)
                {
                    cmd.Transaction  = cmd.Connection.BeginTransaction();
                    closeTransaction = true;
                }

                var sql = new StringBuilder();
                using (var reader = cmd.ExecuteReader())
                    while (reader.Read())
                    {
                        sql.AppendLine($"FETCH ALL IN \"{reader.GetString(0)}\";");
                    }

                using (var cmd2 = new NpgsqlCommand())
                {
                    cmd2.Connection     = cmd.Connection;
                    cmd2.Transaction    = cmd.Transaction;
                    cmd2.CommandTimeout = cmd.CommandTimeout;
                    cmd2.CommandText    = sql.ToString();
                    cmd2.CommandType    = CommandType.Text;
                    return(implementation(cmd2));
                }
            }
            finally
            {
                if (closeTransaction)
                {
                    cmd.Transaction !.Commit();
                }
            }
        }
        public HitsoundPreviewHelperVM()
        {
            _items = new ObservableCollection <HitsoundZone>();

            RhythmGuideCommand = new CommandImplementation(
                _ => {
                try {
                    if (_rhythmGuideWindow == null)
                    {
                        _rhythmGuideWindow         = new RhythmGuideWindow();
                        _rhythmGuideWindow.Closed += RhythmGuideWindowOnClosed;
                        _rhythmGuideWindow.Show();
                    }
                    else
                    {
                        _rhythmGuideWindow.Focus();
                    }
                } catch (Exception ex) { MessageBox.Show(ex.Message); }
            });
            AddCommand = new CommandImplementation(
                _ => {
                try {
                    Items.Add(new HitsoundZone());
                } catch (Exception ex) { MessageBox.Show(ex.Message); }
            });
            CopyCommand = new CommandImplementation(
                _ => {
                try {
                    int initialCount = Items.Count;
                    for (int i = 0; i < initialCount; i++)
                    {
                        if (Items[i].IsSelected)
                        {
                            Items.Add(Items[i].Copy());
                        }
                    }
                } catch (Exception ex) { MessageBox.Show(ex.Message); }
            });
            RemoveCommand = new CommandImplementation(
                _ => {
                try {
                    Items.RemoveAll(o => o.IsSelected);
                } catch (Exception ex) { MessageBox.Show(ex.Message); }
            });
        }
Example #13
0
        public ComboColourProject()
        {
            ColourPoints = new ObservableCollection <ColourPoint>();
            ComboColours = new ObservableCollection <SpecialColour>();

            MaxBurstLength = 1;

            AddColourPointCommand = new CommandImplementation(_ => {
                ColourPoints.Add(ColourPoints.Count > 0
                    ? (ColourPoint)ColourPoints[ColourPoints.Count - 1].Clone()
                    : GenerateNewColourPoint());
            });

            RemoveColourPointCommand = new CommandImplementation(_ => {
                if (ColourPoints.Any(o => o.IsSelected))
                {
                    ColourPoints.RemoveAll(o => o.IsSelected);
                    return;
                }
                if (ColourPoints.Count > 0)
                {
                    ColourPoints.RemoveAt(ColourPoints.Count - 1);
                }
            });

            AddComboCommand = new CommandImplementation(_ => {
                if (ComboColours.Count >= 8)
                {
                    return;
                }
                ComboColours.Add(ComboColours.Count > 0
                    ? new SpecialColour(ComboColours[ComboColours.Count - 1].Color, $"Combo{ComboColours.Count + 1}")
                    : new SpecialColour(Colors.White, $"Combo{ComboColours.Count + 1}"));
            });

            RemoveComboCommand = new CommandImplementation(_ => {
                if (ComboColours.Count > 0)
                {
                    ComboColours.RemoveAt(ComboColours.Count - 1);
                }
            });
        }
        public MainWindow()
        {
            InitializeComponent();
            Titlebar.IsMainWindow             = true;
            Worker.DoWork                    += WorkerOnDoWork;
            Worker.WorkerSupportsCancellation = true;

            fileWatcher.EnableRaisingEvents = true;
            fileWatcher.Changed            += FileWatcherOnChanged;
            fileWatcher.Renamed            += FileWatcherOnChanged;
            fileWatcher.Deleted            += FileWatcherOnChanged;
            fileWatcher.Created            += FileWatcherOnChanged;

            CheckFileExistance();

            DialogYesPrompt = new CommandImplementation(OnYesDialogClick);
            DialogNoPrompt  = new CommandImplementation(OnNoDialogClick);

            //Check if the PC is connected to the internet, and show a warning if it is.
#if !DEBUG
            if (NetworkInterface.GetIsNetworkAvailable())
            {
                ShowStartDialog("This machine is currently connected to the internet! We would not advise creating or storing Groestlcoin wallets on a machine which is connected to the internet as it poses a risk\n\nAlthough we advise users to use the Generator offline we do allow the application to be run whilst connected to the internet.\n\nWould you like to continue?");
            }
            else
            {
                DialogHelper.ShowOKDialog(DH, "Online Status: Offline");
            }


            CpuTimer.Interval  = new TimeSpan(0, 0, 0, 0, 1024);
            CpuTimer.IsEnabled = true;

            CpuTimer.Tick += (sender, args) => {
                var counterPercent = Convert.ToInt32(CpuCounter.NextValue());
                uxCPULbl.Text = counterPercent + "%";
            };
#endif
            Titlebar.Clicked += (sender, args) => ThemeSelector.ThemeSelector.SetCurrentThemeDictionary(this, new Uri((Titlebar.uxThemeSelector.SelectedItem as ComboBoxItem).Tag.ToString(), UriKind.Relative));
        }
        public SnappingToolsProjectWindow(SnappingToolsProject project)
        {
            InitializeComponent();
            Project     = project;
            DataContext = this;

            AddCommand = new CommandImplementation(_ => {
                var newSave = new SnappingToolsSaveSlot {
                    Name = $"Save {Project.SaveSlots.Count + 1}"
                };
                Project.SaveToSlot(newSave, false);
                newSave.Activate();
                Project.SaveSlots.Add(newSave);
            });
            RemoveCommand = new CommandImplementation(_ => {
                if (SaveSlotsGrid.SelectedItems.Count == 0 && Project.SaveSlots.Count > 0)
                {
                    Project.SaveSlots.RemoveAt(Project.SaveSlots.Count - 1);
                    return;
                }

                Project.SaveSlots.RemoveAll(o => SaveSlotsGrid.SelectedItems.Contains(o));
            });
            DuplicateCommand = new CommandImplementation(_ => {
                var itemsToDupe = new SnappingToolsSaveSlot[SaveSlotsGrid.SelectedItems.Count];
                var i           = 0;
                foreach (var listSelectedItem in SaveSlotsGrid.SelectedItems)
                {
                    itemsToDupe[i++] = (SnappingToolsSaveSlot)listSelectedItem;
                }
                foreach (var listSelectedItem in itemsToDupe)
                {
                    var clone   = (SnappingToolsSaveSlot)listSelectedItem.Clone();
                    clone.Name += " - Copy";
                    Project.SaveSlots.Insert(SaveSlotsGrid.Items.IndexOf(listSelectedItem) + 1, clone);
                }
            });
        }
        public MainPage(bool server, string endpoint = null, int port = 10156, string username = null, string password = null)
        {
            InitializeComponent();

            DataContext = this;

            CreateStandardMatch = new CommandImplementation(CreateStandardMatch_Executed, CreateStandardMatch_CanExecute);
            CreateBRMatch       = new CommandImplementation(CreateBRMatch_Executed, CreateStandardMatch_CanExecute);

            DestroyMatch = new CommandImplementation(DestroyMatch_Executed, (_) => true);

            MoveAllRight      = new CommandImplementation(MoveAllRight_Executed, MoveAllRight_CanExecute);
            MoveSelectedRight = new CommandImplementation(MoveSelectedRight_Executed, MoveSelectedRight_CanExecute);
            MoveAllLeft       = new CommandImplementation(MoveAllLeft_Executed, MoveAllLeft_CanExecute);
            MoveSelectedLeft  = new CommandImplementation(MoveSelectedLeft_Executed, MoveSelectedLeft_CanExecute);

            ListBoxLeft = new ObservableCollection <Player>();
            Application.Current.Dispatcher.BeginInvoke(new Action(() => { BindingOperations.EnableCollectionSynchronization(ListBoxLeft, ListBoxLeftSync); }));
            ListBoxRight = new ObservableCollection <Player>();
            Application.Current.Dispatcher.BeginInvoke(new Action(() => { BindingOperations.EnableCollectionSynchronization(ListBoxRight, ListBoxRightSync); }));

            if (server)
            {
                Connection = new SystemServer();
                (Connection as SystemServer).Start();
            }
            else
            {
                Connection = new SystemClient(endpoint, port, username, TournamentAssistantShared.Models.Packets.Connect.ConnectTypes.Coordinator, password: password);
                (Connection as SystemClient).Start();
            }

            (Connection as SystemClient).PlayerConnected    += MainPage_PlayerConnected;
            (Connection as SystemClient).PlayerDisconnected += MainPage_PlayerDisconnected;
            (Connection as SystemClient).ConnectedToServer  += MainPage_ConnectedToServer;
        }
        protected override int? Execute(CommandExecutionToken<OleDbCommand, OleDbParameter> executionToken, CommandImplementation<OleDbCommand> implementation, object state)
        {
            if (executionToken == null)
                throw new ArgumentNullException("executionToken", "executionToken is null.");
            if (implementation == null)
                throw new ArgumentNullException("implementation", "implementation is null.");

            var startTime = DateTimeOffset.Now;
            OnExecutionStarted(executionToken, startTime, state);

            try
            {
                using (var con = CreateConnection())
                {
                    using (var cmd = new OleDbCommand())
                    {
                        cmd.Connection = con;
                        if (DefaultCommandTimeout.HasValue)
                            cmd.CommandTimeout = (int)DefaultCommandTimeout.Value.TotalSeconds;
                        cmd.CommandText = executionToken.CommandText;
                        cmd.CommandType = executionToken.CommandType;
                        foreach (var param in executionToken.Parameters)
                            cmd.Parameters.Add(param);

                        executionToken.ApplyCommandOverrides(cmd);

                        var rows = implementation(cmd);
                        executionToken.RaiseCommandExecuted(cmd, rows);
                        OnExecutionFinished(executionToken, startTime, DateTimeOffset.Now, rows, state);
                        return rows;
                    }
                }
            }
            catch (Exception ex)
            {
                OnExecutionError(executionToken, startTime, DateTimeOffset.Now, ex, state);
                throw;
            }

        }
Example #18
0
        /// <summary>
        /// Executes the specified operation.
        /// </summary>
        /// <param name="executionToken">The execution token.</param>
        /// <param name="implementation">The implementation that handles processing the result of the command.</param>
        /// <param name="state">User supplied state.</param>
        protected override int?Execute(CommandExecutionToken <NpgsqlCommand, NpgsqlParameter> executionToken, CommandImplementation <NpgsqlCommand> implementation, object?state)
        {
            if (executionToken == null)
            {
                throw new ArgumentNullException(nameof(executionToken), $"{nameof(executionToken)} is null.");
            }
            if (implementation == null)
            {
                throw new ArgumentNullException(nameof(implementation), $"{nameof(implementation)} is null.");
            }

            var startTime = DateTimeOffset.Now;

            OnExecutionStarted(executionToken, startTime, state);

            try
            {
                using (var cmd = new NpgsqlCommand())
                {
                    cmd.Connection = m_Connection;
                    if (m_Transaction != null)
                    {
                        cmd.Transaction = m_Transaction;
                    }
                    executionToken.PopulateCommand(cmd, DefaultCommandTimeout);

                    int?rows;

                    if (((PostgreSqlCommandExecutionToken)executionToken).DereferenceCursors)
                    {
                        rows = DereferenceCursors(cmd, implementation);
                    }
                    else
                    {
                        rows = implementation(cmd);
                    }

                    executionToken.RaiseCommandExecuted(cmd, rows);
                    OnExecutionFinished(executionToken, startTime, DateTimeOffset.Now, rows, state);
                    return(rows);
                }
            }
            catch (Exception ex)
            {
                OnExecutionError(executionToken, startTime, DateTimeOffset.Now, ex, state);
                throw;
            }
        }
        /// <summary>
        /// Executes the specified operation.
        /// </summary>
        /// <param name="executionToken">The execution token.</param>
        /// <param name="implementation">The implementation that handles processing the result of the command.</param>
        /// <param name="state">User supplied state.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">
        /// executionToken;executionToken is null.
        /// or
        /// implementation;implementation is null.
        /// </exception>
        protected override int?Execute(CommandExecutionToken <NpgsqlCommand, NpgsqlParameter> executionToken, CommandImplementation <NpgsqlCommand> implementation, object?state)
        {
            if (executionToken == null)
            {
                throw new ArgumentNullException(nameof(executionToken), $"{nameof(executionToken)} is null.");
            }
            if (implementation == null)
            {
                throw new ArgumentNullException(nameof(implementation), $"{nameof(implementation)} is null.");
            }

            var startTime = DateTimeOffset.Now;

            OnExecutionStarted(executionToken, startTime, state);

            try
            {
                using (var cmd = new NpgsqlCommand())
                {
                    cmd.Connection  = m_Connection;
                    cmd.Transaction = m_Transaction;
                    if (DefaultCommandTimeout.HasValue)
                    {
                        cmd.CommandTimeout = (int)DefaultCommandTimeout.Value.TotalSeconds;
                    }
                    cmd.CommandText = executionToken.CommandText;
                    cmd.CommandType = executionToken.CommandType;
                    foreach (var param in executionToken.Parameters)
                    {
                        cmd.Parameters.Add(param);
                    }

                    int?rows;

                    if (((PostgreSqlCommandExecutionToken)executionToken).DereferenceCursors)
                    {
                        rows = DereferenceCursors(cmd, implementation);
                    }
                    else
                    {
                        rows = implementation(cmd);
                    }

                    executionToken.RaiseCommandExecuted(cmd, rows);
                    OnExecutionFinished(executionToken, startTime, DateTimeOffset.Now, rows, state);
                    return(rows);
                }
            }
            catch (Exception ex)
            {
                OnExecutionError(executionToken, startTime, DateTimeOffset.Now, ex, state);
                throw;
            }
        }
Example #20
0
    protected override int?Execute(CommandExecutionToken <OleDbCommand, OleDbParameter> executionToken, CommandImplementation <OleDbCommand> implementation, object?state)
    {
        if (executionToken == null)
        {
            throw new ArgumentNullException(nameof(executionToken), $"{nameof(executionToken)} is null.");
        }
        if (implementation == null)
        {
            throw new ArgumentNullException(nameof(implementation), $"{nameof(implementation)} is null.");
        }
        var currentToken = executionToken as AccessCommandExecutionToken;

        if (currentToken == null)
        {
            throw new ArgumentNullException(nameof(executionToken), "only AccessCommandExecutionToken is supported.");
        }

        var startTime = DateTimeOffset.Now;

        try
        {
            using (var con = CreateConnection())
            {
                int?rows = null;
                while (currentToken != null)
                {
                    OnExecutionStarted(currentToken, startTime, state);
                    using (var cmd = new OleDbCommand())
                    {
                        cmd.Connection = con;
                        currentToken.PopulateCommand(cmd, DefaultCommandTimeout);

                        if (currentToken.ExecutionMode == AccessCommandExecutionMode.Materializer)
                        {
                            rows = implementation(cmd);
                        }
                        else if (currentToken.ExecutionMode == AccessCommandExecutionMode.ExecuteScalarAndForward)
                        {
                            if (currentToken.ForwardResult == null)
                            {
                                throw new InvalidOperationException("currentToken.ExecutionMode is ExecuteScalarAndForward, but currentToken.ForwardResult is null.");
                            }

                            currentToken.ForwardResult(cmd.ExecuteScalar());
                        }
                        else
                        {
                            rows = cmd.ExecuteNonQuery();
                        }
                        currentToken.RaiseCommandExecuted(cmd, rows);
                        OnExecutionFinished(currentToken, startTime, DateTimeOffset.Now, rows, state);
                    }
                    currentToken = currentToken.NextCommand;
                }
                return(rows);
            }
        }
        catch (Exception ex)
        {
            OnExecutionError(executionToken, startTime, DateTimeOffset.Now, ex, state);
            throw;
        }
    }
 /// <summary>
 /// Helper method for executing the operation.
 /// </summary>
 /// <param name="implementation">The implementation.</param>
 /// <param name="state">The state.</param>
 protected void ExecuteCore(CommandImplementation <TCommand> implementation, object state)
 {
     Prepare().Execute(implementation, state);
 }
Example #22
0
        /// <summary>
        /// Executes the specified operation.
        /// </summary>
        /// <param name="executionToken">The execution token.</param>
        /// <param name="implementation">The implementation that handles processing the result of the command.</param>
        /// <param name="state">User supplied state.</param>
        /// <returns>System.Nullable&lt;System.Int32&gt;.</returns>
        /// <exception cref="ArgumentNullException">executionToken;executionToken is null.
        /// or
        /// implementation;implementation is null.</exception>
        protected override int?Execute(CommandExecutionToken <MySqlCommand, MySqlParameter> executionToken, CommandImplementation <MySqlCommand> implementation, object?state)
        {
            if (executionToken == null)
            {
                throw new ArgumentNullException(nameof(executionToken), $"{nameof(executionToken)} is null.");
            }
            if (implementation == null)
            {
                throw new ArgumentNullException(nameof(implementation), $"{nameof(implementation)} is null.");
            }

            var startTime = DateTimeOffset.Now;

            OnExecutionStarted(executionToken, startTime, state);

            try
            {
                using (var con = CreateConnection())
                {
                    using (var cmd = new MySqlCommand())
                    {
                        cmd.Connection = con;
                        if (DefaultCommandTimeout.HasValue)
                        {
                            cmd.CommandTimeout = (int)DefaultCommandTimeout.Value.TotalSeconds;
                        }
                        cmd.CommandText = executionToken.CommandText;
                        cmd.CommandType = executionToken.CommandType;
                        foreach (var param in executionToken.Parameters)
                        {
                            cmd.Parameters.Add(param);
                        }

                        executionToken.ApplyCommandOverrides(cmd);

                        var rows = implementation(cmd);

                        executionToken.RaiseCommandExecuted(cmd, rows);
                        OnExecutionFinished(executionToken, startTime, DateTimeOffset.Now, rows, state);
                        return(rows);
                    }
                }
            }
            catch (Exception ex)
            {
                OnExecutionError(executionToken, startTime, DateTimeOffset.Now, ex, state);
                throw;
            }
        }
Example #23
0
        protected override int? Execute(CommandExecutionToken<SQLiteCommand, SQLiteParameter> executionToken, CommandImplementation<SQLiteCommand> implementation, object state)
        {
            if (executionToken == null)
                throw new ArgumentNullException("executionToken", "executionToken is null.");
            if (implementation == null)
                throw new ArgumentNullException("implementation", "implementation is null.");

            var mode = DisableLocks ? LockType.None : (executionToken as SQLiteCommandExecutionToken)?.LockType ?? LockType.Write;

            var startTime = DateTimeOffset.Now;
            OnExecutionStarted(executionToken, startTime, state);

            IDisposable lockToken = null;
            try
            {
                switch (mode)
                {
                    case LockType.Read: lockToken = SyncLock.ReaderLock(); break;
                    case LockType.Write: lockToken = SyncLock.WriterLock(); break;
                }

                using (var con = CreateConnection())
                {
                    using (var cmd = new SQLiteCommand())
                    {
                        cmd.Connection = con;
                        if (DefaultCommandTimeout.HasValue)
                            cmd.CommandTimeout = (int)DefaultCommandTimeout.Value.TotalSeconds;
                        cmd.CommandText = executionToken.CommandText;
                        //TODO: add potential check for this type.
                        cmd.CommandType = executionToken.CommandType;
                        foreach (var param in executionToken.Parameters)
                            cmd.Parameters.Add(param);

                        executionToken.ApplyCommandOverrides(cmd);

                        var rows = implementation(cmd);
                        executionToken.RaiseCommandExecuted(cmd, rows);
                        OnExecutionFinished(executionToken, startTime, DateTimeOffset.Now, rows, state);
                        return rows;
                    }
                }
            }
            catch (Exception ex)
            {
                OnExecutionError(executionToken, startTime, DateTimeOffset.Now, ex, state);
                throw;
            }
            finally
            {
                if (lockToken != null)
                    lockToken.Dispose();
            }
        }
    /// <summary>
    /// Executes the specified operation.
    /// </summary>
    /// <param name="executionToken">The execution token.</param>
    /// <param name="implementation">The implementation that handles processing the result of the command.</param>
    /// <param name="state">User supplied state.</param>
    protected override int?Execute(CommandExecutionToken <OleDbCommand, OleDbParameter> executionToken, CommandImplementation <OleDbCommand> implementation, object?state)
    {
        if (executionToken == null)
        {
            throw new ArgumentNullException(nameof(executionToken), $"{nameof(executionToken)} is null.");
        }
        if (implementation == null)
        {
            throw new ArgumentNullException(nameof(implementation), $"{nameof(implementation)} is null.");
        }

        var startTime = DateTimeOffset.Now;

        OnExecutionStarted(executionToken, startTime, state);

        try
        {
            using (var cmd = new OleDbCommand())
            {
                cmd.Connection  = m_Connection;
                cmd.Transaction = m_Transaction;
                executionToken.PopulateCommand(cmd, DefaultCommandTimeout);

                var rows = implementation(cmd);
                executionToken.RaiseCommandExecuted(cmd, rows);
                OnExecutionFinished(executionToken, startTime, DateTimeOffset.Now, rows, state);
                return(rows);
            }
        }
        catch (Exception ex)
        {
            OnExecutionError(executionToken, startTime, DateTimeOffset.Now, ex, state);
            throw;
        }
    }
Example #25
0
 int?ICommandDataSource <TCommand, TParameter> .Execute(CommandExecutionToken <TCommand, TParameter> executionToken, CommandImplementation <TCommand> implementation, object state)
 {
     return(Execute(executionToken, implementation, state));
 }
Example #26
0
 /// <summary>
 /// Executes the specified operation.
 /// </summary>
 /// <param name="executionToken">The execution token.</param>
 /// <param name="implementation">The implementation that handles processing the result of the command.</param>
 /// <param name="state">User supplied state.</param>
 protected internal abstract int?Execute(CommandExecutionToken <TCommand, TParameter> executionToken, CommandImplementation <TCommand> implementation, object state);
 /// <summary>
 /// Executes the specified implementation.
 /// </summary>
 /// <param name="implementation">The implementation.</param>
 /// <param name="state">The state.</param>
 public int?Execute(CommandImplementation <TCommand> implementation, object?state)
 {
     return(m_DataSource.Execute(this, implementation, state));
 }
Example #28
0
        /// <summary>
        /// Executes the specified operation.
        /// </summary>
        /// <param name="executionToken">The execution token.</param>
        /// <param name="implementation">The implementation that handles processing the result of the command.</param>
        /// <param name="state">User supplied state.</param>
        /// <exception cref="ArgumentNullException">
        /// executionToken;executionToken is null.
        /// or
        /// implementation;implementation is null.
        /// </exception>
        protected override int?Execute(CommandExecutionToken <SQLiteCommand, SQLiteParameter> executionToken, CommandImplementation <SQLiteCommand> implementation, object?state)
        {
            if (executionToken == null)
            {
                throw new ArgumentNullException(nameof(executionToken), $"{nameof(executionToken)} is null.");
            }
            if (implementation == null)
            {
                throw new ArgumentNullException(nameof(implementation), $"{nameof(implementation)} is null.");
            }

            var mode = DisableLocks ? LockType.None : (executionToken as SQLiteCommandExecutionToken)?.LockType ?? LockType.Write;

            var startTime = DateTimeOffset.Now;

            OnExecutionStarted(executionToken, startTime, state);

            IDisposable?lockToken = null;

            try
            {
                switch (mode)
                {
                case LockType.Read: lockToken = SyncLock.ReaderLock(); break;

                case LockType.Write: lockToken = SyncLock.WriterLock(); break;
                }

                using (var cmd = new SQLiteCommand())
                {
                    cmd.Connection = m_Connection;
                    if (m_Transaction != null)
                    {
                        cmd.Transaction = m_Transaction;
                    }
                    executionToken.PopulateCommand(cmd, DefaultCommandTimeout);

                    var rows = implementation(cmd);
                    executionToken.RaiseCommandExecuted(cmd, rows);
                    OnExecutionFinished(executionToken, startTime, DateTimeOffset.Now, rows, state);
                    return(rows);
                }
            }
            catch (Exception ex)
            {
                OnExecutionError(executionToken, startTime, DateTimeOffset.Now, ex, state);
                throw;
            }
            finally
            {
                if (lockToken != null)
                {
                    lockToken.Dispose();
                }
            }
        }
Example #29
0
        protected override int?Execute(CommandExecutionToken <SQLiteCommand, SQLiteParameter> executionToken, CommandImplementation <SQLiteCommand> implementation, object?state)
        {
            if (executionToken == null)
            {
                throw new ArgumentNullException(nameof(executionToken), $"{nameof(executionToken)} is null.");
            }
            if (implementation == null)
            {
                throw new ArgumentNullException(nameof(implementation), $"{nameof(implementation)} is null.");
            }

            var mode = DisableLocks ? LockType.None : (executionToken as SQLiteCommandExecutionToken)?.LockType ?? LockType.Write;

            var startTime = DateTimeOffset.Now;

            OnExecutionStarted(executionToken, startTime, state);

            IDisposable?lockToken = null;

            try
            {
                switch (mode)
                {
                case LockType.Read: lockToken = SyncLock.ReaderLock(); break;

                case LockType.Write: lockToken = SyncLock.WriterLock(); break;
                }

                using (var con = CreateConnection())
                {
                    using (var cmd = new SQLiteCommand())
                    {
                        cmd.Connection = con;
                        if (DefaultCommandTimeout.HasValue)
                        {
                            cmd.CommandTimeout = (int)DefaultCommandTimeout.Value.TotalSeconds;
                        }
                        cmd.CommandText = executionToken.CommandText;
                        //TODO: add potential check for this type.
                        cmd.CommandType = executionToken.CommandType;
                        foreach (var param in executionToken.Parameters)
                        {
                            cmd.Parameters.Add(param);
                        }

                        executionToken.ApplyCommandOverrides(cmd);

                        var rows = implementation(cmd);
                        executionToken.RaiseCommandExecuted(cmd, rows);
                        OnExecutionFinished(executionToken, startTime, DateTimeOffset.Now, rows, state);
                        return(rows);
                    }
                }
            }
            catch (Exception ex)
            {
                OnExecutionError(executionToken, startTime, DateTimeOffset.Now, ex, state);
                throw;
            }
            finally
            {
                if (lockToken != null)
                {
                    lockToken.Dispose();
                }
            }
        }
Example #30
0
        /// <summary>
        /// Executes the specified operation.
        /// </summary>
        /// <param name="executionToken">The execution token.</param>
        /// <param name="implementation">The implementation that handles processing the result of the command.</param>
        /// <param name="state">User supplied state.</param>
        /// <exception cref="ArgumentNullException">
        /// executionToken;executionToken is null.
        /// or
        /// implementation;implementation is null.
        /// </exception>
        protected override int?Execute(CommandExecutionToken <OleDbCommand, OleDbParameter> executionToken, CommandImplementation <OleDbCommand> implementation, object state)
        {
            if (executionToken == null)
            {
                throw new ArgumentNullException("executionToken", "executionToken is null.");
            }
            if (implementation == null)
            {
                throw new ArgumentNullException("implementation", "implementation is null.");
            }

            var startTime = DateTimeOffset.Now;

            OnExecutionStarted(executionToken, startTime, state);

            try
            {
                using (var cmd = new OleDbCommand())
                {
                    cmd.Connection = m_Connection;
                    if (m_Transaction != null)
                    {
                        cmd.Transaction = m_Transaction;
                    }
                    if (DefaultCommandTimeout.HasValue)
                    {
                        cmd.CommandTimeout = (int)DefaultCommandTimeout.Value.TotalSeconds;
                    }
                    cmd.CommandText = executionToken.CommandText;
                    cmd.CommandType = executionToken.CommandType;
                    foreach (var param in executionToken.Parameters)
                    {
                        cmd.Parameters.Add(param);
                    }

                    var rows = implementation(cmd);
                    executionToken.RaiseCommandExecuted(cmd, rows);
                    OnExecutionFinished(executionToken, startTime, DateTimeOffset.Now, rows, state);
                    return(rows);
                }
            }
            catch (Exception ex)
            {
                OnExecutionError(executionToken, startTime, DateTimeOffset.Now, ex, state);
                throw;
            }
        }
Example #31
0
        protected override int?Execute(CommandExecutionToken <OleDbCommand, OleDbParameter> executionToken, CommandImplementation <OleDbCommand> implementation, object state)
        {
            if (executionToken == null)
            {
                throw new ArgumentNullException("executionToken", "executionToken is null.");
            }
            if (implementation == null)
            {
                throw new ArgumentNullException("implementation", "implementation is null.");
            }
            var currentToken = executionToken as AccessCommandExecutionToken;

            if (currentToken == null)
            {
                throw new ArgumentNullException("executionToken", "only AccessCommandExecutionToken is supported.");
            }

            var startTime = DateTimeOffset.Now;

            try
            {
                using (var con = CreateConnection())
                {
                    int?rows = null;
                    while (currentToken != null)
                    {
                        OnExecutionStarted(currentToken, startTime, state);
                        using (var cmd = new OleDbCommand())
                        {
                            cmd.Connection = con;
                            if (DefaultCommandTimeout.HasValue)
                            {
                                cmd.CommandTimeout = (int)DefaultCommandTimeout.Value.TotalSeconds;
                            }
                            cmd.CommandText = currentToken.CommandText;
                            cmd.CommandType = currentToken.CommandType;
                            foreach (var param in currentToken.Parameters)
                            {
                                cmd.Parameters.Add(param);
                            }

                            currentToken.ApplyCommandOverrides(cmd);

                            if (currentToken.ExecutionMode == AccessCommandExecutionMode.Materializer)
                            {
                                rows = implementation(cmd);
                            }
                            else if (currentToken.ExecutionMode == AccessCommandExecutionMode.ExecuteScalarAndForward)
                            {
                                currentToken.ForwardResult(cmd.ExecuteScalar());
                            }
                            else
                            {
                                rows = cmd.ExecuteNonQuery();
                            }
                            executionToken.RaiseCommandExecuted(cmd, rows);
                            OnExecutionFinished(currentToken, startTime, DateTimeOffset.Now, rows, state);
                        }
                        currentToken = currentToken.NextCommand;
                    }
                    return(rows);
                }
            }
            catch (Exception ex)
            {
                OnExecutionError(executionToken, startTime, DateTimeOffset.Now, ex, state);
                throw;
            }
        }
        public MetadataManagerVm()
        {
            _importPath = "";
            _exportPath = "";

            _useComboColours = true;
            ComboColours     = new ObservableCollection <ComboColour>();
            SpecialColours   = new ObservableCollection <SpecialColour>();

            ImportLoadCommand = new CommandImplementation(
                _ => {
                var path = IOHelper.GetCurrentBeatmap();
                if (path != "")
                {
                    ImportPath = path;
                }
            });

            ImportBrowseCommand = new CommandImplementation(
                _ => {
                var paths = IOHelper.BeatmapFileDialog(restore: !SettingsManager.Settings.CurrentBeatmapDefaultFolder);
                if (paths.Length != 0)
                {
                    ImportPath = paths[0];
                }
            });

            ImportCommand = new CommandImplementation(
                _ => {
                ImportFromBeatmap(ImportPath);
            });

            ExportLoadCommand = new CommandImplementation(
                _ => {
                var path = IOHelper.GetCurrentBeatmap();
                if (path != "")
                {
                    ExportPath = path;
                }
            });

            ExportBrowseCommand = new CommandImplementation(
                _ => {
                var paths = IOHelper.BeatmapFileDialog(true, !SettingsManager.Settings.CurrentBeatmapDefaultFolder);
                if (paths.Length != 0)
                {
                    ExportPath = string.Join("|", paths);
                }
            });

            AddCommand = new CommandImplementation(_ => {
                if (ComboColours.Count >= 8)
                {
                    return;
                }
                ComboColours.Add(ComboColours.Count > 0
                    ? new ComboColour(ComboColours[ComboColours.Count - 1].Color)
                    : new ComboColour(Colors.White));
            });

            RemoveCommand = new CommandImplementation(_ => {
                if (ComboColours.Count > 0)
                {
                    ComboColours.RemoveAt(ComboColours.Count - 1);
                }
            });

            AddSpecialCommand = new CommandImplementation(_ => {
                SpecialColours.Add(SpecialColours.Count > 0
                    ? new SpecialColour(SpecialColours[SpecialColours.Count - 1].Color)
                    : new SpecialColour(Colors.White));
            });

            RemoveSpecialCommand = new CommandImplementation(_ => {
                if (SpecialColours.Count > 0)
                {
                    SpecialColours.RemoveAt(SpecialColours.Count - 1);
                }
            });


            PropertyChanged += OnPropertyChanged;
        }
Example #33
0
        protected override int? Execute(CommandExecutionToken<OleDbCommand, OleDbParameter> executionToken, CommandImplementation<OleDbCommand> implementation, object state)
        {
            if (executionToken == null)
                throw new ArgumentNullException("executionToken", "executionToken is null.");
            if (implementation == null)
                throw new ArgumentNullException("implementation", "implementation is null.");
            var currentToken = executionToken as AccessCommandExecutionToken;
            if (currentToken == null)
                throw new ArgumentNullException("executionToken", "only AccessCommandExecutionToken is supported.");

            var startTime = DateTimeOffset.Now;

            try
            {
                using (var con = CreateConnection())
                {
                    int? rows = null;
                    while (currentToken != null)
                    {
                        OnExecutionStarted(currentToken, startTime, state);
                        using (var cmd = new OleDbCommand())
                        {
                            cmd.Connection = con;
                            if (DefaultCommandTimeout.HasValue)
                                cmd.CommandTimeout = (int)DefaultCommandTimeout.Value.TotalSeconds;
                            cmd.CommandText = currentToken.CommandText;
                            cmd.CommandType = currentToken.CommandType;
                            foreach (var param in currentToken.Parameters)
                                cmd.Parameters.Add(param);

                            currentToken.ApplyCommandOverrides(cmd);

                            if (currentToken.ExecutionMode == AccessCommandExecutionMode.Materializer)
                                rows = implementation(cmd);
                            else if (currentToken.ExecutionMode == AccessCommandExecutionMode.ExecuteScalarAndForward)
                                currentToken.ForwardResult(cmd.ExecuteScalar());
                            else
                                rows = cmd.ExecuteNonQuery();
                            executionToken.RaiseCommandExecuted(cmd, rows);
                            OnExecutionFinished(currentToken, startTime, DateTimeOffset.Now, rows, state);
                        }
                        currentToken = currentToken.NextCommand;
                    }
                    return rows;
                }
            }
            catch (Exception ex)
            {
                OnExecutionError(executionToken, startTime, DateTimeOffset.Now, ex, state);
                throw;
            }
        }