Пример #1
0
        public object Deserialize(string serializedObject)
        {
            if (serializedObject == null) throw new ArgumentNullException("serializedObject");

            Dictionary<string, string> dic = StringConversionServices.ParseKeyValueCollection(serializedObject);

            UploadedFile uploadedFile = new UploadedFile();

            if (dic.ContainsKey("HasFile") == false) throw new InvalidOperationException("Not correct serialized format");
            uploadedFile.HasFile = StringConversionServices.DeserializeValueBool(dic["HasFile"]);

            if (dic.ContainsKey("FileName"))
            {
                uploadedFile.FileName = StringConversionServices.DeserializeValueString(dic["FileName"]);
            }

            if (dic.ContainsKey("ContentType"))
            {
                uploadedFile.ContentType = StringConversionServices.DeserializeValueString(dic["ContentType"]);
            }

            if (dic.ContainsKey("ContentLength") == false) throw new InvalidOperationException("Not correct serialized format");
            uploadedFile.ContentLength = StringConversionServices.DeserializeValueInt(dic["ContentLength"]);

            if (dic.ContainsKey("FileStream"))
            {
                byte[] bytes = StringConversionServices.DeserializeValueArray<byte>(dic["FileStream"]);

                uploadedFile.FileStream = new MemoryStream(bytes);
            }

            return uploadedFile;
        }
Пример #2
0
        private void InitializeCodeActivity_ExecuteCode(object sender, EventArgs e)
        {
            FormsWorkflow workflow = this.GetRoot<FormsWorkflow>();

            string parentFolderPath;
            string storeId;
            if (this.EntityToken is MediaRootFolderProviderEntityToken)
            {
                var token = (MediaRootFolderProviderEntityToken)this.EntityToken;
                parentFolderPath = "/";
                storeId = token.Id;
            }
            else
            {
                var token = (DataEntityToken)this.EntityToken;
                IMediaFileFolder parentFolder = (IMediaFileFolder)token.Data;
                parentFolderPath = parentFolder.Path;
                storeId = parentFolder.StoreId;
            }

            string providerName = DataFacade.GetData<IMediaFileStore>().First(x => x.Id == storeId).DataSourceId.ProviderName;

            UploadedFile file = new UploadedFile();

            workflow.Bindings.Add("UploadedFile", file);
            workflow.Bindings.Add("RecreateFolders", true);
            workflow.Bindings.Add("OverwriteExisting", false);
            workflow.Bindings.Add("ParentFolderPath", parentFolderPath);
            workflow.Bindings.Add("ProviderName", providerName);
        }
        private void initializeCodeActivity_ExecuteCode(object sender, EventArgs e)
        {
            FormsWorkflow workflow = this.GetRoot<FormsWorkflow>();

            DataEntityToken token = (DataEntityToken)this.EntityToken;
            IMediaFile mediaFile = (IMediaFile)token.Data;

            UploadedFile file = new UploadedFile();

            workflow.Bindings.Add("UploadedFile", file);
            workflow.Bindings.Add("File", mediaFile);
        }
        private void InitializeCodeActivity_ExecuteCode(object sender, EventArgs e)
        {
            FormsWorkflow workflow = this.GetRoot<FormsWorkflow>();

            string parentFolderPath;

            if (this.EntityToken is WebsiteFileElementProviderRootEntityToken)
            {
                parentFolderPath = PathUtil.Resolve("~/");
            }
            else
            {
                var token = (WebsiteFileElementProviderEntityToken)this.EntityToken;
                parentFolderPath = token.Path;
            }

            UploadedFile file = new UploadedFile();

            workflow.Bindings.Add("UploadedFile", file);
            workflow.Bindings.Add("OverwriteExisting", false);
            workflow.Bindings.Add("ParentFolderPath", parentFolderPath);
        }
        private void initializeCodeActivity_Initialize_ExecuteCode(object sender, EventArgs e)
        {
            UploadedFile file = new UploadedFile();

            this.Bindings.Add("UploadedFile", file);
        }
Пример #6
0
        private void initializeCodeActivity_InitializeBindings_ExecuteCode(object sender, EventArgs e)
        {
            UploadedFile file = new UploadedFile();

            this.Bindings.Add("UploadedFile", file);
            this.Bindings.Add("AllowOverwrite", false);
            this.Bindings.Add("Title", "");
            this.Bindings.Add("Description", "");
        }
Пример #7
0
        /// <exclude />
        public static string GetMimeType(UploadedFile uploadedFile)
        {
            string fileName = System.IO.Path.GetFileName(uploadedFile.FileName);

            string mimeTypeFromExtension = MimeTypeInfo.GetCanonicalFromExtension(System.IO.Path.GetExtension(fileName));
            if (mimeTypeFromExtension != MimeTypeInfo.Default)
            {
                Log.LogInformation(LogTitle, "Uploading file '{0}'. MIME type from extension: '{1}'"
                                                .FormatWith(fileName, mimeTypeFromExtension));

                return mimeTypeFromExtension;
            }
            
            string mimeTypeFromBrowser = MimeTypeInfo.GetCanonical(uploadedFile.ContentType);

            // Default MIME type for Chrome is "application/xml"
            // Default MIME type for IE is "text/plain"
            // for the rest it is "application/octet-stream"
            if (mimeTypeFromBrowser != "application/xml"
                && mimeTypeFromBrowser != "text/plain")
            {
                Log.LogInformation(LogTitle, "Uploading file '{0}'. Browser provided MIME type: '{1}'. Canonical MIME type: '{2}'"
                                        .FormatWith(fileName, uploadedFile.ContentType ?? string.Empty, mimeTypeFromBrowser));
                

                return mimeTypeFromBrowser;
            }
            
            Log.LogInformation(LogTitle, "Uploading file '{0}'. Applying default MIME type '{1}'"
                                            .FormatWith(fileName, MimeTypeInfo.Default));

            return MimeTypeInfo.Default;
        }