Esempio n. 1
0
        //    send_init (string filename)
        //
        //    2) Store the filename on the server [storefile_open]
        //    3) Send the file line by line
        //    4) Close the stream for sending the file
        public string send_init(string fname)
        {
            G_ProgressBar pbar;
            TcpClient myclient;
            NetworkStream mystream;
            StreamReader fp = null;
            string buf;
            string remote_fname;
            double lines = 0;
            double lines_sent = 0;
            double percent = 0;

            if (Settings.Faxtracing == true) {
                Console.WriteLine("[Hylafax.send_init] Filename : {0}", fname);
            }

            //timezone("LOCAL");
            // Setup the server and return a passive connection
            // PASV, STOT
            myclient = storefile_open();
            if (Settings.Faxtracing == true) {
                Console.WriteLine("[Hylafax.send_init] Got tcpclient");
            }

            mystream = myclient.GetStream();
            if (Settings.Faxtracing == true) {
                Console.WriteLine("[Hylafax.send_init] Stream is open");
            }
            //figure out how many lines in the file for progress bar
            // TODO progress bar and error
            try { fp = File.OpenText(fname); }
            catch (Exception e) {
              Console.WriteLine("[hylafax.sendinit] Exception: {0}", e);
            }

            while ( (buf = fp.ReadLine()) != null ) {
                lines = lines + 1;
            }
            fp.Close();

            try { fp = File.OpenText(fname); }
            catch (Exception e) {
              Console.WriteLine("[hylafax.sendinit] Exception: {0}", e);
            }

            if (Settings.Faxtracing == true) {
                Console.WriteLine("[Hylafax.send_init] File :{0} is open and has {1} lines", fname,lines);
            }

            pbar = new G_ProgressBar();
            //pbar.Text = "File xmit";
            lines_sent = 1;
            while ( (buf = fp.ReadLine()) != null ) {
                write(mystream, buf);
                write(mystream, "\n");
                lines_sent = lines_sent + 1;
                percent = lines_sent / lines;
                if (percent <= 1.0)
                    pbar.Fraction = percent;
                //GLib.MainContext.Iteration ();
                while (Gtk.Application.EventsPending ())
                    Gtk.Application.RunIteration ();
                if (pbar.Cancel)
                    break;
            }
            fp.Close();
            remote_fname = storefile_close(myclient);

            if (pbar.Cancel) {	//If the transfer was cancelled
                deletefile(remote_fname);
                remote_fname = "cancelled";
                pbar.Close();
            } else {
                pbar.Finished();
            }

            if (Settings.Faxtracing == true) {
                Console.WriteLine("[Hylafax.send_init] Stream is closed, sent {0} lines",lines_sent);
            }
            return remote_fname;
        }
Esempio n. 2
0
        //	send_init (string filename)
        //
        //	2) Store the filename on the server [storefile_open]
        //	3) Send the file line by line
        //	4) Close the stream for sending the file
        public string send_init(string fname)
        {
            G_ProgressBar pbar;
            TcpClient     myclient;
            NetworkStream mystream;
            StreamReader  fp = null;
            string        buf;
            string        remote_fname;
            double        lines      = 0;
            double        lines_sent = 0;
            double        percent    = 0;

            if (Settings.Faxtracing == true)
            {
                Console.WriteLine("[Hylafax.send_init] Filename : {0}", fname);
            }

            //timezone("LOCAL");
            // Setup the server and return a passive connection
            // PASV, STOT
            myclient = storefile_open();
            if (Settings.Faxtracing == true)
            {
                Console.WriteLine("[Hylafax.send_init] Got tcpclient");
            }

            mystream = myclient.GetStream();
            if (Settings.Faxtracing == true)
            {
                Console.WriteLine("[Hylafax.send_init] Stream is open");
            }
            //figure out how many lines in the file for progress bar
            // TODO progress bar and error
            try { fp = File.OpenText(fname); }
            catch (Exception e) {
                Console.WriteLine("[hylafax.sendinit] Exception: {0}", e);
            }

            while ((buf = fp.ReadLine()) != null)
            {
                lines = lines + 1;
            }
            fp.Close();

            try { fp = File.OpenText(fname); }
            catch (Exception e) {
                Console.WriteLine("[hylafax.sendinit] Exception: {0}", e);
            }

            if (Settings.Faxtracing == true)
            {
                Console.WriteLine("[Hylafax.send_init] File :{0} is open and has {1} lines", fname, lines);
            }

            pbar = new G_ProgressBar();
            //pbar.Text = "File xmit";
            lines_sent = 1;
            while ((buf = fp.ReadLine()) != null)
            {
                write(mystream, buf);
                write(mystream, "\n");
                lines_sent = lines_sent + 1;
                percent    = lines_sent / lines;
                if (percent <= 1.0)
                {
                    pbar.Fraction = percent;
                }
                //GLib.MainContext.Iteration ();
                while (Gtk.Application.EventsPending())
                {
                    Gtk.Application.RunIteration();
                }
                if (pbar.Cancel)
                {
                    break;
                }
            }
            fp.Close();
            remote_fname = storefile_close(myclient);

            if (pbar.Cancel)                    //If the transfer was cancelled
            {
                deletefile(remote_fname);
                remote_fname = "cancelled";
                pbar.Close();
            }
            else
            {
                pbar.Finished();
            }

            if (Settings.Faxtracing == true)
            {
                Console.WriteLine("[Hylafax.send_init] Stream is closed, sent {0} lines", lines_sent);
            }
            return(remote_fname);
        }