Commit 9527fa3e by wangonghui

媒体资源添加修改

parent 6c361a41
......@@ -27,6 +27,12 @@ namespace VIZ.TVP.Domain
/// </summary>
public CsvContext CsvContext { get; set; }
/// <summary>
/// 媒体库配置文件
/// </summary>
public ConfigContext ConfigContext { get; set; }
/// <summary>
/// 销毁
/// </summary>
......
......@@ -74,7 +74,7 @@ namespace VIZ.TVP.Module
}
else if (ThumbnailHelper.IsVideo(fileModel.Path))
{
string strVedioPath = string.Format("{0}{1}", System.Environment.CurrentDirectory, "\\VedioImage\\Vedio.jpeg");
string strVedioPath = string.Format("{0}{1}", System.Environment.CurrentDirectory, "\\Resource\\VedioImage\\Vedio.jpeg");
Image vedioImage = Image.FromFile(strVedioPath);
......
......@@ -49,15 +49,6 @@ namespace VIZ.TVP.Module
{
try
{
//string newPath = "";
//if (File.Exists(Application.StartupPath + path))
//{
// newPath = Application.StartupPath + path;
//}
//else
//{//如果图片不存在,使用默认图片
// //newPath = Application.StartupPath + LocalConfig.defaultPicPath;
//}
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
Image result = Image.FromStream(fs);
fs.Close();
......@@ -88,16 +79,27 @@ namespace VIZ.TVP.Module
return false;
}
}
public static Boolean IsImageByName(string name)
{
int pos = name.LastIndexOf(".");
if (name.Length - pos - 1 < 3)
return false;
try
{
if (name == null) return false;
int pos = name.LastIndexOf(".");
if (name.Length - pos - 1 < 3)
return false;
string ext = name.Substring(pos + 1, name.Length - pos - 1);
string[] imge = { "jpg", "jpeg", "png", "gif", "bmp", "TIFF", "tif" };
string ext = name.Substring(pos + 1, name.Length - pos - 1);
string[] imge = { "jpg", "jpeg", "png", "gif", "bmp", "TIFF", "tif" };
return IsInIgnoreCase(ext, imge);
}
catch(Exception e)
{
return false;
}
return IsInIgnoreCase(ext, imge);
}
private static bool IsInIgnoreCase(string source, params string[] list)
......@@ -159,10 +161,30 @@ namespace VIZ.TVP.Module
return isVideo;
}
#endregion
/// <summary>
/// 从完整路径中查找文件或文件夹名称
/// </summary>
/// <param name="path">完整路径</param>
/// <returns></returns>
public static string GetFileFolderName(string path)
{
// 如果没有路径,则返回空
if (string.IsNullOrEmpty(path))
return string.Empty;
// 使所有斜杠成反斜杠
var normalizedPath = path.Replace('/', '\\');
// 找到最后一个反斜杠就是路径
var lastIndex = normalizedPath.LastIndexOf('\\');
// 如果找不到反斜线,则返回路径本身
if (lastIndex <= 0)
return path;
// 最后一个反斜杠后返回名称
return path.Substring(lastIndex + 1);
}
#endregion
}
}
......@@ -273,30 +273,6 @@ namespace VIZ.TVP.Module
#endregion
/// <summary>
/// 从完整路径中查找文件或文件夹名称
/// </summary>
/// <param name="path">完整路径</param>
/// <returns></returns>
public static string GetFileFolderName(string path)
{
// 如果没有路径,则返回空
if (string.IsNullOrEmpty(path))
return string.Empty;
// 使所有斜杠成反斜杠
var normalizedPath = path.Replace('/', '\\');
// 找到最后一个反斜杠就是路径
var lastIndex = normalizedPath.LastIndexOf('\\');
// 如果找不到反斜线,则返回路径本身
if (lastIndex <= 0)
return path;
// 最后一个反斜杠后返回名称
return path.Substring(lastIndex + 1);
}
......@@ -369,7 +345,7 @@ namespace VIZ.TVP.Module
{
selectedFolderModel.Children.Add(new LFResourceFolderModel()
{
Name = GetFileFolderName(directoryPath),
Name = ThumbnailHelper.GetFileFolderName(directoryPath),
Path = directoryPath,
FolderType = ResourceFolderType.Folder
});
......@@ -446,7 +422,7 @@ namespace VIZ.TVP.Module
Files.ForEach(filePath =>
{
var ghFileModel = new LFResourceFileModel();
ghFileModel.Name = GetFileFolderName(filePath);
ghFileModel.Name = ThumbnailHelper.GetFileFolderName(filePath);
ghFileModel.Path = filePath;
files.Add(ghFileModel);
......
using log4net;
using DevExpress.Internal.WinApi.Windows.UI.Notifications;
using log4net;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
......@@ -9,8 +11,10 @@ using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using VIZ.Framework.Core;
using VIZ.TVP.Domain;
using VIZ.TVP.Module.Resource.MediaResource.Controller.Model;
using VIZ.TVP.Service;
using VIZ.TVP.Storage;
......@@ -23,6 +27,11 @@ namespace VIZ.TVP.Module
/// </summary>
private static readonly ILog log = LogManager.GetLogger(typeof(VizResourceFileController));
public static AppSettingsSection config = ApplicationDomainEx.DataBaseManager.ConfigContext.configuration.AppSettings;
private static string httpUrl = config.Settings["url"].Value.ToString();
/// <summary>
/// VIZ资源缩略图控制器
/// </summary>
......@@ -42,7 +51,7 @@ namespace VIZ.TVP.Module
/// 更新文件模型
/// </summary>
/// <param name="folder">文件夹</param>
public void UpdateFileModels(MHResourceFolderModel folder)
public void UpdateFileModels(MHResourceFolderModel folder)
{
// 文件夹对象不存在
if (folder == null)
......@@ -59,105 +68,146 @@ namespace VIZ.TVP.Module
return;
}
//GH_Link_Node link_related = folder.EntryNode.links.FirstOrDefault(p => p.rel == GH_Link_Rel_Enums.related);
//if (link_related == null || string.IsNullOrWhiteSpace(link_related.href))
//{
// folder.IsRefreshedFiles = true;
// return;
//}
//this.Support.IsFileLoading = true;
//ThreadHelper.SafeRun(() =>
//{
// List<GHResourceFileModel> files = ghResourceService.GetGHResourceFiles(link_related.href, folder);
// WPFHelper.BeginInvoke(() =>
// {
// folder.Files = files.ToObservableCollection();
// this.Support.FileModels = folder.Files;
// folder.IsRefreshedFiles = true;
// this.Support.IsFileLoading = false;
// // 开始下载缩略图
// this.BeginDownloadThumbnail(folder);
// });
//});
//
WPFHelper.BeginInvoke(async () =>
{
string header = string.Format("{0}GetListFile?filePath={1}", httpUrl, folder.Path);
var FileResult = await MediaResourceFileService.PostObjectAsync<fileListResult, string>(header, "");
List<MHResourceFileModel> list = new List<MHResourceFileModel>();
// folder.Files = new System.Collections.ObjectModel.ObservableCollection<GHResourceFileModel>();
WPFHelper.BeginInvoke(async () =>
foreach (var file in FileResult.masterData)
{
string header = string.Format("http://192.168.3.76:9000/api/home/GetListFile?filePath={0}", folder.Path);
var FileResult = await MediaResourceFileService.PostObjectAsync<fileListResult,string>(header,"");
List<MHResourceFileModel> list = new List<MHResourceFileModel>();
// folder.Files = new System.Collections.ObjectModel.ObservableCollection<GHResourceFileModel>();
foreach (var file in FileResult.masterData)
try
{
MHResourceFileModel GHFile = new MHResourceFileModel();
GHFile.Name = file.fileName;
GHFile.Path = file.smallIconUrl;
if(ThumbnailHelper.IsImageByName(GHFile.Name))
if (ThumbnailHelper.IsImageByName(file.fileName))
{
//GetFile
string url = string.Format("http://192.168.3.76:9000/api/home/GetFile?filePath={0}", GHFile.Path);
GHFile.Name = file.fileName;
GHFile.Path = file.smallIconUrl;
string url = string.Format("{0}GetFile?filePath={1}", httpUrl, GHFile.Path);
var fileResult = await MediaResourceFileService.GetImage(url);
GHFile.FileType = ResourceFileType.IMAGE;
Image img = Bitmap.FromStream(fileResult);
Bitmap bmp = new Bitmap(img);
img = ThumbnailHelper.GetThumbnail(img, 100, 200);
Bitmap bmp = new Bitmap(img);
GHFile.ThumbnailBitmap = bmp;
list.Add(GHFile);
}
else if(ThumbnailHelper.IsVideo(GHFile.Name))
else if (ThumbnailHelper.IsVideo(file.fileName))
{
string strVedioPath = string.Format("{0}{1}", System.Environment.CurrentDirectory, "\\VedioImage\\Vedio.jpeg");
GHFile.Name = file.fileName;
GHFile.Path = file.smallIconUrl;
string strVedioPath = string.Format("{0}{1}", System.Environment.CurrentDirectory, "\\Resource\\VedioImage\\Vedio.jpeg");
Image vedioImage = Image.FromFile(strVedioPath);
vedioImage = ThumbnailHelper.GetThumbnail(vedioImage, 100, 200);
Bitmap vedioBtm = new Bitmap(vedioImage);
GHFile.ThumbnailBitmap = vedioBtm;
GHFile.FileType = ResourceFileType.Video;
list.Add(GHFile);
}
list.Add(GHFile);
}
catch(Exception ex)
{
log.Error(ex.Message);
}
}
folder.Files = list.ToObservableCollection();
this.Support.FileModels = folder.Files;
});
}
//string oldFile, string newFile
public async void MoveFile(string oldPath,string newPath)
{
string header = string.Format("{0}MoveFile?oldFile={1}&newFile={2}",httpUrl, oldPath, newPath);
var errorMessage = await MediaResourceFileService.PostAsyncJson(header,"");
}
folder.Files = list.ToObservableCollection();
/// <summary>
/// 添加文件夹
/// </summary>
/// <param name="path"></param>
public async void CreateFolder(string path)
{
string header = string.Format("{0}CreateFiles?newDir={1}", httpUrl,path);
var strError = await MediaResourceFileService.PostAsyncJson(header, "");
this.Support.FileModels = folder.Files;
});
}
/// <summary>
/// 删除文件夹
/// </summary>
/// <param name="path"></param>
public async void DeleteFolder(string path)
{
string header = string.Format("{0}DeleteFiles?delDir={1}",httpUrl, path);
var strError=await MediaResourceFileService.PostAsyncJson(header, "");
}
/// <summary>
/// 创建文件
/// </summary>
/// <param name="filePath"></param>
/// <param name="fileName"></param>
/// <returns></returns>
public async Task<fileUploadResult> CreateFile(string filePath,string fileName)
{
string requestUri = string.Format("{0}UplodFile?filePath={1}",httpUrl,this.Support.SelectedFolderModel.Path + "\\");
fileUploadResult upLoadResult = await MediaResourceFileService.PostImage<fileUploadResult>(requestUri,filePath,fileName);
return upLoadResult;
}
public async void DeleteFile(string path)
{
string header = string.Format("{0}DeleteFile?delFile={1}",httpUrl, path);
var strError = await MediaResourceFileService.PostAsyncJson(header, "");
}
/// <summary>
///获取文件
/// </summary>
/// <returns></returns>
public async Task<List<MHResourceFolderModel>> GetMeiaResourceFolder()
{
var folderResult = await MediaResourceFileService.PostObjectAsync<fileListResult, string>("http://192.168.3.76:9000/api/home/GetListFiles", "");
// var config =
var folderResult = await MediaResourceFileService.PostObjectAsync<fileListResult, string>(string.Format( "{0}GetListFiles",httpUrl), "");
if (folderResult == null)
return null;
return GetFolder(folderResult.masterData);
}
/// <summary>
/// 获取文件夹
/// </summary>
/// <param name="foldersDatas"></param>
/// <returns></returns>
private List<MHResourceFolderModel> GetFolder(List<ms> foldersDatas)
{
List<MHResourceFolderModel> listFolderModel = new List<MHResourceFolderModel>();
foreach(var floderData in foldersDatas)
foreach (var floderData in foldersDatas)
{
if(floderData.fileType== "floder")
if (floderData.fileType == "floder")
{
MHResourceFolderModel child = new MHResourceFolderModel();
child.Name = floderData.fileName;
......@@ -166,7 +216,6 @@ namespace VIZ.TVP.Module
List<MHResourceFolderModel> children_list = GetFolder(floderData.m);
foreach (MHResourceFolderModel item in children_list)
{
......
......@@ -7,6 +7,7 @@ using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Web.UI.WebControls;
namespace VIZ.TVP.Module
{
......@@ -36,9 +37,9 @@ namespace VIZ.TVP.Module
return responseBody;
}
catch(Exception ex)
catch (Exception ex)
{
log.Error(string.Format("{0}_{1}","获取媒体资源文件夹",ex.ToString()));
log.Error(string.Format("{0}_{1}", "获取媒体资源文件夹", ex.ToString()));
return "";
}
......@@ -72,7 +73,7 @@ namespace VIZ.TVP.Module
//}
//else
//{
responseBody = await response.Content.ReadAsStringAsync();
responseBody = await response.Content.ReadAsStringAsync();
//}
return responseBody;
......@@ -105,7 +106,7 @@ namespace VIZ.TVP.Module
//}
//else
//{
responseBody = await response.Content.ReadAsStringAsync();
responseBody = await response.Content.ReadAsStringAsync();
//}
return responseBody;
......@@ -139,7 +140,7 @@ namespace VIZ.TVP.Module
}
/// <summary>
/// 获取图片
/// </summary>
......@@ -159,9 +160,42 @@ namespace VIZ.TVP.Module
return ms;
}
}
/// <summary>
/// 上传图片
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="requestUri"></param>
/// <param name="path"></param>
/// <param name="fileName"></param>
/// <returns></returns>
public static async Task<T> PostImage<T>(string requestUri,string path,string fileName)
{
HttpClient client = new HttpClient();
var content = new MultipartFormDataContent();
content.Headers.Add("ContentType", $"multipart/form-data");
//添加字符串参数,参数名为qq
// content.Add(new StringContent("123456"), "qq");
//string path = Path.Combine(System.Environment.CurrentDirectory, "1.png");
//添加文件参数,参数名为files,文件名为123.png
var b = new ByteArrayContent(System.IO.File.ReadAllBytes(path));
content.Add(new ByteArrayContent(System.IO.File.ReadAllBytes(path)), "image", fileName);
var response = await client.PostAsync(requestUri, content);
var result = response.Content.ReadAsStringAsync().Result;
return JsonConvert.DeserializeObject<T>(result);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VIZ.TVP.Module.Resource.MediaResource.Controller.Model
{
public class fileUploadResult
{
/// <summary>
/// 状态码:0-成功
/// </summary>
public string errCode
{
get;
set;
}
/// <summary>
/// 状态描述:0-成功
/// </summary>
public string message
{
get;
set;
}
/// <summary>
/// 状态描述:0-success
/// </summary>
public string status
{
get;
set;
}
/// <summary>
/// 设置文件信息
/// </summary>
public ms masterData = new ms();
}
}
<UserControl x:Class="VIZ.TVP.Module.CreateFolder"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm"
d:DataContext="{d:DesignInstance Type=local:CreateProjectViewModel}"
d:Background="White"
xmlns:local="clr-namespace:VIZ.TVP.Module"
mc:Ignorable="d"
d:DesignHeight="200" d:DesignWidth="400">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="120"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="80"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Text="文件名:" VerticalAlignment="Center" HorizontalAlignment="Right" Margin="0,0,10,0"></TextBlock>
<TextBox Text="{Binding Path=FolderName}" Grid.Column="1" VerticalAlignment="Center" VerticalContentAlignment="Center"
AcceptsReturn="False" TextWrapping="NoWrap" Height="30" Margin="10,0,10,0"></TextBox>
<StackPanel Grid.Row="2" Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Right">
<Button Content="确定" Width="80" Height="30" Margin="10" Command="{Binding EnterCommand}"></Button>
<Button Content="取消" Width="80" Height="30" Margin="10" Command="{Binding CancelCommand}"></Button>
</StackPanel>
</Grid>
</UserControl>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using VIZ.Framework.Core;
namespace VIZ.TVP.Module
{
/// <summary>
/// Interaction logic for CreateFolder.xaml
/// </summary>
public partial class CreateFolder : UserControl
{
public CreateFolder()
{
InitializeComponent();
WPFHelper.BindingViewModel(this, new CreateFolderViewModel());
}
}
}
<dx:ThemedWindow
x:Class="VIZ.TVP.Module.CreateFolderWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
xmlns:module="clr-namespace:VIZ.TVP.Module"
Title="创建文件夹" Height="240" Width="400" WindowStartupLocation="CenterScreen" WindowStyle="None" >
<Grid>
<module:CreateFolder x:Name="createFolderView"></module:CreateFolder>
</Grid>
</dx:ThemedWindow>
using DevExpress.Xpf.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace VIZ.TVP.Module
{
/// <summary>
/// Interaction logic for CreateFolderWindow.xaml
/// </summary>
public partial class CreateFolderWindow : ThemedWindow
{
public CreateFolderWindow()
{
InitializeComponent();
}
}
}
......@@ -46,6 +46,9 @@
<dxg:TreeViewControl.ContextMenu>
<ContextMenu>
<MenuItem Header="刷新" Command="{Binding Path=PlacementTarget.DataContext.RefreshFolderCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}}"/>
<MenuItem Header="创建文件夹" Command="{Binding Path=PlacementTarget.DataContext.CreateFloderCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}}"/>
<MenuItem Header="删除文件夹" Command="{Binding Path=PlacementTarget.DataContext.DeleteFloderCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}}"/>
<MenuItem Header="移入文件夹" Command="{Binding Path=PlacementTarget.DataContext.MoveFloderCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}}"/>
</ContextMenu>
</dxg:TreeViewControl.ContextMenu>
<dxmvvm:Interaction.Behaviors>
......@@ -112,8 +115,11 @@
<dxmvvm:EventToCommand EventName="Opened" Command="{Binding Path=FileContextMenuOpendCommand}"></dxmvvm:EventToCommand>
</dxmvvm:Interaction.Behaviors>
<MenuItem Header="刷新" Command="{Binding Path=PlacementTarget.DataContext.RefreshFileCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}}"/>
<MenuItem Header="添加文件" Command="{Binding Path=PlacementTarget.DataContext.CreateFileCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}}"/>
<MenuItem Header="删除文件" Command="{Binding Path=PlacementTarget.DataContext.DeleteFileCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}}"/>
<MenuItem Header="移动文件" Command="{Binding Path=PlacementTarget.DataContext.MoveFileCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}}"/>
<Separator/>
<MenuItem Header="添加至场景模板" Command="{Binding Path=PlacementTarget.DataContext.AddProgramTemplateCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}}"/>
<!--<MenuItem Header="添加至场景模板" Command="{Binding Path=PlacementTarget.DataContext.AddProgramTemplateCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}}"/>-->
<MenuItem Header="复制路径" Command="{Binding Path=PlacementTarget.DataContext.CopyFilePathCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}}"/>
</ContextMenu>
</dxg:GridControl.ContextMenu>
......
using DevExpress.Data.Mask.Internal;
using DevExpress.Xpf.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VIZ.Framework.Core;
using VIZ.Framework.Plugin;
namespace VIZ.TVP.Module
{
public class CreateFolderViewModel : PluginViewModelBase
{
public CreateFolderViewModel()
{
EnterCommand = new VCommand(Enter);
CancelCommand = new VCommand(Cancel);
}
private string folderName;
public string FolderName
{
get { return folderName; }
set { folderName = value; this.RaisePropertyChanged(nameof(FolderName)); }
}
private bool isEnter;
/// <summary>
/// 是否确定
/// </summary>
public bool IsEnter
{
get { return isEnter; }
set { isEnter = value; this.RaisePropertyChanged(nameof(IsEnter)); }
}
public VCommand EnterCommand { get; set; }
public VCommand CancelCommand { get; set; }
/// <summary>
/// 确定
/// </summary>
private void Enter()
{
if (string.IsNullOrWhiteSpace(this.FolderName))
{
DXMessageBox.Show("请输入文件名");
return;
}
this.IsEnter = true;
this.GetWindow()?.Close();
}
/// <summary>
/// 取消
/// </summary>
private void Cancel()
{
this.IsEnter = false;
this.GetWindow()?.Close();
}
public override void Dispose()
{
}
}
}
using DevExpress.Mvvm.POCO;
using DevExpress.Mvvm.UI.Native.ViewGenerator;
using DevExpress.Mvvm.Xpf;
using DevExpress.Utils.CommonDialogs.Internal;
using DevExpress.Xpf.Core;
using DevExpress.Xpf.Core.Native;
using DevExpress.XtraPrinting.Native;
using log4net;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Configuration;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
......@@ -17,13 +21,14 @@ using VIZ.Framework.Plugin;
using VIZ.TVP.Domain;
using VIZ.TVP.Service;
using VIZ.TVP.Storage;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace VIZ.TVP.Module
{
/// <summary>
/// 媒体资源视图模型
/// </summary>
public class MediaResourceViewModel : PluginViewModelBase,IMediaResourceFileSupport
public class MediaResourceViewModel : PluginViewModelBase, IMediaResourceFileSupport
{
/// <summary>
......@@ -46,8 +51,18 @@ namespace VIZ.TVP.Module
private void initCommand()
{
this.LoadedCommand = new VCommand(this.Loaded);
this.RefreshFolderCommand = new VCommand(this.RefreshFolder);
this.RefreshFileCommand = new VCommand(this.RefreshFile);
this.CreateFloderCommand = new VCommand(this.CreateFloder);
this.DeleteFloderCommand = new VCommand(this.DeleteFloder);
this.CreateFileCommand = new VCommand(this.CreateFile);
this.DeleteFileCommand = new VCommand(this.DeleteFile);
this.MoveFileCommand = new VCommand(this.MoveFile);
this.MoveFloderCommand = new VCommand(this.MoveFileFloder);
this.FolderExpandCommand = new VCommand<DevExpress.Xpf.Grid.TreeList.NodeDoubleClickEventArgs>(this.FolderExpand);
this.FileFilterCommand = new VCommand<ResourceFileType>(this.FileFilter);
this.FileRowFilterCommand = new DevExpress.Mvvm.DelegateCommand<RowFilterArgs>(this.FileRowFilter);
......@@ -97,7 +112,7 @@ namespace VIZ.TVP.Module
selectedFolderModel = value;
this.RaisePropertyChanged(nameof(SelectedFolderModel));
// 更新文件模型
// this.mediaResourceFileController.UpdateFileModels(value);
this.mediaResourceFileController.UpdateFileModels(value);
}
}
......@@ -259,8 +274,8 @@ namespace VIZ.TVP.Module
//{
// this.FolderModels = list.FirstOrDefault()?.Children.Select(p => (GHResourceFolderModel)p).ToObservableCollection();
this.IsFolderLoading = false;
// });
this.IsFolderLoading = false;
// });
......@@ -276,6 +291,8 @@ namespace VIZ.TVP.Module
#region RefreshFileCommand -- 刷新文件命令
/// <summary>
/// 刷新文件命令
/// </summary>
......@@ -286,20 +303,201 @@ namespace VIZ.TVP.Module
/// </summary>
private void RefreshFile()
{
//MHResourceFolderModel folder = this.SelectedFolderModel;
MHResourceFolderModel folder = this.SelectedFolderModel;
if (folder == null)
return;
this.mediaResourceFileController.DisposeFileModels(folder);
folder.IsRefreshedFiles = false;
this.mediaResourceFileController.UpdateFileModels(this.SelectedFolderModel);
}
#endregion
#region 创建文件夹
public VCommand CreateFloderCommand { get; set; }
/// <summary>
/// 创建文件夹
/// </summary>
private void CreateFloder()
{
CreateFolderWindow floderView = new CreateFolderWindow();
CreateFolderViewModel vm = floderView.createFolderView.DataContext as CreateFolderViewModel;
floderView.ShowDialog();
if (vm == null || !vm.IsEnter)
return;
string createPath = String.Format("{0}\\{1}", selectedFolderModel.Path, vm.FolderName);
SelectedFolderModel.Children.Add(new MHResourceFolderModel()
{
Name = vm.FolderName,
Path = createPath,
FolderType = ResourceFolderType.Folder
});
this.mediaResourceFileController.CreateFolder(createPath);
}
#endregion
#region 删除文件夹
public VCommand DeleteFloderCommand { get; set; }
private void DeleteFloder()
{
if ((DialogResult)DXMessageBox.Show("是否此文件夹", "", MessageBoxButton.YesNo) == DialogResult.Yes)
{
string path = SelectedFolderModel.Path;
SelectedFolderModel.Parent.Children.Remove(SelectedFolderModel);
this.mediaResourceFileController.DeleteFolder(path);
}
}
#endregion
#region 创建文件
public VCommand CreateFileCommand { get; set; }
/// <summary>
/// 从配置文件读取
/// </summary>
public static AppSettingsSection config = ApplicationDomainEx.DataBaseManager.ConfigContext.configuration.AppSettings;
/// <summary>
/// 从配置文件读取过滤字符串
/// </summary>
private static string filter = config.Settings["MediaFilter"].Value.ToString();
/// <summary>
/// 创建文件方法
/// </summary>
private async void CreateFile()
{
//if (folder == null)
System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog();
ofd.Filter = filter;
ofd.Multiselect = false;
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
string path = System.IO.Path.GetFullPath(ofd.FileName);
string fileName = ThumbnailHelper.GetFileFolderName(path);
var fileResult = await this.mediaResourceFileController.CreateFile(path, fileName);
if (fileResult != null && fileResult.errCode == "0")
{
try
{
MHResourceFileModel fileModel = new MHResourceFileModel();
if (ThumbnailHelper.IsImageByName(fileName))
{
Image image = ThumbnailHelper.GetImage(path, 100, 200);
Bitmap btm = new Bitmap(image);
fileModel.ThumbnailBitmap = btm;
fileModel.FileType = ResourceFileType.IMAGE;
fileModel.Name = fileName;
this.FileModels.Add(fileModel);
}
else if (ThumbnailHelper.IsVideo(fileName))
{
string vedioImage = string.Format("{0}{1}", System.Environment.CurrentDirectory, "\\Resource\\VedioImage\\Vedio.jpeg");
Image image = ThumbnailHelper.GetImage(vedioImage, 100, 200);
Bitmap btm = new Bitmap(image);
fileModel.ThumbnailBitmap = btm;
fileModel.FileType = ResourceFileType.Video;
fileModel.Name = fileName;
this.FileModels.Add(fileModel);
}
}
catch (Exception ex)
{
log.Error(ex.Message);
}
}
}
//System.Windows.Forms.FileDialog fbd = new System.Windows.Forms.FileDialog();
//if (fbd.ShowDialog() != System.Windows.Forms.DialogResult.OK)
// return;
}
#endregion 创建文件
//this.mediaResourceFileController.DisposeFileModels(folder);
#region 删除文件
public VCommand DeleteFileCommand { get; set; }
private void DeleteFile()
{
if ((DialogResult)DXMessageBox.Show("是否删除此文件", "", MessageBoxButton.YesNo) == DialogResult.Yes)
{
//folder.IsRefreshedFiles = false;
this.mediaResourceFileController.DeleteFile(selectedFileModel.Path);
//this.mediaResourceFileController.UpdateFileModels(this.SelectedFolderModel);
this.FileModels.Remove(this.SelectedFileModel);
}
}
#endregion
#region 移动文件
public VCommand MoveFileCommand { get; set; }
public string moveFilePath = "";
public MHResourceFileModel moveFileModel = null;
private void MoveFile()
{
if ((DialogResult)DXMessageBox.Show("是否移动此文件", "", MessageBoxButton.YesNo) == DialogResult.Yes)
{
moveFilePath = selectedFileModel.Path;
moveFileModel = selectedFileModel;
}
}
public VCommand MoveFloderCommand { get; set; }
private void MoveFileFloder()
{
if (string.IsNullOrEmpty(moveFilePath))
{
// DXMessageBox.Show("请先选择移入的文件,在选择移动此文件夹","移入当前文件夹", MessageBoxButton.YesNo);
DXMessageBox.Show("请先选择移入的文件,在选择移动此文件夹");
// MessageBox.Show("请先选择移入的文件");
}
else
{
this.mediaResourceFileController.MoveFile(moveFilePath, selectedFolderModel.Path);
if(moveFileModel!=null)
{
this.FileModels.Add(moveFileModel);
}
}
}
#endregion
#region FolderExpandCommand -- 文件夹展开命令
/// <summary>
......@@ -390,7 +588,7 @@ namespace VIZ.TVP.Module
if (service == null)
return;
// service.AddSceneTemplate(this.SelectedFileModel);
// service.AddSceneTemplate(this.SelectedFileModel);
}
#endregion
......
using DevExpress.DirectX.Common.Direct2D;
using log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VIZ.Framework.Module;
using VIZ.TVP.Domain;
namespace VIZ.TVP.Module
{
public class AppSetup_InitMedia : AppSetupBase
{
/// <summary>
/// 日志
/// </summary>
private static ILog log = LogManager.GetLogger(typeof(AppSetup_InitMedia));
public override string Detail { get; } = "应用程序启动 -- 初始化媒体资源库";
public override bool Setup(AppSetupContext context)
{
ApplicationDomainEx.DataBaseManager.ConfigContext = new Storage.ConfigContext();
this.LoadConfig();
return true;
}
/// <summary>
/// 加载插件配置
/// </summary>
private void LoadConfig()
{
string folder = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config");
if (!System.IO.Directory.Exists(folder))
{
System.IO.Directory.CreateDirectory(folder);
}
string path = System.IO.Path.Combine(folder, "MediaResouce.config");
ApplicationDomainEx.DataBaseManager.ConfigContext.LoadMediaConfig(path);
}
public override void Shutdown(AppSetupContext context)
{
}
}
}
......@@ -102,6 +102,14 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Resource\MediaResource\View\CreateFolder.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Resource\MediaResource\View\CreateFolderWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="SettingInner\Control\View\ControlSettingView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
......@@ -218,7 +226,15 @@
<Compile Include="Resource\MediaResource\Controller\MediaResourceFile\MediaResourceFileController.cs" />
<Compile Include="Resource\MediaResource\Controller\MediaResourceFile\MediaResourceFileService.cs" />
<Compile Include="Resource\MediaResource\Controller\Model\fileListResult.cs" />
<Compile Include="Resource\MediaResource\Controller\Model\fileUploadResult.cs" />
<Compile Include="Resource\MediaResource\Controller\Model\ms.cs" />
<Compile Include="Resource\MediaResource\ViewModel\CreateFolderViewModel.cs" />
<Compile Include="Resource\MediaResource\View\CreateFolder.xaml.cs">
<DependentUpon>CreateFolder.xaml</DependentUpon>
</Compile>
<Compile Include="Resource\MediaResource\View\CreateFolderWindow.xaml.cs">
<DependentUpon>CreateFolderWindow.xaml</DependentUpon>
</Compile>
<Compile Include="SettingInner\Control\ViewModel\ControlSettingViewModel.cs" />
<Compile Include="SettingInner\Control\View\ControlSettingView.xaml.cs">
<DependentUpon>ControlSettingView.xaml</DependentUpon>
......@@ -319,6 +335,7 @@
<Compile Include="Common\View\TextInputView.xaml.cs">
<DependentUpon>TextInputView.xaml</DependentUpon>
</Compile>
<Compile Include="Setup\Provider\Setup\AppSetup_InitMedia.cs" />
<Compile Include="Take\ViewModel\TakeViewModel.cs" />
<Compile Include="Take\View\TakeView.xaml.cs">
<DependentUpon>TakeView.xaml</DependentUpon>
......@@ -422,5 +439,10 @@
<Folder Include="PluginPanel\Controller\" />
<Folder Include="Program\Controller\" />
</ItemGroup>
<ItemGroup>
<None Include="Resource\VedioImage\Vedio.jpeg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file
using CsvHelper;
using log4net;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace VIZ.TVP.Storage
{
public class ConfigContext
{
/// <summary>
/// 日志
/// </summary>
private readonly static ILog log = LogManager.GetLogger(typeof(ConfigContext));
public Configuration configuration { get; set; }
/// <summary>
/// 加载插件配置
/// </summary>
/// <param name="path">文件路径</param>
public void LoadMediaConfig(string path)
{
if (File.Exists(path) == false)
{
{
string msg = string.Format("{0}路径下的文件未找到 ", path);
throw new FileNotFoundException(msg);
}
}
try
{
ExeConfigurationFileMap configFile = new ExeConfigurationFileMap();
configFile.ExeConfigFilename = path;
configuration = ConfigurationManager.OpenMappedExeConfiguration(configFile, ConfigurationUserLevel.None);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
}
}
......@@ -95,6 +95,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Config\ConfigContext.cs" />
<Compile Include="CSV\CsvContext.cs" />
<Compile Include="CSV\Plugin\Enum\PluginTypeEnum.cs" />
<Compile Include="CSV\Plugin\PluginConfig.cs" />
......
......@@ -28,6 +28,10 @@ namespace VIZ.TVP
// 初始化CSV
AppSetup.AppendSetup(new AppSetup_InitCSV());
//初始化媒体库配置文件
AppSetup.AppendSetup(new AppSetup_InitMedia());
// 执行启动流程
AppSetupContext context = AppSetup.Setup();
......
......@@ -122,6 +122,9 @@
<None Include="config\log.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="config\MediaResouce.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="config\plugin_config.csv">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
......
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="url" value="http://localhost:9000/api/home/"/>
<add key="MediaFilter" value="(*.jpg,*.png,*.jpeg,*.bmp,*.gif,*.avi,*.mp4)|*.jgp;*.png;*.jpeg;*.bmp;*.gif;*.avi;*.mp4"/>
</appSettings>
</configuration>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment