static int Main(string[] arguments)
        {
            Arguments splitArguments=null;
            try
            {
                 splitArguments = new Arguments(arguments);
                ExceptionFunctions.ForceVerbose = splitArguments.Exists(Arguments.DefaultArgumentPrefix + "verbose");
                string operation = splitArguments.String(Arguments.OperationArgument, true);

                AdapterFunctions.RunOperation(operation, splitArguments);
                return 0;
            } catch (Exception error)
            {
                string message = string.Empty
                    + Arguments.ErrorArgument + " " + ExceptionFunctions.Write(error, !ExceptionFunctions.ForceVerbose) + Environment.NewLine
                    + "Arguments: " + string.Join(" ", arguments) + Environment.NewLine;
                //if (ExceptionFunctions.ForceVerbose)
                //{
                //    message += ProcessFunctions.WriteProcessHeritage() + Environment.NewLine;
                //    message += ProcessFunctions.WriteSystemVariables() + Environment.NewLine;
                //}
                Console.Write(message);
                if (ExceptionFunctions.ForceVerbose)
                {
                    SwishFunctions.MessageTextBox(message, false);
                }
                return -1;
            }
        }
        static int Main(string[] arguments)
        {
            try
            {
                Arguments splitArguments = new Arguments(arguments);
                ExceptionFunctions.ForceVerbose = splitArguments.Exists(Arguments.DefaultArgumentPrefix + "verbose");
                string inputFileName = FileFunctions.AdjustFileName(splitArguments.String(Arguments.InputArgument, true));
                string variable = splitArguments.String(Arguments.DefaultArgumentPrefix + "variable", true);
                string operation = splitArguments.String(Arguments.DefaultArgumentPrefix + "operation", false);

                if (string.IsNullOrWhiteSpace(operation))
                {
                    operation = "mean";
                }

                CollapseOpperation operationCode = (CollapseOpperation)Enum.Parse(typeof(CollapseOpperation), operation, true);

                double result = AdapterFunctions.Collapse(inputFileName, variable, operationCode);

                Console.Write(result.ToString());
                return 0;
            } catch (Exception error)
            {
                string message = Arguments.ErrorArgument + " " + ExceptionFunctions.Write(error, !ExceptionFunctions.ForceVerbose);
                //if (ExceptionFunctions.ForceVerbose)
                //{
                //    message += ProcessFunctions.WriteProcessHeritage();
                //    message += ProcessFunctions.WriteSystemVariables();
                //}
                Console.Write(message);
                if (ExceptionFunctions.ForceVerbose)
                {
                    SwishFunctions.MessageTextBox(message, false);
                }
                return -1;
            }
        }
        public static void RunOperation(string operation, Arguments splitArguments)
        {
            switch (operation)
            {
            case FormatOperation:
                {
                    string inputFileName = FileFunctions.AdjustFileName(splitArguments.String(Arguments.InputArgument, true));
                    string outputFileName = splitArguments.OutputFileName();
                    List<string> variableNames = splitArguments.StringList(Arguments.DefaultArgumentPrefix + "variables", true, true);
                    string format = splitArguments.String(Arguments.DefaultArgumentPrefix + "format", true);
                    Format(inputFileName, outputFileName, variableNames, format);
                    Console.Write(outputFileName);
                }
                break;

            case CompressOperation:
                {
                    string inputFileName = FileFunctions.AdjustFileName(splitArguments.String(Arguments.InputArgument, true));
                    string outputFileName = splitArguments.OutputFileName();
                    Compress(inputFileName, outputFileName);
                    Console.Write(outputFileName);
                }
                break;

            case FileNameOperation:
                {
                    string inputFileName = FileFunctions.AdjustFileName(splitArguments.String(Arguments.InputArgument, true));
                    string fileName = Path.GetFileName(inputFileName);
                    Console.Write(fileName);
                }
                break;

            case FileNameWithoutExtensionOperation:
                {
                    string inputFileName = FileFunctions.AdjustFileName(splitArguments.String(Arguments.InputArgument, true));
                    string fileName = Path.GetFileNameWithoutExtension(inputFileName);
                    Console.Write(fileName);
                }
                break;

            case GenerateOperation:
                {
                    string inputFileName = FileFunctions.AdjustFileName(splitArguments.String(Arguments.InputArgument, true));
                    string outputFileName = splitArguments.OutputFileName();
                    string variableName = splitArguments.String(Arguments.DefaultArgumentPrefix + "variable", true);
                    string expression = splitArguments.String(Arguments.DefaultArgumentPrefix + "expression", true);
                    string type = splitArguments.String(Arguments.DefaultArgumentPrefix + "type", false);
                    Generate(inputFileName, outputFileName, variableName, type, expression);
                    Console.Write(outputFileName);
                }
                break;

            case PasswordOperation:
                {
                    string prompt = splitArguments.String(Arguments.DefaultArgumentPrefix + "prompt", false);
                    bool requireEntry = splitArguments.Bool(Arguments.DefaultArgumentPrefix + "ignoreCache", false);
                    string password = Password(prompt, requireEntry);
                    Console.Write(password);
                }
                break;

            case TransposeOperation:
                {
                    string inputFileName = FileFunctions.AdjustFileName(splitArguments.String(Arguments.InputArgument, true));
                    string outputFileName = splitArguments.OutputFileName();
                    Transpose(inputFileName, outputFileName);
                    Console.Write(outputFileName);
                }
                break;

            case SortOperation:
                {
                    string inputFileName = FileFunctions.AdjustFileName(splitArguments.String(Arguments.InputArgument, true));
                    List<string> variableNames = splitArguments.StringList(Arguments.DefaultArgumentPrefix + "variables", true, true);
                    string outputFileName = splitArguments.OutputFileName();
                    outputFileName = Sort(inputFileName, variableNames, outputFileName);
                    Console.Write(outputFileName);
                }
                break;

            case SelectCloumnsOperation:
                {
                    string inputFileName = FileFunctions.AdjustFileName(splitArguments.String(Arguments.InputArgument, true));
                    List<string> variableNames = splitArguments.StringList(Arguments.DefaultArgumentPrefix + "variables", true, true);
                    string outputFileName = splitArguments.OutputFileName();
                    SelectColumns(inputFileName, outputFileName, variableNames);
                    Console.Write(outputFileName);
                }
                break;

            case SelectRecordsOperation:
                {
                    string inputFileName = FileFunctions.AdjustFileName(splitArguments.String(Arguments.InputArgument, true));
                    string expression = splitArguments.String(Arguments.DefaultArgumentPrefix + "expression", true);
                    string outputFileName = splitArguments.OutputFileName();
                    Select(inputFileName, outputFileName, expression);
                    Console.Write(outputFileName);
                }
                break;

            case SaveOperation:
                {
                    string inputFileName = FileFunctions.AdjustFileName(splitArguments.String(Arguments.InputArgument, true));
                    string outputFileName = splitArguments.OutputFileName();
                    SaveFile(inputFileName, outputFileName);
                    Console.Write(outputFileName);
                }
                break;

            case MergeOperation:
                {
                    string input1FileName = FileFunctions.AdjustFileName(splitArguments.String(Arguments.InputArgument + "1", true));
                    string input2FileName = FileFunctions.AdjustFileName(splitArguments.String(Arguments.InputArgument + "2", true));
                    List<string> variableNames = splitArguments.StringList(Arguments.DefaultArgumentPrefix + "variables", true, true);
                    string outputFileName = splitArguments.OutputFileName();
                    List<MergeRecordResult> keep = splitArguments.EnumList<MergeRecordResult>(Arguments.DefaultArgumentPrefix + "keep", false, false);

                    string keepMergeString = FileFunctions.AdjustFileName(splitArguments.String(Arguments.DefaultArgumentPrefix + "keepMerge", false));
                    bool keepMerge;
                    if (!string.IsNullOrWhiteSpace(keepMergeString))
                    {
                        keepMerge = bool.Parse(keepMergeString.ToLower());
                    } else
                    {
                        keepMerge = false;
                    }

                    Merge(input1FileName, input2FileName, variableNames, outputFileName, keepMerge, keep);
                    Console.Write(outputFileName);
                }
                break;

            case DoScriptOperation:
                {
                    string inputFileName = FileFunctions.AdjustFileName(splitArguments.String(Arguments.DefaultArgumentPrefix + "filename", true));
                    string log = StataFunctions.RunScript(inputFileName, false);
                    Console.Write(log);
                }
                break;

            case CommandOperation:
                {
                    string inputFileName = FileFunctions.AdjustFileName(splitArguments.String(Arguments.InputArgument, true));
                    string command = splitArguments.String(Arguments.DefaultArgumentPrefix + "command", true);
                    string outputFileName = splitArguments.OutputFileName();
                    StataCommand(inputFileName, outputFileName, command);
                    Console.Write(outputFileName);
                }
                break;

            case AppendOperation:
                {
                    string input1FileName = FileFunctions.AdjustFileName(splitArguments.String(Arguments.InputArgument + "1", true));
                    string input2FileName = FileFunctions.AdjustFileName(splitArguments.String(Arguments.InputArgument + "2", true));
                    string outputFileName = splitArguments.OutputFileName();
                    outputFileName = Append(input1FileName, input2FileName, outputFileName);
                    Console.Write(outputFileName);
                }
                break;

            case RemoveColumnsOperation:
                {
                    string inputFileName = FileFunctions.AdjustFileName(splitArguments.String(Arguments.InputArgument, true));
                    List<string> variableNames = splitArguments.StringList(Arguments.DefaultArgumentPrefix + "variables", true, true);
                    string outputFileName = splitArguments.OutputFileName();
                    RemoveColumns(inputFileName, outputFileName, variableNames);
                    Console.Write(outputFileName);
                }
                break;

            case DisplayOperation:
                {
                    string inputFileName = FileFunctions.AdjustFileName(splitArguments.String(Arguments.InputArgument, true));
                    Display(inputFileName);
                }
                break;

            case DisplayClientOperation:
                {
                    string inputFileName = FileFunctions.AdjustFileName(splitArguments.String(Arguments.InputArgument, true));
                    DisplayClient(inputFileName);
                }
                break;

            case TestOperation:
                {
                    bool silent = splitArguments.Exists(Arguments.DefaultArgumentPrefix + "silent");

                    List<string> lines = new List<string>();
                    lines.Add("Arguments: " + splitArguments.ArgumentString);
                    lines.Add("Startup path: " + Application.StartupPath);
                    lines.Add("Working directory: " + Environment.CurrentDirectory);

                    if (ProcessFunctions.KeplerProcess != null)
                    {
                        lines.Add("Keper process:");
                        lines.Add(ProcessFunctions.WriteProcessInformation(ProcessFunctions.KeplerProcess));
                    } else
                    {
                        lines.Add("Keper process: Not found");
                    }

                    lines.Add("Current process heritage: ");

                    lines.AddRange(ProcessFunctions.WriteProcessHeritage().Split(new string[] { Environment.NewLine }, StringSplitOptions.None));
                    lines.AddRange(ProcessFunctions.WriteSystemVariables().Split(new string[] { Environment.NewLine }, StringSplitOptions.None));
                    if (!silent)
                    {
                        SwishFunctions.MessageTextBox("Test display", lines, false);
                    }
                    Console.Write(string.Join(Environment.NewLine, lines));
                }
                break;

            case TemporaryFileNameOperation:
                {
                    string fileName = FileFunctions.TempoaryOutputFileName(string.Empty);
                    if (FileFunctions.FileExists(fileName))
                    {
                        File.Delete(fileName);
                    }
                    Console.Write(fileName);
                }
                break;

            case ReplaceOperation:
                {
                    string inputFileName = FileFunctions.AdjustFileName(splitArguments.String(Arguments.InputArgument, true));
                    string outputFileName = splitArguments.OutputFileName();
                    string condition = splitArguments.String(Arguments.DefaultArgumentPrefix + "condition", true);
                    string value = splitArguments.String(Arguments.DefaultArgumentPrefix + "value", true);
                    Replace(inputFileName, outputFileName, condition, value);
                    Console.Write(outputFileName);
                }
                break;

            default:
                throw new Exception("Unknown operation \"" + operation + "\"");
            }
        }