public override void Build() { var files = GetFilesWithoutDirectories(Data.FullSearchPath); for (int i = 0; i < files.Count; i++) { var item = files[i]; if (EditorUtility.DisplayCancelableProgressBar(string.Format("Packing... [{0}/{1}]", i, files.Count), item, i * 1f / files.Count)) { EditorUtility.ClearProgressBar(); break; } string bundleName = GetABNameWithDirectoryAndFile(Data.FinalDirectory, item); if (!IsContainInPackedAssets(item)) { AssetBundleBuild build = new AssetBundleBuild(); build.assetBundleName = bundleName; build.assetNames = new string[] { item }; Builds.Add(build); AddToPackedAssets(item); } if (!AllAssets.ContainsKey(item)) { AllAssets.Add(item, bundleName); } } }
public ActionResult AddToCart(int Id, string Type) { Asset asset = new Asset(); if (Type == "2D") { asset = _context.Assets2D.FirstOrDefault(z => z.Id == Id); } if (Type == "3D") { asset = _context.Assets3D.FirstOrDefault(z => z.Id == Id); } if (Type == "Audio") { asset = _context.AssetsAudio.FirstOrDefault(z => z.Id == Id); } if (Type == "Tools") { asset = _context.AssetsTools.FirstOrDefault(z => z.Id == Id); } Item item = new Item(); item.assetId = asset.Id; item.assetType = asset.Type; item.name = asset.Name; int first = int.Parse(asset.imagesId.Split(',').First()); var photo = _photoContext.AssetsPhotos.FirstOrDefault(z => z.Id == first); item.image = photo.ImageData; item.price = asset.Price; item.isInCart = true; var claimsIdentity = User.Identity as ClaimsIdentity; if (claimsIdentity != null) { // the principal identity is a claims identity. // now we need to find the NameIdentifier claim var userIdClaim = claimsIdentity.Claims .FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier); if (userIdClaim != null) { var userIdValue = userIdClaim.Value; item.buyerId = userIdValue; } } _itemContext.Assets.Add(item); _itemContext.SaveChanges(); AllAssets allAssets = new AllAssets(); allAssets.assets2D = _context.Assets2D.ToList(); allAssets.assets3D = _context.Assets3D.ToList(); allAssets.assetsAudio = _context.AssetsAudio.ToList(); allAssets.assetsTools = _context.AssetsTools.ToList(); return(RedirectToAction("Index", allAssets)); }
public static void BuildDLCConfig(DLCItem dlc) { //清除缓存 PackedAssets_Internal.Clear(); PackedAssets_Native.Clear(); PackedAssets_DLC.Clear(); Builds.Clear(); Rules.Clear(); AllDependencies.Clear(); AllAssets.Clear(); AllBundles.Clear(); AllSharedBundles.Clear(); Consts.Clear(); //永远提前打包Internal if (!dlc.IsInternal) { BuildDLCConfigInternal(Internal); } //如果不是NativeDLC则先BuildNativeDLC,防止资源被其他DLC重复打包 if (!dlc.IsInternal && !dlc.IsNative) { BuildDLCConfigInternal(Native); } BuildDLCConfigInternal(dlc); }
private static void AddToAllAssets(string item, Tuple <string, string> bundleName) { if (!AllAssets.ContainsKey(item)) { AllAssets.Add(item, bundleName.Item2); } }
/// <summary> /// 活的构建的数据 /// </summary> /// <param name="manifestPath"></param> /// <returns></returns> private static List <AssetBundleBuild> GenerateAssetBundleBuildData(DLCItem dlc) { if (dlc.IsInternal) { PackedAssets_Internal.Clear(); } else if (dlc.IsNative) { PackedAssets_Native.Clear(); } PackedAssets_DLC.Clear(); Builds.Clear(); Rules.Clear(); AllDependencies.Clear(); AllAssets.Clear(); AllBundles.Clear(); AllSharedBundles.Clear(); //建立其他文件 List <BuildRuleConfig> tempBuildDatas = dlc.BuildRuleData; if (tempBuildDatas == null && tempBuildDatas.Count == 0) { CLog.Error("没有配置相关的AssetBundle信息"); return(null); } foreach (var item in tempBuildDatas) { BuildRule buildRule = null; if (item.BuildRuleType == BuildRuleType.Directroy) { buildRule = new BuildAssetsWithDirectroy(dlc, item); } else if (item.BuildRuleType == BuildRuleType.FullPath) { buildRule = new BuildAssetsWithPath(dlc, item); } else if (item.BuildRuleType == BuildRuleType.File) { buildRule = new BuildAssetsWithFile(dlc, item); } Rules.Add(buildRule); } //搜集依赖的资源 foreach (var item in Rules) { CollectDependencies(item.Config.FullSearchPath); } //打包共享的资源 BuildSharedAssets(dlc); foreach (var item in Rules) { item.Build(); } EditorUtility.ClearProgressBar(); return(Builds); }
static void BuildManifestInternel(DLCItem dlcItem) { var builds = AssetBundleBuildsCache = BuildBuildRules(dlcItem); string dlcName = dlcItem.Name; string manifestPath = DLCAssetMgr.GetDLCManifestPath(dlcName); string dlcItemPath = DLCAssetMgr.GetDLCItemPath(dlcName); List <string> bundles = new List <string>(); List <string> assets = new List <string>(); if (builds.Count > 0) { foreach (var item in builds) { bundles.Add(item.assetBundleName); foreach (var assetPath in item.assetNames) { assets.Add(assetPath + ":" + (bundles.Count - 1)); } } } #region 创建Manifest文件 if (File.Exists(manifestPath)) { File.Delete(manifestPath); } DLCManifest dlcManifest = new DLCManifest(); foreach (var item in builds) { BundleData tempData = new BundleData(); tempData.DLCName = dlcItem.Name; tempData.BundleName = item.assetBundleName; foreach (var asset in item.assetNames) { AssetPathData pathData = new AssetPathData(); pathData.FullPath = asset; pathData.FileName = Path.GetFileNameWithoutExtension(asset); if (AllAssets.ContainsKey(asset)) { pathData.SourceBundleName = AllAssets[asset]; } tempData.AssetFullPaths.Add(pathData); } dlcManifest.Data.Add(tempData); } BaseFileUtils.SaveJson(manifestPath, dlcManifest, true); #endregion #region dlcitem if (File.Exists(dlcItemPath)) { File.Delete(dlcItemPath); } BaseFileUtils.SaveJson(dlcItemPath, dlcItem, true); #endregion CLog.Debug("[BuildScript] BuildManifest with " + assets.Count + " assets and " + bundles.Count + " bundels."); }
public void add_cdn_that_does_not_match() { var asset = AllAssets.RegisterCdnAsset(new CdnAsset { Url = "http://cdn.server.com/jquery.js" }); asset.CdnUrl.ShouldEqual("http://cdn.server.com/jquery.js"); asset.FallbackTest.ShouldBeNull(); asset.File.ShouldBeNull(); }
/// <summary> /// Returns list of AssetViewModels by category that exist in <see cref="AllAssets"/> /// </summary> private IEnumerable <AssetViewModel> GetAssetsByCategory(AssetCategory cat) { IEnumerable <AssetViewModel> assetsInCategory = new List <AssetViewModel>(); lock (allListLock) { assetsInCategory = AllAssets.Where(a => a.AssetCategory == cat.Value); } return(assetsInCategory); }
public void cdn_registration_with_file_name() { var cdn = new CdnAsset { File = "fubar.1.2.js", Url = "http://server/fubar.js" }; var asset = AllAssets.RegisterCdnAsset(cdn); asset.Filename.ShouldEqual("fubar.1.2.js"); asset.File.ShouldNotBeNull(); // just seeing that we match up on existing asset.CdnUrl.ShouldEqual("http://server/fubar.js"); asset.Url.ShouldEqual("fubar.1.2.js"); }
public void add_cdn_that_does_match() { var cdn = new CdnAsset { Url = "http://cdn.server.com/foo.js", Fallback = "something == null" }; var asset = AllAssets.RegisterCdnAsset(cdn); asset.File.ShouldNotBeNull(); asset.FallbackTest.ShouldEqual("something == null"); asset.CdnUrl.ShouldEqual("http://cdn.server.com/foo.js"); }
public void Cleanup(Workitem item) { if (item.Parent != null && AllAssets.Contains(item.Parent.Asset)) { item.Parent.Asset.Children.Remove(item.Asset); } AllAssets.Remove(item.Asset); Efforts.Remove(item.Asset); foreach (var child in item.Asset.Children) { Efforts.Remove(child); } }
private void RootAssetsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { // Replicate changes switch (e.Action) { case NotifyCollectionChangedAction.Add: foreach (var newItem in e.NewItems.Cast <AssetViewModel>()) { // Shouldn't happen, but make sure an item with same id is not already added Package.RootAssets.Remove(newItem.Id); Package.RootAssets.Add(new AssetReference(newItem.Id, newItem.Url)); Package.IsDirty = true; newItem.Dependencies.NotifyRootAssetChange(true); } break; case NotifyCollectionChangedAction.Remove: foreach (var oldItem in e.OldItems.Cast <AssetViewModel>()) { Package.RootAssets.Remove(oldItem.Id); Package.IsDirty = true; oldItem.Dependencies.NotifyRootAssetChange(true); } break; case NotifyCollectionChangedAction.Replace: case NotifyCollectionChangedAction.Move: case NotifyCollectionChangedAction.Reset: // Let's do a full resync Package.RootAssets.Clear(); Package.RootAssets.AddRange(RootAssets.Select(x => new AssetReference(x.Id, x.Url))); AllAssets.ForEach(x => { x.Dependencies.NotifyRootAssetChange(false); }); break; default: throw new ArgumentOutOfRangeException(); } Session.SelectionIsRoot = Session.ActiveAssetView.SelectedAssets.All(x => x.Dependencies.IsRoot); }
private void DownloadAllPreviewImagesAsync() { Task t = Task.Factory.StartNew(() => { CreateRequiredFolders(); foreach (AssetViewModel asset in AllAssets.ToList()) { string pathToThumbnail = Path.Combine(AbsolutePathToThumbnails, asset.Asset.IDWithoutExtension); if (ImageCache.IsOutOfDate(pathToThumbnail) || ImageCache.IsSourceUrlDifferent(pathToThumbnail, asset.Asset.PreviewImage)) { ImageCache.AddOrUpdate(pathToThumbnail, asset.Asset.PreviewImage); Guid downloadId = Guid.NewGuid(); Action onCancel = () => { RemoveFromDownloads(downloadId); }; Action onError = () => { RemoveFromDownloads(downloadId); }; Action onComplete = () => { RemoveFromDownloads(downloadId); }; string formattedUrl = "rsmm://Url/" + asset.Asset.PreviewImage.Replace("://", "$"); DownloadItemViewModel downloadItem = new DownloadItemViewModel() { UniqueId = downloadId, DownloadType = DownloadType.Image, ItemName = "Downloading preview image", DownloadUrl = formattedUrl, SaveFilePath = pathToThumbnail, OnCancel = onCancel, OnComplete = onComplete, OnError = onError }; AddToDownloads(downloadItem); } } }); }
/// <summary> /// Updates <see cref="AuthorList"/> with distinct sorted list of authors in <see cref="AllAssets"/> /// </summary> private void RefreshAuthorList() { List <AuthorDropdownViewModel> newAuthorList = new List <AuthorDropdownViewModel>(); // use GroupBy to get count of assets per author foreach (IGrouping <string, AssetViewModel> author in AllAssets.GroupBy(a => a.Author)) { newAuthorList.Add(new AuthorDropdownViewModel(author.Key, author.Count())); } newAuthorList = newAuthorList.OrderBy(a => a.Author).ToList(); newAuthorList.Insert(0, new AuthorDropdownViewModel(defaultAuthorValue, 0)); AuthorList = newAuthorList; //clear selection if selected author not in list if (AuthorList.Any(a => a.Author == AuthorToFilterBy.Author) == false) { AuthorToFilterBy = AuthorList[0]; } }
static void BuildDLCConfigInternal(DLCItem dlcItem) { var builds = AssetBundleBuildsCache = GenerateAssetBundleBuildData(dlcItem); string constPath = dlcItem.GetConst(); string manifestPath = dlcItem.GetManifest(); string dlcItemPath = dlcItem.GetConfig(); List <string> bundles = new List <string>(); List <string> assets = new List <string>(); if (builds.Count > 0) { foreach (var item in builds) { bundles.Add(item.assetBundleName); foreach (var assetPath in item.assetNames) { assets.Add(assetPath + ":" + (bundles.Count - 1)); } } } #region 创建Manifest文件 if (File.Exists(manifestPath)) { File.Delete(manifestPath); } DLCManifest dlcManifest = new DLCManifest(); foreach (var item in builds) { BundleData tempData = new BundleData(); tempData.DLCName = dlcItem.Name; if (AllBundles.ContainsKey(item.assetBundleName)) { tempData.BundleName = item.assetBundleName; if (AllSharedBundles.Contains(item.assetBundleName)) { tempData.IsShared = true; } } else { CLog.Error("没有包含:" + item.assetBundleName); } foreach (var asset in item.assetNames) { AssetPathData pathData = new AssetPathData(); pathData.FullPath = asset; pathData.FileName = Path.GetFileNameWithoutExtension(asset); if (AllAssets.ContainsKey(asset)) { pathData.SourceBundleName = AllAssets[asset]; } tempData.AssetFullPaths.Add(pathData); } dlcManifest.Data.Add(tempData); } FileUtil.SaveJson(manifestPath, dlcManifest, true); #endregion #region dlcitem if (File.Exists(dlcItemPath)) { File.Delete(dlcItemPath); } FileUtil.SaveJson(dlcItemPath, dlcItem.Config, true); #endregion #region const if (File.Exists(constPath)) { File.Delete(constPath); } var cultureInfo = new System.Globalization.CultureInfo("en-us"); var w = new CodegenTextWriter(constPath, System.Text.Encoding.UTF8); w.WithCurlyBraces("namespace CYM", () => { w.WithCurlyBraces("public partial class Const", () => { foreach (var bundleData in dlcManifest.Data) { string newBundleName = ""; foreach (var pathData in bundleData.AssetFullPaths) { if (pathData.SourceBundleName.IsInv()) { continue; } //跳过指定的Bundle资源 if (pathData.SourceBundleName == Const.BN_System || pathData.SourceBundleName == Const.BN_Shared) { continue; } //获得相应的Bundle名称 if (pathData.SourceBundleName.StartsWith(Const.BN_Scene)) { newBundleName = Const.BN_Scene; } else { newBundleName = pathData.SourceBundleName; } //保证变量名称有效 var fileName = pathData.FileName.Replace(".", "_").Replace("(", "_").Replace(")", "").Trim(); //加上前缀 fileName = newBundleName.ToUpper() + "_" + fileName; //忽略不需要的Const if (DLCConfig.IsInIgnoreConst(fileName)) { continue; } if (Consts.Contains(fileName)) { continue; } Consts.Add(fileName); w.WriteLine($"public const string {fileName} = \"{pathData.FileName}\";"); } } }); }); w.Flush(); w.Dispose(); #endregion CLog.Info("[Builder][{0}] BuildManifest with " + assets.Count + " assets and " + bundles.Count + " bundels.", dlcItem.Name); }
public ActionResult Publish(AssetImages model) { if (!ModelState.IsValid) { return(View("Publish", model)); } model.asset.Publisher = User.Identity.Name; model.asset.ReleaseDate = DateTime.Now.ToString(); if (!model.File.FileName.EndsWith("rar") && !model.File.FileName.EndsWith("zip")) { return(View("Publish", model)); } string[] formats = new string[] { ".jpg", ".png", ".jpeg" }; bool Wrong = true; foreach (var image in model.Files) { foreach (var item in formats) { if (image.FileName.Contains(item)) { Wrong = false; break; } } } if (Wrong) { return(View("Publish", model)); } foreach (var file in model.Files) { if (file == null) { //at least 1 photo per asset return(View(model)); } else if (file.ContentLength > 0) { Picture c = new Picture(); c.ImageData = new byte[file.ContentLength]; file.InputStream.Read(c.ImageData, 0, c.ImageData.Length); _photoContext.AssetsPhotos.Add(c); _photoContext.SaveChanges(); if (model.asset.imagesId == null) { model.asset.imagesId = c.Id.ToString(); } else { model.asset.imagesId += "," + c.Id.ToString(); } } } if (model.File.ContentLength > 0) { MemoryStream target = new MemoryStream(); model.File.InputStream.CopyTo(target); byte[] data = target.ToArray(); model.asset.assetZip = data; } model.asset.Size = model.asset.assetZip.Count() / 1048576f; ////// if (model.asset.Type == "2D") { Asset2D asset2D = new Asset2D(model.asset); _context.Assets2D.Add(asset2D); } else if (model.asset.Type == "3D") { Asset3D asset3D = new Asset3D(model.asset); _context.Assets3D.Add(asset3D); } else if (model.asset.Type == "Audio") { AssetAudio assetAudio = new AssetAudio(model.asset); _context.AssetsAudio.Add(assetAudio); } else if (model.asset.Type == "Tools") { AssetTools assetTools = new AssetTools(model.asset); _context.AssetsTools.Add(assetTools); } else { return(HttpNotFound()); } try { _context.SaveChanges(); } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Debug.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Debug.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } Debug.WriteLine(model.asset.Type); } AllAssets allAssets = new AllAssets(); allAssets.assets2D = _context.Assets2D.ToList(); allAssets.assets3D = _context.Assets3D.ToList(); allAssets.assetsAudio = _context.AssetsAudio.ToList(); allAssets.assetsTools = _context.AssetsTools.ToList(); return(RedirectToAction("Index", allAssets)); }
public void alias_is_not_found_sad_path() { Exception <ArgumentOutOfRangeException> .ShouldBeThrownBy(() => { AllAssets.As <AssetGraph>().StoreAlias("bar", "nonexistent.js"); }).Message.ShouldContain("No asset file named 'nonexistent.js' can be found"); }
public ActionResult Index(string search) { AllAssets all = new AllAssets(); if (search != null) { if (search.ToLower().Contains("2d")) { all.assets2D = _context.Assets2D.ToList(); } if (search.ToLower().Contains("3d")) { all.assets3D = _context.Assets3D.ToList(); } if (search.ToLower().Contains("tools")) { all.assetsTools = _context.AssetsTools.ToList(); } if (search.ToLower().Contains("audio")) { all.assetsAudio = _context.AssetsAudio.ToList(); } if (search.ToLower().Contains("free")) { all.assets2D = _context.Assets2D.Where(z => z.Price == 0).ToList(); all.assets3D = _context.Assets3D.Where(z => z.Price == 0).ToList(); all.assetsAudio = _context.AssetsAudio.Where(z => z.Price == 0).ToList(); all.assetsTools = _context.AssetsTools.Where(z => z.Price == 0).ToList(); } if (_context.Assets2D != null) { foreach (var item in _context.Assets2D) { if (item.Name.Contains(search) && !all.assets2D.Contains(item)) { all.assets2D.Add(item); } } } if (_context.Assets3D != null) { foreach (var item in _context.Assets3D) { if (item.Name.Contains(search) && !all.assets3D.Contains(item)) { all.assets3D.Add(item); } } } if (_context.AssetsTools != null) { foreach (var item in _context.AssetsTools) { if (item.Name.Contains(search) && !all.assetsTools.Contains(item)) { all.assetsTools.Add(item); } } } if (_context.AssetsAudio != null) { foreach (var item in _context.AssetsAudio) { if (item.Name.Contains(search) && !all.assetsAudio.Contains(item)) { all.assetsAudio.Add(item); } } } } else { all.assets2D = _context.Assets2D.ToList(); all.assets3D = _context.Assets3D.ToList(); all.assetsTools = _context.AssetsTools.ToList(); all.assetsAudio = _context.AssetsAudio.ToList(); } if (all.assets2D != null) { foreach (Asset2D model in all.assets2D) { if (model.imagesId != null) { int elem = int.Parse(model.imagesId.Split(',').First()); var photo = _photoContext.AssetsPhotos.FirstOrDefault(z => z.Id == elem); all.asset2dImages.Add(photo.ImageData); } } } if (all.assets3D != null) { foreach (Asset3D model in all.assets3D) { if (model.imagesId != null) { int elem = int.Parse(model.imagesId.Split(',').First()); var photo = _photoContext.AssetsPhotos.FirstOrDefault(z => z.Id == elem); all.asset3dImages.Add(photo.ImageData); } } } if (all.assetsAudio != null) { foreach (AssetAudio model in all.assetsAudio) { if (model.imagesId != null) { int elem = int.Parse(model.imagesId.Split(',').First()); var photo = _photoContext.AssetsPhotos.FirstOrDefault(z => z.Id == elem); all.assetAudioImages.Add(photo.ImageData); } } } if (all.assetsTools != null) { foreach (AssetTools model in all.assetsTools) { if (model.imagesId != null) { int elem = int.Parse(model.imagesId.Split(',').First()); var photo = _photoContext.AssetsPhotos.FirstOrDefault(z => z.Id == elem); all.assetsToolsImages.Add(photo.ImageData); } } } return(View(all)); }
public void Add(Workitem item) { AllAssets.Add(item.Asset); }
public void AddAssetImage(AssetImage assetImg) { AllAssets.Add(assetImg); AssetImages.Add(assetImg); }
public void AddAssetObject(AssetObject assetObj) { AllAssets.Add(assetObj); AssetObjects.Add(assetObj); }
public IList <Workitem> GetWorkitems(bool showAll) { return(AllAssets.Where(asset => showAll || dataLayer.AssetPassesShowMyTasksFilter(asset)) .Select(asset => WorkitemFactory.CreateWorkitem(asset, null, this)) .ToList()); }