コード例 #1
0
        public static StatusStateInfo Begin(string strText)
        {
            StatusStateInfo s = new StatusStateInfo();

            try
            {
                MainForm mf = IOProtocolExtExt.Host.MainWindow;

                if (!IOProtocolExtExt.MainFormLoading)
                {
                    mf.SetStatusEx(strText);

                    s.Visible = mf.MainProgressBar.Visible;
                    if (!s.Visible)
                    {
                        mf.MainProgressBar.Visible = true;
                    }

                    s.Style = mf.MainProgressBar.Style;
                    mf.MainProgressBar.Style = ProgressBarStyle.Marquee;
                }
                else
                {
                    s.Form = BeginStatusDialog(strText);
                }
            }
            catch (Exception) { Debug.Assert(false); }

            return(s);
        }
コード例 #2
0
        private void EnsureStream()
        {
            if (m_s != null)
            {
                return;
            }

            StatusStateInfo st = StatusUtil.Begin("Downloading file...");

            try
            {
                m_bFileDownloaded = false;
                m_exDownload      = null;

                WaitCallback wc = new WaitCallback(DownloadFileProc);
                ThreadPool.QueueUserWorkItem(wc);

                bool bFinished = false;
                while (!bFinished)
                {
                    lock (m_objDownloadSync) { bFinished = m_bFileDownloaded; }

                    Thread.Sleep(100);
                    Application.DoEvents();
                }

                if (m_exDownload != null)
                {
                    throw m_exDownload;
                }

                m_s = new FileStream(m_strTempFile, m_fm, m_fa, m_fs);
            }
            finally { StatusUtil.End(st); }
        }
コード例 #3
0
        public static void End(StatusStateInfo s)
        {
            if (s == null)
            {
                Debug.Assert(false); return;
            }

            try
            {
                if (s.Form != null)
                {
                    EndStatusDialog(s.Form);
                    s.Form = null;
                }
                else
                {
                    MainForm mf = IOProtocolExtExt.Host.MainWindow;
                    mf.MainProgressBar.Style   = s.Style;
                    mf.MainProgressBar.Visible = s.Visible;
                }
            }
            catch (Exception) { Debug.Assert(false); }
        }
コード例 #4
0
        // private static string GetHostKey(string strError)
        // {
        //	strError = strError.Replace("\r\n", "\n");
        //	strError = strError.Replace("\r", "\n");
        //	string[] vLines = strError.Split(new char[] { '\n' },
        //		StringSplitOptions.RemoveEmptyEntries);
        //	foreach(string strLineIt in vLines)
        //	{
        //		if(strLineIt.StartsWith("ssh-rsa")) return strLineIt;
        //		if(strLineIt.StartsWith("ssh-dss")) return strLineIt;
        //	}
        //	return null;
        // }

        private WebResponse RunOp(string strTempFile, string strSessionUrl,
                                  string strRemotePath)
        {
            WswrOp wOp;

            if (m_strMethod == IOConnection.WrmDeleteFile)
            {
                wOp = WswrOp.Delete;
            }
            else if (m_strMethod == IOConnection.WrmMoveFile)
            {
                wOp = WswrOp.Move;
            }
            else if (m_lRequestData.Count > 0)
            {
                wOp = WswrOp.Upload;
            }
            else
            {
                wOp = WswrOp.Download;
            }

            if (wOp == WswrOp.Upload)
            {
                File.WriteAllBytes(strTempFile, m_lRequestData.ToArray());
            }

            // StringBuilder sbHostKeyDetect = InitScript();
            // sbHostKeyDetect.AppendLine(AddCommonOpenOptions(
            //	"open " + strSessionUrl, strSessionUrl, string.Empty));
            // sbHostKeyDetect.AppendLine("exit");
            // string strHostKey = null;
            // try { WinScpExecutor.RunScript(sbHostKeyDetect.ToString()); }
            // catch(Exception exProbe)
            // {
            //	strHostKey = GetHostKey(exProbe.Message);
            //	if(string.IsNullOrEmpty(strHostKey)) throw;
            // }

            string strScript;

            if (wOp == WswrOp.Download)            // Test file exists
            {
                strScript = BuildScript(WswrOp.Download, true, strTempFile,
                                        strSessionUrl, strRemotePath);
                string strResult = WinScpExecutor.RunScript(strScript);

                string strRemoteFile = UrlUtil.GetFileName(strRemotePath);

                strResult = strResult.Replace("\r\n", "\n");
                strResult = strResult.Replace("\r", "\n");
                string[] vLines = strResult.Split(new char[] { '\n' },
                                                  StringSplitOptions.RemoveEmptyEntries);
                bool bFound = false;
                foreach (string strLine in vLines)
                {
                    if ((strLine == strRemoteFile) ||
                        strLine.EndsWith(" " + strRemoteFile) ||
                        strLine.EndsWith("\t" + strRemoteFile) ||
                        strLine.EndsWith("/" + strRemoteFile))
                    {
                        bFound = true;
                        break;
                    }
                }
                if (!bFound)
                {
                    throw new FileNotFoundException("Remote file not found!");
                }
            }

            strScript = BuildScript(wOp, false, strTempFile, strSessionUrl,
                                    strRemotePath);

            StatusStateInfo st = null;

            if (wOp == WswrOp.Upload)
            {
                st = StatusUtil.Begin("Uploading file...");
            }

            WebResponse wr;

            try
            {
                if (wOp == WswrOp.Upload)
                {
                    object[] vState = new object[4];
                    vState[0] = m_uri;
                    vState[1] = strScript;
                    vState[2] = strTempFile;
                    vState[3] = m_whcHeaders;

                    m_bUploadResponseReady = false;
                    m_exUpload             = null;

                    object objState = (object)vState;
                    ThreadPool.QueueUserWorkItem(new WaitCallback(
                                                     CreateUploadResponse), objState);

                    bool bReady = false;
                    while (!bReady)
                    {
                        lock (objState) { bReady = m_bUploadResponseReady; }

                        Thread.Sleep(100);
                        Application.DoEvents();
                    }

                    wr = m_wswrUpload;
                    if (m_exUpload != null)
                    {
                        throw m_exUpload;
                    }
                }
                else
                {
                    wr = new WinScpWebResponse(m_uri, strScript, strTempFile,
                                               (wOp == WswrOp.Download), m_whcHeaders);
                }
            }
            finally
            {
                if (wOp == WswrOp.Upload)
                {
                    StatusUtil.End(st);
                }
            }

            return(wr);
        }
コード例 #5
0
        public static StatusStateInfo Begin(string strText)
        {
            StatusStateInfo s = new StatusStateInfo();

            try
            {
                MainForm mf = IOProtocolExtExt.Host.MainWindow;

                if(!IOProtocolExtExt.MainFormLoading)
                {
                    mf.SetStatusEx(strText);

                    s.Visible = mf.MainProgressBar.Visible;
                    if(!s.Visible) mf.MainProgressBar.Visible = true;

                    s.Style = mf.MainProgressBar.Style;
                    mf.MainProgressBar.Style = ProgressBarStyle.Marquee;
                }
                else s.Form = BeginStatusDialog(strText);
            }
            catch(Exception) { Debug.Assert(false); }

            return s;
        }
コード例 #6
0
        public static void End(StatusStateInfo s)
        {
            if(s == null) { Debug.Assert(false); return; }

            try
            {
                if(s.Form != null)
                {
                    EndStatusDialog(s.Form);
                    s.Form = null;
                }
                else
                {
                    MainForm mf = IOProtocolExtExt.Host.MainWindow;
                    mf.MainProgressBar.Style = s.Style;
                    mf.MainProgressBar.Visible = s.Visible;
                }
            }
            catch(Exception) { Debug.Assert(false); }
        }