Ejemplo n.º 1
0
        private static Log CheckLicenseStatus(string macAddress, string productCode, string clientPublicKey, string functionName)
        {
            string httpGetURL = ConfigUtils.GetSetting(DefineUtils.Lm_Url);

            if (!string.IsNullOrEmpty(httpGetURL))
            {
                httpGetURL = string.Concat(httpGetURL, "/api/user/checklicensestatus");
                httpGetURL = string.Concat(httpGetURL, "/", macAddress);
                httpGetURL = string.Concat(httpGetURL, "/", productCode);
                httpGetURL = string.Concat(httpGetURL, "/", functionName);
                httpGetURL = string.Concat(httpGetURL, "/?clientPublicKey=", clientPublicKey);

                HttpWebRequest webRequest = ( HttpWebRequest )WebRequest.Create(httpGetURL);
                webRequest.Method      = "GET";
                webRequest.ContentType = "application/json";

                HttpWebResponse webResponse      = ( HttpWebResponse )webRequest.GetResponse();
                Encoding        enc              = Encoding.GetEncoding("utf-8");
                StreamReader    loResponseStream = new StreamReader(webResponse.GetResponseStream(), enc);
                string          result           = loResponseStream.ReadToEnd();
                loResponseStream.Close();
                webResponse.Close();

                return(JsonConvert.DeserializeObject <Log> (result));
            }

            return(new Log());
        }
Ejemplo n.º 2
0
        public static bool CheckInstallerExistence(string productVersion)
        {
            bool result = false;

            try
            {
                string httpGetURL = ConfigUtils.GetSetting(DefineUtils.Lm_Url);
                httpGetURL = string.Concat(httpGetURL, "/api/upload/isinstallerexisted");
                httpGetURL = string.Concat(httpGetURL, "/", productVersion);

                HttpWebRequest webRequest = ( HttpWebRequest )WebRequest.Create(httpGetURL);
                webRequest.Method      = "GET";
                webRequest.ContentType = "application/json";

                HttpWebResponse webResponse      = ( HttpWebResponse )webRequest.GetResponse();
                Encoding        enc              = Encoding.GetEncoding("utf-8");
                StreamReader    loResponseStream = new StreamReader(webResponse.GetResponseStream(), enc);
                result = bool.Parse(loResponseStream.ReadToEnd());

                loResponseStream.Close();
                webResponse.Close();
            }
            catch (Exception)
            {
                result = false;
            }

            return(result);
        }
Ejemplo n.º 3
0
        public static string GetLatestPatch(string productVersion)
        {
            string result = string.Empty;

            string httpGetURL = ConfigUtils.GetSetting(DefineUtils.Lm_Url);

            if (!string.IsNullOrEmpty(httpGetURL))
            {
                httpGetURL = string.Concat(httpGetURL, "/api/productversion/getlatestpatch");
                httpGetURL = string.Concat(httpGetURL, "/", productVersion);

                HttpWebRequest webRequest = ( HttpWebRequest )WebRequest.Create(httpGetURL);
                webRequest.Method      = "GET";
                webRequest.ContentType = "application/json";

                HttpWebResponse webResponse      = ( HttpWebResponse )webRequest.GetResponse();
                Encoding        enc              = Encoding.GetEncoding("utf-8");
                StreamReader    loResponseStream = new StreamReader(webResponse.GetResponseStream(), enc);
                result = loResponseStream.ReadToEnd();

                loResponseStream.Close();
                webResponse.Close();
            }

            return(result);
        }
Ejemplo n.º 4
0
        private static void DownloadPatch(string productVersion)
        {
            Uri uri = new Uri(string.Concat(ConfigUtils.GetSetting(DefineUtils.Lm_Url), "/File/DownloadPatch?productversion=", productVersion));

            patch = string.Concat(Path.GetTempPath(), "patch.exe");

            if (CheckPatchExistence())
            {
                Download download = new Download(uri, patch);
                download.ShowDialog();
            }
        }
Ejemplo n.º 5
0
        public static void DownloadVersion(string productVersion)
        {
            Uri uri = new Uri(string.Concat(ConfigUtils.GetSetting(DefineUtils.Lm_Url), "/api/upload/download/", productVersion));

            patch = string.Concat(Path.GetTempPath(), "setup_", productVersion, ".exe");

            if (CheckInstallerExistence(productVersion))
            {
                Download download = new Download(uri, patch);
                download.ShowDialog();
            }
        }
Ejemplo n.º 6
0
        private static void CreateLog(Log log)
        {
            string httpPostURL = string.Concat(ConfigUtils.GetSetting(DefineUtils.Lm_Url), "/api/log");

            JsonSerializer serializer = new JsonSerializer();

            serializer.Converters.Add(new JavaScriptDateTimeConverter());
            serializer.NullValueHandling = NullValueHandling.Ignore;

            string jsonString = JsonConvert.SerializeObject(log, Formatting.Indented);

            HttpWebRequest request = ( HttpWebRequest )WebRequest.Create(httpPostURL);

            request.Method = "POST";

            UTF8Encoding encoding = new UTF8Encoding();

            byte [] byteArray = encoding.GetBytes(jsonString);

            request.ContentLength = byteArray.Length;
            request.ContentType   = "application/json";

            using (Stream dataStream = request.GetRequestStream())
            {
                dataStream.Write(byteArray, 0, byteArray.Length);
            }

            long length = 0;

            try
            {
                using (HttpWebResponse response = ( HttpWebResponse )request.GetResponse())
                {
                    // got response
                    length = response.ContentLength;
                }
            }
            catch (WebException ex)
            {
                WebResponse errorResponse = ex.Response;
                using (Stream responseStream = errorResponse.GetResponseStream())
                {
                    StreamReader reader    = new StreamReader(responseStream, Encoding.GetEncoding("utf-8"));
                    string       errorText = reader.ReadToEnd();
                }
            }
        }