예제 #1
0
파일: Tests.cs 프로젝트: weijx-xa/test
        internal static void TestVaultAppDefFile()
        {
            var appDefFile =
                @"D:\Program Files\M-Files\10.2.3920.54\Client\Apps\{B33E2A16-C8BA-410A-BE31-61CB2B369215}\sysapps\F101258B-FD65-4199-B22F-240B507C0DCC\appdef.xml";
            string err;
            var    ad = SerialUtils.GetObject <VaultAppDefFile>(appDefFile, out err);

            Console.WriteLine(ad == null ? err : ad.Guid);
            Console.ReadKey();
        }
예제 #2
0
        public static VaultAppDefFile GetFromFile(string appdefXml)
        {
            string err;
            var    obj = SerialUtils.GetObject <VaultAppDefFile>(appdefXml, out err);

            if (!String.IsNullOrEmpty(err))
            {
                Trace.WriteLine(err);
            }
            return(obj);
        }
예제 #3
0
        public static RevitAddinFile GetFromFile(string filePath)
        {
            string err = null;
            var    obj = SerialUtils.GetObject <RevitAddinFile>(filePath, out err);

            if (!String.IsNullOrEmpty(err))
            {
                Trace.WriteLine(err);
            }
            return(obj);
        }
예제 #4
0
        public static VaultAppDefFile GetAppDef(string zipFile)
        {
            using (var zip = new ZipFile(zipFile, Encoding.Default))
            {
                var defEntry = zip.Entries.FirstOrDefault(c =>
                                                          c.FileName.EndsWith(VaultAppDefFile.FileName, StringComparison.OrdinalIgnoreCase));
                var appdefFile = Path.Combine(_tempPath, defEntry.FileName);
                if (File.Exists(appdefFile))
                {
                    File.Delete(appdefFile);
                }
                defEntry.Extract(_tempPath, ExtractExistingFileAction.OverwriteSilently);

                string err;
                var    defObj = SerialUtils.GetObject <VaultAppDefFile>(appdefFile, out err);
                if (defObj == null)
                {
                    Trace.WriteLine("appdef.xml文件格式不正确:" + err);
                    return(null);
                }
                return(defObj);
            }
        }
예제 #5
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);
        }