示例#1
0
 public HtmlString RenderScript(ScriptLocation location)
 {
   var sb = new StringBuilder();
   var assets = AssetRepository.Current.Items.Where(asset => (asset.Type == AssetType.JavaScript || asset.Type == AssetType.Raw) && asset.Location == location && this.IsForContextSite(asset));
   foreach (var item in assets)
   {
     if (!string.IsNullOrEmpty(item.File))
     {
       sb.AppendFormat("<script src=\"{0}\"></script>", item.File).AppendLine();
     }
     else if (!string.IsNullOrEmpty(item.Inline))
     {
       if (item.Type == AssetType.Raw)
       {
         sb.AppendLine(HttpUtility.HtmlDecode(item.Inline));
       }
       else
       {
         sb.AppendLine("<script>\njQuery(document).ready(function() {");
         sb.AppendLine(item.Inline);
         sb.AppendLine("});\n</script>");
       }
     }
   }
   return new HtmlString(sb.ToString());
 }
示例#2
0
 public Asset(AssetType type, string file, ScriptLocation location = ScriptLocation.Body, string inline = null, string addOnceToken = null)
 {
     this.Type = type;
       this.File = file;
       this.Location = location;
       this.Inline = inline;
       this.AddOnceToken = addOnceToken;
 }
示例#3
0
文件: Asset.cs 项目: Sitecore/Habitat
 public Asset(AssetType type, ScriptLocation location, string file = null, string inline = null, string site = null)
 {
   this.Type = type;
   this.File = file;
   this.Location = location;
   this.Inline = inline;
   if (!string.IsNullOrEmpty(inline))
   {
     this.AddOnceToken = inline.GetHashCode().ToString();
   }
   this.Site = site;
 }
示例#4
0
 public void AddScript(string script, string addOnceToken, ScriptLocation location, bool preventAddToCache = false)
 {
     this.Add(new Asset(AssetType.JavaScript, null, location, script, script.GetHashCode().ToString()), preventAddToCache);
 }
示例#5
0
        /// <summary>
        ///     This event occurs when a terminating execption is thrown from the 
        ///     PowerShell debugger.
        /// </summary>
        /// <remarks>
        ///     This event triggers a Visual Studio Excecption event so that 
        ///     Visual Studio displays the exception window accordingly. 
        /// </remarks>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void Debugger_TerminatingException(object sender, EventArgs<Exception> e)
        {
            if (e.Value is RuntimeException)
            {
                var re = e.Value as RuntimeException;
                var scriptLocation = new ScriptLocation();
                scriptLocation.Column = 0;
                scriptLocation.File = re.ErrorRecord.InvocationInfo.ScriptName;
                scriptLocation.Line = re.ErrorRecord.InvocationInfo.ScriptLineNumber;

                //_events.Break(_node);
            }

            _events.Exception(_node, e.Value);
        }
示例#6
0
 public void AddScript(string script, string addOnceToken, ScriptLocation location, bool preventAddToCache = false)
 {
   this.Add(new Asset(AssetType.JavaScript, location, inline:script), preventAddToCache);
 }
示例#7
0
 public Asset AddInlineScript(string script, ScriptLocation location, bool preventAddToCache)
 {
     return(this.AddAsset(script, location, preventAddToCache, AssetType.JavaScript, AssetContentType.Inline));
 }
示例#8
0
 public Asset AddScriptFile(string file, ScriptLocation location, bool preventAddToCache = false)
 {
     return(this.AddAsset(file, location, preventAddToCache, AssetType.JavaScript, AssetContentType.File));
 }
示例#9
0
 public void AddScript(string script, string addOnceToken, ScriptLocation location, bool preventAddToCache = false)
 {
     this.Add(new Asset(AssetType.JavaScript, null, location, script, script.GetHashCode().ToString()), preventAddToCache);
 }
示例#10
0
        ///////////////////////////////////////////////////////////////////////

        public ReturnCode MatchBreakpoint(
            Interpreter interpreter,
            IScriptLocation location,
            ref bool match,
            ref Result error
            )
        {
            CheckDisposed();

            if (location != null)
            {
                if (ScriptLocation.Check(interpreter, location, false))
                {
                    string fileName = location.FileName;

                    if (fileName != null)
                    {
                        fileName = ScriptLocation.NormalizeFileName(
                            interpreter, fileName);
                    }

                    //
                    // NOTE: *WARNING: Empty file names are allowed here, please
                    //       do not change this to !String.IsNullOrEmpty.
                    //
                    if (fileName != null)
                    {
                        BreakpointDictionary breakpoints = Breakpoints;

                        if (breakpoints != null)
                        {
                            ScriptLocationIntDictionary scriptLocations;

                            if (breakpoints.TryGetValue(
                                    interpreter, fileName,
                                    out scriptLocations))
                            {
                                return(scriptLocations.Match(
                                           interpreter, location, ref match,
                                           ref error));
                            }
                            else
                            {
                                //
                                // NOTE: It was not found.
                                //
                                match = false;
                                return(ReturnCode.Ok);
                            }
                        }
                        else
                        {
                            error = "breakpoints not available";
                        }
                    }
                    else
                    {
                        error = "invalid script location file name";
                    }
                }
                else
                {
                    error = "bad script location";
                }
            }
            else
            {
                error = "invalid script location";
            }

            return(ReturnCode.Error);
        }
示例#11
0
 public void AddScript(string script, string addOnceToken, ScriptLocation location, bool preventAddToCache = false)
 {
     this.Add(new Asset(AssetType.JavaScript, location, inline: script), preventAddToCache);
 }
示例#12
0
 /// <summary>
 /// Initializes a new instance of Token
 /// </summary>
 /// <param name="tokenID">The token's ID</param>
 /// <param name="value">The value of this token</param>
 /// <param name="start">The starting position of the token in the source code</param>
 /// <param name="end">The ending position of the token in the source code</param>
 public Token(TokenID tokenID, object value, ScriptLocation start, ScriptLocation end)
     : base(start, end)
 {
     TokenID = tokenID;
     Value   = value;
 }
示例#13
0
        private Asset AddAsset(string content, ScriptLocation location, bool preventAddToCache, AssetType assetType, AssetContentType contentType, string site = null)
        {
            var asset = this.CreateAsset(content, location, assetType, contentType, site);

            return(asset == null ? null : this.Add(asset, preventAddToCache));
        }
示例#14
0
        private void ApplyScriptsToDatabaseRecursiveDirectoryWalk(SchemaVersion currentVersion, ScriptLocation location, string currentDirectoryPath)
        {
            foreach (var scriptFile in location.ScriptFiles.OrderBy(s => s))
            {
                var scriptNameToBeLogged = scriptFile.Replace(location.AbsolutePath, string.Empty);

                if (!location.RunOnce) //Can be run many times
                {
                    TraceHelper.Info("Applying Script '{0}'", scriptNameToBeLogged);

                    var scripts = IOManager.ReadSqlScripts(scriptFile);

                    var hash = IOManager.GetFileMD5Hash(scriptFile);

                    SqlManager.ExecuteScriptFile(scripts, scriptNameToBeLogged, hash, currentVersion);
                }
                else
                {
                    TraceHelper.Info("Applying Script '{0}'", scriptNameToBeLogged);

                    var scripts = IOManager.ReadSqlScripts(scriptFile);

                    var hash = IOManager.GetFileMD5Hash(scriptFile);

                    SqlManager.ExecuteScriptFile(scripts, scriptNameToBeLogged, hash, currentVersion);
                }
            }


            //foreach file in the location
            // is directory marked as "runOnce"
            //if yes
            //check if file applied before in a previous version.
            //if no
            // Apply that file & log it
            //if yes
            //skip it
            //if not
            //run that file regardless

            /*
             * if (!location.Recursive) return;
             * //foreach directory in the location
             * foreach(var subDirectoryPath in Directory.GetDirectories(currentDirectoryPath))
             * {
             *  // Recursively repeat.
             *  ApplyScriptsToDatabaseRecursiveDirectoryWalk(currentVersion, location, subDirectoryPath);
             * }
             */
        }
示例#15
0
 public ParseTimeLabel(string name, ScriptLocation start, ScriptLocation end)
 {
     Name  = name;
     Start = start;
     End   = end;
 }