Example #1
0
        public void TestJsonResult()
        {
            List <WebReturnESightResult> list = new List <WebReturnESightResult>();
            WebReturnESightResult        webReturnESightResult1 = new WebReturnESightResult();

            webReturnESightResult1.ESightIp    = "127.0.0.1";
            webReturnESightResult1.Code        = 0;
            webReturnESightResult1.Description = "成功";
            list.Add(webReturnESightResult1);
            WebReturnESightResult webReturnESightResult2 = new WebReturnESightResult();

            webReturnESightResult2.ESightIp    = "127.0.0.3";
            webReturnESightResult2.Code        = 51001;
            webReturnESightResult2.Description = "模板名称重复,模板已存在";
            list.Add(webReturnESightResult2);
            WebReturnResult <List <WebReturnESightResult> > taskResult = new WebReturnResult <List <WebReturnESightResult> >();

            taskResult.Data        = list;
            taskResult.Code        = 51001;
            taskResult.Description = "模板名称重复,模板已存在";
            LogUtil.HWLogger.API.Info("TestJsonResult Result:" + JsonUtil.SerializeObject(taskResult));
        }
        /// <summary>
        /// 添加升级包
        /// </summary>
        private ApiListResult <WebReturnESightResult> Save(object eventData)
        {
            var ret = new ApiListResult <WebReturnESightResult>(ConstMgr.ErrorCode.SYS_UNKNOWN_ERR, "");

            try
            {
                //1. 获取UI传来的参数
                var jsData    = JsonUtil.SerializeObject(eventData);
                var newJsData = CommonBLLMethodHelper.HidePassword(jsData);
                LogUtil.HWLogger.UI.InfoFormat("Saving basepackage..., the param is [{0}]", newJsData);
                WebMutilESightsParam <BasePackage> webMutilESightsParam = JsonUtil.DeserializeObject <WebMutilESightsParam <BasePackage> >(jsData);
                //2. 根据HostIP获取IESSession
                IList <WebReturnESightResult> webReturnESightResultList = new List <WebReturnESightResult>();
                int    eSightCount = webMutilESightsParam.ESights.Count;
                int    errorCount  = 0;
                string errorCode   = "";
                foreach (string hostIP in webMutilESightsParam.ESights)
                {
                    IESSession esSession = null;
                    //3. 保存
                    WebReturnESightResult webReturnESightResult = new WebReturnESightResult();
                    try
                    {
                        esSession = ESSessionHelper.GetESSession(hostIP);
                        esSession.BasePackageWorker.UploadBasePackage(webMutilESightsParam.Data);

                        webReturnESightResult.ESightIp    = hostIP;
                        webReturnESightResult.Code        = 0;
                        webReturnESightResult.Description = "successful";
                        LogUtil.HWLogger.UI.InfoFormat("Saving basepackage successful on eSight [{0}]", webReturnESightResult.ESightIp);
                    }
                    catch (BaseException ex)
                    {
                        webReturnESightResult.ESightIp    = hostIP;
                        webReturnESightResult.Code        = CommonUtil.CoreUtil.GetObjTranNull <int>(ex.Code);
                        webReturnESightResult.ErrorModel  = ex.ErrorModel;
                        webReturnESightResult.Description = ex.Message;
                        errorCount++;
                        SetErrorCode(errorCount, ex.Code, ex.ErrorModel, ref errorCode);
                        LogUtil.HWLogger.UI.Error(string.Format("Saving basepackage failed on eSight [{0}]: ", webReturnESightResult.ESightIp), ex);
                    }
                    catch (Exception ex)
                    {
                        webReturnESightResult.ESightIp    = hostIP;
                        webReturnESightResult.Code        = CommonUtil.CoreUtil.GetObjTranNull <int>(ConstMgr.ErrorCode.SYS_UNKNOWN_ERR);
                        webReturnESightResult.Description = ex.InnerException.Message ?? ex.Message;
                        errorCount++;
                        SetErrorCode(errorCount, ConstMgr.ErrorCode.SYS_UNKNOWN_ERR, "", ref errorCode);
                        LogUtil.HWLogger.UI.Error(string.Format("Saving basepackage failed on eSight [{0}]: ", webReturnESightResult.ESightIp), ex);
                    }
                    webReturnESightResultList.Add(webReturnESightResult);
                }
                SetSaveResultWhenComplete(errorCount, eSightCount, errorCode, ref ret);
                ret.Data = webReturnESightResultList;
                LogUtil.HWLogger.UI.InfoFormat("Saving basepackage completed! the ret is [{0}]", JsonUtil.SerializeObject(ret));
            }
            catch (BaseException ex)
            {
                LogUtil.HWLogger.UI.Error("Saving basepackage failed: ", ex);
                ret.Code         = string.Format("{0}{1}", ex.ErrorModel, ex.Code);
                ret.Success      = false;
                ret.ExceptionMsg = ex.Message;
                ret.Data         = null;
            }
            catch (Exception ex)
            {
                LogUtil.HWLogger.UI.Error("Saving basepackage failed: ", ex);
                ret.Code         = ConstMgr.ErrorCode.SYS_UNKNOWN_ERR;
                ret.Success      = false;
                ret.ExceptionMsg = ex.InnerException.Message ?? ex.Message;
                ret.Data         = null;
            }
            return(ret);
        }