UpdateFile() public method

Adds or Updates a File in a Zip file archive.

This method adds a file to a zip archive, or, if the file already exists in the zip archive, this method Updates the content of that given filename in the zip archive. The UpdateFile method might more accurately be called "AddOrUpdateFile".

Upon success, there is no way for the application to learn whether the file was added versus updated.

For ZipFile properties including Encryption, , SetCompression, , ExtractExistingFile, ZipErrorAction, and CompressionLevel, their respective values at the time of this call will be applied to the ZipEntry added.

public UpdateFile ( string fileName ) : ZipEntry
fileName string /// The name of the file to add or update. It should refer to a file in the /// filesystem. The name of the file may be a relative path or a /// fully-qualified path. ///
return ZipEntry
Beispiel #1
0
		/// <summary>Copy all the files in the TOC to the all the destination zips</summary>
		/// <param name="TableOfContents">Container for all the files to copy</param>
		public static void ZipFiles( TOC TableOfContents )
		{
			// Handle zips
			if( Options.ZipName.Length > 0 )
			{
				long TotalFilesZipped = TableOfContents.Entries.Count;
				long TotalBytesZipped = TableOfContents.Entries.Sum( x => x.Info.Length );

				ZipFile Zip = new ZipFile( Options.ZipName );
				Zip.CompressionLevel = Ionic.Zlib.CompressionLevel.Level9;
				Zip.UseZip64WhenSaving = Zip64Option.Always;
				Zip.BufferSize = 0x10000;

				TableOfContents.Entries.ForEach( x => Zip.UpdateFile( x.Name ) );

				Log( " ... saving zip: " + Zip.Name, ConsoleColor.Green );
				Zip.Save();

				FileInfo ZipInfo = new FileInfo( Zip.Name );
				Log( "Completed saving zip with " + TotalFilesZipped + " files to " + ZipInfo.Length + " bytes (from " + TotalBytesZipped + ")", ConsoleColor.Green );
			}
		}
        public void Create_RenameRemoveAndRenameAgain_wi8047()
        {
            string filename = "file.test";
            string dirToZip = Path.GetFileNameWithoutExtension(Path.GetRandomFileName());
            var files = TestUtilities.GenerateFilesFlat(dirToZip);

            for (int m = 0; m < 2; m++)
            {
                string zipFileToCreate = Path.Combine(TopLevelDir, String.Format("Create_RenameRemoveAndRenameAgain_wi8047-{0}.zip", m));

                using (var zip = new ZipFile())
                {
                    // select a single file from the list
                    int n = _rnd.Next(files.Length);

                    // insert the selected file into the zip, and also rename it
                    zip.UpdateFile(files[n]).FileName = filename;

                    // conditionally save
                    if (m > 0) zip.Save(zipFileToCreate);

                    // remove the original file
                    zip.RemoveEntry(zip[filename]);

                    // select another file from the list, making sure it is not the same file
                    int n2 = 0;
                    while ((n2 = _rnd.Next(files.Length)) == n) ;

                    // insert that other file and rename it
                    zip.UpdateFile(files[n2]).FileName = filename;
                    zip.Save(zipFileToCreate);
                }

                Assert.AreEqual<int>(1, TestUtilities.CountEntries(zipFileToCreate), "Trial {0}: The Zip file has the wrong number of entries.", m);
            }
        }
        public void Create_DuplicateEntries_wi8047()
        {
            string zipFileToCreate = Path.Combine(TopLevelDir, "Create_DuplicateEntries_wi8047.zip");
            string filename = "file.test";
            string dirToZip = Path.GetFileNameWithoutExtension(Path.GetRandomFileName());
            var files = TestUtilities.GenerateFilesFlat(dirToZip);

            using (var zip = new ZipFile())
            {
                int n = _rnd.Next(files.Length);
                zip.UpdateFile(files[n]).FileName = filename;
                int n2 = 0;
                while ((n2 = _rnd.Next(files.Length)) == n) ;
                zip.UpdateFile(files[n2]).FileName = filename;
                zip.Save(zipFileToCreate);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Creates/updates a ZIP archive.
        /// </summary>
        /// <param name="baseDirectory">
        /// The base directory. Can be <see langword="null"/> or empty.
        /// </param>
        /// <param name="searchPatterns">
        /// The search patterns relative to the <paramref name="baseDirectory"/> or the current working
        /// directory. May include wildcards ('?', '*').
        /// </param>
        /// <param name="recursive">
        /// If set to <see langword="true"/> all subdirectories will be included in the search.
        /// </param>
        /// <param name="packageFileName">The file name of the ZIP archive.</param>
        /// <param name="cancellationToken">
        /// The token to monitor for cancellation requests. The default value is 
        /// <see cref="CancellationToken.None"/>.
        /// </param>
        public void Pack(string baseDirectory, IEnumerable<string> searchPatterns, bool recursive, string packageFileName, CancellationToken cancellationToken)
        {
            if (searchPatterns == null)
                throw new ArgumentNullException(nameof(searchPatterns));

            baseDirectory = string.IsNullOrEmpty(baseDirectory)
              ? Directory.GetCurrentDirectory()
              : Path.GetFullPath(baseDirectory);

            if (File.Exists(packageFileName))
                WriteLine("Updating existing package \"{0}\".", packageFileName);
            else
                WriteLine("Creating new package \"{0}\".", packageFileName);

            // Create/open ZIP archive.
            using (var zipFile = new ZipFile(packageFileName))
            {
                bool isDirty = false;

                zipFile.CompressionLevel = CompressionLevel.BestCompression;
                zipFile.Password = string.IsNullOrEmpty(Password) ? null : Password;
                zipFile.Encryption = string.IsNullOrEmpty(Password) ? EncryptionAlgorithm.None : Encryption;
                //zipFile.StatusMessageTextWriter = MessageWriter;
                zipFile.ZipErrorAction = ZipErrorAction.Throw;

                zipFile.SaveProgress += (s, e) =>
                                        {
                                            if (cancellationToken.IsCancellationRequested)
                                                e.Cancel = true;

                                    // Note: We could report the saving progress here.
                                };

                // Search for files.
                var fileNames = new List<string>();
                foreach (var searchPattern in searchPatterns)
                {
                    cancellationToken.ThrowIfCancellationRequested();
                    fileNames.AddRange(GetFiles(baseDirectory, searchPattern, recursive));
                }

                // Exclude output file in case it is included in the search results.
                fileNames.Remove(Path.GetFullPath(packageFileName));

                // Sort in ascending order.
                fileNames.Sort();

                // Create a copy of the original ZIP entries.
                var originalZipEntries = zipFile.Entries.ToList();

                // Add/update files in ZIP archive.
                foreach (var fileName in fileNames)
                {
                    cancellationToken.ThrowIfCancellationRequested();

                    var fileInfo = new FileInfo(fileName);
                    string directory = fileInfo.DirectoryName;
                    string directoryInArchive = ChangePath(directory, baseDirectory, string.Empty);
                    string filenameInArchive = Path.Combine(directoryInArchive, fileInfo.Name);
                    filenameInArchive = NormalizePath(filenameInArchive);

                    var zipEntry = zipFile[filenameInArchive];
                    if (zipEntry == null)
                    {
                        // ----- New file.
                        MessageWriter.WriteLine("Adding \"{0}\".", filenameInArchive);
                        isDirty = true;
                        if (!IsTestRun)
                            zipFile.AddFile(fileName, directoryInArchive);
                    }
                    else
                    {
                        // ----- Existing file.
                        originalZipEntries.Remove(zipEntry);
                        if (fileInfo.LastWriteTimeUtc > zipEntry.ModifiedTime // Input file is newer.
                            || fileInfo.Length != zipEntry.UncompressedSize) // Different file size.
                        {
                            MessageWriter.WriteLine("Updating \"{0}\".", filenameInArchive);
                            isDirty = true;
                            if (!IsTestRun)
                                zipFile.UpdateFile(fileName, directoryInArchive);
                        }
                    }
                }

                // Remove obsolete files from ZIP archive.
                foreach (var zipEntry in originalZipEntries)
                {
                    cancellationToken.ThrowIfCancellationRequested();
                    if (zipEntry.IsDirectory)
                        continue;

                    MessageWriter.WriteLine("Removing \"{0}\".", zipEntry.FileName);
                    isDirty = true;
                    zipFile.RemoveEntry(zipEntry);
                }

                // Remove empty directories from ZIP archive.
                foreach (var zipEntry in originalZipEntries)
                {
                    cancellationToken.ThrowIfCancellationRequested();

                    if (!zipEntry.IsDirectory)
                        continue;

                    if (IsEmptyDirectory(zipFile, zipEntry))
                    {
                        MessageWriter.WriteLine("Removing empty directory \"{0}\".", zipEntry.FileName);
                        isDirty = true;
                        zipFile.RemoveEntry(zipEntry);
                    }
                }

                if (isDirty)
                {
                    if (!IsTestRun)
                    {
                        // Save ZIP archive.
                        MessageWriter.WriteLine("Saving package \"{0}\".", packageFileName);
                        zipFile.Save();
                        cancellationToken.ThrowIfCancellationRequested();
                    }
                }
                else
                {
                    // Leave ZIP archive untouched.
                    MessageWriter.WriteLine("Package is up-to-date.");
                }
            }
        }
Beispiel #5
0
        public void CompressFiles_zip(string destinationDirectory, string archiveName, string pwd, params string[] files)
        {
            try
            {
                if (archiveName == null || archiveName == string.Empty)
                    archiveName = DateTime.Now.ToString("dd_MM_yyyy");
                else
                    if (archiveName[0] == '#')
                        archiveName = System.String.Format("{0}_{1:dd_MM_yyyy}", archiveName.Substring(1), System.DateTime.Now);

                if (pwd == null || pwd == string.Empty)
                    pwd = Convert.ToString(int.Parse(DateTime.Now.ToString("ddMMyyyy")), 16).ToUpper();
                //DateTime.Now.ToString("C_dd_MM_yyyy");
                string pathZip = destinationDirectory + "\\" + archiveName + ".storage";

                using (ZipFile zip = new ZipFile(pathZip))
                {
                    //zip.AddFile("ReadMe.txt"); // unencrypted
                    //zip.
                    zip.Password = pwd;
                    zip.Encryption = EncryptionAlgorithm.WinZipAes256;
                    string singleName = string.Empty;
                    //ZipEntry itemZ = new ZipEntry();
                    foreach (string item in files)
                    {
                        singleName = item;

                        if (zip.ContainsEntry(singleName))
                            zip.UpdateFile(singleName).Password = pwd;
                        else
                        {
                            //itemZ.Encryption = EncryptionAlgorithm.WinZipAes256;
                            //itemZ.Password = pwd;
                            //itemZ.FileName = item;

                            zip.AddFile(singleName).Password = pwd;

                            //zip.Entries.Add(itemZ);

                            //ZipEntry.itemZ = new ZipEntry();
                        }
                    }
                    //zip.AddFile().pa(files, destinationDirectory);
                    //zip.AddFile("2008_Annual_Report.pdf");
                    try
                    {
                        zip.Comment = string.Format("{0}", int.Parse(zip.Comment) + 1);
                    }
                    catch (Exception ex)
                    {
                        pdLogger.pdLogger.Logme(ex, System.Reflection.MethodInfo.GetCurrentMethod().Name);
                        zip.Comment = zip.Count.ToString();
                    }

                    zip.Save(pathZip);

                }

            }
            catch (Exception ex)
            {
                pdLogger.pdLogger.Logme(ex, System.Reflection.MethodInfo.GetCurrentMethod().Name);
            }
        }
Beispiel #6
0
        /// <summary>
        /// Recursively adds files from the given directory into the given jar
        /// </summary>
        /// <param name="dir">directory to copy files from</param>
        /// <param name="jarFile">jar file to add them to</param>
        private void AddToJar(string dir, ZipFile jarFile, string pathInJar = "")
        {
            IEnumerable<string> cFiles = Directory.EnumerateFileSystemEntries(dir);
            foreach (string f in cFiles)
            {
                // For files that are not zip files...
                if (File.Exists(f) && Path.GetExtension(f) != ".zip")
                {
                    // Automatically put world edit in the bin folder.
                    if (Path.GetFileName(f) == "WorldEdit.jar")
                    {
                        File.Copy(f,
                            Path.Combine(Target.BinDir, "WorldEdit.jar"), true);
                        continue;
                    }

                    string existing = Path.Combine(pathInJar, Path.GetFileName(f));
                    int index = 0;

                    if (jarFile[existing] != null &&
                        !string.IsNullOrEmpty(jarFile[existing].Comment) &&
                        !Int32.TryParse(jarFile[existing].Comment, out index))
                    {
                        Console.WriteLine("Can't parse index: {0}", jarFile[existing].Comment);
                    }

                    if (jarFile[existing] != null &&
                        index > (int)modFileIndices[f])
                    {
                        DebugUtils.Print("File conflict between {0} in jar ({2}) and {1} ({3}) " +
                            "being added, " + "not overwriting.", existing, f,
                            jarFile[existing].Comment,
                            (modFileIndices.ContainsKey(f) ?
                                modFileIndices[f].ToString() : "none"));
                    }
                    else
                    {
                        if (jarFile[existing] != null)
                        {
                            DebugUtils.Print("File conflict between {0} " +
                                "in jar ({2}) and {1} ({3}) " +
                                "being added, " + " overwriting.", existing, f,
                                jarFile[existing].Comment,
                                (modFileIndices.ContainsKey(f) ?
                                    modFileIndices[f].ToString() : "none"));
                        }

                        ZipEntry fEntry = jarFile.UpdateFile(f, pathInJar);
                        fEntry.SetEntryTimes(File.GetCreationTime(f),
                            fEntry.AccessedTime, fEntry.ModifiedTime);
                        if (modFileIndices.ContainsKey(f))
                            fEntry.Comment = modFileIndices[f].ToString();
                    }
                }

                // For directories
                else if (Directory.Exists(f))
                {
                    DebugUtils.Print("Adding subdirectory " + f + " to " +
                        Path.Combine(pathInJar, Path.GetFileName(f)));
                    AddToJar(f, jarFile, Path.Combine(pathInJar, Path.GetFileName(f)));
                }

                // For zip files
                else if (File.Exists(f) &&
                    (Path.GetExtension(f) == ".zip" || Path.GetExtension(f) == ".jar"))
                {
                    string tmpDir = Path.Combine(Target.RootDir, MODTEMP_DIR_NAME,
                        Path.GetFileNameWithoutExtension(f));
                    DebugUtils.Print("Adding zip file {0}, extracting to {1}...", f, tmpDir);
                    //Console.WriteLine("Temp directory for {0}: {1}", f, tmpDir);

                    if (Directory.Exists(tmpDir))
                    {
                        Directory.Delete(tmpDir, true);
                        Directory.CreateDirectory(tmpDir);
                    }
                    else
                        Directory.CreateDirectory(tmpDir);

                    //Console.WriteLine("Extracting {0} to temp directory...", f);
                    using (ZipFile zipFile = new ZipFile(f))
                    {
                        foreach (ZipEntry entry in zipFile)
                        {
                            entry.Extract(tmpDir);
                            string extractedFile = Path.Combine(tmpDir,
                                entry.FileName.Replace('/', Path.DirectorySeparatorChar));

                            //if (modFileIndices.ContainsKey(f))
                            //    continue;
                            RecursiveSetIndex(extractedFile, (int) modFileIndices[f]);

                            // If it's a file
                            //						if (File.Exists(extractedFile))
                            //							File.SetCreationTime(extractedFile, File.GetCreationTime(f));

                            // If it's a directory
                            //						else if (Directory.Exists(extractedFile))
                            //							Directory.SetCreationTime(extractedFile, File.GetCreationTime(f));

                            //Console.WriteLine("{0} create time is {1}", extractedFile,
                            //    File.GetCreationTime(f).ToString());
                        }

                        //Console.WriteLine("Adding to jar...");
                        AddToJar(tmpDir, jarFile, pathInJar);
                    }
                }
            }
        }
        /// <summary>
        ///     Store the current pack files in storage.
        /// </summary>
        /// <param name="zip"><see cref="ZipFile" /> to store the current packs in.</param>
        private void StorePacks(ZipFile zip)
        {
            const string ExdPackPattern = "0a*.*";

            foreach (var file in Packs.DataDirectory.EnumerateFiles(ExdPackPattern, SearchOption.AllDirectories)) {
                string targetDir = GameVersion + "/" + file.Directory.Name;
                zip.UpdateFile(file.FullName, targetDir);
            }
        }
Beispiel #8
0
        /// <summary>
        /// Recursively adds files from the given directory into the given jar
        /// </summary>
        /// <param name="dir">directory to copy files from</param>
        /// <param name="jarFile">jar file to add them to</param>
        private void AddToJar(string dir, ZipFile jarFile, string pathInJar = "")
        {
            IEnumerable<string> cFiles = Directory.EnumerateFileSystemEntries(dir);
            foreach (string f in cFiles)
            {
                // For files that are not zip files...
                if (File.Exists(f) && Path.GetExtension(f) != ".zip")
                {
                    // Automatically put world edit in the bin folder.
                    if (Path.GetFileName(f) == "WorldEdit.jar")
                    {
                        File.Copy(f,
                            Path.Combine(Target.RootDir, ".minecraft", "bin", "WorldEdit.jar"), true);
                        continue;
                    }

                    string existing = Path.Combine(pathInJar, Path.GetFileName(f));
                    if (jarFile[existing] != null &&
                        jarFile[existing].CreationTime.CompareTo(File.GetCreationTimeUtc(f)) > 0)
                    {
                        //Console.WriteLine("File conflict between {0} in jar ({2}) and {1} ({3}) " +
                        //    "being added, " + "not overwriting.", existing, f,
                        //    jarFile[existing].CreationTime.ToString(),
                        //    File.GetCreationTimeUtc(f).ToString());
                    }
                    else
                    {
                        if (jarFile[existing] != null)
                        {
                            //Console.WriteLine("File conflict between {0} in jar ({2}) and {1} ({3}) " +
                            //    "being added, " + " overwriting.", existing, f,
                            //    jarFile[existing].CreationTime.ToString(),
                            //    File.GetCreationTimeUtc(f).ToString());
                        }

                        ZipEntry fEntry = jarFile.UpdateFile(f, pathInJar);
                        fEntry.SetEntryTimes(File.GetCreationTime(f),
                            fEntry.AccessedTime, fEntry.ModifiedTime);
                    }
                }

                // For directories
                else if (Directory.Exists(f))
                {
                    Console.WriteLine("Adding subdirectory " + f + " to " +
                        Path.Combine(pathInJar, Path.GetFileName(f)));
                    AddToJar(f, jarFile, Path.Combine(pathInJar, Path.GetFileName(f)));
                }

                // For zip files
                else if (File.Exists(f) && Path.GetExtension(f) == ".zip" && OSUtils.Windows)
                {
                    string tmpDir = Path.Combine(Target.RootDir, MODTEMP_DIR_NAME,
                        Path.GetFileNameWithoutExtension(f));
                    Console.WriteLine("Adding zip file {0}, extracting to {1}...", f, tmpDir);
                    //Console.WriteLine("Temp directory for {0}: {1}", f, tmpDir);

                    if (Directory.Exists(tmpDir))
                    {
                        Directory.Delete(tmpDir, true);
                        Directory.CreateDirectory(tmpDir);
                    }
                    else
                        Directory.CreateDirectory(tmpDir);

                    //Console.WriteLine("Extracting {0} to temp directory...", f);
                    ZipFile zipFile = new ZipFile(f);
                    foreach (ZipEntry entry in zipFile)
                    {
                        entry.Extract(tmpDir);
                        string extractedFile = Path.Combine(tmpDir, entry.FileName);

                        // If it's a file
                        if (File.Exists(extractedFile))
                            File.SetCreationTime(extractedFile, File.GetCreationTime(f));

                        // If it's a directory
                        else if (Directory.Exists(extractedFile))
                            Directory.SetCreationTime(extractedFile, File.GetCreationTime(f));

                        //Console.WriteLine("{0} create time is {1}", extractedFile,
                        //    File.GetCreationTime(f).ToString());
                    }

                    //Console.WriteLine("Adding to jar...");
                    AddToJar(tmpDir, jarFile, pathInJar);
                }
            }
        }
        protected void Button1_Click(object sender, System.EventArgs e)
        {
            string loc = ConfigurationManager.AppSettings["transitLocation"].ToString();
            string arch = ConfigurationManager.AppSettings["transitArchive"].ToString();
            string appRoot = HttpRuntime.AppDomainAppPath;
            string transitDirectory = loc.Replace("~/", appRoot);
            System.IO.StreamWriter agencyRecord, feedInfoRecord, routesRecord, stopsRecord, calendarsRecord, calendarDatesRecord, tripsRecord, stopTimesRecord, fareAttributesRecord, fareRulesRecord, testingRecord;

            // Set the message text back to nothing
            message.Text = " ";

            // Create root variables
            int agencyRoot;
            int routesRoot;
            int servicesRoot;
            int exceptionsRoot;
            int stopsRoot;
            int tripsRoot;
            int faresRoot;

            // Create an Error Counter
            int errors = 0;

            // Check to see if each of the txt files exist. If they don't then create them
            if (!System.IO.File.Exists(transitDirectory + "\\agency.txt"))
            {
                System.IO.File.Create(transitDirectory + "\\agency.txt");
            }
            if (!System.IO.File.Exists(transitDirectory + "\\feed_info.txt"))
            {
                System.IO.File.Create(transitDirectory + "\\feed_info.txt");
            }
            if (!System.IO.File.Exists(transitDirectory + "\\routes.txt"))
            {
                System.IO.File.Create(transitDirectory + "\\routes.txt");
            }
            if (!System.IO.File.Exists(transitDirectory + "\\stops.txt"))
            {
                System.IO.File.Create(transitDirectory + "\\stops.txt");
            }
            if (!System.IO.File.Exists(transitDirectory + "\\calendar.txt"))
            {
                System.IO.File.Create(transitDirectory + "\\calendar.txt");
            }
            if (!System.IO.File.Exists(transitDirectory + "\\calendar_dates.txt"))
            {
                System.IO.File.Create(transitDirectory + "\\calendar_dates.txt");
            }
            if (!System.IO.File.Exists(transitDirectory + "\\trips.txt"))
            {
                System.IO.File.Create(transitDirectory + "\\trips.txt");
            }
            if (!System.IO.File.Exists(transitDirectory + "\\stop_times.txt"))
            {
                System.IO.File.Create(transitDirectory + "\\stop_times.txt");
            }
            if (!System.IO.File.Exists(transitDirectory + "\\fare_attributes.txt"))
            {
                System.IO.File.Create(transitDirectory + "\\fare_attributes.txt");
            }
            if (!System.IO.File.Exists(transitDirectory + "\\fare_rules.txt"))
            {
                System.IO.File.Create(transitDirectory + "\\fare_rules.txt");
            }
            if (!System.IO.File.Exists(transitDirectory + "\\testing.txt"))
            {
                System.IO.File.Create(transitDirectory + "\\testing.txt");
            }

            try
            {
                // Create StreamWriters for each of the txt Records
                agencyRecord = new StreamWriter(transitDirectory + "\\agency.txt");
                feedInfoRecord = new StreamWriter(transitDirectory + "\\feed_info.txt");
                routesRecord = new StreamWriter(transitDirectory + "\\routes.txt");
                stopsRecord = new StreamWriter(transitDirectory + "\\stops.txt");
                calendarsRecord = new StreamWriter(transitDirectory + "\\calendar.txt");
                calendarDatesRecord = new StreamWriter(transitDirectory + "\\calendar_dates.txt");
                tripsRecord = new StreamWriter(transitDirectory + "\\trips.txt");
                stopTimesRecord = new StreamWriter(transitDirectory + "\\stop_times.txt");
                fareAttributesRecord = new StreamWriter(transitDirectory + "\\fare_attributes.txt");
                fareRulesRecord = new StreamWriter(transitDirectory + "\\fare_rules.txt");
                testingRecord = new StreamWriter(transitDirectory + "\\testing.txt");

                // Write the first line of each txt file
                agencyRecord.WriteLine("agency_id,agency_name,agency_url,agency_timezone,agency_lang,agency_phone,agency_fare_url");
                feedInfoRecord.WriteLine("feed_publisher_name,feed_publisher_url,feed_lang,feed_version");
                routesRecord.WriteLine("route_id,agency_id,route_short_name,route_long_name,route_desc,route_type,route_url,route_color,route_text_color");
                stopsRecord.WriteLine("stop_id,stop_code,stop_name,stop_desc,stop_lat,stop_lon,zone_id,stop_url,location_type,parent_station");
                calendarsRecord.WriteLine("service_id,monday,tuesday,wednesday,thursday,friday,saturday,sunday,start_date,end_date");
                calendarDatesRecord.WriteLine("service_id,date,exception_type");
                tripsRecord.WriteLine("route_id,service_id,trip_id,trip_headsign,direction_id,block_id,shape_id");
                stopTimesRecord.WriteLine("trip_id,arrival_time,departure_time,stop_id,stop_sequence,stop_headsign,pickup_type,drop_off_type,shape_dist_traveled");
                fareAttributesRecord.WriteLine("fare_id,price,currency_type,payment_method,transfers,transfer_duration");
                fareRulesRecord.WriteLine("fare_id,route_id,origin_id,destination_id,contains_id");

                // Connect to the SQL Database
                SqlConnection SQLConn = new SqlConnection(GlobalSettings.DbDSN);
                SQLConn.Open();
                SqlDataAdapter dataAdapter;
                DataTableReader dataReader;

                // Connect to the SQL database for the Routes node
                string agencySQL = string.Format(@"select id from umbracoNode where text = 'Routes'");
                dataAdapter = new SqlDataAdapter(agencySQL, SQLConn);
                DataSet agencyDataSet = new DataSet();
                dataAdapter.Fill(agencyDataSet);

                // Connect to the SQL database for the Transit Routes node
                string routesSQL = string.Format(@"select id from umbracoNode where text = 'Transit Routes'");
                dataAdapter = new SqlDataAdapter(routesSQL, SQLConn);
                DataSet routesDataSet = new DataSet();
                dataAdapter.Fill(routesDataSet);

                // Connect to the SQL database for the Transit Service Calendars node
                string servicesSQL = string.Format(@"select id from umbracoNode where text = 'Transit Service Calendars'");
                dataAdapter = new SqlDataAdapter(servicesSQL, SQLConn);
                DataSet servicesDataSet = new DataSet();
                dataAdapter.Fill(servicesDataSet);

                // Connect to the SQL database for the Transit Service Calendar Exceptions node
                string exceptionsSQL = string.Format(@"select id from umbracoNode where text = 'Transit Service Calendar Exceptions'");
                dataAdapter = new SqlDataAdapter(exceptionsSQL, SQLConn);
                DataSet exceptionsDataSet = new DataSet();
                dataAdapter.Fill(exceptionsDataSet);

                // Connect to the SQL database for the Transit Stops node
                string stopsSQL = string.Format(@"select id from umbracoNode where text = 'Transit Stops'");
                dataAdapter = new SqlDataAdapter(stopsSQL, SQLConn);
                DataSet stopsDataSet = new DataSet();
                dataAdapter.Fill(stopsDataSet);

                // Connect to the SQL database for the Transit Trips node
                string tripsSQL = string.Format(@"select id from umbracoNode where text = 'Transit Trips and Stop Times'");
                dataAdapter = new SqlDataAdapter(tripsSQL, SQLConn);
                DataSet tripsDataSet = new DataSet();
                dataAdapter.Fill(tripsDataSet);

                // Connect to the SQL database for the Transit Fares node
                string faresSQL = string.Format(@"select id from umbracoNode where text = 'Transit Fares'");
                dataAdapter = new SqlDataAdapter(faresSQL, SQLConn);
                DataSet faresDataSet = new DataSet();
                dataAdapter.Fill(faresDataSet);

                // Close and dispose SQL connection
                SQLConn.Close();
                SQLConn.Dispose();

                // Set the data reader for the Routes node and set the ID for the Routes node
                dataReader = agencyDataSet.CreateDataReader();
                if (dataReader.Read()) { agencyRoot = (int)dataReader["id"]; } else { status.Text = "No Routes Folder Found!"; return; }

                // Set the data reader for the Transit Routes node and set the ID for the Transit Routes node
                dataReader = routesDataSet.CreateDataReader();
                if (dataReader.Read()) { routesRoot = (int)dataReader["id"]; } else { status.Text = "No Transit Routes Folder Found!"; return; }

                // Set the data reader for the Transit Service Calendars node and set the ID for the Transit Service Calendars node
                dataReader = servicesDataSet.CreateDataReader();
                if (dataReader.Read()) { servicesRoot = (int)dataReader["id"]; } else { status.Text = "No Transit Service Calendars Folder Found!"; return; }

                // Set the data reader for the Transit Service Calendars Exceptions node and set the ID for the Transit Service Calendars Exceptions node
                dataReader = exceptionsDataSet.CreateDataReader();
                if (dataReader.Read()) { exceptionsRoot = (int)dataReader["id"]; } else { status.Text = "No Transit Service Calendar Exceptions Folder Found!"; return; }

                // Set the data reader for the Transit Stops node and set the ID for the Transit Stops node
                dataReader = stopsDataSet.CreateDataReader();
                if (dataReader.Read()) { stopsRoot = (int)dataReader["id"]; } else { status.Text = "No Transit Stops Folder Found!"; return; }

                // Set the data reader for the Transit Trips node and set the ID for the Transit Trips and Stop Times node
                dataReader = tripsDataSet.CreateDataReader();
                if (dataReader.Read()) { tripsRoot = (int)dataReader["id"]; } else { status.Text = "No Transit Trips and Stop Times Folder Found!"; return; }

                // Set the data reader for the Transit Fares node and set the ID for the Transit Fares node
                dataReader = faresDataSet.CreateDataReader();
                if (dataReader.Read()) { faresRoot = (int)dataReader["id"]; } else { status.Text = "No Transit Fares Folder Found!"; return; }

                // Dispose dataReader
                dataReader.Dispose();

                // Get the agency.txt information from the Routes node and write it to agencyRecord
                Document agency = new Document(agencyRoot);
                // Create URL out of agency fare page id
                string fareURL = new Node(Convert.ToInt32(agency.getProperty("agencyFarePage").Value.ToString())).NiceUrl;
                agencyRecord.WriteLine(agency.getProperty("agencyID").Value.ToString() + "," + agency.getProperty("agencyName").Value.ToString().Replace(",", " ") + "," + agency.getProperty("agencyURL").Value.ToString() + "," + agency.getProperty("agencyTimezone").Value.ToString() + ",EN," + agency.getProperty("agencyPhoneNumber").Value.ToString() + "," + agency.getProperty("agencyURL").Value.ToString() + fareURL);
                // Testing
                testingRecord.WriteLine("agency.txt");
                testingRecord.WriteLine("agency_id = " + agency.getProperty("agencyID").Value.ToString() + "  |  agency_name = " + agency.getProperty("agencyName").Value.ToString().Replace(",", " ") + "  |  agency_url = " + agency.getProperty("agencyURL").Value.ToString() + "  |  agency_timezone = " + agency.getProperty("agencyTimezone").Value.ToString() + "  |  agency_lang = EN  |  agency_phone = " + agency.getProperty("agencyPhoneNumber").Value.ToString() + "  |  agency_fare_url = " + agency.getProperty("agencyURL").Value.ToString() + fareURL);
                testingRecord.WriteLine("");

                // Write the only line for feed_info.txt
                feedInfoRecord.WriteLine("HillSouth,http://hillsouth.com,EN,");
                // Testing
                testingRecord.WriteLine("feed_info.txt");
                testingRecord.WriteLine("feed_publisher_name = HillSouth  |  feed_publisher_url = http://hillsouth.com  |  feed_lang = EN  |  feed_version =  ");
                testingRecord.WriteLine("");

                // Get the routes.txt information from the Transit Routes children nodes and write it to routesRecord
                Document[] routes = new Document(routesRoot).Children;
                // Testing
                testingRecord.WriteLine("routes.txt");
                for (int a = 0; a < routes.Length; a++)
                {
                    // Send the route to XML
                    XmlNode routesNode = routes[a].ToXml(new XmlDocument(), false);
                    // Check to see if the routesNode equals null, if so, the route is not published
                    string routeNodeName;
                    if (routesNode == null)
                    {
                        continue;
                    }
                    else
                    {
                        // Get the route node name from the xml node attributes
                        routeNodeName = routesNode.Attributes.GetNamedItem("nodeName").Value.ToString();
                    }
                    // Check to see if the Route needs to be excludes due to the googleTransitOverride
                    string googleTransitOverride = routes[a].getProperty("googleTransitOverride").Value.ToString();
                    if (googleTransitOverride == "1")
                    {
                        message.Text = message.Text + "&#8226; <span style='color: red;'>Route <b>" + routeNodeName + "</b> has not been added to the Google Transit Feed.</span><br />";
                        continue;
                    }
                    // Write the needed line
                    routesRecord.WriteLine(routeNodeName + ",," + routes[a].getProperty("routeShortName").Value.ToString().Replace(",", " ") + "," + routes[a].getProperty("routeFullName").Value.ToString().Replace(",", " ") + "," + routes[a].getProperty("routeDescription").Value.ToString().Replace(",", " ") + ",3,,,");
                    // Testing
                    testingRecord.WriteLine("route_id = " + routeNodeName + "  |  agency_id =  |  route_short_name = " + routes[a].getProperty("routeShortName").Value.ToString().Replace(",", " ") + "  |  route_long_name = " + routes[a].getProperty("routeFullName").Value.ToString().Replace(",", " ") + "  |  route_description = " + routes[a].getProperty("routeDescription").Value.ToString().Replace(",", " ") + "  |  route_type = 3  |  route_url =  |  route_color =  |  route_text_color = ");
                }
                // Testing
                testingRecord.WriteLine("");

                // Get the stops.txt information from the Transit Stops children nodes and write it to stopsRecord
                Document[] stops = new Document(stopsRoot).Children;
                // Testing
                testingRecord.WriteLine("stops.txt");
                for (int b = 0; b < stops.Length; b++)
                {
                    // Send the stop to XML
                    XmlNode stopsNode = stops[b].ToXml(new XmlDocument(), false);
                    // Check to see if the stopsNode equals null, if so, the stop is not published
                    string stopNodeName;
                    if (stopsNode == null)
                    {
                        continue;
                    }
                    else
                    {
                        // Get the stop node name from the xml node attributes
                        stopNodeName = stopsNode.Attributes.GetNamedItem("nodeName").Value.ToString();
                    }
                    // Create stopCoordinates variable
                    string[] stopCoordinates;
                    // Check to see whether or not stopMap has been populated
                    if (String.IsNullOrEmpty(stops[b].getProperty("stopMap").Value.ToString()))
                    {
                        message.Text = message.Text + "&#8226; <span style='color: red;'>Stop <b>" + stopNodeName + "</b> has not been mapped correctly.</span><br />";
                        errors++;
                        continue;
                    }
                    else
                    {
                        stopCoordinates = stops[b].getProperty("stopMap").Value.ToString().Split(',');
                    }
                    // Check to see whether or not stopZone has been populated
                    if (stops[b].getProperty("stopZone").Value.ToString() == "-1")
                    {
                        message.Text = message.Text + "&#8226; <span style='color: red;'>Stop <b>" + stopNodeName + "</b> does not have a stop zone applied to it.</span><br />";
                        errors++;
                        continue;
                    }
                    // Write the information
                    stopsRecord.WriteLine(stopNodeName + ",," + stops[b].getProperty("stopName").Value.ToString().Replace(",", " ") + "," + stops[b].getProperty("stopDescription").Value.ToString().Replace(",", " ") + "," + stopCoordinates[0] + "," + stopCoordinates[1] + "," + stops[b].getProperty("stopZone").Value.ToString() + ",,,");
                    // Testing
                    testingRecord.WriteLine("stop_id = " + stopNodeName + "  |  stop_code =  |  stop_name = " + stops[b].getProperty("stopName").Value.ToString().Replace(",", " ") + "  |  stop_desc = " + stops[b].getProperty("stopDescription").Value.ToString().Replace(",", " ") + "  |  stop_lat = " + stopCoordinates[0] + "  |  stop_lon = " + stopCoordinates[1] + "  |  zone_id = " + stops[b].getProperty("stopZone").Value.ToString() + "  |  stop_url =  |  location_type =  |  parent_station = ");
                }
                // Testing
                testingRecord.WriteLine("");

                // Get the calendar.txt information from the Transit Service Calendars children nodes and write it to calendarsRecord
                Document[] services = new Document(servicesRoot).Children;
                // Testing
                testingRecord.WriteLine("calendar.txt");
                for (int c = 0; c < services.Length; c++)
                {
                    // Send the calendar to XML
                    XmlNode servicesNode = services[c].ToXml(new XmlDocument(), false);
                    // Check to see if the servicesNode equals null, if so, the exception is not published
                    string serviceNodeName;
                    if (servicesNode == null)
                    {
                        continue;
                    }
                    else
                    {
                        // Get the calendar node name from the xml node attributes
                        serviceNodeName = servicesNode.Attributes.GetNamedItem("nodeName").Value.ToString();
                    }
                    // Check to see if the service calendar has at least one day selected
                    if (services[c].getProperty("serviceMonday").Value.ToString() == "0" && services[c].getProperty("serviceTuesday").Value.ToString() == "0" && services[c].getProperty("serviceWednesday").Value.ToString() == "0" && services[c].getProperty("serviceThursday").Value.ToString() == "0" && services[c].getProperty("serviceFriday").Value.ToString() == "0" && services[c].getProperty("serviceSaturday").Value.ToString() == "0" && services[c].getProperty("serviceSunday").Value.ToString() == "0")
                    {
                        message.Text = message.Text + "&#8226; <span style='color: red;'>Service Calendar <b>" + serviceNodeName + "</b> does not have any days chosen. A Service Calendar must have at least one day chosen.</span><br />";
                        errors++;
                        continue;
                    }
                    // Write the information
                    calendarsRecord.WriteLine(serviceNodeName + "," + services[c].getProperty("serviceMonday").Value.ToString() + "," + services[c].getProperty("serviceTuesday").Value.ToString() + "," + services[c].getProperty("serviceWednesday").Value.ToString() + "," + services[c].getProperty("serviceThursday").Value.ToString() + "," + services[c].getProperty("serviceFriday").Value.ToString() + "," + services[c].getProperty("serviceSaturday").Value.ToString() + "," + services[c].getProperty("serviceSunday").Value.ToString() + "," + services[c].getProperty("serviceStartDate").Value.ToString().Substring(6, 4) + services[c].getProperty("serviceStartDate").Value.ToString().Substring(3, 2) + services[c].getProperty("serviceStartDate").Value.ToString().Substring(0, 2) + "," + services[c].getProperty("serviceEndDate").Value.ToString().Substring(6, 4) + services[c].getProperty("serviceEndDate").Value.ToString().Substring(3, 2) + services[c].getProperty("serviceEndDate").Value.ToString().Substring(0, 2));
                    // Testing
                    testingRecord.WriteLine("service_id = " + serviceNodeName + "  |  monday = " + services[c].getProperty("serviceMonday").Value.ToString() + "  |  tuesday = " + services[c].getProperty("serviceTuesday").Value.ToString() + "  |  wednesday = " + services[c].getProperty("serviceWednesday").Value.ToString() + "  |  thursday = " + services[c].getProperty("serviceThursday").Value.ToString() + "  |  friday = " + services[c].getProperty("serviceFriday").Value.ToString() + "  |  saturday = " + services[c].getProperty("serviceSaturday").Value.ToString() + "  |  sunday = " + services[c].getProperty("serviceSunday").Value.ToString() + "  |  start_date = " + services[c].getProperty("serviceStartDate").Value.ToString().Substring(6, 4) + services[c].getProperty("serviceStartDate").Value.ToString().Substring(3, 2) + services[c].getProperty("serviceStartDate").Value.ToString().Substring(0, 2) + "  |  end_date = " + services[c].getProperty("serviceEndDate").Value.ToString().Substring(6, 4) + services[c].getProperty("serviceEndDate").Value.ToString().Substring(3, 2) + services[c].getProperty("serviceEndDate").Value.ToString().Substring(0, 2));
                }
                // Testing
                testingRecord.WriteLine("");

                // Get the calendar_dates.txt information from the Transit Service Calendar Exceptions children nodes and write it to calendarDatesRecord
                Document[] exceptions = new Document(exceptionsRoot).Children;
                // Testing
                testingRecord.WriteLine("calendar_dates.txt");
                for (int d = 0; d < exceptions.Length; d++)
                {
                    // Send the calendar exception to XML
                    XmlNode exceptionsNode = exceptions[d].ToXml(new XmlDocument(), false);
                    // Check to see if the exceptionsNode equals null, if so, the exception is not published
                    string exceptionNodeName;
                    if (exceptionsNode == null)
                    {
                        continue;
                    }
                    else
                    {
                        // Get the calendar exception node name from the xml node attributes
                        exceptionNodeName = exceptionsNode.Attributes.GetNamedItem("nodeName").Value.ToString();
                    }
                    // Check to see if the calendar exception has the removeService option selected
                    if (exceptions[d].getProperty("removeService").Value.ToString() == "-1")
                    {
                        message.Text = message.Text + "&#8226; <span style='color: red;'>Service Calendar Exception <b>" + exceptionNodeName + "</b> does not have a value for Remove Service. To create an exception, you must choose to remove a service.</span><br />";
                        errors++;
                        continue;
                    }
                    // Check to see if the calendar exception has the addService option selected
                    if (exceptions[d].getProperty("addService").Value.ToString() == "-1")
                    {
                        message.Text = message.Text + "&#8226; <span style='color: red;'>Service Calendar Exception <b>" + exceptionNodeName + "</b> does not have a value for Add Service. To create an exception, you must choose to add a service.</span><br />";
                        errors++;
                        continue;
                    }
                    // Check to see if the calendar exception's removeService and addService options are the same, if so pass error
                    if (exceptions[d].getProperty("removeService").Value.ToString() == exceptions[d].getProperty("addService").Value.ToString())
                    {
                        message.Text = message.Text + "&#8226; <span style='color: red;'>Service Calendar Exception <b>" + exceptionNodeName + "</b> has the same value for its Remove Service and Add Service options. The two options have to be different.</span><br />";
                        errors++;
                        continue;
                    }
                    // Write the first line which is the remove service line
                    calendarDatesRecord.WriteLine(exceptions[d].getProperty("removeService").Value.ToString() + "," + exceptions[d].getProperty("exceptionDate").Value.ToString().Substring(6, 4) + exceptions[d].getProperty("exceptionDate").Value.ToString().Substring(3, 2) + exceptions[d].getProperty("exceptionDate").Value.ToString().Substring(0, 2) + ",2");
                    // Write the second line which is the add service line
                    calendarDatesRecord.WriteLine(exceptions[d].getProperty("addService").Value.ToString() + "," + exceptions[d].getProperty("exceptionDate").Value.ToString().Substring(6, 4) + exceptions[d].getProperty("exceptionDate").Value.ToString().Substring(3, 2) + exceptions[d].getProperty("exceptionDate").Value.ToString().Substring(0, 2) + ",1");
                    // Testing
                    testingRecord.WriteLine("service_id = " + exceptions[d].getProperty("removeService").Value.ToString() + "  |  date = " + exceptions[d].getProperty("exceptionDate").Value.ToString().Substring(6, 4) + exceptions[d].getProperty("exceptionDate").Value.ToString().Substring(3, 2) + exceptions[d].getProperty("exceptionDate").Value.ToString().Substring(0, 2) + "  |  exception_type = 2");
                    testingRecord.WriteLine("service_id = " + exceptions[d].getProperty("addService").Value.ToString() + "  |  date = " + exceptions[d].getProperty("exceptionDate").Value.ToString().Substring(6, 4) + exceptions[d].getProperty("exceptionDate").Value.ToString().Substring(3, 2) + exceptions[d].getProperty("exceptionDate").Value.ToString().Substring(0, 2) + "  |  exception_type = 1");
                }
                // Testing
                testingRecord.WriteLine("");

                // Get the trips.txt information from the Transit Trips children nodes and write it to the tripsRecord
                Document[] trips = new Document(tripsRoot).Children;
                // Create the DataSet
                DataSet set = new DataSet("Trip_Stop_Times");
                // Loop through all trips and stop times and put them in a DataSet for using when a trip is based on another
                using (set)
                {
                    for (int m = 0; m < trips.Length; m++)
                    {
                        // Send the trip to XML
                        XmlNode tripsNode = trips[m].ToXml(new XmlDocument(), false);
                        // Check to see if the tripsNode equals null, if so, the trip is not published
                        string tripNodeName;
                        if (tripsNode == null)
                        {
                            continue;
                        }
                        else
                        {
                            // Get the trip node name from the xml node attributes
                            tripNodeName = tripsNode.Attributes.GetNamedItem("nodeName").Value.ToString();
                        }
                        // Check to see if the trip has a route selected
                        if (trips[m].getProperty("route").Value.ToString() == "-1")
                        {
                            continue;
                        }
                        // Check to see if the trip has a calendar selected
                        if (trips[m].getProperty("calendar").Value.ToString() == "-1")
                        {
                            continue;
                        }
                        // Create a table for this trip
                        DataTable table1 = new DataTable(tripNodeName);
                        table1.Columns.Add("tripHeadway");
                        table1.Columns.Add("stop_id");
                        table1.Columns.Add("arrival_time");
                        table1.Columns.Add("departure_time");
                        // Set the trip's stop times to a variable
                        Document[] stopTimes = trips[m].Children;
                        for (int n = 0; n < stopTimes.Length; n++)
                        {
                            // Send the stop time to XML
                            XmlNode stopTimesNode = stopTimes[n].ToXml(new XmlDocument(), false);
                            // Check to see if the stopTimesNode equals null, if so, the stop time is not published
                            string stopTimeNodeName;
                            if (stopTimesNode == null)
                            {
                                continue;
                            }
                            else
                            {
                                // Get the stop time node name from the xml node attributes
                                stopTimeNodeName = stopTimesNode.Attributes.GetNamedItem("nodeName").Value.ToString();
                            }
                            // Check to see if a stop has been selected
                            if (stopTimes[n].getProperty("transitStop").Value.ToString() == "-1")
                            {
                                continue;
                            }
                            // Check to see if a departure time has been given, if not set the departure time to the arrival time
                            string arrivalTime = stopTimes[n].getProperty("arrivalTime").Value.ToString();
                            string departureTime = stopTimes[n].getProperty("departureTime").Value.ToString();
                            if (String.IsNullOrEmpty(departureTime))
                            {
                                departureTime = arrivalTime;
                            }
                            // Create the DataTable row with the correct information for the columns
                            if (String.IsNullOrEmpty(trips[m].getProperty("tripHeadway").Value.ToString()))
                            {
                                table1.Rows.Add(null, stopTimes[n].getProperty("transitStop").Value.ToString(), arrivalTime, departureTime);
                            }
                            else
                            {
                                table1.Rows.Add(trips[m].getProperty("tripHeadway").Value.ToString(), stopTimes[n].getProperty("transitStop").Value.ToString(), arrivalTime, departureTime);
                            }
                        }
                        // Add the DataTables to the DataSet
                        set.Tables.Add(table1);
                    }
                }
                // Testing
                testingRecord.WriteLine("trips.txt");
                // Loop through and do all of the work
                for (int f = 0; f < trips.Length; f++)
                {
                    // Send the trip to XML
                    XmlNode tripsNode = trips[f].ToXml(new XmlDocument(), false);
                    // Check to see if the tripsNode equals null, if so, the trip is not published
                    string tripNodeName;
                    if (tripsNode == null)
                    {
                        continue;
                    }
                    else
                    {
                        // Get the trip node name from the xml node attributes
                        tripNodeName = tripsNode.Attributes.GetNamedItem("nodeName").Value.ToString();
                    }
                    // Check to see if the trip has a route selected
                    if (trips[f].getProperty("route").Value.ToString() == "-1")
                    {
                        message.Text = message.Text + "&#8226; <span style='color: red;'>Trip <b>" + tripNodeName + "</b> does not have a route selected.</span><br />";
                        errors++;
                        continue;
                    }
                    // Check to see if the trip has a calendar selected
                    if (trips[f].getProperty("calendar").Value.ToString() == "-1")
                    {
                        message.Text = message.Text + "&#8226; <span style='color: red;'>Trip <b>" + tripNodeName + "</b> does not have a calendar selected.</span><br />";
                        errors++;
                        continue;
                    }
                    // Set the direction of the trip if it has been given a value
                    string direction;
                    if (String.IsNullOrEmpty(trips[f].getProperty("tripDirection").Value.ToString()))
                    {
                        direction = "";
                    }
                    else
                    {
                        if (trips[f].getProperty("tripDirection").Value.ToString() == "96" || trips[f].getProperty("tripDirection").Value.ToString() == "57")
                        {
                            direction = "0";
                        }
                        else
                        {
                            direction = "1";
                        }
                    }
                    // Testing
                    // message.Text = message.Text + "&#8226; <span style='color: red;'>Trip <b>" + tripNodeName + "</b> direction is: " + trips[f].getProperty("tripDirection").Value.ToString() + ".</span><br />";
                    // Set the trip's stop times to a variable
                    Document[] stopTimes = trips[f].Children;
                    // Check to see if the current trip is based on another.
                    if (trips[f].getProperty("tripBasedOn").Value.ToString() == "-1")
                    {
                        // The trip is not based on another, check to see if there are any stopTimes. If not, is it possible that they accidently meant to base it off of another
                        if (stopTimes.Length == 0)
                        {
                            message.Text = message.Text + "&#8226; <span style='color: red;'>Trip <b>" + tripNodeName + "</b> does not have any stop times provided. Did you mean to base it off of another trip and didn't?</span><br />";
                            errors++;
                            continue;
                        }
                        // Check to see if there is a tripHeadway
                        if (String.IsNullOrEmpty(trips[f].getProperty("tripHeadway").Value.ToString()))
                        {
                            // There is not a tripHeadway, write out the trip
                            tripsRecord.WriteLine(trips[f].getProperty("route").Value.ToString() + "," + trips[f].getProperty("calendar").Value.ToString() + "," + tripNodeName + "," + trips[f].getProperty("tripHeadsign").Value.ToString().Replace(",", " ") + "," + direction + ",,");
                            // Testing
                            testingRecord.WriteLine("");
                            testingRecord.WriteLine("route_id = " + trips[f].getProperty("route").Value.ToString() + "  |  service_id = " + trips[f].getProperty("calendar").Value.ToString() + "  |  trip_id = " + tripNodeName + "  |  trip_headsign = " + trips[f].getProperty("tripHeadsign").Value.ToString().Replace(",", " ") + "  |  direction_id = " + direction + "  |  block_id =  |  shape_id = ");
                            // Loop through each of the stop times and write to the stopTimesRecord
                            for (int g = 0; g < stopTimes.Length; g++)
                            {
                                // Send the stop time to XML
                                XmlNode stopTimesNode = stopTimes[g].ToXml(new XmlDocument(), false);
                                // Check to see if the stopTimesNode equals null, if so, the stop time is not published
                                string stopTimeNodeName;
                                if (stopTimesNode == null)
                                {
                                    continue;
                                }
                                else
                                {
                                    // Get the stop time node name from the xml node attributes
                                    stopTimeNodeName = stopTimesNode.Attributes.GetNamedItem("nodeName").Value.ToString();
                                }
                                // Check to see if a stop has been selected
                                if (stopTimes[g].getProperty("transitStop").Value.ToString() == "-1")
                                {
                                    message.Text = message.Text + "&#8226; <span style='color: red;'>Stop Time <b>" + stopTimeNodeName + "</b> does not have a stop selected.</span><br />";
                                    errors++;
                                    continue;
                                }
                                // Check to see if a departure time has been given, if not set the departure time to the arrival time
                                string arrivalTime = stopTimes[g].getProperty("arrivalTime").Value.ToString();
                                string departureTime = stopTimes[g].getProperty("departureTime").Value.ToString();
                                if (String.IsNullOrEmpty(departureTime))
                                {
                                    departureTime = arrivalTime;
                                }
                                // Write out the stop times
                                stopTimesRecord.WriteLine(tripNodeName + "," + arrivalTime + "," + departureTime + "," + stopTimes[g].getProperty("transitStop").Value.ToString() + "," + (g + 1) + ",,0,0,");
                                // Testing
                                testingRecord.WriteLine("     stop_times.txt:  trip_id = " + tripNodeName + "  |  arrival_time = " + arrivalTime + "  |  departure_time = " + departureTime + "  |  stop_id = " + stopTimes[g].getProperty("transitStop").Value.ToString() + "  |  stop_sequence = " + (g + 1) + "  |  stop_headsign =  |  pickup_type = 0  |  drop_off_type = 0  |  shape_dist_traveled = ");
                            }
                        }
                        else
                        {
                            // There is a tripHeadway
                            // Check to make sure that there is a calendarStartTime and calendarEndTime
                            if (String.IsNullOrEmpty(trips[f].getProperty("calendarStartTime").Value.ToString()) || String.IsNullOrEmpty(trips[f].getProperty("calendarEndTime").Value.ToString()))
                            {
                                message.Text = message.Text + "&#8226; <span style='color: red;'>Trip <b>" + tripNodeName + "</b> has a Trip Headway provided, but does not have a Calendar Start Time or Calendar End Time provided.</span><br />";
                                errors++;
                                continue;
                            }
                            // Create DateTime objects out of the present CalendarStartTime and CalendarEndTime
                            DateTime calendarStartTime = new DateTime(2011, 1, 1, Convert.ToInt32(trips[f].getProperty("calendarStartTime").Value.ToString().Substring(0, 2)), Convert.ToInt32(trips[f].getProperty("calendarStartTime").Value.ToString().Substring(3, 2)), Convert.ToInt32(trips[f].getProperty("calendarStartTime").Value.ToString().Substring(6, 2)));
                            DateTime calendarEndTime = new DateTime(2011, 1, 1, Convert.ToInt32(trips[f].getProperty("calendarEndTime").Value.ToString().Substring(0, 2)), Convert.ToInt32(trips[f].getProperty("calendarEndTime").Value.ToString().Substring(3, 2)), Convert.ToInt32(trips[f].getProperty("calendarEndTime").Value.ToString().Substring(6, 2)));
                            // Find the nextStartTime
                            string lastTime;
                            if (String.IsNullOrEmpty(stopTimes[stopTimes.Length - 1].getProperty("departureTime").Value.ToString()))
                            {
                                lastTime = stopTimes[stopTimes.Length - 1].getProperty("arrivalTime").Value.ToString();
                            }
                            else
                            {
                                lastTime = stopTimes[stopTimes.Length - 1].getProperty("departureTime").Value.ToString();
                            }
                            DateTime lastStopTime = new DateTime(2011, 1, 1, Convert.ToInt32(lastTime.Substring(0, 2)), Convert.ToInt32(lastTime.Substring(3, 2)), Convert.ToInt32(lastTime.Substring(6, 2)));
                            // Create a double variable out of the tripHeadway
                            double headway = Convert.ToInt32(trips[f].getProperty("tripHeadway").Value.ToString());
                            // Add the tripHeadway to the nextStartTime to get the real nextStartTime
                            DateTime nextStartTime = lastStopTime.AddSeconds(headway);
                            // Find the hour difference between the nextStartTime and all of the stopTimes
                            string arrivalTime;
                            string departureTime;
                            int stopTimeHour;
                            int nextStartTimeHour = Convert.ToInt32(nextStartTime.ToString("HH"));
                            int[] hourDifferences = new int[stopTimes.Length];
                            // Testing
                            // testingRecord.WriteLine("");
                            // testingRecord.WriteLine("Stop Time Information:");
                            for (int h = 0; h < stopTimes.Length; h++)
                            {
                                // Send the stop time to XML
                                XmlNode stopTimesNode = stopTimes[h].ToXml(new XmlDocument(), false);
                                // Check to see if a departureTime has been given, if not, set the departureTime to the arrivalTime
                                arrivalTime = stopTimes[h].getProperty("arrivalTime").Value.ToString();
                                departureTime = stopTimes[h].getProperty("departureTime").Value.ToString();
                                if (String.IsNullOrEmpty(departureTime))
                                {
                                    departureTime = arrivalTime;
                                }
                                // Assign the stopTimeHour
                                stopTimeHour = Convert.ToInt32(departureTime.Substring(0, 2));
                                hourDifferences[h] = nextStartTimeHour - stopTimeHour;
                                // Testing
                                //testingRecord.WriteLine("");
                                //testingRecord.WriteLine("CalendarStartTime: " + calendarStartTime.ToString() + " | CalendarEndTime: " + calendarEndTime.ToString() + " | Stop Time: " + departureTime + " | Stop Time Hour: " + stopTimeHour.ToString() + " | Next Start Time of Trip: " + nextStartTime.ToString() + " | Next Start Time Hour: " + nextStartTimeHour.ToString() + " | Hour Difference: " + hourDifferences[h].ToString());
                            }
                            // Create a variable for iteration
                            int sequence = 1;
                            // Grab the first hour of the stopTimes sequence
                            string firstTime;
                            if (String.IsNullOrEmpty(stopTimes[0].getProperty("departureTime").Value.ToString()))
                            {
                                firstTime = stopTimes[0].getProperty("arrivalTime").Value.ToString();
                            }
                            else
                            {
                                firstTime = stopTimes[0].getProperty("departureTime").Value.ToString();
                            }
                            int currentHour = Convert.ToInt32(firstTime.Substring(0, 2));
                            string hasBeenIncreased = "no";
                            // While the nextStartTime is less than the calendarEndTime, loop through the stopTimes and write them and a trip with every pass
                            while (nextStartTime < calendarEndTime)
                            {
                                // Write the trip
                                tripsRecord.WriteLine(trips[f].getProperty("route").Value.ToString() + "," + trips[f].getProperty("calendar").Value.ToString() + "," + tripNodeName + "_" + sequence.ToString() + "," + trips[f].getProperty("tripHeadsign").Value.ToString().Replace(",", " ") + "," + direction + ",,");
                                // Testing
                                testingRecord.WriteLine("");
                                testingRecord.WriteLine("route_id = " + trips[f].getProperty("route").Value.ToString() + "  |  service_id = " + trips[f].getProperty("calendar").Value.ToString() + "  |  trip_id = " + tripNodeName + "_" + sequence.ToString() + "  |  trip_headsign = " + trips[f].getProperty("tripHeadsign").Value.ToString().Replace(",", " ") + "  |  direction_id = " + direction + "  |  block_id =  |  shape_id = ");
                                // Loop through each of the stop times and write to the stopTimesRecord
                                for (int g = 0; g < stopTimes.Length; g++)
                                {
                                    // Send the stop time to XML
                                    XmlNode stopTimesNode = stopTimes[g].ToXml(new XmlDocument(), false);
                                    // Check to see if the stopTimesNode equals null, if so, the stop time is not published
                                    string stopTimeNodeName;
                                    if (stopTimesNode == null)
                                    {
                                        continue;
                                    }
                                    else
                                    {
                                        // Get the stop time node name from the xml node attributes
                                        stopTimeNodeName = stopTimesNode.Attributes.GetNamedItem("nodeName").Value.ToString().Replace(",", " ");
                                    }
                                    // Check to see if a stop has been selected
                                    if (stopTimes[g].getProperty("transitStop").Value.ToString() == "-1")
                                    {
                                        message.Text = message.Text + "&#8226; <span style='color: red;'>Stop Time <b>" + stopTimeNodeName + "</b> does not have a stop selected.</span><br />";
                                        errors++;
                                        continue;
                                    }
                                    // If the hourDifference is 0, then increase the currentHour
                                    //if (hourDifferences[g] == 0 && hasBeenIncreased == "no")
                                    if (g != 0)
                                    {
                                        if (hourDifferences[g] < hourDifferences[g - 1] && hasBeenIncreased == "no")
                                        {
                                            currentHour++;
                                            hasBeenIncreased = "yes";
                                        }
                                    }
                                    // Check to see if a departure time has been given, if not, set the departure time to the arrival time
                                    string arrivalTime2;
                                    string departureTime2;
                                    arrivalTime2 = currentHour.ToString() + stopTimes[g].getProperty("arrivalTime").Value.ToString().Substring(2, 6);
                                    departureTime2 = stopTimes[g].getProperty("departureTime").Value.ToString();
                                    if (String.IsNullOrEmpty(departureTime2))
                                    {
                                        departureTime2 = arrivalTime2;
                                    }
                                    else
                                    {
                                        departureTime2 = currentHour.ToString() + stopTimes[g].getProperty("departureTime").Value.ToString().Substring(2, 6);
                                    }
                                    // Testing
                                    testingRecord.WriteLine("CurrentHour: " + currentHour.ToString() + " | Has Been Increased: " + hasBeenIncreased);
                                    // Write out the stop times
                                    stopTimesRecord.WriteLine(tripNodeName + "_" + sequence.ToString() + "," + arrivalTime2 + "," + departureTime2 + "," + stopTimes[g].getProperty("transitStop").Value.ToString() + "," + (g + 1) + ",,0,0,");
                                    // Testing
                                    testingRecord.WriteLine("     stop_times.txt:  trip_id = " + tripNodeName + "_" + sequence.ToString() + "  |  arrival_time = " + arrivalTime2 + "  |  departure_time = " + departureTime2 + "  |  stop_id = " + stopTimes[g].getProperty("transitStop").Value.ToString() + "  |  stop_sequence = " + (g + 1) + "  |  stop_headsign =  |  pickup_type = 0  |  drop_off_type = 0  |  shape_dist_traveled = ");
                                }
                                // Set the new hour to be working with
                                nextStartTime = new DateTime(2011, 1, 1, currentHour, Convert.ToInt32(lastTime.Substring(3, 2)), Convert.ToInt32(lastTime.Substring(6, 2)));
                                nextStartTime = nextStartTime.AddSeconds(headway);
                                currentHour = Convert.ToInt32(nextStartTime.ToString("HH"));
                                hasBeenIncreased = "no";
                                // Testing
                                // testingRecord.WriteLine("Next Start Time: " + nextStartTime.ToString());
                                // Increase the sequence variable
                                sequence++;
                            }
                        }
                    }
                    else
                    {
                        // Check to see that the trip has a calendarStartTime and calendarEndTime
                        if (String.IsNullOrEmpty(trips[f].getProperty("calendarStartTime").Value.ToString()) || String.IsNullOrEmpty(trips[f].getProperty("calendarEndTime").Value.ToString()))
                        {
                            message.Text = message.Text + "&#8226; <span style='color: red;'>Trip <b>" + tripNodeName + "</b> is based off of another trip, but does not have a Calendar Start Time or Calendar End Time provided.</span><br />";
                            errors++;
                            continue;
                        }
                        // Check to see if the trip that this trip is based on has a tripHeadway
                        if (DBNull.Value.Equals(set.Tables[trips[f].getProperty("tripBasedOn").Value.ToString()].Rows[0]["tripHeadway"]))
                        {
                            // There is NO tripHeadway in the based on trip
                            // Write out the trip
                            tripsRecord.WriteLine(trips[f].getProperty("route").Value.ToString() + "," + trips[f].getProperty("calendar").Value.ToString() + "," + tripNodeName + "," + trips[f].getProperty("tripHeadsign").Value.ToString().Replace(",", " ") + "," + direction + ",,");
                            // Testing
                            testingRecord.WriteLine("");
                            testingRecord.WriteLine("route_id = " + trips[f].getProperty("route").Value.ToString() + "  |  service_id = " + trips[f].getProperty("calendar").Value.ToString() + "  |  trip_id = " + tripNodeName + "  |  trip_headsign = " + trips[f].getProperty("tripHeadsign").Value.ToString().Replace(",", " ") + "  |  direction_id = " + direction + "  |  block_id =  |  shape_id = ");
                            // Find out how many hours separate the calendarStartTime of the trip and the based on trip's stop times
                            int hourDifference;
                            // Loop through each of the stop times and write to the stopTimesRecord
                            for (int r = 0; r < set.Tables[trips[f].getProperty("tripBasedOn").Value.ToString()].Rows.Count; r++)
                            {
                                // Find the new arrival and departure times created by the trip's calendarStartTime
                                hourDifference = Convert.ToInt32(trips[f].getProperty("calendarStartTime").Value.ToString().Substring(0, 2)) - Convert.ToInt32(set.Tables[trips[f].getProperty("tripBasedOn").Value.ToString()].Rows[r]["arrival_time"].ToString().Substring(0, 2));
                                int newArrivalTimeHour = Convert.ToInt32(set.Tables[trips[f].getProperty("tripBasedOn").Value.ToString()].Rows[r]["arrival_time"].ToString().Substring(0, 2)) + hourDifference;
                                int newDepartureTimeHour = Convert.ToInt32(set.Tables[trips[f].getProperty("tripBasedOn").Value.ToString()].Rows[r]["departure_time"].ToString().Substring(0, 2)) + hourDifference;
                                string newArrivalTime = newArrivalTimeHour.ToString() + set.Tables[trips[f].getProperty("tripBasedOn").Value.ToString()].Rows[r]["arrival_time"].ToString().Substring(2, 6);
                                string newDepartureTime = newDepartureTimeHour.ToString() + set.Tables[trips[f].getProperty("tripBasedOn").Value.ToString()].Rows[r]["departure_time"].ToString().Substring(2, 6);
                                // Write out the stop times
                                stopTimesRecord.WriteLine(tripNodeName + "," + newArrivalTime + "," + newDepartureTime + "," + set.Tables[trips[f].getProperty("tripBasedOn").Value.ToString()].Rows[r]["stop_id"] + "," + (r + 1) + ",,0,0,");
                                // Testing
                                testingRecord.WriteLine("     stop_times.txt:  trip_id = " + tripNodeName + "  |  arrival_time = " + newArrivalTime + "  |  departure_time = " + newDepartureTime + "  |  stop_id = " + set.Tables[trips[f].getProperty("tripBasedOn").Value.ToString()].Rows[r]["stop_id"] + "  |  stop_sequence = " + (r + 1) + "  |  stop_headsign =  |  pickup_type = 0  |  drop_off_type = 0  |  shape_dist_traveled = ");
                            }
                        }
                        else
                        {
                            // There is a tripHeadway in the based on trip
                            // Create DateTime objects out of the present CalendarStartTime and CalendarEndTime
                            DateTime calendarStartTime = new DateTime(2011, 1, 1, Convert.ToInt32(trips[f].getProperty("calendarStartTime").Value.ToString().Substring(0, 2)), Convert.ToInt32(trips[f].getProperty("calendarStartTime").Value.ToString().Substring(3, 2)), Convert.ToInt32(trips[f].getProperty("calendarStartTime").Value.ToString().Substring(6, 2)));
                            DateTime calendarEndTime = new DateTime(2011, 1, 1, Convert.ToInt32(trips[f].getProperty("calendarEndTime").Value.ToString().Substring(0, 2)), Convert.ToInt32(trips[f].getProperty("calendarEndTime").Value.ToString().Substring(3, 2)), Convert.ToInt32(trips[f].getProperty("calendarEndTime").Value.ToString().Substring(6, 2)));
                            // Find out how many stops where in the based on trip
                            int stopTimesLength = set.Tables[trips[f].getProperty("tripBasedOn").Value.ToString()].Rows.Count;
                            // Find the nextStartTime of the based on trip
                            string lastTime;
                            if (String.IsNullOrEmpty(set.Tables[trips[f].getProperty("tripBasedOn").Value.ToString()].Rows[stopTimesLength - 1]["departure_time"].ToString()))
                            {
                                lastTime = set.Tables[trips[f].getProperty("tripBasedOn").Value.ToString()].Rows[stopTimesLength - 1]["arrival_time"].ToString();
                            }
                            else
                            {
                                lastTime = set.Tables[trips[f].getProperty("tripBasedOn").Value.ToString()].Rows[stopTimesLength - 1]["departure_time"].ToString();
                            }
                            DateTime lastStopTime = new DateTime(2011, 1, 1, Convert.ToInt32(lastTime.Substring(0, 2)), Convert.ToInt32(lastTime.Substring(3, 2)), Convert.ToInt32(lastTime.Substring(6, 2)));
                            // Create a double variable out of the tripHeadway of the based on trip
                            double headway = Convert.ToInt32(set.Tables[trips[f].getProperty("tripBasedOn").Value.ToString()].Rows[0]["tripHeadway"]);
                            // Add the tripHeadway to the nextStartTime to get the real nextStartTime
                            DateTime nextStartTime = lastStopTime.AddSeconds(headway);
                            // Find the hourDifferences between the nextStartTime and all of the stopTimes
                            string arrivalTime;
                            string departureTime;
                            int stopTimeHour;
                            int nextStartTimeHour = Convert.ToInt32(nextStartTime.ToString("HH"));
                            int[] hourDifferences = new int[stopTimesLength];
                            // Testing
                            // testingRecord.WriteLine("");
                            // testingRecord.WriteLine("Stop Time Information: ");
                            for (int h = 0; h < stopTimesLength; h++)
                            {
                                arrivalTime = set.Tables[trips[f].getProperty("tripBasedOn").Value.ToString()].Rows[h]["arrival_time"].ToString();
                                departureTime = set.Tables[trips[f].getProperty("tripBasedOn").Value.ToString()].Rows[h]["departure_time"].ToString();
                                // Assign the stopTimeHour
                                stopTimeHour = Convert.ToInt32(departureTime.Substring(0, 2));
                                hourDifferences[h] = nextStartTimeHour - stopTimeHour;
                                // Testing
                                // testingRecord.WriteLine("CalendarStartTime: " + calendarStartTime.ToString() + " | CalendarEndTime: " + calendarEndTime.ToString() + " | Stop Time: " + departureTime + " | Stop Time Hour: " + stopTimeHour.ToString() + " | Next Start Time of Trip: " + nextStartTime.ToString() + " | Next Start Time Hour: " + nextStartTimeHour.ToString() + " | Hour Difference: " + hourDifferences[h].ToString());
                            }
                            // Create a variable for iteration
                            int sequence = 1;
                            // Grab the first hour of the stopTimes sequence
                            string firstTime = set.Tables[trips[f].getProperty("tripBasedOn").Value.ToString()].Rows[0]["departure_time"].ToString();
                            int currentHour = Convert.ToInt32(firstTime.Substring(0, 2));
                            string hasBeenIncreased = "no";
                            // While the nextStartTime is less than the calendarEndTime, loop through the stopTimes and write them and a trip with every pass
                            while (nextStartTime < calendarEndTime)
                            {
                                // Testing
                                testingRecord.WriteLine("");
                                // Create a DateTime object for the next arrivalTime and test that it is in the calendarStartTime and calendarEndTime scope
                                DateTime arrivalTimeTest;
                                // Loop through each of the stop times and write to the stopTimesRecord
                                for (int g = 0; g < stopTimesLength; g++)
                                {
                                    // If the hourDifference is 0, then increase the currentHour
                                    if (g != 0)
                                    {
                                        if (hourDifferences[g] < hourDifferences[g - 1] && hasBeenIncreased == "no")
                                        {
                                            currentHour++;
                                            hasBeenIncreased = "yes";
                                        }
                                    }
                                    // Assign the arrivalTime2 and departureTime2 values
                                    string arrivalTime2;
                                    string departureTime2;
                                    arrivalTime2 = currentHour.ToString() + set.Tables[trips[f].getProperty("tripBasedOn").Value.ToString()].Rows[g]["arrival_time"].ToString().Substring(2, 6);
                                    departureTime2 = currentHour.ToString() + set.Tables[trips[f].getProperty("tripBasedOn").Value.ToString()].Rows[g]["departure_time"].ToString().Substring(2, 6);
                                    // Testing
                                    // testingRecord.WriteLine("CurrentHour: " + currentHour.ToString());
                                    // Set arrivalTimeTest
                                    arrivalTimeTest = new DateTime(2011, 1, 1, currentHour, Convert.ToInt32(set.Tables[trips[f].getProperty("tripBasedOn").Value.ToString()].Rows[0]["arrival_time"].ToString().Substring(3, 2)), Convert.ToInt32(set.Tables[trips[f].getProperty("tripBasedOn").Value.ToString()].Rows[0]["arrival_time"].ToString().Substring(6, 2)));
                                    if (arrivalTimeTest >= calendarStartTime && g != stopTimesLength - 1)
                                    {
                                        // Write out the stop times
                                        stopTimesRecord.WriteLine(tripNodeName + "_" + sequence.ToString() + "," + arrivalTime2 + "," + departureTime2 + "," + set.Tables[trips[f].getProperty("tripBasedOn").Value.ToString()].Rows[g]["stop_id"] + "," + (g + 1) + ",,0,0,");
                                        // Testing
                                        testingRecord.WriteLine("     stop_times.txt:  trip_id = " + tripNodeName + "_" + sequence.ToString() + "  |  arrival_time = " + arrivalTime2 + "  |  departure_time = " + departureTime2 + "  |  stop_id = " + set.Tables[trips[f].getProperty("tripBasedOn").Value.ToString()].Rows[g]["stop_id"] + "  |  stop_sequence = " + (g + 1) + "  |  stop_headsign =  |  pickup_type = 0  |  drop_off_type = 0  |  shape_dist_traveled = ");
                                    }
                                }
                                // Set arrivalTimeTest
                                arrivalTimeTest = new DateTime(2011, 1, 1, currentHour, Convert.ToInt32(set.Tables[trips[f].getProperty("tripBasedOn").Value.ToString()].Rows[0]["arrival_time"].ToString().Substring(3, 2)), Convert.ToInt32(set.Tables[trips[f].getProperty("tripBasedOn").Value.ToString()].Rows[0]["arrival_time"].ToString().Substring(6, 2)));
                                // Testing
                                testingRecord.WriteLine("Arrival Time Test: " + arrivalTimeTest);
                                // Write a variable for when a trip gets written
                                string tripWritten = "no";
                                // Only write the trip if the arrivalTimeTest is within the scope
                                if (arrivalTimeTest >= calendarStartTime)
                                {
                                    // Write the trip
                                    tripsRecord.WriteLine(trips[f].getProperty("route").Value.ToString() + "," + trips[f].getProperty("calendar").Value.ToString() + "," + tripNodeName + "_" + sequence.ToString() + "," + trips[f].getProperty("tripHeadsign").Value.ToString().Replace(",", " ") + "," + direction + ",,");
                                    // Testing
                                    testingRecord.WriteLine("route_id = " + trips[f].getProperty("route").Value.ToString() + "  |  service_id = " + trips[f].getProperty("calendar").Value.ToString() + "  |  trip_id = " + tripNodeName + "_" + sequence.ToString() + "  |  trip_headsign = " + trips[f].getProperty("tripHeadsign").Value.ToString().Replace(",", " ") + "  |  direction_id = " + direction + "  |  block_id =  |  shape_id = ");
                                    testingRecord.WriteLine("");
                                    // Set tripWritten to yes
                                    tripWritten = "yes";
                                }
                                // Set the new hour
                                nextStartTime = new DateTime(2011, 1, 1, currentHour, Convert.ToInt32(lastTime.Substring(3, 2)), Convert.ToInt32(lastTime.Substring(3, 2)));
                                nextStartTime = nextStartTime.AddSeconds(headway);
                                currentHour = Convert.ToInt32(nextStartTime.ToString("HH"));
                                hasBeenIncreased = "no";
                                // Testing
                                // testingRecord.WriteLine("Next Start Time: " + nextStartTime.ToString());
                                // Increase the sequence variable
                                if (tripWritten == "yes")
                                {
                                    sequence++;
                                }
                            }
                        }
                        //testingRecord.WriteLine("");
                        //testingRecord.WriteLine("Table Name: " + set.Tables[tripNodeName] + " | Table that it is based on = " + trips[f].getProperty("tripBasedOn").Value.ToString() + " | Based on Tables's Row Count: = " + set.Tables[trips[f].getProperty("tripBasedOn").Value.ToString()].Rows.Count + " | Based on tables's tripHeadway = " + set.Tables[trips[f].getProperty("tripBasedOn").Value.ToString()].Rows[0]["tripHeadway"]);
                        //testingRecord.WriteLine("");
                    }
                }
                // Testing
                testingRecord.WriteLine("");

                // Get the fare_attributes.txt information from the Transit Fares children nodes and write it to fareAttributesRecord
                Document[] fares = new Document(faresRoot).Children;
                // Testing
                testingRecord.WriteLine("fare_attributes.txt");
                for (int h = 0; h < fares.Length; h++)
                {
                    // Send the fare to XML
                    XmlNode faresNode = fares[h].ToXml(new XmlDocument(), false);
                    // Check to see if the faresNode equals null, if so, the fare is not published
                    string fareNodeName;
                    if (faresNode == null)
                    {
                        continue;
                    }
                    else
                    {
                        // Get the route node name from the xml node attributes
                        fareNodeName = faresNode.Attributes.GetNamedItem("nodeName").Value.ToString();
                    }
                    // Set the transfer option to a value - 0 = No transfers allowed, 1 = 1 transfer allowed, 2 = 2 transfers allowed and empty = Unlimited transfers allowed
                    string transfers;
                    if (fares[h].getProperty("fareTransfers").Value.ToString() == "135")
                    {
                        transfers = "0";
                    }
                    else if (fares[h].getProperty("fareTransfers").Value.ToString() == "136")
                    {
                        transfers = "1";
                    }
                    else if (fares[h].getProperty("fareTransfers").Value.ToString() == "137")
                    {
                        transfers = "2";
                    }
                    else
                    {
                        transfers = "";
                    }
                    // Check to see if a transfer duration has been provided if a transfer is available, if not, return an error
                    if ((transfers == "1" || transfers == "2" || transfers == "") && String.IsNullOrEmpty(fares[h].getProperty("fareTransferDuration").Value.ToString()))
                    {
                        message.Text = message.Text + "&#8226; <span style='color: red;'>Fare <b>" + fareNodeName + "</b> has transfers allowed, but does not have a transfer duration provided.</span><br />";
                        errors++;
                        continue;
                    }
                    // Write the fare attribute information
                    fareAttributesRecord.WriteLine(fareNodeName + "," + fares[h].getProperty("farePrice").Value.ToString() + ",USD,0," + transfers + "," + fares[h].getProperty("fareTransferDuration").Value.ToString());
                    // Testing
                    testingRecord.WriteLine("");
                    testingRecord.WriteLine("fare_id = " + fareNodeName + "  |  price = " + fares[h].getProperty("farePrice").Value.ToString() + "  |  currency_type = USD  |  payment_method = 0  |  transfers = " + transfers + "  |  transfer_duration = " + fares[h].getProperty("fareTransferDuration").Value.ToString());
                    // Check to see if they are using the Routes or Origin and Destination Zones, if they are not using one or the other, return an error
                    if (String.IsNullOrEmpty(fares[h].getProperty("fareRoutes").Value.ToString()) && fares[h].getProperty("fareOriginZone").Value.ToString() == "-1" && fares[h].getProperty("fareDestinationZone").Value.ToString() == "-1")
                    {
                        message.Text = message.Text + "&#8226; <span style='color: red;'>Fare <b>" + fareNodeName + "</b> does not have any Routes selected or does not have an Origin Zone and Destination Zone selected.</span><br />";
                        errors++;
                        continue;
                    }
                    // Check to see if they are using Routes and not Origin and Destination Zones
                    if (!String.IsNullOrEmpty(fares[h].getProperty("fareRoutes").Value.ToString()) && fares[h].getProperty("fareOriginZone").Value.ToString() == "-1" && fares[h].getProperty("fareDestinationZone").Value.ToString() == "-1")
                    {
                        // Take the csv fareRoutes string and separate it by comma
                        string[] fareRoutes = fares[h].getProperty("fareRoutes").Value.ToString().Split(',');
                        // Loop through the fareRoutes string and add a new fare rule to the fareRulesRecord for each
                        for (int g = 0; g < fareRoutes.Length; g++)
                        {
                            // Write the fare rules information
                            fareRulesRecord.WriteLine(fareNodeName + "," + fareRoutes[g] + ",,,");
                            // Testing
                            testingRecord.WriteLine("     fare_rules.txt:  fare_id = " + fareNodeName + "  |  route_id = " + fareRoutes[g] + "  |  origin_id =  |  destination_id =  | contains_id = ");
                        }
                    }
                    // Check to see if they are using Origin and Destination Zones, these options will override the Routes
                    if ((!String.IsNullOrEmpty(fares[h].getProperty("fareRoutes").Value.ToString()) || String.IsNullOrEmpty(fares[h].getProperty("fareRoutes").Value.ToString())) && (fares[h].getProperty("fareOriginZone").Value.ToString() != "-1" || fares[h].getProperty("fareDestinationZone").Value.ToString() != "-1"))
                    {
                        // Check to see that both the Origin Zone and Destination Zone have been selected, if they haven't, return an error
                        if (fares[h].getProperty("fareOriginZone").Value.ToString() == "-1" && fares[h].getProperty("fareDestinationZone").Value.ToString() == "-1")
                        {
                            message.Text = message.Text + "&#8226; <span style='color: red;'>Fare <b>" + fareNodeName + "</b> has a Origin Zone selected or a Destination Zone selected but not both. Both must be selected if that is the option chosen.</span><br />";
                            errors++;
                            continue;
                        }
                        // Write the fare rules information with the Origin and Destination Zone options
                        fareRulesRecord.WriteLine(fareNodeName + ",," + fares[h].getProperty("fareOriginZone").Value.ToString() + "," + fares[h].getProperty("fareDestinationZone").Value.ToString() + ",");
                        // Testing
                        testingRecord.WriteLine("     fare_rules.txt:  fare_id = " + fareNodeName + "  |  route_id =  |  origin_id = " + fares[h].getProperty("fareOriginZone").Value.ToString() + "  |  destination_zone = " + fares[h].getProperty("fareDestinationZone").Value.ToString() + "  |  contains_id = ");
                    }
                }
                // Testing
                testingRecord.WriteLine("");

                // Close and Dispose of all Records and run GC.Collect()
                agencyRecord.Close();
                feedInfoRecord.Close();
                routesRecord.Close();
                stopsRecord.Close();
                calendarsRecord.Close();
                calendarDatesRecord.Close();
                tripsRecord.Close();
                stopTimesRecord.Close();
                fareAttributesRecord.Close();
                fareRulesRecord.Close();
                testingRecord.Close();

                agencyRecord.Dispose();
                feedInfoRecord.Dispose();
                routesRecord.Dispose();
                stopsRecord.Dispose();
                calendarsRecord.Dispose();
                calendarDatesRecord.Dispose();
                tripsRecord.Dispose();
                stopTimesRecord.Dispose();
                fareAttributesRecord.Dispose();
                fareRulesRecord.Dispose();
                testingRecord.Dispose();

                GC.Collect();
            }
            catch (IOException except)
            {
                status.Text = except.Message;
            }

            // If there are no errors, zip up the files and validate the feed
            if (errors > 0)
            {
                status.Text = "<b>Feed NOT Published.</b> Last attempted -- " + DateTime.Now.ToString("dddd, MMMM dd, yyyy hh:mm tt");
                if (errors == 1)
                {
                    message.Text = message.Text + "<br /><b>There is currently " + errors + " error in your transit grouping.</b><br /><br />The Feed Creation has been halted until this error can be resolved.";
                }
                else
                {
                    message.Text = message.Text + "<br /><b>There are currently " + errors + " errors in your transit grouping.</b><br /><br />The Feed Creation has been halted until these errors can be resolved.";
                }
            }
            else
            {
                // Zip up the txt files
                if (!File.Exists(transitDirectory + "\\" + arch))
                {
                    ZipFile output = new ZipFile();
                    output.AddFile(transitDirectory + "\\agency.txt", ".");
                    output.AddFile(transitDirectory + "\\feed_info.txt", ".");
                    output.AddFile(transitDirectory + "\\routes.txt", ".");
                    output.AddFile(transitDirectory + "\\stops.txt", ".");
                    output.AddFile(transitDirectory + "\\calendar.txt", ".");
                    output.AddFile(transitDirectory + "\\calendar_dates.txt", ".");
                    output.AddFile(transitDirectory + "\\trips.txt", ".");
                    output.AddFile(transitDirectory + "\\stop_times.txt", ".");
                    output.AddFile(transitDirectory + "\\fare_attributes.txt", ".");
                    output.AddFile(transitDirectory + "\\fare_rules.txt", ".");
                    output.Name = transitDirectory + "\\" + arch;
                    output.Save();
                    output.Dispose();
                    GC.Collect();
                }
                else
                {
                    ZipFile output = new ZipFile(transitDirectory + "\\" + arch);
                    output.UpdateFile(transitDirectory + "\\agency.txt", ".");
                    output.UpdateFile(transitDirectory + "\\feed_info.txt", ".");
                    output.UpdateFile(transitDirectory + "\\routes.txt", ".");
                    output.UpdateFile(transitDirectory + "\\stops.txt", ".");
                    output.UpdateFile(transitDirectory + "\\calendar.txt", ".");
                    output.UpdateFile(transitDirectory + "\\calendar_dates.txt", ".");
                    output.UpdateFile(transitDirectory + "\\trips.txt", ".");
                    output.UpdateFile(transitDirectory + "\\stop_times.txt", ".");
                    output.UpdateFile(transitDirectory + "\\fare_attributes.txt", ".");
                    output.UpdateFile(transitDirectory + "\\fare_rules.txt", ".");
                    output.Save();
                    output.Dispose();
                    GC.Collect();
                }

                // Feed validation
                try
                {
                    string fileName = transitDirectory + @"\\feedvalidator_googletransit.exe";
                    Process cmdLineProcess = new Process();
                    cmdLineProcess.StartInfo.FileName = fileName;
                    cmdLineProcess.StartInfo.Arguments = "-o " + transitDirectory + "\\error.html -l 9999 " + transitDirectory + "\\" + arch;
                    cmdLineProcess.StartInfo.UseShellExecute = true;
                    cmdLineProcess.StartInfo.CreateNoWindow = true;
                    cmdLineProcess.StartInfo.RedirectStandardOutput = false;
                    cmdLineProcess.StartInfo.RedirectStandardError = false;
                    if (cmdLineProcess.Start())
                    {
                        //litsample1.Text = cmdLineProcess.StandardOutput.ReadToEnd();
                    }
                    else
                    {
                        throw new ApplicationException("Can't read the command line process:" + fileName);
                    }
                }
                catch (ApplicationException except)
                {
                    message.Text = message.Text + except.Message;
                }

                status.Text = "<b>Feed Published Successfully</b> -- " + DateTime.Now.ToString("dddd, MMMM dd, yyyy hh:mm tt");
                message.Text = message.Text + "<br />View the full Feed Validation Report: <a href='/transit/error.html' target='_blank'>Google Feed Validation Report</a><br />View the testing.txt file: <a href='/transit/testing.txt' target='_blank'>testing.txt</a>";
            }

            return;
        }
Beispiel #10
0
        public void UpdateZip_UpdateFile_2_NoPasswords()
        {
            string filename = null;
            int entriesAdded = 0;
            int j = 0;
            string repeatedLine = null;

            // select the name of the zip file
            string zipFileToCreate = Path.Combine(TopLevelDir, "UpdateZip_UpdateFile_NoPasswords.zip");

            // create the subdirectory
            string subdir = Path.Combine(TopLevelDir, "A");
            Directory.CreateDirectory(subdir);

            // create the files
            int NumFilesToCreate = _rnd.Next(23) + 14;
            for (j = 0; j < NumFilesToCreate; j++)
            {
                filename = Path.Combine(subdir, String.Format("file{0:D3}.txt", j));
                repeatedLine = String.Format("This line is repeated over and over and over in file {0}",
                    Path.GetFileName(filename));
                TestUtilities.CreateAndFillFileText(filename, repeatedLine, _rnd.Next(34000) + 5000);
                entriesAdded++;
            }

            // create the zip archive
            Directory.SetCurrentDirectory(TopLevelDir);
            using (ZipFile zip1 = new ZipFile())
            {
                String[] filenames = Directory.GetFiles("A");
                foreach (String f in filenames)
                    zip1.UpdateFile(f, "");
                zip1.Comment = "UpdateTests::UpdateZip_UpdateFile_NoPasswords(): This archive will be updated.";
                zip1.Save(zipFileToCreate);
            }

            // Verify the number of files in the zip
            Assert.AreEqual<int>(TestUtilities.CountEntries(zipFileToCreate), entriesAdded,
                "Zoiks! The Zip file has the wrong number of entries.");


            // create another subdirectory
            subdir = Path.Combine(TopLevelDir, "updates");
            Directory.CreateDirectory(subdir);

            // Create a bunch of new files, in that new subdirectory
            var UpdatedFiles = new List<string>();
            int NumToUpdate = _rnd.Next(NumFilesToCreate - 4);
            for (j = 0; j < NumToUpdate; j++)
            {
                // select a new, uniquely named file to create
                do
                {
                    filename = String.Format("file{0:D3}.txt", _rnd.Next(NumFilesToCreate));
                } while (UpdatedFiles.Contains(filename));
                // create a new file, and fill that new file with text data
                repeatedLine = String.Format("**UPDATED** This file ({0}) has been updated on {1}.",
                    filename, System.DateTime.Now.ToString("yyyy-MM-dd"));
                TestUtilities.CreateAndFillFileText(Path.Combine(subdir, filename), repeatedLine, _rnd.Next(34000) + 5000);
                UpdatedFiles.Add(filename);
            }

            // update those files in the zip archive
            using (ZipFile zip2 = FileSystemZip.Read(zipFileToCreate))
            {
                foreach (string s in UpdatedFiles)
                    zip2.UpdateFile(Path.Combine(subdir, s), "");
                zip2.Comment = "UpdateTests::UpdateZip_UpdateFile_NoPasswords(): This archive has been updated.";
                zip2.Save(zipFileToCreate);
            }

            // Verify the number of files in the zip
            Assert.AreEqual<int>(TestUtilities.CountEntries(zipFileToCreate), entriesAdded,
                "Zoiks! The Zip file has the wrong number of entries.");

            // update those files AGAIN in the zip archive
            using (ZipFile zip3 = FileSystemZip.Read(zipFileToCreate))
            {
                foreach (string s in UpdatedFiles)
                    zip3.UpdateFile(Path.Combine(subdir, s), "");
                zip3.Comment = "UpdateTests::UpdateZip_UpdateFile_NoPasswords(): This archive has been re-updated.";
                zip3.Save(zipFileToCreate);
            }

            // extract the updated files and verify their contents
            using (ZipFile zip4 = FileSystemZip.Read(zipFileToCreate))
            {
                foreach (string s in UpdatedFiles)
                {
                    repeatedLine = String.Format("**UPDATED** This file ({0}) has been updated on {1}.",
                        s, System.DateTime.Now.ToString("yyyy-MM-dd"));
                    zip4[s].Extract("extract");

                    // verify the content of the updated file.
                    var sr = new StreamReader(Path.Combine("extract", s));
                    string sLine = sr.ReadLine();
                    sr.Close();

                    Assert.AreEqual<string>(repeatedLine, sLine,
                            String.Format("The content of the Updated file ({0}) in the zip archive is incorrect.", s));
                }
            }

            // extract all the other files and verify their contents
            using (ZipFile zip5 = FileSystemZip.Read(zipFileToCreate))
            {
                foreach (string s1 in zip5.EntryFileNames)
                {
                    bool NotUpdated = true;
                    foreach (string s2 in UpdatedFiles)
                    {
                        if (s2 == s1) NotUpdated = false;
                    }
                    if (NotUpdated)
                    {
                        zip5[s1].Extract("extract");
                        repeatedLine = String.Format("This line is repeated over and over and over in file {0}",
                            s1);

                        // verify the content of the updated file.
                        var sr = new StreamReader(Path.Combine("extract", s1));
                        string sLine = sr.ReadLine();
                        sr.Close();

                        Assert.AreEqual<string>(repeatedLine, sLine,
                                String.Format("The content of the originally added file ({0}) in the zip archive is incorrect.", s1));
                    }
                }
            }
        }
Beispiel #11
0
 public void UpdatePackages(string packagesDirectory, string zipFileName)
 {
     using (var zipFile = new ZipFile(zipFileName)) {
         _log.InfoFormat("Updating packages in {0}", zipFileName);
         var zippedPackages = zipFile.SelectEntries("name = *.gz", PackagesName).ToList();
         var notUpdatedPackages = zippedPackages.ConvertAll(p => p.FileName).ToList();
         foreach (var entry in zippedPackages) {
             var filePath = Utils.GetFilePath(packagesDirectory, entry.FileName);
             var fileInfo = new FileInfo(filePath);
             _log.InfoFormat("Updating package: {0}", fileInfo.Name);
             zipFile.UpdateFile(fileInfo.FullName, PackagesName);
             notUpdatedPackages.Remove(fileInfo.Name);
         }
         if (notUpdatedPackages.Count > 0) {
             throw new Exception("Some packages not updated. " + string.Concat(notUpdatedPackages));
         }
         _log.InfoFormat("Saving zip: {0}", zipFileName);
         zipFile.Save();
     }
 }