Exemple #1
0
        private IncludeInfo AnalyzeIncludeInfoString(string includeValue)
        {
            if (includeValue == null)
            {
                return(null);
            }

            string[] parts = includeValue.Split(',');
            if (parts.Length == 1)
            {
                return(new IncludeInfo
                {
                    Name = includeValue.Trim()
                });
            }
            else
            {
                var info = new IncludeInfo
                {
                    Name = parts[0].Trim()
                };

                // ... version


                return(info);
            }
        }
        /// <summary>
        /// Starts an asynchronous operation to get include info.
        /// </summary>
        /// <param name="domainName"></param>
        /// <param name="callback"></param>
        /// <param name="userState"></param>
        /// <returns></returns>
        public static IAsyncResult BeginGetIncludeInfo(string domainName, AsyncCallback callback, object userState)
        {
            HttpWebRequest request = CreateNormalRequest(GetIncludeInfoQueryUri(domainName));
            AsyncResult <IHaosouIncludeInfo> result = new AsyncResult <IHaosouIncludeInfo>(callback, userState);

            NetworkRequestAsyncTimeout.RegisterRequest(request.BeginGetResponse((ar) => {
                IHaosouIncludeInfo info = null;
                Exception error         = null;
                byte[] buffer           = g_bufferManager.TakeBuffer(BUFFER_SIZE);

                try {
                    string content = null;
                    using (HttpWebResponse response = (HttpWebResponse)((HttpWebRequest)ar.AsyncState).EndGetResponse(ar)) {
                        content = response.GetResponseString(buffer);
                    }

                    info = new IncludeInfo {
                        IncludeCount = ParseIncludeCount(content),
                    };
                } catch (Exception ex) {
                    error = ex;
                } finally {
                    g_bufferManager.ReturnBuffer(buffer);
                }

                result.MarkCompleted(error, false, info);
            }, request), request, TIMEOUT);

            return(result);
        }
        private static ISougouIncludeInfo ParseIncludeInfo(string content)
        {
            IncludeInfo info = new IncludeInfo();

            if (string.IsNullOrWhiteSpace(content))
            {
                return(info);
            }

            Match[] matches = g_includeCountRegex1.Matches(content).Cast <Match>().ToArray();
            if (matches.Length > 0)
            {
                info.IndexCount = int.Parse(g_includeCountRegex2.Match(matches[0].Groups[1].Value).Value, NumberStyles.AllowThousands);
                if (matches.Length > 1)
                {
                    info.IncludeCount = int.Parse(g_includeCountRegex2.Match(matches[1].Groups[1].Value).Value, NumberStyles.AllowThousands);
                }
                else
                {
                    info.IncludeCount = info.IndexCount;
                }
            }

            return(info);
        }
        /// <summary>
        /// Return the contents of an include file.
        /// </summary>
        /// <param name="includeInfo"></param>
        /// <returns></returns>
        private IEnumerable <string> FetchIncludeContents(IncludeInfo includeInfo)
        {
            // Find the include file
            var f = FindIncludeFile(includeInfo.includeName);

            if (f == null)
            {
                yield return("# *** Unable to find include file in svn!");
            }
            else
            {
                foreach (var l in GetSvnFileLines(f))
                {
                    yield return(l);
                }
            }
        }
        /// <summary>
        /// Reads data for this dependency cache from disk
        /// </summary>
        private void Read()
        {
            try
            {
                using (BinaryArchiveReader Reader = new BinaryArchiveReader(Location))
                {
                    int Version = Reader.ReadInt();
                    if (Version != CurrentVersion)
                    {
                        Log.TraceLog("Unable to read dependency cache from {0}; version {1} vs current {2}", Location, Version, CurrentVersion);
                        return;
                    }

                    int FileToFirstIncludeCount = Reader.ReadInt();
                    for (int Idx = 0; Idx < FileToFirstIncludeCount; Idx++)
                    {
                        FileItem File = Reader.ReadCompactFileItem();

                        IncludeInfo IncludeInfo = new IncludeInfo();
                        IncludeInfo.LastWriteTimeUtc = Reader.ReadLong();
                        IncludeInfo.IncludeText      = Reader.ReadString();

                        FileToIncludeInfo[File] = IncludeInfo;
                    }

                    int FileToMarkupFlagCount = Reader.ReadInt();
                    for (int Idx = 0; Idx < FileToMarkupFlagCount; Idx++)
                    {
                        FileItem File = Reader.ReadCompactFileItem();

                        ReflectionInfo ReflectionInfo = new ReflectionInfo();
                        ReflectionInfo.LastWriteTimeUtc = Reader.ReadLong();
                        ReflectionInfo.bContainsMarkup  = Reader.ReadBool();

                        FileToReflectionInfo[File] = ReflectionInfo;
                    }
                }
            }
            catch (Exception Ex)
            {
                Log.TraceWarning("Unable to read {0}. See log for additional information.", Location);
                Log.TraceLog("{0}", ExceptionUtils.FormatExceptionDetails(Ex));
            }
        }
 /// <summary>
 /// Gets the first included file from a source file
 /// </summary>
 /// <param name="SourceFile">The source file to parse</param>
 /// <returns>Text from the first include directive. Null if the file did not contain any include directives.</returns>
 public string GetFirstInclude(FileItem SourceFile)
 {
     if (Parent != null && !SourceFile.Location.IsUnderDirectory(BaseDirectory))
     {
         return(Parent.GetFirstInclude(SourceFile));
     }
     else
     {
         IncludeInfo IncludeInfo;
         if (!FileToIncludeInfo.TryGetValue(SourceFile, out IncludeInfo) || SourceFile.LastWriteTimeUtc.Ticks > IncludeInfo.LastWriteTimeUtc)
         {
             IncludeInfo = new IncludeInfo();
             IncludeInfo.LastWriteTimeUtc  = SourceFile.LastWriteTimeUtc.Ticks;
             IncludeInfo.IncludeText       = ParseFirstInclude(SourceFile.Location);
             FileToIncludeInfo[SourceFile] = IncludeInfo;
             bModified = true;
         }
         return(IncludeInfo.IncludeText);
     }
 }
 public void SetExtraIncludeInfo(IncludeInfo extraIncludeInfo)
 {
     this._extraIncludeInfo = extraIncludeInfo;
 }
Exemple #8
0
        private static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            PreProcessorInclude include = new PreProcessorInclude();
            int startIndex = parentInfo.CurrentIndex;

            MoveInfo moveInfo = new MoveInfo(parentInfo);

            moveInfo.Move(SearchDirection.LeftToRight); // "include"
            moveInfo.Move(SearchDirection.LeftToRight); // after "include"
            moveInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible);

            Path path = Path.Parse(moveInfo, parsingInfo, scriptInfo);

            if (path == null)
            {
                throw new SyntaxException("Bad path", parentInfo.GetErrorInfo());
            }

            include.Path = path;

            moveInfo.Move(SearchDirection.LeftToRight);
            IElement terminal = moveInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible);

            if (terminal == null || !terminal.IsTT(TokenType.SemiColon))
            {
                throw new SyntaxException("Could not find ;", parentInfo.GetErrorInfo());
            }


            int             length   = (moveInfo.CurrentIndex + 1) - startIndex;
            List <IElement> children = parentInfo.CurrentElements.GetRange(startIndex, length);

            include.AddChildren(children);
            parentInfo.Replace(length, include);

            // include file
            string SFPath = path.ToString();

            if (scriptInfo.Includes.Find(a => a.SFPath.EqualCode(SFPath)) != null)
            {
                scriptInfo.SF.Errors.Add(
                    new SemanticError("File '" + SFPath + "' already included",
                                      parentInfo.GetErrorInfo(include)));
            }

            ScriptFile includeFile = scriptInfo.SF.Manager.GetSF(SFPath);

            if (includeFile != null)
            {
                IncludeInfo includeInfo = new IncludeInfo(includeFile);
                scriptInfo.AddInclude(includeInfo);

                parsingInfo.IncludeDefList.Add(include);
            }
            else
            {
                scriptInfo.SF.Errors.Add(
                    new SemanticError("Could not include file '" + SFPath + "'",
                                      parentInfo.GetErrorInfo(include)));
            }
        }
 /// <summary>
 /// Return the contents of an include file.
 /// </summary>
 /// <param name="includeInfo"></param>
 /// <returns></returns>
 private IEnumerable<string> FetchIncludeContents(IncludeInfo includeInfo)
 {
     // Find the include file
     var f = FindIncludeFile(includeInfo.includeName);
     if (f == null)
     {
         yield return "# *** Unable to find include file in svn!";
     } else
     {
         foreach (var l in GetSvnFileLines(f))
         {
             yield return l;
         }
     }
 }