Beispiel #1
0
        public static string BuildJsonFromArgs(IJobArgs args)
        {
            if (args == null)
                return "";

            var keys = new List<string>(args.GetKeys());
            if (keys.Count == 0)
                return "";

            var sb = new StringBuilder();
            sb.Append("[");
            bool firstkey = true;
            foreach (var k in keys)
            {
                foreach (var v in args.GetValues(k))
                {
                    if (!firstkey)
                        sb.Append(",");
                    sb.Append("\"");
                    sb.Append(EscapeJson(k + ":=" + v));
                    sb.Append("\"");
                    firstkey = false;
                }
            }
            sb.Append("]");
            return sb.ToString();
        }
Beispiel #2
0
 public ClientConfig()
 {
     ManagerUrl = "";
     Assemblies = new List<string>();
     JobType = "";
     JobArgs = new DefaultJobArgs();
     Instances = 5;
 }
Beispiel #3
0
 public ManagerJob()
 {
     ID = ""; // newjob.ID = Guid.NewGuid().ToString().Replace("-", "").Substring(0, 10);
     CallbackUrl = "";
     Workers = new List<WorkerInfo>();
     State = ManagerJobState.Preparing;
     JobType = "";
     JobArgs = new DefaultJobArgs();
     Timeout = 5;
     Assemblies = new Dictionary<string, byte[]>();
 }
Beispiel #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ServiceJob{T}" /> class.
        /// </summary>
        /// <param name="invokeMethodName">Name of the invoke method.</param>
        /// <param name="args">The arguments.</param>
        /// <exception cref="ArgumentNullException">invokeMethodName</exception>
        /// <exception cref="ServiceInitializationException"></exception>
        public ServiceJob(string invokeMethodName, IJobArgs args)
        {
            if (invokeMethodName == null)
            {
                throw new ArgumentNullException(nameof(invokeMethodName));
            }

            JobClassType = typeof(T);
            JobArgs      = args ?? throw new ArgumentNullException(nameof(args));

            InvokeMethodInfo = BuildInvokeMethodInfo(invokeMethodName);
        }
Beispiel #5
0
 public WorkerJob()
 {
     // LoadedAssemblies = new List<Assembly>();
     SandboxPath = Path.GetTempPath() + Path.DirectorySeparatorChar + "wa-" + Guid.NewGuid().ToString();
     if (!Directory.Exists(SandboxPath))
         Directory.CreateDirectory(SandboxPath);
     var setup = new AppDomainSetup();
     setup.ApplicationBase = SandboxPath;
     var perms = new PermissionSet(System.Security.Permissions.PermissionState.Unrestricted);
     Sandbox = AppDomain.CreateDomain("Temp sandbox", null, setup, perms, new StrongName[] { });
     JobType = "";
     JobArgs = new DefaultJobArgs();
 }
Beispiel #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CrontabSchedulerJob{T}" /> class.
        /// </summary>
        /// <param name="settings">The settings.</param>
        /// <param name="crontabProcessorFactory">The crontab processor factory.</param>
        /// <param name="invokeMethodName">Name of the invoke method.</param>
        /// <param name="args">The job arguments.</param>
        /// <exception cref="ArgumentNullException">settings
        /// or
        /// invokeMethodName</exception>
        /// <exception cref="SchedulerInitializationException"></exception>
        /// <exception cref="ArgumentNullException">settings
        /// or
        /// invokeMethodName</exception>
        public CrontabSchedulerJob(ISchedulerJobSettings settings,
                                   ICrontabProcessorFactory crontabProcessorFactory,
                                   string invokeMethodName,
                                   IJobArgs args)
            : base(invokeMethodName, args)
        {
            if (invokeMethodName == null)
            {
                throw new ArgumentNullException(nameof(invokeMethodName));
            }

            Settings = settings ?? throw new ArgumentNullException(nameof(settings));
            _crontabProcessorFactory = crontabProcessorFactory ?? throw new ArgumentNullException(nameof(crontabProcessorFactory));
        }
Beispiel #7
0
        public void Run(IJobArgs args)
        {
            if (_isRunning)
            {
                throw new SimplifyWindowsServicesException("TwoSecondStepProcessor is running a duplicate!");
            }

            _isRunning = true;

            Trace.WriteLine("TwoSecondStepProcessor launched");
            Trace.WriteLine($"TwoSecondStepProcessor args startup args is: {args.StartupArgs}");
            Trace.WriteLine($"TwoSecondStepProcessor args service name is: {args.ServiceName}");

            Thread.Sleep(3670);

            _isRunning = false;
        }
Beispiel #8
0
        public static void FillArgsFromJson(IJobArgs args, object jsonvalue)
        {
            if( jsonvalue == null )
                return;

            var strings = jsonvalue as string[];
            if( strings == null )
                return;

            foreach(var s in strings)
            {
                var i = s.IndexOf(":=");
                if( i == -1 )
                    continue;

                args.Add(s.Substring(0,i), s.Substring(i+2));
            }
        }
Beispiel #9
0
        public string RunJob(AppDomain domain, string jobtype, IJobArgs args)
        {
            string ret = "";
            Console.WriteLine("SandboxProxy: Trying to create a " + jobtype);
            try
            {
                var aa = jobtype.Split(',');

                var t = domain.CreateInstanceAndUnwrap(aa[1].Trim(), aa[0].Trim()) as ISandboxedJob;
                // var t = Activator.CreateInstance(Type.GetType(jobtype)) as ISandboxedJob;
                Console.WriteLine("Created type " + t);
                Console.WriteLine("---------------------------------------------------------");
                ret = t.Run(args);
                Console.WriteLine("---------------------------------------------------------");
            }
            catch (Exception z)
            {
                Console.WriteLine(z);
            }
            return ret;
        }