} // end method

        #endregion

        #region Private Methods

        /// <summary>
        /// Notify listeners of ip address change.
        /// </summary>
        /// <param name="newIpRecord">New IP record.</param>
        private void notifyIpAddressChange(IpRecord newIpRecord)
        {
            NewIpAddressEvent handler = OnNewIpAddress;
            if (handler != null)
            {
                handler(newIpRecord.IpAddress, newIpRecord.RecordDate, new EventArgs());
            } // end if
        } // end method
        }             // end method

        #endregion

        #region Private Methods

        /// <summary>
        /// Notify listeners of ip address change.
        /// </summary>
        /// <param name="newIpRecord">New IP record.</param>
        private void notifyIpAddressChange(IpRecord newIpRecord)
        {
            NewIpAddressEvent handler = OnNewIpAddress;

            if (handler != null)
            {
                handler(newIpRecord.IpAddress, newIpRecord.RecordDate, new EventArgs());
            } // end if
        }     // end method
        } // end method

        /// <summary>
        /// Write new IP record to file.
        /// </summary>
        /// <param name="ipRecord">New IP record.</param>
        /// <returns>True if write was successful.</returns>
        public bool WriteIpAddressRecordToFile(IpRecord ipRecord)
        {
            string ipAddress = ipRecord.IpAddress;
            string dateTime = ipRecord.RecordDate.ToShortDateString();

            try
            {
                File.WriteAllText(dataFile_m, ipAddress + Environment.NewLine + dateTime);
                return true;
            }
            catch (Exception)
            {
                return false;
            } // end try-catch
        } // end method
Esempio n. 4
0
        }     // end method

        /// <summary>
        /// Write new IP record to file.
        /// </summary>
        /// <param name="ipRecord">New IP record.</param>
        /// <returns>True if write was successful.</returns>
        public bool WriteIpAddressRecordToFile(IpRecord ipRecord)
        {
            string ipAddress = ipRecord.IpAddress;
            string dateTime  = ipRecord.RecordDate.ToShortDateString();

            try
            {
                File.WriteAllText(dataFile_m, ipAddress + Environment.NewLine + dateTime);
                return(true);
            }
            catch (Exception)
            {
                return(false);
            } // end try-catch
        }     // end method
        /// <summary>
        /// Update the IP address information after retrieving it.
        /// </summary>
        public void UpdateExternalIpAddressRecord()
        {
            IpRecordFileHandler recordHandler = new IpRecordFileHandler();
            IpRecord record = recordHandler.GetIpRecord();
            string externalIp = getExternalIpAddress();

            if (externalIp != null)
            {
                IpRecord newRecord = new IpRecord(externalIp, DateTime.Now);

                if (record == null || !string.Equals(record.IpAddress, externalIp))
                {
                    if (recordHandler.WriteIpAddressRecordToFile(newRecord))
                    {
                        notifyIpAddressChange(newRecord);
                    } // end if
                } // end if
            } // end if
        } // end method
        /// <summary>
        /// Update the IP address information after retrieving it.
        /// </summary>
        public void UpdateExternalIpAddressRecord()
        {
            IpRecordFileHandler recordHandler = new IpRecordFileHandler();
            IpRecord            record        = recordHandler.GetIpRecord();
            string externalIp = getExternalIpAddress();

            if (externalIp != null)
            {
                IpRecord newRecord = new IpRecord(externalIp, DateTime.Now);

                if (record == null || !string.Equals(record.IpAddress, externalIp))
                {
                    if (recordHandler.WriteIpAddressRecordToFile(newRecord))
                    {
                        notifyIpAddressChange(newRecord);
                    } // end if
                }     // end if
            }         // end if
        }             // end method