Exemple #1
0
        private List <TXFileInfo> GetFilesAndFolders()
        {
            using (var proxy = new ProxyFileEnum())
            {
                proxy.SetHost(HostAndPort);
                proxy.SetCredentials(GetCreds());

                // If there's an exception, it probably occurs on the first call to the proxy.

                Log.Info("Exchanging version numbers with. ", HostAndPort);
                int serverVersion = proxy.ExchangeVersion(1);

                // We pass _savedViewedFiles and _savedViewedFolders to the service so it can
                // check if they still exist.  If they do, they will be in the result list.

                Log.Info("Getting remote files from ", HostName);
                List <TXFileInfo> filesAndFolders = proxy.GetRecentFilesAndFolders(_savedViewedFiles.Select(f => f.Path), _savedViewedFolders.Select(f => f.Path));
                Log.Info("Got ", filesAndFolders.Count, " results.");

                // TODO: This might be the place to remove files and folders that have
                // FoundInRecentFiles == false and whose last viewed time isn't very recent.

                return(filesAndFolders);
            }
        }
Exemple #2
0
        /// <summary>
        /// Attempts to connect to the TraceX-Service on the specified server and
        /// returns true if successful.
        /// </summary>
        public bool CheckForService()
        {
            try
            {
                using (var proxy = new ProxyFileEnum())
                {
                    proxy.SetHost(HostAndPort);
                    proxy.SetCredentials(GetCreds());

                    Log.Info("Exchanging version numbers with ", HostAndPort);
                    int serverVersion = proxy.ExchangeVersion(1);
                    return(true);
                }
            }
            catch (Exception ex)
            {
                // The TracerX-Service probably just isn't running on the remote server.
                Log.Info("Exception checking for TracerX-Service on ", HostAndPort, ": ", ex.Message);
                return(false);
            }
        }
Exemple #3
0
        public TestConnectionResult TestConnection()
        {
            var result = new TestConnectionResult()
            {
                HostAndPort = this.HostAndPort
            };

            try
            {
                using (ProxyFileEnum serviceProxy = new ProxyFileEnum())
                {
                    serviceProxy.SetHost(HostAndPort);
                    serviceProxy.SetCredentials(GetCreds());
                    result.ServiceVersion = serviceProxy.ExchangeVersion(1);

                    if (result.ServiceVersion < 3)
                    {
                        // That's all we can get (the interface version).
                    }
                    else if (result.ServiceVersion < 5)
                    {
                        serviceProxy.GetServiceHostInfo(out result.HostExe, out result.HostVersion, out result.HostAccount);
                    }
                    else
                    {
                        // As of version 5, we can get whether or not the service is impersonating clients or not.
                        bool isImpersonating;
                        serviceProxy.GetServiceHostInfo2(out result.HostExe, out result.HostVersion, out result.HostAccount, out isImpersonating);
                        result.IsImpersonatingClients = isImpersonating;
                    }
                }
            }
            catch (Exception ex)
            {
                result.Exception = ex;
            }

            return(result);
        }
        // Returns true if any files were deleted or listed.
        private void Go(bool listFiles)
        {
            try
            {
                List <string> files = null;

                if (_server == null)
                {
                    // Process local files directly.

                    if (listFiles || DialogResult.Yes == MainForm.ShowMessageBoxBtns("Delete specified files?", MessageBoxButtons.YesNo))
                    {
                        files = DeleteRelated.DeleteMany(
                            txtFileSpec.Text,
                            txtFolderSpec.Text,
                            dtpFromTime.Value,
                            dtpToTime.Value,
                            int.Parse(txtFromSize.Text) * 1024,
                            int.Parse(txtToSize.Text) * 1024,
                            chkBinary.Checked,
                            chkText.Checked,
                            chkDeleteFolders.Checked,
                            listFiles,
                            Log);
                    }
                }
                else
                {
                    // Process remote files via the WCF server.
                    using (ProxyFileEnum serviceProxy = new ProxyFileEnum())
                    {
                        // Need to use host:port and credentials.
                        serviceProxy.SetHost(_server.HostAndPort);
                        serviceProxy.SetCredentials(_server.GetCreds());
                        int serverVersion = serviceProxy.ExchangeVersion(1);

                        if (serverVersion >= 4)
                        {
                            // This version of the server has a method for deleting all the
                            // matching files and parent folder(s) in one call, so display the
                            // appropriate message and call that method.

                            if (listFiles || DialogResult.Yes == MainForm.ShowMessageBoxBtns("Delete specified files?", MessageBoxButtons.YesNo))
                            {
                                files = serviceProxy.DeleteMany(
                                    txtFileSpec.Text,
                                    txtFolderSpec.Text,
                                    dtpFromTime.Value,
                                    dtpToTime.Value,
                                    int.Parse(txtFromSize.Text) * 1024,
                                    int.Parse(txtToSize.Text) * 1024,
                                    chkBinary.Checked,
                                    chkText.Checked,
                                    chkDeleteFolders.Checked,
                                    listFiles);
                            }
                        }
                        else
                        {
                            string msg = "Sorry, the TracerX-Service you're connected to is an old version that doesn't support this feature.";
                            MainForm.ShowMessageBox(msg);
                        }
                    }
                }

                if (files != null)
                {
                    Log.Info(files.Count, " files were returned by DeleteMany().");

                    if (files.Any())
                    {
                        if (listFiles)
                        {
                            // Display the files.
                            var dlg = new FullText(string.Join("\r\n", files), false, true);
                            dlg.Height = 500;
                            dlg.Text   = "Matching Log Files (" + files.Count + ")";
                            dlg.ShowDialog();
                        }
                        else
                        {
                            MainForm.ShowMessageBox(files.Count.ToString() + " files were deleted.");
                            DidDeleteFiles = true;
                        }
                    }
                    else
                    {
                        MainForm.ShowMessageBox("No files matched the specified criteria.");
                    }
                }
            }
            catch (Exception ex)
            {
                MainForm.ShowMessageBox("An error occurred in the Clean Up Files dialog.\n\n" + ex.ToString());
            }
        }
Exemple #5
0
        // Determines if the specified port is in use by the TracerX service by attempting to connect to it.
        private static void TryConnecting(int port)
        {
            try
            {
                using (ProxyFileEnum serviceProxy = new ProxyFileEnum())
                {
                    serviceProxy.SetHost("localhost:" + port);
                    int serviceInterfaceVersion = serviceProxy.ExchangeVersion(1);

                    // Getting here without an exception means the TracerX service is listening on the port.
                    // Depending on the version, we may be able to get additional info.

                    if (serviceInterfaceVersion < 3)
                    {
                        // That's all we can get (the interface version).
                        MainForm.ShowMessageBox("The specified port is in use by another process that's running the TracerX service.");
                    }
                    else
                    {
                        string processExe;
                        string processVersion;
                        string processAccount;

                        if (serviceInterfaceVersion < 5)
                        {
                            serviceProxy.GetServiceHostInfo(out processExe, out processVersion, out processAccount);
                        }
                        else
                        {
                            // As of version 5, we can get whether the service is impersonating
                            // clients or not with GetServiceHostInfo2, but we don't need to.
                            serviceProxy.GetServiceHostInfo(out processExe, out processVersion, out processAccount);
                        }

                        string msg = "The specified port is in use by another process that's running the TracerX service.";

                        if (processExe != null)
                        {
                            msg += "\n\nExecutable: " + processExe;

                            if (processVersion != null)
                            {
                                msg += " (version " + processVersion + ")";
                            }
                        }

                        if (processAccount != null)
                        {
                            msg += "\n\nAccount: " + processAccount;
                        }

                        MainForm.ShowMessageBox(msg);
                    }
                }
            }
            catch (Exception ex)
            {
                // Assume this means the process using the port is not TracerX.
                MainForm.ShowMessageBox("The specified port is in use by another process.");
            }
        }