public static string PrintObject(CombinedSearch item, bool outputAsHtml = false) { //we are assuming the type is in the same assembly, otherwise you would need to ensure namespace prefix and the assembly is loaded Type castToType = Type.GetType(item.Type); dynamic myObject = castToType == null?JsonConvert.DeserializeObject(item.Details) : JsonConvert.DeserializeObject(item.Details, castToType); return(outputAsHtml ? ObjectDumper.DumpHtml(myObject) : ObjectDumper.Dump(myObject)); }
public void StartSearch() { WriteLine($"Enter Your Search Query:"); var basePath = "../AzureSearch"; var query = ReadLine(); var results = Search(query) .ToCombinedSearch() .ApplyIndex(startingIndex: indexOffset) .ToList(); ForegroundColor = Green; var resultsCount = results.Count; WriteLine($"{Environment.NewLine}{resultsCount} results found for : {query}{Environment.NewLine}"); ResetColor(); var table = results.ToStringTable( u => u.Index, u => u.Name, u => u.DisplayType ); WriteLine(table); WriteLine($"{Environment.NewLine}Enter an ID from the results to view, or enter 0 to start a new search"); var input = ReadLine(); if (Int32.TryParse(input, out int inputOption)) { if (inputOption == 0) { StartSearch(); } else { CombinedSearch item = results[inputOption - indexOffset]; if (item.SearchType == SearchType.File) { var file = FileSearch.Create(apiKey, storageKey).DownloadFile($"{basePath}/Downloads", item.Name); WriteLine($"Opening File from {file}"); try { Process.Start(@"cmd.exe ", $@"/c ""{file}"""); } catch (System.ComponentModel.Win32Exception ex) { Console.WriteLine(ex.Message); } } else if (item.SearchType == SearchType.Media) { WriteLine($"Launching Video"); try { Process.Start(@"cmd.exe ", $@"/c ""{basePath}/Media/Output/{item.Details}"""); } catch (System.ComponentModel.Win32Exception ex) { Console.WriteLine(ex.Message); } } else if (item.SearchType == SearchType.Object) { WriteLine(PrintObject(item)); } StartSearch(); } } else { StartSearch(); } }