Example #1
0
        protected virtual CommandViewItem GetChangedCommand(ICommand source, ICommand target)
        {
            var result = new CommandViewItem
            {
                CommandKey   = this.GetCommandKey(source),
                CommandName  = source.CommandPrefix,
                LeftCommand  = source,
                RightCommand = target,
                Database     = this.GetCommandDatabase(source)
            };

            string sourceStr = CommandSerializer.Serialize(source);
            string targetStr = CommandSerializer.Serialize(target);

            result.Group = String.CompareOrdinal(sourceStr, targetStr) == 0 ? Groups.Unmodified : Groups.Changed;

            return(result);
        }
Example #2
0
        private void ApplyChanges_Click(object sender, EventArgs e)
        {
            string   commandText = this.CommandContent.Text;
            ICommand command     = null;

            try
            {
                MemoryStream stream = new MemoryStream();
                using (var writer = new StreamWriter(stream))
                {
                    writer.Write(commandText);
                    writer.Flush();
                    stream.Flush();
                    stream.Seek(0, SeekOrigin.Begin);
                    var reader = CommandSerializer.GetReader(stream);
                    reader.MoveToContent();
                    SerializationContext context = SerializationCommandFactory.GetSerializationContext();
                    command = SerializationCommandFactory.DeserializeCommand(reader, context);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Invalid command text format. Cannot deserialize the command.", "Desirizalization Error");
                return;
            }

            if (command == null)
            {
                MessageBox.Show("Invalid command text format. Cannot deserialize the command.", "Desirizalization Error");
                return;
            }

            if (this.selectedCommand == null)
            {
                MessageBox.Show("Hm... Command to be updated not found.", "Strange error.");
                return;
            }

            this.diff.Commands.Insert(this.diff.Commands.IndexOf(this.selectedCommand), command);
            this.diff.Commands.Remove(this.selectedCommand);
            this.BindCommandText(command);
        }
Example #3
0
        private void commandsView_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            CommandViewItem command = null;
            string          path    = this.commandsView.SelectedItems[0].SubItems[1].Text;

            foreach (var cmd in this.data)
            {
                if (string.CompareOrdinal(cmd.CommandKey, path) == 0)
                {
                    command = cmd;
                    break;
                }
            }

            if (command == null)
            {
                MessageBox.Show("Command not found... Something is going wrong.");
            }
            else
            {
                string assemblyPath = Assembly.GetExecutingAssembly().Location;
                string dumpPath     = new FileInfo(assemblyPath).DirectoryName + "\\merge";
                if (!Directory.Exists(dumpPath))
                {
                    Directory.CreateDirectory(dumpPath);
                }

                string sourcePath = dumpPath + "\\source_" + command.CommandKey.GetHashCode() + ".txt";
                string targetPath = dumpPath + "\\target_" + command.CommandKey.GetHashCode() + ".txt";

                CommandSerializer.Serialize(sourcePath, command.LeftCommand);
                CommandSerializer.Serialize(targetPath, command.RightCommand);

                Process.Start("winmergeU.exe", "\"" + sourcePath + "\"" + " " + "\"" + targetPath + "\"");
            }
        }
Example #4
0
        protected virtual IList <CommandViewItem> FilterCommands(IList <CommandViewItem> commands)
        {
            var result = new List <CommandViewItem>();

            var groupTypes = new List <string>();

            for (int i = 0; i < this.clbGroupFilters.CheckedItems.Count; i++)
            {
                groupTypes.Add(this.clbGroupFilters.CheckedItems[i].ToString());
            }

            var commandTypes = new List <string>();

            for (int i = 0; i < this.clbCommandTypeFilter.CheckedItems.Count; i++)
            {
                commandTypes.Add(this.clbCommandTypeFilter.CheckedItems[i].ToString());
            }

            string searchText = this.SearchText.Text;

            foreach (var command in commands)
            {
                if (!groupTypes.Contains(command.Group.ToString()))
                {
                    continue;
                }

                if (!commandTypes.Contains((command.LeftCommand ?? command.RightCommand).CommandPrefix))
                {
                    continue;
                }

                var leftCommand = command.LeftCommand;
                if (leftCommand != null && FilterByCustomFilter(leftCommand) == null)
                {
                    continue;
                }

                var rightCommand = command.RightCommand;
                if (rightCommand != null && FilterByCustomFilter(rightCommand) == null)
                {
                    continue;
                }

                if (!string.IsNullOrEmpty(searchText))
                {
                    if (command.LeftCommand != null)
                    {
                        if (CommandSerializer.Serialize(command.LeftCommand).ToLower().Contains(searchText))
                        {
                            result.Add(command);
                            continue;
                        }
                    }

                    if (command.RightCommand != null)
                    {
                        if (CommandSerializer.Serialize(command.RightCommand).ToLower().Contains(searchText))
                        {
                            result.Add(command);
                            continue;
                        }
                    }

                    continue;
                }

                result.Add(command);
            }

            return(result);
        }
Example #5
0
 protected string GetCommandText(ICommand command)
 {
     return(CommandSerializer.Serialize(command));
 }