Exemple #1
0
        public DiskListener(IListenerConfiguration configuration)
        {
            _continiousRead = false;

            if (!(configuration is DiskConfigurationModel))
            {
                throw new Exception(string.Format("The listener for device {0} is not a disk type listener!", configuration.DeviceName));
            }

            Configuration = configuration;
            DiskConfigurationModel dc = (DiskConfigurationModel)configuration;

            Logger.Info("Created file listener for device on {0}", dc.FilePath);
        }
Exemple #2
0
        private void PollDisk()
        {
            do
            {
                try
                {
                    DiskConfigurationModel dc = (DiskConfigurationModel)Configuration;

                    IEnumerable <string> files = (from file in Directory.EnumerateFiles(dc.FilePath, dc.SearchPattern, SearchOption.AllDirectories)
                                                  select file).ToList();

                    foreach (var fileFullName in files)
                    {
                        using (var file = new StreamReader(fileFullName))
                        {
                            string line;

                            while ((line = file.ReadLine()) != null)
                            {
                                if (!string.IsNullOrWhiteSpace(line))
                                {
                                    OnListenEventReceived(new ListenEvent {
                                        Message = line
                                    });
                                }
                            }

                            file.Close();
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.Trace("Poll Error" + ex.Message);
                }
                finally
                {
                    Thread.Sleep(Configuration.ListenEveryMilliseconds);
                }
            } while (_continiousRead);

            KillThread();
        }
Exemple #3
0
        public static BaseCameraListener GetListener(Defaults defaults, PointDefinition pointDefinition)
        {
            switch (defaults.Listener)
            {
            case ListenerTypeEnum.Socket:
                switch (pointDefinition)
                {
                case PointDefinition.PointA:
                    SocketConfigurationModel pointA = new SocketConfigurationModel
                    {
                        ListenEveryMilliseconds = defaults.ListenEveryMilliseconds,
                        TimeoutInMilliseconds   = 60000,
                        IpAddress = defaults.IpAndPortA.Split(':')[0],
                        IpPort    = int.Parse(defaults.IpAndPortA.Split(':')[1])
                    };

                    return(new iCamCameraListener(new SocketListener(pointA)));

                case PointDefinition.PointB:
                    SocketConfigurationModel pointB = new SocketConfigurationModel
                    {
                        ListenEveryMilliseconds = defaults.ListenEveryMilliseconds,
                        TimeoutInMilliseconds   = 60000,
                        IpAddress = defaults.IpAndPortB.Split(':')[0],
                        IpPort    = int.Parse(defaults.IpAndPortB.Split(':')[1])
                    };

                    return(new iCamCameraListener(new SocketListener(pointB)));
                }
                break;

            case ListenerTypeEnum.Mock:
                switch (pointDefinition)
                {
                case PointDefinition.PointA:
                    MockConfigurationModel modelStart = new MockConfigurationModel
                    {
                        ListenEveryMilliseconds = defaults.ListenEveryMilliseconds,
                        TimeOffsetSecondsStart  = 0,
                        TimeOffsetSecondsEnd    = 5,
                        Seed         = 1500,
                        DeviceId     = 1,
                        DeviceName   = "Mock Device A",
                        LocationCode = "MockA"
                    };

                    return(new MockCameraListener(new MockListener(modelStart)));

                case PointDefinition.PointB:
                    MockConfigurationModel modelEnd = new MockConfigurationModel
                    {
                        ListenEveryMilliseconds = defaults.ListenEveryMilliseconds,
                        TimeOffsetSecondsStart  = 250,
                        TimeOffsetSecondsEnd    = 360,
                        Seed         = 2500,
                        DeviceId     = 2,
                        DeviceName   = "Mock Device B",
                        LocationCode = "MockB"
                    };
                    return(new MockCameraListener(new MockListener(modelEnd)));
                }
                break;

            case ListenerTypeEnum.Disk:
                switch (pointDefinition)
                {
                case PointDefinition.PointA:
                    DiskConfigurationModel pointA = new DiskConfigurationModel
                    {
                        ListenEveryMilliseconds = defaults.ListenEveryMilliseconds,
                        FilePath      = Helper.PathPointA,
                        SearchPattern = Helper.PathFilter
                    };

                    return(new iCamCameraListener(new DiskListener(pointA)));

                case PointDefinition.PointB:
                    DiskConfigurationModel pointB = new DiskConfigurationModel
                    {
                        ListenEveryMilliseconds = defaults.ListenEveryMilliseconds,
                        FilePath      = Helper.PathPointB,
                        SearchPattern = Helper.PathFilter
                    };

                    return(new iCamCameraListener(new DiskListener(pointB)));
                }
                break;
            }

            return(null);
        }