public static void UnclaimMojios(MojioClient client, Mojio.Mojio mojio)
        {
            Logger logger = Logger.Instance;

            // Unclaiming Mojio using our C# SDK
            // NOTE: This is a restricted call and your developer account must be authorized
            var response = client.UnclaimAsync(mojio.Id);
            var result = response.Result;
            var statusCode = result.StatusCode;
            var errorMessage = result.ErrorMessage;
            switch (statusCode)
            {
                case HttpStatusCode.NotFound:
                    logger.LogErrorUnclaim(mojio.Imei, errorMessage);
                    break;
                case HttpStatusCode.Conflict:
                    logger.LogErrorUnclaim(mojio.Imei, errorMessage);
                    break;
                case HttpStatusCode.OK:
                    logger.LogSuccessfulUnclaim(mojio.Imei);
                    break;
                default:
                    logger.LogErrorUnclaim(mojio.Imei, errorMessage);
                    break;
            }
        }
 public static User CreateNewUser(MojioClient client, string userName, string password, string email)
 {
     // Create a new Mojio user
     var task = client.RegisterUserAsync(userName, email, password);
     var result = task.Result;
     var mojioUser = result.Data;
     return mojioUser;
 }
Exemplo n.º 3
0
        private void SetupMojioClient()
        {
            Client = new MojioClient (this, new Guid (ConfigSettings.MojioAppId), new Guid (ConfigSettings.MojioAppKey), ConfigSettings.MojioApiEndpoint);

            if (Client.Token == null) {
                Client.Begin (new Guid (ConfigSettings.MojioAppId), new Guid (ConfigSettings.MojioAppKey));
            }
        }
        public static void UnclaimMojios(MojioClient client, string fileName)
        {
            Logger logger = Logger.Instance;
            logger.Log("Un-clamining Mojio Process Starting. . .");
            logger.Log("Filename: " + fileName);
            try
            {
                using (var reader = new StreamReader(fileName))
                {

                    var claimedMojioList = GetAllClaimdMojio(client);

                    while (!reader.EndOfStream)
                    {
                        var row = reader.ReadLine();
                        // todo: fake some values here
                        // EXPECTED ROW: "TV156403609,\"123456789012345\""
                        // NOTE: if this row looks different than the string above please change the row.Split accordingly
                        if (row != null)
                        {
                            var arry = row.Split(',', (char)34, (char)92); // Delimiter: ',', '/', '"'
                            arry = arry.Where(x => !string.IsNullOrEmpty(x)).ToArray();
                            var imei = arry[1]; //Imei
                            var regex = new Regex(@"^[0-9]+$");

                            if (regex.IsMatch(imei))
                            {
                                // Get Mojio
                                var mojio = GetMojio(imei, claimedMojioList);

                                if (mojio != null)
                                {
                                    UnclaimMojios(client, mojio);
                                }
                                else
                                {
                                    logger.Log("Could not find Mojio with IMEI: " + imei);
                                } 
                            }
                            else
                            {
                                logger.Log(String.Format("{0} is not an IMEI number", imei));
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                //eat it
            }
        }
 public static void UnclaimMojiosByImei(MojioClient client, string imei)
 {
     Logger logger = Logger.Instance;
     var mojio = GetMojio(imei, GetAllClaimdMojio(client));
     if (mojio != null)
     {
         UnclaimMojios(client, mojio);
     }
     else
     {
         logger.Log("Could not find Mojio with IMEI: " + imei);
     }
 }
        private static void Main(string[] args)
        {
            // APP INFO
            Guid appId = new Guid("00000000-0000-0000-0000-000000000000"); // Application Id
            Guid secretKey = new Guid("00000000-0000-0000-0000-000000000000"); // Sandbox
            //Guid secretKey = new Guid("00000000-0000-0000-0000-000000000000"); // Live

            // LOG-IN CREDENTIAL
            // USER ACCOUNT YOU WANT TO CLAIM/UN-CLAIM UNDER
            var adminUserOrEmail = "*****@*****.**";
            var adminPassword = "******";

            // SET UP
            var logger = Logger.Instance;

            // AUTHENTICATING TO MOJIO
            var client = new MojioClient(appId, secretKey, adminUserOrEmail, adminPassword);
            logger.Log("Aquiring Token From Mojio....");

            if (client.Token == null)
            {
                logger.Log("Failed to aquire token.");
                logger.Log("Press any key to quit...");
                Console.ReadKey();
            }
            else
            {
                logger.Log("Log In: Successful");
            }

            // GET FILE PATH
            var fileName = GetFilePathFromUser();

            // PROCESS FILE AND CLAIM MOJIO
            ClaimMojio.ClaimMojio.ClaimMojios(client, fileName);

            // PROCESS FILE AND UNCLAIM MOJIO
            UnClaimingMojio.UnclaimMojio.UnclaimMojios(client, fileName);

            // PROCESS FILE AND ASSIGN MOJIO TO NEW USER
            CreateAndAssignUserToUnclaimedMojio(client, fileName);

            // END OF PROGRAM
            logger.Log("Press any key to stop...");
            Console.ReadKey();
        }
        public static void ClaimMojioByImei(MojioClient client, string imei)
        {
            Logger logger = Logger.Instance;
            var regex = new Regex(@"^[0-9]+$");

            if (!regex.IsMatch(imei))
            {
                logger.Log(String.Format("{0} is not an IMEI number", imei));
            }
            try
            {
                // Claiming Mojio using C# SDK
                // NOTE: This is a restricted call and your developer account must be authorized
                var task = client.ClaimAsync(imei);
                var mojioResult = task.Result;
                var statusCode = mojioResult.StatusCode;
                var errorMessage = mojioResult.ErrorMessage;
                switch (statusCode)
                {
                    case HttpStatusCode.NotFound:
                        logger.LogErrorClaim(imei, errorMessage);
                        break;
                    case HttpStatusCode.Conflict:
                        logger.LogErrorClaim(imei, errorMessage);
                        break;
                    case HttpStatusCode.OK:
                        logger.LogSuccessfulClaim(imei);
                        break;
                    default:
                        logger.LogErrorClaim(imei, errorMessage);
                        break;
                }
            }
            catch (Exception ex)
            {
                Logger.Instance.Log(string.Format("An exception occured while claiming Mojio\nException Message: {0}",
                    ex.Message));
            }
        }
        public static void ClaimMojios(MojioClient client, string fileName)
        {
            Logger logger = Logger.Instance;
            logger.Log("Claiming Mojio Process Starting. . .");
            logger.Log("Filename: " + fileName);
            try
            {
                using (var reader = new StreamReader(fileName))
                {
                    while (!reader.EndOfStream)
                    {
                        var row = reader.ReadLine();
                        // EXPECTED ROW: "TV156403609,\"123456789012345\""
                        // NOTE: if this row looks different than the string above please change the row.Split accordingly
                        if (row != null)
                        {
                            var arry = row.Split(',', (char)34, (char)92); // Delimiter: ',', '/', '"'
                            arry = arry.Where(x => !string.IsNullOrEmpty(x)).ToArray();
                            var imei = arry[1]; //Imei
                            var regex = new Regex(@"^[0-9]+$");

                            if (regex.IsMatch(imei))
                            {
                                ClaimMojioByImei(client, imei);
                            }
                            else
                            {
                                logger.Log(String.Format("{0} is not an IMEI number", imei));
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Instance.Log(string.Format("An exception occured while claiming Mojio\nException Message: {0}",
                    ex.Message));
            }
        }
        private static List<Mojio.Mojio> GetAllClaimdMojio(MojioClient client)
        {
            // Get all the Mojios under the currented logged on user
            var mojiosResponse = client.GetAsync<Mojio.Mojio>();
            var result = mojiosResponse.Result;
            var data = result.Data;
            var mojios = data.Data;

            // Store all the Mojios
            return new List<Mojio.Mojio>(mojios);
        }
        private static void CreateAndAssignUserToUnclaimedMojio(MojioClient client, string fileName)
        {
            // ASSUMPTION: THE IMEI IN THE FILE ARE ALL UNCLAIMED

            // NEW USER ACCOUNT CREATION PATTERN
            var newUserNameFormat = "UserName"; //expected: wizardUser0, wizardUser1 ... etc.
            var newUserPasswordFormat = "Us3rpaSsw0rd"; // expected: wIzpaSsw0rd0, wIzpaSsw0rd1 ... etc.
            var newUserEmailFormat = "@youemail.com"; // expected: [email protected], [email protected] ... etc.
            var currentUserNumber = 0;
            var totalImei = GetTotalImei(fileName); // Number of user account needs to be created
            Logger logger = Logger.Instance;
            
            List<User> newUserList = CreateUserAccounts(client, newUserNameFormat, newUserPasswordFormat, newUserEmailFormat,
                totalImei);

            logger.Log("Assigning User To Mojio Starting. . .");
            try
            {
                using (var reader = new StreamReader(fileName))
                {
                    while (!reader.EndOfStream)
                    {
                        var row = reader.ReadLine();

                        // EXPECTED ROW: "TV156403609,\"123456789012345\""
                        // NOTE: if this row looks different than the string above please change the row.Split accordingly
                        if (row != null)
                        {
                            var arry = row.Split(',', (char) 34, (char) 92); // Delimiter: ',', '/', '"'
                            arry = arry.Where(x => !string.IsNullOrEmpty(x)).ToArray();
                            var imei = arry[1]; //Imei
                            var regex = new Regex(@"^[0-9]+$");

                            if (regex.IsMatch(imei))
                            {
                                var user = newUserList[currentUserNumber];
                                var task = client.SetUserAsync(user.Email, newUserPasswordFormat + currentUserNumber);
                                var result = task.Result;
                                if (result.Data != null)
                                {
                                    ClaimMojio.ClaimMojio.ClaimMojioByImei(client, imei);
                                    currentUserNumber++;
                                }
                            }
                            else
                            {
                                logger.Log(String.Format("{0} is not an IMEI number", imei));
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Instance.Log(string.Format("An exception occured while claiming Mojio\nException Message: {0}",
                    ex.Message));
            }
        }
 private static List<User> CreateUserAccounts(MojioClient client, string newUserNameFormat, string newUserPasswordFormat,
     string newUserEmailFormat, int numberOfAccount)
 {
     Logger logger = Logger.Instance;
     logger.Log("Creating User Accounts Starting . . .");
     var newUserList = new List<User>();
     for (int currentUserNumber = 0; currentUserNumber < numberOfAccount; currentUserNumber++)
     {
         // Create a new user
         var userName = newUserNameFormat + currentUserNumber;
         var userPassword = newUserPasswordFormat + currentUserNumber;
         var userEmail = userName + newUserEmailFormat;
         var user = Accounts.MojioAccount.CreateNewUser(client, userName, userPassword, userEmail);
         if (user != null)
         {
             newUserList.Add(user);
             logger.logSuccessfulNewUser(user);
         }
         else
         {
             logger.LogErrorNewUser(userName);
         }
     }
     logger.Log(string.Format("Created {0} user accounts", newUserList.Count));
     return newUserList;
 }