Ejemplo n.º 1
0
 private void ExecuteCommand(CommandBase command, List <CommandParameter> commandsParameters, List <string> consoleInputs = null)
 {
     try
     {
         command.OnLog += Command_OnLog;
         command.OnReplacedAutoIncrementInSubCommand += _parameterManager_OnReplacedAutoIncrement;
         if (command.CanExecute(commandsParameters))
         {
             var commandName         = command.CommandName;
             var processedParameters = commandName != "AddParameterCommand"
                     ? _parameterManager.ResolveParameters(StoredDataService, commandsParameters)
                     : commandsParameters;
             var timer = new Stopwatch(); timer.Start();
             command.ConsoleService = new ConsoleService(LoggerService, consoleInputs);
             command.Execute(processedParameters);
             var tab  = ExecutionMode == ExecutionModeTypes.Single ? "" : "\t";
             var time = StringFormats.MillisecondsToHumanTime(timer.ElapsedMilliseconds);
             Log($"{tab}Executed command in {time}");
         }
         else
         {
             command.ExecuteHelp();
         }
     }
     catch (Exception ex)
     {
         throw;
     }
     finally
     {
         command.OnLog -= Command_OnLog;
     }
 }
Ejemplo n.º 2
0
        public override void Execute(List <CommandParameter> parameters)
        {
            var path        = GetStringParameterValue(parameters, CommandPathParameter.Name);
            var name        = GetStringParameterValue(parameters, CommandNameParameter.Name);
            var description = GetStringParameterValue(parameters, CommandDescriptionParameter.Name);

            if (StoredDataService.ExistsTemplate(name))
            {
                throw new TemplateNameRepeatedException();
            }
            if (!FileService.ExistsDirectory(path))
            {
                throw new PathNotFoundException(path);
            }
            if (!FileService.ExistsTemplateConfigFile(path))
            {
                throw new TemplateConfigFileNotFoundException(path);
            }
            if (!StringFormats.IsValidLogicalName(name))
            {
                throw new InvalidStringFormatException("Name can only contains alphanumeric characters");
            }

            StoredDataService.AddTemplate(path, name, description);

            Log($"Template stored!");
        }
Ejemplo n.º 3
0
        public Dictionary <string, object> ExecuteAction(ProjectState projectState, ActionBase action, List <ActionParameter> actionParameters, List <string> consoleInputs = null)
        {
            var outputParameters = new Dictionary <string, object>();

            try
            {
                action.OnLog += Action_OnLog;
                if (action.CanExecute(projectState, actionParameters))
                {
                    var timer = new Stopwatch(); timer.Start();
                    action.ConsoleService = new ConsoleService(consoleInputs);
                    outputParameters      = action.PrepareExecution(projectState, actionParameters);
                    var time = StringFormats.MillisecondsToHumanTime(timer.ElapsedMilliseconds);
                }
                else
                {
                    action.ExecuteHelp();
                }
            }
            catch (Exception ex)
            {
                OnErrorExecution?.Invoke(this, new ErrorExecutionActionEventArgs(action, ex));
                throw;
            }
            finally
            {
                action.OnLog -= Action_OnLog;
            }
            return(outputParameters);
        }
Ejemplo n.º 4
0
        private static string[] GetCommandArgs(string replacedCommand)
        {
            var args = StringFormats.StringToParams(replacedCommand);

            for (int i = 0; i < args.Length; i++)
            {
                var arg = args[i];
                args[i] = arg.Replace("$$", "\"");
            }
            return(args);
        }
Ejemplo n.º 5
0
 public static String ToTrueFalse(object value, string passValue, StringFormats format = StringFormats.BigFirst)
 {
     if (format == StringFormats.BigFirst)
     {
         return((value.ToString().Equals(passValue)) ? "True" : "False");
     }
     else if (format == StringFormats.Capitals)
     {
         return((value.ToString().Equals(passValue)) ? "TRUE" : "FALSE");
     }
     else
     {
         return((value.ToString().Equals(passValue)) ? "true" : "false");
     }
 }
Ejemplo n.º 6
0
        private byte[] FromString(string aValue, StringFormats resultFormat)
        {
            switch (resultFormat)
            {
            case StringFormats.BASE64:
                return(Convert.FromBase64String(aValue));

            case StringFormats.HEX:
            case StringFormats.BIT:
                return(HexConvert.FromString(aValue));

            default:
                return(Convert.FromBase64String(aValue));
            }
        }
Ejemplo n.º 7
0
 public static String ToPassFail(object value, string passValue, StringFormats format = StringFormats.BigFirst)
 {
     if (format == StringFormats.BigFirst)
     {
         return((value.ToString().Equals(passValue)) ? "Pass" : "Fail");
     }
     else if (format == StringFormats.Capitals)
     {
         return((value.ToString().Equals(passValue)) ? "PASS" : "FAIL");
     }
     else
     {
         return((value.ToString().Equals(passValue)) ? "pass" : "fail");
     }
 }
Ejemplo n.º 8
0
        private static string ConvertString(byte[] aValue, StringFormats resultFormat)
        {
            switch (resultFormat)
            {
            case StringFormats.BASE64:
                return(Convert.ToBase64String(aValue));

            case StringFormats.HEX:
                return(HexConvert.ToString(aValue));

            case StringFormats.BIT:
                return(BitConverter.ToString(aValue).Replace("-", ""));

            default:
                return(Convert.ToBase64String(aValue));
            }
        }
Ejemplo n.º 9
0
        public override void Execute(ProjectState project, List <ActionParameter> parameters)
        {
            var name     = GetStringParameterValue(parameters, NameParameter);
            var token    = GetStringParameterValue(parameters, OAuthTokenKeyParameter);
            var uri      = GetStringParameterValue(parameters, UriParameter);
            var repeated = project.GithubSettings
                           .FirstOrDefault(k => k.OauthToken == token);

            if (repeated != null)
            {
                throw new Exception("Repeated Github setting");
            }

            var standardUri = StringFormats.ParseStringUri(uri)
                              ?? throw new Exception("Invalid uri");

            var decriptedToken = CryptoService.Decrypt(token);

            project.GithubSettings.Add(new GithubSetting(name, standardUri.ToString(), decriptedToken));
        }
Ejemplo n.º 10
0
        public override void Execute(ProjectState project, List <ActionParameter> parameters)
        {
            var name            = GetStringParameterValue(parameters, NameParameter);
            var organizationUri = GetStringParameterValue(parameters, OrganizationUriParameter);
            var token           = GetStringParameterValue(parameters, TokenParameter);
            //var projectId = GetStringParameterValue(parameters, ProjectIdParameter);

            var repeated = project.AzurePipelineSettings
                           .FirstOrDefault(k => k.Name == name);

            if (repeated != null)
            {
                throw new Exception("Repeated Azure pipeline setting");
            }
            var standardUri = StringFormats.ParseStringUri(organizationUri)
                              ?? throw new Exception("Invalid organization uri");

            var decriptedToken = CryptoService.Decrypt(token);

            //var validGuid = Guid.Parse(projectId);
            project.AzurePipelineSettings.Add(new AzurePipelineSetting(name, standardUri.ToString(), decriptedToken));
        }
Ejemplo n.º 11
0
        static void Main(string[] args)
        {
            //var argsV2 = StringFormats.StringToParams(string.Join(" ", args));
            _loggerService = new LoggerService();
            _loggerService.Log("###### INITIALIZED DYNAMICS CLI ######");
            LogRecievedArgs(args);
            bool isRecursive = args.Any(k => k.Length > 0 && k.First() == '\"');
            var  argsV2      = isRecursive ? StringFormats.StringToParams(string.Join(" ", args)) : args;

            LogProcessedArgs(argsV2);

            var storedData = StoredDataManager.GetStoredData();

            _loggerService = new LoggerService();
            IRegistryService   registryService   = new RegistryService();
            ICryptoService     cryptoService     = new CryptoService(registryService);
            IStoredDataService storedDataService = new StoredDataService(storedData, cryptoService);

            commandManager        = new CommandManager(_loggerService, storedDataService, cryptoService);
            commandManager.OnLog += CommandManager_OnLog;

            RegisterCommands(storedDataService, registryService, cryptoService);

            try
            {
                var inputCommand = new InputRequest(argsV2);
                commandManager.ExecuteInputRequest(inputCommand);
            }
            catch (PathNotFoundException ex)
            {
                ExceptionManager.RaiseException(_loggerService, $"Path '{ex.Message}' does not exists");
            }
            catch (Exception ex)
            {
                ExceptionManager.RaiseException(_loggerService, $"Throwed uncatched exception: {ex.ToString()}");
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        ///		computes the hash code and converts it to string
        /// </summary>
        /// <param name="inputText">input text to be hashed</param>
        /// <param name="hashingType">type of hashing to use</param>
        /// <returns>hashed string</returns>
        private static string ComputeHash(string inputText, HashingTypes hashingType, EncodingTypes encodingTypes, StringFormats resultFormat)
        {
            HashAlgorithm HA          = getHashAlgorithm(hashingType);
            Encoding      textEncoder = getEncodingTypes(encodingTypes);

            //get byte representation of input text
            byte[] inputBytes = textEncoder.GetBytes(inputText);


            //hash the input byte array
            byte[] output = HA.ComputeHash(inputBytes);

            //convert output byte array to a string
            return(ConvertString(output, resultFormat));
        }
Ejemplo n.º 13
0
 public static String ToTrueFalseWithMinMax(object value, string minValue, string maxValue, StringFormats format = StringFormats.BigFirst)
 {
     if (value is int || value is short || value is byte)
     {
         int minInt   = Convert.ToInt32(minValue);
         int maxInt   = Convert.ToInt32(minValue);
         int valueInt = Convert.ToInt32(value);
         if (format == StringFormats.BigFirst)
         {
             return((valueInt >= minInt && valueInt <= maxInt) ? "True" : "False");
         }
         else if (format == StringFormats.Capitals)
         {
             return((valueInt >= minInt && valueInt <= maxInt) ? "TRUE" : "FALSE");
         }
         else
         {
             return((valueInt >= minInt && valueInt <= maxInt) ? "true" : "false");
         }
     }
     else if (value is float || value is double || value is string)
     {
         double minInt   = Convert.ToDouble(minValue);
         double maxInt   = Convert.ToDouble(minValue);
         double valueInt = Convert.ToDouble(value);
         if (format == StringFormats.BigFirst)
         {
             return((valueInt >= minInt && valueInt <= maxInt) ? "True" : "False");
         }
         else if (format == StringFormats.Capitals)
         {
             return((valueInt >= minInt && valueInt <= maxInt) ? "TRUE" : "FALSE");
         }
         else
         {
             return((valueInt >= minInt && valueInt <= maxInt) ? "true" : "false");
         }
     }
     else
     {
         throw new Exception("변환불가능(ToTrueFalseWithMinMax) - value:" + value);
     }
 }
Ejemplo n.º 14
0
        /// <summary>
        /// Once this runs, you have the tab delimited data.  You'll have to add it to your spreadsheet and manually move stuff around.
        /// </summary>
        private static void CrossExamination()
        {
            //Purpose of this is to get some tickers.  Adjust for Splits.  Create moving averages.  Document Crosses.
            var amznFile = Path.Combine(Vars.Paths.YahooFinance, "AMZN.csv");
            var spyFile  = Path.Combine(Vars.Paths.YahooFinance, "SPY.csv");

            if (!File.Exists(amznFile))
            {
                ETL.Scraping.Yahoo.GetTickerHistory("AMZN", amznFile);
            }
            if (!File.Exists(spyFile))
            {
                ETL.Scraping.Yahoo.GetTickerHistory("SPY", spyFile);
            }

            //Get the source data.
            var iSpy  = InstrumentMeasure.FromYahoo("SPY");
            var iAmzn = InstrumentMeasure.FromYahoo("AMZN");

            //Update the measures
            ETL.Measure.Trading.UpdateAllSMAs(iAmzn);
            ETL.Measure.Trading.UpdateAllSMAs(iSpy);
            ETL.Measure.Trading.DoCrosses(iAmzn);
            ETL.Measure.Trading.DoCrosses(iSpy);
            ETL.Transform.Trading.FindAndFixSplits(iAmzn);

            var fmt = StringFormats.BuildDelimiter("\t", 5);
            var csv = string.Format(fmt,
                                    "Ticker",
                                    "Event",
                                    "Date",
                                    "Note",
                                    "AMZN Next Open"
                                    );

            //SPY
            foreach (var ev in iSpy.EODEvents.OrderBy(rd => rd.EODDate))
            {
                var nextDay = ev.EODDate.NextTradingDay();
                var eq      = iAmzn.Measures.Values.Where(rd => rd.EODDate == nextDay).FirstOrDefault();
                csv += string.Format(fmt,
                                     "SPY",
                                     ev.CrossEventType,
                                     ev.EODDate.ToShortDateString(),
                                     ev.EventInt1,
                                     Math.Round(eq.Open, 2)
                                     );

                Trace.WriteLine(ev.EODDate.ToShortDateString() + " - " + ev.CrossEventType.ToString() + " - " + ev.EventInt1);
            }

            //AMZN
            foreach (var ev in iAmzn.EODEvents.OrderBy(rd => rd.EODDate))
            {
                var nextDay = ev.EODDate.NextTradingDay();
                var eq      = iAmzn.Measures.Values.Where(rd => rd.EODDate == nextDay).FirstOrDefault();
                csv += string.Format(fmt,
                                     "AMZN",
                                     ev.CrossEventType,
                                     ev.EODDate.ToShortDateString(),
                                     ev.EventInt1,
                                     Math.Round(eq.OrigOpen > 0.0M ? eq.OrigOpen : eq.Open, 2)
                                     );

                Trace.WriteLine(ev.EODDate.ToShortDateString() + " - " + ev.CrossEventType.ToString() + " - " + ev.EventInt1);
            }

            Trace.WriteLine(csv);
        }
Ejemplo n.º 15
0
        static void Main(string[] args)
        {
            _loggerService = new LoggerService();
            _loggerService.Log("###### INITIALIZED CLI ######");
            LogRecievedArgs(args);
            bool isRecursive = args.Any(k => k.Length > 0 && k.First() == '\"');
            var  argsV2      = isRecursive ? StringFormats.StringToParams(string.Join(" ", args)) : args;

            LogProcessedArgs(argsV2);
            var storedData = StoredDataManager.GetStoredData();

            IRegistryService   registryService   = new RegistryService();
            ICryptoService     cryptoService     = new CryptoService(registryService);
            IStoredDataService storedDataService = new StoredDataService(storedData, cryptoService);

            commandManager        = new CommandManager(_loggerService, storedDataService, cryptoService);
            commandManager.OnLog += CommandManager_OnLog;

            RegisterCommands(storedDataService, registryService, cryptoService);

            try
            {
                var inputCommand = new InputRequest(argsV2);
                commandManager.ExecuteInputRequest(inputCommand);
            }
            catch (DuplicateCommandException ex)
            {
                ExceptionManager.RaiseException(_loggerService, $"Found {ex.Commands.Count} commands with the same name in different namespaces. In this case is necessary use the namespace for execute it. Commands: {string.Join(",", ex.Commands.ToArray())}");
            }
            catch (CommandNotFoundException)
            {
                ExceptionManager.RaiseException(_loggerService, $"Command not found. Use 'help' for check the available commands");
            }
            catch (InvalidParamsException)
            {
                ExceptionManager.RaiseException(_loggerService, $"This command cannot be executed with this combination of parameters");
            }
            catch (InvalidParamNameException ex)
            {
                ExceptionManager.RaiseException(_loggerService, $"Invalid parameter name '{ex.Message}'");
            }
            catch (NotArgumentsException)
            {
                ExceptionManager.RaiseException(_loggerService, $"Check all the params with 'help' command");
            }
            catch (NotValidCommandNameException ex)
            {
                ExceptionManager.RaiseException(_loggerService, $"Invalid command name '{ex.Message}'");
            }
            catch (AliasRepeatedException ex)
            {
                ExceptionManager.RaiseException(_loggerService, $"Alias '{ex.Message}' is already used");
            }
            catch (AliasNotFoundException ex)
            {
                ExceptionManager.RaiseException(_loggerService, $"Alias '{ex.Message}' is not registered");
            }
            catch (ParameterRepeatedException ex)
            {
                ExceptionManager.RaiseException(_loggerService, $"Parameter '{ex.Message}' is already used");
            }
            catch (ParameterNotFoundException ex)
            {
                ExceptionManager.RaiseException(_loggerService, $"Parameter '{ex.Message}' is not registered");
            }
            catch (InvalidParamException ex)
            {
                ExceptionManager.RaiseException(_loggerService, $"Cannot resolver parameter {ex.Message}");
            }
            catch (PathNotFoundException ex)
            {
                ExceptionManager.RaiseException(_loggerService, $"Path '{ex.Message}' does not exists");
            }
            catch (TemplateConfigFileNotFoundException)
            {
                ExceptionManager.RaiseException(_loggerService, $"Can't find '{Definitions.TemplateConfigFilename}' file in path");
            }
            catch (InvalidTemplateConfigFileException ex)
            {
                ExceptionManager.RaiseException(_loggerService, $"Config file '{Definitions.TemplateConfigFilename}' is invalid. Error parsing: {ex.Message}");
            }
            catch (InvalidStringFormatException ex)
            {
                ExceptionManager.RaiseException(_loggerService, $"Invalid string format. {ex.Message}");
            }
            catch (TemplateNameRepeatedException)
            {
                ExceptionManager.RaiseException(_loggerService, $"Template name repeated");
            }
            catch (TemplateNotFoundException)
            {
                ExceptionManager.RaiseException(_loggerService, $"Can't find any template with this name");
            }
            catch (RepositoryNotFoundException)
            {
                ExceptionManager.RaiseException(_loggerService, $"Can't find any repository with this name");
            }
            catch (PipelineConfigFileNotFoundException)
            {
                ExceptionManager.RaiseException(_loggerService, $"Can't find '{Definitions.PipelineConfigFilename}' file in path");
            }
            catch (InvalidPipelineConfigFileException ex)
            {
                ExceptionManager.RaiseException(_loggerService, $"Config file '{Definitions.PipelineConfigFilename}' is invalid. Error parsing: {ex.Message}");
            }
            catch (PipelineNameRepeatedException)
            {
                ExceptionManager.RaiseException(_loggerService, $"Pipeline name repeated");
            }
            catch (PipelineNotFoundException)
            {
                ExceptionManager.RaiseException(_loggerService, $"Can't find any pipeline with this name");
            }
            catch (Exception ex)
            {
                ExceptionManager.RaiseException(_loggerService, $"Throwed uncatched exception: {ex.ToString()}");
            }
            finally
            {
                _loggerService.Log("###### FINISHED! ######");
            }
        }
Ejemplo n.º 16
0
        public override void Execute(List <CommandParameter> parameters)
        {
            string path = string.Empty;

            if (IsParamOk(parameters, CommandNameParameter.Name))
            {
                var pipelineName = GetStringParameterValue(parameters, CommandNameParameter.Name);
                path = StoredDataService.GetPipelinePath(pipelineName);
            }
            else
            {
                path = GetStringParameterValue(parameters, CommandPathParameter.Name);
            }

            var debugMode = GetBoolParameterValue(parameters, DebugParameter.Name, false);;


            if (!FileService.ExistsFile(path))
            {
                throw new PathNotFoundException(path);
            }

            var pipelineConfig =
                ExceptionInLine.Run <DDPipelineConfig>(
                    () => { return(FileService.GetPipelineConfig(path)); },
                    (ex) => { throw new InvalidPipelineConfigFileException(ex.Message); });

            if (!FileService.IsValidPipelineConfiguration(pipelineConfig))
            {
                throw new InvalidPipelineConfigFileException();
            }

            var multipleCommandManager =
                new CommandManager(LoggerService, StoredDataService, CryptoService, CommandManager.ExecutionModeTypes.Multiple);

            multipleCommandManager.RegisterCommands(RegisteredCommands);
            multipleCommandManager.OnLog += MultipleCommandManager_OnLog;
            multipleCommandManager.OnReplacedAutoIncrementInCommand += MultipleCommandManager_OnReplacedAutoIncrementInSubCommand;

            RequestInputVariables(pipelineConfig);

            Log($"## Executing pipeline {pipelineConfig.PipelineName}...");
            Stopwatch sb                 = new Stopwatch(); sb.Start();
            int       counter            = 0;
            int       totalCommandsCound = pipelineConfig.Commands.Count;

            foreach (var commandDefinition in pipelineConfig.Commands)
            {
                var currentCounter = counter++;
                var commandName    = string.IsNullOrEmpty(commandDefinition.Alias) ? "" : commandDefinition.Alias;
                if (commandDefinition.IsDisabled)
                {
                    Log($"### [{currentCounter + 1}/{totalCommandsCound}] {commandName} | Skip command. Reason: Disabled");
                }
                else
                {
                    if (commandDefinition.IsIteration)
                    {
                        ExecuteIterationCommand(
                            multipleCommandManager,
                            commandDefinition.Command,
                            commandDefinition.ConsoleInputs,
                            pipelineConfig.PipelineConstants,
                            totalCommandsCound,
                            currentCounter,
                            commandName,
                            commandDefinition);
                    }
                    else
                    {
                        ExecuteCommand(
                            multipleCommandManager,
                            commandDefinition.Command,
                            commandDefinition.ConsoleInputs,
                            pipelineConfig.PipelineConstants,
                            totalCommandsCound,
                            currentCounter,
                            commandName);
                    }
                }
                if (debugMode)
                {
                    Console.WriteLine("---- ENABLED DEBUG MODE ----");
                    Console.WriteLine("---- Type any character for continue... ");
                    Console.WriteLine("---- ENABLED DEBUG MODE ----");
                    Console.ReadLine();
                }
            }
            var time = StringFormats.MillisecondsToHumanTime(sb.ElapsedMilliseconds);

            Log($"## Completed pipeline {pipelineConfig.PipelineName} in {time}");
        }
Ejemplo n.º 17
0
 public static string Hash(String inputText, HashingTypes hashingType, EncodingTypes encodingTypes, StringFormats resultFormat)
 {
     return(ComputeHash(inputText, hashingType, encodingTypes, resultFormat));
 }