コード例 #1
0
        public async Task <ActionResult> Create(QuestionCreateViewModel model, FormCollection formCollection)
        {
            List <AddAnswerRequest> answers = new List <AddAnswerRequest>();

            for (int i = 4; i < formCollection.Count; i += 2)
            {
                AddAnswerRequest addAnswerRequest = new AddAnswerRequest()
                {
                    Title           = formCollection[i],
                    IsCorrectAnswer = Convert.ToBoolean(formCollection[i + 1])
                };
                answers.Add(addAnswerRequest);
            }

            CreateQuestionRequest createQuestionRequest = new CreateQuestionRequest()
            {
                Title       = model.Title,
                Explanation = model.Explanation,
                ThemeId     = model.ThemeId,
                Answers     = answers
            };

            var question = await _questionAdminService.CreateQuestionAsync(createQuestionRequest);

            if (model.Image != null && model.Image.ContentLength > 0)
            {
                var extension = AttachmentsUtil.GetExtentionFromMimeType(model.Image.ContentType);
                var content   = GetAttachmentContent(model.Image);
                await _questionAdminService.UploadAttachmentAsync(new UploadQuestionAttachmentRequest(question.Id, content, extension));
            }

            return(RedirectToAction("Index", new { themeId = model.ThemeId }));
        }
コード例 #2
0
        public virtual bool IsPass(string attachment)
        {
            string attachmentType = AttachmentsUtil.GetAttachmentType(attachment);

            if (m_AttachmentsFilter == TIS_ATTACHMENTS_FILTER.ALL)
            {
                if (isInExcludedAttachmentTypes(attachmentType))
                {
                    return(false);
                }

                return(true);
            }

            if (m_AttachmentsFilter == TIS_ATTACHMENTS_FILTER.NONE)
            {
                if (!isInExcludedAttachmentTypes(attachmentType))
                {
                    return(false);
                }

                return(true);
            }

            throw new TisException("Unknown TIS_ATTACHMENTS_FILTER value: {0}", m_AttachmentsFilter);
        }
コード例 #3
0
        //
        //	Private
        //

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

            m_oSupportedAttachmentNames[sAttName] = true;
        }
コード例 #4
0
        public async Task <ActionResult> Edit(QuestionEditViewModel model, FormCollection formCollection)
        {
            if (model.File != null && model.File.ContentLength > 0) // Replace image
            {
                if (model.ImageUrl != null)
                {
                    await _questionAdminService.DeleteAttachmentAsync(model.Id);

                    model.ImageUrl = null;
                }
                var extension = AttachmentsUtil.GetExtentionFromMimeType(model.File.ContentType);
                var content   = GetAttachmentContent(model.File);
                model.ImageUrl = await _questionAdminService.UploadAttachmentAsync(new UploadQuestionAttachmentRequest(model.Id, content, extension));
            }
            else if (model.DeleteImage && model.ImageUrl != null) // Delete image
            {
                await _questionAdminService.DeleteAttachmentAsync(model.Id);

                model.ImageUrl = null;
            }

            List <UpdateAnswerRequest> answers = new List <UpdateAnswerRequest>();

            for (int i = 6; i < formCollection.Count; i += 3)
            {
                UpdateAnswerRequest updateAnswerRequest = new UpdateAnswerRequest()
                {
                    Id = Guid.Parse(formCollection[i]),
                    IsCorrectAnswer = Convert.ToBoolean(formCollection[i + 1]),
                    Title           = formCollection[i + 2]
                };
                answers.Add(updateAnswerRequest);
            }

            EditQuestionRequest editQuestionRequest = new EditQuestionRequest()
            {
                Id          = model.Id,
                Title       = model.Title,
                ImageUrl    = model.ImageUrl,
                Explanation = model.Explanation,
                Answers     = answers
            };

            await _questionAdminService.EditQuestionAsync(editQuestionRequest);

            Guid themeId = await _questionAdminService.GetThemeIdByQuestionIdAsync(model.Id);

            return(RedirectToAction("Index", new { themeId }));
        }
コード例 #5
0
        public bool QueryAttachment(string attachedFileName)
        {
            string localFileName;

            if (Path.IsPathRooted(attachedFileName))
            {
                localFileName    = attachedFileName;
                attachedFileName = AttachmentsUtil.GetAttachmentName(attachedFileName);
            }
            else
            {
                localFileName = GetLocalFileName(attachedFileName);
            }

            return(System.IO.File.Exists(localFileName) || m_SourceStorage.IsStorageExist(attachedFileName));
        }
コード例 #6
0
        public void SaveAttachment(string attachment, TIS_ATTACHMENT_EXISTS_ACTION attachmentExistsAction)
        {
            string localFileName;

            if (Path.IsPathRooted(attachment))
            {
                localFileName = attachment;
                attachment    = AttachmentsUtil.GetAttachmentName(attachment);
            }
            else
            {
                localFileName = GetLocalFileName(attachment);
            }

            m_SourceStorage.WriteStorage(attachment, FileUtil.ReadAllBytes(localFileName));
        }
コード例 #7
0
        public string GetLocalFileName(string attachmentFile)
        {
            string localPath = Path.GetDirectoryName(attachmentFile);

            if (m_LocalPathProvider is LocalPathLocator)
            {
                if (StringUtil.IsStringInitialized(localPath))
                {
                    return(Path.Combine(((LocalPathLocator)m_LocalPathProvider).DefaultRoot, attachmentFile));
                }

                localPath = m_LocalPathProvider.GetPath(AttachmentsUtil.GetAttachmentType(attachmentFile));
            }
            else
            {
                localPath = m_LocalPathProvider.GetPath(attachmentFile);
            }

            // Return full path
            return(Path.Combine(localPath, attachmentFile));
        }
コード例 #8
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);
        }
コード例 #9
0
        public string GetPath(string sFileName)
        {
            if (StringUtil.IsStringInitialized(SpecificPath))
            {
                return(SpecificPath);
            }
            else
            {
                string sExt = AttachmentsUtil.GetAttachmentType(sFileName);

                // If the file has no extension, error
                if (sExt.Length == 0)
                {
                    throw new TisException(
                              "The file name [{0}] has no extension, " +
                              "can't determine target path");
                }

                // Use PathLocator to determine target path
                return(m_pathLocator[sExt]);
            }
        }
コード例 #10
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
                    );
            }
        }
コード例 #11
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);
        }
コード例 #12
0
        private bool IsBelongToObject(
            string sAttachmentFileName,
            object oObj)
        {
            if (m_oSupportedAttachmentNames == null)
            {
                //m_oSupportedAttachmentNames = new Hashtable(
                //    new CaseInsensitiveHashCodeProvider(),
                //    new CaseInsensitiveComparer());

                // Changed after moving from .NET 1.1
                // TODO : check whether we should use InvariantCulture or CurrentCulture
                m_oSupportedAttachmentNames = new Hashtable(StringComparer.InvariantCultureIgnoreCase);

                if (oObj is ISupportsAttachments)
                {
                    AddObjectAttachmentNameToCache((ISupportsAttachments)oObj);
                }

                foreach (object oChildObj in (oObj as EntityBase).GetAllChildren(true).Where(x => x is ISupportsAttachments))
                {
                    AddObjectAttachmentNameToCache(
                        (ISupportsAttachments)oChildObj);
                }
            }

            string sAttName = AttachmentsUtil.GetAttachmentNameWithoutType(
                sAttachmentFileName);

            if (m_oSupportedAttachmentNames[sAttName] == null)
            {
                return(false);
            }

            return(true);

            //			if(IsBelongToObjectNonRecursive(
            //				sAttachmentFileName,
            //				oObj))
            //			{
            //				return true;
            //			}

            //			if(m_oObjectChildren == null)
            //			{
            //				ICollection oAllChildren = m_oEntityReflection.GetAllChildren(
            //					oObj,
            //					true	// Recursive
            //					);
            //
            //				ArrayList oSupportAttachmentsChildren = new ArrayList(
            //					oAllChildren.Count);
            //
            //				foreach(object oChildObj in oAllChildren)
            //				{
            //					if(oChildObj is ISupportsAttachments)
            //					{
            //						oSupportAttachmentsChildren.Add(oChildObj);
            //					}
            //				}
            //
            //				m_oObjectChildren = oSupportAttachmentsChildren;
            //			}

            //			// Check all children
            //			foreach(object oChild in m_oObjectChildren)
            //			{
            //				if(IsBelongToObjectNonRecursive(sAttachmentFileName, oChild))
            //				{
            //					return true;
            //				}
            //			}

            //			return false;
        }
コード例 #13
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);
            }
        }