コード例 #1
0
ファイル: ApplicationProxiyNode.cs プロジェクト: lucaslra/SPM
        public ApplicationProxyNode(SPServiceApplicationProxy proxy)
        {
            this.Tag = proxy;
            this.SPParent = proxy.Farm;

            this.Setup();
        }
コード例 #2
0
        public ApplicationProxyNode(SPServiceApplicationProxy proxy)
        {
            this.Tag      = proxy;
            this.SPParent = proxy.Farm;

            this.Setup();
        }
コード例 #3
0
        /// <summary>
        /// This method gets invoked when the command is called.
        /// </summary>
        protected override void InternalProcessRecord()
        {
            SPServiceApplicationProxy        resolvedProxy = null;
            ClubCloudServiceApplicationProxy castedProxy   = null;

            resolvedProxy = this.Identity.Read();

            if (resolvedProxy == null)
            {
                this.ThrowTerminatingError(new InvalidOperationException("No service application proxy was found."), ErrorCategory.InvalidOperation, this);
            }

            castedProxy = resolvedProxy as ClubCloudServiceApplicationProxy;

            if (castedProxy == null)
            {
                this.ThrowTerminatingError(new InvalidOperationException("The service application proxy was not of the correct type."), ErrorCategory.InvalidOperation, this);
            }

            if (this.ShouldProcess(castedProxy.Name))
            {
                if (!string.IsNullOrEmpty(this.Name) && (!string.Equals(this.Name.Trim(), castedProxy.Name, StringComparison.OrdinalIgnoreCase)))
                {
                    // Get the service proxy and check for duplicate name
                    ClubCloudServiceProxy     serviceProxy   = SPFarm.Local.ServiceProxies.GetValue <ClubCloudServiceProxy>();
                    SPServiceApplicationProxy duplicateProxy = serviceProxy.ApplicationProxies[this.Name.Trim()];

                    if (duplicateProxy != null)
                    {
                        this.ThrowTerminatingError(new InvalidOperationException("There is already a service application proxy with that name."), ErrorCategory.InvalidOperation, this);
                    }

                    castedProxy.Name = this.Name.Trim();
                    castedProxy.Update();
                }

                if (this.DefaultProxyGroup.IsPresent)
                {
                    SPServiceApplicationProxyGroup group = SPServiceApplicationProxyGroup.Default;

                    if (this.DefaultProxyGroup.ToBool())
                    {
                        group.Add(castedProxy);
                    }
                    else
                    {
                        group.Remove(castedProxy.Id);
                    }
                }
            }
        }
コード例 #4
0
ファイル: History.aspx.cs プロジェクト: davgit/WAS
        protected void Page_Load(object sender, EventArgs e)
        {
            using (SPSite spSite = new SPSite(Web.Url))
            {
                using (SPWeb spWeb = spSite.OpenWeb())
                {
                    try
                    {
                        var proxies = SPServiceContext.Current.GetProxies(typeof(WordServiceApplicationProxy));

                        if (proxies.Any())
                        {
                            _proxy = proxies.First();
                        }
                        else
                        {
                            return;
                        }


                        if (spSite.SiteSubscription != null)
                        {
                            _jobStatuses = ConversionJobStatus.GetAllJobs(_proxy.DisplayName, spSite.UserToken,
                                                                     spSite.SiteSubscription.Id);
                        }
                        else
                        {
                            _jobStatuses = ConversionJobStatus.GetAllJobs(_proxy.DisplayName, spSite.UserToken, null);
                        }
                    }
                    catch (SPException exception)
                    {
                        SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory("NaupliusWASHistory",
                            TraceSeverity.High, EventSeverity.Error),
                            TraceSeverity.Unexpected, "An unexpected error has occurred", exception.StackTrace);
                        return;
                    }
                    catch (InvalidOperationException exception2)
                    {
                        SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory("NaupliusWASStatus",
                            TraceSeverity.High, EventSeverity.Error), TraceSeverity.Unexpected,
                            "An unexpected error has occurred attempting to contact the Word Automation Services. Validate that the" +
                            "Word Automation Service is Started.", exception2.StackTrace);
                        return;
                    }

                    GetJobHistory();
                }
            }
        }
コード例 #5
0
        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();
                }
            }
        }
コード例 #6
0
        public static bool ConvertLibrary(SPList list, string fileFormat, bool isWorkflow, ActivityExecutionContext executionContext)
        {
            ISharePointService wfService = null;

            if (executionContext != null)
            {
                wfService = executionContext.GetService <ISharePointService>();
            }

            using (SPSite spSite = new SPSite(list.ParentWeb.Site.Url))
            {
                using (SPWeb spWeb = spSite.OpenWeb())
                {
                    try
                    {
                        var proxies =
                            SPServiceContext.GetContext(spSite).GetProxies(typeof(WordServiceApplicationProxy));

                        if (proxies.Any())
                        {
                            _proxy = proxies.First();
                        }
                        else
                        {
                            var exception = new SPException();
                            throw exception;
                        }

                        var job = new ConversionJob(_proxy.DisplayName)
                        {
                            UserToken = spSite.UserToken
                        };

                        if (spSite.SiteSubscription != null)
                        {
                            job.SubscriptionId = spSite.SiteSubscription.Id;
                        }

                        job.Settings.OutputFormat = DeriveFileFormat(fileFormat);
                        job.Name = list.Title + "-" + Guid.NewGuid();
                        job.AddLibrary(list, list);
                        job.Start();

                        if (wfService != null)
                        {
                            wfService.LogToHistoryList(executionContext.ContextGuid, SPWorkflowHistoryEventType.WorkflowCompleted,
                                                       0, TimeSpan.Zero, "Information", "Conversion job queued for " + list.Title, string.Empty);
                        }

                        return(true);
                    }
                    catch (SPException exception)
                    {
                        SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory("NaupliusWASStatus",
                                                                                           TraceSeverity.High, EventSeverity.Error), TraceSeverity.Unexpected,
                                                              "An unexpected error has occurred attempting to find the Word Automation Services Proxy", exception.StackTrace);

                        if (wfService != null)
                        {
                            wfService.LogToHistoryList(executionContext.ContextGuid, SPWorkflowHistoryEventType.WorkflowError,
                                                       0, TimeSpan.Zero, "Information", "An unexpected error has occurred attempting to find the" +
                                                       "Word Automation Services Proxy for " + list.Title, exception.StackTrace);
                        }

                        return(false);
                    }
                    catch (InvalidOperationException exception2)
                    {
                        SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory("NaupliusWASStatus",
                                                                                           TraceSeverity.High, EventSeverity.Error), TraceSeverity.Unexpected,
                                                              "An unexpected error has occurred attempting to contact the Word Automation Services. Validate that the" +
                                                              "Word Automation Service is Started.", exception2.StackTrace);

                        if (wfService != null)
                        {
                            wfService.LogToHistoryList(executionContext.ContextGuid, SPWorkflowHistoryEventType.WorkflowError,
                                                       0, TimeSpan.Zero, "Information", "An unexpected error has occurred attempting to contact the " +
                                                       "Word Automation Services. Validate that the Word Automation Service is Started. Attempted to process file " +
                                                       list.Title, exception2.StackTrace);
                        }

                        return(false);
                    }
                }
            }
        }
コード例 #7
0
        public static bool ConvertFolder(SPFolder folderItem, string fileFormat, string location, bool isWorkflow, ActivityExecutionContext executionContext)
        {
            ISharePointService wfService = null;

            if (executionContext != null)
            {
                wfService = executionContext.GetService <ISharePointService>();
            }

            if (string.IsNullOrEmpty(location))
            {
                location = null;
            }

            using (SPSite spSite = new SPSite(location ?? SPContext.Current.Web.Url))
            {
                using (SPWeb spWeb = spSite.OpenWeb())
                {
                    try
                    {
                        var proxies =
                            SPServiceContext.GetContext(spSite).GetProxies(typeof(WordServiceApplicationProxy));

                        if (proxies.Any())
                        {
                            _proxy = proxies.First();
                        }
                        else
                        {
                            var exception = new SPException();
                            throw exception;
                        }

                        var job = new ConversionJob(_proxy.DisplayName)
                        {
                            UserToken = spSite.UserToken
                        };

                        if (spSite.SiteSubscription != null)
                        {
                            job.SubscriptionId = spSite.SiteSubscription.Id;
                        }

                        job.Settings.OutputFormat = DeriveFileFormat(fileFormat);
                        job.Name = folderItem.Name + "-" + Guid.NewGuid();

                        if (string.IsNullOrEmpty(location))
                        {
                            job.AddFolder(folderItem, folderItem, true);
                        }
                        else
                        {
                            if (location.ToLower().Contains("http://"))
                            {
                                location = location.Remove(0, 7);
                            }
                            else if (location.ToLower().Contains("https://"))
                            {
                                location = location.Remove(0, 8);
                            }

                            var index = location.IndexOf('/');

                            if (index > 0)
                            {
                                location = location.Substring(index);
                            }

                            var list = spWeb.GetList(location);

                            try
                            {
                                var folder = list.Items.Add(list.RootFolder.ServerRelativeUrl, SPFileSystemObjectType.Folder,
                                                            folderItem.Name);

                                folder["Title"] = folderItem.Name;
                                folder.Update();
                            }
                            catch (SPException)
                            {
                                //Folder already exists
                            }

                            var folder2 = list.RootFolder.SubFolders[folderItem.Name];

                            job.AddFolder(folderItem, folder2, true);
                        }

                        job.Start();

                        if (wfService != null)
                        {
                            wfService.LogToHistoryList(executionContext.ContextGuid, SPWorkflowHistoryEventType.WorkflowCompleted,
                                                       0, TimeSpan.Zero, "Information", "Conversion job queued for " + folderItem.Name, string.Empty);
                        }

                        return(true);
                    }
                    catch (SPException exception)
                    {
                        SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory("NaupliusWASStatus",
                                                                                           TraceSeverity.High, EventSeverity.Error), TraceSeverity.Unexpected,
                                                              "An unexpected error has occurred attempting to find the Word Automation Services Proxy", exception.StackTrace);

                        if (wfService != null)
                        {
                            wfService.LogToHistoryList(executionContext.ContextGuid, SPWorkflowHistoryEventType.WorkflowError,
                                                       0, TimeSpan.Zero, "Information", "An unexpected error has occurred attempting to find the" +
                                                       "Word Automation Services Proxy for " + folderItem.Name, exception.StackTrace);
                        }

                        return(false);
                    }
                    catch (InvalidOperationException exception2)
                    {
                        SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory("NaupliusWASStatus",
                                                                                           TraceSeverity.High, EventSeverity.Error), TraceSeverity.Unexpected,
                                                              "An unexpected error has occurred attempting to contact the Word Automation Services. Validate that the" +
                                                              "Word Automation Service is Started.", exception2.StackTrace);

                        if (wfService != null)
                        {
                            wfService.LogToHistoryList(executionContext.ContextGuid, SPWorkflowHistoryEventType.WorkflowError,
                                                       0, TimeSpan.Zero, "Information", "An unexpected error has occurred attempting to contact the " +
                                                       "Word Automation Services. Validate that the Word Automation Service is Started. Attempted to process file " +
                                                       folderItem.Name, exception2.StackTrace);
                        }

                        return(false);
                    }
                }
            }
        }
コード例 #8
0
        public static bool ConvertDocument(SPListItem listItem, string fileFormat, string newFileName, bool isWorkflow,
                                           ActivityExecutionContext executionContext, WorkflowContext __Context, SPFolder folder, string settings, bool isImmediate)
        {
            ISharePointService wfService = null;

            if (executionContext != null)
            {
                wfService = executionContext.GetService <ISharePointService>();
            }

            using (SPSite spSite = new SPSite(listItem.ParentList.ParentWeb.Url))
            {
                using (SPWeb spWeb = spSite.OpenWeb())
                {
                    int i       = listItem.Url.IndexOf("/");
                    var listUrl = listItem.Url.Remove(i + 1);

                    var listItemUri        = new Uri(listItem.Web.Url + "/" + listItem.Url);
                    var listItemLibraryUri = new Uri(listItem.Web.Url + "/" + listUrl);

                    var fileName = listItem.Name;
                    var idx      = fileName.LastIndexOf(".", StringComparison.Ordinal);

                    if (string.IsNullOrEmpty(newFileName))
                    {
                        newFileName = fileName.Replace(fileName.Substring(idx, fileName.Length - idx),
                                                       "." + fileFormat);
                    }
                    else
                    {
                        if (isWorkflow)
                        {
                            newFileName = newFileName + fileName.Replace(fileName.Substring(idx, fileName.Length - idx),
                                                                         "." + fileFormat);
                        }
                    }

                    try
                    {
                        var proxies = SPServiceContext.GetContext(spSite).GetProxies(typeof(WordServiceApplicationProxy));

                        if (proxies.Any())
                        {
                            _proxy = proxies.First();
                        }
                        else
                        {
                            var exception = new SPException();
                            throw exception;
                        }

                        #region ImmediateJob
                        if (isImmediate)
                        {
                            SyncConverter immJob;

                            if (isWorkflow)
                            {
                                immJob = new SyncConverter(_proxy.DisplayName)
                                {
                                    UserToken = __Context.InitiatorUser.UserToken
                                };
                            }
                            else
                            {
                                immJob = new SyncConverter(_proxy.DisplayName)
                                {
                                    UserToken = spSite.UserToken
                                };
                            }

                            if (spSite.SiteSubscription != null)
                            {
                                immJob.SubscriptionId = spSite.SiteSubscription.Id;
                            }

                            immJob.Settings.OutputFormat = DeriveFileFormat(fileFormat);

                            if (!string.IsNullOrEmpty(settings))
                            {
                                var splitSettings = settings.Split(';');

                                if (fileFormat.ToLower(CultureInfo.InvariantCulture) == splitSettings[0].Remove(0, 2).ToLower(CultureInfo.InvariantCulture))
                                {
                                    switch (fileFormat)
                                    {
                                    case "xps":
                                    case "pdf":
                                    {
                                        immJob.Settings.FixedFormatSettings.Bookmarks =
                                            (FixedFormatBookmark)
                                            Enum.Parse(typeof(FixedFormatBookmark),
                                                       splitSettings[1].Remove(0, 2));
                                        immJob.Settings.FixedFormatSettings.BalloonState =
                                            (BalloonState)
                                            Enum.Parse(typeof(BalloonState), splitSettings[2].Remove(0, 2));

                                        if (splitSettings.Contains("BitmapEmbeddedFonts"))
                                        {
                                            immJob.Settings.FixedFormatSettings.BitmapEmbeddedFonts = true;
                                        }

                                        if (splitSettings.Contains("IncludeDocumentProperties"))
                                        {
                                            immJob.Settings.FixedFormatSettings.IncludeDocumentProperties = true;
                                        }

                                        if (splitSettings.Contains("IncludeDocumentStructure"))
                                        {
                                            immJob.Settings.FixedFormatSettings.IncludeDocumentStructure = true;
                                        }

                                        if (splitSettings.Contains("OptimizeForMinimumSize"))
                                        {
                                            immJob.Settings.FixedFormatSettings.OutputQuality =
                                                FixedFormatQuality.Minimum;
                                        }

                                        if (splitSettings.Contains("UsePdfA"))
                                        {
                                            immJob.Settings.FixedFormatSettings.UsePDFA = true;
                                        }

                                        break;
                                    }

                                    case "doc":
                                    case "docx":
                                    case "docm":
                                    case "dot":
                                    case "dotx":
                                    case "dotm":
                                    {
                                        immJob.Settings.CompatibilityMode = (CompatibilityMode)
                                                                            Enum.Parse(typeof(CompatibilityMode),
                                                                                       splitSettings[1].Remove(0, 2));

                                        if (splitSettings.Contains("AddThumbnail"))
                                        {
                                            immJob.Settings.AddThumbnail = true;
                                        }

                                        if (splitSettings.Contains("EmbedFonts"))
                                        {
                                            immJob.Settings.AddThumbnail = true;
                                        }

                                        if (splitSettings.Contains("UpdateFields"))
                                        {
                                            immJob.Settings.UpdateFields = true;
                                        }

                                        break;
                                    }
                                    }
                                }
                            }
                            var sStream     = new SPFileStream(spWeb, 0x1000);
                            var inputStream = listItem.File.OpenBinaryStream();

                            immJob.Convert(inputStream, sStream);

                            try
                            {
                                if (folder == null)
                                {
                                    listItem.Folder.Files.Add(newFileName, sStream);
                                }
                                else
                                {
                                    if (spWeb.Url != folder.ParentWeb.Url)
                                    {
                                        using (SPWeb web2 = spSite.OpenWeb(folder.ParentWeb.Url))
                                        {
                                            folder.Files.Add(newFileName, sStream);
                                        }
                                    }
                                    folder.Files.Add(newFileName, sStream);
                                }
                            }
                            catch (Exception exception)
                            {
                                if (wfService != null)
                                {
                                    Exceptions.CheckedOutException(exception, listItem, wfService, executionContext);
                                    return(false);
                                }
                                Exceptions.CheckedOutException(exception, listItem, null, null);
                                return(false);
                            }

                            return(true);
                        }
                        #endregion

                        #region Timer Conversion Job
                        else
                        {
                            ConversionJob job;

                            if (isWorkflow)
                            {
                                job = new ConversionJob(_proxy.DisplayName)
                                {
                                    UserToken = __Context.InitiatorUser.UserToken
                                };
                            }
                            else
                            {
                                job = new ConversionJob(_proxy.DisplayName)
                                {
                                    UserToken = spSite.UserToken
                                };
                            }

                            if (spSite.SiteSubscription != null)
                            {
                                job.SubscriptionId = spSite.SiteSubscription.Id;
                            }

                            job.Settings.OutputFormat = DeriveFileFormat(fileFormat);
                            job.Name = listItem.Name + "-" + Guid.NewGuid();

                            if (!string.IsNullOrEmpty(settings))
                            {
                                var splitSettings = settings.Split(';');

                                if (fileFormat.ToLower(CultureInfo.InvariantCulture) == splitSettings[0].Remove(0, 2).ToLower(CultureInfo.InvariantCulture))
                                {
                                    switch (fileFormat)
                                    {
                                    case "xps":
                                    case "pdf":
                                    {
                                        job.Settings.FixedFormatSettings.Bookmarks =
                                            (FixedFormatBookmark)
                                            Enum.Parse(typeof(FixedFormatBookmark), splitSettings[1].Remove(0, 2));
                                        job.Settings.FixedFormatSettings.BalloonState =
                                            (BalloonState)
                                            Enum.Parse(typeof(BalloonState), splitSettings[2].Remove(0, 2));

                                        if (splitSettings.Contains("BitmapEmbeddedFonts"))
                                        {
                                            job.Settings.FixedFormatSettings.BitmapEmbeddedFonts = true;
                                        }

                                        if (splitSettings.Contains("IncludeDocumentProperties"))
                                        {
                                            job.Settings.FixedFormatSettings.IncludeDocumentProperties = true;
                                        }

                                        if (splitSettings.Contains("IncludeDocumentStructure"))
                                        {
                                            job.Settings.FixedFormatSettings.IncludeDocumentStructure = true;
                                        }

                                        if (splitSettings.Contains("OptimizeForMinimumSize"))
                                        {
                                            job.Settings.FixedFormatSettings.OutputQuality = FixedFormatQuality.Minimum;
                                        }

                                        if (splitSettings.Contains("UsePdfA"))
                                        {
                                            job.Settings.FixedFormatSettings.UsePDFA = true;
                                        }
                                        break;
                                    }

                                    case "doc":
                                    case "docx":
                                    case "docm":
                                    case "dot":
                                    case "dotx":
                                    case "dotm":
                                    {
                                        job.Settings.CompatibilityMode = (CompatibilityMode)
                                                                         Enum.Parse(typeof(CompatibilityMode),
                                                                                    splitSettings[1].Remove(0, 2));

                                        if (splitSettings.Contains("AddThumbnail"))
                                        {
                                            job.Settings.AddThumbnail = true;
                                        }

                                        if (splitSettings.Contains("EmbedFonts"))
                                        {
                                            job.Settings.EmbedFonts = true;
                                        }

                                        if (splitSettings.Contains("UpdateFields"))
                                        {
                                            job.Settings.UpdateFields = true;
                                        }

                                        break;
                                    }
                                    }
                                }
                            }

                            try
                            {
                                if (folder == null)
                                {
                                    job.AddFile(listItemUri.ToString(), listItemLibraryUri + newFileName);
                                }
                                else
                                {
                                    job.AddFile(listItemUri.ToString(),
                                                string.Format("{0}/{1}/{2}", folder.ParentWeb.Url, folder.Url, newFileName));
                                }
                            }
                            catch (Exception exception)
                            {
                                if (wfService != null)
                                {
                                    Exceptions.CheckedOutException(exception, listItem, wfService, executionContext);
                                    return(false);
                                }
                                Exceptions.CheckedOutException(exception, listItem, null, null);
                                return(false);
                            }

                            job.Start();

                            if (wfService != null)
                            {
                                wfService.LogToHistoryList(executionContext.ContextGuid, SPWorkflowHistoryEventType.WorkflowCompleted,
                                                           0, TimeSpan.Zero, "Information", "Conversion job queued for " + listItem.DisplayName, string.Empty);
                            }

                            return(true);

                            #endregion
                        }
                    }
                    catch (SPException exception)
                    {
                        if (wfService != null)
                        {
                            Exceptions.SharePointException(exception, listItem, wfService, executionContext);
                            return(false);
                        }
                        Exceptions.SharePointException(exception, listItem, null, null);
                        return(false);
                    }
                    catch (InvalidOperationException exception)
                    {
                        if (wfService != null)
                        {
                            Exceptions.InvalidOperationException(exception, listItem, wfService, executionContext);
                            return(false);
                        }
                        Exceptions.InvalidOperationException(exception, listItem, null, null);
                        return(false);
                    }
                }
            }
        }
コード例 #9
0
        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);
        }
コード例 #10
0
ファイル: Status.aspx.cs プロジェクト: davgit/WAS
        private void GetJobStatus()
        {
            try
            {
                using (SPSite spSite = new SPSite(Web.Url))
                {
                    using (SPWeb spWeb = spSite.OpenWeb())
                    {
                        try
                        {
                            var proxies = SPServiceContext.Current.GetProxies(typeof(WordServiceApplicationProxy));

                            if (proxies.Any())
                            {
                                _proxy = proxies.First();
                            }
                            else
                            {
                                litErr.Visible = true;
                                return;
                            }


                            if (spSite.SiteSubscription != null)
                            {
                                _jobStatuses = ConversionJobStatus.GetAllJobs(_proxy.DisplayName, spSite.UserToken, spSite.SiteSubscription.Id);
                            }
                            else
                            {
                                _jobStatuses = ConversionJobStatus.GetAllJobs(_proxy.DisplayName, spSite.UserToken, null);
                            }
                        }
                        catch (SPException exception)
                        {
                            SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory("NaupliusWASStatus",
                                                                                               TraceSeverity.High, EventSeverity.Error), TraceSeverity.Unexpected,
                                                                  "An unexpected error has occurred attempting to find the Word Automation Services Proxy", exception.StackTrace);
                            return;
                        }
                        catch (InvalidOperationException exception2)
                        {
                            SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory("NaupliusWASStatus",
                                                                                               TraceSeverity.High, EventSeverity.Error), TraceSeverity.Unexpected,
                                                                  "An unexpected error has occurred attempting to contact the Word Automation Services. Validate that the" +
                                                                  "Word Automation Service is Started.", exception2.StackTrace);
                            return;
                        }
                    }
                }
            }
            catch (SPException exception)
            {
                SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory("NaupliusWASStatus",
                                                                                   TraceSeverity.High, EventSeverity.Error), TraceSeverity.Unexpected,
                                                      "An unexpected error has occurred", exception.StackTrace);
            }

            if (_jobStatuses.Count == 0 || _jobStatuses == null)
            {
                litErr.Visible = true;
                return;
            }

            foreach (var job in _jobStatuses.Reverse().Take(100))
            {
                var itemType   = GetItemType();
                var cJobStatus = new ConversionJobStatus(_proxy.DisplayName, job.JobId, null).GetItems(itemType);

                foreach (var jS in cJobStatus)
                {
                    if (itemType == ItemTypes.Canceled || itemType == ItemTypes.InProgress)
                    {
                        var row = new TableRow();
                        table1.Rows.Add(row);
                        var cell = new TableCell {
                            Text = jS.ConversionId.ToString()
                        };
                        var cell2 = new TableCell {
                            Text = jS.StartTime.ToString()
                        };
                        var cell3 = new TableCell {
                            Text = jS.InputFile
                        };
                        var cell4 = new TableCell {
                            Text = jS.OutputFile
                        };
                        row.Cells.Add(cell);
                        row.Cells.Add(cell2);
                        row.Cells.Add(cell3);
                        row.Cells.Add(cell4);
                    }
                    else if (itemType == ItemTypes.Failed)
                    {
                        var row = new TableRow();
                        table1.Rows.Add(row);
                        var cell = new TableCell {
                            Text = jS.ConversionId.ToString()
                        };
                        var cell2 = new TableCell {
                            Text = jS.InputFile
                        };
                        var cell3 = new TableCell {
                            Text = jS.ErrorCode.ToString(CultureInfo.InvariantCulture)
                        };
                        var cell4 = new TableCell {
                            Text = jS.ErrorMessage
                        };
                        row.Cells.Add(cell);
                        row.Cells.Add(cell2);
                        row.Cells.Add(cell3);
                        row.Cells.Add(cell4);
                    }
                    else if (itemType == ItemTypes.NotStarted)
                    {
                        var row = new TableRow();
                        table1.Rows.Add(row);
                        var cell = new TableCell {
                            Text = jS.ConversionId.ToString()
                        };
                        var cell2 = new TableCell {
                            Text = jS.InputFile
                        };
                        var cell3 = new TableCell {
                            Text = jS.OutputFile
                        };
                        row.Cells.Add(cell);
                        row.Cells.Add(cell2);
                        row.Cells.Add(cell3);
                    }
                    else if (itemType == ItemTypes.Succeeded)
                    {
                        var row = new TableRow();
                        table1.Rows.Add(row);
                        var cell = new TableCell {
                            Text = jS.ConversionId.ToString()
                        };
                        var cell2 = new TableCell {
                            Text = jS.InputFile
                        };
                        var cell3 = new TableCell {
                            Text = jS.OutputFile
                        };
                        var cell4 = new TableCell {
                            Text = jS.CompleteTime.Value.ToString(CultureInfo.InvariantCulture)
                        };
                        row.Cells.Add(cell);
                        row.Cells.Add(cell2);
                        row.Cells.Add(cell3);
                        row.Cells.Add(cell4);
                    }
                }
            }

            if (table1.Rows.Count < 2)
            {
                litErr.Visible = true;
            }
            else
            {
                litErr.Visible = false;
            }
        }