Beispiel #1
0
        public async Task <HttpResponseMessage> CheckUpdateDownload(UserUpdateCheck obj)
        {
            ApiResponse apiResponse = new ApiResponse();
            LoginRepo   _loginRepo  = new LoginRepo();

            try
            {
                HttpResponseMessage objUserUpdate = await _loginRepo.CheckUpdateDownload(obj);

                return(objUserUpdate);
            }
            catch (Exception ex)
            {
                apiResponse = TaskUTL.GenerateExceptionResponse(ex, _pageName, true);
                return(null);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Only for Version Check
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public async Task <UserUpdateRespCheck> CheckUpdate(UserUpdateCheck obj)
        {
            try
            {
                UserUpdateRespCheck objUserupdate = new UserUpdateRespCheck();
                using (SqlCommand dataCmd = new SqlCommand("CheckUpdateExists", objCommonDB.con))
                {
                    dataCmd.CommandType = CommandType.StoredProcedure;
                    dataCmd.Parameters.AddWithValue("@UserId", obj.UserId);
                    dataCmd.Parameters.AddWithValue("@Token", obj.Token);
                    dataCmd.Parameters.AddWithValue("@CurrExeVersion", obj.CurrentVersion);

                    if (objCommonDB.con.State == ConnectionState.Closed)
                    {
                        objCommonDB.con.Open();
                    }
                    var reader = await dataCmd.ExecuteReaderAsync();

                    while (reader.Read())
                    {
                        objUserupdate.IsUpdateAvailable = Convert.ToBoolean(reader["IsUpdateAvailable"]);
                        objUserupdate.IsValidUser       = Convert.ToBoolean(reader["IsValidUser"]);
                        objUserupdate.LatestVersion     = Convert.ToInt32(reader["VersionId"]);

                        //objUserupdate._apiUrl = reader["ApiUrl"].ToString();

                        //objUserupdate._exes = reader["Exes"].ToString();
                        //objUserupdate._updateUrl = reader["UpdateUrl"].ToString();
                    }
                    return(objUserupdate);
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                if (objCommonDB.con.State == ConnectionState.Open)
                {
                    objCommonDB.con.Close();
                }
            }
        }
Beispiel #3
0
        public async Task <ApiResponse> CheckUpdate(UserUpdateCheck obj)
        {
            LoginRepo   loginRepo   = new LoginRepo();
            ApiResponse apiResponse = new ApiResponse();

            try
            {
                UserUpdateRespCheck objCheckUpdate = await loginRepo.CheckUpdate(obj);

                if (objCheckUpdate.IsValidUser)
                {
                    apiResponse = TaskUTL.CheckUpdate(objCheckUpdate.IsValidUser, objCheckUpdate.IsUpdateAvailable, obj.Token, objCheckUpdate);
                }
            }
            catch (Exception ex)
            {
                apiResponse = TaskUTL.GenerateExceptionResponse(ex, _pageName, true);
            }
            return(apiResponse);
        }
Beispiel #4
0
        /// <summary>
        /// Version check + Download new version
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public async Task <HttpResponseMessage> CheckUpdateDownload(UserUpdateCheck obj)
        {
            try
            {
                UserUpdateResp objUserupdate = new UserUpdateResp();
                using (SqlCommand dataCmd = new SqlCommand("GetLatestVersionByUser", objCommonDB.con))
                {
                    dataCmd.CommandType = CommandType.StoredProcedure;
                    dataCmd.Parameters.AddWithValue("@UserId", obj.UserId);
                    dataCmd.Parameters.AddWithValue("@Token", obj.Token);
                    dataCmd.Parameters.AddWithValue("@CurrExeVersion", obj.CurrentVersion);

                    if (objCommonDB.con.State == ConnectionState.Closed)
                    {
                        objCommonDB.con.Open();
                    }
                    var reader = await dataCmd.ExecuteReaderAsync();

                    while (reader.Read())
                    {
                        //        objUserupdate._latestVersion = reader["LatestVersion"].ToString();
                        //        objUserupdate._isValid = Convert.ToBoolean(reader["IsValid"]);
                        objUserupdate.ApiUrl        = reader["ApiUrl"].ToString();
                        objUserupdate.UpdateUrl     = reader["UpdateUrl"].ToString();
                        objUserupdate.FileName      = reader["FileName"].ToString();
                        objUserupdate.FilePath      = reader["FilePath"].ToString();
                        objUserupdate.LatestVersion = Convert.ToInt32(reader["VersionId"].ToString());
                        objUserupdate._exes         = reader["FileName"].ToString();
                    }
                    var multiFileContent = new MultipartContent();
                    if (obj.CurrentVersion != objUserupdate.LatestVersion)
                    {
                        //string[] _arrExe = objUserupdate.FileName.Split(',');

                        List <int> versionList = new List <int>();
                        versionList.Add(objUserupdate.LatestVersion);
                        //List<string> list = new List<string>(_arrExe);
                        //var fileNames = new List<string>(_arrExe);
                        //var objectContent = new ObjectContent<List<string>>(fileNames, new System.Net.Http.Formatting.JsonMediaTypeFormatter());
                        //multiFileContent.Add(objectContent);

                        var objectContent1 = new ObjectContent <List <int> >(versionList, new System.Net.Http.Formatting.JsonMediaTypeFormatter());
                        multiFileContent.Add(objectContent1);

                        var fullPath = objUserupdate.FilePath + objUserupdate.FileName;

                        var fileBytes = File.ReadAllBytes(fullPath);

                        //for (int i = 0; i < fileNames.Count ; i++)
                        //{
                        //  string fileName = fileNames[i].ToString();
                        // var filePath = objUserupdate.UpdateUrl + fileName;
                        //client = new WebClient();

//                            byte[] fileBytes = client.DownloadData((new Uri(filePath)));
                        var fileMemoryStream = new MemoryStream(fileBytes);

                        var fileContent = new StreamContent(fileMemoryStream);
                        fileContent.Headers.ContentDisposition          = new ContentDispositionHeaderValue("attachment");
                        fileContent.Headers.ContentDisposition.FileName = objUserupdate.FileName;
                        fileContent.Headers.ContentType   = new MediaTypeHeaderValue("application/octet-stream");
                        fileContent.Headers.ContentLength = fileMemoryStream.Length;

                        multiFileContent.Add(fileContent);
                        //}
                    }
                    var response = new HttpResponseMessage(HttpStatusCode.OK);
                    //response.Headers.Add("objUserupdate", new JavaScriptSerializer().Serialize(objUserupdate));
                    response.Content = multiFileContent;
                    return(response);
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                if (objCommonDB.con.State == ConnectionState.Open)
                {
                    objCommonDB.con.Close();
                }
            }
        }