Ejemplo n.º 1
0
        public TResult Login(string name, string pwd)
        {
            _Logger.LogInformation("登录中....");

            if (string.IsNullOrWhiteSpace(name) || string.IsNullOrWhiteSpace(pwd))
            {
                return(TResult.Fail("用户名/密码不能为空"));
            }
            else
            {
                ClaimsIdentity claimIdentity = new ClaimsIdentity();
                claimIdentity.AddClaim(new Claim(ClaimTypes.Name, name));
                claimIdentity.AddClaim(new Claim(ClaimTypes.Role, "AAA"));
                claimIdentity.AddClaim(new Claim("自定义组策略", "this is my custom policy"));


                claimIdentity.AddClaim(new Claim("UserID", "012345"));

                AuthenticationProperties properties = new AuthenticationProperties();

                properties.GetJwtAuthenticationProperties("ilbli_custom_key", DateTime.UtcNow.AddMinutes(10), claims: claimIdentity.Claims);

                string token = properties.GetTokenValue("ILBLI_Token");
                return(TResult.DataSuccess(token));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 啟用/停用 APP
        /// </summary>
        /// <returns></returns>
        public TResult <bool> EnableOrDisableApp(AppListItem appListItem)
        {
            //UI 畫面  是啟用 就是 反向
            string status = appListItem.Status ? AppStatus.Disable : AppStatus.Enable;

            if (status == AppStatus.Enable && !string.IsNullOrEmpty(appListItem.OSType))
            {
                //先檢查 有無其他版本啟用 不包含自己
                WisAppOs wisAppOs = _appListService.CheckAppOsStatus(appListItem.AppID, appListItem.OSType == "IOS" ? 1 : 2);

                if (wisAppOs != null && wisAppOs.AppOSID != Convert.ToInt32(appListItem.AppOSID))
                {
                    return(TResult <bool> .Fail(false, FaultInfoRcConstants.ERR_CODE_FAIL, "已有其本版已啟用!"));
                }
            }

            bool updated = _appListService.EnableOrDisableApp(appListItem.AppOSID, status);

            if (updated)
            {
                return(TResult <bool> .OK(true, "OK"));
            }
            else
            {
                return(TResult <bool> .Fail(false, FaultInfoRcConstants.ERR_CODE_FAIL, "updated fail!"));
            }
        }
Ejemplo n.º 3
0
        public TResult WriteAndGetCache(string cacheStr)
        {
            bool isExist = this._BaseCache.Exist("a");

            if (!isExist)
            {
                this._BaseCache.Set("a", cacheStr, new DistributedCacheEntryOptions().SetAbsoluteExpiration(DateTimeOffset.Now.AddMinutes(1)));
            }
            var msg = this._BaseCache.Get <string>("a", out isExist);

            if (isExist)
            {
                return(TResult.DataSuccess(msg));
            }
            else
            {
                return(TResult.Fail());
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 如果資料 只新增 AppList 需刪除 AppID 就可
        /// 如果資料 新增到 AppOS 需刪除 AppOSID
        /// </summary>
        /// <param name="appListItem"></param>
        /// <returns></returns>
        public TResult <bool> DeleteApp(AppListItem appListItem)
        {
            bool deleted = false;

            if (!string.IsNullOrEmpty(appListItem.AppOSID))
            {
                //有值 代表需刪除  AppOS 就可以
                deleted = _appListService.DeleteAppOs(appListItem.AppOSID);
            }
            else
            {
                //無值 代表 只新增 AppList 階段 需刪除 AppID 就可
                deleted = _appListService.DeleteApp(appListItem.AppID);
            }
            if (deleted)
            {
                return(TResult <bool> .OK(true, "OK"));
            }
            else
            {
                return(TResult <bool> .Fail(false, FaultInfoRcConstants.ERR_CODE_FAIL, "delete fail!"));
            }
        }
Ejemplo n.º 5
0
        public TResult <LoginViewModel> Login(string userId, string password)
        {
            #region  Use AD service to auth

            bool isPassByAd = _authService.ValidateByAd(userId, password);

            //AD 認證沒過 回傳失敗
            if (!isPassByAd)
            {
                return(TResult <LoginViewModel> .Fail(new LoginViewModel
                {
                    IsLogin = isPassByAd,
                    IsAdmin = false,
                    IsMember = false,
                }, FaultInfoRcConstants.LOGIN_FAIL, "Account/Password error."));
            }

            #endregion

            //bool isExisted = _authService.FindSecurityUserAccount(userId.Trim());

            #region 找査  SecurityUserAccount Table 無資料 insert

            //if (!isExisted)
            //{
            //    DateTime dateTime = DateTime.Now;
            //    _authService.InsertSecurityUserAccount(new SecurityUserAccount
            //    {
            //        GroupID = "Console",
            //        AccountID = userId,
            //        Name = userId,
            //        Description = "AD Account",
            //        Password = userId,
            //        Startup = true,
            //        PWLastUpdateTime = null,
            //        PWType = 0,
            //        CreateTime = dateTime,
            //        dModifyTime = dateTime,
            //        iFailTimes = 0,
            //        dLockTime = null,
            //        cRoleID = 0,
            //        AD_CheckFlag = false,
            //        cCallID = null,
            //        cPWD = null,
            //        DEPARTMENT = "",
            //        Email = "",
            //        DomainName = "",
            //    });
            //}

            #endregion

            List <string> uID = new List <string> {
                userId.Trim()
            };

            List <MdsAdUserData> mdsAdUserData = _authService.GetMdsAdUser(uID);

            //檢查是否為 Admin 權限
            List <WisGroupUser> wisGroupUser = _authService.CheckIsAdminOrMember(userId);

            //DB 目前狀況可能會有查到同一個工號 會有雙重身份 admin 和 apadmin
            //雙重身分 只要有找到 Admin 就是管理者
            if (wisGroupUser.Any(p => p.GroupID == "admin"))
            {
                //為Admin 管理者可使用後台 APP List
                return(TResult <LoginViewModel> .OK(new LoginViewModel
                {
                    UID = mdsAdUserData.Count > 0 ? mdsAdUserData.FirstOrDefault().Uid : "",
                    Name = mdsAdUserData.Count > 0 ? mdsAdUserData.FirstOrDefault().Name : "",
                    IsLogin = isPassByAd,
                    IsAdmin = true,
                    IsMember = false,
                }, "is login successful!"));
            }
            else
            {
                //為一般 使用者只能使用 下載app 版本裝到手機上
                return(TResult <LoginViewModel> .OK(new LoginViewModel
                {
                    UID = mdsAdUserData.Count > 0 ? mdsAdUserData.FirstOrDefault().Uid : "",
                    Name = mdsAdUserData.Count > 0 ? mdsAdUserData.FirstOrDefault().Name : "",
                    IsLogin = isPassByAd,
                    IsAdmin = false,
                    IsMember = true,
                }, "is login successful!"));
            }
        }
        /// <summary>
        /// 更新 Wis APP os
        /// </summary>
        /// <param name="appOsInfo"></param>
        /// <returns></returns>
        public TResult <bool> InsertOrModifyAppOs(AppOsInfo appOsInfo)
        {
            DateTime date = DateTime.Now;

            WisAppOs wisAppOs = _mapper.Map <AppOsInfo, WisAppOs>(appOsInfo);

            List <WisAppPhoto> wisAppPhoto = _mapper.Map <List <AppPhotoContent>, List <WisAppPhoto> >(appOsInfo.Photo);

            //視為存在條件  AppID & OsType & Version
            WisAppOs wisAppOsFromDb = _appListService.AppOsIsExisted(appOsInfo.AppID, appOsInfo.OSType, appOsInfo.Version);

            //沒有代表是新增
            if (wisAppOsFromDb == null)
            {
                List <WisAppOsOther> insertWisAppOsOthers = new List <WisAppOsOther>();
                wisAppOs.DelFlag        = false;
                wisAppOs.LastUpdateUser = "******";
                wisAppOs.CreateDT       = date;
                wisAppOs.LastUpdateDT   = date;

                //多載點處理
                foreach (DownloadUrlList downloadUrl in appOsInfo.DownloadUrlList)
                {
                    insertWisAppOsOthers.Add(new WisAppOsOther
                    {
                        AppID          = wisAppOs.AppID,
                        AppOsID        = 0,//等transaction當中insert
                        Site           = downloadUrl.Site,
                        OSType         = wisAppOs.OSType,
                        Version        = wisAppOs.Version,
                        FileName       = appOsInfo.FileName, //IOS 為 ipa路徑 Android 為原始 apk檔案名稱
                        FilePath       = downloadUrl.Url,    //IOS 為plist路徑  Android 為apk路徑
                        LastUpdateUser = "******",
                        LastUpdateDT   = date,
                        CreateDT       = date
                    });
                }

                bool isInserted = _appListService.DisableAppOsStatusAndInsertAppOsAndPhotoAndOsOther(wisAppOs, wisAppPhoto, insertWisAppOsOthers);

                if (isInserted)
                {
                    //取新增後的 appOsID
                    int insertPrimaryKey = _appListService.GetAppOs(appOsInfo.AppID).Where(p => p.OSType == appOsInfo.OSType).Max(p => p.AppOSID);
                    return(TResult <bool> .OK(true, insertPrimaryKey.ToString()));
                }
                else
                {
                    return(TResult <bool> .Fail(false, FaultInfoRcConstants.ERR_CODE_FAIL, "Insert App Os fail!"));
                }
            }

            //有在DB 找到 代表更新
            if (wisAppOsFromDb != null)
            {
                List <AppOsOther> updateAppOsOthers = new List <AppOsOther>();
                wisAppOs.DelFlag        = wisAppOsFromDb.DelFlag;
                wisAppOs.LastUpdateUser = wisAppOsFromDb.LastUpdateUser;
                wisAppOs.CreateDT       = wisAppOsFromDb.CreateDT;
                wisAppOs.LastUpdateDT   = date;

                //多載點 處理
                foreach (DownloadUrlList downloadUrl in appOsInfo.DownloadUrlList)
                {
                    AppOsOther appOsOther = appOsInfo.AppOsOther.Where(p => p.Site == downloadUrl.Site).Select(p => { return(p); }).FirstOrDefault();
                    // 更新 ipa or apk 檔案
                    appOsOther.FileName = wisAppOs.FileName;
                    //更新 plist
                    appOsOther.FilePath = downloadUrl.Url;
                    updateAppOsOthers.Add(appOsOther);
                }

                List <WisAppOsOther> updateWisAppOsOther = _mapper.Map <List <AppOsOther>, List <WisAppOsOther> >(updateAppOsOthers);

                bool isUpdated = _appListService.DisableAppOsStatusAndModifyAppOsAndPhotoAndOsOther(wisAppOs, wisAppPhoto, updateWisAppOsOther);

                if (isUpdated)//返回 更新
                {
                    return(TResult <bool> .OK(true, appOsInfo.AppOSID.ToString()));
                }
                else
                {
                    return(TResult <bool> .Fail(false, FaultInfoRcConstants.ERR_CODE_FAIL, "Update App Os fail!"));
                }
            }

            return(TResult <bool> .Fail(false, FaultInfoRcConstants.ERR_CODE_FAIL, "The proccess is fail!"));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 新增時需檢查置頂資料
        /// </summary>
        /// <param name="appNameCreate"></param>
        /// <returns></returns>
        public TResult <ResponseAppNameCreate> InsertAppName(AppNameCreate appNameCreate)
        {
            List <WisAppUserList> wisAppUserList = new List <WisAppUserList>();

            bool isExisted = _appListService.AppNameIsExisted(appNameCreate.AppName);

            if (appNameCreate.Category == "None")
            {
                return(TResult <ResponseAppNameCreate> .Fail(new ResponseAppNameCreate { IsSuccessful = false, AppID = "" }, FaultInfoRcConstants.ERR_CODE_FAIL, "請選擇類別"));
            }

            if (isExisted)
            {
                return(TResult <ResponseAppNameCreate> .Fail(new ResponseAppNameCreate { IsSuccessful = false, AppID = "" }, FaultInfoRcConstants.ERR_CODE_FAIL, "App 名稱已存在"));
            }

            //撈出置頂資料
            List <InSideOrOutSideApp> inSideOrOutSideApps = _appListService.GetIsTopAppList();

            #region  Check 置頂

            //如果要頂置 檢查頂置規則 企業APP 2筆 外部 App 2筆
            var result = IsTopCalculateHelper.IsOverTopQuantity(appNameCreate, inSideOrOutSideApps, true);

            if (!result.isCheckTop)
            {
                return(TResult <ResponseAppNameCreate> .Fail(new ResponseAppNameCreate { IsSuccessful = false, AppID = "" }, FaultInfoRcConstants.ERR_CODE_FAIL, result.errorMessage));
            }

            #endregion

            //DTO
            WisAppList wisApp = _mapper.Map <AppNameCreate, WisAppList>(appNameCreate);

            string   appID = Guid.NewGuid().ToString();
            DateTime date  = DateTime.Now;

            appNameCreate.AppID   = appID;
            wisApp.AppID          = appID;
            wisApp.LastUpdateUser = "******";
            wisApp.LastUpdateDT   = date;
            wisApp.CreateDT       = date;
            wisApp.Delflag        = false;
            //開放使用,無須授權	1:開放,0:有授權名單

            #region 授權群組 設定 AppOen  1:開放,0:有授權名單
            List <string> groupID = wisApp.AppUserGroup?.Split(',').ToList();

            List <WisDefineGroup> wisDefineGroups = _appListService.GetDefineGroup(groupID);

            foreach (var item in wisDefineGroups)
            {
                //新增群組
                if (!string.IsNullOrEmpty(item.GroupInclude))
                {
                    List <MdsHrEmpData> mdsHrEmpData = new List <MdsHrEmpData>();
                    List <string>       findGroup    = item.GroupInclude.Split(',').ToList();
                    if (item.SelectGroup == "1") // 找Site
                    {
                        mdsHrEmpData.AddRange(_appListService.GetHrEmpByLocation(findGroup));
                    }
                    else // 找 DeptID
                    {
                        mdsHrEmpData.AddRange(_appListService.GetHrEmpByDept(findGroup));
                    }

                    List <WisAppUserList> findAppUser = mdsHrEmpData.Select(p => new WisAppUserList {
                        AppID = appNameCreate.AppID, UserID = p.Uid
                    }).ToList();

                    wisAppUserList.AddRange(findAppUser);
                }

                //新增 自定義的user
                if (!string.IsNullOrEmpty(item.AccountInclude))
                {
                    List <MdsAdUserData> mdsAdUserDatas = new List <MdsAdUserData>();
                    List <MdsHrEmpData>  mdsHrEmpData   = new List <MdsHrEmpData>();
                    List <string>        findUId        = item.AccountInclude.Split(',').ToList();
                    if (item.SelectAccount == "1") // 找 AD Data
                    {
                        mdsAdUserDatas = _appListService.GetMdsAdUser(findUId);
                    }
                    else // 找 HR Data
                    {
                        mdsHrEmpData = _appListService.GetHrEmpByUId(findUId);
                    }

                    List <WisAppUserList> findAppUser = mdsAdUserDatas.Select(p => new WisAppUserList {
                        AppID = appNameCreate.AppID, UserID = p.Uid
                    }).ToList();
                    List <WisAppUserList> findAppUserByHr = mdsHrEmpData.Select(p => new WisAppUserList {
                        AppID = appNameCreate.AppID, UserID = p.Uid
                    }).ToList();

                    wisAppUserList.AddRange(findAppUser);
                    wisAppUserList.AddRange(findAppUserByHr);
                }
            }

            #endregion

            bool inserted = _appListService.InsertAppName(wisApp, wisAppUserList);

            if (inserted)
            {
                return(TResult <ResponseAppNameCreate> .OK(new ResponseAppNameCreate { IsSuccessful = true, AppID = appID }, appNameCreate.AppName));
            }
            else
            {
                return(TResult <ResponseAppNameCreate> .Fail(new ResponseAppNameCreate { IsSuccessful = false, AppID = "" }, FaultInfoRcConstants.ERR_CODE_FAIL, "Insert App name fail!"));
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 更新 Wis App name
        /// </summary>
        /// <param name="appNameCreate"></param>
        /// <returns></returns>
        public TResult <bool> ModifyAppName(AppNameCreate appNameCreate)
        {
            List <WisAppUserList> wisAppUserList = new List <WisAppUserList>();

            //撈出置頂總合資料
            List <InSideOrOutSideApp> inSideOrOutSideApps = _appListService.GetIsTopAppList();

            #region Check 置頂

            //如果要頂置 需檢查頂置規則 企業APP 2筆 外部 App 2筆
            var result = IsTopCalculateHelper.IsOverTopQuantity(appNameCreate, inSideOrOutSideApps, false);

            if (!result.isCheckTop)
            {
                return(TResult <bool> .Fail(false, FaultInfoRcConstants.ERR_CODE_FAIL, result.errorMessage));
            }

            #endregion

            //DTO
            WisAppList wisApp = _mapper.Map <AppNameCreate, WisAppList>(appNameCreate);
            DateTime   date   = DateTime.Now;
            wisApp.LastUpdateUser = "******";
            wisApp.LastUpdateDT   = date;

            #region 授權群組 設定 AppOen  1:開放,0:有授權名單

            if (!string.IsNullOrEmpty(wisApp.AppUserGroup) && wisApp.AppOpen == false)
            {
                List <string> groupID = wisApp.AppUserGroup?.Split(',').ToList();

                List <WisDefineGroup> wisDefineGroups = _appListService.GetDefineGroup(groupID);

                foreach (var item in wisDefineGroups)
                {
                    //新增群組
                    if (!string.IsNullOrEmpty(item.GroupInclude))
                    {
                        List <MdsHrEmpData> mdsHrEmpData = new List <MdsHrEmpData>();
                        List <string>       findGroup    = item.GroupInclude.Split(',').ToList();
                        if (item.SelectGroup == "1") // 找Site
                        {
                            mdsHrEmpData.AddRange(_appListService.GetHrEmpByLocation(findGroup));
                        }
                        else // 找 DeptID
                        {
                            mdsHrEmpData.AddRange(_appListService.GetHrEmpByDept(findGroup));
                        }

                        List <WisAppUserList> findAppUser = mdsHrEmpData.Select(p => new WisAppUserList {
                            AppID = appNameCreate.AppID, UserID = p.Uid
                        }).ToList();

                        wisAppUserList.AddRange(findAppUser);
                    }

                    //新增 自定義的user
                    if (!string.IsNullOrEmpty(item.AccountInclude))
                    {
                        List <MdsAdUserData> mdsAdUserDatas = new List <MdsAdUserData>();
                        List <MdsHrEmpData>  mdsHrEmpData   = new List <MdsHrEmpData>();
                        List <string>        findUId        = item.AccountInclude.Split(',').ToList();
                        if (item.SelectAccount == "1") // 找 AD Data
                        {
                            mdsAdUserDatas = _appListService.GetMdsAdUser(findUId);
                        }
                        else // 找 HR Data
                        {
                            mdsHrEmpData = _appListService.GetHrEmpByUId(findUId);
                        }

                        List <WisAppUserList> findAppUser = mdsAdUserDatas.Select(p => new WisAppUserList {
                            AppID = appNameCreate.AppID, UserID = p.Uid
                        }).ToList();
                        List <WisAppUserList> findAppUserByHr = mdsHrEmpData.Select(p => new WisAppUserList {
                            AppID = appNameCreate.AppID, UserID = p.Uid
                        }).ToList();

                        wisAppUserList.AddRange(findAppUser);
                        wisAppUserList.AddRange(findAppUserByHr);
                    }
                }
            }

            #endregion

            bool isModified = _appListService.ModifyAppName(wisApp, wisAppUserList);

            if (isModified)
            {
                return(TResult <bool> .OK(true, appNameCreate.AppName));
            }
            else
            {
                return(TResult <bool> .Fail(false, FaultInfoRcConstants.ERR_CODE_FAIL, "Modify App name fail!"));
            }
        }
Ejemplo n.º 9
0
        public TResult <LoginViewModel> Login(string userId, string password)
        {
            bool isPass = false;
            HrIdentityResponse hrResponse = null;

            try
            {
                #region  Use AD service to auth & HR API Identity

                //AD 驗證先 結果為fasle 再call HR API
                if (_authService.ValidateByAd(userId, password))
                {
                    isPass = true;
                }
                else
                {
                    hrResponse = _authService.IdentityByHr(userId, password);
                    isPass     = hrResponse.Status;
                }

                //AD 認證 和 HR API 其中一個沒過 回傳失敗
                if (!isPass)
                {
                    return(TResult <LoginViewModel> .Fail(new LoginViewModel
                    {
                        IsLogin = isPass,
                        IsAdmin = false,
                        IsMember = false,
                    }, FaultInfoRcConstants.LOGIN_FAIL, "Account/Password error."));
                }

                #endregion

                List <string> uID = new List <string> {
                    userId.ToLower().Trim()
                };

                List <MdsAdUserData> mdsAdUserData = _authService.GetMdsAdUser(uID);

                //檢查是否為 Admin 權限
                List <WisGroupUser> wisGroupUser = _authService.CheckIsAdminOrMember(userId);

                //DB 目前狀況可能會有查到同一個工號 會有雙重身份 admin 和 apadmin
                //雙重身分 只要有找到 Admin 就是管理者
                if (wisGroupUser.Any(p => p.GroupID == "admin"))
                {
                    //為Admin 管理者可使用後台 APP List
                    return(TResult <LoginViewModel> .OK(new LoginViewModel
                    {
                        UID = mdsAdUserData.Count > 0 ? mdsAdUserData.FirstOrDefault().Uid : "",
                        //沒AD 名子資訊就取 HR 名子資訊  格式: Ting Chen/WHQ/Wistron
                        Name = mdsAdUserData.Count > 0 ? mdsAdUserData.FirstOrDefault().Name : hrResponse != null ? $"{hrResponse.Name_Ac.Trim()}{"/"}{hrResponse.Z_Site_ID}{"/Wistron"}" : "",
                        IsLogin = isPass,
                        IsAdmin = true,
                        IsMember = false,
                    }, "is login successful!"));
                }
                else
                {
                    //為一般 使用者只能使用 下載app 版本裝到手機上
                    return(TResult <LoginViewModel> .OK(new LoginViewModel
                    {
                        UID = mdsAdUserData.Count > 0 ? mdsAdUserData.FirstOrDefault().Uid : "",
                        //沒AD 名子資訊就取 HR 名子資訊  格式: Ting Chen/WHQ/Wistron
                        Name = mdsAdUserData.Count > 0 ? mdsAdUserData.FirstOrDefault().Name : hrResponse != null ? $"{hrResponse.Name_Ac.Trim()}{"/"}{hrResponse.Z_Site_ID}{"/Wistron"}" : "",
                        IsLogin = isPass,
                        IsAdmin = false,
                        IsMember = true,
                    }, "is login successful!"));
                }
            }
            catch (Exception ex)
            {
                //考慮到PassWord和OA密碼一致,不記錄PassWord
                LogHelper.WriteException(ex, MethodBase.GetCurrentMethod(), userId);
                return(TResult <LoginViewModel> .Fail(new LoginViewModel
                {
                    IsLogin = false,
                    IsAdmin = false,
                    IsMember = false,
                }, FaultInfoRcConstants.LOGIN_FAIL, "System error."));
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 因實體檔案 目前已 dev server C:/AppOs 路徑下為主 所以再本機 測試 會有無法刪除檔案情形
        /// </summary>
        /// <param name="appListItem"></param>
        /// <returns></returns>
        public TResult <bool> DeleteFile(AppListItem appListItem)
        {
            bool deleted = false;

            if (string.IsNullOrEmpty(appListItem.AppOSID))
            {
                return(TResult <bool> .Fail(false, FaultInfoRcConstants.ERR_CODE_FAIL, "無法刪除實體檔案 因為 AppOsId 為空值"));
            }

            if (string.IsNullOrEmpty(appListItem.FilePath))
            {
                return(TResult <bool> .Fail(false, FaultInfoRcConstants.ERR_CODE_FAIL, "無實體安裝檔案"));
            }

            //IOS 刪除檔案
            if (appListItem.OSType == "IOS")
            {
                //Plist 檔案
                string filePath = $"{_configContext.UploadPath}/{appListItem.FilePath}";
                //ipa 檔案
                string fileName = $"{_configContext.UploadPath}/{appListItem.FileName}";

                if (!File.Exists(filePath))
                {
                    return(TResult <bool> .Fail(false, FaultInfoRcConstants.ERR_CODE_FAIL, " 無實體安裝Plist路徑檔案"));
                }

                if (!File.Exists(fileName))
                {
                    return(TResult <bool> .Fail(false, FaultInfoRcConstants.ERR_CODE_FAIL, " 無實體安裝ipa路徑檔案"));
                }

                //刪除實體檔案
                File.Delete(filePath);
                File.Delete(fileName);
            }

            //Android 刪除檔案
            if (appListItem.OSType == "Android")
            {
                //apk 檔案 Android filePath  為 .apk 檔案路徑 fileName 為原.apk 黨案名稱
                string filePath = $"{_configContext.UploadPath}/{appListItem.FilePath}";

                if (!File.Exists(filePath))
                {
                    return(TResult <bool> .Fail(false, FaultInfoRcConstants.ERR_CODE_FAIL, " 無實體安裝apk路徑檔案"));
                }

                //刪除實體檔案
                File.Delete(filePath);
            }

            //DB 更新
            deleted = _appListService.DeleteAppFilePath(appListItem.AppOSID);

            if (deleted)
            {
                return(TResult <bool> .OK(true, "OK"));
            }
            else
            {
                return(TResult <bool> .Fail(false, FaultInfoRcConstants.ERR_CODE_FAIL, "再刪除資料庫 欄位 FilePath出現錯誤"));
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 上傳 Ios Android 安裝檔案
        /// </summary>
        /// <param name="appOsInfo"></param>
        /// <param name="uploadFile"></param>
        /// <returns></returns>
        public async Task <TResult <AppOsInfo> > UploadInstallFile(AppOsInfo appOsInfo, IMatFileUploadEntry uploadFile)
        {
            //存放多載點 plist 檔案名稱
            List <DownloadUrlList> downloadUrlList = new List <DownloadUrlList>();

            #region 驗證檔案格式

            int findExtension = uploadFile.Name.LastIndexOf(".");

            if (string.IsNullOrEmpty(appOsInfo.Version))
            {
                return(TResult <AppOsInfo> .Fail(null, FaultInfoRcConstants.ERR_CODE_VERSIONREQUIRED, "必須輸入 版本號碼"));
            }

            if (appOsInfo.Photo.Where(p => p.FileNumber == 5).FirstOrDefault() == null)
            {
                return(TResult <AppOsInfo> .Fail(null, FaultInfoRcConstants.ERR_CODE_OSFORMATTYPE, "必須上傳 Icon 圖片"));
            }

            if (findExtension == -1)
            {
                return(TResult <AppOsInfo> .Fail(null, FaultInfoRcConstants.ERR_CODE_OSFORMATTYPE, "檔案格式錯誤: 無附檔名"));
            }

            string extension = uploadFile.Name.Substring(uploadFile.Name.LastIndexOf(".")).ToLower();

            //驗證 Ios 是否符合格式 目前只看.ipa 檔案
            if (appOsInfo.OSType == OsType.Ios && !extension.Equals(".ipa"))
            {
                return(TResult <AppOsInfo> .Fail(null, FaultInfoRcConstants.ERR_CODE_OSFORMATTYPE, "檔案格式限制:  IOS 安裝檔應為 .ipa 格式"));
            }

            //驗證 Android 是否符合格式 目前只看.apk 檔案
            if (appOsInfo.OSType == OsType.Android && !extension.Equals(".apk"))
            {
                return(TResult <AppOsInfo> .Fail(null, FaultInfoRcConstants.ERR_CODE_OSFORMATTYPE, "檔案格式限制:  Android 安裝檔應為 .apk 格式"));
            }

            #endregion

            string fileName = $"{appOsInfo.Version}-{Guid.NewGuid().ToString("N")}{extension}"; //Create a new Name
            string osPath   = OsType.Ios == appOsInfo.OSType ? "IOS" : "Android";
            string filePath = Path.Combine(_configContext.UploadPath, appOsInfo.AppNameEn.Replace(" ", ""), osPath, "Install");

            //檔案資料夾路徑不存在就新增
            if (!Directory.Exists(filePath))
            {
                Directory.CreateDirectory(filePath);
            }

            using (var fs = new FileStream(Path.Combine(filePath, fileName), FileMode.Create, FileAccess.Write))
            {
                await uploadFile.WriteToStreamAsync(fs);
            }

            #region 如果是 IOS 必須做出 Plist 檔案 和多載點 plist

            //如果是IOS 除了上傳.ipa 檔案 還要上傳 Plist xml file
            if (appOsInfo.OSType == OsType.Ios)
            {
                //圖片 url 路徑
                AppPhotoContent iosIconPhoto = appOsInfo.Photo.Where(P => P.FileNumber == 5).FirstOrDefault();

                //多載點 plist
                foreach (OtherSideEndPoint endPoint in _configContext.OtherSideEndPoint)
                {
                    // 組plist 黨案名稱
                    string pListFileName = $"{Guid.NewGuid().ToString("N")}{".plist"}";

                    // 組 ipa url 路徑
                    string ipaPath = $"{endPoint.Url}/{appOsInfo.AppNameEn.Replace(" ", "")}/{osPath}/{"Install"}/{fileName}";

                    // 組圖片 url 路徑
                    string iconPath = iosIconPhoto != null ? $"{endPoint.Url}/{iosIconPhoto.FilePath.Replace(" ", "")}" : "";

                    //做出 plist xml 內容物
                    string plistXml = UploadFileHepler.GetPlistXml(ipaPath, iconPath, appOsInfo.PackageName, appOsInfo.Version, appOsInfo.AppNameEn);

                    //存入 Plist 實體路徑
                    File.WriteAllText(Path.Combine(filePath, pListFileName), plistXml);

                    //原始路徑 存在Wis_AppOS table
                    if (endPoint.Site == "WHQ")
                    { //原始載點不加入 DownloadUrlList
                      //為 plist 檔案路徑
                        appOsInfo.FilePath = $"{appOsInfo.AppNameEn.Replace(" ", "")}/{osPath}/{"Install"}/{pListFileName}";

                        //為 .ipa 檔案路徑
                        appOsInfo.FileName = $"{appOsInfo.AppNameEn.Replace(" ", "")}/{osPath}/{"Install"}/{fileName}";
                    }
                    else
                    {//多載點資訊 存在 Wis_AppOs_Other
                        downloadUrlList.Add(new DownloadUrlList
                        {
                            Site = endPoint.Site,
                            Url  = $"{appOsInfo.AppNameEn.Replace(" ", "")}/{osPath}/{"Install"}/{pListFileName}"//plist 路徑
                        });
                    }
                }

                //前端必須按下儲存按鈕  url資訊才會寫入 DB
                //Ios 上傳檔案路徑 是 plist檔案路徑
                appOsInfo.DownloadUrlList = downloadUrlList;
            }

            #endregion

            #region Android 處理檔案 路徑

            //Android 直接存放 apk 檔案路徑
            if (appOsInfo.OSType == OsType.Android)
            {
                foreach (OtherSideEndPoint endPoint in _configContext.OtherSideEndPoint)
                {
                    //Wis_AppOS url 路徑處理
                    if (endPoint.Site == "WHQ")
                    {
                        //為 .apk 檔案路徑
                        appOsInfo.FilePath = $"{appOsInfo.AppNameEn.Replace(" ", "")}/{osPath}/{"Install"}/{fileName}";

                        //為 .apk 原檔案名稱
                        appOsInfo.FileName = uploadFile.Name;
                    }
                    else
                    {//Wis_AppOs_Other 資訊
                        downloadUrlList.Add(new DownloadUrlList
                        {
                            Site = endPoint.Site,
                            Url  = $"{appOsInfo.AppNameEn.Replace(" ", "")}/{osPath}/{"Install"}/{fileName}"//.apk 檔案路徑
                        });
                    }
                }
                //Android 上傳檔案路徑 是apk檔案路徑 與原本路徑一模一樣
                appOsInfo.DownloadUrlList = downloadUrlList;
            }
            #endregion

            return(TResult <AppOsInfo> .OK(appOsInfo, "OK"));
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 上傳圖片檔案 對象物件 AppOsInfo 裡的 AppPhotoContent
        /// </summary>
        /// <param name="fileNumber">記錄圖檔上傳位置 5 為安裝檔案Icon圖片</param>
        /// <param name="osType">IOS = 1 Android=2</param>
        /// <param name="appIos"></param>
        /// <param name="uploadFile"></param>
        /// <returns>實體路徑圖片</returns>
        public async Task <TResult <AppOsInfo> > UploadImageFile(int fileNumber, AppOsInfo appOsInfo, IMatFileUploadEntry uploadFile)
        {
            #region 驗證圖片檔案格式

            //驗證圖片是否符合格式  目前只接受 PNG JPEG
            ImageFormat imageType = await _uploadFileService.CheckImageType(uploadFile);

            if (imageType == null)
            {
                return(TResult <AppOsInfo> .Fail(null, FaultInfoRcConstants.ERR_CODE_IMAGEFORMATTYPE, "檔案格式限制: jpg、jpeg、png"));
            }

            int findExtension = uploadFile.Name.LastIndexOf(".");

            if (findExtension == -1)
            {
                return(TResult <AppOsInfo> .Fail(null, FaultInfoRcConstants.ERR_CODE_OSFORMATTYPE, "檔案格式錯誤: 無附檔名"));
            }

            #endregion

            string extension = uploadFile.Name.Substring(uploadFile.Name.LastIndexOf(".")).ToLower();
            string fileName  = $"{Guid.NewGuid().ToString("N")}{extension}"; //Create a new Name
            string osPath    = OsType.Ios == appOsInfo.OSType ? "IOS" : "Android";
            string filePath  = Path.Combine(_configContext.UploadPath, appOsInfo.AppNameEn.Replace(" ", ""), osPath, "Images");

            //檔案資料夾路徑不存在就新增
            if (!Directory.Exists(filePath))
            {
                Directory.CreateDirectory(filePath);
            }

            using (var fs = new FileStream(Path.Combine(filePath, fileName), FileMode.Create, FileAccess.Write))
            {
                await uploadFile.WriteToStreamAsync(fs);
            }

            AppPhotoContent appPhotoContent = new AppPhotoContent
            {
                AppID      = appOsInfo.AppID,
                AppOS      = appOsInfo.OSType,
                FileNumber = fileNumber,
                FileName   = fileName,
                //exapmle Wistron%20Ark\IOS\Images\5-623cefb49e3946a28198464dd72b5bb4.png 子目錄位址
                FilePath  = $"{appOsInfo.AppNameEn.Replace(" ", "")}/{osPath}/{"Images"}/{fileName}",
                PhotoType = fileNumber == 5 ? PhotoType.IconType : PhotoType.NormalType
            };

            //把有存在編號的 去除 在Add更新過後的 但還未更新資料庫 等待 按下儲存按鈕
            AppPhotoContent existed = appOsInfo.Photo.Where(p => p.FileNumber == fileNumber).FirstOrDefault();
            if (existed != null)
            {
                appOsInfo.Photo.Remove(existed);
                appOsInfo.Photo.Add(appPhotoContent);
            }
            else
            {
                appOsInfo.Photo.Add(appPhotoContent);
            }

            return(TResult <AppOsInfo> .OK(appOsInfo, "OK"));
        }
Ejemplo n.º 13
0
        /// <summary>
        /// 更新 Wis APP os
        /// </summary>
        /// <param name="appOsInfo"></param>
        /// <returns></returns>
        public TResult <bool> InsertOrModifyAppOs(AppOsInfo appOsInfo)
        {
            //短解 應該前端要給預設值 DownloadUrlList.Count = 0 這樣的設定 要不然會throw exception
            if (appOsInfo.DownloadUrlList == null)
            {
                appOsInfo.DownloadUrlList = new List <DownloadUrlList>();
            }

            //CompanyApp  = false 欄位版本資訊為空值 補上預設值 原因是外部App 不需要輸入版本號 但是db 欄位為必填
            if (string.IsNullOrEmpty(appOsInfo.Version))
            {
                appOsInfo.Version = "";
            }

            DateTime date = DateTime.Now;

            WisAppOs           wisAppOs    = _mapper.Map <AppOsInfo, WisAppOs>(appOsInfo);
            List <WisAppPhoto> wisAppPhoto = _mapper.Map <List <AppPhotoContent>, List <WisAppPhoto> >(appOsInfo.Photo);

            //視為存在條件  AppID & OsType & Version
            WisAppOs wisAppOsFromDb = _appListService.AppOsIsExisted(appOsInfo.AppID, appOsInfo.OSType, appOsInfo.Version);

            //沒有代表是新增
            if (wisAppOsFromDb == null)
            {
                List <WisAppOsOther> insertWisAppOsOthers = new List <WisAppOsOther>();
                wisAppOs.DelFlag        = false;
                wisAppOs.LastUpdateUser = "******";
                wisAppOs.CreateDT       = date;
                wisAppOs.LastUpdateDT   = date;

                //多載點功能啟用 才新增
                if (appOsInfo.MultipleDownload)
                {
                    //多載點處理
                    foreach (DownloadUrlList downloadUrl in appOsInfo.DownloadUrlList)
                    {
                        insertWisAppOsOthers.Add(new WisAppOsOther
                        {
                            AppID          = wisAppOs.AppID,
                            AppOsID        = 0,//等transaction當中insert
                            Site           = downloadUrl.Site,
                            OSType         = wisAppOs.OSType,
                            Version        = wisAppOs.Version,
                            FileName       = appOsInfo.FileName, //IOS 為 ipa路徑 Android 為原始 apk檔案名稱
                            FilePath       = downloadUrl.Url,    //IOS 為plist路徑  Android 為apk路徑
                            LastUpdateUser = "******",
                            LastUpdateDT   = date,
                            CreateDT       = date
                        });
                    }
                }

                bool isInserted = _appListService.DisableAppOsStatusAndInsertAppOsAndPhotoAndOsOther(wisAppOs, wisAppPhoto, insertWisAppOsOthers);

                if (isInserted)
                {
                    //取新增後的 appOsID
                    WisAppOs insertObject = _appListService.GetAppOs(appOsInfo.AppID).FirstOrDefault(p => p.OSType == appOsInfo.OSType && p.Status == AppStatus.EnableBool);
                    return(TResult <bool> .OK(true, insertObject.AppOSID.ToString()));
                }
                else
                {
                    return(TResult <bool> .Fail(false, FaultInfoRcConstants.ERR_CODE_FAIL, "Insert App Os fail!"));
                }
            }
            else
            { //有在DB 找到 代表更新
                List <WisAppOsOther> insertWisAppOsOthers = new List <WisAppOsOther>();
                wisAppOs.DelFlag        = wisAppOsFromDb.DelFlag;
                wisAppOs.LastUpdateUser = wisAppOsFromDb.LastUpdateUser;
                wisAppOs.CreateDT       = wisAppOsFromDb.CreateDT;
                wisAppOs.LastUpdateDT   = date;

                //多載點功能啟用 才更新
                if (appOsInfo.MultipleDownload)
                {
                    //多載點 處理
                    foreach (DownloadUrlList downloadUrl in appOsInfo.DownloadUrlList)
                    {
                        insertWisAppOsOthers.Add(new WisAppOsOther
                        {
                            AppID          = wisAppOs.AppID,
                            AppOsID        = wisAppOs.AppOSID,//必定會有 AppOsID
                            Site           = downloadUrl.Site,
                            OSType         = wisAppOs.OSType,
                            Version        = wisAppOs.Version,
                            FileName       = appOsInfo.FileName, //IOS 為 ipa路徑 Android 為原始 apk檔案名稱
                            FilePath       = downloadUrl.Url,    //IOS 為plist路徑  Android 為apk路徑
                            LastUpdateUser = "******",
                            LastUpdateDT   = date,
                            CreateDT       = date
                        });
                    }
                }

                bool isUpdated = _appListService.DisableAppOsStatusAndModifyAppOsAndPhotoAndOsOther(wisAppOs, wisAppPhoto, insertWisAppOsOthers);

                if (isUpdated)//返回 更新
                {
                    return(TResult <bool> .OK(true, appOsInfo.AppOSID.ToString()));
                }
                else
                {
                    return(TResult <bool> .Fail(false, FaultInfoRcConstants.ERR_CODE_FAIL, "Update App Os fail!"));
                }
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// 更新 Wis App name
        /// </summary>
        /// <param name="appNameCreate"></param>
        /// <returns></returns>
        public TResult <bool> ModifyAppName(AppNameCreate appNameCreate)
        {
            List <WisAppUserList> wisAppUserList = new List <WisAppUserList>();

            //撈出置頂總合資料
            List <InSideOrOutSideApp> inSideOrOutSideApps = _appListService.GetIsTopAppList();

            #region Check 置頂

            //如果要頂置 需檢查頂置規則 企業APP 2筆 外部 App 2筆
            if (appNameCreate.IsTop)
            {
                //企業專用	true:企業APP , false:外部APP
                if (appNameCreate.CompanyApp)
                {
                    //內部 app得要排除 自己的部分
                    int inSideTop = inSideOrOutSideApps.Where(p => p.CompanyApp.Equals("Inside App") && p.AppID != appNameCreate.AppID).Count();

                    if (inSideTop >= 2)
                    {
                        return(TResult <bool> .Fail(false, FaultInfoRcConstants.ERR_CODE_FAIL, "企業內部 App 置頂最多為2筆"));
                    }
                }
                else
                {
                    //外部 app 得要排除 自己的部分
                    int outSideTop = inSideOrOutSideApps.Where(p => p.CompanyApp.Equals("Outside App") && p.AppID != appNameCreate.AppID).Count();

                    if (outSideTop >= 2)
                    {
                        return(TResult <bool> .Fail(false, FaultInfoRcConstants.ERR_CODE_FAIL, "外部 App 置頂最多為2筆"));
                    }
                }
            }

            #endregion

            //DTO
            WisAppList wisApp = _mapper.Map <AppNameCreate, WisAppList>(appNameCreate);
            DateTime   date   = DateTime.Now;
            wisApp.LastUpdateUser = "******";
            wisApp.LastUpdateDT   = date;

            #region 授權群組 設定 AppOen  1:開放,0:有授權名單

            List <string> groupID = wisApp.AppUserGroup?.Split(',').ToList();

            List <WisDefineGroup> wisDefineGroups = _appListService.GetDefineGroup(groupID);

            foreach (var item in wisDefineGroups)
            {
                //新增群組
                if (!string.IsNullOrEmpty(item.GroupInclude))
                {
                    List <MdsHrEmpData> mdsHrEmpData = new List <MdsHrEmpData>();
                    List <string>       findGroup    = item.GroupInclude.Split(',').ToList();
                    if (item.SelectGroup == "1") // 找Site
                    {
                        mdsHrEmpData = _appListService.GetHrEmpByLocation(findGroup);
                    }
                    else // 找 DeptID
                    {
                        mdsHrEmpData = _appListService.GetHrEmpByDept(findGroup);
                    }

                    List <WisAppUserList> findAppUser = mdsHrEmpData.Select(p => new WisAppUserList {
                        AppID = appNameCreate.AppID, UserID = p.Uid
                    }).ToList();

                    wisAppUserList.AddRange(findAppUser);
                }

                //新增 自定義的user
                if (!string.IsNullOrEmpty(item.AccountInclude))
                {
                    List <MdsAdUserData> mdsAdUserDatas = new List <MdsAdUserData>();
                    List <MdsHrEmpData>  mdsHrEmpData   = new List <MdsHrEmpData>();
                    List <string>        findUId        = item.AccountInclude.Split(',').ToList();
                    if (item.SelectAccount == "1") // 找 AD Data
                    {
                        mdsAdUserDatas = _appListService.GetMdsAdUser(findUId);
                    }
                    else // 找 HR Data
                    {
                        mdsHrEmpData = _appListService.GetHrEmpByUId(findUId);
                    }

                    List <WisAppUserList> findAppUser = mdsAdUserDatas.Select(p => new WisAppUserList {
                        AppID = appNameCreate.AppID, UserID = p.Uid
                    }).ToList();
                    List <WisAppUserList> findAppUserByHr = mdsHrEmpData.Select(p => new WisAppUserList {
                        AppID = appNameCreate.AppID, UserID = p.Uid
                    }).ToList();

                    wisAppUserList.AddRange(findAppUser);
                    wisAppUserList.AddRange(findAppUserByHr);
                }
            }

            #endregion

            bool isModified = _appListService.ModifyAppName(wisApp, wisAppUserList);

            if (isModified)
            {
                return(TResult <bool> .OK(true, appNameCreate.AppName));
            }
            else
            {
                return(TResult <bool> .Fail(false, FaultInfoRcConstants.ERR_CODE_FAIL, "Modify App name fail!"));
            }
        }