/// <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); }