Exemplo n.º 1
0
        public ErrorCodes.XMLParserError WriteContext(ExcludeContext context)
        {
            StreamWriter file = null;

            try
            {
                file = new StreamWriter(mFilename);

                file.WriteLine("<excludeAssets>");
                WriteAssetTags(file, context.ExcludeClasses);
                file.WriteLine("</excludeAssets>");
                file.WriteLine("<includeAssets>");
                WriteAssetTags(file, context.IncludeClasses);
                file.WriteLine("</includeAssets>");
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("Unable to write file, are you sure you have write permissions?\n" + ex.Message, "Error Writing File");
                mErrorMessage = ex.Message;

                if (null != file)
                {
                    file.Close();
                }

                return(ErrorCodes.XMLParserError.FileWriteError);
            }

            file.Close();
            return(ErrorCodes.XMLParserError.NoError);
        }
Exemplo n.º 2
0
        public void GenerateExcludeContext()
        {
            mContext = new ExcludeContext();
            ErrorCodes.XMLParserError result = mReader.ParseFile(mContext);
            if (result != ErrorCodes.XMLParserError.NoError)
            {
                mErrorCallback(result, "");
            }

            List <String> loadedClasses = GetLoadedClasses();

            foreach (String className in loadedClasses)
            {
                if (false == mContext.IncludeClasses.Contains(className) &&
                    false == mContext.ExcludeClasses.Contains(className))
                {
                    mContext.ExcludeClasses.Add(className);
                }
            }
        }
Exemplo n.º 3
0
        public ErrorCodes.XMLParserError ParseFile(ExcludeContext context)
        {
            if (File.Exists(mFileName))
            {
                StreamReader file = null;

                try
                {
                    file = new StreamReader(mFileName);

                    bool          excludeOpened = false;
                    bool          excludeClosed = false;
                    bool          includeOpened = false;
                    bool          includeClosed = false;
                    List <string> excludeAssets = context.ExcludeClasses;
                    List <string> includeAssets = context.IncludeClasses;

                    while (file.Peek() != -1)
                    {
                        string line = file.ReadLine();

                        if (line == "<excludeAssets>")
                        {
                            excludeOpened = true;
                        }
                        else if (line == "</excludeAssets>")
                        {
                            excludeClosed = true;
                        }
                        else if (line == "<includeAssets>")
                        {
                            includeOpened = true;
                        }
                        else if (line == "</includeAssets>")
                        {
                            includeClosed = true;

                            excludeAssets.Sort();
                            includeAssets.Sort();
                            // Export a sorted list, for flavour sake
                        }
                        else if (line.Contains(kAssetTag))
                        {
                            int firstQuote = line.IndexOf('\"');
                            int lastQuote  = line.LastIndexOf('\"');

                            int    classNameLength = lastQuote - firstQuote;
                            string className       = line.Substring(firstQuote + 1, classNameLength - 1);


                            if (excludeOpened && !excludeClosed &&
                                false == excludeAssets.Contains(className))
                            {
                                excludeAssets.Add(className);
                            }
                            else if (includeOpened && !includeClosed &&
                                     false == includeAssets.Contains(className))
                            {
                                excludeAssets.Remove(className);
                                // Dumbly call remove on this entry, just
                                // in case it is on the exclude list too
                                // Adds compelxity, but this will vanish
                                // during the planned tree refactor...

                                includeAssets.Add(className);
                            }
                        }
                    }
                }
                catch (System.Exception ex)
                // Since this is not a proper XML file we can be pretty loose on error
                // handling, if there is any error, we'll just spit out this generic error message
                {
                    // Close reader
                    file.Close();
                    return(ErrorCodes.XMLParserError.TagReadError);
                }

                file.Close();
                context.VarifyConsistencyOK();
            }
            else
            {
                return(ErrorCodes.XMLParserError.InputFileDoesNotExist);
            }

            return(ErrorCodes.XMLParserError.NoError);
        }