コード例 #1
0
        public void WatchHiddenFilesTester3()
        {
            string path   = $"{Guid.NewGuid()}.xml";
            var    stream = File.Create(path);

            try
            {
                new FileInfo(stream.Name).Attributes |= FileAttributes.Hidden;

                var folderConfig = new FolderConfig
                {
                    FolderPath = stream.Name.GetDirectoryPath(),
                    //WatchLogFiles = true,
                    WatchHiddenFiles = false
                };

                var op = new CreateOperationEvent
                {
                    FilePath   = stream.Name,
                    RaisedTime = new DateTime(2017, 11, 27)
                };

                Assert.AreEqual(false, folderConfig.IsValid(op));
            }
            finally
            {
                stream.Close();
                File.Delete(path);
            }
        }
コード例 #2
0
        public void TextLogFileNameTester2()
        {
            string path   = $"SomeDateTime - {Constants.TextLogFileName}";
            var    stream = File.Create(path);

            try
            {
                var folderConfig = new FolderConfig
                {
                    FolderPath       = stream.Name.GetDirectoryPath(),
                    WatchHiddenFiles = false
                };

                var op = new CreateOperationEvent
                {
                    FilePath   = stream.Name,
                    RaisedTime = new DateTime(2017, 11, 27)
                };

                Assert.AreEqual(true, folderConfig.IsValid(op));
            }
            finally
            {
                stream.Close();
                File.Delete(path);
            }
        }
コード例 #3
0
        public void FilteredFilesTester2()
        {
            string path   = $"SomeTempFile.txt";
            var    stream = File.Create(path);

            try
            {
                var folderConfig = new FolderConfig
                {
                    FolderPath       = stream.Name.GetDirectoryPath(),
                    WatchHiddenFiles = false,
                    FilteredFiles    = new List <string>()
                    {
                        $"{stream.Name.GetDirectoryPath()}SomeTempFile2.txt"
                    }
                };

                var op = new CreateOperationEvent
                {
                    FilePath   = stream.Name,
                    RaisedTime = new DateTime(2017, 11, 27)
                };

                Assert.AreEqual(true, folderConfig.IsValid(op));
            }
            finally
            {
                stream.Close();
                File.Delete(path);
            }
        }
コード例 #4
0
        public void JsonLogFileNameTester2()
        {
            string path   = $"SomeDateTime - {Constants.JsonLogFileName}";
            var    stream = File.Create(path);

            try
            {
                var folderConfig = new FolderConfig
                {
                    FolderPath       = stream.Name.GetDirectoryPath(),
                    WatchHiddenFiles = false
                };

                var op = new CreateOperationEvent
                {
                    FilePath   = stream.Name,
                    RaisedTime = new DateTime(2017, 11, 27)
                };

                Assert.AreEqual(
                    !FolderConfig.IsLogFile(op.FilePath,
                                            Path.GetFullPath($"{folderConfig.FolderPath}/{Constants.JsonLogFileName}")),
                    folderConfig.IsValid(op, jsonLogFileName: Constants.JsonLogFileName));
            }
            finally
            {
                stream.Close();
                File.Delete(path);
            }
        }
        public void LogOperation <Operation>(Operation operation) where Operation : OperationEvent
        {
            if (!folderConfig.IsValid(operation))
            {
                return;
            }

            //This is not responsibility of this operation. It needs abstraction
            var content = new ToastContent()
            {
                Launch = "app-defined-string",
                Visual = new ToastVisual()
                {
                    BindingGeneric = new ToastBindingGeneric()
                    {
                        Children =
                        {
                            new AdaptiveText()
                            {
                                Text = $"Action:  {operation.EventType.ToString()}"
                            },
                            new AdaptiveText()
                            {
                                Text = $"Action: {operation.EventType.ToString()}{Environment.NewLine}FileName: {operation.FileName}"
                            },
                            new AdaptiveImage()
                            {
                                Source = @"C:\Windows\WinSxS\amd64_microsoft-windows-t..nbackgrounds-client_31bf3856ad364e35_10.0.17134.1_none_c2974feb629c22da\img100.jpg"
                            }
                        },
                        AppLogoOverride = new ToastGenericAppLogo()
                        {
                            Source   = @"C:\Windows\WinSxS\amd64_microsoft-windows-shell-wallpaper-theme2_31bf3856ad364e35_10.0.17134.1_none_bc5a789c0e1871e3\img8.jpg",
                            HintCrop = ToastGenericAppLogoCrop.Circle
                        }
                    }
                },
                DisplayTimestamp = operation.RaisedTime
            };

            // Display toast
            var doc = new XmlDocument();

            doc.LoadXml(content.GetContent());

            ToastNotificationManager.CreateToastNotifier(applicationID).Show(new ToastNotification(doc));
        }