Ejemplo n.º 1
0
        private int Count()
        {
            var request = MojioClient.AvoidAsyncDeadlock(() => CountAsync());

            request.Wait();
            return(request.Result);
        }
        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;
            }
        }
Ejemplo n.º 3
0
        protected async override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.Display);

            MojioClient client = Globals.client;

            client.PageSize = 15; //Gets 15 results
            MojioResponse <Results <Trip> > response = await client.GetAsync <Trip> ();

            Results <Trip> result = response.Data;

            var    results      = FindViewById <TextView> (Resource.Id.tripResults);
            int    tripIndex    = 1;
            String outputString = "";

            // Iterate over each trip
            foreach (Trip trip in result.Data)
            {
                outputString += string.Format("Trip {0}:", tripIndex) + System.Environment.NewLine + "Start time: " + trip.StartTime.ToString()
                                + System.Environment.NewLine + "End time: " + trip.EndTime.ToString() + System.Environment.NewLine + "Longitude: "
                                + trip.EndLocation.Lng.ToString() + System.Environment.NewLine + "Latitude: " + trip.EndLocation.Lat.ToString()
                                + System.Environment.NewLine + "Max Speed: " + trip.MaxSpeed.Value.ToString() + " km/h"
                                + System.Environment.NewLine + System.Environment.NewLine;
                tripIndex++;
            }
            results.Text = outputString;
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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));
            }
        }
Ejemplo n.º 6
0
        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);
        }
        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));
        }
        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
            }
        }
Ejemplo n.º 9
0
        public static void SignalRCleanup(MojioClient client)
        {
            Guid vehicleID = new Guid(AFLib.Configurations.vehicleID);

            EventType[] types = new EventType[] {
                EventType.IgnitionOn,
                EventType.IgnitionOff,
                EventType.Speed,
                EventType.FenceEntered,
                EventType.FenceExited
            };
            client.Unsubscribe <Vehicle> (vehicleID, types);
        }
        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);
            }
        }
Ejemplo n.º 11
0
        public async static Task SignalRSetup(MojioClient client, ISharedPreferences prefs)
        {
            Guid appID     = new Guid(AFLib.Configurations.appID);
            Guid secretKey = new Guid(AFLib.Configurations.secretKey);
            Guid vehicleID = new Guid(AFLib.Configurations.vehicleID);

            savedPref = prefs;

            //--------------------Subscribing to SignalR Events--------------------------//
            EventType[] types = new EventType[] {
                EventType.IgnitionOn,
                EventType.IgnitionOff,
                EventType.Speed,
                EventType.FenceEntered,
                EventType.FenceExited,
                EventType.TripStatus
            };
            client.EventHandler += ReceiveEvent;                 //Call event handler
            await client.Subscribe <Vehicle> (vehicleID, types); //Subscribe to Mojio events with ID

            Console.WriteLine("Subscription to Mojio SignalR events sucessful!");

            //Setting up Geographical Spherical Fence
            var center = new Location {
                Lat = Convert.ToDouble(prefs.GetString("geofencinglatitude", null)),
                Lng = Convert.ToDouble(prefs.GetString("geofencinglongitude", null))
            };

            var radius = prefs.GetInt("geofencingradius", 0);   // radius in km

            // Create a new observer
            if (center.Lat != null && center.Lng != null && radius > 0)
            {
                var observer = new GeoFenceObserver(vehicleID, center, radius);
                var result   = await client.CreateAsync(observer);

                // Subscript SignalR to the observer
                client.Observe(result.Data);

                // Register the Event Callback Handler for when a fence is entered or exited.
                client.ObserveHandler += (entity) => {
                    var vehicle = entity as Vehicle;
                    Notification.Builder builder = new Notification.Builder(Application.Context)
                                                   .SetContentTitle("Mojio GeoFencing Alert")
                                                   .SetContentText("Vehicle has crossed the GeoFence.")
                                                   .SetSmallIcon(Resource.Drawable.ic_logo);
                };
            }
        }
Ejemplo n.º 12
0
        public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId)
        {
            var prefs = Application.Context.GetSharedPreferences("settings", FileCreationMode.Private);

            client = AFLib.Globals.client;

            if (client == null)
            {
                AFLib.MojioConnectionHelper.setupMojioConnection(prefs);
                client = AFLib.Globals.client;
            }

            SignalRHelper.SignalRSetup(client, prefs);
            return(StartCommandResult.Sticky);
        }
Ejemplo n.º 13
0
        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));
            }
        }
Ejemplo n.º 16
0
 public IEnumerable <TData> Fetch(Expression expression = null)
 {
     return(MojioClient.AvoidAsyncDeadlock(() => FetchAsync(expression)).Result);
 }
Ejemplo n.º 17
0
 public MojioQueryProvider(MojioClient client, string action)
 {
     _action = action;
     _client = client;
 }