Пример #1
0
        static void Run(string[] args)
        {
            var needAdmin = Convert.ToInt32(args[1]) == 1;

            switch (args[3])
            {
            case "vaultapp":
                var appFolder = args[5];
                var files     = args.SkipWhile((c, i) => i < 7).ToArray();
                try
                {
                    var errList = VaultAppUtils.ExtractApps(appFolder, files, Logger.Log);
                    Logger.Log.Error("加载App失败:" + String.Join("\r\n", errList));
                    Trace.WriteLine("加载App成功:");
                }
                catch (Exception ex)
                {
                    Trace.WriteLine("加载App失败:" + ex.Message);
                }
                break;

            case "revitplugin":
                var baseFolder = args[5];
                var dict       = AddinPathUtils.GetAddinDict(baseFolder);
                foreach (var d in dict)
                {
                    foreach (var f in d.Value)
                    {
                        AddinPathUtils.InstallPlugin(d.Key, f, needAdmin);
                    }
                }
                break;
            }
        }
Пример #2
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);
        }