Ejemplo n.º 1
0
        private void mInitTestingModeFile()
        {
            _size     = FileName.Length;
            _exists   = true;
            _fileType = FileTypeEnum.Undefined;
            System.IO.Stream lFileStream;
            OpenReadTestingModeFile(out lFileStream);
            using (lFileStream)
            {
                Utility.Crc32 lCrcCalculator = new PIS.Ground.Core.Utility.Crc32();

                _crc = lCrcCalculator.CalculateChecksum(lFileStream);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initialization for a local file (i.e UNC or local path). Use FileInfo for checking path and
        /// getting file size. Use Utility.Crc32 to calculate the CRC. All errors are catch and write in
        /// log manager.
        /// </summary>
        private void mInitLocalFile()
        {
            try
            {
                System.IO.FileInfo lFileInfo = new System.IO.FileInfo(_filePath);
                _exists   = lFileInfo.Exists;
                _size     = lFileInfo.Length;
                _fileType = FileTypeEnum.LocalFile;

                using (System.IO.Stream lFileStream = lFileInfo.OpenRead())
                {
                    //Calcul CRC
                    Utility.Crc32 lCrcCalculator = new PIS.Ground.Core.Utility.Crc32();

                    _crc = lCrcCalculator.CalculateChecksum(lFileStream);
                }
            }
            catch (System.Security.SecurityException lEx)
            {
                PIS.Ground.Core.LogMgmt.LogManager.WriteLog(TraceType.ERROR, "mInitLocalFile() SecurityException with FilePath : " + _filePath, "PIS.Ground.Core.Data.RemoteFileClass", lEx, EventIdEnum.GroundCore);
            }
            catch (ArgumentException lEx)
            {
                PIS.Ground.Core.LogMgmt.LogManager.WriteLog(TraceType.ERROR, "mInitLocalFile() ArgumentException with FilePath : " + _filePath, "PIS.Ground.Core.Data.RemoteFileClass", lEx, EventIdEnum.GroundCore);
            }
            catch (UnauthorizedAccessException lEx)
            {
                PIS.Ground.Core.LogMgmt.LogManager.WriteLog(TraceType.ERROR, "mInitLocalFile() UnauthorizedAccessException with FilePath : " + _filePath, "PIS.Ground.Core.Data.RemoteFileClass", lEx, EventIdEnum.GroundCore);
            }
            catch (System.IO.PathTooLongException lEx)
            {
                PIS.Ground.Core.LogMgmt.LogManager.WriteLog(TraceType.ERROR, "mInitLocalFile() PathTooLongException with FilePath : " + _filePath, "PIS.Ground.Core.Data.RemoteFileClass", lEx, EventIdEnum.GroundCore);
            }
            catch (NotSupportedException lEx)
            {
                PIS.Ground.Core.LogMgmt.LogManager.WriteLog(TraceType.ERROR, "mInitLocalFile() NotSupportedException with FilePath : " + _filePath, "PIS.Ground.Core.Data.RemoteFileClass", lEx, EventIdEnum.GroundCore);
            }
            catch (Exception lEx)
            {
                PIS.Ground.Core.LogMgmt.LogManager.WriteLog(TraceType.ERROR, "mInitLocalFile() UnsupportedException with FilePath : " + _filePath, "PIS.Ground.Core.Data.RemoteFileClass", lEx, EventIdEnum.GroundCore);
            }
        }
Ejemplo n.º 3
0
        public void ContructorTestsAndCrcCalculation()
        {
            System.IO.FileStream          lStream;
            PIS.Ground.Core.Utility.Crc32 lCrcCalculator = new PIS.Ground.Core.Utility.Crc32();

            //Check constructor with local file
            RemoteFileClass rFile1 = new RemoteFileClass(pathString, true);

            try
            {
                lStream = new System.IO.FileStream(pathString, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                Assert.AreEqual(lCrcCalculator.CalculateChecksum(lStream), rFile1.CRC);
            }
            catch (Exception ex)
            {
                PIS.Ground.Core.LogMgmt.LogManager.WriteLog(TraceType.ERROR, ex.Message, "PIS.Ground.Core.Data.RemoteFileClass", ex, EventIdEnum.GroundCore);
                lStream = null;
            }
            Assert.True(rFile1.Exists);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initialization for a ftp remote file (i.e http://). Use HttpWebRequest for checking path.
        /// Then open a stream and get file size. Use Utility.Crc32 to calculate the CRC on the stream.
        /// All errors are catch and write in log manager.
        /// </summary>
        private void mInitHttpFile()
        {
            try
            {
                string connectionGroupName         = Guid.NewGuid().ToString();
                System.Net.HttpWebRequest lRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(_filePath);
                lRequest.ConnectionGroupName = connectionGroupName;
                ServicePoint servicePoint = lRequest.ServicePoint;
                try
                {
                    lRequest.Method = System.Net.WebRequestMethods.Http.Head;
                    using (System.Net.HttpWebResponse lResponse = (System.Net.HttpWebResponse)lRequest.GetResponse())
                    {
                        _exists   = true;
                        _fileType = FileTypeEnum.HttpFile;

                        //CalculCRC
                        Utility.Crc32 lCrcCalculator = new PIS.Ground.Core.Utility.Crc32();

                        System.IO.Stream lFileStream;
                        OpenReadHttpFile(out lFileStream, connectionGroupName);
                        if (lFileStream != null)
                        {
                            using (lFileStream)
                            {
                                _size = lFileStream.Length;
                                _crc  = lCrcCalculator.CalculateChecksum(lFileStream);
                            }
                        }
                        else
                        {
                            PIS.Ground.Core.LogMgmt.LogManager.WriteLog(PIS.Ground.Core.Data.TraceType.ERROR, "mInitHttpFile returned null file", "PIS.Ground.Core.Data.RemoteFileClass", null, EventIdEnum.GroundCore);
                        }
                    }
                }
                finally
                {
                    if (lRequest != null)
                    {
                        try
                        {
                            lRequest.Abort();
                        }
                        catch (NotImplementedException)
                        {
                            // Ignore the not implemented exception
                        }
                    }

                    if (servicePoint != null)
                    {
                        servicePoint.CloseConnectionGroup(connectionGroupName);
                        servicePoint = null;
                    }
                }
            }
            catch (NotSupportedException lEx)
            {
                PIS.Ground.Core.LogMgmt.LogManager.WriteLog(TraceType.ERROR, "mInitHttpFile() NotSupportedException with FilePath : " + _filePath, "PIS.Ground.Core.Data.RemoteFileClass", lEx, EventIdEnum.GroundCore);
            }
            catch (System.Security.SecurityException lEx)
            {
                PIS.Ground.Core.LogMgmt.LogManager.WriteLog(TraceType.ERROR, "mInitHttpFile() SecurityException with FilePath : " + _filePath, "PIS.Ground.Core.Data.RemoteFileClass", lEx, EventIdEnum.GroundCore);
            }
            catch (UriFormatException lEx)
            {
                PIS.Ground.Core.LogMgmt.LogManager.WriteLog(TraceType.ERROR, "mInitHttpFile() UriFormatException with FilePath : " + _filePath, "PIS.Ground.Core.Data.RemoteFileClass", lEx, EventIdEnum.GroundCore);
            }
            catch (Exception lEx)
            {
                PIS.Ground.Core.LogMgmt.LogManager.WriteLog(TraceType.ERROR, "mInitHttpFile() UnsupportedException with FilePath : " + _filePath, "PIS.Ground.Core.Data.RemoteFileClass", lEx, EventIdEnum.GroundCore);
            }
        }