Example #1
0
        /// <summary>
        /// Creates the entity object.
        /// </summary>
        /// <param name="metaClassName">Name of the meta class.</param>
        /// <param name="primaryKeyId">The primary key id.</param>
        /// <returns></returns>
        protected override EntityObject CreateEntityObject(string metaClassName, PrimaryKeyId?primaryKeyId)
        {
            if (metaClassName == DocumentTemplateEntity.GetAssignedMetaClassName())
            {
                DocumentTemplateEntity retVal = new DocumentTemplateEntity();
                retVal.PrimaryKeyId = primaryKeyId;
                return(retVal);
            }

            return(base.CreateEntityObject(metaClassName, primaryKeyId));
        }
Example #2
0
        protected override void PostCreateInsideTransaction(BusinessContext context)
        {
            base.PostCreateInsideTransaction(context);

            PrimaryKeyId documentPrimaryKeyId = ((CreateResponse)context.Response).PrimaryKeyId;

            // Check TemplateId
            PrimaryKeyId templatePrimaryKeyId = context.Request.Parameters.GetValue <PrimaryKeyId>(DocumentRequestParameters.Create_DocumentTemplatedId, PrimaryKeyId.Empty);

            if (templatePrimaryKeyId != PrimaryKeyId.Empty)
            {
                // Load Template
                DocumentTemplateEntity template = (DocumentTemplateEntity)BusinessManager.Load(DocumentTemplateEntity.GetAssignedMetaClassName(), templatePrimaryKeyId);

                if (template.File != null)
                {
                    // Initialize Content
                    //DocumentContentEntity content = (DocumentContentEntity)BusinessManager.InitializeEntity(DocumentContentEntity.GetAssignedMetaClassName());
                    //content.Name = template.File.Name;
                    //content.OwnerDocumentId = documentPrimaryKeyId;

                    //PrimaryKeyId contentPrimaryKeyId = BusinessManager.Create(content);

                    // Initialize Version
                    DocumentContentVersionEntity version = (DocumentContentVersionEntity)BusinessManager.InitializeEntity(DocumentContentVersionEntity.GetAssignedMetaClassName());
                    version.Name            = template.File.Name;
                    version.OwnerDocumentId = documentPrimaryKeyId;

                    // version.DocumentContentId is not updateble
                    //version.DocumentContentId = contentPrimaryKeyId;

                    // Upload File
                    using (System.IO.Stream inputStream = template.File.OpenRead())
                    {
                        // Modify Template
                        string extension = System.IO.Path.GetExtension(template.File.Name);
                        IDocumentTemplateProcessor processor = FindTemplateProcessor(extension);

                        System.IO.Stream outputStream = null;
                        if (processor != null)
                        {
                            Dictionary <string, EntityObject> keys = (Dictionary <string, EntityObject>)context.Items["MC_DocumentTemplateProcessorKeys"];

                            context.Request.Target.PrimaryKeyId = ((CreateResponse)context.Response).PrimaryKeyId;

                            keys.Add("Document", context.Request.Target);
                            keys.Add("DocumentContentVersion", version);
                            keys.Add("DocumentTemplateEntity", template);

                            outputStream = processor.Convert(extension, inputStream, keys);
                        }
                        else
                        {
                            outputStream = inputStream;
                        }

                        FileInfo fileInfo = new FileInfo(template.File.Name, outputStream);
                        version.File = fileInfo;

                        PrimaryKeyId versionPrimaryKeyId = BusinessManager.Create(version);
                    }
                }
            }
            else
            {
                // Initialize Content
                //DocumentContentEntity content = (DocumentContentEntity)BusinessManager.InitializeEntity(DocumentContentEntity.GetAssignedMetaClassName());
                //content.Name = string.Empty;
                //content.OwnerDocumentId = documentPrimaryKeyId;

                //PrimaryKeyId contentPrimaryKeyId = BusinessManager.Create(content);
            }
        }