Exemplo n.º 1
0
        public bool Contains(FileNode file)
        {
            if (file == null) return false;
            foreach (var f in Content)
            {
                if (f.FullPath.ToLower().Equals(file.FullPath.ToLower()))
                {
                    return true;
                }
            }

            return false;
        }
Exemplo n.º 2
0
        public void TestEvaluateFolderSelector()
        {
            var script = new Script("(folder path:\"root\\blandet\")");
            var root = Fixture.Create<string>();
            var path = root + "\\blandet";
            var file = new FileNode()
            {
                FullPath = path + @"\test.png"
            };
            var playablefile1 = new PlayableFile()
            {
                File = file
            };
            var playablefile2 = new PlayableFile()
            {
                File = new FileNode()
                {
                    FullPath = Fixture.Create<string>()
                }
            };

            var container = CreateContainer(c =>
            {
                c.RegisterFake<IQueryHandler<GetStringSettingQuery, string>>()
                    .Handle(Arg.Any<GetStringSettingQuery>())
                    .Returns(root);

                c.RegisterFake<IQueryHandler<GetFoldersQuery, IQueryable<FolderNode>>>()
                    .Handle(Arg.Any<GetFoldersQuery>())
                    .Returns(new[] {
                            new FolderNode(null)
                            {
                                FullPath = path,
                                Content = new List<FileNode>()
                                {
                                    file
                                }
                            }
                        }.AsQueryable());
            });

            var interpreter = container.Resolve<IScriptInterpreter>();

            Assert.IsTrue(interpreter.Evaluate(script, playablefile1));
            Assert.IsFalse(interpreter.Evaluate(script, playablefile2));
        }
Exemplo n.º 3
0
        public void Handle(FileNode file, IVideoPlayerController controller, IPlayStrategy playStrategy, IQueryProcessor processor, IFileDelayStrategy delay)
        {
            var isStatFile = processor.Process(new IsStatFileQuery()
            {
                File = file
            });

            var isStatStrategy = playStrategy is PlayerStatPlayStrategy;

            if (isStatFile)
            {
                controller.ShowStats();
                delay.StartTimer();
            }
            else if (file.Type == FileType.Picture && isStatStrategy)
            {
                delay.StartTimer();
            }
        }
Exemplo n.º 4
0
        public void Play(FileNode file)
        {
            if (file.Type == FileType.Picture)
            {
                ShowPicture(file);
            }
            else
            {
                if (file.Type == FileType.Video) _mediaView.Picture.Visibility = Visibility.Collapsed;

                var mediaelement = GetMediaElement(file.Type);
                mediaelement.Source = new Uri(file.FullPath);

                if (file.Type == FileType.Video) _mediaView.Video.Visibility = Visibility.Visible;

                mediaelement.Play();
                Console.WriteLine("PlayController playing: {0}", file.Name);
            }
            ChangeState(file.Type, MediaPlayerState.Playing);
        }
Exemplo n.º 5
0
        public void TestEvaluateMultiSelector()
        {
            var intScript = "(property name:Number value:42)";
            var boolScript = "(property name:Trainer value:True)";
            var typeScript = "(type name:Player)";

            var script = new Script("(multi left:" + intScript + " right:(multi left:" + typeScript + " right:" + boolScript + "))");

            var player1 = new Player()
            {
                Trainer = true,
                Number = 42
            };
            var player2 = new Player()
            {
                Trainer = false,
                Number = 21
            };
            var player3 = new Player()
            {
                Trainer = true,
                Number = 21
            };
            var file = new FileNode().RandomizeTheRest();

            var container = CreateContainer();
            var interpreter = container.Resolve<IScriptInterpreter>();

            Assert.IsTrue(interpreter.Evaluate(script, player1));
            Assert.IsFalse(interpreter.Evaluate(script, player2));
            Assert.IsFalse(interpreter.Evaluate(script, player3));
            Assert.IsFalse(interpreter.Evaluate(script, file));
        }
Exemplo n.º 6
0
        public void TestEvaluatePropertySelector()
        {
            var path = @"test";
            var file1 = new FileNode()
            {
                FullPath = path
            }.RandomizeTheRest();
            var file2 = new FileNode()
            {
                FullPath = Fixture.Create<string>()
            }.RandomizeTheRest();
            var player1 = new Player()
            {
                Trainer = false,
                Number = 42
            };
            var player2 = new Player()
            {
                Trainer = true,
                Number = 21
            };

            var stringScript = new Script("(property name:FullPath value:\"" + path + "\")");
            var intScript = new Script("(property name:Number value:42)");
            var boolScript = new Script("(property name:Trainer value:True)");

            var container = CreateContainer();
            var interpreter = container.Resolve<IScriptInterpreter>();

            Assert.IsTrue(interpreter.Evaluate(stringScript, file1));
            Assert.IsFalse(interpreter.Evaluate(stringScript, file2));
            Assert.IsFalse(interpreter.Evaluate(stringScript, player1));

            Assert.IsTrue(interpreter.Evaluate(intScript, player1));
            Assert.IsFalse(interpreter.Evaluate(intScript, player2));
            Assert.IsFalse(interpreter.Evaluate(intScript, file1));

            Assert.IsTrue(interpreter.Evaluate(boolScript, player2));
            Assert.IsFalse(interpreter.Evaluate(boolScript, player1));
            Assert.IsFalse(interpreter.Evaluate(boolScript, file1));
        }
Exemplo n.º 7
0
        public void TestIsStatFile()
        {
            var folderpath = "c:\\test";
            var file1 = new FileNode()
            {
                FullPath = folderpath + "\\test.png"
            };

            var file2 = new FileNode()
            {
                FullPath = "z:\\test\\test.png"
            };

            var container = CreateContainer(c =>
            {
                c.RegisterFake<IQueryHandler<GetFolderByPathSubscriptQuery, FolderNode>>()
                    .Handle(Arg.Any<GetFolderByPathSubscriptQuery>())
                    .Returns(new FolderNode(null)
                    {
                        FullPath = folderpath,
                        Content = new List<FileNode>()
                        {
                            file1
                        }
                    });
            });

            var processor = container.Resolve<IQueryProcessor>();

            var result1 = processor.Process(new IsStatFileQuery()
            {
                File = file1
            });

            var result2 = processor.Process(new IsStatFileQuery()
            {
                File = file2
            });

            Assert.IsTrue(result1);
            Assert.IsFalse(result2);
        }
Exemplo n.º 8
0
        public void TestGetPlayablesAffectedByFolder()
        {
            var folderPath = "c:\\test";
            var file = new FileNode()
            {
                FullPath = folderPath + "\\test.mp3"
            };

            var container = CreateContainer(c =>
            {
                c.RegisterFake<IQueryHandler<GetPlayableFilesQuery, IQueryable<PlayableFile>>>()
                    .Handle(Arg.Any<GetPlayableFilesQuery>())
                    .Returns(new[]
                    {
                        new PlayableFile()
                        {
                            File = file
                        }
                    }.AsQueryable());

                c.RegisterFake<IQueryHandler<GetPlayerFoldersQuery, IQueryable<FolderNode>>>()
                    .Handle(Arg.Any<GetPlayerFoldersQuery>())
                    .Returns(new[]
                    {
                        new FolderNode(null)
                        {
                            FullPath = folderPath
                        }.RandomizeTheRest()
                    }.AsQueryable());
            });

            var commandProcessor = container.Resolve<ICommandProcessor>();

            var folder = new FolderNode(commandProcessor)
            {
                FullPath = folderPath
            };

            folder.AddFile(file);

            var queryProcessor = container.Resolve<IQueryProcessor>();

            var center = container.Resolve<IDataCenter>();

            var playables = queryProcessor.Process(new GetPlayablesAffectedByFolderQuery()
            {
                Folder = folder
            });

            Assert.IsNotNull(playables);
            Assert.AreEqual(1, playables.Count());
        }
Exemplo n.º 9
0
 public void Play(FileNode file)
 {
     _handleFileStrategy.Handle(file, this, _videoPlayStrategy, _processor, _delayStrategy);
     Console.WriteLine(file.Name);
     _observers.ForEach(x => x.Play(file));
 }
Exemplo n.º 10
0
 public void AddFile(FileNode node)
 {
     Content.Add(node);
 }
Exemplo n.º 11
0
        private void ShowPicture(FileNode file)
        {
            _mediaView.Video.Visibility = Visibility.Collapsed;

            _mediaView.Picture.Source = ConstructImage(file);

            _mediaView.Picture.Visibility = Visibility.Visible;
        }
Exemplo n.º 12
0
 private BitmapImage ConstructImage(FileNode file)
 {
     var res = new BitmapImage();
     res.BeginInit();
     res.UriSource = new Uri(file.FullPath);
     res.EndInit();
     return res;
 }
Exemplo n.º 13
0
        public void TestCreatePlayer()
        {
            var filename = "001 - Chana de Souza Mason.png";
            var playername = "Chana de Souza Mason";
            var number = 1;
            var file = new FileNode()
            {
                Name = filename,
                NameWithoutExtension = "001 - Chana de Souza Mason",
                FullPath = Path.Combine("stuff", filename)
            };
            var statFolder = new FolderNode(null);

            var container = CreateContainer(c =>
            {
                c.RegisterFake<IQueryHandler<GetPlayerFoldersQuery, IQueryable<FolderNode>>>()
                    .Handle(Arg.Any<GetPlayerFoldersQuery>())
                    .Returns(new[]
                    {
                        new FolderNode(null)
                        {
                            Content = new List<FileNode>()
                            {
                                file
                            }
                        }
                    }.AsQueryable());
            });

            var processor = container.Resolve<ICommandProcessor>();
            processor.Process(new CreatePlayerCommand()
            {
                File = file,
                Folder = statFolder
            });

            var datacenter = container.Resolve<IDataCenter>();

            Assert.AreEqual(playername, datacenter.Players[0].Name);
            Assert.AreEqual(number, datacenter.Players[0].Number);
            Assert.AreEqual(file, datacenter.Players[0].Content.ToList()[0]);
            Assert.IsFalse(datacenter.Players[0].Trainer);
        }