Ejemplo n.º 1
0
        public static void emailAll()
        {
            long[] ids = SqliteHandler.getAllUserIds();
            for (int i = 0; i < ids.Length; i++)
            {
                string[] stocks   = SqliteHandler.getAllMail(ids[i]);
                string   contents = "";
                for (int j = 0; j < stocks.Length; j++)
                {
                    string[]       fields = { "*" };
                    ServerResponse sr     = StockUtilities.getQuote(stocks[j], fields);

                    if (sr.payload != null)
                    {
                        contents += sr.payload.ToString();
                    }
                }

                UserModel user = SqliteHandler.getUser(ids[i]);

                if (stocks.Length != 0)
                {
                    sendEmail(user.email, "Stock Update", contents);
                }
                else
                {
                    Console.WriteLine(user.email + " was skipped as they had no subscriptions");
                }
            }
        }
        // Warning - will not work - see comment above ProblemFour method invokation in Main()
        public static void Main()
        {
            var mongoHandler = new MongoDbHandler();
            var sqlHandler = new SqlServerHandler();
            var mySqlHandler = new MySqlHandler();
            var pdfHandler = new PdfHandler();
            var xmlToSql = new XmlToSqlServerLoader();
            var excellHandler = new ExcellHandler();
            var mongoToSql = new MongoToSqlServerLoader();
            var zipExtractor = new ZipExtractor();
            var jsonHandler = new JsonHandler();
            var sqliteHandler = new SqliteHandler();
            var xmlHandler = new XmlHandler();

            if (!Directory.Exists(OutputDirectory))
            {
                Directory.CreateDirectory(OutputDirectory);
            }

            //// Mongolab.com credentials - Username: TeamXenon , Passsword: xenon123

            ProblemOne(mongoHandler, mongoToSql, zipExtractor, excellHandler);

            ProblemTwo(pdfHandler);

            ProblemThree(xmlHandler);

            //// NOTE!!! - you need to go to CarParts.Data.MySql project and in its App.config file
            //// you should change the password in the connectionString tag with which you connect to your localhost instance of the MySQL Workbench server.
            ProblemFour(sqlHandler, mySqlHandler, jsonHandler);

            ProblemFive(mongoHandler, xmlToSql);

            ProblemSix(excellHandler, sqlHandler, sqliteHandler, mySqlHandler);
        }
Ejemplo n.º 3
0
        public static ServerResponse loginUser(string email, string password)
        {
            long id = SqliteHandler.getUserId(email);

            if (id == -1)
            {
                //return a failure with an error message an no payload
                return(new ServerResponse(false, "email doesn't exist", null));
            }
            string realPassword = SqliteHandler.getUserPassword(id);

            //hash password
            password = hashPassword(password);

            if (realPassword != null && realPassword.Equals(password))
            {
                UserModel user = SqliteHandler.getUser(id);
                return(new ServerResponse(true, "user login successfull", user));
            }
            //if not successful
            else
            {
                //...
                //sql call returns no match
                return(new ServerResponse(false, "password doesn't match", null));
            }
        }
Ejemplo n.º 4
0
 public SettingsManager(string filename)
 {
     SqliteHandler = new SqliteHandler(filename);
     if (!File.Exists(SqliteHandler.DatabaseName))
     {
         EnsureTable();
     }
 }
Ejemplo n.º 5
0
        public static ServerResponse getUserWidget(long widgetID)
        {
            WidgetModel widget = SqliteHandler.getWidget(widgetID);

            if (widget == null)
            {
                return(new ServerResponse(false, "widget not found", null));
            }

            return(new ServerResponse(true, "widget loaded succesfully", widget));
        }
Ejemplo n.º 6
0
        public static ServerResponse getUserDashboard(long userID)
        {
            UserModel existing = SqliteHandler.getUser(userID);

            if (existing == null)
            {
                return(new ServerResponse(false, "user not found", null));
            }

            return(new ServerResponse(true, "dashboard loaded successfully", existing.widgetList));
        }
Ejemplo n.º 7
0
        public static ServerResponse addUserWidget(long userId, WidgetModel widget)
        {
            UserModel user = SqliteHandler.getUser(userId);

            if (user == null)
            {
                return(new ServerResponse(false, "user could not be found", null));
            }

            long wid = SqliteHandler.createWidget(userId, widget);

            return(new ServerResponse(true, "widget was successfully created", wid));
        }
Ejemplo n.º 8
0
        public void TestRavenclawAnswerReturnsString()
        {
            //Arrange
            string        hogwartsHouse  = "Ravenclaw";
            SqliteHandler connectDb      = new SqliteHandler();
            int           questionNumber = 1;

            //Act
            string answer = connectDb.GetAnswer(hogwartsHouse, questionNumber).ToLower();

            //Assert
            Assert.AreNotEqual(answer, "");
        }
Ejemplo n.º 9
0
        public void TestSlytherinQuestionReturnsString()
        {
            //Arrange
            string        hogwartsHouse  = "Slytherin";
            SqliteHandler connectDb      = new SqliteHandler();
            int           questionNumber = 1;

            //Act
            string question = connectDb.GetQuestion(hogwartsHouse, questionNumber);

            //Assert
            Assert.AreNotEqual(question, "");
        }
Ejemplo n.º 10
0
        public static ServerResponse logoutUser(long userID)
        {
            //for now just verify that a user exists to be criteria
            UserModel user = SqliteHandler.getUser(userID);

            if (user != null)
            {
                return(new ServerResponse(true, "user logged out", null));
            }
            else
            {
                return(new ServerResponse(false, "unable to log out", null));
            }
        }
Ejemplo n.º 11
0
        public static ServerResponse getAllMail(long userid)
        {
            string[] stocks;

            stocks = SqliteHandler.getAllMail(userid);
            if (stocks.Length != 0)
            {
                return(new ServerResponse(true, "retrieved mail list successfully", stocks));
            }
            else
            {
                return(new ServerResponse(false, "There are no subscriptions currently.", null));
            }
        }
Ejemplo n.º 12
0
        public static ServerResponse updateUserWidget(long widgetID, WidgetModel widget)
        {
            WidgetModel oldWidget = SqliteHandler.getWidget(widgetID);

            if (oldWidget == null)
            {
                return(new ServerResponse(false, "widget not found", null));
            }

            SqliteHandler.updateWidget(widgetID, widget);

            oldWidget = SqliteHandler.getWidget(widgetID);

            return(new ServerResponse(true, "widget updated successfully", oldWidget));
        }
Ejemplo n.º 13
0
        public static ServerResponse deleteUserWidget(long widgetID)
        {
            WidgetModel widget = SqliteHandler.getWidget(widgetID);

            //find user, set = to existing

            if (widget == null)
            {
                return(new ServerResponse(false, "widget not found", null));
            }

            SqliteHandler.deleteWidget(widgetID);

            return(new ServerResponse(true, "widget deleted succesfully", null));
        }
Ejemplo n.º 14
0
        //functions should preferably be static as they should be stateless
        public static ServerResponse createUser(string email, string password, string passwordConf)
        {
            //check to see if the email is already taken
            long id = SqliteHandler.getUserId(email);

            if (id != -1)
            {
                //return a failure with an error message an no payload
                return(new ServerResponse(false, "email already exists", null));
            }
            //check to see if passwords match
            if (password.Equals(passwordConf) == false)
            {
                return(new ServerResponse(false, "passwords do not match", null));
            }

            //Down the line do some call to send an email to the user, for now do nothing
            //grab the user id of the created user


            //hash the password
            password = hashPassword(password);


            id = SqliteHandler.createUser(email, password);
            if (id == -1)
            {
                //there was some failure
                return(new ServerResponse(false, "there was an error creating the user", null));
            }


            UserModel newUser = SqliteHandler.getUser(id); //grab the created user

            if (newUser != null)
            {
                //return a success with a success message and put the user into the payload
                return(new ServerResponse(true, "account created successfully", newUser));
            }
            else
            {
                //there was some failure
                return(new ServerResponse(false, "there was an error grabbing the created the user", null));
            }
        }
Ejemplo n.º 15
0
 public SqliteFinanceiro(string db_path = "db.db")
 {
     if (!db_path.Contains(@"\"))
     {
         db_path = AppDomain.CurrentDomain.BaseDirectory + @"\" + db_path;
     }
     Handler = new SqliteHandler(db_path);
     if (!File.Exists(db_path))
     {
         Handler.NonQuery(Properties.Resources.DatabaseCreation);
         Handler.NonQuery(Properties.Resources.InitialData);
     }
     Transaction        = new Transaction(Handler);
     TransactionPayment = new TransactionPayment(Handler);
     SimpleTableManager = new SimpleTableManager(Handler);
     ToUpload           = new ToUpload(Handler);
     TransactionV       = new TransactionV(Handler);
 }
Ejemplo n.º 16
0
 public Transaction(SqliteHandler handler)
 {
     Handler            = handler;
     TransactionPayment = new TransactionPayment(Handler);
 }
Ejemplo n.º 17
0
        public static ServerResponse deleteMail(long userid, string stock)
        {
            SqliteHandler.removeMail(userid, stock);

            return(new ServerResponse(true, "mail successfully removed", null));
        }
Ejemplo n.º 18
0
        public static ServerResponse addMail(long userid, string stock)
        {
            SqliteHandler.createMail(userid, stock);

            return(new ServerResponse(true, "mail successfully added", null));
        }
        private static void ProblemSix(ExcellHandler excellHandler, SqlServerHandler sqlHandler, SqliteHandler sqliteHandler, MySqlHandler mySqlHandler)
        {
            var reports = mySqlHandler.ReadReports();
            var taxes = sqliteHandler.ReadTaxes();

            excellHandler.GenerateExcellFile(reports, taxes, "VendorsFinancialReport.xlsx");
            Console.WriteLine("Successfully generated excell file to ");
        }
Ejemplo n.º 20
0
 public ToUpload(SqliteHandler handler)
 {
     Handler = handler;
 }
Ejemplo n.º 21
0
 public TransactionV(SqliteHandler handler)
 {
     Handler = handler;
 }
Ejemplo n.º 22
0
 public SimpleTableManager(SqliteHandler handler, string table_name = null)
 {
     Handler   = handler;
     TableName = table_name;
 }
Ejemplo n.º 23
0
 public TransactionPayment(SqliteHandler handler)
 {
     Handler = handler;
 }