private void AssertFileListing(DirectoryInfo info, IFileNameFilter filter, int expectedItems)
        {
            IEnumerator enumerator = DirectorySearcher.GetFileEnumerator(info, filter);

            Assert.AreEqual(expectedItems, CountItemsInEnumeration(enumerator), "Wrong number of files returned");

            FileInfo[] infos = DirectorySearcher.GetFiles(info, filter);
            Assert.AreEqual(expectedItems, infos.Length, "Wrong number of files returned");
        }
Ejemplo n.º 2
0
 public IEnumerable <ReferencePage <TPageModel> > GetPagesIn <TPageModel>(string uri) where TPageModel : IPageModel
 {
     foreach (var fileUri in directorySearcher.GetFiles(uri))
     {
         var data   = FileReader.Read(directorySearcher.GetFile(fileUri));
         var parser = parserFactory.CreateParser(data);
         var model  = parser.Parse <TPageModel>();
         yield return(new ReferencePage <TPageModel>(model, fileUri));
     }
 }
Ejemplo n.º 3
0
        public virtual void Process()
        {
            //  Look for all non-"*.pkt" files; if a file doesn't end in an extension,
            //	it has no content and represents a pending SIF_Response. These are the
            //	files we're interested in processing in the files[] loop below.
            DirectoryInfo dir = new DirectoryInfo(fWorkDir);

            FileInfo[] files =
                DirectorySearcher.GetFiles(dir, new ResponseDeliveryFilenameFilter());

            //bool errorPacket = false;

            if (files != null && files.Length > 0)
            {
                if (((Adk.Debug & AdkDebugFlags.Messaging_Response_Processing) != 0))
                {
                    fZone.Log.Debug
                        ("Processing " + (files.Length) + " pending SIF_Response packets...");
                }

                for (int i = 0; i < files.Length; i++)
                {
                    string fileName = files[i].Name;
                    bool   responseHasMorePackets = fileName.EndsWith("Y");
                    string _msgId = fileName.Substring(0, fileName.Length - 2);

                    //  Get all packets awaiting delivery...
                    FileInfo[] packets = dir.GetFiles(_msgId + "*.pkt");

                    if (packets.Length == 0)
                    {
                        continue;
                    }

                    if ((Adk.Debug & AdkDebugFlags.Messaging_Response_Processing) != 0)
                    {
                        fZone.Log.Debug
                            ("Found " + (packets.Length) +
                            " pending SIF_Response packets for request " +
                            _msgId);
                    }

                    //  Sort the files by packet #
                    Array.Sort(packets, delegate(FileInfo o1, FileInfo o2)
                    {
                        int o1Packet = int.Parse(o1.Name.Split('.')[2]);
                        int o2Packet = int.Parse(o2.Name.Split('.')[2]);

                        if (o1Packet < o2Packet)
                        {
                            return(-1);
                        }
                        else if (o1Packet == o2Packet)
                        {
                            return(0);
                        }
                        return(1);
                    });

                    //  Process each packet
                    int p;
                    for (p = 0; p < packets.Length; p++)
                    {
                        bool morePackets = responseHasMorePackets || (p < (packets.Length - 1));
                        SendPacket(packets[p], morePackets);
                    }

                    //  Delete files[i] if we processed all packets. If the
                    //  thread is being shut down and not all packets were
                    //  processed, however, leave the file for the next
                    //  session.
                    if (p >= packets.Length)
                    {
                        //	System.out.println( "Deleting " + files[i].getAbsolutePath() );
                        if (File.Exists(files[i].FullName))
                        {
                            File.Delete(files[i].FullName);
                        }
                        else if (Directory.Exists(files[i].FullName))
                        {
                            Directory.Delete(files[i].FullName);
                        }

                        if (fSrc == ResponseDeliveryType.SIFReportObject)
                        {
                            //	SRC_SIFREPORTOBJECT: Also delete the .rpt file
                            FileInfo f =
                                new FileInfo
                                    (fWorkDir + Path.DirectorySeparatorChar.ToString() + _msgId +
                                    ".rpt");
                            //	System.out.println( "Deleting " + f.getAbsolutePath() );
                            if (File.Exists(f.FullName))
                            {
                                File.Delete(f.FullName);
                            }
                            else if (Directory.Exists(f.FullName))
                            {
                                Directory.Delete(f.FullName);
                            }
                        }
                    }
                }
            }
        }