Exemple #1
0
        public virtual void CopyAppFilesToAppCenterServer(string filePath, int pe_id)
        {
            string packUploadFolder = ConfigurationManager.AppSettings["packUploadFolder"];


            if (Directory.Exists(packUploadFolder))
            {
                string[] sourceFiles = null;
                if (pe_id <= 0)
                {
                    sourceFiles = Directory.GetFiles(packUploadFolder);
                }
                else
                {
                    sourceFiles = new string[] { filePath };
                }

                foreach (string file in sourceFiles)
                {
                    string fileName = Path.GetFileName(file);

                    Service.ApplicationCenterWS.WebService ws = new Service.ApplicationCenterWS.WebService();

                    FileStream fs      = null;
                    byte[]     content = null;
                    try
                    {
                        fs      = new FileStream(file, FileMode.Open, FileAccess.Read);
                        content = new byte[fs.Length];
                        fs.Read(content, 0, (int)fs.Length - 1);
                        ws.AppFileSync(content, fileName);
                    }
                    catch (Exception ex)
                    {
                        Log4NetHelper.Error(ex);
                        continue;
                    }
                    finally
                    {
                        fs.Close();
                        fs.Dispose();
                    }
                }

                //更新server缓存
                try
                {
                    SmartBox.Console.Service.ServiceReference1.ManagerServiceClient cli = new Service.ServiceReference1.ManagerServiceClient();
                    cli.ResetClientVer();
                }
                catch (Exception ex)
                {
                    throw new Exception("文件同步成功,Server缓存数据清除失败。如遇到未提示版本更新问题请联系管理员重启服务", ex);
                }
            }
            else
            {
                Log4NetHelper.Info("packUploadFolder不存在:" + packUploadFolder);
            }
        }
Exemple #2
0
 public virtual bool SaveSystemConfig(string key, string val, Hashtable result)
 {
     if (String.IsNullOrEmpty(key) || String.IsNullOrEmpty(val))
     {
         result["r"] = false;
         result["d"] = "key或者val为空,保存失败!";
     }
     else
     {
         List <KeyValuePair <string, object> > pars = new List <KeyValuePair <string, object> >();
         pars.Add(new KeyValuePair <string, object>("[key]", key));
         SystemConfig config = SystemConfigDao.Get(pars);
         if (config == null)
         {
             config       = new SystemConfig();
             config.Key   = key;
             config.Value = val;
             int i = SystemConfigDao.Insert(config);
             result["r"] = true;
             result["d"] = "服务配置保存成功!";
         }
         else
         {
             config.Value = val;
             SystemConfigDao.Update(config);
             result["r"] = true;
             result["d"] = "服务配置保存成功!";
         }
         SmartBox.Console.Service.ServiceReference1.ManagerServiceClient ms = new Service.ServiceReference1.ManagerServiceClient();
         ms.ResetRuntimeConfigs();
     }
     return((bool)result["r"]);
 }
Exemple #3
0
        public virtual bool LostDevice(string id, string checkUser)
        {
            DeviceUserDao dudao  = new DeviceUserDao(AppConfig.mainDbKey);
            Device        device = deviceDao.Get(id);

            if (device != null)
            {
                device.LostTime = DateTime.Now;
                device.Status   = 2;
                deviceDao.Update(device);

                List <Tuple <string, string, object> > pars = new List <Tuple <string, string, object> >();
                pars.Add(new Tuple <string, string, object>("deviceid", "=", id));
                List <DeviceUser> deviceUsers = dudao.QueryList(pars);

                try
                {
                    Service.ServiceReference1.ManagerServiceClient msc = new Service.ServiceReference1.ManagerServiceClient();
                    msc.ForceQuitClient(device.ID, device.Resource);
                }
                catch (Exception ex)
                {
                    Log4NetHelper.Error(ex);
                }

                string[] uids = null;

                string uid_online = dudao.GetDeviceOnlineUser(id);//根据设备id取最后登陆成功的用户

                string send_msg_after_device_lost = ConfigurationManager.AppSettings["send_msg_after_device_lost"];
                if (!String.IsNullOrEmpty(send_msg_after_device_lost) && send_msg_after_device_lost.ToLower() == "true")
                {
                    SmartBox.Console.Reminder.Reminder reminder = new Reminder.Reminder();
                    string send_msg_after_device_lost_content   = ConfigurationManager.AppSettings["send_msg_after_device_lost_content"];
                    if (String.IsNullOrEmpty(send_msg_after_device_lost_content))
                    {
                        send_msg_after_device_lost_content = "您的设备已经挂失成功!";
                    }

                    //for (int i = 0; i < uids.Length; ++i)
                    //{
                    try
                    {
                        reminder.RemindByMobile(uid_online, "", "设备挂失", send_msg_after_device_lost_content);
                    }
                    catch (Exception ex)
                    {
                        Log4NetHelper.Error(ex);
                    }
                    //}
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #4
0
 public virtual void ResetClientVer()
 {
     try
     {
         SmartBox.Console.Service.ServiceReference1.ManagerServiceClient ms = new Service.ServiceReference1.ManagerServiceClient();
         ms.ResetClientVer();
     }
     catch (Exception ex)
     {
         Log4NetHelper.Error(ex);
     }
 }
        public JsonResult SaveDeviceAuthSetting(string enableDeviceAuth)
        {
            enableDeviceAuth = Server.UrlEncode(enableDeviceAuth);
            GlobalParam p = Bo.BoFactory.GetGlobalParamBO.GetGlobalParam("device_need_auth");
            if (p == null)
            {
                p = new GlobalParam();
                p.ConfigKey = "device_need_auth";
            }
            p.ConfigValue = enableDeviceAuth;
            Bo.BoFactory.GetGlobalParamBO.Save(p);
            string val = enableDeviceAuth == "1" ? "true" : "false";
            Hashtable hr = new Hashtable();
            Bo.BoFactory.GetSystemConfigBO.SaveSystemConfig("com.beyondbit.user.auth.apply.enable", val, hr);
            Service.ServiceReference1.ManagerServiceClient msc = new Service.ServiceReference1.ManagerServiceClient();
            msc.ResetRuntimeConfigs();

            Hashtable result = new Hashtable();

            result["r"] = true;
            result["d"] = "设备审核设置成功!";

            return Json(result);
        }
Exemple #6
0
        public virtual bool UnBindDevice(string deviceuser_id, string checkUser)
        {
            DeviceUserDao dao        = new DeviceUserDao(AppConfig.mainDbKey);
            DeviceUser    deviceUser = dao.Get(deviceuser_id);

            if (deviceUser != null)
            {
                deviceUser.Status         = 0;
                deviceUser.LastUpdateTime = DateTime.Now;
                deviceUser.LastUpdateUID  = checkUser;
                dao.Update(deviceUser);


                List <Tuple <string, string, object> > pars = new List <Tuple <string, string, object> >();
                pars.Add(new Tuple <string, string, object>("id", "=", deviceUser.DeviceID));
                List <Device> devices = deviceDao.QueryList(pars);

                if (devices.Count > 0)
                {
                    try
                    {
                        //踢用户
                        SmartBox.Console.Service.ServiceReference1.ManagerServiceClient cli = new Service.ServiceReference1.ManagerServiceClient();
                        cli.ForceQuitClient(devices[0].ID, devices[0].Resource);
                    }
                    catch (Exception ex)
                    {
                        Log4NetHelper.Error(ex);
                    }
                }

                string send_msg_after_device_unbind = ConfigurationManager.AppSettings["send_msg_after_device_unbind"];
                if (!String.IsNullOrEmpty(send_msg_after_device_unbind) && send_msg_after_device_unbind.ToLower() == "true")
                {
                    SmartBox.Console.Reminder.Reminder reminder = new Reminder.Reminder();

                    try
                    {
                        string s = "";
                        if (devices.Count > 0)
                        {
                            s = devices[0].Model + "(" + deviceUser.DeviceID + ")";
                        }
                        reminder.RemindByMobile(deviceUser.UID, "", "设备挂失", "您的账号与设备" + s + "已解除绑定!");
                    }
                    catch (Exception ex)
                    {
                        Log4NetHelper.Error(ex);
                    }
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public virtual bool UnBindDevice(string deviceuser_id, string checkUser)
        {
            DeviceUserDao dao = new DeviceUserDao(AppConfig.mainDbKey);
            DeviceUser deviceUser = dao.Get(deviceuser_id);
            if (deviceUser != null)
            {
                deviceUser.Status = 0;
                deviceUser.LastUpdateTime = DateTime.Now;
                deviceUser.LastUpdateUID = checkUser;
                dao.Update(deviceUser);

                List<Tuple<string, string, object>> pars = new List<Tuple<string, string, object>>();
                pars.Add(new Tuple<string, string, object>("id", "=", deviceUser.DeviceID));
                List<Device> devices = deviceDao.QueryList(pars);

                if (devices.Count > 0)
                {
                    try
                    {
                        //踢用户
                        SmartBox.Console.Service.ServiceReference1.ManagerServiceClient cli = new Service.ServiceReference1.ManagerServiceClient();
                        cli.ForceQuitClient(devices[0].ID, devices[0].Resource);
                    }
                    catch (Exception ex)
                    {
                        Log4NetHelper.Error(ex);
                    }
                }

                string send_msg_after_device_unbind = ConfigurationManager.AppSettings["send_msg_after_device_unbind"];
                if (!String.IsNullOrEmpty(send_msg_after_device_unbind) && send_msg_after_device_unbind.ToLower() == "true")
                {
                    SmartBox.Console.Reminder.Reminder reminder = new Reminder.Reminder();

                    try
                    {
                        string s = "";
                        if (devices.Count > 0)
                            s = devices[0].Model + "(" + deviceUser.DeviceID + ")";
                        reminder.RemindByMobile(deviceUser.UID, "", "设备挂失", "您的账号与设备" + s + "已解除绑定!");
                    }
                    catch (Exception ex)
                    {
                        Log4NetHelper.Error(ex);
                    }
                }
                return true;
            }
            else
            {
                return false;
            }
        }
        public virtual bool LostDevice(string id, string checkUser)
        {
            DeviceUserDao dudao = new DeviceUserDao(AppConfig.mainDbKey);
            Device device = deviceDao.Get(id);
            if (device != null)
            {
                device.LostTime = DateTime.Now;
                device.Status = 2;
                deviceDao.Update(device);

                List<Tuple<string, string, object>> pars = new List<Tuple<string, string, object>>();
                pars.Add(new Tuple<string, string, object>("deviceid", "=", id));
                List<DeviceUser> deviceUsers = dudao.QueryList(pars);

                try
                {
                    Service.ServiceReference1.ManagerServiceClient msc = new Service.ServiceReference1.ManagerServiceClient();
                    msc.ForceQuitClient(device.ID, device.Resource);
                }
                catch (Exception ex)
                {
                    Log4NetHelper.Error(ex);
                }

                string[] uids = null;

                string uid_online = dudao.GetDeviceOnlineUser(id);//根据设备id取最后登陆成功的用户

                string send_msg_after_device_lost = ConfigurationManager.AppSettings["send_msg_after_device_lost"];
                if (!String.IsNullOrEmpty(send_msg_after_device_lost) && send_msg_after_device_lost.ToLower() == "true")
                {
                    SmartBox.Console.Reminder.Reminder reminder = new Reminder.Reminder();
                    string send_msg_after_device_lost_content = ConfigurationManager.AppSettings["send_msg_after_device_lost_content"];
                    if (String.IsNullOrEmpty(send_msg_after_device_lost_content))
                        send_msg_after_device_lost_content = "您的设备已经挂失成功!";

                    //for (int i = 0; i < uids.Length; ++i)
                    //{
                    try
                    {
                        reminder.RemindByMobile(uid_online, "", "设备挂失", send_msg_after_device_lost_content);
                    }
                    catch (Exception ex)
                    {
                        Log4NetHelper.Error(ex);
                    }
                    //}
                }
                return true;
            }
            else
            {
                return false;
            }
        }
        public virtual void CopyAppFilesToAppCenterServer(string filePath, int pe_id)
        {
            string packUploadFolder = ConfigurationManager.AppSettings["packUploadFolder"];

            if (Directory.Exists(packUploadFolder))
            {
                string[] sourceFiles = null;
                if (pe_id <= 0)
                {
                    sourceFiles = Directory.GetFiles(packUploadFolder);
                }
                else
                {
                    sourceFiles = new string[] { filePath };
                }

                foreach (string file in sourceFiles)
                {
                    string fileName = Path.GetFileName(file);

                    Service.ApplicationCenterWS.WebService ws = new Service.ApplicationCenterWS.WebService();

                    FileStream fs = null;
                    byte[] content = null;
                    try
                    {
                        fs = new FileStream(file, FileMode.Open, FileAccess.Read);
                        content = new byte[fs.Length];
                        fs.Read(content, 0, (int)fs.Length - 1);
                        ws.AppFileSync(content, fileName);
                    }
                    catch (Exception ex)
                    {
                        Log4NetHelper.Error(ex);
                        continue;
                    }
                    finally
                    {
                        fs.Close();
                        fs.Dispose();
                    }
                }

                //更新server缓存
                try
                {
                    SmartBox.Console.Service.ServiceReference1.ManagerServiceClient cli = new Service.ServiceReference1.ManagerServiceClient();
                    cli.ResetClientVer();
                }
                catch (Exception ex)
                {
                    throw new Exception("文件同步成功,Server缓存数据清除失败。如遇到未提示版本更新问题请联系管理员重启服务", ex);
                }
            }
            else
            {
                Log4NetHelper.Info("packUploadFolder不存在:" + packUploadFolder);
            }
        }
        public JsonResult CreateApplicationPackage(FormCollection form)
        {
            JsonReturnMessages data = new JsonReturnMessages() { IsSuccess = true, Msg = "操作成功" };
            Package4AI package = new Package4AI();

            Hashtable extentInfo = new Hashtable();
            try
            {
                package.CreateUid = CurrentUser.UserUId;
                package.UpdateUid = CurrentUser.UserUId;
                package.CreateTime = DateTime.Now;
                package.UpdateTime = DateTime.Now;
                package.DownloadUri = form["packageFileName"];
                package.Name = form["packageName"];
                package.DisplayName = form["packageDisplayName"];
                package.ClientType = form["packageClientType"];
                package.Type = form["packageType"];
                package.Version = form["packageVersion"];
                package.BuildVer = Convert.ToInt32(form["packageBuildVer"]);
                package.Description = form["packageDescription"];

                List<KeyValuePair<string, object>> _pars = new List<KeyValuePair<string, object>>();

                _pars.Add(new KeyValuePair<string, object>("Name", package.Name));
                _pars.Add(new KeyValuePair<string, object>("ClientType", package.ClientType));

                Package4AI pai = BoFactory.GetPackage4AIBO.Get(_pars);
                if (pai != null)
                {
                    throw new ArgumentException("不能发布重复的包");
                }

                SMC_PackageExt packageExt = new SMC_PackageExt();

                List<Hashtable> applications = new List<Hashtable>();
                extentInfo["Applications"] = applications;
                for (int appIndex = 0; appIndex < Convert.ToInt32(form["applicationCount"]); appIndex++)
                {
                    Hashtable application = new Hashtable();
                    applications.Add(application);
                    Hashtable AppIcons = new Hashtable();
                    application["ApplicationIcon"] = AppIcons;

                    App4AI app4AI = new App4AI();
                    if (!"".Equals(form["AppCode_" + appIndex.ToString()]))
                    {
                        app4AI.AppID = Convert.ToInt32(form["AppCode_" + appIndex.ToString()]);
                    }
                    app4AI.AppCode = form["AppName_" + appIndex.ToString()];
                    packageExt.pe_ApplicationCode += app4AI.AppCode + ",";
                    List<KeyValuePair<string, object>> pars = new List<KeyValuePair<string, object>>();
                    KeyValuePair<string, object> par = new KeyValuePair<string, object>("Name", app4AI.AppCode);
                    pars.Add(par);
                    Application app = BoFactory.GetApplicationBO.Get(pars);
                    string applicationName = "";
                    if (app != null)
                        applicationName = app.DisplayName;
                    packageExt.pe_ApplicationName += applicationName + ",";
                    app4AI.ClientType = form["AppCheckClentType_" + appIndex.ToString()];

                    application["ApplicationID"] = form["AppCode_" + appIndex.ToString()];
                    AppIcons["AppIconName"] = form["AppIco_" + appIndex.ToString()];
                    //AppIcons.Add(new Tuple<string, string, object>("ApplicationID", form["AppCode_" + appIndex.ToString()], form["AppIco_" + appIndex.ToString()]));

                    app4AI.IconUri = GetAndroidApplicationIcoUri(Path.Combine(TEMPPATH, package.DownloadUri), form["AppIco_" + appIndex.ToString()]);
                    AppIcons["AppIconUri"] = app4AI.IconUri;

                    app4AI.Seq = appIndex + 1;
                    app4AI.CreateTime = DateTime.Now;
                    app4AI.UpdateTime = DateTime.Now;
                    app4AI.CreateUid = CurrentUser.UserUId;
                    app4AI.UpdateUid = CurrentUser.UserUId;

                    List<Hashtable> activities = new List<Hashtable>();
                    application["activities"] = activities;
                    for (int activtyIndex = 0; activtyIndex < Convert.ToInt32(form["activityCount_" + appIndex.ToString()]); activtyIndex++)
                    {
                        Action4Android action4Android = new Action4Android();
                        action4Android.Seq = Convert.ToInt32(form["ActivitySeq_" + appIndex.ToString() + "_" + activtyIndex.ToString()]);
                        action4Android.DisplayName = form["ActivityDisplayName_" + appIndex.ToString() + "_" + activtyIndex.ToString()];
                        action4Android.IsLaunch = Convert.ToBoolean(form["ActivityLaunch_" + appIndex.ToString() + "_" + activtyIndex.ToString()]);
                        action4Android.IconUri = GetAndroidApplicationIcoUri(Path.Combine(TEMPPATH, package.DownloadUri), form["ActivityIco_" + appIndex.ToString() + "_" + activtyIndex.ToString()]);
                        action4Android.ShortName = form["ActivityShortName_" + appIndex.ToString() + "_" + activtyIndex.ToString()];
                        action4Android.Name = form["ActivityName_" + appIndex.ToString() + "_" + activtyIndex.ToString()];
                        action4Android.CreateTime = DateTime.Now;
                        action4Android.UpdateTime = DateTime.Now;
                        action4Android.CreateUid = CurrentUser.UserUId;
                        action4Android.UpdateUid = CurrentUser.UserUId;

                        Hashtable activity = new Hashtable();
                        activity["DisplayName"] = form["ActivityDisplayName_" + appIndex.ToString() + "_" + activtyIndex.ToString()];
                        activity["ActivitySeq"] = form["ActivitySeq_" + appIndex.ToString() + "_" + activtyIndex.ToString()];
                        activity["IsLaunch"] = action4Android.IsLaunch;
                        activity["IconUri"] = action4Android.IconUri;
                        activity["ShortName"] = action4Android.ShortName;
                        activity["Name"] = action4Android.Name;
                        activity["CreateTime"] = action4Android.CreateTime;
                        activity["UpdateTime"] = action4Android.UpdateTime;
                        activity["CreateUid"] = action4Android.CreateUid;
                        activity["UpdateUid"] = action4Android.UpdateUid;

                        activities.Add(activity);
                        app4AI.ActionList.Add(action4Android);
                    }
                    package.App4AIList.Add(app4AI);
                }

                string saveFileName = string.Format("{0}_v{1}_{2}{3}", package.Name, package.BuildVer, DateTime.Now.ToString("yyyyMMddHHmmss"), Path.GetExtension(package.DownloadUri));
                string tempFilePath = Path.Combine(TEMPPATH, package.DownloadUri);
                string saveFilePath = Path.Combine(SAVEPATH, saveFileName);

                if (package.Type.Equals("Main", StringComparison.CurrentCultureIgnoreCase))
                {
                    var mainConfig = AppConfig.PublishConfig.GetValue(package.ClientType);
                    if (package.ClientType.EndsWith("ios", StringComparison.CurrentCultureIgnoreCase))
                    {
                        mainConfig.Url = IOS_URL_PREFIX + mainConfig.Url;
                    }
                    package.DownloadUri = mainConfig.Url;
                    saveFilePath = mainConfig.Path;
                }
                else
                {
                    package.DownloadUri = Path.Combine(AppConfig.PackUrl, saveFileName);
                }

                GlobalParam parm = Bo.BoFactory.GetGlobalParamBO.GetGlobalParam("app_sj_need_auth");
                packageExt.pe_id = BoFactory.GetVersionTrackBo.GetMaxPackageExtId() + 1;
                packageExt.pe_ExtentInfo = Newtonsoft.Json.JsonConvert.SerializeObject(extentInfo);

                if (parm.ConfigValue == "0")
                {
                    //不需要审核
                    BoFactory.GetVersionTrackBo.InsertPackage4AI(package, tempFilePath, saveFilePath);
                    packageExt.pe_UsefulStstus = "1";//上架状态
                    packageExt.pe_UsefulTime = DateTime.Now;
                    packageExt.pe_UsefulOperatorUID = CurrentUser.UserUId;
                    packageExt.pe_UsefulOperatorName = CurrentUser.UnitName;
                    packageExt.pe_AuthStatus = 1;//审核通过
                    packageExt.pe_AuthTime = DateTime.Now;
                    packageExt.pe_AuthSubmitName = CurrentUser.FullName;
                    packageExt.pe_AuthSubmitUID = CurrentUser.UserUId;
                    packageExt.pe_AuthManUID = CurrentUser.UserUId;
                    packageExt.pe_AuthMan = CurrentUser.FullName;
                    packageExt.pe_SyncStatus = 0;
                    packageExt.pe_Direction = "发布";
                    packageExt.pe_AuthSubmitTime = DateTime.Now;
                }
                else
                {
                    string serializationPath = Server.MapPath("~/PackageSerialization/") + packageExt.pe_id + "/";
                    if (!Directory.Exists(serializationPath))
                        Directory.CreateDirectory(serializationPath);
                    using (Stream fStream = new FileStream(serializationPath + "package.xml", FileMode.Create, FileAccess.ReadWrite))
                    {
                        XmlSerializer xmlFormat = new XmlSerializer(typeof(Package4AI));
                        xmlFormat.Serialize(fStream, package);
                        fStream.Close();
                        fStream.Dispose();
                    }
                    XmlDocument xmlDoc = new XmlDocument();
                    string content = String.Format("<PackagePath><TempFilePath>{0}</TempFilePath><SaveFileName>{1}</SaveFileName></PackagePath>", tempFilePath, saveFilePath);
                    xmlDoc.LoadXml(content);
                    xmlDoc.Save(serializationPath + "path.xml");

                    //审核通过后再同步到Package4AI表
                    packageExt.pe_UsefulStstus = "0";//上架状态
                    packageExt.pe_Direction = "上架";
                    packageExt.pe_AuthStatus = 0;//待审核
                    packageExt.pe_AuthSubmitTime = DateTime.Now;
                    packageExt.pe_AuthSubmitName = CurrentUser.FullName;
                    packageExt.pe_AuthSubmitUID = CurrentUser.UserUId;
                    packageExt.pe_Direction = "发布";
                    packageExt.pe_UsefulTime = DateTime.Now;
                    packageExt.pe_UsefulOperatorUID = CurrentUser.UserUId;
                    packageExt.pe_UsefulOperatorName = CurrentUser.FullName;

                    System.IO.File.Copy(tempFilePath, saveFilePath, true);
                }

                //插入扩展表
                packageExt.pe_ClientType = package.ClientType;
                var s1 = form["IsRecom"];
                var s2 = form["IsMust"];
                packageExt.pe_IsTJ = form["IsRecom"];
                packageExt.pe_IsBB = form["IsMust"];
                FileInfo fi = new FileInfo(saveFilePath);
                packageExt.pe_Size = (int)fi.Length;
                packageExt.TableName = "Package4AI";
                packageExt.TableID = package.ID;
                packageExt.pe_UnitCode = form["Unit"];
                packageExt.pe_CategoryID = form["AppID"];
                packageExt.pe_Category = BoFactory.GetVersionTrackBo.GetApplicationCategory(form["AppID"]).DisplayName;
                packageExt.pe_UnitName = BoFactory.GetSMC_UnitBo.Get(packageExt.pe_UnitCode).Unit_Name;
                packageExt.pe_CreateUid = CurrentUser.UserUId;
                packageExt.pe_CreatedTime = DateTime.Now;
                packageExt.pe_UpdateUid = CurrentUser.UserUId;
                packageExt.pe_UpdateTime = DateTime.Now;
                packageExt.pe_Version = form["packageVersion"];
                packageExt.pe_BuildVer = form["packageBuildVer"];
                packageExt.pe_Name = form["packageDisplayName"];
                packageExt.pe_DisplayName = form["packageDisplayName"];
                packageExt.pe_Description = form["packageDescription"];
                packageExt.pe_Firmware = form["Firmware"];
                packageExt.pe_Type = package.Type;

                string conSolePath = HttpRuntime.AppDomainAppPath;//服务器路径
                string pDir = Path.Combine(SAVEOUTPATH, packageExt.pe_id.ToString());//相对路径 用安装包ID做文件夹名
                string saveDir = Path.Combine(conSolePath, pDir);

                if (!System.IO.Directory.Exists(saveDir))
                {
                    System.IO.Directory.CreateDirectory(saveDir);
                }
                //生成下载url,并生成二维码
                string url = package.DownloadUri;

                string pe_2dPictureUrl = Save2DPicture(packageExt.pe_id, url);

                //保存安装包
                string packageName = "Package4AI-" + Path.GetFileName(tempFilePath);
                string packageFilePath = System.IO.Path.Combine(saveDir, packageName);
                System.IO.File.Copy(saveFilePath, packageFilePath, true);

                packageExt.pe_FileUrl = "~/PackageExt/" + packageExt.pe_id + "/" + packageName;

                packageExt.pe_2dPictureUrl = pe_2dPictureUrl;// @"~/" + pDir + "/二维码图片.jpeg";
                //packageExt.pe_2dPictureUrl = packageExt.pe_2dPictureUrl.Replace(@"\\", "/");
                packageExt.pe_DownloadUri = url.Replace(@"\", "/");

                int i = Request.Files.Count;
                string iconSavePath = "";
                if (i > 0)
                {
                    //保存安装包图标
                    HttpPostedFileBase icon = Request.Files[0];
                    string iconFileName = "AppIcon.png";
                    iconSavePath = System.IO.Path.Combine(saveDir, iconFileName);
                    if (System.IO.File.Exists(iconSavePath))
                    {
                        System.IO.File.Delete(iconSavePath);
                    }
                    icon.SaveAs(iconSavePath);

                    packageExt.pe_PictureUrl = @"~/" + pDir + "/AppIcon.png";
                    packageExt.pe_PictureUrl = packageExt.pe_PictureUrl.Replace(@"\\", "/");
                }

                BoFactory.GetVersionTrackBo.InsertPackageExt(packageExt);

                if (parm.ConfigValue == "0")
                {
                    //不需要审核,直接同步到应用中心
                    //同步至外网数据
                    _SyncPackageExt(packageExt);
                }

                if (package.Type.Equals("Main", StringComparison.CurrentCultureIgnoreCase))
                {
                    try
                    {
                        //更新server缓存
                        SmartBox.Console.Service.ServiceReference1.ManagerServiceClient cli = new Service.ServiceReference1.ManagerServiceClient();
                        cli.ResetClientVer();
                    }
                    catch
                    {
                        data.Msg = "操作成功,更新SmartBox服务缓存失败。";
                    }
                }

                //app更新到外网
                BoFactory.GetCommonBO.CopyAppFilesToAppCenterServer(saveFilePath, packageExt.pe_id);

                #region pad布局检查
                if (package.ClientType.StartsWith("Pad", StringComparison.CurrentCultureIgnoreCase))
                {
                    PageView view = new PageView();
                    view.PageSize = 15;
                    view.PageIndex = 0;
                    int HomePlans = BoFactory.GetVersionTrackBo.QueryHomePlanList(view).rows.Count;
                    if (HomePlans < 1)
                    {
                        data.Msg += " \n没有页面布局,请在Home布局管理中增加.";
                    }
                }
                #endregion
            }
            catch (Exception ex)
            {
                Log4NetHelper.Error(ex);
                data.IsSuccess = false;
                data.Msg = ex.Message;
            }

            return Json(data, "text/html");
        }
        public JsonResult UpdatePackage(FormCollection form)
        {
            JsonReturnMessages data = new JsonReturnMessages() { IsSuccess = true, Msg = "操作成功" };
            Package4AI package = new Package4AI();
            SMC_PackageExtHistory history = new SMC_PackageExtHistory();

            package.CreateUid = form["packageCreateUser"];
            package.UpdateUid = CurrentUser.UserUId;
            package.CreateTime = Convert.ToDateTime(form["packageCreateDateTime"]);
            package.UpdateTime = DateTime.Now;
            package.DownloadUri = form["packageFileName"];
            package.Name = form["packageName"];
            package.DisplayName = form["packageDisplayName"];
            package.ClientType = form["packageClientType"];
            package.Type = form["packageType"];
            package.Version = form["packageVersion"];
            package.BuildVer = Convert.ToInt32(form["packageBuildVer"]);
            package.Description = form["packageDescription"];
            package.ID = Convert.ToInt32(form["packageID"]);

            SMC_PackageExt ext = BoFactory.GetAppCenterBO.GetPackageExt(package.ID);
            string tableName = ext.TableName.ToLower();
            if (tableName != "webapplication" && tableName != "smc_package4out")
            {
                package.ID = ext.TableID;
            }

            for (int appIndex = 0; appIndex < Convert.ToInt32(form["applicationCount"]); appIndex++)
            {
                App4AI app4AI = new App4AI();
                if (!"".Equals(form["AppCode_" + appIndex.ToString()]))
                {
                    app4AI.AppID = Convert.ToInt32(form["AppCode_" + appIndex.ToString()]);
                }
                app4AI.AppCode = form["AppName_" + appIndex.ToString()];
                app4AI.ClientType = form["AppCheckClentType_" + appIndex.ToString()];
                app4AI.IconUri = form["AppIco_" + appIndex.ToString()];
                app4AI.Seq = 1;
                app4AI.CreateTime = package.CreateTime;
                app4AI.UpdateTime = DateTime.Now;
                app4AI.CreateUid = package.CreateUid;
                app4AI.UpdateUid = CurrentUser.UserUId;

                for (int activtyIndex = 0; activtyIndex < Convert.ToInt32(form["activityCount_" + appIndex.ToString()]); activtyIndex++)
                {
                    Action4Android action4Android = new Action4Android();
                    action4Android.Seq = Convert.ToInt32(form["ActivitySeq_" + appIndex.ToString() + "_" + activtyIndex.ToString()]);
                    action4Android.DisplayName = form["ActivityDisplayName_" + appIndex.ToString() + "_" + activtyIndex.ToString()];
                    action4Android.IsLaunch = Convert.ToBoolean(form["ActivityLaunch_" + appIndex.ToString() + "_" + activtyIndex.ToString()]);
                    action4Android.IconUri = form["ActivityIco_" + appIndex.ToString() + "_" + activtyIndex.ToString()];
                    action4Android.ShortName = form["ActivityShortName_" + appIndex.ToString() + "_" + activtyIndex.ToString()];
                    action4Android.Name = form["ActivityName_" + appIndex.ToString() + "_" + activtyIndex.ToString()];
                    action4Android.CreateTime = package.CreateTime;
                    action4Android.UpdateTime = DateTime.Now;
                    action4Android.CreateUid = package.CreateUid;
                    action4Android.UpdateUid = CurrentUser.UserUId;
                    app4AI.Package4AIID = package.ID;
                    action4Android.App4AIID = package.ID;
                    Action4Android a4a = BoFactory.GetAction4AndroidBO.Get(action4Android.Name);
                    if (a4a == null)
                        app4AI.ActionList.Add(action4Android);
                }

                IList<KeyValuePair<string, object>> pars = new List<KeyValuePair<string, object>>();
                pars.Add(new KeyValuePair<string, object>("Package4AIID", app4AI.Package4AIID));
                pars.Add(new KeyValuePair<string, object>("AppCode", app4AI.AppCode));
                pars.Add(new KeyValuePair<string, object>("ClientType", app4AI.ClientType));
                App4AI _app4ai = BoFactory.GetApp4AIBO.Get(pars);
                if (_app4ai == null)
                {
                    package.App4AIList.Add(app4AI);
                }
                else
                {
                    _app4ai.AppID = app4AI.AppID;
                    BoFactory.GetApp4AIBO.Update(_app4ai);
                }
            }

            try
            {
                string saveFileName = string.Format("{0}_v{1}_{2}{3}", package.Name, package.BuildVer, DateTime.Now.ToString("yyyyMMddHHmmss"), Path.GetExtension(package.DownloadUri));
                string tempFilePath = Path.Combine(TEMPPATH, package.DownloadUri);
                string saveFilePath = Path.Combine(SAVEPATH, saveFileName);

                if (package.ClientType.EndsWith("ios", StringComparison.CurrentCultureIgnoreCase))
                {
                    string padUrl = string.Empty;
                    string phoneUrl = string.Empty;
                    Common.Configuration.IOSConfiguration iosConfig = (Common.Configuration.IOSConfiguration)System.Configuration.ConfigurationManager.GetSection("PublishConfig");
                    if (iosConfig != null && iosConfig.IOSPublishs != null)
                    {
                        foreach (Common.Configuration.IOSPublishElement item in iosConfig.IOSPublishs)
                        {
                            if (item.ClientType.StartsWith("Pad/iOS", StringComparison.CurrentCultureIgnoreCase))
                                padUrl = item.Url;
                            if (item.ClientType.StartsWith("Phone/iOS", StringComparison.CurrentCultureIgnoreCase))
                                phoneUrl = item.Url;
                        }
                    }
                    if (package.Type.Equals("Main", StringComparison.CurrentCultureIgnoreCase))
                    {
                        if (package.ClientType.StartsWith("Pad", StringComparison.CurrentCultureIgnoreCase))
                        {
                            package.DownloadUri = @"itms-services://?action=download-manifest&url=" + padUrl;
                        }
                        else if (package.ClientType.StartsWith("Phone", StringComparison.CurrentCultureIgnoreCase))
                        {
                            package.DownloadUri = @"itms-services://?action=download-manifest&url=" + phoneUrl;
                        }
                    }
                }
                else
                {
                    string padUrl = string.Empty;
                    string phoneUrl = string.Empty;
                    Common.Configuration.IOSConfiguration iosConfig = (Common.Configuration.IOSConfiguration)System.Configuration.ConfigurationManager.GetSection("PublishConfig");
                    if (iosConfig != null && iosConfig.IOSPublishs != null)
                    {
                        foreach (Common.Configuration.IOSPublishElement item in iosConfig.IOSPublishs)
                        {
                            if (item.ClientType.StartsWith("Pad/Android", StringComparison.CurrentCultureIgnoreCase))
                                padUrl = item.Url;
                            if (item.ClientType.StartsWith("Phone/Android", StringComparison.CurrentCultureIgnoreCase))
                                phoneUrl = item.Url;
                        }
                    }
                    if (package.Type.Equals("Main", StringComparison.CurrentCultureIgnoreCase))
                    {
                        package.DownloadUri = Path.Combine(AppConfig.PackUrl, saveFileName);
                    }
                }

                SMC_PackageExt _ext = BoFactory.GetAppCenterBO.GetPackage("Package4AI", package.ID.ToString());
                _ext.pe_LastVersion = _ext.pe_Version;
                _ext.pe_Version = package.Version;
                _ext.pe_FileUrl = "~/PackageExt/" + _ext.pe_id + "/" + Path.GetFileName(tempFilePath);
                GlobalParam parm = Bo.BoFactory.GetGlobalParamBO.GetGlobalParam("app_sj_need_auth");

                if (parm.ConfigValue != "0")
                {
                    string serializationPath = Server.MapPath("~/PackageSerialization/") + _ext.pe_id + "/";
                    if (!Directory.Exists(serializationPath))
                        Directory.CreateDirectory(serializationPath);
                    using (Stream fStream = new FileStream(serializationPath + "package.xml", FileMode.Create, FileAccess.ReadWrite))
                    {
                        XmlSerializer xmlFormat = new XmlSerializer(typeof(Package4AI));
                        xmlFormat.Serialize(fStream, package);
                        fStream.Close();
                        fStream.Dispose();
                    }
                    XmlDocument xmlDoc = new XmlDocument();
                    string content = String.Format("<PackagePath><TempFilePath>{0}</TempFilePath><SaveFileName>{1}</SaveFileName></PackagePath>", tempFilePath, saveFilePath);
                    xmlDoc.LoadXml(content);
                    xmlDoc.Save(serializationPath + "path.xml");

                    //审核通过后再同步到Package4AI表
                    _ext.pe_UsefulStstus = "0";//上架状态
                    _ext.pe_AuthStatus = 0;
                    _ext.pe_AuthSubmitName = CurrentUser.FullName;
                    _ext.pe_AuthSubmitTime = DateTime.Now;
                    _ext.pe_AuthSubmitUID = CurrentUser.UserUId;
                    _ext.pe_UsefulTime = DateTime.Now;
                    _ext.pe_UsefulOperatorUID = CurrentUser.UserUId;
                    _ext.pe_UsefulOperatorName = CurrentUser.FullName;
                    if (package.ClientType.ToLower().IndexOf("ios") != -1)
                        _ext.pe_DownloadUri = package.DownloadUri;
                }

                _ext.pe_Version = form["packageVersion"];
                _ext.pe_BuildVer = form["packageBuildVer"];
                Bo.BoFactory.GetSMC_PackageExtBO.Save(_ext);

                if (parm.ConfigValue == "0")
                {
                    //不需要审核,直接同步到应用中心
                    //同步至外网数据

                    BoFactory.GetVersionTrackBo.UpdatePackage(package, tempFilePath, saveFilePath);
                    _ext.pe_UsefulStstus = "1";//上架状态
                    _ext.pe_UsefulTime = DateTime.Now;
                    _ext.pe_UsefulOperatorUID = CurrentUser.UserUId;
                    _ext.pe_UsefulOperatorName = CurrentUser.FullName;
                    _ext.pe_AuthStatus = 1;//审核通过
                    _ext.pe_AuthTime = DateTime.Now;
                    _ext.pe_AuthManUID = CurrentUser.UserUId;
                    _ext.pe_AuthMan = CurrentUser.FullName;
                    _ext.pe_DownloadUri = ConfigurationManager.AppSettings["packUrl"] + saveFileName;
                    if (package.ClientType.ToLower().IndexOf("ios") != -1)
                        _ext.pe_DownloadUri = package.DownloadUri;

                    //内部发布到Package4AI
                    BoFactory.GetCommonBO.SMC_PackageExtInternalRelease(_ext);

                    //同步到应用中心
                    _SyncPackageExt(_ext);
                }

                #region 上传文件自动发布
                if (package.Type.Equals("Main", StringComparison.CurrentCultureIgnoreCase))
                {
                    //更新server缓存
                    try
                    {
                        SmartBox.Console.Service.ServiceReference1.ManagerServiceClient cli = new Service.ServiceReference1.ManagerServiceClient();
                        cli.ResetClientVer();
                    }
                    catch
                    {
                        data.Msg = "操作成功,更新Server缓存失败。如遇到未提示版本更新问题请联系管理员重启服务。";
                    }
                }

                #endregion
            }
            catch (Exception ex)
            {
                Log4NetHelper.Error(ex);
                data.IsSuccess = false;
                data.Msg = ex.Message;
            }

            return Json(data);
        }