예제 #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
        private VaultAppModel ToModel(VaultApp app, bool needImpersonate, bool isUpdate = false)
        {
            if (app == null)
            {
                throw new ArgumentNullException("app");
            }
            var vam = new VaultAppModel
            {
                AppId = app.Id,
                Guid  = app.Guid,
                //CloudAppEnabled = app.CloudAppEnabled,
                IsUpdate = isUpdate,
                Version  = app.Version
            };

            try
            {
                if (needImpersonate)
                {
                    using (StorageUtility.GetImpersonator())
                    {
                        vam.ZipFile = File.ReadAllBytes(app.Filepath);
                    }
                }
                else
                {
                    vam.ZipFile = File.ReadAllBytes(app.Filepath);
                }
            }
            catch (Exception ex)
            {
                Log.Info(app.Filepath + ex.Message);
            }
            return(vam);
        }
예제 #3
0
 public void DeleteVaultApp(VaultApp app)
 {
     if (app == null)
     {
         throw new ArgumentNullException("app");
     }
     _appRepo.Delete(app);
 }
예제 #4
0
 public void InsertVaultApp(VaultApp app)
 {
     if (app == null)
     {
         throw new ArgumentNullException("app");
     }
     //var app0 = _appRepo.Table.FirstOrDefault(c => c.Guid == app.Guid);
     //if (app0 != null) throw new AecException("此VaultApp已存在:" + app.Guid);
     _appRepo.Insert(app);
 }
예제 #5
0
        private VaultAppModel ToModel(VaultApp app, bool isUpdate = false)
        {
            var vam = new VaultAppModel
            {
                AppId    = app.Id,
                Guid     = app.Guid,
                IsUpdate = isUpdate,
                Version  = app.Version
            };

            try
            {
                vam.ZipFile = File.ReadAllBytes(app.Filepath);
            }
            catch (Exception ex)
            {
                Log.Info(app.Filepath + ex.Message);
            }
            return(vam);
        }
예제 #6
0
        /// <summary>
        /// 必须先设置UNCPath属性
        /// </summary>
        /// <param name="app"></param>
        public static void SetPropertiesFromAppDefFile(this VaultApp app)
        {
            if (app == null)
            {
                throw new ArgumentNullException("app");
            }
            //if (app.File == null || app.File.Length == 0) throw new ArgumentException("File");
            //var tempPath = Path.GetTempPath();
            var appPath = app.Filepath;//Path.Combine(tempPath, DateTime.Now.ToString("yyyyMMddHHmmss") + ".zip");

            //File.WriteAllBytes(appPath, app.File);
            if (!File.Exists(appPath))
            {
                throw new FileNotFoundException("VaultApp的路径不存在:" + appPath);
            }
            using (var appStream = new MemoryStream())
            {
                //string filePath = null;
                using (var zipFile = new ZipFile(appPath, Encoding.Default))
                {
                    var entry = zipFile.Entries.FirstOrDefault(c => c.FileName.ToUpper().Contains("APPDEF.XML"));
                    if (entry == null)
                    {
                        throw new FileNotFoundException("缺少appdef.xml文件");
                    }
                    //filePath = Path.Combine(tempPath, entry.FileName.Replace('/', '\\'));

                    entry.Extract(appStream);
                    //entry.Extract(tempPath, ExtractExistingFileAction.OverwriteSilently);
                }
                appStream.Position = 0;
                //var appdefFile = filePath;
                var appElem = XElement.Load(appStream);
                if (appElem.Name.LocalName.ToUpper() != "APPLICATION")
                {
                    throw new Exception("appdef.xml的格式不正确,缺少application节点");
                }
                var guidElem = appElem.Element("guid");
                if (guidElem != null)
                {
                    app.Guid = guidElem.Value;
                }
                var nameElem = appElem.Element("name");
                if (nameElem != null)
                {
                    app.Name = nameElem.Value;
                }
                var descElem = appElem.Element("description");
                if (descElem != null)
                {
                    app.Description = descElem.Value;
                }
                var publisherElem = appElem.Element("publisher");
                if (publisherElem != null)
                {
                    app.Publisher = publisherElem.Value;
                }
                var versionElem = appElem.Element("version");
                if (versionElem != null)
                {
                    app.Version = versionElem.Value;
                }
                else
                {
                    app.Version = "1.1";
                }
            }
        }