예제 #1
0
        private void uploadCodeActivity_ExecuteCode(object sender, EventArgs e)
        {
            UpdateTreeRefresher updateTreeRefresher = this.CreateUpdateTreeRefresher(this.EntityToken);

            FlowControllerServicesContainer flowControllerServicesContainer = WorkflowFacade.GetFlowControllerServicesContainer(WorkflowEnvironment.WorkflowInstanceId);
            var managementConsoleMessageService = flowControllerServicesContainer.GetService <IManagementConsoleMessageService>();

            UploadedFile uploadedFile = this.GetBinding <UploadedFile>("UploadedFile");
            IMediaFile   mediaFile    = this.GetBinding <IMediaFile>("File");

            if (uploadedFile.HasFile)
            {
                string mimeType = MimeTypeInfo.GetMimeType(uploadedFile);

                // Image cannot be replaced with a file of not image mime type
                string imageMimeTypePrefix = "image/";
                if ((mediaFile.MimeType.StartsWith(imageMimeTypePrefix, StringComparison.OrdinalIgnoreCase) &&
                     !mimeType.StartsWith(imageMimeTypePrefix, StringComparison.OrdinalIgnoreCase)))
                {
                    managementConsoleMessageService.CloseCurrentView();
                    string failure        = StringResourceSystemFacade.GetString("Composite.Management", "UploadNewMediaFileWorkflow.UploadFailure");
                    string failureMessage = StringResourceSystemFacade.GetString("Composite.Management", "UploadNewMediaFileWorkflow.UploadFailureMessage");
                    managementConsoleMessageService.ShowMessage(DialogType.Message, failure, failureMessage);
                    return;
                }

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

            DataFacade.Update(mediaFile);

            SetSaveStatus(true);

            SelectElement(mediaFile.GetDataEntityToken());

            updateTreeRefresher.PostRefreshMesseges(mediaFile.GetDataEntityToken());
        }
        private void finalizeCodeActivity_ExecuteCode(object sender, EventArgs e)
        {
            UpdateTreeRefresher updateTreeRefresher = this.CreateUpdateTreeRefresher(this.EntityToken);

            DataEntityToken token = (DataEntityToken)this.EntityToken;
            IMediaFile      file  = (IMediaFile)token.Data;
            IMediaFileStore store = DataFacade.GetData <IMediaFileStore>(x => x.Id == file.StoreId).First();

            file.FileName    = this.GetBinding <string>("FileDataFileName");
            file.Title       = this.GetBinding <string>("FileDataTitle");
            file.Description = this.GetBinding <string>("FileDataDescription");

            DataFacade.Update(file);

            SetSaveStatus(true);

            updateTreeRefresher.PostRefreshMesseges(file.GetDataEntityToken());
        }
        private SearchDocument FromMediaFile(IMediaFile mediaFile)
        {
            string label = mediaFile.Title;

            if (string.IsNullOrWhiteSpace(label))
            {
                label = mediaFile.FileName;
            }

            string documentId = mediaFile.Id.ToString();

            var docBuilder = new SearchDocumentBuilder();

            docBuilder.SetDataType(typeof(IMediaFile));
            docBuilder.CrawlData(mediaFile);

            return(docBuilder.BuildDocument(Name, documentId, label, null, mediaFile.GetDataEntityToken(), null));
        }
예제 #4
0
        private SearchDocument FromMediaFile(IMediaFile mediaFile)
        {
            string label = mediaFile.Title;

            if (string.IsNullOrWhiteSpace(label))
            {
                label = mediaFile.FileName;
            }

            if (string.IsNullOrEmpty(label))
            {
                Log.LogWarning(nameof(MediaLibraryDocumentSource),
                               $"A media file has neither FileName nor Label fields specified, Id: '{mediaFile.Id}', StoreId: '{mediaFile.StoreId}'.");
                return(null);
            }

            var docBuilder = new SearchDocumentBuilder(_docBuilderExtensions);

            docBuilder.SetDataType(typeof(IMediaFile));
            docBuilder.CrawlData(mediaFile);

            return(docBuilder.BuildDocument(Name, mediaFile.Id.ToString(), label, null, mediaFile.GetDataEntityToken()));
        }
예제 #5
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();
            }
        }