Example #1
0
        public bool WithSMSService()
        {
            /*
             * SMS service initialization
             */
            if (!RequiredEnvironmentVariables.ContainsKey("TWILIO_ACCOUNT_SID") ||
                !RequiredEnvironmentVariables.ContainsKey("TWILIO_AUTH_TOKEN") ||
                !RequiredEnvironmentVariables.ContainsKey("TWILIO_FROM_PHONE_NO"))
            {
                LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, "TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN, TWILIO_FROM_PHONE_NO parameters must be provided and valid."), ProgramID, "Initialization");
                return(false);
            }

            SMSService = new BSMSServiceTwilio(
                RequiredEnvVars["TWILIO_ACCOUNT_SID"],
                RequiredEnvVars["TWILIO_AUTH_TOKEN"],
                RequiredEnvVars["TWILIO_FROM_PHONE_NO"],
                (string Message) =>
            {
                LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, Message), ProgramID, "Initialization");
            });

            if (SMSService == null || !SMSService.HasInitializationSucceed())
            {
                LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, "SMS service initialization has failed."), ProgramID, "Initialization");
                return(false);
            }

            return(true);
        }
Example #2
0
        public bool WithMailService()
        {
            /*
             * Mail service initialization
             */
            if (!RequiredEnvironmentVariables.ContainsKey("SENDGRID_API_KEY") ||
                !RequiredEnvironmentVariables.ContainsKey("SENDGRID_SENDER_EMAIL") ||
                !RequiredEnvironmentVariables.ContainsKey("SENDGRID_SENDER_NAME"))
            {
                LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, "SENDGRID_API_KEY, SENDGRID_SENDER_EMAIL, SENDGRID_SENDER_NAME parameters must be provided and valid."), ProgramID, "Initialization");
                return(false);
            }

            MailService = new BMailServiceSendGrid(
                RequiredEnvVars["SENDGRID_API_KEY"],
                RequiredEnvVars["SENDGRID_SENDER_EMAIL"],
                RequiredEnvVars["SENDGRID_SENDER_NAME"],
                (string Message) =>
            {
                LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, Message), ProgramID, "Initialization");
            });

            if (MailService == null || !MailService.HasInitializationSucceed())
            {
                LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, "Mail service initialization has failed."), ProgramID, "Initialization");
                return(false);
            }

            return(true);
        }
Example #3
0
        public bool WithDatabaseService()
        {
            /*
             * File service initialization
             */
            if (!RequiredEnvironmentVariables.ContainsKey("MONGODB_DATABASE"))
            {
                LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, "((MONGODB_CONNECTION_STRING) or (MONGODB_CLIENT_CONFIG, MONGODB_PASSWORD) or (MONGODB_HOST, MONGODB_PORT)) and MONGODB_DATABASE must be provided and valid."), ProgramID, "Initialization");
                return(false);
            }

            if (RequiredEnvironmentVariables.ContainsKey("MONGODB_CLIENT_CONFIG") &&
                RequiredEnvironmentVariables.ContainsKey("MONGODB_PASSWORD"))
            {
                DatabaseService = new BDatabaseServiceMongoDB(RequiredEnvironmentVariables["MONGODB_CLIENT_CONFIG"], RequiredEnvironmentVariables["MONGODB_PASSWORD"], RequiredEnvironmentVariables["MONGODB_DATABASE"],
                                                              (string Message) =>
                {
                    LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, Message), ProgramID, "Initialization");
                });
            }
            else if (RequiredEnvironmentVariables.ContainsKey("MONGODB_CONNECTION_STRING"))
            {
                DatabaseService = new BDatabaseServiceMongoDB(RequiredEnvironmentVariables["MONGODB_CONNECTION_STRING"], RequiredEnvironmentVariables["MONGODB_DATABASE"],
                                                              (string Message) =>
                {
                    LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, Message), ProgramID, "Initialization");
                });
            }
            else if (RequiredEnvironmentVariables.ContainsKey("MONGODB_HOST") &&
                     RequiredEnvironmentVariables.ContainsKey("MONGODB_PORT") &&
                     int.TryParse(RequiredEnvironmentVariables["MONGODB_PORT"], out int MongoDbPort))
            {
                DatabaseService = new BDatabaseServiceMongoDB(RequiredEnvironmentVariables["MONGODB_HOST"], MongoDbPort, RequiredEnvironmentVariables["MONGODB_DATABASE"],
                                                              (string Message) =>
                {
                    LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, Message), ProgramID, "Initialization");
                });
            }
            else
            {
                LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, "((MONGODB_CONNECTION_STRING) or (MONGODB_CLIENT_CONFIG, MONGODB_PASSWORD) or (MONGODB_HOST, MONGODB_PORT)) and MONGODB_DATABASE must be provided and valid."), ProgramID, "Initialization");
                return(false);
            }

            if (DatabaseService == null || !DatabaseService.HasInitializationSucceed())
            {
                LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, "Database service initialization has failed."), ProgramID, "Initialization");
                return(false);
            }

            return(true);
        }
Example #4
0
        public bool WithTracingService()
        {
            /*
             * Tracing service initialization
             */
            if (!RequiredEnvironmentVariables.ContainsKey("ZIPKIN_SERVER_IP") ||
                !RequiredEnvironmentVariables.ContainsKey("ZIPKIN_SERVER_PORT"))
            {
                LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, "ZIPKIN_SERVER_IP, ZIPKIN_SERVER_PORT parameters must be provided and valid."), ProgramID, "Initialization");
                return(false);
            }

            var LoggingServiceLogger = new BLoggingServiceLoggerZipkin(
                LoggingService,
                PreLoggingServiceLogger,
                ProgramID);

            if (!int.TryParse(RequiredEnvironmentVariables["ZIPKIN_SERVER_PORT"], out int ZipkinServerPort))
            {
                LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, "Given zipkin server port is invalid."), ProgramID, "Initialization");
                return(false);
            }

            TracingService = new BTracingServiceZipkin(
                LoggingServiceLogger,
                ProgramID,
                RequiredEnvironmentVariables["ZIPKIN_SERVER_IP"],
                ZipkinServerPort,
                (string Message) =>
            {
                LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, Message), ProgramID, "Initialization");
            });

            if (TracingService == null || !TracingService.HasInitializationSucceed())
            {
                LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, "Tracing service initialization has failed."), ProgramID, "Initialization");
                return(false);
            }

            return(true);
        }
Example #5
0
        public bool WithMemoryService(bool _bFailoverMechanismEnabled = true, IBPubSubServiceInterface _WithPubSubService = null)
        {
            /*
             * Memory service initialization
             */
            if (!RequiredEnvironmentVariables.ContainsKey("REDIS_ENDPOINT") ||
                !RequiredEnvironmentVariables.ContainsKey("REDIS_PORT") ||
                !int.TryParse(RequiredEnvironmentVariables["REDIS_PORT"], out int RedisPort) ||
                !RequiredEnvironmentVariables.ContainsKey("REDIS_PASSWORD"))
            {
                LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, "REDIS_ENDPOINT, REDIS_PORT, REDIS_PASSWORD parameters must be provided and valid."), ProgramID, "Initialization");
                return(false);
            }

            bool RedisSslEnabled = false;

            if (RequiredEnvironmentVariables.ContainsKey("REDIS_SSL_ENABLED") && !bool.TryParse(RequiredEnvironmentVariables["REDIS_SSL_ENABLED"], out RedisSslEnabled))
            {
                LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Warning, "REDIS_SSL_ENABLED parameter has been provided, but it has not a valid value. It will be continued without SSL."), ProgramID, "Initialization");
            }

            MemoryService = new BMemoryServiceRedis(
                RequiredEnvironmentVariables["REDIS_ENDPOINT"],
                RedisPort,
                RequiredEnvironmentVariables["REDIS_PASSWORD"],
                RedisSslEnabled,
                _WithPubSubService,
                _bFailoverMechanismEnabled,
                (string Message) =>
            {
                LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, Message), ProgramID, "Initialization");
            });

            if (MemoryService == null || !MemoryService.HasInitializationSucceed())
            {
                LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, "Memory service initialization has failed."), ProgramID, "Initialization");
                return(false);
            }

            return(true);
        }