public ReturnValue Run() { ReturnValue _result = new ReturnValue(); #region get ship method list TShipMethod _tShipMethod = new TShipMethod(); _result = _tShipMethod.getShipMethodList(); if (_result.Success == false) { _result.Success = false; _result.ErrMessage = "getShipMethodList failed. \r\n " + _result.ErrMessage; Common.Log("getShipMethodList---ER \r\n" + _result.ErrMessage); return(_result); } ShipMethods = _result.ObjectList.ConvertAll(t => t as TShipMethod); #endregion #region get product list TProgram_Product _tProgram_Product = new TProgram_Product(); _result = _tProgram_Product.getProgramProductList(); if (_result.Success == false) { _result.Success = false; _result.ErrMessage = "getProgramProductList failed. \r\n " + _result.ErrMessage; Common.Log("getProgramProductList---ER \r\n" + _result.ErrMessage); return(_result); } Products = _result.ObjectList.ConvertAll(t => t as TProgram_Product); #endregion #region get country list TCountry _tCountry = new TCountry(); _result = _tCountry.getCountryList(); if (_result.Success == false) { _result.Success = false; _result.ErrMessage = "getCountryList failed. \r\n " + _result.ErrMessage; Common.Log("getCountryList---ER \r\n" + _result.ErrMessage); return(_result); } Countrys = _result.ObjectList.ConvertAll(t => t as TCountry); #endregion #region get state list TState _tState = new TState(); _result = _tState.getStateList(); if (_result.Success == false) { _result.Success = false; _result.ErrMessage = "getStateList failed. \r\n " + _result.ErrMessage; Common.Log("getStateList---ER \r\n" + _result.ErrMessage); return(_result); } States = _result.ObjectList.ConvertAll(t => t as TState); #endregion #region get type list TType _tType = new TType(); _result = _tType.geTTypeList(); if (_result.Success == false) { _result.Success = false; _result.ErrMessage = "geTTypeList failed. \r\n " + _result.ErrMessage; Common.Log("geTTypeList---ER \r\n" + _result.ErrMessage); return(_result); } Types = _result.ObjectList.ConvertAll(t => t as TType); #endregion #region PULLOrders _result = SS2.ShipStationAPI.PULLOrders(); if (_result.Success == false) { _result.Success = false; _result.ErrMessage = "PULLOrders failed. \r\n " + _result.ErrMessage; Common.Log("PULLOrders---ER \r\n" + _result.ErrMessage); Common.SentAlterEmail(1, _result.ErrMessage); return(_result); } List <ShipStationResponseOrder> orderList = _result.ObjectValue as List <ShipStationResponseOrder>; #endregion foreach (ShipStationResponseOrder order in orderList) { #region check program ID if (string.IsNullOrWhiteSpace(order.advancedOptions.customField1) == true) { continue; } var programId = order.advancedOptions.customField1; Common.Log("ProgramID:" + programId + " Order : " + order.orderId + "---Start"); List <string> Programs = ConfigurationSettings.AppSettings["ProgramList"].Split(',').ToList(); if (Programs.Exists(p => p.Equals(programId)) == false) { _result.ErrMessage = "Program ID:" + programId + " is valid"; errorNotes = errorNotes + order.orderId + "\r\n" + _result.ErrMessage + "\r\n"; failedRecord++; Common.Log("ProgramID:" + programId + " Order : " + order.orderId + "---ER \r\n" + _result.ErrMessage); continue; } #endregion #region check order existed TShipStationOrders shipStationOrders = new TShipStationOrders(); _result = shipStationOrders.getOrderBySOrderId(order.orderId); if (_result.Success == false) { errorNotes = errorNotes + order.orderId + "\r\n" + _result.ErrMessage + "\r\n"; failedRecord++; Common.Log("ProgramID:" + programId + " Order : " + order.orderId + "---ER \r\n" + _result.ErrMessage); continue; } shipStationOrders = _result.Object as TShipStationOrders; if (shipStationOrders.ID != 0) { continue; } #endregion #region create ZStore Order _result = createZOrder(order); if (_result.Success == false) { errorNotes = errorNotes + order.orderId + "\r\n" + _result.ErrMessage + "\r\n"; failedRecord++; Common.Log("ProgramID:" + programId + " Order : " + order.orderId + "---ER \r\n" + _result.ErrMessage); continue; } TOrder _tOrder = _result.Object as TOrder; #endregion #region save Order _result = saveZOrder(_tOrder, order); if (_result.Success == false) { errorNotes = errorNotes + order.orderId + "\r\n" + _result.ErrMessage + "\r\n"; failedRecord++; Common.Log("ProgramID:" + programId + " Order : " + order.orderId + "---ER \r\n" + _result.ErrMessage); continue; } #endregion Common.Log("ProgramID:" + programId + " Order : " + order.orderId + "---OK"); } Common.SentAlterEmail(failedRecord, errorNotes); _result.Success = true; return(_result); }