Пример #1
0
        /// <summary>
        /// Detaches the operation.
        /// </summary>
        /// <param name="commonResponse">Common response object</param>
        /// <param name="clientContext">Client context object</param>
        /// <param name="list">List object</param>
        /// <param name="listItems">List item collection object</param>
        /// <returns>Returns Common response object</returns>
        internal static CommonResponse DetachOperation(CommonResponse commonResponse, ClientContext clientContext, List list, ListItemCollection listItems)
        {
            CommonResponse detachOperationResponse = new CommonResponse();

            try
            {
                ContentType targetDocumentSetContentType = BriefcaseContentTypeHelperFunctions.GetContentType(list, clientContext);
                if (null != targetDocumentSetContentType)
                {
                    foreach (var listItem in listItems)
                    {
                        listItem[ServiceConstantStrings.OneDriveSiteColumn]   = string.Empty;
                        listItem[ConstantStrings.OneDriveContentTypeProperty] = Convert.ToString(targetDocumentSetContentType.Id, CultureInfo.InvariantCulture);
                        listItem.Update();
                        clientContext.ExecuteQuery();
                        commonResponse.Status.Add(true);
                    }
                    detachOperationResponse = commonResponse;
                }
            }
            catch (Exception exception)
            {
                Logger.LogError(exception, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ServiceConstantStrings.LogTableName);
            }
            return(detachOperationResponse);
        }
Пример #2
0
        /// <summary>
        /// Determines whether the content type exists in the content type group under the specified client context.
        /// </summary>
        /// <param name="clientContext">Client context</param>
        /// <param name="web">Object of site</param>
        /// <param name="receivedContentType">Type of the received content</param>
        /// <param name="contentTypeGroup">The content type group</param>
        /// <param name="siteColumns">List of site columns</param>
        internal static bool IsContentTypePresentCheck(ClientContext clientContext, Microsoft.SharePoint.Client.Web web, string receivedContentType, string contentTypeGroup, List <string> siteColumns)
        {
            bool status = true;

            try
            {
                ContentTypeCollection contentTypeCollection = web.ContentTypes;
                clientContext.Load(contentTypeCollection, contentTypes => contentTypes.Include(contentTypeProperties => contentTypeProperties.Group, contentTypeProperties => contentTypeProperties.Name).Where(contentTypeValues => (contentTypeValues.Group == ServiceConstantStrings.OneDriveContentTypeGroup) && (contentTypeValues.Name == ServiceConstantStrings.OneDriveContentTypeName)));
                clientContext.ExecuteQuery();

                if (0 < contentTypeCollection.Count)
                {
                    FieldCollection fields = contentTypeCollection[0].Fields;
                    clientContext.Load(fields, field => field.Include(fieldType => fieldType.Title).Where(column => column.Title == ServiceConstantStrings.OneDriveSiteColumn));
                    clientContext.ExecuteQuery();
                    if (0 == fields.Count)
                    {
                        BriefcaseContentTypeHelperFunctions.AddColumnsToContentType(web, siteColumns, contentTypeCollection[0]);
                        web.Update();
                        clientContext.ExecuteQuery();
                    }
                }
                else
                {
                    status = BriefcaseContentTypeHelperFunctions.CreateContentType(clientContext, web, siteColumns, receivedContentType, contentTypeGroup);
                }
            }
            catch (Exception exception)
            {
                status = false;
                Logger.LogError(exception, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ServiceConstantStrings.LogTableName);
            }
            return(status);
        }
Пример #3
0
        /// <summary>
        /// Uploads the document to matter library.
        /// </summary>
        /// <param name="requestObject">Request Object containing SharePoint App Token</param>
        /// <param name="sourceUrl">URL of the source document</param>
        /// <param name="documentStream">Content stream of the document</param>
        /// <param name="versionInfo">The version information.</param>
        /// <param name="comments">The comments.</param>
        /// <param name="retainCheckOut">retain check out option</param>
        /// <returns>Content Type List for the Request Object containing SharePoint App Token</returns>
        internal static string UploadtoMatter(RequestObject requestObject, string sourceUrl, Stream documentStream, int versionInfo, string comments, bool retainCheckOut)
        {
            string status = ConstantStrings.FALSE;
            string result = ConstantStrings.FALSE;

            try
            {
                if (null != requestObject)
                {
                    ClientContext clientContext;
                    if (!string.IsNullOrWhiteSpace(sourceUrl) && null != documentStream)
                    {
                        string[] sourceUrlParts = sourceUrl.Split(Convert.ToChar(ConstantStrings.DOLLAR, CultureInfo.InvariantCulture));
                        if (2 == sourceUrlParts.Length)
                        {
                            using (clientContext = ServiceUtility.GetClientContext(requestObject.SPAppToken, new Uri(sourceUrlParts[0]), requestObject.RefreshToken))
                            {
                                Microsoft.SharePoint.Client.File file = clientContext.Web.GetFileByServerRelativeUrl(sourceUrlParts[1]);
                                string documentLibraryName            = BriefcaseHelperFunction.getLibraryName(clientContext, file);
                                string contentType = string.Empty;
                                contentType = BriefcaseContentTypeHelperFunctions.ContentTypeByName(requestObject, clientContext, file.Name, sourceUrl, 1, contentType, documentLibraryName);
                                string listContentType = BriefcaseContentTypeHelperFunctions.GetContentTypeList(requestObject, clientContext, sourceUrl, contentType, 1, documentLibraryName);
                                status = BriefcaseContentTypeHelperFunctions.GetContentTypeList(requestObject, clientContext, sourceUrl, contentType, 2, documentLibraryName);
                                FileSaveBinaryInformation fileSaveBinaryInformation = new FileSaveBinaryInformation();
                                fileSaveBinaryInformation.ContentStream = documentStream;
                                file.SaveBinary(fileSaveBinaryInformation);
                                // Check if file is already checked out
                                if (file.CheckOutType == CheckOutType.None)
                                {
                                    file.CheckOut();
                                }
                                // Check the type of Check in to be performed
                                switch (versionInfo)
                                {
                                case 0:
                                    file.CheckIn(comments, CheckinType.MinorCheckIn);
                                    break;

                                case 1:
                                    file.CheckIn(comments, CheckinType.MajorCheckIn);
                                    break;

                                case 2:
                                    file.CheckIn(comments, CheckinType.OverwriteCheckIn);
                                    break;
                                }
                                // Load the Stream data for the file
                                clientContext.ExecuteQuery();
                                status = BriefcaseContentTypeHelperFunctions.GetContentTypeList(requestObject, clientContext, sourceUrl, listContentType, 2, documentLibraryName);
                                // Check whether we need to retain checkout
                                if (retainCheckOut)
                                {
                                    file.CheckOut();
                                    clientContext.ExecuteQuery();
                                }
                                status = string.Concat(ConstantStrings.TRUE, ConstantStrings.Comma, ConstantStrings.Space, file.ServerRelativeUrl);
                            }
                        }
                        result = status;
                    }
                    else
                    {
                        status = string.Concat(ConstantStrings.FALSE, ConstantStrings.Comma, ConstantStrings.Space, TextConstants.MissingParametersMessage);
                        result = status;
                    }
                }
            }
            catch (Exception exception)
            {
                status = string.Concat(ConstantStrings.FALSE, ConstantStrings.Comma, ConstantStrings.Space, ServiceUtility.RemoveEscapeCharacter(exception.Message));
                result = status;
            }
            return(result);
        }
Пример #4
0
        /// <summary>
        /// Uploads the document to OneDrive (Users MySite document library).
        /// </summary>
        /// <param name="requestObject">Request Object containing SharePoint App Token</param>
        /// <param name="collectionOfAttachments">Collection of documents with data for each document</param>
        /// <param name="collectionOfOriginalAttachments">Collection of documents with path of source document</param>
        /// <param name="usersMySite">User's My site URL</param>
        /// <param name="allAttachmentUrl">Attachment URL.</param>
        /// <param name="isOverwrite">Overwrite check</param>
        /// <returns>JSON string specifying path of OneDrive as success and false as failure</returns>
        internal static string UploadtoBriefcase(RequestObject requestObject, Dictionary <string, Stream> collectionOfAttachments, Dictionary <string, string> collectionOfOriginalAttachments, string usersMySite, string[] allAttachmentUrl, int isOverwrite)
        {
            string status = ConstantStrings.FALSE;

            try
            {
                using (ClientContext clientContext = ServiceUtility.GetClientContext(requestObject.SPAppToken, new Uri(usersMySite), requestObject.RefreshToken))
                {
                    Microsoft.SharePoint.Client.Web web = clientContext.Web;
                    string        contentType           = ServiceConstantStrings.OneDriveContentTypeName;  // Get Content Type
                    string        contentTypegroup      = ServiceConstantStrings.OneDriveContentTypeGroup; // Get Group of Content Type
                    List <string> siteColumns           = new List <string>(new string[] { ServiceConstantStrings.OneDriveSiteColumn });
                    bool          isSiteColumnCreated   = BriefcaseContentTypeHelperFunctions.CreateSiteColumn(clientContext, web, siteColumns);
                    if (isSiteColumnCreated)
                    {
                        bool isContentTypeCreated = BriefcaseContentTypeHelperFunctions.IsContentTypePresentCheck(clientContext, web, contentType, contentTypegroup, siteColumns);
                        if (isContentTypeCreated)
                        {
                            List               list = web.Lists.GetByTitle(ServiceConstantStrings.OneDriveDocumentLibraryTitle);
                            string             briefcaseFolderQuery = string.Format(CultureInfo.InvariantCulture, ServiceConstantStrings.BriefcaseFolderQuery, ServiceConstantStrings.LegalBriefcaseFolder);
                            ListItemCollection listItems            = Lists.GetData(clientContext, ServiceConstantStrings.OneDriveDocumentLibraryTitle, briefcaseFolderQuery);
                            BriefcaseContentTypeHelperFunctions.SetContentType(clientContext, list, usersMySite);
                            string defaultContentTypeId = BriefcaseContentTypeHelperFunctions.SetOneDriveDefaultContentType(clientContext, list, contentType);
                            if (ConstantStrings.FALSE != defaultContentTypeId)
                            {
                                web.Update();
                                if (0 == isOverwrite)
                                {
                                    MailAttachmentDetails.CheckoutFailedPosition = 0;
                                    status = BriefcaseUtilityHelperFunctions.NewDocumentToOneDrive(clientContext, collectionOfAttachments, collectionOfOriginalAttachments, allAttachmentUrl, web, usersMySite, defaultContentTypeId);
                                    //// Undo check out in case of failure
                                    //// undo checkout all documents from position MailAttachmentDetails.checkOutFailedPosition
                                    BriefcaseHelperFunction.DiscardDocumentCheckout(requestObject, allAttachmentUrl);
                                }
                                else
                                {
                                    MailAttachmentDetails.CheckoutFailedPosition = 0;
                                    status = BriefcaseUtilityHelperFunctions.OverWriteDocument(collectionOfAttachments, collectionOfOriginalAttachments, usersMySite, status, clientContext, web, listItems, defaultContentTypeId);
                                    string[] returnedStatus = status.Split(Convert.ToChar(ConstantStrings.DOLLAR, CultureInfo.InvariantCulture));
                                    if (ConstantStrings.TRUE == returnedStatus[0])
                                    {
                                        BriefcaseHelperFunction.DiscardDocumentCheckout(requestObject, allAttachmentUrl);
                                    }
                                    status = returnedStatus[1];
                                }
                            }
                            else
                            {
                                MatterCenterException customException = new MatterCenterException(TextConstants.ErrorCodeAssignDefaultContentType, TextConstants.ErrorMessageAssignDefaultContentType);
                                throw customException; // Throw will direct to current function's catch block (if present). If not present then it will direct to parent catch block. Parent will be the calling function
                            }
                        }
                        else
                        {
                            MatterCenterException customException = new MatterCenterException(TextConstants.ErrorCodeCreateSiteContentType, TextConstants.ErrorMessageCreateSiteContentType);
                            throw customException; // Throw will direct to current function's catch block (if present). If not present then it will direct to parent catch block. Parent will be the calling function
                        }
                    }
                    else
                    {
                        MatterCenterException customException = new MatterCenterException(TextConstants.ErrorCodeCreateSiteColumn, TextConstants.ErrorMessageCreateSiteColumn);
                        throw customException; // Throw will direct to current function's catch block (if present). If not present then it will direct to parent catch block. Parent will be the calling function
                    }
                }
            }
            catch (Exception exception)
            {
                Logger.LogError(exception, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ServiceConstantStrings.LogTableName);
                status += ConstantStrings.Semicolon + usersMySite;
            }
            return(status);
        }