internal static IEnumerable <ScriptReference> GetScriptReferences(Type controlType, string scriptPath)
        {
            List <ScriptReference> refs = new List <ScriptReference>();

            refs.AddRange(ScriptObjectBuilder.GetScriptReferences(controlType));

            if (scriptPath.Length > 0)
            {
                refs.Add(new ScriptReference(scriptPath));
            }

            lock (controlType)
            {
                if (ScriptControlSection.GetSection().UseScriptReferencesInAssembly == false)
                {
                    refs = ConvertScriptReferenceToLocalScript(refs);
                }

                foreach (ScriptReference sr in refs)
                {
                    if (sr.Path.IndexOf("ClientScriptCacheability.None") == 0)
                    {
                        sr.Path = string.Empty;
                    }
                }
            }

            return(refs);
        }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public ScriptReference ToScriptReference()
        {
            ScriptReference refr = new ScriptReference();

            refr.Assembly = ComponentType.Assembly.FullName;
            refr.Name     = ResourcePath;

            if (Cacheability == ClientScriptCacheability.None && ScriptControlSection.GetSection().UseScriptReferencesInAssembly == false)
            {
                refr.Path = "ClientScriptCacheability.None" + refr.Name;
            }

            return(refr);
        }
        private static ScriptReference ConvertOneScriptToLocalScript(ScriptReference originalScript)
        {
            ScriptReference result = originalScript;

            if (string.IsNullOrEmpty(originalScript.Assembly) == false)
            {
                Assembly assembly = Assembly.Load(originalScript.Assembly);

                byte[] buffer = new byte[4096];

                string targetVFilePath = ScriptControlSection.GetSection().LocalScriptVirtualDir;

                targetVFilePath = Path.Combine(targetVFilePath, originalScript.Name);
                targetVFilePath = targetVFilePath.Replace('\\', '/');

                string targetFilePath = HttpContext.Current.Server.MapPath(targetVFilePath);

                string targetDir = Path.GetDirectoryName(targetFilePath);

                if (Directory.Exists(targetDir) == false)
                {
                    Directory.CreateDirectory(targetDir);
                }

                if (FileTimeMatched(assembly.Location, targetFilePath) == false)
                {
                    lock (typeof(ScriptControlHelper))
                    {
                        using (Stream stream = assembly.GetManifestResourceStream(originalScript.Name))
                        {
                            using (FileStream fs = new FileStream(targetFilePath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite))
                            {
                                stream.CopyTo(fs);
                            }

                            File.SetLastWriteTime(targetFilePath, File.GetLastAccessTime(assembly.Location));
                        }
                    }
                }

                result      = new ScriptReference();
                result.Path = targetVFilePath;
            }

            return(result);
        }