Esempio n. 1
0
        protected override void SaveRequestPreset(SearchConnection searchConnection, SearchQueryRequest searchRequest)
        {
            if (IsSavePreset())
            {
                SearchPreset newPreset = new SearchPreset();
                var          path      = GetPresetFilename(SavePreset);

                newPreset.Name = Path.GetFileNameWithoutExtension(path);
                newPreset.Path = path;

                if (!Path.IsPathRooted(SavePreset))
                {
                    newPreset.Path = Path.Combine(SessionState.Path.CurrentFileSystemLocation.Path, newPreset.Path);
                }

                searchConnection.CopyFrom(searchRequest);

                newPreset.Connection = searchConnection;
                newPreset.Request    = SetSelectProperties(searchRequest);

                newPreset.Save();

                WriteInformation(new HostInformationMessage
                {
                    Message         = $"Preset saved to {newPreset.Path}",
                    ForegroundColor = Host.UI.RawUI.BackgroundColor,        // invert
                    BackgroundColor = Host.UI.RawUI.ForegroundColor,
                    NoNewLine       = false
                }, new[] { "PSHOST" });
            }
        }
        protected override void ProcessRecord()
        {
            try
            {
                base.ProcessRecord();

                SkipSSLValidation = SkipServerCertificateValidation.IsPresent;

                WriteDebug($"Enter {GetType().Name} ProcessRecord");

                SearchConnection searchConnection = new SearchConnection();
                TSearchRequest   searchRequest    = new TSearchRequest();

                // Load Preset
                if (ParameterSetName == "P2")
                {
                    SearchPreset preset = LoadPresetFromFile();

                    searchConnection = preset.Connection;

                    PresetLoaded(ref searchRequest, preset);
                }

                // additional command line argument validation. Throw an error if not valid
                ValidateCommandlineArguments();

                // Set Script Parameters from Command Line. Override in deriving classes

                SetRequestParameters(searchRequest);

                // Save Site/Preset

                if (IsSavePreset())
                {
                    SaveRequestPreset(searchConnection, searchRequest);
                }
                else
                {
                    EnsureValidQuery(searchRequest);

                    ExecuteRequest(searchRequest);
                }
            }
            catch (Exception ex)
            {
                WriteError(new ErrorRecord(ex,
                                           GetErrorId(),
                                           ErrorCategory.NotSpecified,
                                           null)
                           );

                WriteDebug(ex.StackTrace);
            }
        }
Esempio n. 3
0
        internal void SaveHistoryItem()
        {
            var filename = $"history-{DateTime.Now:yyyy-MM-dd_HH-mm-ss}.xml";
            var path     = Path.Combine(_mainWindow.HistoryFolderPath, filename);
            var preset   = new SearchPreset()
            {
                Request    = _mainWindow.GetSearchQueryRequestFromUi(),
                Connection = _mainWindow.GetSearchConnectionFromUi(),
                Path       = path,
                Name       = Path.GetFileNameWithoutExtension(filename)
            };

            var unused = preset.Save();
        }
Esempio n. 4
0
        private void SavePresetToFile(SearchConnection searchConnection, SearchQueryRequest searchQueryRequest)
        {
            if (!String.IsNullOrWhiteSpace(SavePreset))
            {
                SearchPreset newPreset = new SearchPreset();
                var          path      = GetPresetFilename(SavePreset);

                newPreset.Name = Path.GetFileNameWithoutExtension(path);
                newPreset.Path = path;

                if (!Path.IsPathRooted(SavePreset))
                {
                    newPreset.Path = Path.Combine(SessionState.Path.CurrentFileSystemLocation.Path, newPreset.Path);
                }

                newPreset.Connection = searchConnection;
                newPreset.Request    = SetSelectProperties(searchQueryRequest);

                newPreset.Save();

                WriteVerbose("Configuration saved to " + newPreset.Path);
            }
        }
 protected abstract void PresetLoaded(ref TSearchRequest searchRequest, SearchPreset preset);
Esempio n. 6
0
        protected override void ProcessRecord()
        {
            try
            {
                base.ProcessRecord();

                SkipSSLValidation = SkipServerCertificateValidation.IsPresent;

                WriteDebug($"Enter {GetType().Name} ProcessRecord");

                SearchConnection searchConnection = new SearchConnection();
                TSearchRequest   searchRequest    = new TSearchRequest();

                // Load Preset
                if (ParameterSetName == "P2")
                {
                    SearchPreset preset = LoadPresetFromFile();

                    searchConnection = preset.Connection;

                    PresetLoaded(ref searchRequest, preset);
                }

                // additional command line argument validation. Throw an error if not valid
                ValidateCommandlineArguments();

                // Set Script Parameters from Command Line. Override in deriving classes

                SetRequestParameters(searchRequest);

                // Save Site/Preset

                if (IsSavePreset())
                {
                    SaveRequestPreset(searchConnection, searchRequest);
                }
                else
                {
                    EnsureValidQuery(searchRequest);

                    WriteVerboseInformation(searchRequest);

                    ExecuteRequest(searchRequest);
                }
            }
            catch (Exception ex)
            {
                // always write last error to a file with as much detail as possible.
                try
                {
                    WriteErrorDetailsToFile(ex);
                }
                catch (Exception wedEx)
                {
                    WriteWarning($"Failed to write error details to file: {wedEx.Message}");
                    WriteDebug(wedEx.StackTrace);
                }

                WriteError(CreateErrorRecord(ex));
                if (ex.InnerException != null)
                {
                    WriteError(CreateErrorRecord(ex.InnerException));
                }

                WriteDebug(ex.StackTrace);

                WriteWarning($"Error details were written to {GetLastErrorFile()}.");
            }
        }
Esempio n. 7
0
 protected override void PresetLoaded(ref SearchQueryRequest searchRequest, SearchPreset preset)
 {
     searchRequest = preset.Request;
 }
 protected override void PresetLoaded(ref SearchSuggestionsRequest searchRequest, SearchPreset preset)
 {
     searchRequest.CopyFrom(preset.Request);
 }
Esempio n. 9
0
        //public string SelectPropertiesAsString
        //{
        //    get
        //    {
        //        return SelectProperties == null ?  null : string.Join(",", SelectProperties);
        //    }

        //    private set
        //    {
        //        AddSelectProperty(value);
        //    }
        //}

        protected override void ProcessRecord()
        {
            try
            {
                base.ProcessRecord();

                WriteDebug("Enter ProcessRecord");

                SearchConnection   searchConnection   = new SearchConnection();
                SearchQueryRequest searchQueryRequest = new SearchQueryRequest();

                // Load Preset
                if (ParameterSetName == "P2")
                {
                    string path = GetPresetFilename(LoadPreset, true);

                    WriteVerbose("Loading preset " + path);

                    SearchPreset preset = new SearchPreset(path, true);

                    searchConnection   = preset.Connection;
                    searchQueryRequest = preset.Request;
                }

                // Set Script Parameters from Command Line

                SetRequestParameters(searchConnection, searchQueryRequest);

                // Save Site/Preset

                if (!(String.IsNullOrWhiteSpace(SaveSite) && String.IsNullOrWhiteSpace(SavePreset)))
                {
                    if (!String.IsNullOrWhiteSpace(SaveSite))
                    {
                        SaveSiteToFile(searchConnection);
                    }

                    if (!String.IsNullOrWhiteSpace(SavePreset))
                    {
                        SavePresetToFile(searchConnection, searchQueryRequest);
                    }
                }
                else // Perform the Search
                {
                    EnsureValidQuery(searchQueryRequest);

                    // split select properties
                    //splitSelectProperties(searchQueryRequest);

                    if (LimitAll || RowLimit > SearchResultBatchSize)
                    {
                        // Try to loop through all results in increments of 500
                        searchQueryRequest.RowLimit = SearchResultBatchSize;

                        int totalRows = (StartRow.HasValue ? StartRow.Value : 0) + 1;
                        int remaining = 0;

                        while (searchQueryRequest.StartRow < totalRows)
                        {
                            ShowProgress(searchQueryRequest.StartRow.Value, totalRows, remaining);

                            totalRows = GetResults(searchQueryRequest);

                            if (!LimitAll)
                            {
                                totalRows = (RowLimit.HasValue ? RowLimit.Value : rowLimitDefault);
                            }
                            searchQueryRequest.StartRow += SearchResultBatchSize;
                            remaining = totalRows - searchQueryRequest.StartRow.Value;
                            //Console.WriteLine(remaining);
                            searchQueryRequest.RowLimit = remaining < SearchResultBatchSize ? remaining : SearchResultBatchSize;
                        }
                    }
                    else
                    {
                        GetResults(searchQueryRequest);
                    }
                }
            }
            catch (Exception ex)
            {
                WriteError(new ErrorRecord(ex,
                                           "SearchSPIndexError",
                                           ErrorCategory.NotSpecified,
                                           null)
                           );

                WriteDebug(ex.StackTrace);
            }
        }