protected void SendCodeButton_Click(object sender, EventArgs e)
    {
        // Check if phone number is empty
        if (PhoneNumberTextBox.Text.Length == 0)
        {
            Session["Error"] = "Phone number cannot be empty.";
            Server.Transfer("Step1.aspx");
            return;
        }

        // Load the API key using the DotNetEnv library
        DotNetEnv.Env.Load(System.AppDomain.CurrentDomain.BaseDirectory + "/APIKey.env");
        String YourAccessKey = System.Environment.GetEnvironmentVariable("MESSAGEBIRD_API_KEY");

        // Initalize the MessageBird API
        MessageBird.Client client = MessageBird.Client.CreateDefault(YourAccessKey);

        Session["client"] = client;

        // Call CreateVerify to send a verification code to the user's phone. Here, we are sending "null" as the second
        // input. This input specifies optional settings, such as the timeout. Since we are sending "null", the default
        // timeout is used, which is 30 seconds.
        try
        {
            Verify verify = client.CreateVerify(PhoneNumberTextBox.Text, null);
            Session["VerifyId"] = verify.Id;
        }
        catch (ErrorException errorException)
        {
            Session["Error"] = ErrorGenerator.Generate(errorException);
            Server.Transfer("Step1.aspx");
        }
        Server.Transfer("Step2.aspx");
    }
    protected void CheckCodeButton_Click(object sender, EventArgs e)
    {
        // Check if code is empty
        if (CodeTextBox.Text.Length == 0)
        {
            Session["Error"] = "Verification code cannot be empty.";
            Server.Transfer("Step2.aspx");
            return;
        }

        // Call SendVerifyToken to verify the code entered in CodeTextBox.Text matches the code
        // sent to the user in the CreateVerify call in Step1.aspx.cs. Here, the words "token" and "code"
        // mean the same thing.
        try
        {
            Client client = ((Client)Session["Client"]);
            client.SendVerifyToken(Session["VerifyId"].ToString(), CodeTextBox.Text);
        }
        catch (ErrorException errorException)
        {
            Session["Error"] = ErrorGenerator.Generate(errorException);
            Server.Transfer("Step2.aspx");
        }
        Server.Transfer("Step3.aspx");
    }
        /// <summary>
        /// WRITE LOG TO THE SYSTEM TRACE
        /// </summary>
        /// <param name="logInfo"></param>
        /// <returns></returns>
        public ILogMessage Write(T logInfo)
        {
            try
            {
                if (logInfo == null)
                {
                    throw ErrorGenerator.Generate(ErrorCode.CDX_NO_VALUE, Messages.NULL_LOG_INFO);
                }

                if (typeof(T) != typeof(BaseLogInfo))
                {
                    throw ErrorGenerator.Generate(ErrorCode.CDX_SQL_CAST_FAIL);
                }

                BaseLogInfo baseLogInfo = logInfo as BaseLogInfo;

                System.Diagnostics.Trace.WriteLine(baseLogInfo.LogLevel.ToString() + ": " + baseLogInfo.LogMessage);

                return(new LogMessageCode()
                {
                    Status = StatusType.SUCCESS, Message = Messages.LOG_SUCCESSFULL
                });
            }
            catch (Exception ex)
            { return(new LogMessageCode()
                {
                    Status = StatusType.EXCEPTION, Message = ex.Message
                }); }
        }
Example #4
0
        static async Task Main(string[] args)
        {
            Task allTasks = null;

            try
            {
                IInputSaver[] inputSavers = new IInputSaver[TaskConsts.STRING_QUANTITY]
                {
                    new FirstInputSaver(),
                    new SecondInputSaver(),
                    new ThirdInputSaver()
                };
                Task[]          tasks          = new Task[TaskConsts.STRING_QUANTITY];
                IInput          input          = new ConsoleInput();
                IErrorGenerator errorGenerator = new ErrorGenerator();
                for (int i = 0; i < TaskConsts.STRING_QUANTITY; i++)
                {
                    tasks[i] = inputSavers[i].InputAndWriteStringAsync(input, errorGenerator);
                }
                allTasks = Task.WhenAll(tasks);
                await allTasks;
                Console.WriteLine("Success");
            }
            catch (RandomException exception)
            {
                logger.Error(exception);
                Console.WriteLine("Failure");
            }
            finally
            {
                Console.ReadKey();
            }
        }
Example #5
0
        public static string GetConnectionString(SqlLogInfo sqlLogInfo)
        {
            string connectionString = string.Empty;

            if (sqlLogInfo.FetchFromConfig)
            {
                sqlLogInfo.ConnectionStringKey.Trim().CheckEmpty(ErrorCode.CDX_NO_VALUE, Messages.CONNECTION_STRING_KEY_MISSING);

                try
                { connectionString = ConfigurationManager.AppSettings[sqlLogInfo.ConnectionStringKey].ToString(); }
                catch (Exception ex)
                { throw ErrorGenerator.Generate(ErrorCode.CDX_NO_VALUE, ex.Message); }

                if (connectionString == null)
                {
                    throw ErrorGenerator.Generate(ErrorCode.CDX_NO_VALUE, Messages.CONNECTION_STRING_READ_ERROR);
                }
            }
            else
            {
                // GENERATE CONNECTIONSTRING
                connectionString = sqlLogInfo.GetConnectionString();
            }
            return(connectionString);
        }
Example #6
0
 public static void CheckEmpty(this string data, string errorCode, string message)
 {
     if (string.IsNullOrEmpty(data))
     {
         throw ErrorGenerator.Generate(errorCode, message);
     }
 }
        public override void OnActionExecuting(HttpActionContext actionContext)
        {
            // base.OnActionExecuting(actionContext);

            if (!actionContext.ModelState.IsValid)
            {
                var parameter = actionContext.ModelState.Keys.FirstOrDefault().Split('.');

                actionContext.Response = ErrorGenerator.GenerateError(actionContext.Request, parameter.Last(), ErrorCodes.InvalidInputs).Response;
            }
        }
Example #8
0
        public static void ValidateLogFileDefaults(FileLogInfo fileLogInfo)
        {
            fileLogInfo.FileName.CheckEmpty(ErrorCode.CDX_NO_VALUE, Messages.FILE_NAME_MISSING);

            fileLogInfo.FilePath.CheckEmpty(ErrorCode.CDX_NO_VALUE, Messages.FILE_PATH_MISSING);

            if (fileLogInfo.LogType == LogType.Message)
            {
                fileLogInfo.LogMessage.CheckEmpty(ErrorCode.CDX_NO_VALUE, Messages.FILE_LOG_MESSAGE_MISSING);
            }
            else
            {
                if (fileLogInfo.Exception == null)
                {
                    throw ErrorGenerator.Generate(ErrorCode.CDX_NO_VALUE, Messages.FILE_LOG_EXCEPTION_MISSING);
                }
            }
        }
Example #9
0
        public ILogMessage Write(T logInfo)
        {
            try
            {
                if (logInfo == null)
                {
                    throw ErrorGenerator.Generate(ErrorCode.CDX_NO_VALUE, Messages.NULL_LOG_INFO);
                }

                if (typeof(T) != typeof(FileLogInfo))
                {
                    throw ErrorGenerator.Generate(ErrorCode.CDX_FILE_CAST_FAIL);
                }

                FileLogInfo fileLogInfo = logInfo as FileLogInfo;

                FileUtils.ValidateLogFileDefaults(fileLogInfo);

                if (fileLogInfo.EnableDate && string.IsNullOrEmpty(fileLogInfo.LogDateFormat))
                {
                    fileLogInfo.LogDateFormat = FileUtils.Default_Date_Format;
                }

                if (fileLogInfo.DedicatedFolder && string.IsNullOrEmpty(fileLogInfo.FolderName))
                {
                    fileLogInfo.FolderName = FileUtils.Default_Log_FolderName;
                }

                // [ WRITE LOG TO FILE ]
                WriteLog(fileLogInfo);

                fileLogInfo.LogMessage = string.Empty;
                return(new LogMessageCode()
                {
                    Status = StatusType.SUCCESS, Message = Messages.LOG_SUCCESSFULL
                });
            }
            catch (Exception ex) { return(new LogMessageCode()
                {
                    Status = StatusType.EXCEPTION, Message = ex.Message
                }); }
        }
        public IHttpActionResult GetCustomer(int customerId = 0, string email = null)
        {
            var urlHelper = new UrlHelper(Request);

            _customerManager = new CustomerManager();
            if (email == null && customerId == 0)
            {
                return(ErrorGenerator.GenerateErrorResponse(Request, HttpStatusCode.BadRequest, ErrorCode.NoInquiry));
            }

            if (Helper.IsValidEmail(email))
            {
                return(ErrorGenerator.GenerateErrorResponse(Request, HttpStatusCode.BadRequest, ErrorCode.InvalidEmail));
            }

            var customer = _customerManager.GetCustomerData(customerId, email);

            if (customer == null)
            {
                return(ErrorGenerator.GenerateErrorResponse(Request, HttpStatusCode.NotFound, ErrorCode.NotFound));
            }

            return(Ok(Mapper.ToCustomerModel(customer)));
        }
Example #11
0
        /// <summary>
        /// WRITE LOG TO DATABASE
        /// </summary>
        /// <param name="logInfo">Database and message definition</param>
        /// <returns></returns>
        public ILogMessage Write(T logInfo)
        {
            try
            {
                if (logInfo == null)
                {
                    throw ErrorGenerator.Generate(ErrorCode.CDX_NO_VALUE, Messages.NULL_LOG_INFO);
                }

                if (typeof(T) != typeof(SqlLogInfo))
                {
                    throw ErrorGenerator.Generate(ErrorCode.CDX_SQL_CAST_FAIL);
                }

                SqlLogInfo sqlLogInfo = logInfo as SqlLogInfo;

                sqlLogInfo.Database.Trim().CheckEmpty(ErrorCode.CDX_NO_VALUE, Messages.SQL_DATABASE_NAME_MISSING);

                if (!sqlLogInfo.WindowsAuthentication)
                {
                    MsSQL.SQLUtil.ValidateSQLAuthentication(sqlLogInfo);
                }

                // [ CONFIGURE CONNECTION STRING ]
                string connectionString = MsSQL.SQLUtil.GetConnectionString(sqlLogInfo);


                if (sqlLogInfo.CallType == SQLCallType.Query)
                {
                    sqlLogInfo.Query.CheckEmpty(ErrorCode.CDX_NO_VALUE, Messages.EMPTY_QUERY);
                }
                else
                {
                    if (sqlLogInfo.StoredProcedureInfo == null)
                    {
                        throw ErrorGenerator.Generate(ErrorCode.CDX_NO_VALUE, Messages.NULL_SP_INFO);
                    }

                    sqlLogInfo.StoredProcedureInfo.StoredProcedureName.CheckEmpty(ErrorCode.CDX_NO_VALUE, Messages.SQL_SP_NAME_MISSING);

                    if (sqlLogInfo.StoredProcedureInfo.LogParams == null || sqlLogInfo.StoredProcedureInfo.LogParams.Count <= 0)
                    {
                        MsSQL.MsSQLHandler handler = new MsSQL.MsSQLHandler(connectionString);
                    }
                }


                // WRITE LOG TO SQL

                return(new LogMessageCode()
                {
                    Status = StatusType.SUCCESS, Message = Messages.LOG_SUCCESSFULL
                });
            }
            catch (Exception ex)
            {
                return(new LogMessageCode()
                {
                    Status = StatusType.EXCEPTION, Message = ex.Message
                });
            }
        }