Beispiel #1
0
        public virtual void LoadFiles(IList <string> FileList)
        {
            //load each item in the list into a IFileObject
            foreach (string str in FileList)
            {
                string ModifiedFullFileName = str;
                //remove the basedir
                foreach (string str2 in SourceDir)
                {
                    if (str.StartsWith(str2))
                    {
                        ModifiedFullFileName = str.Replace(str2, "");
                    }
                }

                var currentFile = FileObjects.Where(a => a.StoreIndependentFileName == ModifiedFullFileName).FirstOrDefault();
                //if the current file in the list does not exists
                if (currentFile == null)
                {
                    //_Files.Add(new IFileObject())
                    //IFileObject fobj2 = Kernel.Get<IFileObject>();
                    IFileObject fobj2 = new DefaultFileObject();
                    _Files.Add(fobj2.Create(str, ModifiedFullFileName));
                }
            }
        }
        public void DefaultObject_stream_test()
        {
            Stream fs = DefaultFileObject.get("$/B2B/Websites/CBG/Dev/_test-branch/jj.txt") as Stream;
            bool   a  = fs == null;

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

            Assert.IsFalse(a);
        }
Beispiel #3
0
        /// <summary>
        /// REturn build configuration config file
        /// </summary>
        /// <param name="basePath">The absolute path of the config file</param>
        /// <returns></returns>
        public static BuildConfiguration GetConfig(string basePath)
        {
            var config = new BuildConfiguration();

            config.Rules = new DirectoryCollection <DirectoryEntry>();
            Stream fileReader = null;
            string filePath   = "";

            try
            {
                config = null;
                if ((config == null))
                {
                    filePath = basePath + (!basePath.EndsWith(".config")?ConfigFileName:string.Empty);
                    //filePath = "stamatsRewrite.config";
                    //Create a FileStream for the Config file
                    if (basePath.StartsWith("$"))
                    {
                        fileReader = DefaultFileObject.get(filePath);
                    }
                    else
                    {
                        fileReader = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
                    }

                    var doc = new XPathDocument(fileReader);
                    config = new BuildConfiguration {
                        Rules = new DirectoryCollection <DirectoryEntry>()
                    };
                    foreach (XPathNavigator nav in doc.CreateNavigator().Select("build/*"))
                    {
                        switch (nav.Name.ToLower())
                        {
                        case "directory":
                            var rule = new DirectoryEntry();
                            //{ LookFor = nav.SelectSingleNode("LookFor").Value, SendTo = nav.SelectSingleNode("SendTo").Value, Handler=nav.SelectSingleNode("Handler").Value };

                            if (nav.GetAttribute("name", "") != null)
                            {
                                rule.Name = nav.GetAttribute("name", "");
                            }
                            if (nav.GetAttribute("value", "") != null)
                            {
                                rule.Value = nav.GetAttribute("value", "");
                            }
                            if (nav.GetAttribute("description", "") != null)
                            {
                                rule.Description = nav.GetAttribute("description", "");
                            }

                            config.Rules.Add(rule);
                            break;

                        case "connectionstring":
                            config.ConnectionString = nav.InnerXml.Trim();
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                if (fileReader != null)
                {
                    //Close the Reader
                    fileReader.Close();
                }
            }
            return(config);
        }