Inheritance: System.MarshalByRefObject, System.IDisposable
		protected static void MigrateUsingXslt(TextReader xslStream, TextReader xmlStream, string destinationFilePath)
		{
			var transform = new XslCompiledTransform();
			using (xslStream)
			{
				using (xmlStream)
				{
					using (var destinationStream = new StreamWriter(destinationFilePath))
					{
						var xslReader = XmlReader.Create(xslStream);
						transform.Load(xslReader);
						xslReader.Close();
						xslStream.Close();

						var reader = XmlReader.Create(xmlStream);

						var settings = new XmlWriterSettings { Indent = true };
						var writer = XmlWriter.Create(destinationStream, settings);

						transform.Transform(reader, writer);

						var tempfiles = transform.TemporaryFiles;
						if (tempfiles != null) // tempfiles will be null when debugging is not enabled
						{
							tempfiles.Delete();
						}
						writer.Close();
						reader.Close();
						destinationStream.Close();
					}
					xmlStream.Close();
				}
			}
		}
        public RecentComputerList Read( TextReader reader )
        {
            RecentComputerList computers = new RecentComputerList();

            while ( true )
            {
                string line = reader.ReadLine();
                if ( line == null )
                    break;

                string[] pair = line.Split( '\t' );

                // Avoid processing an empty line
                if ( pair[0] == "" )
                    continue;
                string computer = pair[0];

                string alias = pair.Length > 1 ? pair[1] : "";

                bool adminMode = false;
                if ( pair.Length > 2 )
                    bool.TryParse( pair[2], out adminMode );

                computers.Add( new ComputerName( computer, alias, adminMode ) );
            }

            return computers;
        }
        public JobDefinition ParseJIL(TextReader instr)
        {
            JobDefinition jobdef = new JobDefinition();

            char[] delim = {':'};
            string [] keyval = new string[2];
            string jil;

            Regex rx = new Regex("[A-Za-z-_]+:.*"); // Looks like a JIL key/value pair

            while ( (jil = instr.ReadLine()) != null )
            {
                if (rx.IsMatch(jil))
                {
                    keyval = jil.Split(delim, 2);
                    jobdef.SetField(keyval[0], keyval[1]);
                }
                else
                {
                    Console.Error.WriteLine("Warning: Malformed JIL encountered and ignored: {0}", jil);
                }
            }

            return jobdef;
        }
        /// <summary>
        /// Provide as much information about the input stream as we can,  size
        /// and position
        /// </summary>
        /// <param name="reader">reader we are analysing</param>
        public StreamInfoProvider(TextReader reader)
        {
            if (reader is StreamReader)
            {
                var stream = ((StreamReader)reader).BaseStream;
                mLength = stream.Length;
                // Uses the buffer position
                mPositionCalculator = () => stream.Position;
            }
            else if (reader is InternalStreamReader)
            {
                var reader2 = ((InternalStreamReader)reader);
                var stream = reader2.BaseStream;

                mLength = stream.Length;
                // Real Position
                mPositionCalculator = () => reader2.Position;
            }
            else if (reader is InternalStringReader)
            {
                var stream = (InternalStringReader)reader;
                mLength = stream.Length;
                mPositionCalculator = () => stream.Position;
            }
        }
Example #5
0
 public ConfigNode(string name, TextReader reader)
 {
     _name = name;
     _data = new Hashtable();
     _childConfigNodes = new ArrayList();
     ReadFrom(reader);
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="data">detailed results of the comparison</param>
 /// <param name="identical">summary result if the 
 /// comparison, value is 'true' if there were no 
 /// differences found.</param>
 internal XmlDiffViewResults(
     MemoryStream data,
     bool identical)
 {
     this.reader = this.PopulateReader(ref data);
     this.identicalData = identical;
 }
 public AbsTcpCommunication(TcpClient sock)
 {
     _sock = sock;
     _socketStream = _sock.GetStream ();
     _in = new StreamReader (_socketStream);
     _out = new StreamWriter (_socketStream);
 }
Example #8
0
        public static void Template(TextReader reader, object data, TextWriter writer, RenderContextBehaviour renderContextBehaviour = null)
        {
            var renderBehaviour = renderContextBehaviour ??
                                        RenderContextBehaviour.GetDefaultRenderContextBehaviour();

            Template(reader, data, writer, null, renderBehaviour);
        }
Example #9
0
        public static KeyValueConfig ReadVerBarConfig(TextReader reader)
        {
            var result = new KeyValueConfig();
            string line;

            int lineNum = 0;

            while ((line = reader.ReadLine()) != null)
            {
                string[] tokens = line.Split(new char[] {'|'});

                if (lineNum == 0) // keys
                {
                    foreach (var token in tokens)
                    {
                        var tokens2 = token.Split(new char[] {'!'});
                        result.Data[tokens2[0]] = new List<string>();
                    }
                }
                else // values
                {
                    //if (Data.Count != tokens.Length)
                    //    throw new Exception("VerBarConfig: Data.Count != tokens.Length");
                    if (result.Data.Count != tokens.Length)
                        continue;

                    for (int i = 0; i < result.Data.Count; i++)
                        result.Data.ElementAt(i).Value.Add(tokens[i]);
                }

                lineNum++;
            }

            return result;
        }
        public DatabaseVersionSetup Load(TextReader reader)
        {
            var versionSetup = new DatabaseVersionSetup();

            var shemas = new XmlSchemaSet();
            Assembly assem = typeof(DatabaseVersionSetup).Assembly;
            using (Stream stream = assem.GetManifestResourceStream("DatabaseVersionControl.Core.Xsd.DVCSchema.xsd"))
            {
                if (stream != null){
                    shemas.Add("", XmlReader.Create(stream));
                }
                else{
                    throw new Exception("Could not load embedded resource Xsd.DVCSchema.xsd");
                }
            }
            XDocument element = XDocument.Load(reader);
            element.Validate(shemas, (sender, e) =>
                                         { if (_exception != null) _exception(e); }, true);
            var profiles = element.XPathSelectElements("//profiles/profile");
            versionSetup.DefaultProfile = element.Root.Attribute("defaultProfile").Value;
            LoadProfiles(versionSetup, profiles);
            var databases = element.XPathSelectElements("//repositories/repository");
            LoadRepositories(versionSetup, databases);
            return versionSetup;
        }
Example #11
0
 public static XmlDocument IsWellFormed(TextReader reader)
 {
     Assert.IsNotNull(reader);
     XmlDocument doc = new XmlDocument();
     doc.Load(reader);
     return doc;
 }
        public List<string> ParseText(TextReader pReader)
        {
            result.Clear();

            int	count = 0;
            do
            {
                count = pReader.ReadBlock(buffer, 0, BUFFER_SIZE);
                for (int i = 0; i < count; ++i)
                {
                    char c = buffer[i];
                    if (char.IsWhiteSpace(c))
                    {
                        ParseWhitespace();
                    }
                    else if (Contains(punctuation, c))
                    {
                        ParsePunctuation(c);
                    }
                    else if (char.IsLetterOrDigit(c))
                    {
                        ParseLetter(c);
                    }else{
                        ParseLetter(c);
                    }
                }

            } while(count == BUFFER_SIZE);
            return result;
        }
Example #13
0
		public static YamlNode LoadFromTextReader(TextReader reader)
		{
			var yaml = new YamlStream();
			yaml.Load(reader);

			return yaml.Documents.First().RootNode;
		}
        public static void Answer(TextReader reader)
        {
            int n = Convert.ToInt32(reader.ReadLine());
            int[] coordinates = reader.ReadLine().Split(' ').Select(x => Convert.ToInt32(x)).ToArray();
            List<Line> lines = new List<Line>();

            for (int index = 0; index < coordinates.Length - 1; index++)
            {
                int a = coordinates[index];
                int b = coordinates[index + 1];
                lines.Add(new Line {From = Math.Min(a,b), To = Math.Max(a,b)});
            }

            for (int i = 0; i < lines.Count; i++)
            {
                for(int j = 0; j< lines.Count; j++)
                {
                    if (intersect(lines[i], lines[j]))
                    {
                        Console.WriteLine("yes");
                        return;
                    }
                }
            }
            Console.WriteLine("no");
        }
Example #15
0
        public static Knapsack GetKnapsack(TextReader reader)
        {
            Contract.Requires<ArgumentNullException>(reader != null, "reader");
            var firstRow = reader.ReadLine();
            var firtsRowParts = firstRow.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
            int capacity = int.Parse(firtsRowParts[0]);
            int numberOfItems = int.Parse(firtsRowParts[1]);

            var items = new List<KnapsackItem>(numberOfItems);
            while (true)
            {
                string row = reader.ReadLine();
                if (row == null)
                {
                    break;
                }

                var parts = row.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                var parameters = parts.Select(x => int.Parse(x, CultureInfo.InvariantCulture)).ToArray();

                items.Add(new KnapsackItem(parameters[0], parameters[1]));
            }

            return new Knapsack(items, capacity);
        }
        /// <summary>
        /// Parse and filter the supplied modifications.  The position of each modification in the list is used as the ChangeNumber.
        /// </summary>
        /// <param name="history"></param>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <returns></returns>
        public Modification[] Parse(TextReader history, DateTime from, DateTime to)
        {
            StringReader sr = new StringReader(string.Format(@"<ArrayOfModification xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">{0}</ArrayOfModification>"
                , history.ReadToEnd()));

            XmlSerializer serializer = new XmlSerializer(typeof(Modification[]));
            Modification[] mods;
            try
            {
                mods = (Modification[])serializer.Deserialize(sr);
            }
            catch (Exception ex)
            {
                throw new CruiseControlException("History Parsing Failed", ex);
            }

            ArrayList results = new ArrayList();
            int change = 0;
            foreach (Modification mod in mods)
            {
                change++;
                mod.ChangeNumber = change;
                if ((mod.ModifiedTime >= from) & (mod.ModifiedTime <= to))
                {
                    results.Add(mod);
                }
            }
            return (Modification[])results.ToArray(typeof(Modification));
        }
Example #17
0
        /// <summary>Read in rating data from a TextReader</summary>
        /// <param name="reader">the <see cref="TextReader"/> to read from</param>
        /// <param name="user_mapping">mapping object for user IDs</param>
        /// <param name="item_mapping">mapping object for item IDs</param>
        /// <returns>the rating data</returns>
        public static ITimedRatings Read(TextReader reader, IEntityMapping user_mapping = null, IEntityMapping item_mapping = null)
        {
            if (user_mapping == null)
                user_mapping = new IdentityMapping();
            if (item_mapping == null)
                item_mapping = new IdentityMapping();

            var ratings = new TimedRatings();

            string[] separators = { "::" };
            string line;

            while ((line = reader.ReadLine()) != null)
            {
                string[] tokens = line.Split(separators, StringSplitOptions.None);

                if (tokens.Length < 4)
                    throw new FormatException(string.Format("Expected at least 4 columns: {0}", line));

                int user_id = user_mapping.ToInternalID(tokens[0]);
                int item_id = item_mapping.ToInternalID(tokens[1]);
                float rating = float.Parse(tokens[2], CultureInfo.InvariantCulture);
                long seconds = uint.Parse(tokens[3]);

                var time = new DateTime(seconds * 10000000L).AddYears(1969);
                var offset = TimeZone.CurrentTimeZone.GetUtcOffset(time);
                time -= offset;

                ratings.Add(user_id, item_id, rating, time);
            }
            return ratings;
        }
Example #18
0
 public BinHexDecoder(TextReader input)
 {
     this.input = input;
     FindBinhexHeader();
     EatNewline();
     EatColon();
 }
Example #19
0
        public MarkdownReader(TextReader reader)
        {
            _reader = reader;
            _spec = new Specification();

            _modes.Push(new HeaderMode(_spec));
        }
 public MainClass(TextReader @in, TextWriter @out)
 {
     _out = @out;
     _in = @in;
     this.movieRepository = new MovieRepository();
     this.rentalFactory = new RentalFactory(movieRepository);
 }
Example #21
0
 public static RuntimeGraph ReadRuntimeGraph(TextReader textReader)
 {
     using (var jsonReader = new JsonTextReader(textReader))
     {
         return ReadRuntimeGraph(JToken.Load(jsonReader));
     }
 }
 public virtual void SetUp()
 {
     stdin = Console.In;
     stdout = Console.Out;
     displayOutput = new StringWriter();
     Console.SetOut(displayOutput);
 }
Example #23
0
        public bool Parse(TextReader reader)
        {
            List<EarleyItem> previousState, currentState;

            currentState = new List<EarleyItem>();
            currentState.Add(new EarleyItem(_start, 0, currentState));

            int i;
            while((i = reader.Read()) >= 0)
            {
                char c = (char)i;

                previousState = currentState;
                currentState = Parse(previousState, c);
            }

            // finish it off
            for (var s = 0; s < currentState.Count; s++)
            {
                var item = currentState[s];

                AddNewItems(currentState, Predict(item, currentState).ToList());
                AddNewItems(currentState, Complete(item).ToList());
            }

            return currentState.Any(x => x.IsComplete && x.Production.Equals(_start));
        }
 protected object Deserialize(TextReader reader, Type aType)
 {
     XmlSerializer xmlSerializer = new XmlSerializer(aType);
     object local = xmlSerializer.Deserialize(reader);
     reader.Close();
     return local;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="T:System.Object"/> class.
        /// </summary>
        public JsonMessageDeserializer([NotNull] IMessageTypeResolver typeResolver, TextReader textReader) : base(textReader) {
            if (typeResolver == null) {
                throw new ArgumentNullException("typeResolver");
            }

            this._typeResolver = typeResolver;
        }
 public OrchardConsoleLogger(
     TextReader input,
     TextWriter output)
 {
     _input = input;
     _output = output;
 }
		public XElement ParseFragment(TextReader reader, string fragmentContext)
		{
			Reset();
			treeBuilder.SetFragmentContext(fragmentContext);
			Tokenize(reader);
			return treeBuilder.getDocumentFragment();
		}
Example #28
0
        /// <exception cref="T:System.NotImplementedException"></exception>
        public MessageParser(TextReader reader)
        {
            string line;
            while ((line = reader.ReadLine()) != nameof(FCP2Protocol.EndMessage))
            {
                int pos;
                if (line == "End")
                    throw new NotImplementedException("NoEnd");
                if (line == "Data")
                {
                    DataAvailable = true;
                    break;
                }
                if ((pos = line.IndexOf('=')) == -1)
                {
                    throw new NotImplementedException("EmptyValue:" + line);
                }
                var key = line.Substring(0, pos);
                var val = line.Substring(pos + 1);
                _parameters.Add(key, val);
#if DEBUG
                _debugCount.Add(line.Substring(0, pos), 0);
#endif
            }
        }
 public override TokenStream TokenStream(string fieldName, TextReader reader)
 {
     // Split the title based on IdSeparators, then run it through the innerAnalyzer
     string title = reader.ReadToEnd();
     string partiallyTokenized = String.Join(" ", title.Split(LuceneIndexingService.IdSeparators, StringSplitOptions.RemoveEmptyEntries));
     return innerAnalyzer.TokenStream(fieldName, new StringReader(partiallyTokenized));
 }
Example #30
0
        public async Task<AdminCommand> CreateAsync(TextReader reader, CancellationToken cancellationToken)
        {
            var json = await reader.ReadJsonAsync(cancellationToken);
            if (string.IsNullOrWhiteSpace(json))
            {
                return null;
            }

            var adminCommandDto = json.FromJson<AdminCommandDto>();
            switch (adminCommandDto.Type)
            {
                case AdminCommandType.StartGame:
                    var startGameAdminCommandDto = json.FromJson<StartGameAdminCommandDto>();
                    return new StartGameAdminCommand(startGameAdminCommandDto.Size, _physics, _stateTracker, _playerRepository);
                case AdminCommandType.StopGame:
                    return new StopGameAdminCommand();
                case AdminCommandType.GetSnapshot:
                    return new GetSnapshotAdminCommand();
                case AdminCommandType.StartPushingState:
                    return new StartPushingStateAdminCommand();
                case AdminCommandType.UpdateSettings:
                    var updateSettingsAdminCommandDto = json.FromJson<UpdateSettingsAdminCommandDto>();
                    var settings = Mapper.Map<WorldSettings>(updateSettingsAdminCommandDto.Settings);
                    return new UpdateSettingsAdminCommand(settings);
                default:
                    throw new ArgumentOutOfRangeException();
            }
        }