Example #1
0
        private void Read(string Filename)
        {
            mFile = new GatFile();

            using (FileStream s = System.IO.File.OpenRead(Filename)) {
                if (s.CanRead == false)
                {
                    try { s.Close(); } catch { }
                    return;
                }
                using (BinaryReader bin = new BinaryReader(s)) {
                    char[] magic     = bin.ReadChars(6);
                    int    num_cells = 0;

                    mFile.Width  = bin.ReadInt32();
                    mFile.Height = bin.ReadInt32();

                    num_cells   = (mFile.Width * mFile.Height);
                    mFile.Cells = new Cell[num_cells];
                    for (int i = 0; i < num_cells; i++)
                    {
                        mFile.Cells[i]        = new Cell();
                        mFile.Cells[i].Height = new Cell.CellHeight(
                            bin.ReadSingle(),
                            bin.ReadSingle(),
                            bin.ReadSingle(),
                            bin.ReadSingle()
                            );
                        mFile.Cells[i].Type    = Convert.Parse <ECellType>(bin.ReadByte().ToString());
                        mFile.Cells[i].Unknown = bin.ReadChars(3);                             // 3x unknown Char
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// Initializes connection to a remote Server with given credentials
        /// </summary>
        private void _Init()
        {
            if (_jsch != null)
            {
                try
                {
                    _sftpSession.disconnect();
                    _sftpSession = null;
                    _jsch        = null;
                }
                catch (Exception e)
                {
                    _sftpSession = null;
                    _jsch        = null;
                    string failMessage = string.Format("SFTP connection  {0}@{1} [{2}] could not be started ({3})",
                                                       _user, _host, _connectionName, e.Message);
                    GatLogger.Instance.AddMessage(failMessage, LogMode.LogAndScreen);
                    GatLogger.Instance.AddMessage(e.StackTrace);
                    SystemMailer.Instance.SendDevEmail(e, failMessage);
                }

                //wait half a second before reconnecting so we dont flood FTP server with continued failed attempts
                Thread.Sleep(500);
            }

            try
            {
                _jsch        = new JSch();
                _sftpSession = _jsch.getSession(_user, _host, _port);

                _ui = new SftpUserInfo(); // this is needed for the passkey
                _sftpSession.setUserInfo(_ui);

                _sftpSession.setPassword(_pass);
                _sftpSession.connect();

                _channel = _sftpSession.openChannel("sftp");
                _channel.connect();

                _sftpChannel = (ChannelSftp)_channel;
                //_ins = Console.OpenStandardInput();
                //_outs = Console.Out;

                _ChangeRemoteWorkingDirectory(_rootDir);
                _ChangeLocalWorkingDirectory(GatFile.Path(Dir.Temp, string.Empty));
            }
            catch (Exception e)
            {
                if (!_reportOnce)
                {
                    string failMsg = string.Format("SFTP Connection is failing ({2}@{0}:{1}) \n\t{3}", _host, _port,
                                                   _user, e.Message);
                    GatLogger.Instance.AddMessage(failMsg, LogMode.LogAndScreen);;
                    GatLogger.Instance.AddMessage(string.Format("Exception Stack: {0}", e.StackTrace));
                    _reportOnce = true;

                    SystemMailer.Instance.SendDevEmail(e, failMsg);
                }
            }
        }
Example #3
0
        public List <string> PullFilesLike(string mask, string destinationFolder)
        {
            List <string> downloadedFiles = new List <string>();

            if (!FileTransferControl.Instance.IsActice)
            {
                string message =
                    string.Format("File Transfer Control is inactive (Transfer Handle '{0}').  {1} No files Acquired.",
                                  Name);
                GatLogger.Instance.AddMessage(message, LogMode.LogAndScreen);
                return(downloadedFiles);
            }

            List <IRemoteFile> remoteDirContent = Handle.GetWorkingDirContents();

            foreach (IRemoteFile remoteFile in remoteDirContent)
            {
                if (remoteFile.Filename.Contains(mask))
                {
                    GatLogger.Instance.AddMessage(string.Format("Pulling {0} to {1}", remoteFile.Filename, destinationFolder));
                    Handle.Pull(remoteFile.Filename, destinationFolder);
                    downloadedFiles.Add(GatFile.Path(destinationFolder, string.Empty, remoteFile.Filename));
                }
            }

            GatLogger.Instance.AddMessage(string.Format("Pulling Files with mask complete. {0} file(s) found", downloadedFiles.Count));
            return(downloadedFiles);
        }
Example #4
0
        private void _Init()
        {
            bool connected;

            if (!(connected = _Reconnect()))
            {
                while (_reconnectionAttempts < ct_maxPossibleAttempts)
                {
                    _reconnectionAttempts++;
                    connected = _Reconnect();
                    if (connected)
                    {
                        break;
                    }
                    continue;
                }
            }

            if (!connected)
            {
                GatLogger.Instance.AddMessage(string.Format("Could not connect to ftp {1}@{2} [{3}] after {0} tries.", ct_maxPossibleAttempts, _user, _host, _connectionName),
                                              LogMode.LogAndScreen);
            }
            else
            {
                _SetRemoteWorkingDirectory(_rootDir);
                _SetLocalWorkingDirectory(GatFile.Path(Dir.Temp, string.Empty));
            }
        }
Example #5
0
        private void _DownLoadAndProcessPositionFiles()
        {
            GatLogger.Instance.AddMessage("Pulling today's position files.", LogMode.LogAndScreen);

            Ftp ftpHandle = new Ftp("54.245.114.32", "usr_vtbullseye", "rod30cl0wn!");

            ftpHandle.ChangeRemoteWorkingDirectory("PositionFiles");

            string        fileDateString = DateTime.Now.ToString("yyMMdd");
            List <string> downloadedList = new List <string>();

            foreach (IRemoteFile remoteFile in ftpHandle.GetWorkingDirContents())
            {
                if (remoteFile.Filename.Contains(fileDateString))
                {
                    GatLogger.Instance.AddMessage(string.Format("Found file {0}", remoteFile.Filename), LogMode.LogAndScreen);

                    string downloadedFile = GatFile.Path(Dir.Temp, remoteFile.Filename);
                    ftpHandle.Pull(remoteFile.Filename, Path.GetDirectoryName(downloadedFile));

                    if (File.Exists(downloadedFile))
                    {
                        downloadedList.Add(downloadedFile);
                        _ProcessPositionFile(downloadedFile);
                    }
                }
            }

            Thread.Sleep(3000);

            foreach (string file in downloadedList)
            {
                File.Delete(file);
            }
        }
Example #6
0
        //static string strFixLogFileName = "FIX.4.2-CSASAVIS-MIXIT.messages.log";

        static void Main(string[] args)
        {
            initSingletons();

            Random rand = new Random(DateTime.Now.Second);
            //string limitID = "";

            string strKnightSettingsFile = GatFile.Path(Dir.Fix, "Connection_Settings.fses");
            bool   connected             = Startup_FixConnection(strKnightSettingsFile);

            while (connected && !ConsoleControl.killApplication)
            {
                ConsoleControl.windowListener();
            }

            if (connected && ConsoleControl.killApplication)
            {
                //add proper disconnect logic
            }
            else
            {
                Console.WriteLine("Could Not Connect to Session(s). Please close application and verify settings restart the application");
                Console.ReadKey();
                Console.WriteLine();
            }
        }
Example #7
0
		private void Read( string Filename ) {
			mFile = new GatFile();

			using( FileStream s = System.IO.File.OpenRead( Filename ) ) {
				if( s.CanRead == false ) {
					try { s.Close(); } catch { }
					return;
				}
				using( BinaryReader bin = new BinaryReader( s ) ) {
					char[] magic = bin.ReadChars( 6 );
					int num_cells = 0;

					mFile.Width = bin.ReadInt32();
					mFile.Height = bin.ReadInt32();

					num_cells = ( mFile.Width * mFile.Height );
					mFile.Cells = new Cell[ num_cells ];
					for( int i = 0; i < num_cells; i++ ) {
						mFile.Cells[ i ] = new Cell();
						mFile.Cells[ i ].Height = new Cell.CellHeight(
							bin.ReadSingle(),
							bin.ReadSingle(),
							bin.ReadSingle(),
							bin.ReadSingle()
						);
						mFile.Cells[ i ].Type = Convert.Parse<ECellType>( bin.ReadByte().ToString() );
						mFile.Cells[ i ].Unknown = bin.ReadChars( 3 ); // 3x unknown Char
					}
				}
			}
		}
        public void SftpConnectionTest()
        {
            IFtpHandle ftpConnection = new Sftp("96.126.108.162", "elliot", "e258G741", 22, "/home/elliot/sub2", "ConnectionTest");

            //new Ftp("54.245.114.32", "DailyFiles", "d@yDump!", 21, "/Temp", "ConnectionTest");
            Assert.AreEqual((int)ftpConnection.ConnectionStatus, (int)FtpStatus.Connected);

            List <IRemoteFile> files      = ftpConnection.GetWorkingDirContents();
            string             localPath  = ftpConnection.LocalWorkingDirectory;
            string             remotePath = ftpConnection.RemoteWorkingDirectory;

            ftpConnection.Pull(files.First().Filename);
            string[] localFiles = Directory.GetFiles(localPath);
            Assert.AreNotEqual(0, localFiles.Count());
            //Assert.IsTrue(files.Any(file => file.Filename.Equals(Path.GetFileName(localFiles[0]))));

            ftpConnection.ChangeRemoteWorkingDirectory("folder");
            Assert.AreNotEqual(remotePath, ftpConnection.RemoteWorkingDirectory);
            files = ftpConnection.GetWorkingDirContents();
            Assert.AreEqual(0, files.Count());
            ftpConnection.Push(localFiles.First());
            files = ftpConnection.GetWorkingDirContents();

            ftpConnection.ChangeLocalWorkingDirectory(GatFile.Path(Dir.Data, string.Empty));
            localPath = ftpConnection.LocalWorkingDirectory;
            ftpConnection.Pull(files.First().Filename);
            localFiles = Directory.GetFiles(localPath);
            Assert.AreNotEqual(0, localFiles.Count());

            localPath = GatFile.Path(Dir.Root, string.Empty);
            ftpConnection.Pull(files.First().Filename, localPath);
            localFiles = Directory.GetFiles(localPath);
            Assert.AreNotEqual(0, localFiles.Count());

            ftpConnection.ResetToRootDirectory();
            Assert.AreEqual(remotePath, ftpConnection.RemoteWorkingDirectory);

            files = ftpConnection.GetWorkingDirContents();
            foreach (var file in files)
            {
                ftpConnection.Pull(file.Filename);
                ftpConnection.Push(Path.Combine(ftpConnection.LocalWorkingDirectory, file.Filename), "folder");
            }
        }
        public void FtpConnectionTest()
        {
            IFtpHandle ftpConnection = new Ftp("54.245.114.32", "DailyFiles", "d@yDump!", 21, "/Temp", "ConnectionTest");

            Assert.AreEqual((int)ftpConnection.ConnectionStatus, (int)FtpStatus.Connected);

            List <IRemoteFile> files      = ftpConnection.GetWorkingDirContents();
            string             localPath  = ftpConnection.LocalWorkingDirectory;
            string             remotePath = ftpConnection.RemoteWorkingDirectory;

            ftpConnection.Pull(files.First().Filename);
            string[] localFiles = Directory.GetFiles(localPath);
            Assert.AreNotEqual(0, localFiles.Count());
            Assert.AreEqual(files.First().Filename, Path.GetFileName(localFiles[0]));

            ftpConnection.ChangeRemoteWorkingDirectory("Archive");
            Assert.AreNotEqual(remotePath, ftpConnection.RemoteWorkingDirectory);
            files = ftpConnection.GetWorkingDirContents();
            ftpConnection.Pull(files.First().Filename);
            localFiles = Directory.GetFiles(localPath);
            Assert.AreEqual(2, localFiles.Count());

            ftpConnection.ChangeLocalWorkingDirectory(GatFile.Path(Dir.Data, string.Empty));
            localPath = ftpConnection.LocalWorkingDirectory;
            ftpConnection.Pull(files.First().Filename);
            localFiles = Directory.GetFiles(localPath);
            Assert.AreNotEqual(0, localFiles.Count());

            localPath = GatFile.Path(Dir.Root, string.Empty);
            ftpConnection.Pull(files.First().Filename, localPath);
            localFiles = Directory.GetFiles(localPath);
            Assert.AreNotEqual(0, localFiles.Count());

            ftpConnection.ResetToRootDirectory();
            Assert.AreEqual(remotePath, ftpConnection.RemoteWorkingDirectory);

            files = ftpConnection.GetWorkingDirContents();
            foreach (var file in files)
            {
                ftpConnection.Pull(file.Filename);
                ftpConnection.Push(Path.Combine(ftpConnection.LocalWorkingDirectory, file.Filename), "Archive");
            }
        }
Example #10
0
 public XmlSettings()
 {
     _xmlFilePath = GatFile.Path(Dir.ApplicationSettings, _xmlFilePath);
     _ReadXmlSettings();
 }
 public ApplicationState()
 {
     _stateDocumentPath = GatFile.Path(Dir.ApplicationSettings, ct_settingDocumentName);
     _LoadSettings();
 }