Пример #1
0
 private void CreateDashboard()
 {
     SetDrawer();
     if (PreferenceHandler.GetUserDetails().RoleId == (int)USER_ROLE.ADMIN)
     {
         try
         {
             if (Utils.Utils.CurrentStage == DemoStage.None && IsDemoMode)
             {
                 Utils.Utils.CurrentStage = DemoStage.Yesterday;
                 client = new MqttClient(Constants.MqttServer);
                 SubscribeMQTT(this);
             }
         }
         catch (Exception)
         {
         }
         GetConsumptionDetails(CurrentConsumption, 0);
         this.Title = "Dashboard";
     }
     else
     {
         //Show Student Fragment
         this.Title = "Feedback";
         var newFragment = new StudentFragment();
         var ft          = FragmentManager.BeginTransaction();
         ft.Add(Resource.Id.fragment_container, newFragment);
         ft.Commit();
         layoutProgress            = FindViewById <LinearLayout>(Resource.Id.layout_progress);
         layoutProgress.Visibility = ViewStates.Gone;
     }
 }
Пример #2
0
        public async void CreateDashboard()
        {
            //var preferenceHandler = new PreferenceHandler();
            //string code = preferenceHandler.GetAccessCode();
            //string tokenURL = string.Format(B2CConfig.TokenURL, B2CConfig.Tenant, B2CPolicy.SignInPolicyId, B2CConfig.Grant_type, B2CConfig.ClientSecret, B2CConfig.ClientId, code);
            //var response = await InvokeApi.Authenticate(tokenURL, string.Empty, HttpMethod.Post);
            //if (response.StatusCode == System.Net.HttpStatusCode.OK)
            //{
            //    string strContent = await response.Content.ReadAsStringAsync();
            //    var token = JsonConvert.DeserializeObject<AccessToken>(strContent);

            //    // string strRefreshToken = "access&refresh_token=AwABAAAAvPM1KaPlrEqdFSBzjqfTGBCmLdgfSTLEMPGYuNHSUYBrq...&redirect_uri=urn:ietf:wg:oauth:2.0:oob";
            //    string strRefreshToken = "https://login.microsoftonline.com/csub2c.onmicrosoft.com/oauth2/v2.0/token?p=b2c_1_b2csignin&grant_type=refresh_token&client_id=3bdf8223-746c-42a2-ba5e-0322bfd9ff76&scope=3bdf8223-746c-42a2-ba5e-0322bfd9ff76" + " " + "offline_access&refresh_token=" + token.id_token + "&redirect_uri=urn:ietf:wg:oauth:2.0:oob";
            //    var res = await InvokeApi.Authenticate(strRefreshToken, string.Empty, HttpMethod.Post);

            //    string strRefreshToken1 = "https://login.microsoftonline.com/csub2c.onmicrosoft.com/oauth2/v2.0/token?p=b2c_1_b2csignin&grant_type=refresh_token&client_id=3bdf8223-746c-42a2-ba5e-0322bfd9ff76&scope=3bdf8223-746c-42a2-ba5e-0322bfd9ff76" + " " + "offline_access&refresh_token=" + code + "&redirect_uri=urn:ietf:wg:oauth:2.0:oob";
            //    var res1 = await InvokeApi.Authenticate(strRefreshToken1, string.Empty, HttpMethod.Post);

            //    preferenceHandler.SetToken(token.id_token);
            var responseUser = await InvokeApi.Invoke(Constants.API_GET_CURRENTUSER, string.Empty, HttpMethod.Get, PreferenceHandler.GetToken());

            if (responseUser.StatusCode != 0)
            {
                GetCurrentUserResponse(responseUser);
            }
            UserDetails user = PreferenceHandler.GetUserDetails();

            if (user.RoleId == (int)Constants.USER_ROLE.ADMIN)
            {
                bool isNetworkEnabled = Utils.Utils.IsNetworkEnabled(this);

                LayoutInsightData = FindViewById <LinearLayout>(Resource.Id.layout_insight_data);
                textViewConsumed  = FindViewById <TextView>(Resource.Id.tv_top_consumed);
                textViewExpected  = FindViewById <TextView>(Resource.Id.tv_top_expected);
                textViewOverused  = FindViewById <TextView>(Resource.Id.tv_top_overused);
                textViewInsights  = FindViewById <TextView>(Resource.Id.tv_insights);

                textViewInsights.Click += delegate
                {
                    // Show insights(Recommendations) Activity
                    Intent intent = new Intent(Application.Context, typeof(InsightsActivity));
                    StartActivity(intent);
                };

                if (!isNetworkEnabled)
                {
                    Utils.Utils.ShowToast(this, "Please enable your internet connection !");
                    //ShowToast("Please enable your internet connection !");
                }
                ////Show Map Fragment
                //GoogleMapOptions mapOptions = new GoogleMapOptions()
                //.InvokeMapType(GoogleMap.MapTypeNormal)
                //.InvokeZoomControlsEnabled(false)
                //.InvokeCompassEnabled(true);

                //_myMapFragment = MapFragment.NewInstance(mapOptions);
                //FragmentTransaction tx = FragmentManager.BeginTransaction();
                //tx.Add(Resource.Id.fragment_container, _myMapFragment, "map");
                //tx.Commit();

                //_myMapFragment.GetMapAsync(this);

                //var preferenceHandler = new PreferenceHandler();
                int userId = PreferenceHandler.GetUserDetails().UserId;
                if (userId != -1)
                {
                    if (isNetworkEnabled)
                    {
                        GetMeterDetails(userId);
                        GetMonthlyConsumptionDetails(userId);
                        ShowInsights(null);
                        GetInsights(userId);
                    }
                    else
                    {
                        Utils.Utils.ShowToast(this, "Please enable your internet connection !");
                    }
                }
                else
                {
                    Utils.Utils.ShowToast(this, "Invalid User Id. Please Login Again !");
                }
            }
            else
            {
                //Show Student Fragment

                var newFragment = new StudentFragment();
                var ft          = FragmentManager.BeginTransaction();
                ft.Add(Resource.Id.fragment_container, newFragment);
                ft.Commit();
                HideInsights();
            }
            // }
        }