예제 #1
0
        public ConfigurationModule()
            : base("/configuration")
        {
            Get["/"] = x =>
                           {
                               var agentWatchList = Container().GetType<IAgentWatchList>();
                               var agentSettings = Container().GetType<IAgentSettings>();

                               var configurationViewModel = new ConfigurationViewModel()
                                                                {
                                                                    WatchList = agentWatchList,
                                                                    Settings = agentSettings
                                                                };

                               return this.ViewOrJson("configuration/index.cshtml", configurationViewModel);
                           };

            Get["/watchList"] = x =>
                                 {
                                     var agentWatchListManager = Container().GetType<IAgentWatchListManager>();
                                     var watchList = agentWatchListManager.Build();
                                     var watchSample = new AgentWatchList()
                                                           {
                                                               Groups = new List<string>(new[] { "Web", "Services" }),
                                                               Packages = new List<WatchPackage>(new[]
                                                                   {
                                                                       new WatchPackage(){Name="package1"},
                                                                       new WatchPackage(){ Name="package2"}
                                                                   })
                                                           };
                                     var serializer = new XmlSerializer(typeof (AgentWatchList));
                                     StringBuilder sb = new StringBuilder();
                                     using (var writer = XmlWriter.Create(sb))
                                     {
                                         serializer.Serialize(writer, watchSample);
                                         writer.Flush();
                                     }

                                     return new TextResponse(sb.ToString(), "text/xml");
                                 };

            Put["/watchList"] = x =>
                                    {
                                        var agentWatchListManager = Container().GetType<IAgentWatchListManager>();
                                        using (var streamReader = new StreamReader(Request.Body))
                                        {
                                            try
                                            {
                                                agentWatchListManager.SaveWatchList(streamReader.ReadToEnd());
                                            } catch (Exception ex)
                                            {
                                                return new TextResponse(HttpStatusCode.BadRequest, ex.Message);
                                            }
                                        }

                                        return new HeadResponse(new Response(){StatusCode = HttpStatusCode.Accepted});
                                    };
        }
예제 #2
0
 public IAgentWatchList Build()
 {
     if (_watchList == null)
     {
         lock (_fileLock)
         {
             using (var fs = new FileStream("~\\watchList.config".MapVirtualPath(), FileMode.Open))
             {
                 _watchList = (AgentWatchList) new XmlSerializer(typeof (AgentWatchList)).Deserialize(fs);
             }
         }
     }
     return _watchList;
 }
 public void SetUp()
 {
     var agentWatchList = new AgentWatchList() {Groups = new List<string>() {"Web", "Backoffice", "Reporting"}};
     var agentWatchListManager = new Mock<IAgentWatchListManager>();
     agentWatchListManager.Setup(m => m.Build()).Returns(agentWatchList);
     _configurationDefaults = new Mock<IConfigurationDefaults>();
     _configurationDefaults.SetupGet(c => c.AgentConfigurationFile).Returns(Guid.NewGuid().ToString());
     _configurationDefaults.SetupGet(c => c.AgentConfigurationFileLocation).Returns(Environment.CurrentDirectory);
     _fileName = Guid.NewGuid().ToString();
     File.WriteAllText(_fileName, CONFIG_FILE);
     _mgr = new AgentConfigurationManager(_logger.Object, agentWatchListManager.Object, _configurationDefaults.Object);
 }