示例#1
0
        private void GenerateNailImage(MemoryLibraryItem item, NailImageFileItem nailItem)
        {
            string sourceName = null;
            string targetName = null;

            if (!string.IsNullOrEmpty(nailItem.Name) &&
                nailItem.Content != null &&
                nailItem.Content.Length > 0)
            {
                targetName = Constance.LibraryNailImageDir + nailItem.Name;
                if (!File.Exists(targetName))
                {
                    IOHelper.WriteAllBytes(targetName, nailItem.Content);
                }
                else
                {
                    sourceName = targetName;
                    targetName = Constance.LibraryNailImageDir + Guid.NewGuid().ToString().Replace("-", "") + Constance.FileExtensionName.NailImage;
                    IOHelper.WriteAllBytes(targetName, nailItem.Content);

                    //Update playlist nail shape
                    UpdateNailImage(sourceName, targetName, new List <PlaylistInfo>()
                    {
                        _target
                    });
                    UpdateNailImage(sourceName, targetName, _playlists);
                }

                item.ImagePath = targetName;
            }
        }
示例#2
0
        private void SerializingPlaylist(PlaylistInfo playlist)
        {
            if (playlist == null || playlist.Items == null || playlist.Items.Length == 0)
            {
                return;
            }

            if (!string.IsNullOrEmpty(playlist.ImagePath) &&
                File.Exists(playlist.ImagePath))
            {
                NailImageFileItem nailItem = new NailImageFileItem();
                nailItem            = new NailImageFileItem();
                nailItem.MemoryName = playlist.Name;
                nailItem.Type       = playlist.Type;
                nailItem.Content    = IOHelper.ReadAllBytes(playlist.ImagePath);
                nailItem.Name       = Path.GetFileName(playlist.ImagePath);
                _nailItems.Add(nailItem);
            }
        }
示例#3
0
        private void SerializingTimeSliceGroup(TimeSliceGroupInfo group)
        {
            if (group == null || group.Items == null || group.Items.Length == 0)
            {
                return;
            }

            if (!string.IsNullOrEmpty(group.ImagePath) &&
                File.Exists(group.ImagePath))
            {
                NailImageFileItem nailItem = new NailImageFileItem();
                nailItem            = new NailImageFileItem();
                nailItem.MemoryName = group.Name;
                nailItem.Type       = group.Type;
                nailItem.Content    = IOHelper.ReadAllBytes(group.ImagePath);
                nailItem.Name       = Path.GetFileName(group.ImagePath);
                _nailItems.Add(nailItem);
            }
        }
示例#4
0
        private void GenerateNailImage(MemoryLibraryItem item, NailImageFileItem nailItem)
        {
            string targetName = null;

            if (!string.IsNullOrEmpty(nailItem.Name) &&
                nailItem.Content != null &&
                nailItem.Content.Length > 0)
            {
                targetName = Constance.LibraryNailImageDir + nailItem.Name;
                if (!File.Exists(targetName))
                {
                    IOHelper.WriteAllBytes(targetName, nailItem.Content);
                }
                else
                {
                    targetName = Constance.LibraryNailImageDir + Guid.NewGuid().ToString().Replace("-", "") + Constance.FileExtensionName.NailImage;
                    IOHelper.WriteAllBytes(targetName, nailItem.Content);
                }

                item.ImagePath = targetName;
            }
        }
示例#5
0
        private void SerializingMessage(MessageInfo message)
        {
            FileItem item = null;

            foreach (ShapeLayer layer in message.Items)
            {
                if (layer.Shape == null)
                {
                    continue;
                }
                if (layer.Shape.Type == ShapeType.Image)
                {
                    ShapeImage image = layer.Shape as ShapeImage;
                    if (image == null ||
                        image.Image == null ||
                        string.IsNullOrEmpty(image.ImageUrl) ||
                        !File.Exists(image.ImageUrl))
                    {
                        continue;
                    }
                    string imageName = Path.GetFileName(image.ImageUrl);

                    byte[] content = IOHelper.ReadAllBytes(image.ImageUrl);

                    item = _images.Find(p => { return(p.Name == imageName); });
                    if (item != null)
                    {
                        if (IOHelper.FileContentCompare(item.Content, content))
                        {
                            continue;
                        }
                        imageName = "_" + imageName;
                    }

                    _images.Add(new FileItem {
                        Id = image.FileHandle, Name = imageName, Path = image.ImageUrl, Content = content, Type = LibraryType.Image
                    });
                }
                else if (layer.Shape.Type == ShapeType.Video)
                {
                    ShapeVideo video = layer.Shape as ShapeVideo;
                    if (video == null ||
                        string.IsNullOrEmpty(video.VideoUrl) ||
                        !File.Exists(video.VideoUrl))
                    {
                        continue;
                    }
                    string videoName = Path.GetFileName(video.VideoUrl);

                    byte[] content = IOHelper.ReadAllBytes(video.VideoUrl);

                    item = _videos.Find(p => { return(p.Name == videoName); });
                    if (item != null)
                    {
                        if (IOHelper.FileContentCompare(item.Content, content))
                        {
                            continue;
                        }
                        videoName = "_" + videoName;
                    }

                    _videos.Add(new FileItem {
                        Id = video.FileHandle, Name = videoName, Path = video.VideoUrl, Content = content, Type = LibraryType.Video
                    });
                }

                if (!string.IsNullOrEmpty(message.ImagePath) &&
                    File.Exists(message.ImagePath))
                {
                    NailImageFileItem nailItem = new NailImageFileItem();
                    nailItem            = new NailImageFileItem();
                    nailItem.MemoryName = message.Name;
                    nailItem.Type       = message.Type;
                    nailItem.Content    = IOHelper.ReadAllBytes(message.ImagePath);
                    nailItem.Name       = Path.GetFileName(message.ImagePath);
                    _nailItems.Add(nailItem);
                }
            }
        }
示例#6
0
        private void Serializing(StreamingContext ctx)
        {
            if (_target == null ||
                _target.Items == null ||
                _target.Items.Length < 1)
            {
                return;
            }
            _images = new List <FileItem>();
            _videos = new List <FileItem>();

            FileItem item = null;

            foreach (ShapeLayer layer in _target.Items)
            {
                if (layer.Shape == null)
                {
                    continue;
                }
                if (layer.Shape.Type == ShapeType.Image)
                {
                    ShapeImage image = layer.Shape as ShapeImage;
                    if (image == null ||
                        image.Image == null ||
                        string.IsNullOrEmpty(image.ImageUrl) ||
                        !File.Exists(image.ImageUrl))
                    {
                        continue;
                    }
                    string imageName = Path.GetFileName(image.ImageUrl);

                    byte[] content = IOHelper.ReadAllBytes(image.ImageUrl);

                    item = _images.Find(p => { return(p.Name == imageName); });
                    if (item != null)
                    {
                        if (IOHelper.FileContentCompare(item.Content, content))
                        {
                            continue;
                        }
                        imageName = "_" + imageName;
                    }

                    _images.Add(new FileItem {
                        Id = image.FileHandle, Name = imageName, Path = image.ImageUrl, Content = content, Type = LibraryType.Image
                    });
                }
                else if (layer.Shape.Type == ShapeType.Video)
                {
                    ShapeVideo video = layer.Shape as ShapeVideo;
                    if (video == null ||
                        string.IsNullOrEmpty(video.VideoUrl) ||
                        !File.Exists(video.VideoUrl))
                    {
                        continue;
                    }
                    string videoName = Path.GetFileName(video.VideoUrl);

                    byte[] content = IOHelper.ReadAllBytes(video.VideoUrl);

                    item = _videos.Find(p => { return(p.Name == videoName); });
                    if (item != null)
                    {
                        if (IOHelper.FileContentCompare(item.Content, content))
                        {
                            continue;
                        }
                        videoName = "_" + videoName;
                    }

                    _videos.Add(new FileItem {
                        Id = video.FileHandle, Name = videoName, Path = video.VideoUrl, Content = content, Type = LibraryType.Video
                    });
                }
            }

            if (_images.Count < 1)
            {
                _images = null;
            }
            if (_videos.Count < 1)
            {
                _videos = null;
            }
            if (!string.IsNullOrEmpty(_target.ImagePath) &&
                File.Exists(_target.ImagePath))
            {
                _nailItem            = new NailImageFileItem();
                _nailItem.MemoryName = _target.Name;
                _nailItem.Type       = _target.Type;
                _nailItem.Content    = IOHelper.ReadAllBytes(_target.ImagePath);
                _nailItem.Name       = Path.GetFileName(_target.ImagePath);
            }
        }