public FileLogEntryController(Invoker dispatcher = null, Func <string, LogEntryParser, ILogFileWatcher <LogEntry> > createLogFileWatcher = null, IPersist persist = null) { Entries = new ObservableCollection <LogEntryViewModel>(); this.watcherFactory = createLogFileWatcher ?? CreateLogFileWatcher; wrappedDispatcher = dispatcher ?? new WrappedDispatcher().Invoke; Counter = new LogEntryCounter(Entries); this.recentFileList = new RecentFileList(persist ?? new XmlPersister(ApplicationAttributes.Get(), 9)); }
public RegistryPersister(ApplicationAttributes attr) { this.attr = attr; RegistryKey = "Software\\" + attr.CompanyName + "\\" + attr.ProductName + "\\" + "RecentFileList"; }
public XmlPersister(ApplicationAttributes attr, int max) { _max = max; Filepath = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), attr.ProductName + "\\" + "RecentFileList.xml"); }
public XmlPersister(ApplicationAttributes attr) { this.attr = attr; Filepath = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), // ApplicationAttributes.CompanyName + "\\" + attr.ProductName + "\\" + "RecentFileList.xml"); }
public void Application() { string dummyString; bool dummyBool; int dummyInt; Service service = Connect(); ApplicationCollection apps = service.GetApplicationsAsync().Result; foreach (Application app in apps) { try { ApplicationSetupInfo applicationSetup = app.GetSetupInfoAsync().Result; //string setupXml = applicationSetup.SetupXml; } catch (Exception) { // silent exception, if setup doesn't exist, exception occurs } ApplicationArchiveInfo applicationArchive = app.PackageAsync().Result; dummyString = app.Author; dummyBool = app.CheckForUpdates; dummyString = app.Description; dummyString = app.Label; dummyBool = app.Refresh; dummyString = app.Version; dummyBool = app.Configured; if (this.VersionCompare(service, "5.0") < 0) { //dummyBool = app.IsManageable; } dummyBool = app.Visible; dummyBool = app.StateChangeRequiresRestart; ApplicationUpdateInfo applicationUpdate = app.GetUpdateInfoAsync().Result; //dummyString = applicationUpdate.Checksum; //dummyString = applicationUpdate.ChecksumType; //dummyString = applicationUpdate.Homepage; //dummyInt = applicationUpdate.UpdateSize; //dummyString = applicationUpdate.UpdateName; //dummyString = applicationUpdate.AppUrl; //dummyString = applicationUpdate.Version; //dummyBool = applicationUpdate.IsImplicitIdRequired; } if (apps.Any(a => a.Name == "sdk-tests")) { service = this.CleanApp("sdk-tests", service); } apps = service.GetApplicationsAsync().Result; Assert.False(apps.Any(a => a.Name == "sdk-tests"), assertRoot + "#1"); ApplicationAttributes createArgs = new ApplicationAttributes(); createArgs.ApplicationAuthor = "me"; if (this.VersionCompare(service, "4.2.4") >= 0) { createArgs.Configured = false; } createArgs.Description = "this is a description"; createArgs.Label = "SDKTEST"; if (this.VersionCompare(service, "5.0") < 0) { //createArgs.manageable", false); } //createArgs.template", "barebones"); createArgs.Visible = false; service.CreateApplicationAsync("sdk-tests", "barebones", createArgs).Wait(); apps.GetAsync().Wait(); Assert.True(apps.Any(a => a.Name == "sdk-tests"), assertRoot + "#2"); Application app2 = service.GetApplicationAsync("sdk-tests").Result; dummyBool = app2.CheckForUpdates; Assert.Equal("SDKTEST", app2.Label); Assert.Equal("me", app2.ApplicationAuthor); Assert.False(app2.Configured, assertRoot + "#5"); if (this.VersionCompare(service, "5.0") < 0) { //Assert.False(app2.Manageable, assertRoot + "#6"); } Assert.False(app2.Visible, assertRoot + "#7"); // update the app ApplicationAttributes attr = new ApplicationAttributes(); attr.ApplicationAuthor = "not me"; attr.Description = "new description"; attr.Label = "new label"; attr.Visible = false; if (this.VersionCompare(service, "5.0") < 0) { //app2.IsManageable = false; } //attr.Version = "5.0.0"; app2.UpdateAsync(attr, true).Wait(); app2.GetAsync().Wait(); // check to see if args took. Assert.Equal("not me", app2.ApplicationAuthor); Assert.Equal("new description", app2.Description); Assert.Equal("new label", app2.Label); Assert.False(app2.Visible, assertRoot + "#11"); //Assert.Equal("5.0.0", app2.Version); // archive (package) the application ApplicationArchiveInfo appArchive = app2.PackageAsync().Result; Assert.True(appArchive.ApplicationName.Length > 0, assertRoot + "#13"); Assert.True(appArchive.Path.Length > 0, assertRoot + "#14"); Assert.True(appArchive.Uri.AbsolutePath.Length > 0, assertRoot + "#15"); ApplicationUpdateInfo appUpdate = app2.GetUpdateInfoAsync().Result; //ApplicationUpdate appUpdate = app2.AppUpdate(); //Assert.True(appUpdate.ContainsKey("eai:acl"), assertRoot + "#16"); service = this.CleanApp("sdk-tests", service); apps = service.GetApplicationsAsync().Result; Assert.False(apps.Any(a => a.Name == "sdk-tests"), assertRoot + "#17"); }
/// <summary> /// Asynchronously updates the attributes of an <see cref="Application"/>. /// </summary> /// <param name="name"> /// Name of the application to update. /// </param> /// <param name="attributes"> /// New attributes for the application identified by <see cref= /// "name"/>. /// </param> /// <returns> /// An object representing the application that was updated. /// </returns> /// <remarks> /// This method uses the <a href="http://goo.gl/SzKzNX">POST /// apps/local/{name}</a> endpoint to update the <see cref= /// "Application"/> object identified by <see cref="name"/>. /// </remarks> public async Task<Application> UpdateApplicationAsync(string name, ApplicationAttributes attributes) { var resource = new Application(this.Context, this.Namespace, name); await resource.RemoveAsync(); return resource; }
/// <summary> /// Asynchronously creates an application from an application template. /// </summary> /// <param name="name"> /// Name of the application to create. /// </param> /// <returns> /// An object representing the application created. /// </returns> /// <remarks> /// This method uses the <a href="http://goo.gl/SzKzNX">POST /// apps/local</a> endpoint to construct the <see cref= /// "Application"/> object it returns. /// </remarks> public async Task<Application> CreateApplicationAsync(string name, string template, ApplicationAttributes attributes = null) { var resource = new Application(this.Context, this.Namespace, name); await resource.CreateAsync(template, attributes); return resource; }
public async Task CanCrudApplication() { using (var service = await SdkHelper.CreateService()) { //// Install, update, and remove the Splunk App for Twitter Data, version 2.3.1 var twitterApp = await service.Applications.GetOrNullAsync("twitter2"); if (twitterApp != null) { await twitterApp.RemoveAsync(); await SdkHelper.ThrowsAsync<ResourceNotFoundException>(async () => { await twitterApp.GetAsync(); }); twitterApp = await service.Applications.GetOrNullAsync("twitter2"); Assert.Null(twitterApp); } IPHostEntry splunkHostEntry = await Dns.GetHostEntryAsync(service.Context.Host); IPHostEntry localHostEntry = await Dns.GetHostEntryAsync("localhost"); if (splunkHostEntry.HostName == localHostEntry.HostName) { var path = Path.Combine(Environment.CurrentDirectory, "Data", "app-for-twitter-data_230.spl"); Assert.True(File.Exists(path)); twitterApp = await service.Applications.InstallAsync(path, update: true); //// Other asserts on the contents of the update Assert.Equal("Splunk", twitterApp.ApplicationAuthor); Assert.Equal(true, twitterApp.CheckForUpdates); Assert.Equal(false, twitterApp.Configured); Assert.Equal("This application indexes Twitter's sample stream.", twitterApp.Description); Assert.Equal("Splunk-Twitter Connector", twitterApp.Label); Assert.Equal(false, twitterApp.Refresh); Assert.Equal(false, twitterApp.StateChangeRequiresRestart); Assert.Equal("2.3.0", twitterApp.Version); Assert.Equal(true, twitterApp.Visible); //// TODO: Check ApplicationSetupInfo and ApplicationUpdateInfo //// We might check that there is no update info for 2.3.1: //// Assert.Null(twitterApplicationUpdateInfo.Update); //// Then change the version number to 2.3.0: //// await twitterApplication.UpdateAsync(new ApplicationAttributes() { Version = "2.3.0" }); //// Finally: //// ApplicationUpdateInfo twitterApplicationUpdateInfo = await twitterApplication.GetUpdateInfoAsync(); //// Assert.NotNull(twitterApplicationUpdateInfo.Update); //// Assert.True(string.Compare(twitterApplicationUpdateInfo.Update.Version, "2.3.0") == 1, "expect the newer twitter app info"); //// Assert.Equal("41ceb202053794cfec54b8d28f78d83c", twitterApplicationUpdateInfo.Update.Checksum); var setupInfo = await twitterApp.GetSetupInfoAsync(); var updateInfo = await twitterApp.GetUpdateInfoAsync(); await twitterApp.RemoveAsync(); try { await twitterApp.GetAsync(); Assert.False(true, "Expected ResourceNotFoundException"); } catch (ResourceNotFoundException) { } twitterApp = await service.Applications.GetOrNullAsync("twitter2"); Assert.Null(twitterApp); } //// Create an app from one of the built-in templates var name = MockContext.GetOrElse(string.Format("delete-me-{0}", Guid.NewGuid())); var creationAttributes = new ApplicationAttributes() { ApplicationAuthor = "Splunk", Configured = true, Description = "This app confirms that an app can be created from a template", Label = name, Version = "2.0.0", Visible = true }; var templatedApp = await service.Applications.CreateAsync(name, "barebones", creationAttributes); Assert.Equal(creationAttributes.ApplicationAuthor, templatedApp.ApplicationAuthor); Assert.Equal(true, templatedApp.CheckForUpdates); Assert.Equal(creationAttributes.Configured, templatedApp.Configured); Assert.Equal(creationAttributes.Description, templatedApp.Description); Assert.Equal(creationAttributes.Label, templatedApp.Label); Assert.Equal(false, templatedApp.Refresh); Assert.Equal(false, templatedApp.StateChangeRequiresRestart); Assert.Equal(creationAttributes.Version, templatedApp.Version); Assert.Equal(creationAttributes.Visible, templatedApp.Visible); var updateAttributes = new ApplicationAttributes() { ApplicationAuthor = "Splunk, Inc.", Configured = true, Description = "This app update confirms that an app can be updated from a template", Label = name, Version = "2.0.1", Visible = true }; bool updatedSnapshot = await templatedApp.UpdateAsync(updateAttributes, checkForUpdates: true); Assert.True(updatedSnapshot); await templatedApp.GetAsync(); // Because UpdateAsync doesn't produce an updated snapshot Assert.Equal(updateAttributes.ApplicationAuthor, templatedApp.ApplicationAuthor); Assert.Equal(true, templatedApp.CheckForUpdates); Assert.Equal(updateAttributes.Configured, templatedApp.Configured); Assert.Equal(updateAttributes.Description, templatedApp.Description); Assert.Equal(updateAttributes.Label, templatedApp.Label); Assert.Equal(false, templatedApp.Refresh); Assert.Equal(false, templatedApp.StateChangeRequiresRestart); Assert.Equal(updateAttributes.Version, templatedApp.Version); Assert.Equal(updateAttributes.Visible, templatedApp.Visible); Assert.False(templatedApp.Disabled); await templatedApp.DisableAsync(); await templatedApp.GetAsync(); // Because POST apps/local/{name} does not return an updated snapshot Assert.True(templatedApp.Disabled); await templatedApp.EnableAsync(); await templatedApp.GetAsync(); // Because POST apps/local/{name} does not return an updated snapshot Assert.False(templatedApp.Disabled); var archiveInfo = await templatedApp.PackageAsync(); await templatedApp.RemoveAsync(); try { await templatedApp.GetAsync(); Assert.False(true, "Expected ResourceNotFoundException"); } catch (ResourceNotFoundException) { } // On Windows, this fails with a permissions error. At some point investigate and reinstate. /* if (splunkHostEntry.HostName == localHostEntry.HostName) { File.Delete(archiveInfo.Path); } */ templatedApp = await service.Applications.GetOrNullAsync(templatedApp.Name); Assert.Null(templatedApp); } }
public async Task Application() { using (var service = await SdkHelper.CreateService()) { ApplicationCollection apps = service.Applications; await apps.GetAllAsync(); foreach (Application app in apps) { await CheckApplication(app); } for (int i = 0; i < apps.Count; i++) { await CheckApplication(apps[i]); } if (await service.Applications.RemoveAsync("sdk-tests")) { await service.Server.RestartAsync(2 * 60 * 1000); await service.LogOnAsync(); } ApplicationAttributes attributes = new ApplicationAttributes { ApplicationAuthor = "me", Description = "this is a description", Label = "SDKTEST", Visible = false }; var testApp = await service.Applications.CreateAsync("sdk-tests", "barebones", attributes); testApp = await service.Applications.GetAsync("sdk-tests"); Assert.Equal("SDKTEST", testApp.Label); Assert.Equal("me", testApp.ApplicationAuthor); Assert.Equal("nobody", testApp.Author); Assert.False(testApp.Configured); Assert.False(testApp.Visible); Assert.DoesNotThrow(() => { bool p = testApp.CheckForUpdates; }); attributes = new ApplicationAttributes { ApplicationAuthor = "not me", Description = "new description", Label = "new label", Visible = false, Version = "1.5" }; //// Update the application await testApp.UpdateAsync(attributes, true); await testApp.GetAsync(); Assert.Equal("not me", testApp.ApplicationAuthor); Assert.Equal("nobody", testApp.Author); Assert.Equal("new description", testApp.Description); Assert.Equal("new label", testApp.Label); Assert.Equal("1.5", testApp.Version); Assert.False(testApp.Visible); ApplicationUpdateInfo updateInfo = await testApp.GetUpdateInfoAsync(); Assert.NotNull(updateInfo.Eai.Acl); //// Package the application ApplicationArchiveInfo archiveInfo = await testApp.PackageAsync(); Assert.Equal("Package", archiveInfo.Title); Assert.NotEqual(DateTime.MinValue, archiveInfo.Updated); Assert.DoesNotThrow(() => { string p = archiveInfo.ApplicationName; }); Assert.True(archiveInfo.ApplicationName.Length > 0); Assert.DoesNotThrow(() => { Eai p = archiveInfo.Eai; }); Assert.NotNull(archiveInfo.Eai); Assert.NotNull(archiveInfo.Eai.Acl); Assert.DoesNotThrow(() => { string p = archiveInfo.Path; }); Assert.True(archiveInfo.Path.Length > 0); Assert.DoesNotThrow(() => { bool p = archiveInfo.Refresh; }); Assert.DoesNotThrow(() => { Uri p = archiveInfo.Uri; }); Assert.True(archiveInfo.Uri.AbsolutePath.Length > 0); Assert.True(await service.Applications.RemoveAsync("sdk-tests")); await service.Server.RestartAsync(2 * 60 * 1000); } }
/// <summary> /// Asynchronously updates the attributes of the application represented by /// the current instance. /// </summary> /// <param name="attributes"> /// New attributes for the current <see cref="Application"/> instance. /// </param> /// <param name="checkForUpdates"> /// A value of <c>true</c>, if Splunk should check Splunkbase for updates to /// the current <see cref="Application"/> instance. /// </param> /// <returns> /// <c>true</c> if the <see cref="CurrentSnapshot"/> was also updated. /// </returns> /// <seealso cref="M:Splunk.Client.IApplication.UpdateAsync(ApplicationAttributes,bool)"/> public Task<bool> UpdateAsync(ApplicationAttributes attributes, bool checkForUpdates) { Contract.Requires<ArgumentNullException>(attributes != null); return default(Task<bool>); }