예제 #1
0
        public static ISystemProcess ExecuteIptables(NetfilterSystem system, String command, String iptablesBinary)
        {
            ISystemProcess process = system.System.StartProcess(iptablesBinary, command);

            process.WaitForExit();

            //OK
            if (process.ExitCode == 0)
            {
                return(process);
            }

            //ERR: INVALID COMMAND LINE
            if (process.ExitCode == 2)
            {
                throw new IpTablesNetException("IPTables execution failed: Invalid Command Line - " + command);
            }

            //ERR: GENERAL ERROR
            if (process.ExitCode == 1)
            {
                throw new IpTablesNetException("IPTables execution failed: Error - " + command);
            }

            //ERR: UNKNOWN
            throw new IpTablesNetException("IPTables execution failed: Unknown Error - " + command);
        }
예제 #2
0
        public void CreateEntityActor <TEvent>(object action, ISystemProcess process, IProcessSystemMessage msg) where TEvent : IMessage
        {
            /// Create Actor Per Event
            Type actorType = typeof(EntityDataServiceActor <>).MakeGenericType(typeof(TEvent));
            var  inMsg     = new CreateEntityService(actorType, action, new StateCommandInfo(process.Id, RevolutionData.Context.Actor.Commands.StartActor), process, Source);

            try
            {
                Task.Run(() =>
                {
                    ctx.ActorOf(
                        Props.Create(actorType, inMsg, msg)
                        .WithRouter(new RoundRobinPool(1,
                                                       new DefaultResizer(1, Environment.ProcessorCount, 1, .2, .3, .1,
                                                                          Environment.ProcessorCount))),
                        "EntityDataServiceActor-" +
                        typeof(TEvent).GetFriendlyName().Replace("<", "'").Replace(">", "'"));
                });
            }
            catch (Exception ex)
            {
                //ToDo: This seems like a good way... getting the expected event type
                PublishProcesError(inMsg, ex, inMsg.ProcessInfo.State.ExpectedEvent.GetType());
            }
        }
예제 #3
0
        public virtual IpSetSets SaveSets(IpTablesSystem iptables)
        {
            IpSetSets sets = new IpSetSets(iptables);
            String    output, error;

            using (ISystemProcess process = _system.StartProcess(BinaryName, "save"))
            {
                ProcessHelper.ReadToEnd(process, out output, out error);
            }

            String[] all = output.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries);
            foreach (String line in all)
            {
                if (String.IsNullOrEmpty(line))
                {
                    break;
                }
                var trimmed = line.Trim();
                if (trimmed.Length != 0)
                {
                    sets.Accept(trimmed, iptables);
                }
            }

            return(sets);
        }
예제 #4
0
        public void CreateEntityViewActor <TEvent>(object action, ISystemProcess process, IProcessSystemMessage msg) where TEvent : IMessage
        {
            Type actorType = typeof(EntityViewDataServiceActor <>).MakeGenericType(typeof(TEvent));
            var  inMsg     = new CreateEntityViewService(actorType, action, new StateCommandInfo(process.Id, RevolutionData.Context.Actor.Commands.StartActor), process, Source);

            EventMessageBus.Current.Publish(inMsg, Source);
            /// Create Actor Per Event
            try
            {
                Task.Run(() =>
                {
                    ctx.ActorOf(
                        Props.Create(inMsg.ActorType, inMsg, msg)
                        .WithRouter(new RoundRobinPool(1,
                                                       new DefaultResizer(1, Environment.ProcessorCount, 1, .2, .3, .1,
                                                                          Environment.ProcessorCount))),
                        "EntityViewDataServiceActor-" +
                        typeof(TEvent).GetFriendlyName().Replace("<", "'").Replace(">", "'"));
                });

                //_childActor.Tell(msg);
            }
            catch (Exception ex)
            {
                Debugger.Break();
                EventMessageBus.Current.Publish(new ProcessEventFailure(failedEventType: inMsg.GetType(),
                                                                        failedEventMessage: inMsg,
                                                                        expectedEventType: typeof(ServiceStarted <>),
                                                                        exception: ex,
                                                                        source: Source, processInfo: new StateEventInfo(process.Id, RevolutionData.Context.Process.Events.Error)), Source);
            }
        }
예제 #5
0
        public static void ExecuteIptables(NetfilterSystem system, String command, String iptablesBinary, out String output, out String error)
        {
            using (ISystemProcess process = system.System.StartProcess(iptablesBinary, command))
            {
                ProcessHelper.ReadToEnd(process, out output, out error);

                //OK
                if (process.ExitCode == 0)
                {
                    return;
                }

                //ERR: INVALID COMMAND LINE
                if (process.ExitCode == 2)
                {
                    throw new IpTablesNetException("IPTables execution failed: Invalid Command Line - " + command);
                }

                //ERR: GENERAL ERROR
                if (process.ExitCode == 1)
                {
                    throw new IpTablesNetException("IPTables execution failed: Error - " + command);
                }

                //ERR: UNKNOWN
                throw new IpTablesNetException("IPTables execution failed: Unknown Error - " + command);
            }
        }
 public ViewEventCommandParameter(object[] @params, IStateCommandInfo processInfo, ISystemProcess process, ISystemSource source)
 {
     Params      = @params;
     Process     = process;
     Source      = source;
     ProcessInfo = processInfo;
 }
예제 #7
0
 public ComplexEventService(string actorId, IComplexEventAction complexEventAction, ISystemProcess process, ISystemSource source)
 {
     ComplexEventAction = complexEventAction;
     Process            = process;
     Source             = source;
     ActorId            = actorId;
 }
 public ViewEventPublicationParameter(object[] @params, IStateEventInfo processInfo, ISystemProcess process, ISystemSource source)
 {
     Params      = @params;
     Process     = process;
     Source      = source;
     ProcessInfo = processInfo;
 }
예제 #9
0
        private bool ExecuteTransaction()
        {
            String output, error;

            using (ISystemProcess process = _system.StartProcess(BinaryName, "restore"))
            {
                if (WriteStrings(_transactionCommands, process.StandardInput))
                {
                    process.StandardInput.Flush();
                    process.StandardInput.Close();
                    ProcessHelper.ReadToEnd(process, out output, out error);

                    //OK
                    if (process.ExitCode == 0)
                    {
                        return(true);
                    }
                }
                else
                {
                    ProcessHelper.ReadToEnd(process, out output, out error);
                }
            }

            error = error.Trim();
            if (error.Length != 0)
            {
                throw new IpTablesNetException(String.Format("Failed to execute transaction: {0}", error));
            }

            return(false);
        }
예제 #10
0
        public override IpTablesChainSet ListRules(String table)
        {
            ISystemProcess process = StartProcess(_iptablesSaveBinary, String.Format("-c -t {0}", table));
            String         toEnd   = process.StandardOutput.ReadToEnd();

            process.WaitForExit();
            return(Helper.IPTablesSaveParser.GetRulesFromOutput(_system, toEnd, table, _ipVersion));
        }
예제 #11
0
        public ViewModelActor(ISystemProcess process) : base(process)
        {
            ctx = Context;
            Command <LoadViewModel>(x => HandleProcessViews(x));

            EventMessageBus.Current.GetEvent <ILoadViewModel>(Source).Subscribe(x => HandleProcessViews(x));
            EventMessageBus.Current.Publish(new ServiceStarted <IViewModelService>(this, new StateEventInfo(process.Id, RevolutionData.Context.Actor.Events.ActorStarted), process, Source), Source);
        }
예제 #12
0
 public Source(Guid sourceId, string sourceName, ISourceType sourceType, ISystemProcess process, IMachineInfo machineInfo)
 {
     SourceId    = sourceId;
     SourceName  = sourceName;
     MachineInfo = machineInfo;
     Process     = process;
     SourceType  = sourceType;
 }
예제 #13
0
 public override IpTablesChainSet ListRules(String table)
 {
     using (ISystemProcess process = StartProcess(_iptablesSaveBinary, String.Format("-c -t {0}", table)))
     {
         String toEnd, error;
         ProcessHelper.ReadToEnd(process, out toEnd, out error);
         return(Helper.IPTablesSaveParser.GetRulesFromOutput(_system, toEnd, table, _ipVersion));
     }
 }
예제 #14
0
 public EntityDataServiceSupervisor(ISystemProcess process, IProcessSystemMessage msg) : base(process)
 {
     ctx = Context;
     foreach (var itm in entityEvents)
     {
         this.GetType()
         .GetMethod("CreateEntityActor")
         .MakeGenericMethod(itm.Key)
         .Invoke(this, new object[] { itm.Value, process, msg });
     }
 }
예제 #15
0
 public ProcessSystemMessage(IProcessStateInfo processInfo, ISystemProcess process, ISystemSource source) : base(source.MachineInfo, source)
 {
     Process         = process;
     ProcessInfo     = processInfo;
     ParentProcessId = Process.ParentProcessId;
     Name            = process.Name;
     Description     = process.Description;
     Symbol          = process.Symbol;
     User            = process.User;
     Id = process.Id;
 }
예제 #16
0
 public LoginLogic(IOAuthManager oAuthManager, IUserInfoLogic userInfoLogic, ISystemProcess process,
                   IRepository <Token> tokenRepository, IRepository <User> userRepository,
                   IRepository <Preferences> preferencesRepository, IRepository <Update> updateRepository)
 {
     _oAuthManager          = oAuthManager;
     _userInfoLogic         = userInfoLogic;
     _process               = process;
     _tokenRepository       = tokenRepository;
     _userRepository        = userRepository;
     _preferencesRepository = preferencesRepository;
     _updateRepository      = updateRepository;
 }
예제 #17
0
        public override IpTablesChainSet ListRules(String table)
        {
            ISystemProcess process = _system.System.StartProcess(_iptablesBinary + "-save", String.Format("-c -t {0}", table));
            String         output  = "";

            do
            {
                output += process.StandardOutput.ReadToEnd();
            } while (!process.HasExited);
            process.WaitForExit();
            return(Helper.IPTablesSaveParser.GetRulesFromOutput(_system, output, table, _ipVersion));
        }
예제 #18
0
        /// <summary>
        ///     Starts the FTP server.
        /// </summary>
        public void Start()
        {
            var tempFilePath = fileSystem.Path.GetTempFilePath("exe");

            if (!fileSystem.Directory.Exists(fileSystem.Path.GetDirectoryName(tempFilePath)))
            {
                fileSystem.Directory.CreateDirectory(fileSystem.Path.GetDirectoryName(tempFilePath));
            }

            fileSystem.File.WriteAllBytes(tempFilePath, Assets.ftpdmin);

            process = operatingSystem.StartProcess(
                tempFilePath,
                $"-p {Configuration.Port} \"{Configuration.HomeDirectory}\"");
        }
        public void Log(Exception e, ISystemProcess process)
        {
            if (process == null)
            {
                this.Log(e);
                return;
            }

            var dto = new ExceptionDto
            {
                ExceptionMessage      = e.Message,
                InnerExceptionMessage = e.InnerException?.Message,
                StackTrace            = e.StackTrace,
                SystemProcessId       = process?.Id
            };

            this._exceptionRepository.Save(dto);
        }
예제 #20
0
        protected BaseViewModel(ISystemProcess process, IViewInfo viewInfo, List <IViewModelEventSubscription <IViewModel, IEvent> > eventSubscriptions, List <IViewModelEventPublication <IViewModel, IEvent> > eventPublications, List <IViewModelEventCommand <IViewModel, IEvent> > commandInfo, Type orientation, int priority)
        {
            if (LicenseManager.UsageMode == LicenseUsageMode.Designtime)
            {
                return;
            }
            Source             = new Source(Guid.NewGuid(), "ViewModel:" + typeof(TViewModel).GetFriendlyName(), new SourceType(typeof(BaseViewModel <TViewModel>)), process, process.MachineInfo);
            Process            = process;
            EventSubscriptions = eventSubscriptions;
            EventPublications  = eventPublications;
            CommandInfo        = commandInfo;
            Orientation        = orientation;
            Priority           = priority;
            ViewInfo           = viewInfo;
            ViewModelType      = typeof(TViewModel);

            RowState = new ReactiveProperty <RowState>(SystemInterfaces.RowState.Loaded);
        }
예제 #21
0
        public bool RestoreSets(IEnumerable <IpSetSet> sets)
        {
            //ipset save
            ISystemProcess process = _system.StartProcess(BinaryName, "restore");

            if (WriteSets(sets, process.StandardInput))
            {
                process.StandardInput.Flush();
                process.StandardInput.Close();
                process.WaitForExit();

                //OK
                if (process.ExitCode != 0)
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #22
0
        private bool ExecuteTransaction()
        {
            //ipset save
            ISystemProcess process = _system.StartProcess(BinaryName, "restore");

            if (WriteStrings(_transactionCommands, process.StandardInput))
            {
                process.StandardInput.Flush();
                process.StandardInput.Close();
                process.WaitForExit();

                //OK
                if (process.ExitCode != 0)
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #23
0
        public async Task Update(ISystemProcess entity)
        {
            if (entity == null || string.IsNullOrWhiteSpace(entity.Id))
            {
                return;
            }

            try
            {
                using (var dbConnection = this._dbConnectionFactory.BuildConn())
                    using (var conn = dbConnection.ExecuteAsync(UpdateSql, entity))
                    {
                        await conn;
                    }
            }
            catch (Exception e)
            {
                this._logger.LogError(e, $"SystemProcessRepository Update Method For {entity?.Id}");
            }
        }
예제 #24
0
 public EntityViewDataServiceSupervisor(ISystemProcess process, IProcessSystemMessage msg) : base(process)
 {
     try
     {
         ctx = Context;
         Parallel.ForEach(entityEvents, new ParallelOptions()
         {
             MaxDegreeOfParallelism = Environment.ProcessorCount
         }, (itm) =>
         {
             this.GetType()
             .GetMethod("CreateEntityViewActor")
             .MakeGenericMethod(itm.Key)
             .Invoke(this, new object[] { itm.Value, process, msg });
         });
     }
     catch (Exception)
     {
         throw;
     }
 }
예제 #25
0
        public virtual IpSetSets SaveSets(IpTablesSystem iptables)
        {
            IpSetSets sets = new IpSetSets(iptables);

            //ipset save
            using (ISystemProcess process = _system.StartProcess(BinaryName, "save"))
            {
                ProcessHelper.ReadToEnd(process, line =>
                {
                    if (line == null)
                    {
                        return;
                    }
                    var trimmed = line.Trim();
                    if (trimmed.Length != 0)
                    {
                        sets.Accept(trimmed, iptables);
                    }
                }, err => { });
            }

            return(sets);
        }
예제 #26
0
        public ViewModelSupervisor(List <IViewModelInfo> processViewModelInfos, ISystemProcess process, ISystemStarted firstMsg) : base(process)
        {
            ProcessViewModelInfos = processViewModelInfos;
            ctx = Context;
            Task.Run(() =>
            {
                ctx.ActorOf(
                    Props.Create <ViewModelActor>(process)
                    .WithRouter(new RoundRobinPool(1,
                                                   new DefaultResizer(1, Environment.ProcessorCount, 1, .2, .3, .1, Environment.ProcessorCount))),
                    "ViewModelActorEntityActor");
            });


            EventMessageBus.Current.GetEvent <ISystemProcessStarted>(Source).Subscribe(x => HandleProcessViews(x));

            EventMessageBus.Current.GetEvent <IServiceStarted <IViewModelService> >(Source).Subscribe(x =>
            {
                EventMessageBus.Current.Publish(new ServiceStarted <IViewModelSupervisor>(this, new StateEventInfo(process.Id, RevolutionData.Context.Actor.Events.ActorStarted), process, Source), Source);
            });

            //HandleProcessViews(firstMsg);
        }
예제 #27
0
        public virtual IpSetSets SaveSets(IpTablesSystem iptables)
        {
            ISystemProcess process = _system.StartProcess(BinaryName, "save");

            IpSetSets sets = new IpSetSets(iptables);

            String[] all = process.StandardOutput.ReadToEnd().Split(new string[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries);
            foreach (String line in all)
            {
                if (String.IsNullOrEmpty(line))
                {
                    break;
                }
                var trimmed = line.Trim();
                if (trimmed.Length != 0)
                {
                    sets.Accept(trimmed, iptables);
                }
            }

            process.WaitForExit();

            return(sets);
        }
예제 #28
0
        public static void ReadToEnd(ISystemProcess process, out String output, out String error, int timeout = DefaultTimeout)
        {
            String toutput = "";
            String terror = "";
            DataReceivedEventHandler errorEvent = null, outEvent = null;

            if (process.StartInfo.RedirectStandardError)
            {
                errorEvent = (a, b) => terror += b.Data + "\n";
                process.ErrorDataReceived += errorEvent;
                process.BeginErrorReadLine();
            }
            if (process.StartInfo.RedirectStandardOutput)
            {
                outEvent = (a, b) => toutput += b.Data + "\n";
                process.OutputDataReceived += outEvent;
                process.BeginOutputReadLine();
            }

            if (!process.WaitForExit(timeout * 1000))
            {
                throw new TimeoutException(String.Format("Timeout. Process did not complete executing within {0} seconds", timeout));
            }

            output = toutput;
            error = terror;

            if (errorEvent != null)
            {
                process.ErrorDataReceived -= errorEvent;
            }
            if (outEvent != null)
            {
                process.OutputDataReceived -= outEvent;
            }
        }
예제 #29
0
 private Journal(IJournalReaderWriterFactory readerWriterFactory, IMarkdownFiles markdownFiles, ISystemProcess systemProcess)
 {
     _readerWriterFactory = readerWriterFactory;
     _markdownFiles       = markdownFiles;
     _systemProcess       = systemProcess;
 }
예제 #30
0
 public ExecuteComplexEventAction(IProcessAction action, IComplexEventParameters complexEventParameters, IStateCommandInfo processInfo, ISystemProcess process, ISystemSource source) : base(processInfo, process, source)
 {
     Action = action;
     ComplexEventParameters = complexEventParameters;
 }
예제 #31
0
 public static Journal Open(IJournalReaderWriterFactory readerWriterFactory, IMarkdownFiles markdownFiles, ISystemProcess systemProcess)
 {
     return(new Journal(readerWriterFactory, markdownFiles, systemProcess));
 }
예제 #32
0
        public static void WaitForExit(ISystemProcess process)
        {
            String temp;

            ReadToEnd(process, out temp, out temp);
        }