예제 #1
0
        /// <summary>
        /// Gets the access token to keep alive login session to Stomt.
        /// </summary>
        /// <param name="s_username">The account's username.</param>
        /// <param name="s_password">The account's password.</param>
        /// <returns>The account's login access token and system's message.</returns>
        public static async Task <information> uf_atsk_cdt_Login(string s_username, string s_password)
        {
            // Get login data from stomt's api asyncrhonously.
            object o_login_values = await uf_atsk_o_GetDataFromRequest(stomt_feature.login, stomt_authentication.normal,
                                                                       new stomt_parameters().uf_cdt_SetNormalLoginParameters(s_username, s_password));

            // Convert the data from an object form to a more easy handled one.
            List <KeyValuePair <string, object> > kvpsol_login_values = ConversionClass.uf_t_ConvertObjectToGeneric <List <KeyValuePair <string, object> > >(o_login_values);

            // Gets a smaller portion of these data to allow the easier finding of the wanted values.
            List <KeyValuePair <string, object> > kvpsol_data_values = DataClass.uf_t_GetConvertedValueFromKeyValuePairListWithStringKey <List <KeyValuePair <string, object> > >(kvpsol_login_values, "data");

            // If no data is found, then something happened and display the error
            if (DataClass.uf_b_ValidList(kvpsol_data_values) == false)
            {
                // Return the error about the lack of data.
                return(new information(Constant.publ_cs_generic_error, DataClass.uf_t_GetConvertedValueFromKeyValuePairListWithStringKey <string>(kvpsol_login_values, "error")));
            }

            // Get the accees token from data's smaller portion.
            string s_access_token = DataClass.uf_t_GetConvertedValueFromKeyValuePairListWithStringKey <string>(kvpsol_data_values, "accesstoken");

            // Check if access token is valid.
            if (string.IsNullOrWhiteSpace(s_access_token) == false)
            {
                // Check if there is already an access token header to avoid duplicates.
                if (publ_httpc_client.DefaultRequestHeaders.Contains("accesstoken") == true)
                {
                    // Removes the old value.
                    publ_httpc_client.DefaultRequestHeaders.Remove("accesstoken");
                }

                // Adds the new access token to header.
                publ_httpc_client.DefaultRequestHeaders.Add("accesstoken", s_access_token);

                // Then return the access token and the success message.
                return(new information(s_access_token, Constant.publ_cs_generic_success_message));
            }

            // If the access token is invalid, then return a no data error.
            return(new information(Constant.publ_cs_generic_error, Constant.publ_cs_generic_no_data_message));
        }
예제 #2
0
 /// <summary>
 /// Searches a given key in a list and gets the converted value.
 /// </summary>
 /// <typeparam name="T">The conversion data type.</typeparam>
 /// <param name="kvpstl_values">The list to search the key value.</param>
 /// <param name="s_key">The key value to search in the list.</param>
 /// <returns>The converted value that the key belongs.</returns>
 public static T uf_t_GetConvertedValueFromKeyValuePairListWithStringKey <T>(List <KeyValuePair <string, object> > kvpsol_values, string s_key)
 {
     // Get the value from the given List, checked by requested key and convert it to r
     return(ConversionClass.uf_t_ConvertObjectToGeneric <T>(uf_t_GetValueFromKeyValuePairListWithStringKey(kvpsol_values, s_key)));
 }