public SlideTagExCollection GetSlideTags(PresentationPart presentationPart)
        {
            TagList tagList = null;
            SlideTagExCollection slideTagList = new SlideTagExCollection();

            foreach (var sldPart in presentationPart.SlideParts)
            {
                var slide = presentationPart.Presentation.SlideIdList.Where(s => ((SlideId)s).RelationshipId == presentationPart.GetIdOfPart(sldPart)).FirstOrDefault();

                int index = presentationPart.Presentation.SlideIdList.ToList().IndexOf(slide);

                foreach (UserDefinedTagsPart tagPart in sldPart.UserDefinedTagsParts)
                {
                    tagList = tagPart.TagList;

                    foreach (Tag tag in tagList.ChildElements)
                    {
                        if (tag.Name.Value.Equals(PL_TAG))
                        {
                            SlideTagEx slideTagEx = null;
                            slideTagEx = XmlUtils.Deserialize <SlideTagEx>(tag.Val.ToString());
                            slideTagEx.PptSlideIndex = ++index;
                            slideTagEx.Title         = sldPart.Slide.InnerText;
                            if (slideTagEx != null)
                            {
                                slideTagList.Add(slideTagEx);
                            }
                        }
                    }
                }
            }

            return(slideTagList);
        }
Пример #2
0
        public bool VerifyFile(CheckUpdateDto data)
        {
            FileTag fileTags = new FileTag();
            SlideTagExCollection     slideTags = new SlideTagExCollection();
            LibrarianContentManifest libraryContentManifest = new LibrarianContentManifest();

            using (Stream stream = new FileStream(data.FileUrl, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                using (PresentationDocument openXmlDoc = PresentationDocument.Open(stream, false))
                {
                    var presentationPart = openXmlDoc.PresentationPart;
                    fileTags  = _tagManagerService.GetFileTag(presentationPart);
                    slideTags = _tagManagerService.GetSlideTags(presentationPart);
                    libraryContentManifest = XmlUtils.Deserialize <LibrarianContentManifest>(_filesService.GetCustomXmlPart(presentationPart));

                    if (fileTags != null)
                    {
                        return(true);
                    }

                    if (slideTags.Count > 0)
                    {
                        return(true);
                    }

                    if (libraryContentManifest != null)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Пример #3
0
        //PRIVATE METHOD
        private bool CheckFileForUpdates(FileTag fileTag, SlideTagExCollection slideTags, CheckUpdateDto fileInfo)
        {
            bool updatesExist = false;

            if (fileTag != null)
            {
                updatesExist = CheckContentForUpdates(fileTag.File.ContentType, fileTag.File.LastModDate.ToUniversalTime(), fileInfo);
            }

            if (slideTags != null)
            {
                updatesExist |= CheckSlidesForUpdates(slideTags, isLibraryFile, fileInfo);
            }

            return(updatesExist);
        }
        public bool SetTags(CheckUpdateDto data, bool overwriteExistingTags)
        {
            bool setTags = false;

            using (Stream stream = new FileStream(data.FileUrl, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
            {
                using (PresentationDocument openXmlDoc = PresentationDocument.Open(stream, true))
                {
                    var presentationPart           = openXmlDoc.PresentationPart;
                    SlideTagExCollection slideTags = GetSlideTags(presentationPart);
                    var libraryFileSlides          = _fileService.GetFileSlidesInfo(data);

                    if (overwriteExistingTags || !slideTags.Any())
                    {
                        var fileInfo = _fileService.GetFileInfo(data);

                        FileTag fileTag = new FileTag();
                        fileTag.Library.Environment = data.ServerInfo.EnvironmentName;
                        fileTag.Library.ShortName   = data.ServerInfo.ShortLibraryName;
                        fileTag.File.Id             = int.Parse(data.FileId);
                        fileTag.File.ContentType    = ContentType.File;
                        fileTag.File.LastModDate    = fileInfo.LastModDate.Value.ToLocalTime();

                        TagList tagList = new TagList();
                        tagList.Append(new Tag()
                        {
                            Name = PL_TAG,
                            Val  = XmlUtils.Serialize(fileTag)
                        });

                        if (presentationPart.UserDefinedTagsPart == null)
                        {
                            presentationPart.AddNewPart <UserDefinedTagsPart>();
                            presentationPart.UserDefinedTagsPart.TagList = tagList;
                        }

                        foreach (var slidePart in presentationPart.SlideParts)
                        {
                            var slideId = presentationPart.Presentation.SlideIdList.Where(s => ((SlideId)s).RelationshipId == presentationPart.GetIdOfPart(slidePart)).Select(s => (SlideId)s).FirstOrDefault();

                            var slideInfo = libraryFileSlides.Slides.Where(x => x.SlidePptId == slideId.Id).FirstOrDefault();

                            SlideTag slideTag = new SlideTag(fileTag);
                            slideTag.Slide.Id          = slideInfo.SlideId;
                            slideTag.Slide.LastModDate = ((DateTime)slideInfo.LastModDate).ToLocalTime();

                            Tag slideObjectTag = new Tag()
                            {
                                Name = PL_TAG, Val = XmlUtils.Serialize(slideTag)
                            };
                            UserDefinedTagsPart userDefinedTagsPart1 = slidePart.AddNewPart <UserDefinedTagsPart>();
                            if (userDefinedTagsPart1.TagList == null)
                            {
                                userDefinedTagsPart1.TagList = new TagList();
                            }

                            userDefinedTagsPart1.TagList.Append(slideObjectTag);

                            var id = slidePart.GetIdOfPart(userDefinedTagsPart1);

                            if (slidePart.Slide.CommonSlideData == null)
                            {
                                slidePart.Slide.CommonSlideData = new CommonSlideData();
                            }
                            if (slidePart.Slide.CommonSlideData.CustomerDataList == null)
                            {
                                slidePart.Slide.CommonSlideData.CustomerDataList = new CustomerDataList();
                            }
                            CustomerDataTags tags = new CustomerDataTags
                            {
                                Id = id
                            };
                            slidePart.Slide.CommonSlideData.CustomerDataList.AppendChild(tags);

                            slidePart.Slide.Save();
                        }
                    }
                    else if (presentationPart.UserDefinedTagsPart == null)
                    {
                        FileTag fileTag = new FileTag();
                        fileTag.Library.Environment = data.ServerInfo.EnvironmentName;
                        fileTag.Library.ShortName   = data.ServerInfo.ShortLibraryName;
                        fileTag.File.Id             = -1;
                        fileTag.File.ContentType    = ContentType.Undefined;
                        fileTag.File.LastModDate    = DateTime.Now;

                        TagList tagList = new TagList();
                        tagList.Append(new Tag()
                        {
                            Name = PL_TAG,
                            Val  = XmlUtils.Serialize(fileTag)
                        });

                        if (presentationPart.UserDefinedTagsPart == null)
                        {
                            presentationPart.AddNewPart <UserDefinedTagsPart>();
                            presentationPart.UserDefinedTagsPart.TagList = tagList;
                        }

                        foreach (var slidePart in presentationPart.SlideParts)
                        {
                            var slideId = presentationPart.Presentation.SlideIdList.Where(s => ((SlideId)s).RelationshipId == presentationPart.GetIdOfPart(slidePart)).Select(s => (SlideId)s).FirstOrDefault();

                            var slideInfo = libraryFileSlides.Slides.Where(x => x.SlidePptId == slideId.Id).FirstOrDefault();

                            var index = libraryFileSlides.Slides.IndexOf(slideInfo);

                            SlideTag slideTag = new SlideTag(data.ServerInfo.EnvironmentName, data.ServerInfo.ShortLibraryName, libraryFileSlides.Slides[index], -1);

                            Tag slideObjectTag = new Tag()
                            {
                                Name = PL_TAG, Val = XmlUtils.Serialize(slideTag)
                            };

                            if (slidePart.UserDefinedTagsParts.Count() > 0)
                            {
                                var customerDataPart = slidePart.UserDefinedTagsParts.FirstOrDefault().TagList;

                                customerDataPart.ReplaceChild(slideObjectTag, customerDataPart.FirstChild);

                                slidePart.Slide.Save();
                            }
                        }
                    }

                    setTags = true;
                }
            }

            return(setTags);
        }
Пример #5
0
        private List <SlideUpdatedResultDto> UpdateListOfSlides(SlideTagExCollection slideTags)
        {
            var result = new List <SlideUpdatedResultDto>();

            if (slideTags != null)
            {
                for (int i = 0; i < slideTags.Count; i++)
                {
                    SlideTagEx slideTagEx     = slideTags[i];
                    string     sourceFilename = ClientUtils.UndecorateFileName(slideTagEx.SourceFilename);
                    string     status         = string.Empty;
                    string     lastModDate    = slideTagEx.SourceLastModDate.ToString(Message.DateFormat);
                    string     source         = string.Format("{0} - Slide {1}", sourceFilename, slideTagEx.SourceSlideNum);
                    switch (slideTagEx.SlideStatus)
                    {
                    case TagUpdateStatus.Updated:
                        status = "Updated";
                        break;

                    case TagUpdateStatus.New:
                        status = "New";
                        break;

                    case TagUpdateStatus.MissingOrDeleted:
                        status      = "Deleted";
                        lastModDate = string.Empty;
                        source      = sourceFilename;
                        break;

                    case TagUpdateStatus.NoChange:
                        status = "No change";
                        break;

                    case TagUpdateStatus.Added:
                        status      = "Added";
                        lastModDate = string.Empty;
                        source      = string.Empty;
                        break;

                    case TagUpdateStatus.Moved:
                        status = "Moved";
                        break;

                    case TagUpdateStatus.Local:
                        lastModDate = string.Empty;
                        source      = string.Empty;
                        break;
                    }


                    bool isUpdated = Helper.IsSlideUpdated(slideTagEx.SlideStatus);

                    result.Add(new SlideUpdatedResultDto
                    {
                        Tag           = slideTagEx,
                        PptSlideIndex = slideTagEx.PptSlideIndex == 0 ? slideTagEx.SourceSlideNum : slideTagEx.PptSlideIndex,
                        Status        = status,
                        LastModDate   = lastModDate,
                        Source        = source,
                        Id            = slideTagEx.Slide.Id.ToString(),
                        IsUpdated     = isUpdated
                    });
                }
            }

            return(result.OrderBy(x => x.PptSlideIndex).ToList());
        }
Пример #6
0
        public object CheckForUpdates(CheckUpdateDto data)
        {
            bool    updatesExist               = false;
            bool    showConfirmation           = true;
            FileTag fileTags                   = new FileTag();
            SlideTagExCollection     slideTags = new SlideTagExCollection();
            LibrarianContentManifest libraryContentManifest = new LibrarianContentManifest();

            using (Stream stream = new FileStream(data.FileUrl, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                using (PresentationDocument openXmlDoc = PresentationDocument.Open(stream, false))
                {
                    var presentationPart = openXmlDoc.PresentationPart;
                    fileTags  = _tagManagerService.GetFileTag(presentationPart);
                    slideTags = _tagManagerService.GetSlideTags(presentationPart);

                    if (fileTags != null)
                    {
                        data.FileId = fileTags.File.Id.ToString();

                        if (data.AskFirst)
                        {
                            if (fileTags != null && fileTags.File.ContentType == ContentType.File)
                            {
                                return(new CheckUpdateResponseDto()
                                {
                                    FileId = data.FileId,
                                    StatusCode = (HttpStatusCode)CheckUpdateStatusCode.HasNewVersion,
                                    StatusText = System.Enum.GetName(typeof(CheckUpdateStatusCode), CheckUpdateStatusCode.HasNewVersion)
                                });
                            }
                            else
                            {
                                return(new CheckUpdateResponseDto()
                                {
                                    FileId = data.FileId,
                                    StatusCode = (HttpStatusCode)CheckUpdateStatusCode.CheckUpdate,
                                    StatusText = System.Enum.GetName(typeof(CheckUpdateStatusCode), CheckUpdateStatusCode.CheckUpdate)
                                });
                            }
                        }

                        if (data.IsConfirm)
                        {
                            updatesExist = CheckFileForUpdates(fileTags, slideTags, data);

                            if (!isExcuted)
                            {
                                return(new CheckUpdateResponseDto()
                                {
                                    StatusCode = HttpStatusCode.BadRequest,
                                    StatusText = Message.ExcuteFailed
                                });
                            }

                            if (slideTags.Count > 0)
                            {
                                _downloadLatestVersion = true;
                                return(new
                                {
                                    FileId = data.FileId,
                                    StatusCode = 215,
                                    Value = UpdateListOfSlides(slideTags)
                                });
                            }

                            updatesExist     = slideTags.Count > 0;
                            showConfirmation = updatesExist;
                        }
                        else
                        {
                            showConfirmation = false;
                        }
                    }
                    else if (slideTags != null && slideTags.Count > 0)
                    {
                        data.FileId = slideTags.FirstOrDefault().File.Id.ToString();

                        if (data.AskFirst)
                        {
                            return(new CheckUpdateResponseDto()
                            {
                                FileId = data.FileId,
                                StatusCode = (HttpStatusCode)CheckUpdateStatusCode.CheckUpdate,
                                StatusText = System.Enum.GetName(typeof(CheckUpdateStatusCode), CheckUpdateStatusCode.CheckUpdate)
                            });
                        }

                        if (data.IsConfirm)
                        {
                            updatesExist = CheckSlidesForUpdates(slideTags, false, data);

                            if (!isExcuted)
                            {
                                return(new CheckUpdateResponseDto()
                                {
                                    StatusCode = HttpStatusCode.BadRequest,
                                    StatusText = Message.ExcuteFailed
                                });
                            }

                            if (slideTags.Count > 0)
                            {
                                _downloadLatestVersion = true;
                                return(new
                                {
                                    FileId = data.FileId,
                                    StatusCode = 215,
                                    Value = UpdateListOfSlides(slideTags)
                                });
                            }

                            updatesExist     = slideTags.Count > 0;
                            showConfirmation = updatesExist;
                        }
                        else
                        {
                            showConfirmation = false;
                        }
                    }
                    else
                    {
                        libraryContentManifest = XmlUtils.Deserialize <LibrarianContentManifest>(_filesService.GetCustomXmlPart(presentationPart));

                        if (libraryContentManifest != null)
                        {
                            data.FileName = libraryContentManifest.Filename;
                            data.FileId   = libraryContentManifest.ContentId;

                            if (data.AskFirst)
                            {
                                return(new CheckUpdateResponseDto()
                                {
                                    FileName = data.FileName,
                                    FileId = data.FileId,
                                    StatusCode = (HttpStatusCode)CheckUpdateStatusCode.HasNewVersion,
                                    StatusText = System.Enum.GetName(typeof(CheckUpdateStatusCode), CheckUpdateStatusCode.HasNewVersion)
                                });
                            }

                            updatesExist = CheckManifestForUpdates(libraryContentManifest, data);

                            if (!isExcuted)
                            {
                                return(new CheckUpdateResponseDto()
                                {
                                    StatusCode = HttpStatusCode.BadRequest,
                                    StatusText = Message.ExcuteFailed
                                });
                            }
                        }
                        else
                        {
                            showConfirmation = false;
                        }
                    }
                }
            }

            if (showConfirmation && !updatesExist)
            {
                return(new CheckUpdateResponseDto()
                {
                    FileId = data.FileId,
                    StatusCode = (HttpStatusCode)CheckUpdateStatusCode.UptoDate,
                    StatusText = System.Enum.GetName(typeof(CheckUpdateStatusCode), CheckUpdateStatusCode.UptoDate)
                });
            }

            if (updatesExist)
            {
                if (fileTags != null && _downloadLatestVersion)
                {
                    _filesService.GetLatestFile(data);
                }
                else if (slideTags != null && slideTags.Count > 0)
                {
                    return(new
                    {
                        FileId = data.FileId,
                        StatusCode = 215,
                        Value = UpdateListOfSlides(slideTags)
                    });
                }
                else if (libraryContentManifest != null)
                {
                    return(new CheckUpdateResponseDto()
                    {
                        FileId = libraryContentManifest.ContentId,
                        StatusCode = (HttpStatusCode)CheckUpdateStatusCode.UpdatedAvailable,
                        StatusText = System.Enum.GetName(typeof(CheckUpdateStatusCode), CheckUpdateStatusCode.UpdatedAvailable)
                    });
                }
            }

            return(updatesExist);
        }
Пример #7
0
        private bool CheckSlidesForUpdates(SlideTagExCollection slideTags, bool isLibraryFile, CheckUpdateDto fileInfo)
        {
            bool updatesExist = false;

            for (int x = 0; x < slideTags.Count; x++)
            {
                SlideTagEx slideTagEx = slideTags[x];
                if (slideTagEx.SlideStatus == TagUpdateStatus.Unknown)
                {
                    LibraryFileSlides libraryFileSlides = null;
                    try
                    {
                        if (fileInfo.FileId == "-1")
                        {
                            fileInfo.FileId = slideTagEx.File.Id.ToString();
                        }

                        libraryFileSlides = _filesService.GetFileSlidesInfo(fileInfo);
                    }
                    catch (Exception ex)
                    {
                        isExcuted = false;
                        return(updatesExist);
                    }

                    if (libraryFileSlides != null)
                    {
                        for (int i = 0; i < libraryFileSlides.Slides.Count; i++)
                        {
                            SlideInfo            librarySlideInfo = libraryFileSlides.Slides[i];
                            SlideTagExCollection findSlideTags;
                            findSlideTags = slideTags.FindBySlideId(fileInfo.ServerInfo.EnvironmentName, fileInfo.ServerInfo.ShortLibraryName, librarySlideInfo.SlideId);

                            if (findSlideTags.Any())
                            {
                                int movedCount = 0;
                                for (int z = 0; z < findSlideTags.Count; z++)
                                {
                                    SlideTagEx foundSlideTag = findSlideTags[z];
                                    if (isLibraryFile && foundSlideTag.PptSlideIndex != librarySlideInfo.SlideNumber)
                                    {
                                        if (z == 0 && movedCount == 0)
                                        {
                                            foundSlideTag.SlideStatus = TagUpdateStatus.Moved;
                                            ++movedCount;
                                        }
                                        else
                                        {
                                            foundSlideTag.SlideStatus = TagUpdateStatus.Added;
                                        }
                                    }
                                    else if (librarySlideInfo.LastModDate <= foundSlideTag.Slide.LastModDate.ToUniversalTime())
                                    {
                                        foundSlideTag.SlideStatus = TagUpdateStatus.NoChange;
                                    }
                                    else
                                    {
                                        foundSlideTag.SlideStatus = TagUpdateStatus.Updated;
                                        updatesExist = true;
                                    }
                                    foundSlideTag.SourceFilename    = librarySlideInfo.FileName;
                                    foundSlideTag.SourceSlideNum    = librarySlideInfo.SlideNumber;
                                    foundSlideTag.SourceLastModDate = (DateTime)librarySlideInfo.LastModDate;
                                }
                            }
                            else if (isLibraryFile)
                            {
                                SlideTagEx newSlideTag = new SlideTagEx(fileInfo.ServerInfo.EnvironmentName, fileInfo.ServerInfo.ShortLibraryName, librarySlideInfo, -1)
                                {
                                    SlideStatus       = TagUpdateStatus.New,
                                    Title             = librarySlideInfo.Title,
                                    SourceFilename    = librarySlideInfo.FileName,
                                    SourceSlideNum    = librarySlideInfo.SlideNumber,
                                    SourceLastModDate = (DateTime)librarySlideInfo.LastModDate
                                };
                                slideTags.Insert(i, newSlideTag);
                                updatesExist = true;
                            }
                        }
                    }

                    foreach (SlideTagEx nextSlideTagEx in slideTags)
                    {
                        if (nextSlideTagEx.SlideStatus == TagUpdateStatus.Unknown)
                        {
                            if (nextSlideTagEx.File.Id == slideTagEx.File.Id &&
                                nextSlideTagEx.Library.ShortName == slideTagEx.Library.ShortName &&
                                nextSlideTagEx.Library.Environment == slideTagEx.Library.Environment)
                            {
                                if (isLibraryFile)
                                {
                                    nextSlideTagEx.SlideStatus = TagUpdateStatus.Added;
                                }
                                else
                                {
                                    updatesExist = true;
                                    nextSlideTagEx.SlideStatus = TagUpdateStatus.MissingOrDeleted;
                                    if (libraryFileSlides != null && libraryFileSlides.Slides.Any())
                                    {
                                        nextSlideTagEx.SourceFilename = libraryFileSlides.Slides[0].FileName;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(updatesExist);
        }