예제 #1
0
        private static int CopyZipData(Stream from, WorkflowMediaFile mediaFile)
        {
            int fileSize = 0;

            using (Stream streamWriter = mediaFile.GetNewWriteStream())
            {
                int    size = 2048;
                byte[] data = new byte[2048];
                while (true)
                {
                    size = from.Read(data, 0, data.Length);
                    if (size > 0)
                    {
                        streamWriter.Write(data, 0, size);
                        fileSize += size;
                    }
                    else
                    {
                        break;
                    }
                }
            }

            return(fileSize);
        }
예제 #2
0
        public string NewMediaObject(FileData mediaObject)
        {
            var mediaFile = new WorkflowMediaFile
            {
                FileName = mediaObject.name,
                Title = mediaObject.name,
                Culture = DataLocalizationFacade.DefaultLocalizationCulture.Name,
                Length = mediaObject.bits.Count(),
                MimeType = MimeTypeInfo.GetCanonical(mediaObject.type)
            };

            if (mediaFile.MimeType == MimeTypeInfo.Default)
            {
                mediaFile.MimeType = MimeTypeInfo.GetCanonicalFromExtension(Path.GetExtension(mediaFile.FileName));
            }

            using (Stream readStream = new MemoryStream(mediaObject.bits))
            {
                using (Stream writeStream = mediaFile.GetNewWriteStream())
                {
                    readStream.CopyTo(writeStream);
                }
            }
            string folderPath = string.Format("/Blog/{0}/{1:yyyy-MM-dd}", Author.Name, DateTime.Now);
            mediaFile.FolderPath = ForceGetMediaFolderPath(folderPath);
            var addedFile = DataFacade.AddNew<IMediaFile>(mediaFile);
            return MediaUrlHelper.GetUrl(addedFile);
        }
예제 #3
0
        private void finalizeCodeActivity_Finalize_ExecuteCode(object sender, EventArgs e)
        {
            AddNewTreeRefresher addNewTreeRefresher = this.CreateAddNewTreeRefresher(this.EntityToken);

            UploadedFile uploadedFile = this.GetBinding<UploadedFile>("UploadedFile");
            string filename;
            if (this.BindingExist("Filename"))
            {
                filename = this.GetBinding<string>("Filename");
            }
            else 
            {
                filename = uploadedFile.FileName;
            }

            using (TransactionScope transactionScope = TransactionsFacade.CreateNewScope())
            {
                IMediaFileStore store = DataFacade.GetData<IMediaFileStore>(x => x.Id == this.StoreId).First();

                IMediaFile existingFile = GetExistingFile(this.FolderPath, filename);

                if (existingFile == null)
                {
                    WorkflowMediaFile mediaFile = new WorkflowMediaFile();
                    mediaFile.FileName = System.IO.Path.GetFileName(filename);
                    mediaFile.FolderPath = this.FolderPath;
                    mediaFile.Title = this.GetBinding<string>("Title");
                    mediaFile.Description = this.GetBinding<string>("Description");
                    mediaFile.Culture = C1Console.Users.UserSettings.ActiveLocaleCultureInfo.Name;
                    mediaFile.Length = uploadedFile.ContentLength;
                    mediaFile.MimeType = MimeTypeInfo.GetMimeType(uploadedFile);

                    using (System.IO.Stream readStream = uploadedFile.FileStream)
                    {
                        using (System.IO.Stream writeStream = mediaFile.GetNewWriteStream())
                        {
                            readStream.CopyTo(writeStream);
                        }
                    }

                    IMediaFile addedFile = DataFacade.AddNew<IMediaFile>(mediaFile, store.DataSourceId.ProviderName);

                    addNewTreeRefresher.PostRefreshMesseges(addedFile.GetDataEntityToken());

                    SelectElement(addedFile.GetDataEntityToken());
                }
                else
                {
                    Guid fileId = existingFile.Id;
                    IMediaFileData fileData = DataFacade.GetData<IMediaFileData>(file => file.Id == fileId).FirstOrDefault();

                    fileData.Title = this.GetBinding<string>("Title");
                    fileData.Description = this.GetBinding<string>("Description");
                    fileData.MimeType = MimeTypeInfo.GetMimeType(uploadedFile);
                    fileData.Length = uploadedFile.ContentLength;

                    using (System.IO.Stream readStream = uploadedFile.FileStream)
                    {
                        using (System.IO.Stream writeStream = existingFile.GetNewWriteStream())
                        {
                            readStream.CopyTo(writeStream);
                        }
                    }

                    DataFacade.Update(existingFile);
                    DataFacade.Update(fileData);

                    addNewTreeRefresher.PostRefreshMesseges(existingFile.GetDataEntityToken());

                    SelectElement(existingFile.GetDataEntityToken());
                }

                transactionScope.Complete();
            }
        }        
예제 #4
0
        private void finalizeCodeActivity_Finalize_ExecuteCode(object sender, EventArgs e)
        {
            AddNewTreeRefresher addNewTreeRefresher = this.CreateAddNewTreeRefresher(this.EntityToken);

            UploadedFile uploadedFile = this.GetBinding <UploadedFile>("UploadedFile");
            string       filename;

            if (this.BindingExist("Filename"))
            {
                filename = this.GetBinding <string>("Filename");
            }
            else
            {
                filename = uploadedFile.FileName;
            }

            using (TransactionScope transactionScope = TransactionsFacade.CreateNewScope())
            {
                IMediaFileStore store = DataFacade.GetData <IMediaFileStore>(x => x.Id == this.StoreId).First();

                IMediaFile existingFile = GetExistingFile(this.FolderPath, filename);

                if (existingFile == null)
                {
                    WorkflowMediaFile mediaFile = new WorkflowMediaFile();
                    mediaFile.FileName    = System.IO.Path.GetFileName(filename);
                    mediaFile.FolderPath  = this.FolderPath;
                    mediaFile.Title       = this.GetBinding <string>("Title");
                    mediaFile.Description = this.GetBinding <string>("Description");
                    mediaFile.Tags        = this.GetBinding <string>("Tags");
                    mediaFile.Culture     = C1Console.Users.UserSettings.ActiveLocaleCultureInfo.Name;
                    mediaFile.Length      = uploadedFile.ContentLength;
                    mediaFile.MimeType    = MimeTypeInfo.GetMimeType(uploadedFile);

                    using (System.IO.Stream readStream = uploadedFile.FileStream)
                    {
                        using (System.IO.Stream writeStream = mediaFile.GetNewWriteStream())
                        {
                            readStream.CopyTo(writeStream);
                        }
                    }

                    IMediaFile addedFile = DataFacade.AddNew <IMediaFile>(mediaFile, store.DataSourceId.ProviderName);

                    addNewTreeRefresher.PostRefreshMesseges(addedFile.GetDataEntityToken());

                    SelectElement(addedFile.GetDataEntityToken());
                }
                else
                {
                    Guid           fileId   = existingFile.Id;
                    IMediaFileData fileData = DataFacade.GetData <IMediaFileData>(file => file.Id == fileId).FirstOrDefault();

                    fileData.Title       = this.GetBinding <string>("Title");
                    fileData.Description = this.GetBinding <string>("Description");
                    fileData.Tags        = this.GetBinding <string>("Tags");
                    fileData.MimeType    = MimeTypeInfo.GetMimeType(uploadedFile);
                    fileData.Length      = uploadedFile.ContentLength;

                    using (System.IO.Stream readStream = uploadedFile.FileStream)
                    {
                        using (System.IO.Stream writeStream = existingFile.GetNewWriteStream())
                        {
                            readStream.CopyTo(writeStream);
                        }
                    }

                    DataFacade.Update(existingFile);
                    DataFacade.Update(fileData);

                    addNewTreeRefresher.PostRefreshMesseges(existingFile.GetDataEntityToken());

                    SelectElement(existingFile.GetDataEntityToken());
                }

                transactionScope.Complete();
            }
        }