public void UpdateAttachmentInfo(string attachmentName, ITisAttachmentInfo attachmentInfo)
 {
     if (m_oNameToInfoMap.Contains(attachmentName))
     {
         m_oNameToInfoMap[attachmentName] = attachmentInfo;
     }
 }
        private bool IsSmallRemoteAttachment(string sAttachment)
        {
            ITisAttachmentInfo oAttInfo =
                m_RemoteAttachmentsInfo.CheckedGetAttachmentInfo(sAttachment);

            if (IsSmallAttachment(oAttInfo.SizeBytes))
            {
                return(true);
            }

            return(false);
        }
        public ITisAttachmentInfo CheckedGetAttachmentInfo(
            string sAttachmentName)
        {
            ITisAttachmentInfo oInfo = GetAttachmentInfo(sAttachmentName);

            if (oInfo == null)
            {
                throw new TisException("No {0} entry found for sAttachmentName={1}",
                                       typeof(ITisAttachmentInfo),
                                       sAttachmentName);
            }

            return(oInfo);
        }
        private bool AreLocalAndSourceDifferent(
            string attachemnt,
            TisAttachmentsSynchronizationPolicy attachmentsComparePolicy)
        {
            if (attachmentsComparePolicy == TisAttachmentsSynchronizationPolicy.None)
            {
                return(true);
            }

            string localFileName = GetLocalFileName(attachemnt);

            FileInfo oFileInfo = new FileInfo(localFileName);

            if (!oFileInfo.Exists)
            {
                // No local file = different
                return(true);
            }

            ITisAttachmentInfo oRemoteAttInfo =
                m_RemoteAttachmentsInfo.GetAttachmentInfo(attachemnt);

            if (oRemoteAttInfo == null)
            {
                // No remote attachment = different
                return(true);
            }

            if (attachmentsComparePolicy == TisAttachmentsSynchronizationPolicy.LocalNew)
            {
                return(oFileInfo.LastWriteTime > oRemoteAttInfo.LastModified);
            }

            if (attachmentsComparePolicy == TisAttachmentsSynchronizationPolicy.RemoteNew)
            {
                return(oFileInfo.LastWriteTime < oRemoteAttInfo.LastModified);
            }

            if (oFileInfo.LastWriteTime != oRemoteAttInfo.LastModified ||
                oFileInfo.Length != oRemoteAttInfo.SizeBytes)
            {
                // Different modify time -> different
                return(true);
            }

            // The same
            return(false);
        }
        protected virtual void DownloadAttachment(
            string sAttachment,
            bool forceOperation = false,
            bool IsChunkedMode  = false)
        {
            // Obtain local file name
            string sLocalFileName =
                GetLocalFileName(sAttachment);

            // Download attachment in most optimal way

            if (IsSmallRemoteAttachment(sAttachment))
            {
                GetSmallAttachment(sLocalFileName, sAttachment);
            }
            else
            {
                GetLargeAttachment(sLocalFileName, sAttachment);
            }

            // Update local file LastWriteTime according to remote file
            // In order to allow comparison later

            ITisAttachmentInfo oAttInfo = m_RemoteAttachmentsInfo.CheckedGetAttachmentInfo(sAttachment);

            FileInfo oDownloadedFileInfo = new FileInfo(sLocalFileName);

            try
            {
                oDownloadedFileInfo.LastWriteTime = oAttInfo.LastModified;
            }
            // File maybe write by other process, so leave the LastWriteTime
            catch (System.IO.IOException)
            {
            }

            // Register attachment in downloaded attachments list
            RegisterDownloadedAttachment(sAttachment);
        }
Ejemplo n.º 6
0
        public ITisAttachmentInfo[] QueryAttachmentsInfo(string attachmentNameFilter, string attachmentTypeFilter)
        {
            string sNameFilterToUse = "*";
            string typeFilterToUse  = "*";

            if (StringUtil.IsStringInitialized(attachmentNameFilter))
            {
                sNameFilterToUse = attachmentNameFilter;
            }

            if (StringUtil.IsStringInitialized(attachmentTypeFilter))
            {
                typeFilterToUse = attachmentTypeFilter;
            }

            // Create filter
            string filter = String.Format(
                "{0}.{1}",
                sNameFilterToUse,
                typeFilterToUse);

            // Perform query

            List <StorageInfo> storagesInfo = new List <StorageInfo>(
                m_SourceStorage.QueryStorageInfo(String.Empty, filter, StorageInfoFlags.Size | StorageInfoFlags.LastModified));

            string[] subDirs = m_SourceStorage.QuerySubDirs(String.Empty, true);

            foreach (var subdir in subDirs)
            {
                StorageInfo[] subDirsStoragesInfo =
                    m_SourceStorage.QueryStorageInfo(subdir, filter, StorageInfoFlags.Size | StorageInfoFlags.LastModified);

                foreach (StorageInfo storageInfo in subDirsStoragesInfo)
                {
                    storagesInfo.Add(new StorageInfo(
                                         Path.Combine(subdir, storageInfo.Name),
                                         storageInfo.SizeBytes,
                                         storageInfo.CRC32,
                                         storageInfo.LastModified,
                                         storageInfo.DataFlags));
                }
            }

            ITisAttachmentInfo[] attachmentInfoArray = new ITisAttachmentInfo[storagesInfo.Count];

            // Repack IBLOBInfo to ITisAttachmentInfo

            for (int i = 0; i < storagesInfo.Count; i++)
            {
                IStorageInfo storageInfo = storagesInfo[i];

                attachmentInfoArray[i] = new AttachmentInfo(
                    storageInfo.Name,
                    AttachmentsUtil.GetAttachmentType(storageInfo.Name),
                    storageInfo.SizeBytes,
                    storageInfo.LastModified,
                    storageInfo.CRC32);
            }

            return(attachmentInfoArray);
        }