Exemplo n.º 1
0
        public GenerateResult Generate(string resourcePath, AssetMapper mapper)
        {
            string[] temp         = resourcePath.Split(',');
            string   typeName     = temp[0];
            string   assemblyName = temp[1];
            var      token        = GetToken(assemblyName); //由于组件的短名称可能重复,所以需要完整的名称(程序集.短名称),所以我们需要对程序集编码,在url路径中不暴露程序集的名称

            var localTypeName = typeName.Substring(assemblyName.Length + 1);
            var assetName     = mapper.GetAssetName(localTypeName);

            StringBuilder vp = new StringBuilder(localTypeName.Substring(0, localTypeName.Length - assetName.Length));

            vp = vp.Replace(assemblyName, string.Empty);
            vp = vp.Replace(".", "/");
            vp.Append(assetName);
            var localVirtualPath = vp.ToString();

            localVirtualPath = mapper.MapPath(localVirtualPath);
            var virtualPath  = string.Format("/assets/{0}/{1}", token, localVirtualPath);
            var physicalPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, virtualPath.Replace('/', '\\').Substring(1));

#if DEBUG
            WriteBytes(physicalPath, resourcePath);
#endif

#if !DEBUG
            if (!File.Exists(physicalPath))
            {
                WriteBytes(physicalPath, resourcePath);
            }
#endif
            return(new GenerateResult(virtualPath, localVirtualPath));
        }
Exemplo n.º 2
0
        ///// <summary>
        ///// 本地虚拟路径
        ///// </summary>
        //public string LocalVirtualPath
        //{
        //    get;
        //    private set;
        //}

        /// <summary>
        /// 生成文件
        /// </summary>
        /// <param name="assemblyName"></param>
        internal void Generate(string assemblyName, AssetMapper mapper)
        {
            //文件的程序集路径
            var assemblyPath = this.Path.TrimStart('/').Replace('/', '.');
            var resourcePath = string.Format("{0}.{1},{0}", assemblyName, assemblyPath);
            var result       = AssetGenerator.Instance.Generate(resourcePath, mapper);

            this.VirtualPath = result.VirtualPath;
            //this.LocalVirtualPath = result.LocalVirtualPath.Substring(parentPath.Length);
            //if (string.IsNullOrEmpty(this.Key)) //如果没有设置文件的键值,那么键值就为本地虚拟路径的值
            //    this.Key = this.LocalVirtualPath;
        }
Exemplo n.º 3
0
        internal void Generate(string assemblyName, AssetMapper mapper)
        {
            var resuorcePath = mapper.MapPath(this.Path);

            if (!resuorcePath.EndsWith("/"))
            {
                resuorcePath += "/";                               //该代码主要是为了路径匹配时使用,避免文件名和路径名匹配导致的BUG
            }
            var resourceNames = _getResourceNames(assemblyName);

            List <AssetFile> files = new List <AssetFile>();

            foreach (var resourceName in resourceNames)
            {
                //资源程序集形式的路径
                var assemblyPath = resourceName.Substring(assemblyName.Length + 1);
                var assetName    = mapper.GetAssetName(assemblyPath);

                string path = "/";
                if (assetName == assemblyPath)
                {
                    path += assetName;
                }
                else
                {
                    var temp = assemblyPath.Substring(0, assemblyPath.Length - assetName.Length);
                    path += temp.Replace('.', '/') + assetName;
                }

                if (path.StartsWith(resuorcePath))
                {
                    AssetFile file = new AssetFile();
                    file.Path = path;
                    file.Generate(assemblyName, mapper);
                    files.Add(file);
                }
            }

            this.Files = files.ToArray();
        }