public ParagoServiceClient(SPServiceContext serviceContext) { if (serviceContext == null) { throw new ArgumentNullException("serviceContext"); } _proxy = serviceContext.GetDefaultProxy(typeof(ParagoServiceApplicationProxy)) as ParagoServiceApplicationProxy; if (_proxy == null) { throw new InvalidOperationException("Parago Service Application Proxy not found"); } }
/// <summary> /// Static invoke method implementation /// </summary> internal static void Invoke(SPServiceContext serviceContext, CodeToRunOnApplicationProxy codeBlock) { if (null == serviceContext) { throw new ArgumentNullException("serviceContext"); } ServiceApplicationProxy proxy = (ServiceApplicationProxy)serviceContext.GetDefaultProxy(typeof(ServiceApplicationProxy)); if (null == proxy) { throw new InvalidOperationException("SharePoint Identity Proxy not found."); } using (new SPServiceContextScope(serviceContext)) { codeBlock(proxy); } }
internal static void Invoke(SPServiceContext serviceContext, CodeToRunOnApplicationProxy codeBlock) { if (serviceContext == null) { throw new ArgumentNullException("serviceContext"); } // get service app proxy from the context DayNamerServiceApplicationProxy proxy = (DayNamerServiceApplicationProxy)serviceContext.GetDefaultProxy(typeof(DayNamerServiceApplicationProxy)); if (proxy == null) { throw new InvalidOperationException("Unable to obtain object reference to the day namer service application proxy."); } // run the code block on the proxy using (new SPServiceContextScope(serviceContext)) { codeBlock(proxy); } }
internal static void Invoke(SPServiceContext serviceContext, Action <BaristaServiceApplicationProxy> codeBlock) { if (serviceContext == null) { throw new ArgumentNullException("serviceContext"); } // get service app proxy from the context var proxy = (BaristaServiceApplicationProxy)serviceContext.GetDefaultProxy(typeof(BaristaServiceApplicationProxy)); if (proxy == null) { throw new InvalidOperationException("Unable to obtain object reference to Barista service proxy."); } // run the code block on the proxy using (new SPServiceContextScope(serviceContext)) { codeBlock(proxy); } }
protected void ExecuteSearchQuery(string searchQueryText) { Logging.Logger.Instance.Info("Executing Search Query"); //TODO: Refactor this to allow reuse with the btnSave code below SPServiceContext serviceContext = SPServiceContext.Current; SPServiceApplicationProxy proxy = serviceContext.GetDefaultProxy(typeof(SearchServiceApplicationProxy)); SearchServiceApplicationProxy searchAppProxy = proxy as SearchServiceApplicationProxy; string scopeName = String.Empty; if (SPContext.Current.Site.RootWeb.AllProperties.Contains(SusDeb.DOI.Common.Utilities.eCaseConstants.PropertyBagKeys.ECASE_SAVED_SEARCH_RESULTS_SCOPE)) { scopeName = SPContext.Current.Site.RootWeb.AllProperties[SusDeb.DOI.Common.Utilities.eCaseConstants.PropertyBagKeys.ECASE_SAVED_SEARCH_RESULTS_SCOPE] as string; } Logging.Logger.Instance.Info(String.Format("Scope retrieved from property bag setting. Scope: {0}; Setting Name: {1} ; Site: {2}", scopeName, SusDeb.DOI.Common.Utilities.eCaseConstants.PropertyBagKeys.ECASE_SAVED_SEARCH_RESULTS_SCOPE, SPContext.Current.Site.RootWeb.Url), Logging.DiagnosticsCategories.eCaseSearch); if (!String.IsNullOrEmpty(searchQueryText)) { using (KeywordQuery query = new KeywordQuery(SPContext.Current.Site)) { int rowsPerSet = 50; query.QueryText = queryLabel.Text; query.ResultsProvider = SearchProvider.Default; query.ResultTypes = ResultType.RelevantResults; query.RowLimit = rowsPerSet; query.TrimDuplicates = false; query.EnableStemming = true; if (!String.IsNullOrEmpty(scopeName)) { query.HiddenConstraints = "scope:\"" + scopeName + "\""; } ResultTableCollection resultsTableCollection = query.Execute(); rowCountSpan.InnerText = resultsTableCollection[ResultType.RelevantResults].TotalRows.ToString(); } } }
static void Main(string[] args) { using (SPSite site = new SPSite("http://portal.spdev16.com/one-stop-shop")) { using (SPWeb web = site.OpenWeb()) { SPServiceContext serviceContext = SPServiceContext.GetContext(site); var searchApplicationProxy = (SearchServiceApplicationProxy)serviceContext.GetDefaultProxy(typeof(SearchServiceApplicationProxy)); //var owner = new SearchObjectOwner(SearchObjectLevel.SPSite, web); var owner = new SearchObjectOwner(SearchObjectLevel.SPWeb, web); ICollection <ResultItemType> itemTypes = searchApplicationProxy.GetResultItemTypes(null, null, owner, true); ResultItemType item = CreateResultType(web, "Internal Resource - Deployed", "/_catalogs/masterpage/Display Templates/Search/Item_InternalResource.js", new PropertyRule[] { CustomPropertyRule("ContentTypeId", PropertyRuleOperator.DefaultOperator.Contains, new string[] { "41E5CAB13DEA48B8A69A7A47EA4F4EE4" }) }, false); searchApplicationProxy.AddResultItemType(item); } } }
private static ISecureStore GetSecureStore(SPSite site) { SPServiceContext context = SPServiceContext.GetContext(site); SecureStoreServiceApplicationProxy proxy = (SecureStoreServiceApplicationProxy)context.GetDefaultProxy(typeof(SecureStoreServiceApplicationProxy)); if (proxy == null) { throw new InvalidOperationException("This web application does not have connections to Secure store service application"); } SecureStoreService service = proxy.Farm.Services.OfType <SecureStoreService>().FirstOrDefault(); SecureStoreServiceApplication application = (SecureStoreServiceApplication)service.Applications.FirstOrDefault(v => v.IsConnected(proxy)); if (!application.IsMasterSecretKeyPopulated()) { throw new InvalidOperationException("Master secret key not set for secure store service application"); } return(((SecureStoreServiceProxy)proxy.Parent).GetSecureStore(context)); }
protected void saveSearchResultsButton_Click(object sender, EventArgs e) { Logging.Logger.Instance.Info("Begin Saving Search Results"); string scopeName = String.Empty; if (SPContext.Current.Site.RootWeb.AllProperties.Contains(SusDeb.DOI.Common.Utilities.eCaseConstants.PropertyBagKeys.ECASE_SAVED_SEARCH_RESULTS_SCOPE)) { scopeName = SPContext.Current.Site.RootWeb.AllProperties[SusDeb.DOI.Common.Utilities.eCaseConstants.PropertyBagKeys.ECASE_SAVED_SEARCH_RESULTS_SCOPE] as string; } Logging.Logger.Instance.Info(String.Format("Scope retrieved from property bag setting. Scope: {0}; Setting Name: {1} ; Site: {2}", scopeName, SusDeb.DOI.Common.Utilities.eCaseConstants.PropertyBagKeys.ECASE_SAVED_SEARCH_RESULTS_SCOPE, SPContext.Current.Site.RootWeb.Url), Logging.DiagnosticsCategories.eCaseSearch); SPServiceContext serviceContext = SPServiceContext.Current; SPServiceApplicationProxy proxy = serviceContext.GetDefaultProxy(typeof(SearchServiceApplicationProxy)); SearchServiceApplicationProxy searchAppProxy = proxy as SearchServiceApplicationProxy; if (!String.IsNullOrEmpty(savedSearchNameTextBox.Text)) //&& !String.IsNullOrEmpty(Request.QueryString["query"])) { using (KeywordQuery query = new KeywordQuery(SPContext.Current.Site)) { int rowsPerSet = 50; query.QueryText = queryLabel.Text; query.ResultsProvider = SearchProvider.Default; query.ResultTypes = ResultType.RelevantResults; query.TrimDuplicates = false; query.EnableStemming = true; if (!String.IsNullOrEmpty(scopeName)) { Logging.Logger.Instance.Info(String.Format("Adding scope to hidden constraints: {0}", scopeName), Logging.DiagnosticsCategories.eCaseSearch); query.HiddenConstraints = "scope:\"" + scopeName + "\""; } query.RowLimit = rowsPerSet; ResultTableCollection resultsTableCollection = query.Execute(); if (resultsTableCollection.Count > 0) { //save search result entry string connectionString = SPContext.Current.Site.RootWeb.Properties[SusDeb.DOI.Common.Utilities.eCaseConstants.PropertyBagKeys.ECASE_DB_CONNECTION_STRING]; Int64 searchRowIdentity = 0; using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(connectionString)) { Logging.Logger.Instance.Info(String.Format("Opening database connection to: {0}", connectionString)); conn.Open(); using (System.Data.SqlClient.SqlTransaction trans = conn.BeginTransaction()) { //Insert the Saved Search Results Parent Entry using (System.Data.SqlClient.SqlCommand parentInsertCommand = new System.Data.SqlClient.SqlCommand()) { parentInsertCommand.Connection = conn; parentInsertCommand.Transaction = trans; parentInsertCommand.CommandType = CommandType.StoredProcedure; parentInsertCommand.CommandText = "CreateSavedSearchResult"; if (!IsNew) { parentInsertCommand.Parameters.AddWithValue("@Id", Request.QueryString["id"]); } parentInsertCommand.Parameters.AddWithValue("@Name", savedSearchNameTextBox.Text); parentInsertCommand.Parameters.AddWithValue("@Description", savedSearchDescriptionTextBox.Text); parentInsertCommand.Parameters.AddWithValue("@Query", queryLabel.Text); parentInsertCommand.Parameters.AddWithValue("@Owner", SPContext.Current.Web.CurrentUser.LoginName); searchRowIdentity = (Int64)parentInsertCommand.ExecuteScalar(); } using (System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter()) { if (IsNew) //skip updating the results if this isn't a new result set to save time and effort { string maxResultsString = SPContext.Current.Site.RootWeb.Properties[SusDeb.DOI.Common.Utilities.eCaseConstants.PropertyBagKeys.ECASE_SAVED_SEARCH_RESULTS_MAX_RESULTS]; int maxResults; if (!int.TryParse(maxResultsString, out maxResults)) { int.TryParse(SusDeb.DOI.Common.Utilities.eCaseConstants.PropertyBagDefaultValues.ECASE_SAVED_SEARCH_RESULTS_MAX_RESULTS, out maxResults); } Logging.Logger.Instance.Info(String.Format("Results limit: {0}", maxResults), Logging.DiagnosticsCategories.eCaseSearch); ResultTable results = resultsTableCollection[ResultType.RelevantResults]; int startRow = 0; int rowsFound = 0; int lastRow = startRow + results.RowCount; using (System.Data.SqlClient.SqlCommand childInsertCommand = new System.Data.SqlClient.SqlCommand()) { childInsertCommand.Connection = conn; childInsertCommand.Transaction = trans; childInsertCommand.CommandText = @"INSERT INTO SavedSearchResultItems ( SavedSearchResultId, WorkId, Rank, Author, Size, Path, Description, SiteName, HitHighlightedSummary, HitHighlightedProperties, ContentClass, IsDocument, PictureThumbnailUrl, Url, ServerRedirectedUrl, FileExtension, SpSiteUrl, docvector, fcocount, fcoid, PictureWidth, PictureHeight ) VALUES ( @SavedSearchResultId, @WorkId, @Rank, @Author, @Size, @Path, @Description, @SiteName, @HitHighlightedSummary, @HitHighlightedProperties, @ContentClass, @IsDocument, @PictureThumbnailUrl, @Url, @ServerRedirectedUrl, @FileExtension, @SpSiteUrl, @docvector, @fcocount, @fcoid, @PictureWidth, @PictureHeight )"; childInsertCommand.Parameters.Add("@SavedSearchResultId", System.Data.SqlDbType.BigInt); childInsertCommand.Parameters["@SavedSearchResultId"].Value = searchRowIdentity; childInsertCommand.Parameters.Add("@WorkId", System.Data.SqlDbType.NVarChar, 50, "WorkId"); childInsertCommand.Parameters.Add("@Rank", System.Data.SqlDbType.Int, 0, "Rank"); childInsertCommand.Parameters.Add("@Author", System.Data.SqlDbType.NVarChar, 50, "Author"); childInsertCommand.Parameters.Add("@Size", System.Data.SqlDbType.Int, 50, "Size"); childInsertCommand.Parameters.Add("@Path", System.Data.SqlDbType.NVarChar, 500, "Path"); childInsertCommand.Parameters.Add("@Description", System.Data.SqlDbType.NVarChar, 500000, "Description"); childInsertCommand.Parameters.Add("@SiteName", System.Data.SqlDbType.NVarChar, 500, "SiteName"); childInsertCommand.Parameters.Add("@HitHighlightedSummary", System.Data.SqlDbType.NVarChar, 500000, "HitHighlightedSummary"); childInsertCommand.Parameters.Add("@HitHighlightedProperties", System.Data.SqlDbType.NVarChar, 500000, "HitHighlightedProperties"); childInsertCommand.Parameters.Add("@ContentClass", System.Data.SqlDbType.NVarChar, 50, "ContentClass"); childInsertCommand.Parameters.Add("@IsDocument", System.Data.SqlDbType.Bit, 0, "IsDocument"); childInsertCommand.Parameters.Add("@PictureThumbnailUrl", System.Data.SqlDbType.NVarChar, 500, "PictureThumbnailUrl"); childInsertCommand.Parameters.Add("@Url", System.Data.SqlDbType.NVarChar, 500, "Url"); childInsertCommand.Parameters.Add("@ServerRedirectedUrl", System.Data.SqlDbType.NVarChar, 500, "ServerRedirectedUrl"); childInsertCommand.Parameters.Add("@FileExtension", System.Data.SqlDbType.NVarChar, 500, "FileExtension"); childInsertCommand.Parameters.Add("@SpSiteUrl", System.Data.SqlDbType.NVarChar, 500, "SpSiteUrl"); childInsertCommand.Parameters.Add("@docvector", System.Data.SqlDbType.NVarChar, 500, "docvector"); childInsertCommand.Parameters.Add("@fcocount", System.Data.SqlDbType.Int, 0, "fcocount"); childInsertCommand.Parameters.Add("@fcoid", System.Data.SqlDbType.NVarChar, 50, "fcoid"); childInsertCommand.Parameters.Add("@PictureWidth", System.Data.SqlDbType.Int, 0, "PictureWidth"); childInsertCommand.Parameters.Add("@PictureHeight", System.Data.SqlDbType.Int, 0, "PictureHeight"); da.InsertCommand = childInsertCommand; //if we've found a number of rows <= the total rows in the result set AND //the current result set contains > 0 results (there are still new results being found) AND //we've found <= the maximum number of rows we're allowing to be saved while (rowsFound <= results.TotalRows && results.RowCount > 0 && rowsFound <= maxResults) { da.Update(results.Table); //set the start row = the last row we found query.StartRow = lastRow; //increment the last row we found by the number of results we retrieved lastRow += results.RowCount; rowsFound += results.RowCount; Logging.Logger.Instance.Info(String.Format("Results Found: {0}; Last Result Found: {1}", rowsFound, query.StartRow), Logging.DiagnosticsCategories.eCaseSearch); resultsTableCollection = query.Execute(); results = resultsTableCollection[ResultType.RelevantResults]; } } } using (System.Data.SqlClient.SqlDataAdapter permsAdapter = new System.Data.SqlClient.SqlDataAdapter()) { //for permissions, always remove all items and then add them back using (System.Data.SqlClient.SqlCommand permsDeleteCommand = new System.Data.SqlClient.SqlCommand()) { permsDeleteCommand.Connection = conn; permsDeleteCommand.Transaction = trans; permsDeleteCommand.CommandText = @"DELETE FROM SavedSearchResultPermissions WHERE SavedSearchResultsId = @SavedSearchResultsId "; permsDeleteCommand.Parameters.Add("@SavedSearchResultsId", System.Data.SqlDbType.BigInt); permsDeleteCommand.Parameters["@SavedSearchResultsId"].Value = searchRowIdentity; permsDeleteCommand.ExecuteNonQuery(); } using (System.Data.SqlClient.SqlCommand permsInsertCommand = new System.Data.SqlClient.SqlCommand()) { permsInsertCommand.Connection = conn; permsInsertCommand.Transaction = trans; permsInsertCommand.CommandText = @"INSERT INTO SavedSearchResultPermissions ( SavedSearchResultsId, PermissionName ) VALUES ( @SavedSearchResultsId, @PermissionName )"; permsInsertCommand.Parameters.Add("@SavedSearchResultsId", System.Data.SqlDbType.BigInt); permsInsertCommand.Parameters["@SavedSearchResultsId"].Value = searchRowIdentity; permsInsertCommand.Parameters.Add("@PermissionName", System.Data.SqlDbType.NVarChar, 100, "PermissionName"); foreach (object account in shareWithPeopleEditor.Accounts) { permsInsertCommand.Parameters["@PermissionName"].Value = account.ToString(); permsInsertCommand.ExecuteNonQuery(); } } } } trans.Commit(); Microsoft.SharePoint.Utilities.SPUtility.Redirect( Microsoft.SharePoint.Utilities.SPUtility.GetPageUrlPath(Context) + String.Format("?id={0}", searchRowIdentity), Microsoft.SharePoint.Utilities.SPRedirectFlags.Default, Context ); } } } } } PopulateSavedSearchResultsSetsInfo(); SetFormDisplayMode(false); }
/// <summary> /// Gets a search service application connected to the specified site collection. /// </summary> /// <param name="site">A site collection object.</param> /// <returns>A search service application.</returns> public static SearchServiceApplication GetSearchServiceApplication(SPSite site) { CommonHelper.ConfirmNotNull(site, "site"); SPServiceContext serviceContext = SPServiceContext.GetContext(site); SearchServiceApplicationProxy searchApplicationProxy = (SearchServiceApplicationProxy)serviceContext.GetDefaultProxy(typeof(SearchServiceApplicationProxy)); Guid applicationId = searchApplicationProxy.GetSearchServiceApplicationInfo().SearchServiceApplicationId; return(SearchService.Service.SearchApplications.GetValue <SearchServiceApplication>(applicationId)); }