コード例 #1
0
ファイル: WBDocument.cs プロジェクト: OliSharpe/wbf
        public void UpdateRecordColumns(String callingUserLogin, WBDocument documentToCopy, IEnumerable <WBColumn> columnsToCopy, String reasonForUpdate)
        {
            // WindowsIdentity identity = WindowsIdentity.GetCurrent();
            WBLogging.RecordsTypes.Verbose("In WBDocument.UpdateRecordColumns() running as: " + Web.CurrentUser.Name);
            WBLogging.RecordsTypes.Verbose("In WBDocument.UpdateRecordColumns() SPSite system account: " + Site.SystemAccount.Name);

            WBLogging.RecordsTypes.Verbose("In WBDocument.UpdateRecordColumns() for " + DebugName);

            bool previousSetting = RecordsLibrary.Web.AllowUnsafeUpdates;

            RecordsLibrary.Web.AllowUnsafeUpdates = true;

            WBLogging.RecordsTypes.Verbose("In WBDocument.UpdateRecordColumns() About to bypass locks on " + DebugName);
            Records.BypassLocks(this.Item, delegate(SPListItem item)
            {
                WBLogging.RecordsTypes.Verbose("In WBDocument.UpdateRecordColumns() inside BypassLocks() for " + DebugName);
                if (item.File.CheckOutType != SPFile.SPCheckOutType.None)
                {
                    WBLogging.RecordsTypes.Verbose("In WBDocument.UpdateRecordColumns() Somehow the record being updated (Record ID = " + this.RecordID + ") was checked out to: " + item.File.CheckedOutByUser.LoginName);
                    item.File.UndoCheckOut();
                }

                WBLogging.RecordsTypes.Verbose("In WBDocument.UpdateRecordColumns(): Checkingout the record copy");
                item.File.CheckOut();
                WBLogging.RecordsTypes.Verbose("In WBDocument.UpdateRecordColumns(): done check out for " + DebugName);

                foreach (WBColumn column in columnsToCopy)
                {
                    if (Item.WBxGet(column) != documentToCopy[column])
                    {
                        item.WBxSet(column, documentToCopy[column]);
                    }
                }
                WBLogging.RecordsTypes.Verbose("In WBDocument.UpdateRecordColumns(): Finished setting all of the columns that needed to be set");

                SPUser callingUser = item.Web.WBxEnsureUserOrNull(callingUserLogin);

                if (callingUserLogin != null)
                {
                    WBLogging.RecordsTypes.Verbose("In WBDocument.UpdateRecordColumns(): Updating with callingUserLogin = "******" and callingUser = "******"In WBDocument.UpdateRecordColumns(): Updating withtout a calling user (callingUserLogin = "******")");
                }

                item.Update();
                WBLogging.RecordsTypes.Verbose("In WBDocument.UpdateRecordColumns(): Done the actual item.Update()");
                item.File.WBxCheckInAs(reasonForUpdate, callingUser);
                WBLogging.RecordsTypes.Verbose("In WBDocument.UpdateRecordColumns(): Done the check in with user from callingUserLogin = " + callingUserLogin);
            });

            RecordsLibrary.Web.AllowUnsafeUpdates = previousSetting;
        }
コード例 #2
0
        /// <summary>
        /// Uses the MIMETypes class to match extensions to known MimeTypes from Guidewire. If changes are made to the document name, the new document URL is returned
        /// </summary>
        /// <param name="documentUrl">The URL of the document to resolve</param>
        /// <param name="mimeType">The MimeType as it exists in ClaimCenter</param>
        /// <returns></returns>
        public static String ResolveMissingExtension(string documentUrl, string mimeType)
        {
            List <string> extension = new List <string>();
            string        newDocUrl = documentUrl;

            //if (Path.HasExtension(newDocUrl)) return newDocUrl;

            // Get the list of known mime types/extensions
            using (MIMETypes mimetypes = new MIMETypes())
            {
                if (mimetypes.ContainsMimetype(mimeType))
                {
                    extension = mimetypes.ExtensionMapping[mimeType];
                }
            }

            // Update the file in SharePoint if no matching extensions were found, or if the mimetype wasn't unknown
            // (mimetypes of unknown should be left alone, Guidewire doesn't know what they are, and we should leave it up to SharePoint to figure out what the file is)
            if (extension.Count > 0 || !extension.Contains("unknown"))
            {
                try
                {
                    using (SPWeb shellWeb = SPContext.Current.Web)
                    {
                        SPSecurity.RunWithElevatedPrivileges(delegate()
                        {
                            using (SPSite site = new SPSite(shellWeb.Site.Url))
                            {
                                using (SPWeb web = site.OpenWeb())
                                {
                                    web.AllowUnsafeUpdates = true;
                                    SPListItem item        = web.GetListItem(documentUrl);
                                    // Bypass the record if needed to, and use the MoveTo method to rename the document
                                    Records.BypassLocks(item, delegate(SPListItem bypassItem)
                                    {
                                        bypassItem.File.MoveTo((documentUrl + extension.First()), true);
                                    });
                                    newDocUrl = documentUrl + extension.First();
                                    web.AllowUnsafeUpdates = false;
                                }
                            }
                        });
                    }
                }
                catch (Exception e)
                {
                    Util.LogError("Adding an extension to the document {1} failed with exception: " + e.Message);
                }
            }

            return(newDocUrl);
        }
コード例 #3
0
        private static bool ProcessWorkMatterDocuments()
        {
            inProgress = true;
            bool success = false;
            try
            {
                foreach(string libraryName in Settings.Default.LibrariesToProcess)
                {
                    using (SPSite site = new SPSite(ConfigurationManager.AppSettings["SiteUrl"], SPUserToken.SystemAccount))
                    {
                        Console.WriteLine("Successfully connected to site at " + site.Url);
                        using (SPWeb web = site.OpenWeb())
                        {
                            Console.WriteLine("Successfully opened SPWeb at " + web.Url);
                            SPList workMatterDocumentLibrary = web.Lists[libraryName];
                            SPQuery query = new SPQuery();
                            query.ViewXml = Util.GetViewQuery();
                            query.QueryThrottleMode = SPQueryThrottleOption.Override;
                            do
                            {
                                SPListItemCollection items = workMatterDocumentLibrary.GetItems(query);
                                int totalItems = items.Count;
                                Console.WriteLine("Processing items " + (query.ListItemCollectionPosition != null ? query.ListItemCollectionPosition.ToString() : "0") + " to " + query.ListItemCollectionPosition + totalItems);
                                query.ListItemCollectionPosition = items.ListItemCollectionPosition;
                                for (int i = 0; i < items.Count; i++)
                                {
                                    SPListItem item = items[i];

                                    try
                                    {
                                        web.AllowUnsafeUpdates = true;
                                        Records.BypassLocks(item, delegate (SPListItem delegateItem)
                                        {
                                            using (DisabledEventsScope scope = new DisabledEventsScope())
                                            {

                                                SPBusinessDataField field = delegateItem.Fields[Resource.FieldBCSWorkMatterDocument] as SPBusinessDataField;
                                                string documentId = Util.GetDocumentId(delegateItem);
                                                using (SPServiceContextScope ctxScope = new SPServiceContextScope(SPServiceContext.GetContext(site)))
                                                {
                                                    try
                                                    {
                                                        Util.SetBCSField(delegateItem, field, documentId, "GetWorkMatterDocumentBySPID");
                                                        Util.ClearFields(item);
                                                        if (delegateItem.Fields.ContainsField(Resource.FieldBCSWorkMatterDocumentStatus) && delegateItem[Resource.FieldBCSWorkMatterDocumentStatus] != null && delegateItem[Resource.FieldBCSWorkMatterDocumentStatus].ToString() == "Final")
                                                        {
                                                            Util.LockItem(delegateItem);
                                                        }
                                                    }
                                                    catch (Exception ex)
                                                    {
                                                        // Swallow the error at this level
                                                    }
                                                }

                                                Console.WriteLine("Document updated. ItemId=" + delegateItem.ID);
                                            }
                                        });
                                    }
                                    catch (Exception ex)
                                    {
                                        Util.LogError("Error updating document: " + ex.Message);
                                        Console.WriteLine("Error updating document: " + ex.Message);
                                    }
                                    finally
                                    {
                                        web.AllowUnsafeUpdates = false;
                                    }
                                }
                            }
                            while (query.ListItemCollectionPosition != null);
                        }
                    }
                }
                success = true;
            }
            catch (Exception ex)
            {
                success = false;
                Util.LogError("Error in ProcessWorkMatterDocuments(): " + ex.Message);
                Console.WriteLine("Error in ProcessWorkMatterDocuments(): " + ex.Message);
            }
            inProgress = false;
            return success;
        }