Exemplo n.º 1
0
 public IActionResult Container(string Id)
 {
     if (string.IsNullOrEmpty(Id))
     {
         return(RedirectToAction("Index"));
     }
     try
     {
         var container = _containerService.GetContainer(Id);
         return(View(container));
     }
     catch (Exception ex)
     {
         return(RedirectToAction("Index"));
     }
 }
Exemplo n.º 2
0
        /*public void Tick(PerformContext hangfireContext)
         * {
         *  Task.Run(async () =>
         *  {
         *      try
         *      {
         *          hangfireContext.WriteLine("Starting to check.");
         *          var containers = await _containerService.CheckAsync();
         *          bool anyUpdate = false;
         *
         *          foreach (var container in containers)
         *          {
         *              hangfireContext.WriteLine($"{container.Name} {container.Folder}");
         *              var probes = container.CheckForProbes();
         *
         *              hangfireContext.WriteLine($"{container.Name} is updating..");
         *
         *              var provider = _providerFactory.GetProvider(container.Repository.Provider);
         *
         *              var fileList = container.Update(provider);
         *
         *              if (fileList.Count() > 0)
         *              {
         *                  container.Repository.UpdatedTime = DateTime.Now;
         *                  anyUpdate = true;
         *
         *                  foreach (var item in fileList)
         *                  {
         *                      hangfireContext.WriteLine($"{container.Name} {item} file updated.");
         *                  }
         *
         *                  hangfireContext.WriteLine($"{container.Name} is updated.");
         *
         *                  var activatedProbes = probes.Where(i => fileList.Contains(i.Object.Path));
         *
         *                  foreach (var item in activatedProbes)
         *                  {
         *                      hangfireContext.WriteLine($"{item.Object.Path} file's probe is activated.");
         *                      _jobClient.Enqueue<ProbeControl>(i => i.Execute(null, item.Id, container.Repository.Id));
         *                      //BackgroundJob.Enqueue<ProbeControl>(i => i.Execute(null, item.Id, container.Repository.Id));
         *                  }
         *              }
         *              else
         *              {
         *                  hangfireContext.WriteLine($"{container.Name} no new changes.");
         *              }
         *          }
         *
         *          if (anyUpdate)
         *          {
         *              await _context.SaveChangesAsync();
         *          }
         *
         *          hangfireContext.WriteLine($"Total found containers {containers.Count()}.");
         *
         *          hangfireContext.WriteLine("End of check.");
         *      }
         *      catch (Exception ex)
         *      {
         *          hangfireContext.WriteLine(ConsoleTextColor.Red, ex);
         *      }
         *
         *
         *  });
         *
         * }*/

        public void Trigger(PerformContext hangfireContext, string repoName, string owner, List <string> modified)
        {
            var repo = _context.Repositories.FirstOrDefault(i => i.Name.Equals(repoName) && i.OwnerName.Equals(owner));

            if (repo != null)
            {
                var container = _containerService.GetContainer(repo);

                var probes = container.CheckForProbes();

                var provider = _providerFactory.GetProvider(repo.Provider);

                container.Update(provider);

                foreach (var probe in probes)
                {
                    if (modified.Contains(probe.Object.Path))
                    {
                        hangfireContext?.WriteLine($"{probe.Object.Path} file's probe is activated.");
                        _jobClient.Enqueue <ProbeControl>(i => i.Execute(null, probe.Id, repo.Id));
                        //BackgroundJob.Enqueue<ProbeControl>(i => i.Execute(null, probe.Id, container.Repository.Id));
                    }
                }
            }
        }
Exemplo n.º 3
0
        /*public void Execute(PerformContext hangfireContext, Container container)
         * {
         *  if (!container.IsTriggrProject())
         *      return;
         *
         *  var probes = container.CheckForProbes();
         *  hangfireContext.WriteLine($"Executing ProbeControl");
         *
         *  var codeChangeProbes = probes.Where(i => i.ProbeType == ProbeType.CodeChanges).ToList();
         *
         *  var oldFiles = new Dictionary<Probe, string>();
         *  if (codeChangeProbes.Count > 0)
         *  {
         *      foreach (var probe in codeChangeProbes)
         *      {
         *          var tempFile = Path.GetTempFileName();
         *
         *          var objectPath = Path.Combine(container.Folder, probe.Object.Path);
         *          if (File.Exists(objectPath))
         *          {
         *              hangfireContext.WriteLine($"Probe {probe.Object.Path}");
         *
         *              File.Copy(objectPath, tempFile, true);
         *
         *              oldFiles.Add(probe, tempFile);
         *          }
         *      }
         *  }
         *
         *  var provider = _providerFactory.GetProvider(container.Repository.Provider);
         *  var updatedPath = provider.Update(container.Repository);
         *
         *  if (!string.IsNullOrEmpty(updatedPath))
         *  {
         *      foreach (var probe in probes)
         *      {
         *          if (probe.ProbeType == ProbeType.CodeChanges)
         *          {
         *              var tempFile = oldFiles[probe];
         *              var objectPath = Path.Combine(container.Folder, probe.Object.Path);
         *              var language = _languageService.Define(probe.Object.Path);
         *
         *              var result = _scriptExecutor.Execute(probe.ProbeType, language.FolderName,
         *                              objectPath, tempFile, probe.Object.Type, probe.Object.Name);
         *
         *              hangfireContext.WriteLine($"Result of comparision {result}");
         *
         *              // it will changed with executing shell script
         *          }
         *      }
         *  }
         *  hangfireContext.WriteLine($"Finished ProbeControl");
         *
         * }
         */
        public void Execute(PerformContext hangfireContext, string probeId, string repoId)
        {
            var repository = _dbContext.Repositories.Find(repoId); // get the repository

            if (repository != null)
            {
                var container = _containerService.GetContainer(repoId); // get the container

                // get all probes and look for probeId
                var probes = container.CheckForProbes();
                var probe  = probes.FirstOrDefault(i => i.Id.Equals(probeId));

                if (probe != null)
                {
                    hangfireContext?.WriteLine(ConsoleTextColor.Gray, $"{probe.Object.Path} is found.");
                    // define the language
                    var language = _languageService.Define(probe.Object.Path);
                    // get the provider
                    var provider = _providerFactory.GetProvider(repository.Provider);
                    // restore to previous file
                    if (provider.Restore(repository, probe.Object.Path, true))
                    {
                        hangfireContext?.WriteLine(ConsoleTextColor.Gray, $"{probe.Object.Path} is restored to old.");
                        // get the file path
                        var objectPath = Path.Combine(container.Folder, probe.Object.Path);

                        // look for the object
                        var ast1 = _scriptExecutor.Execute("AST", language.FolderName, objectPath, probe.Object.Type, probe.Object.Name);

                        hangfireContext?.WriteLine(ConsoleTextColor.Gray, $"{probe.Object.Path} old version is loaded.");

                        var temp1 = WriteToTemp(ast1);

                        // restore to original file
                        if (provider.Restore(repository, probe.Object.Path, false))
                        {
                            // look for the object
                            var ast2 = _scriptExecutor.Execute("AST", language.FolderName, objectPath, probe.Object.Type, probe.Object.Name);

                            var temp2 = WriteToTemp(ast2);

                            hangfireContext?.WriteLine(ConsoleTextColor.Gray, $"{probe.Object.Path} new version is loaded.");

                            Control(hangfireContext, probe, repository, temp1, temp2, language.FolderName);
                        }
                    }
                }
            }
        }