private async void OnActivate(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtCode.Text) || string.IsNullOrEmpty(txtCode.Text.Trim()))
            {
                Common.Instance.ShowToastMessage("Please provide correct activation code", DoubleResources.DangerSnackBar);
                return;
            }

            var activationCode = txtCode.Text.Trim();

            ProjectInsightWebApiClient client = new ProjectInsightWebApiClient(Common.WorkspaceApi);

            try
            {
                DeviceActivationRequestComplete completeRequest = await client.DeviceActivationRequest.CompleteRequestAsync(DeviceActivationId, activationCode, "Chrome", null);

                if (completeRequest == null)
                {
                    Common.Instance.ShowToastMessage("Please check the activation code or request new one", DoubleResources.DangerSnackBar);
                    return;
                }
                string   ApiToken = completeRequest.ApiToken;
                DateTime TokenExpirationDateTime = completeRequest.AuthenticationTokenExpirationDateTimeUTC.Value;
                string   DeviceId = completeRequest.DeviceId;
                string   UserId   = completeRequest.UserId;



                if (AuthenticationService.PI_Client == null)
                {
                    APIsInitialization.InitializeApis(ApiToken);
                    Common.CurrentWorkspace.ApiToken = ApiToken;
                    Common.CurrentWorkspace.UserID   = new Guid(completeRequest.UserId);

                    Common.Instance._sqlconnection.Update(Common.CurrentWorkspace);

                    ProjectInsight.Models.Users.User userMe = UsersService.GetSimpleMe();
                    Common.UserGlobalCapability = userMe.UserGlobalCapability;
                    Common.WorkspaceCapability  = WorkspaceService.GetWorkspaceCapability();
                    //var logingUser = await UsersService.GetUser(new Guid(UserId));


                    //ProjectInsightMobile.Models.User user = new ProjectInsightMobile.Models.User();
                    //user.Email = logingUser.EmailAddress;
                    //user.FirstName = logingUser.FirstName;
                    //user.LastName = logingUser.LastName;
                    //user.DateTimeCreated = DateTime.Now;
                    //user.UserToken = ApiToken;
                    //user.UserID = new Guid(UserId);
                    //Common.Instance.user = user;
                    //SQLiteConnection connection = Common.Instance.InitializeDatabase();
                    //Common.Instance.CreateTable<User>();
                    //Common.Instance._sqlconnection.Insert(user);
                }
                //Common.Instance.ShowToastMessage("Success", DoubleResources.SuccessSnackBar);
                //await Navigation.PushAsync(new StartupMasterPage());
                App.Current.MainPage = new StartupMasterPage();
            }
            catch (Exception ex)
            {
            }
        }
        public StartupMasterPage()
        {
            NavigationPage.SetBackButtonTitle(this, "");
            InitializeComponent();

            //MasterPage.ListView.ItemSelected += OnItemSelected;


            if (Common.PushNotificationAction != null)
            {
                //switch workspace
                if (Common.CurrentWorkspace == null || Common.CurrentWorkspace.DomainID != Common.PushNotificationAction.DomainId)
                {
                    var       workspaces = Common.Instance.GetWorkspaces();
                    Workspace ws;
                    ws = workspaces.FirstOrDefault(x => x.DomainID == Common.PushNotificationAction.DomainId);
                    if (ws != null)
                    {
                        foreach (Workspace wsp in workspaces.Where(x => x.isActive))
                        {
                            wsp.isActive = false;
                            Common.Instance._sqlconnection.Update(wsp);
                        }
                        ws.isActive = true;
                        Common.Instance._sqlconnection.Update(ws);
                        Common.CurrentWorkspace = ws;

                        if (!string.IsNullOrEmpty(ws.ApiToken) && ws.UserID != null)
                        {
                            //check if ApiToken is not expired
                            var handler = new JwtSecurityTokenHandler();
                            var tokenS  = handler.ReadToken(ws.ApiToken) as JwtSecurityToken;
                            var exp     = tokenS.Claims.First(claim => claim.Type == "exp").Value;

                            var expDate = tokenS.ValidTo;
                            if (expDate < DateTime.UtcNow.AddMinutes(1))
                            {
                                ws.ApiToken = null;
                                Common.Instance._sqlconnection.Update(ws);
                                Common.CurrentWorkspace = ws;
                                this.Detail             = new NavigationPage(new SignInUsingPhoneOrEmailPage());

                                return;
                            }

                            //if (AuthenticationService.PI_Client == null)
                            APIsInitialization.InitializeApis();

                            ProjectInsight.Models.Users.User userMe = UsersService.GetSimpleMe();
                            Common.UserGlobalCapability = userMe.UserGlobalCapability;
                            Common.WorkspaceCapability  = WorkspaceService.GetWorkspaceCapability();

                            string notifCount = string.Empty;
                            // Common.Instance.bottomNavigationViewModel.IsNottificationContVisible = false;
                            if (userMe.NotificationNewCount != null && userMe.NotificationNewCount.Value > 0)
                            {
                                //Common.Instance.bottomNavigationViewModel.IsNottificationContVisible = true;
                                if (userMe.NotificationNewCount.Value > 99)
                                {
                                    notifCount = "99+";
                                }
                                else
                                {
                                    notifCount = userMe.NotificationNewCount.Value.ToString();
                                }
                            }

                            Common.Instance.bottomNavigationViewModel.NumberNottificationItems = notifCount;
                            Common.Instance.bottomNavigationViewModel.NumberWorkListItems      = new ObservableCollection <MyWorkItem>(Common.Instance.GetUserWork().Where(x => x.ItemType != ItemType.Projects && x.WorkspaceId == Common.CurrentWorkspace.Id)).Count;
                            Common.Instance.bottomNavigationViewModel.NumberProjectItems       = new ObservableCollection <MyWorkItem>(Common.Instance.GetUserWork().Where(x => x.ItemType == ItemType.Projects && x.WorkspaceId == Common.CurrentWorkspace.Id)).Count;
                        }
                    }
                }

                //ProjectInsight.Items.Projects.Tasks.Task
                //ProjectInsight.Items.Projects.Project
                //ProjectInsight.Items.ApprovalRequests.ApprovalRequest
                //ProjectInsight.Items.Issues.Issue
                //ProjectInsight.Items.Files.File
                //ProjectInsight.Items.CustomItems.CustomItem
                //ProjectInsight.Items.Proposals.Proposal
                //ProjectInsight.Items.ToDos.ToDo
                //ProjectInsight.Items.Workflows.Workflow
                //ProjectInsight.Items.Domains.TimeAndBilling.TimeEntries.TimeSheet
                //ProjectInsightItems.Domains.TimeAndBilling.ExpenseEntries.ExpenseReport

                if (Common.PushNotificationAction.ObjectTypeString == "ProjectInsight.Items.Projects.Tasks.Task")
                {
                    this.Detail = new NavigationPage(new TaskDetailsPage(Common.PushNotificationAction.ObjectId));
                }

                else if (Common.PushNotificationAction.ObjectTypeString == "ProjectInsight.Items.Projects.Project")
                {
                    this.Detail = new NavigationPage(new ProjectDetailsPage(Common.PushNotificationAction.ObjectId));
                }

                else if (Common.PushNotificationAction.ObjectTypeString == "ProjectInsight.Items.ApprovalRequests.ApprovalRequest")
                {
                    this.Detail = new NavigationPage(new ApprovalRequestPage(Common.PushNotificationAction.ObjectId));
                }

                else if (Common.PushNotificationAction.ObjectTypeString == "ProjectInsight.Items.Issues.Issue")
                {
                    this.Detail = new NavigationPage(new IssueDetailsPage(Common.PushNotificationAction.ObjectId));
                }

                //else if (Common.PushNotificationAction.ObjectTypeString == "ProjectInsight.Items.Files.File")
                //    this.Detail = new NavigationPage(new IssueDetailsPage(Common.PushNotificationAction.ObjectId));

                //else if (Common.PushNotificationAction.ObjectTypeString == "ProjectInsight.Items.CustomItems.CustomItem")
                //    this.Detail = new NavigationPage(new IssueDetailsPage(Common.PushNotificationAction.ObjectId));

                else if (Common.PushNotificationAction.ObjectTypeString == "ProjectInsight.Items.ToDos.ToDo")
                {
                    this.Detail = new NavigationPage(new ToDoDetailsPage(Common.PushNotificationAction.ObjectId));
                }

                //else if (Common.PushNotificationAction.ObjectTypeString == "ProjectInsight.Items.Workflows.Workflow")
                //    this.Detail = new NavigationPage(new ToDoDetailsPage(Common.PushNotificationAction.ObjectId));
                //else if (Common.PushNotificationAction.ObjectTypeString == "ProjectInsight.Items.Domains.TimeAndBilling.TimeEntries.TimeSheet")
                //    this.Detail = new NavigationPage(new ToDoDetailsPage(Common.PushNotificationAction.ObjectId));
                //else if (Common.PushNotificationAction.ObjectTypeString == "ProjectInsightItems.Domains.TimeAndBilling.ExpenseEntries.ExpenseReport")
                //    this.Detail = new NavigationPage(new ToDoDetailsPage(Common.PushNotificationAction.ObjectId));

                else
                {
                    this.Detail = new NavigationPage(new NotificationsPage());
                }

                Common.PushNotificationAction = null;
                return;
            }
        }
        private async void GridTemplate_Tapped(object sender, EventArgs e)
        {
            //try
            //{
            if (sender is SwipeGestureGrid || sender is Grid)
            {
                var templateGrid = (Grid)sender;
                if (templateGrid.Parent != null && templateGrid.Parent.BindingContext != null)
                {
                    Workspace workspace = ((Workspace)templateGrid.Parent.BindingContext);
                    if (workspace.Id >= 0)
                    {
                        var workspaces = Common.Instance.GetWorkspaces();
                        foreach (Workspace ws in workspaces.Where(x => x.isActive))
                        {
                            ws.isActive = false;
                            Common.Instance._sqlconnection.Update(ws);
                        }


                        workspace.isActive = true;

                        Common.Instance._sqlconnection.Update(workspace);
                        Common.CurrentWorkspace = workspace;

                        if (string.IsNullOrEmpty(workspace.ApiToken) || workspace.UserID == null)
                        {
                            await Navigation.PushAsync(new SignIn(workspace));
                        }
                        else
                        {
                            APIsInitialization.InitializeApis();

                            ProjectInsight.Models.Users.User userMe = UsersService.GetSimpleMe();

                            Common.UserGlobalCapability = userMe.UserGlobalCapability;
                            Common.WorkspaceCapability  = WorkspaceService.GetWorkspaceCapability();
                            Common.Instance.bottomNavigationViewModel.ActiveIcon = 1;


                            string notifCount = string.Empty;
                            //Common.Instance.bottomNavigationViewModel.IsNottificationContVisible = false;
                            if (userMe.NotificationNewCount != null && userMe.NotificationNewCount.Value > 0)
                            {
                                //  Common.Instance.bottomNavigationViewModel.IsNottificationContVisible = true;
                                if (userMe.NotificationNewCount.Value > 99)
                                {
                                    notifCount = "99+";
                                }
                                else
                                {
                                    notifCount = userMe.NotificationNewCount.Value.ToString();
                                }
                            }

                            Common.Instance.bottomNavigationViewModel.NumberNottificationItems = notifCount;
                            Common.Instance.bottomNavigationViewModel.NumberWorkListItems      = new ObservableCollection <MyWorkItem>(Common.Instance.GetUserWork().Where(x => x.ItemType != ItemType.Projects && x.WorkspaceId == Common.CurrentWorkspace.Id)).Count;
                            Common.Instance.bottomNavigationViewModel.NumberProjectItems       = new ObservableCollection <MyWorkItem>(Common.Instance.GetUserWork().Where(x => x.ItemType == ItemType.Projects && x.WorkspaceId == Common.CurrentWorkspace.Id)).Count;


                            App.Current.MainPage = new StartupMasterPage();
                        }

                        //var itemID = item.Id;
                    }
                    else if (workspace.Id == -1)
                    {
                        await Navigation.PushAsync(new SignInWorkSpace());
                    }
                    else if (workspace.Id == -2)
                    {
                        if (Xamarin.Forms.Device.RuntimePlatform.ToLower() == "android")
                        {
                            await Navigation.PushAsync(new StartUp());
                        }
                        else
                        {
                            await Navigation.PushAsync(new SignInWorkSpace());
                        }
                    }
                }
            }
            //}
            //catch (Exception ex)
            //{

            //}
        }
Example #4
0
        public App()
        {
            //Register Syncfusion license
            Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("MTMwMzUyQDMxMzcyZTMyMmUzMGJNN243dHFuWkNMRlVpaTY2U3BjVjVSSDh1Z2pMM0haVVdUSkFmOHh1ZnM9");

            InitializeComponent();


            //Check internet connection
            bool isConnected = CrossConnectivity.Current.IsConnected;

            CrossConnectivity.Current.ConnectivityChanged += Current_ConnectivityChanged;


            if (isConnected)
            {
                Common.RefreshWorkList     = true;
                Common.RefreshProjectsList = true;
            }
            //HockeyApp.MetricsManager.TrackEvent("Application initialization");

            SQLiteConnection connection = Common.Instance.InitializeDatabase();

            Common.Instance.bottomNavigationViewModel = new BottomNavigationViewModel();

            Common.Filter = new Filter();



            NavigationPage.SetBackButtonTitle(this, "");

            var workspaces = Common.Instance.GetWorkspaces();


            /// todo fixme
            if (workspaces == null || workspaces.Count() == 0)
            {
                if (Device.RuntimePlatform.ToLower() == "android")
                {
                    MainPage = new NavigationPage(new StartUp());
                }
                else
                {
                    MainPage = new NavigationPage(new SignInWorkSpace());
                }
                return;
            }

            Workspace ws;

            if (Common.PushNotificationAction != null)
            {
                ws = workspaces.FirstOrDefault(x => x.DomainID == Common.PushNotificationAction.DomainId);
                foreach (Workspace wsp in workspaces.Where(x => x.isActive))
                {
                    wsp.isActive = false;
                    Common.Instance._sqlconnection.Update(wsp);
                }
                if (ws != null)
                {
                    ws.isActive = true;
                    Common.Instance._sqlconnection.Update(ws);
                }
            }
            else
            {
                ws = workspaces.FirstOrDefault(x => x.isActive);
            }
            if (ws != null)
            {
                ws.isActive = true;
                Common.Instance._sqlconnection.Update(ws);

                Common.CurrentWorkspace = ws;

                //ws = workspaces.FirstOrDefault(x => x.isActive);

                if (!string.IsNullOrEmpty(ws.ApiToken) && ws.UserID != null)
                {
                    //check if ApiToken is not expired
                    var handler = new JwtSecurityTokenHandler();
                    var tokenS  = handler.ReadToken(ws.ApiToken) as JwtSecurityToken;
                    var exp     = tokenS.Claims.First(claim => claim.Type == "exp").Value;

                    var expDate = tokenS.ValidTo;
                    if (expDate < DateTime.UtcNow.AddMinutes(1))
                    {
                        ws.ApiToken = null;
                        Common.Instance._sqlconnection.Update(ws);
                        Common.CurrentWorkspace = ws;
                        MainPage = new NavigationPage(new SignInUsingPhoneOrEmailPage());

                        return;
                    }

                    //if (AuthenticationService.PI_Client == null)
                    APIsInitialization.InitializeApis();


                    if (isConnected)
                    {
                        ProjectInsight.Models.Users.User userMe = UsersService.GetSimpleMe();

                        if (userMe != null)
                        {
                            Common.UserGlobalCapability = userMe.UserGlobalCapability;


                            //userMe.NotificationNewCount = 131;
                            //var respo = UsersService.SaveUser(userMe);

                            string notifCount = string.Empty;
                            //Common.Instance.bottomNavigationViewModel.IsNottificationContVisible = false;
                            if (userMe.NotificationNewCount != null && userMe.NotificationNewCount.Value > 0)
                            {
                                //Common.Instance.bottomNavigationViewModel.IsNottificationContVisible = true;
                                if (userMe.NotificationNewCount.Value > 99)
                                {
                                    notifCount = "99+";
                                }
                                else
                                {
                                    notifCount = userMe.NotificationNewCount.Value.ToString();
                                }
                            }
                            Common.Instance.bottomNavigationViewModel.NumberNottificationItems = notifCount;
                            Common.Instance.bottomNavigationViewModel.NumberWorkListItems      = new ObservableCollection <MyWorkItem>(Common.Instance.GetUserWork().Where(x => x.ItemType != ItemType.Projects && x.WorkspaceId == Common.CurrentWorkspace.Id)).Count;
                            Common.Instance.bottomNavigationViewModel.NumberProjectItems       = new ObservableCollection <MyWorkItem>(Common.Instance.GetUserWork().Where(x => x.ItemType == ItemType.Projects && x.WorkspaceId == Common.CurrentWorkspace.Id)).Count;
                        }
                        Common.WorkspaceCapability = WorkspaceService.GetWorkspaceCapability();
                    }

                    MainPage = new StartupMasterPage();

                    return;
                }
                else
                {
                    MainPage = new NavigationPage(new StartUp());
                    return;
                }
            }
            else
            {
                MainPage = new NavigationPage(new ChooseWorkspace());
                return;
            }
        }