示例#1
0
        public static void CopyAttachments(
            ICollection oSrcObjects,
            ICollection oTargetObjects)
        {
            if (oSrcObjects.Count != oTargetObjects.Count)
            {
                throw new TisException("oSrcObjects.Count != oTargetObjects.Count");
            }

            IEnumerator oSrcEnumerator    = oSrcObjects.GetEnumerator();
            IEnumerator oTargetEnumerator = oTargetObjects.GetEnumerator();

            while (oSrcEnumerator.MoveNext() && oTargetEnumerator.MoveNext())
            {
                ISupportsAttachments oSrcObject =
                    oSrcEnumerator.Current as ISupportsAttachments;

                ISupportsAttachments oTargetObject =
                    oTargetEnumerator.Current as ISupportsAttachments;

                if (oSrcObject != null && oTargetObject != null)
                {
                    CopyAttachments(oSrcObject, oTargetObject);
                }
            }
        }
示例#2
0
        //
        //	Private
        //

        private void AddObjectAttachmentNameToCache(
            ISupportsAttachments oObj)
        {
            string sAttName = AttachmentsUtil.GetAttachmentNameWithoutType(
                oObj.GetAttachmentFileNameWithoutPath(""));

            m_oSupportedAttachmentNames[sAttName] = true;
        }
示例#3
0
        private bool IsBelongToObjectNonRecursive(
            string sAttachmentFileName,
            object oObj)
        {
            // Cast to ISupportsAttachments
            ISupportsAttachments oSupportsAttachments = oObj as ISupportsAttachments;

            // Cast succeeded
            if (oSupportsAttachments != null)
            {
                // Get attachment type
                string sAttType = AttachmentsUtil.GetAttachmentType(
                    sAttachmentFileName);

                // Get file name for attachment type that can belong to object
                string sSupportedAttachmentFileName =
                    oSupportsAttachments.GetAttachmentFileName(sAttType);

                // Get attachment name (without path)
                string sAttachmentName =
                    AttachmentsUtil.GetAttachmentName(sAttachmentFileName);

                // Get supported attachment name (without path)
                string sSupportedAttachmentName =
                    AttachmentsUtil.GetAttachmentName(sSupportedAttachmentFileName);

                // Check if object supports the specified attachment
                // By comparing names
                if (StringUtil.CompareIgnoreCase(
                        sSupportedAttachmentName,
                        sAttachmentName))
                {
                    // Passed the filter
                    return(true);
                }
            }

            return(false);
        }
示例#4
0
        public static void CopyAttachments(
            ISupportsAttachments oSource,
            ISupportsAttachments oTarget)
        {
            IList <string> Attachments = oSource.LocalAttachments;

            foreach (string sAttachment in Attachments)
            {
                // Get attachment type
                string sAttType = AttachmentsUtil.GetAttachmentType(sAttachment);

                // Create target file name
                string sTargetAttFileName =
                    oTarget.GetAttachmentFileName(sAttType);

                // Copy file
                System.IO.File.Copy(
                    sAttachment,
                    sTargetAttFileName,
                    true // Overwrite
                    );
            }
        }
示例#5
0
        //
        //	Private
        //

        #region Import support

        private void CopyNodeAttachments(
            ITisDataLayerTreeNode oSrcTreeNode,
            ITisDataLayerTreeNode oDstTreeNode)
        {
            ISupportsAttachments oSrc = oSrcTreeNode as ISupportsAttachments;
            ISupportsAttachments oDst = oDstTreeNode as ISupportsAttachments;

            EntityBase oSrcEntity = oSrcTreeNode as EntityBase;
            EntityBase oDstEntity = oDstTreeNode as EntityBase;

            if (oSrc == null || oDst == null || oSrcEntity == null || oDstEntity == null)
            {
                return;
            }

            IList <string> oLocalAttachments = oSrc.LocalAttachments;

            ITisAttachedFileManager oSrcAttachedFileManager = (ITisAttachedFileManager)oSrcEntity.GetContextService(
                TisServicesSchema.SetupAttachmentsFileManager.ServiceName);

            ITisAttachedFileManager oDstAttachedFileManager = (ITisAttachedFileManager)oDstEntity.GetContextService(
                TisServicesSchema.SetupAttachmentsFileManager.ServiceName);

            foreach (string sAttachment in oLocalAttachments)
            {
                string sAttType    = AttachmentsUtil.GetAttachmentType(sAttachment);
                string sDstAttName = oDst.GetAttachmentFileName(sAttType) ?? oDst.GetAttachmentNameByFileName(sAttachment);

                try
                {
                    if (!StringUtil.CompareIgnoreCase(sAttachment, sDstAttName))
                    {
                        if (!File.Exists(sAttachment))
                        {
                            oSrcAttachedFileManager.GetAttachment(sAttachment);
                        }

                        if (StringUtil.CompareIgnoreCase(sAttType, "EFI"))
                        {
                            // Special handling for EFIs
                            int nRetVal = FoLearn.CopyToNewEfi(
                                sAttachment,
                                sDstAttName);

                            if (nRetVal != 0)
                            {
                                throw new TisException("FoLearn.CopyToNewEfi failed, Code={0}", nRetVal);
                            }
                        }
                        else
                        {
                            // Copy local (cached)
                            File.Copy(
                                sAttachment,
                                sDstAttName,
                                true // Overwrite
                                );
                        }
                    }
                }
                catch (Exception oExc)
                {
                    Log.WriteException(oExc);

                    throw;
                }

                // Save to server
                oDstAttachedFileManager.SaveAttachment(
                    sDstAttName,
                    TIS_ATTACHMENT_EXISTS_ACTION.TIS_EXISTING_OVERRIDE);
            }
        }