Beispiel #1
0
        static int runTermination(Logit log, string targetName, ContractEnum contractType, int maxTTL, int targetsProcessed)
        {
            log.Append("acquiring targets...", LogVerboseLevel.Normal);
            List <Target> targets = new List <Target>();

            try
            {
                targets = acquireTargets(targetName, log);
            }
            catch (Exception ex)
            {
                log.Append("Error acquiring targets: " + ex.Message, LogVerboseLevel.Normal);
            }
            if (targets.Count > 0)
            {
                log.Append("targets acquired: " + targets.Count + "  processing targets...", LogVerboseLevel.Normal);
                foreach (Target target in targets)
                {
                    if (processTarget(target, contractType, maxTTL, log))
                    {
                        targetsProcessed++;
                    }
                }
            }
            return(targetsProcessed);
        }
Beispiel #2
0
 public static void RunTopLevelTasks(int currentMinute, CancellationToken token)
 {
     List<EntityServer> servers = null;
     try
     {
         token.ThrowIfCancellationRequested();
         servers = DbRepo.ListServersByMinute(currentMinute);
         Logit.LogInformation("Processing " + servers.Count.ToString() + " servers...");
     }
     catch (Exception exc)
     {
         var errMsg = "Dispatcher Error: " + exc.Message;
         if (exc.InnerException != null)
         {
             errMsg += "-- " + exc.InnerException.Message;
         }
         Logit.LogError(new ApplicationException(errMsg));
     }
     try
     {
         token.ThrowIfCancellationRequested();
         var processor = new TaskProcessor();
         var topLevelTasks = processor.GenerateTopLevelTasks(servers, token);
         Parallel.ForEach(topLevelTasks, topLevelResult =>
         {
         });
         Task.WaitAll(topLevelTasks.ToArray()); //needed to catch aggregate exceptions
     }
     catch (Exception exc)
     {
         Logit.LogError(exc);
     }
 }
Beispiel #3
0
            public void LogitTest()
            {
                var actual   = new Matrix(4, 1);
                var expected = new Matrix(4, 1);

                actual.InRandomize();
                expected.InRandomize();

                var autoErr = new Logit().Evaluate(actual, expected);
                var error   = 0.0;

                for (var i = 0; i < actual.Rows; i++)
                {
                    for (var j = 0; j < actual.Columns; j++)
                    {
                        error += Math.Log(1.0 + Math.Exp(actual[i, j] * -expected[i, j]));
                    }
                }
                error /= actual.Rows * actual.Columns;
                Assert.IsTrue(Math.Abs(error - autoErr) < 0.01, new Logit().Type().ToString() + " Forward!");

                var autoDErr = new Logit().Backward(actual, expected);
                var dErr     = new Matrix(actual.Rows, actual.Columns);

                for (var i = 0; i < actual.Rows; i++)
                {
                    for (var j = 0; j < actual.Columns; j++)
                    {
                        dErr[i, j] = -1.0 / (1.0 + Math.Exp(actual[i, j] * expected[i, j]));
                    }
                }
                Assert.IsTrue(Math.Abs(dErr.FrobeniusNorm() - autoDErr.FrobeniusNorm()) < 0.01, new Logit().Type().ToString() + "  Backward!");
            }
        /// <summary>
        /// GENERATE IMAGE TASKS
        /// Given a list of raw camera images, generate a list of associated published images.
        /// </summary>
        /// <param name="gatherResult"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public List <Task> GenerateImageTasks(GatherResult gatherResult, CancellationToken token)
        {
            var processor = new ImageProcessor();
            var pubImages = DbRepo.ListPubImages(gatherResult);
            var items     = new List <Task>();

            foreach (var pubImage in pubImages)
            {
                items.Add(Task <GenerateImageResult> .Factory.StartNew(()
                                                                       => processor.GeneratePubImage(pubImage), token, TaskCreationOptions.LongRunning, TaskScheduler.Default)
                          .ContinueWith(taskInfo =>
                {
                    try
                    {
                        token.ThrowIfCancellationRequested();
                        var pubImageResult = (GenerateImageResult)taskInfo.Result;
                        Logit.LogGenerateImageResult(pubImageResult);
                        var publishTasks = GeneratePublishTasks(pubImageResult, token);
                        Parallel.ForEach(publishTasks, publishResult =>
                        {
                        });
                        Task.WaitAll(publishTasks.ToArray());
                    }
                    catch (Exception exc)
                    {
                        Logit.LogError(exc);
                    }
                })
                          );
            }
            return(items);
        }
Beispiel #5
0
        static List <Target> acquireTargets(string name, Logit log)
        {
            List <Target> targets  = new List <Target>();
            List <Target> allprocs = GetActiveProcessList(log);

            foreach (Target proc in allprocs)
            {
                log.Append("evaluating: " + proc.Name, LogVerboseLevel.Debug);
                if (proc.Name.ToLower() == name.ToLower())
                {
                    try
                    {
                        Target target = new Target();
                        target.Name          = proc.Name;
                        target.Path          = proc.Path;
                        target.StartTime     = proc.StartTime;
                        target.DiscoveryTime = DateTime.Now;
                        target.PID           = proc.PID;
                        targets.Add(target);
                    }
                    catch (Exception ex)
                    {
                        log.Append("Warning: could not evaluate potential target: " + proc.Name + "  error: " + ex.Message, LogVerboseLevel.Normal);
                    }
                }
            }
            return(targets);
        }
Beispiel #6
0
        private void UsfmToUsfxButton_Click(object sender, EventArgs e)
        {
            UsfmToUsfxButton.Enabled = false;
            Application.DoEvents();
            Utils.DeleteDirectory(UsfxPath);
            if (m_options.m_languageId.Length < 3)
            {
                return;
            }
            Utils.EnsureDirectory(UsfxPath);
            string logFile = Path.Combine(UsfxPath, "ConversionReports.txt");

            Logit.OpenFile(logFile);
            SFConverter.scripture = new Scriptures();
            Logit.loggedError     = false;

            // Read the input USFM files into internal data structures.
            SFConverter.ProcessFilespec(Path.Combine(UsfmPath, "*.usfm"), Encoding.UTF8);

            // Write out the USFX file.
            SFConverter.scripture.languageCode = m_options.m_languageId;
            SFConverter.scripture.WriteUSFX(Path.Combine(UsfxPath, "usfx.xml"));
            Logit.CloseFile();
            if (Logit.loggedError)
            {
                StreamReader log    = new StreamReader(logFile);
                string       errors = log.ReadToEnd();
                log.Close();
                MessageBox.Show(errors, "Errors in " + logFile);
            }
            UsfmToUsfxButton.Enabled = true;
            Application.DoEvents();
        }
Beispiel #7
0
        public void LogitPrimeTest()
        {
            var a = new Matrix(2, 2);

            a.InRandomize();
            var b = a.Duplicate();

            a = new Logit().Backward(a);
            b.InMap((x) => - 1 / Math.Pow(x, 2) - 1 / Math.Pow(1 - x, 2));
            Assert.IsTrue(Math.Abs(a.FrobeniusNorm() - b.FrobeniusNorm()) < 0.1,
                          new Logit().Type().ToString() + " Derivative.");
        }
Beispiel #8
0
        public void LogitTest()
        {
            var a = new Matrix(2, 2);

            a.InRandomize();
            var b = a.Duplicate();

            a = new Logit().Forward(a);
            b.InMap((x) => Math.Log(x / (1 - x)));
            Assert.IsTrue(Math.Abs(a.FrobeniusNorm() - b.FrobeniusNorm()) < 0.1,
                          new Logit().Type().ToString() + " Activation.");
        }
Beispiel #9
0
        static int pullTTLFromArgs(string[] args, Logit log)
        {
            int ttl = 0;

            foreach (string arg in args)
            {
                if (arg.ToLower().StartsWith("ttl="))
                {
                    ttl = Convert.ToInt32(arg.Split(new char[] { '=' })[1]);
                    break;
                }
            }
            return(ttl);
        }
        /// <summary>
        /// GENERATE PUBLISH TASKS
        /// Given a published image, send it to all associated destinations.
        /// </summary>
        /// <param name="imageResult"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public List <Task> GeneratePublishTasks(GenerateImageResult imageResult, CancellationToken token)
        {
            var processor    = new PublishProcessor();
            var destinations = DbRepo.ListDestinations(imageResult);
            var items        = new List <Task>();

            foreach (var dest in destinations)
            {
                items.Add(Task <PublishResult> .Factory.StartNew(() => processor.Publish(dest), token, TaskCreationOptions.LongRunning, TaskScheduler.Default)
                          .ContinueWith(taskInfo => Logit.LogPublishResult(taskInfo.Result))
                          );
            }
            return(items);
        }
Beispiel #11
0
        static List <Target> GetActiveProcessList(Logit log)
        {
            List <Target>            activeList = new List <Target>();
            WqlObjectQuery           w          = new WqlObjectQuery("Select * from Win32_Process");
            ManagementObjectSearcher mos        = new ManagementObjectSearcher(w);

            foreach (ManagementObject mo in mos.Get())
            {
                try
                {
                    Target po = new Target();
                    po.PID = Convert.ToInt32(mo.Properties["ProcessID"].Value.ToString());
                    try
                    {
                        po.StartTime = convertFromWmiToDotNetDateTime(mo.Properties["CreationDate"].Value.ToString());
                    }
                    catch { }
                    string pathName = "NA";
                    if (po.PID == 0)
                    {
                        pathName = "System Idle Process";
                    }
                    else if (po.PID == 4)
                    {
                        pathName = "System";
                    }
                    else
                    {
                        try
                        {
                            pathName = mo.Properties["ExecutablePath"].Value.ToString();
                        }
                        catch
                        {
                            pathName = mo.Properties["Caption"].Value.ToString();  // can fail when attempting to get extended process info on protected processes, until i do, we use the process name as path
                        }
                    }
                    po.Name = mo.Properties["Caption"].Value.ToString().ToLower();
                    po.Path = pathName.ToLower();
                    activeList.Add(po);
                }
                catch (Exception ex)
                {
                    log.Append("Warning:  could not get details on process: " + mo.Path, LogVerboseLevel.Normal);
                }
            }
            return(activeList);
        }
Beispiel #12
0
        /// <summary>
        /// MAIN
        /// </summary>
        /// <param name="args"></param>
        public static void Main(string[] args)
        {
            var startTime    = DateTime.Now;
            var _tokenSource = new CancellationTokenSource();

            Logit.LogInformation("CssDirector starting...");
            CssDispatcher.RunTopLevelTasks(DateTime.Now.Minute, _tokenSource.Token);
            var elapsedTime = String.Format("{0:0.0}", (DateTime.Now - startTime).TotalMilliseconds / 1000);

            Logit.LogInformation("CssDirector finished in " + elapsedTime + " seconds.");
            Console.Write("Type any key to pause...");
            if (ConsoleReadPauseWithTimeout(3))
            {
                Console.Write("\nType any key to exit...");
                Console.ReadKey();
            }
        }
Beispiel #13
0
        static ContractEnum pullContractFromArgs(string[] args, Logit log)
        {
            ContractEnum hitType = ContractEnum.Tag;

            foreach (string arg in args)
            {
                if (arg.ToLower().StartsWith("contract="))
                {
                    if (arg.Split(new char[] { '=' })[1].ToUpper() == "KILL")
                    {
                        hitType = ContractEnum.Kill;
                        break;
                    }
                }
            }
            return(hitType);
        }
Beispiel #14
0
        static void Main(string[] args)
        {
            // diagnostics log, written to %TEMP% by default
            Logit log = new Logit();

            log.Verbosity = LogVerboseLevel.Normal;
            if (args.Contains("LOG=DEBUG"))
            {
                log.Verbosity = LogVerboseLevel.Debug;
            }
            log.Init();
            string       targetName       = "NA";
            int          maxTTL           = 0;
            ContractEnum contractType     = ContractEnum.Tag;
            int          targetsProcessed = 0;
            bool         proceed          = true;

            try
            {
                targetName   = pullTargetFromArgs(args, log);
                maxTTL       = pullTTLFromArgs(args, log);
                contractType = pullContractFromArgs(args, log);
                if (targetName == "NA" || maxTTL == 0)
                {
                    displayHelp();
                    proceed = false;
                }
            }
            catch (Exception ex)
            {
                log.Append("Error pulling command line parameters: " + ex.Message, LogVerboseLevel.Normal);
                proceed = false;
            }
            if (proceed)
            {
                log.Append("Terminate is starting", LogVerboseLevel.Normal);
                log.Append("     target app: " + targetName, LogVerboseLevel.Normal);
                log.Append("     max time to live (minutes): " + maxTTL, LogVerboseLevel.Normal);
                log.Append("     contract type: " + contractType, LogVerboseLevel.Normal);
                targetsProcessed = runTermination(log, targetName, contractType, maxTTL, targetsProcessed);
                log.Append("Total targets processed: " + targetsProcessed, LogVerboseLevel.Normal);
                log.Append("Terminate is complete.   Shutting down.", LogVerboseLevel.Normal);
            }
            quit(log);
        }
Beispiel #15
0
        static string pullTargetFromArgs(string[] args, Logit log)
        {
            string targetName = "NA";

            foreach (string arg in args)
            {
                if (arg.ToLower().StartsWith("target="))
                {
                    targetName = arg.Split(new char[] { '=' })[1].ToLower();
                    if (!targetName.EndsWith(".exe"))
                    {
                        targetName = targetName + ".exe";
                    }
                    break;
                }
            }
            return(targetName);
        }
Beispiel #16
0
        static bool processTarget(Target target, ContractEnum contract, int ttl, Logit log)
        {
            bool success = false;

            try
            {
                if (contract == ContractEnum.Kill && target.TargetAge > ttl)
                {
                    log.Append("Killing process: " + target.Name, LogVerboseLevel.Normal);
                    Process deadProcRunning = Process.GetProcessById(target.PID);
                    deadProcRunning.Kill();
                    log.Append("     done", LogVerboseLevel.Normal);
                    success = true;
                }
                else if (contract == ContractEnum.Tag && target.TargetAge > ttl)
                {
                    log.Append("tagging process: " + target.Name, LogVerboseLevel.Normal);
                    RegistryKey      ldKey  = Registry.LocalMachine.OpenSubKey("SOFTWARE\\LANDesk\\ManagementSuite\\WinClient");
                    string           ldPath = ldKey.GetValue("Path").ToString();
                    ProcessStartInfo psi    = new ProcessStartInfo();
                    psi.FileName         = ldPath + "\\miniscan.exe";
                    psi.Arguments        = "\"/send=Custom Data - Support - ProcessName = " + target.Name + "\"";
                    psi.WorkingDirectory = ldPath;
                    Process myProc = Process.Start(psi);
                    myProc.WaitForExit();
                    psi.Arguments = "\"/send=Custom Data - Support - ProcessAgeMinutes = " + target.TargetAge + "\"";
                    myProc        = Process.Start(psi);
                    myProc.WaitForExit();
                    log.Append("     done", LogVerboseLevel.Normal);
                    success = true;
                }
                else
                {
                    log.Append("Hit aborted.  target too young: " + target.TargetAge + " minutes, name: " + target.Name, LogVerboseLevel.Normal);
                }
            }
            catch (Exception ex)
            {
                log.Append("Error completing processing target: " + target.Name + "  error: " + ex.Message, LogVerboseLevel.Normal);
            }
            return(success);
        }
Beispiel #17
0
        public Layer(int nCount, int index, ActivationSettings activationSettings)
        {
            NCount = nCount;

            Index = index;

            ActivationType = activationSettings.Type();

            // Activation Setup
            switch (activationSettings.Type())
            {
            case EActivationType.Invalid:
                Activation = null;
                throw new ArgumentException("Activation Type Invalid.");

            case EActivationType.Arctan:
                Activation = new Arctan();
                break;

            case EActivationType.BinaryStep:
                Activation = new BinaryStep();
                break;

            case EActivationType.BipolarSigmoid:
                Activation = new BipolarSigmoid();
                break;

            case EActivationType.ELU:
                Activation = new ELU((ELUSettings)activationSettings);
                break;

            case EActivationType.HardSigmoid:
                Activation = new HardSigmoid();
                break;

            case EActivationType.HardTanh:
                Activation = new HardTanh();
                break;

            case EActivationType.Identity:
                Activation = new Identity();
                break;

            case EActivationType.Logit:
                Activation = new Logit();
                break;

            case EActivationType.LReLU:
                Activation = new LReLU((LReLUSettings)activationSettings);
                break;

            case EActivationType.Mish:
                Activation = new Mish();
                break;

            case EActivationType.ReLU:
                Activation = new ReLU();
                break;

            case EActivationType.SeLU:
                Activation = new SeLU();
                break;

            case EActivationType.Sigmoid:
                Activation = new Sigmoid();
                break;

            case EActivationType.Softmax:
                Activation = new Softmax();
                break;

            case EActivationType.Softplus:
                Activation = new Softplus();
                break;

            case EActivationType.Softsign:
                Activation = new Softsign();
                break;

            case EActivationType.Tanh:
                Activation = new Tanh();
                break;

            default:
                throw new ArgumentException("Activation Type Invalid.");
            }
        }
Beispiel #18
0
 /// <summary>
 /// Converts a general-purpose log object into a string format expected by Logstash V1.
 /// </summary>
 /// <param name="log">The log object to convert.</param>
 /// <returns>>The log formatted as expected by Logstash V1.</returns>
 public string Format(Logit.Layout.Log log)
 {
     return log == null ? string.Empty : log.ToString();
 }
Beispiel #19
0
 static void quit(Logit log)
 {
     log.Close();
 }
        /// <summary>
        /// GENERATE TOP LEVEL TASKS
        /// Combination of direct copy camera tasks, http camera tasks, and ftp server tasks.
        /// </summary>
        /// <param name="servers"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public List <Task> GenerateTopLevelTasks(List <EntityServer> servers, CancellationToken token)
        {
            var processor = new GatherProcessor();
            var items     = new List <Task>();

            foreach (var server in servers)
            {
                if (server.ServerType == "FTP")
                {
                    items.Add(Task <List <GatherResult> > .Factory.StartNew(()
                                                                            => processor.PerformFtpGather(server), token, TaskCreationOptions.None, TaskScheduler.Default)
                              .ContinueWith(taskInfo =>
                    {
                        try
                        {
                            token.ThrowIfCancellationRequested();
                            var gatherResults = (List <GatherResult>)taskInfo.Result;
                            Logit.LogGatherResults(gatherResults);
                            List <Task> imageTasks = new List <Task>();
                            foreach (var gatherResult in gatherResults)
                            {
                                imageTasks.AddRange(GenerateImageTasks(gatherResult, token));
                            }
                            Parallel.ForEach(imageTasks, imageResult =>
                            {
                            });
                            Task.WaitAll(imageTasks.ToArray());
                        }
                        catch (Exception exc)
                        {
                            Logit.LogError(exc);
                        }
                    })
                              );
                }
                else
                {
                    foreach (var camera in server.Cameras)
                    {
                        items.Add(Task <GatherResult> .Factory.StartNew(()
                                                                        => processor.PerformGather(camera), token, TaskCreationOptions.LongRunning, TaskScheduler.Default)
                                  .ContinueWith(taskInfo =>
                        {
                            try
                            {
                                token.ThrowIfCancellationRequested();
                                var gatherResult = (GatherResult)taskInfo.Result;
                                Logit.LogGatherResult(gatherResult);
                                var imageTasks = GenerateImageTasks(gatherResult, token);
                                Parallel.ForEach(imageTasks, imageResult =>
                                {
                                });
                                Task.WaitAll(imageTasks.ToArray());
                            }
                            catch (Exception exc)
                            {
                                Logit.LogError(exc);
                            }
                        })
                                  );
                    }
                }
            }
            return(items);
        }