示例#1
0
        private List <VaultAppModel> GetCloudDiscApps(AppDescList appList)
        {
            var appPath = Path.Combine(Global.ServerPath, @"App_Data\CloudApps.zip");
            var va      = new VaultApp {
                Filepath = appPath
            };

            va.SetPropertiesFromAppDefFile();
            var models  = new List <VaultAppModel>();
            var needGet = true;

            if (appList != null && appList.Apps != null && appList.Apps.Count > 0)
            {
                var a = //是否存在版本和GUID相同的App
                        appList.Apps.FirstOrDefault(c => c.Guid.ToUpper() == va.Guid.ToUpper() && c.Version == va.Version);
                if (a != null)
                {
                    needGet = false;            //若存在,则不再下载
                }
            }
            if (needGet)
            {
                var m = ToModel(va, false);
                models.Add(m);
            }
            return(models);
        }
示例#2
0
        public async Task <IHttpActionResult> AppsNeeded([FromUri] long id, [FromBody] AppDescList appList)
        {
            AppDesc[] apps0 = null;
            if (appList != null && appList.Apps != null)
            {
                apps0 = appList.Apps.ToArray();
            }
            var apps = await Task.Run(() => GetAppsByVault(id, apps0));

            Log.Info(" AppsNeeded :" + apps.Count);
            return(Ok(apps));
        }
示例#3
0
        public async Task <IHttpActionResult> CloudDiscAppNeeded(AppDescList appList)
        {
            var apps = await Task.Run(() => GetCloudDiscApps(appList));

            return(Ok(apps));
        }
示例#4
0
 public Task <HttpResponseMessage> AppsNeeded(long vaultId, AppDescList apps, TokenModel token)
 {
     TokenClient.RefreshToken(_client, token);
     return(_client.PostAsJsonAsync(_routePrefix + "/AppsNeeded/" + vaultId, apps));
 }
示例#5
0
 public Task <HttpResponseMessage> CloudDiscAppsNeeded(AppDescList apps, TokenModel token)
 {
     TokenClient.RefreshToken(_client, token);
     return(_client.PostAsJsonAsync(_routePrefix + "/CloudDiscAppNeeded", apps));
 }
示例#6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="proj"></param>
        /// <returns>是否需要加载App</returns>
        internal bool LoadApps(ProjectDto proj)
        {
            var token = BimToken;
            //var proj = GetProject();
            //if (proj == null) return;
            var guid   = proj.Vault.Guid;
            var loaded = VaultAppDict.ContainsKey(guid);

            if (loaded)
            {
                return(false);
            }

            var appDefs = ClientUtils.GetVaultSysAppDefFiles(guid);

            //if (appDefs.Count > 0) return true; // todo

            var appList = new AppDescList();

            foreach (var a in appDefs)
            {
                string err;
                var    defObj = SerialUtils.GetObject <VaultAppDefFile>(a, out err);
                if (defObj == null)
                {
                    continue;
                }
                appList.Apps.Add(new AppDesc {
                    Guid = defObj.Guid, Version = defObj.Version
                });
            }


            var res    = VaultClient.AppsNeeded(proj.Vault.Id, appList, token).Result;
            var resStr = res.Content.ReadAsStringAsync().Result;

            if (!res.IsSuccessStatusCode)
            {
                Log.Info("LoadApps failure?");
                return(false);
                //throw new Exception("无法获取需要加载的库应用:" + resStr);
            }
            var apps = JsonConvert.DeserializeObject <List <VaultAppModel> >(resStr);

            Log.Info("loadapps apps.count:" + apps.Count);
            //if (!User.CloudAppEnabled)
            //{
            //    apps = apps.Where(c => !c.CloudAppEnabled).ToList();
            //}

            var zipFiles   = new List <string>();
            var exportPath = Path.GetTempPath();
            var appPath    = ClientUtils.GetAppPath(guid);

            foreach (var a in apps)
            {
                var path = Path.Combine(exportPath, a.Guid + ".zip");
                File.WriteAllBytes(path, a.ZipFile);
                var needUpdate = VaultAppUtils.NeedUpdate(appPath, a.Guid, path);
                if (!needUpdate)
                {
                    continue;
                }
                zipFiles.Add(path);
            }
            if (zipFiles.Count == 0)
            {
                VaultAppDict.Add(guid, apps);
                return(false);
            }
            var isAdmin = IsAdministrator();

            if (isAdmin)
            {
                var errs = VaultAppUtils.ExtractApps(appPath, zipFiles.ToArray(), Log);
                if (errs.Count > 0 && Log != null)
                {
                    Log.Warn(String.Join("; ", errs));
                }
            }
            else
            {
                var fileStr   = zipFiles.Select(c => "\"" + c + "\"").ToArray();
                var location  = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                var exeFile   = Path.Combine(location, "AecCloud.ClientConsole.exe");
                var startInfo = new ProcessStartInfo
                {
                    FileName         = exeFile,
                    Arguments        = String.Format("-u 1 -t vaultapp -p \"{0}\" -d {1}", appPath.TrimEnd('\\'), String.Join(" ", fileStr)),
                    UseShellExecute  = true,
                    Verb             = "runas",
                    WorkingDirectory = Environment.CurrentDirectory
                };
                try
                {
                    var p        = Process.Start(startInfo);
                    var exitCode = -1;
                    if (p != null)
                    {
                        p.WaitForExit();
                        exitCode = p.ExitCode;
                    }
                    if (exitCode != 0)
                    {
                        Log.Error("加载VaultApp失败:" + exitCode);
                    }
                }
                catch (System.ComponentModel.Win32Exception)//用户点击取消的异常
                {
                }
            }
            VaultAppDict.Add(guid, apps);
            return(true);
        }