Exemple #1
0
        public async Task <string> GetAnalysisCaseRequest()
        {
            var url      = Route.SERVER_PATH + Route.API_PATH + Route.URLDictionary["api.get_analysis_case"];
            var request  = new Autin.Services.HttpRequest(); // [email protected], Mba287xd!
            var response = await request.PostRequest(url,
                                                     new Dictionary <string, string>() {
                { "user_id", $"{SystemManager.Instance.CurrentUser.Id}" },
                { "client_id", $"{SystemManager.Instance.CurrentUser.ClientId}" },
                { "case_id", $"{SystemManager.Instance.CurrentCaseId}" },
                { "client_token", $"{SystemManager.Instance.CurrentUser.ClientToken}" }
            });

            try
            {
                if (SystemManager.Instance.CurrentUnitList == null)
                {
                    SystemManager.Instance.CurrentUnitList = new Unit();
                }
                if (SystemManager.Instance.CaseList == null)
                {
                    SystemManager.Instance.CaseList = new List <IAutinDataModel>();
                }
                SystemManager.Instance.CaseList.Clear();
                var caseInfoList = AnalysisCaseInfo.FromJson(response);
                SystemManager.Instance.CaseList.AddRange(caseInfoList);
                SystemManager.Instance.CurrentSettlementDate = caseInfoList.Where(p => p.CaseId == "default").Select(p => p.SettlementDate).FirstOrDefault();
                Console.WriteLine("get AnalysisCase list successfully!");
                return("success");
            }
            catch
            {
                Console.WriteLine("get AnalysisCase list fails!");
                return("fails");
            }
        }
Exemple #2
0
        public async Task <string> GetInfoRequest()
        {
            var url      = Route.SERVER_PATH + Route.API_PATH + Route.URLDictionary["api.get_control_info"];
            var request  = new Autin.Services.HttpRequest(); // [email protected], Mba287xd!
            var response = await request.PostRequest(url,
                                                     new Dictionary <string, string>() {
                { "user_id", $"{SystemManager.Instance.CurrentUser.Id}" },
                { "client_id", $"{SystemManager.Instance.CurrentUser.ClientId}" },
                { "case_id", $"{SystemManager.Instance.CurrentCaseId}" },
                { "client_token", $"{SystemManager.Instance.CurrentUser.ClientToken}" },
                { "settlement_date", $"{SystemManager.Instance.CurrentSettlementDate}" }
            });

            try
            {
                SystemManager.Instance.CurrentControlInfoList = ControlInfo.FromJson(response);
                Console.WriteLine("get control info list successfully!");
                return("success");
            }
            catch
            {
                Console.WriteLine("get control info list fails!");
                return("fails");
            }
        }
Exemple #3
0
        public async Task <string> LoginRequest()
        {
            var url      = Route.SERVER_PATH + Route.API_PATH + Route.URLDictionary["api.login"];
            var request  = new Autin.Services.HttpRequest(); // [email protected], Mba287xd!
            var response = await request.PostRequest(url,
                                                     new Dictionary <string, string>() {
                { "email", $"{UserName}" },
                { "password", $"{Password}" }
            });

            try
            {
                if (SystemManager.Instance.CurrentUser != null)
                {
                    SystemManager.Instance.CurrentUser.ClientToken = ""; // clear ClientToken
                }
                SystemManager.Instance.CurrentUser = User.FromJson(response);
                Console.WriteLine("Login successfully!");
                return("success");
            }
            catch
            {
                Console.WriteLine("Login fails!");
                return("fails");
            }
        }
Exemple #4
0
        public async Task <string> GetUnitPriceRequest(string unitId)
        {
            var url      = Route.SERVER_PATH + Route.API_PATH + Route.URLDictionary["api.get_unit_price"];
            var request  = new Autin.Services.HttpRequest(); // [email protected], Mba287xd!
            var response = await request.PostRequest(url,
                                                     new Dictionary <string, string>() {
                { "user_id", $"{SystemManager.Instance.CurrentUser.Id}" },
                { "client_id", $"{SystemManager.Instance.CurrentUser.ClientId}" },
                { "case_id", $"{SystemManager.Instance.CurrentCaseId}" },
                { "unit_id", unitId },
                { "client_token", $"{SystemManager.Instance.CurrentUser.ClientToken}" },
                { "settlement_date", $"{SystemManager.Instance.CurrentSettlementDate}" }
            });

            if (response.Contains("Error"))
            {
                return("fails");
            }
            try
            {
                if (SystemManager.Instance.CurrentUnitList == null)
                {
                    SystemManager.Instance.CurrentUnitList = new Unit();
                }
                SystemManager.Instance.CurrentUnitList.UnitPrice = UnitPrice.FromJson(response);
                Console.WriteLine("get UnitPrice list successfully!");
                return(response);
            }
            catch
            {
                Console.WriteLine("get UnitParam list fails!");
                return("fails");
            }
        }
Exemple #5
0
        public async Task <string> PostSettlement(long id, string clientToken, long clientId, string case_id, DateTimeOffset settlementDate)
        {
            var url      = Route.SERVER_PATH + Route.API_PATH + Route.URLDictionary["api.post_settlement"];
            var request  = new Autin.Services.HttpRequest(); // [email protected], Mba287xd!
            var response = await request.PostRequest(url,
                                                     new Dictionary <string, string>() {
                { "user_id", $"{id}" },
                { "client_id", $"{clientId}" },
                { "client_token", $"{clientToken}" },
                { "case_id", case_id },
                { "settlement_date", $"{settlementDate}" },
            });

            return(response);
        }
Exemple #6
0
        public async Task <string> SetConsumerDeclareRequest(long id, string nodeId, string caseId, string clientToken, long clientId, DateTimeOffset settlementDate, string powerLoad)
        {
            var url      = Route.SERVER_PATH + Route.API_PATH + Route.URLDictionary["api.set_consumer_load"];
            var request  = new Autin.Services.HttpRequest(); // [email protected], Mba287xd!
            var response = await request.PostRequest(url,
                                                     new Dictionary <string, string>() {
                { "node_id", $"{nodeId}" },
                { "user_id", $"{id}" },
                { "client_id", $"{clientId}" },
                { "case_id", $"{caseId}" },
                { "client_token", $"{clientToken}" },
                { "settlement_date", $"{settlementDate}" },
                { "power_load", powerLoad },
            });

            return(response);
        }
Exemple #7
0
        public async Task <string> SetUnitPriceRequest(long id, string unitId, long clientId, string caseId, string clientToken, DateTimeOffset settlementDate, string unitPrice, string unitStartPrice)
        {
            var url      = Route.SERVER_PATH + Route.API_PATH + Route.URLDictionary["api.set_unit_price_data"];
            var request  = new Autin.Services.HttpRequest(); // [email protected], Mba287xd!
            var response = await request.PostRequest(url,
                                                     new Dictionary <string, string>() {
                { "user_id", $"{id}" },
                { "unit_id", $"{unitId}" },
                { "client_id", $"{clientId}" },
                { "case_id", $"{caseId}" },
                { "client_token", $"{clientToken}" },
                { "settlement_date", $"{settlementDate}" },
                { "unit_price", unitPrice },
                { "unit_start_price", unitStartPrice }
            });

            return(response);
        }
Exemple #8
0
        public async void LoginRequest()
        {
            var url      = "http://59.110.173.242/api/login";
            var request  = new Autin.Services.HttpRequest(); // [email protected], Mba287xd!
            var response = await request.PostRequest(url, new Dictionary <string, string>() { { "email", $"{textboxUsername.Text}" }, { "password", $"{textboxPassword.Password}" } });

            try
            {
                if (SystemManager.Instance.CurrentUser != null)
                {
                    SystemManager.Instance.CurrentUser.ClientToken = ""; // clear ClientToken
                }
                SystemManager.Instance.CurrentUser = User.FromJson(response);
                NotifyContainer?.Invoke(new object[] { "success" });
                Console.WriteLine("Login successfully!");
            }
            catch
            {
                NotifyContainer?.Invoke(new object[] { "fails" });
                Console.WriteLine("Login fails!");
            }
        }
Exemple #9
0
        public async Task <string> LogoutRequest()
        {
            var url      = Route.SERVER_PATH + Route.API_PATH + Route.URLDictionary["api.logout"];
            var request  = new Autin.Services.HttpRequest(); // [email protected], Mba287xd!
            var response = await request.PostRequest(url,
                                                     new Dictionary <string, string>() {
                { "email", $"{UserName}" },
                { "password", $"{Password}" }
            });

            try
            {
                if (response.Contains("User logged out"))
                {
                    Console.WriteLine("Logout successfully!");
                }
                return("success");
            }
            catch
            {
                Console.WriteLine("Login fails!");
                return("fails");
            }
        }