Ejemplo n.º 1
0
        public static ActionResponse Get(Action action)
        {
            var request = (HttpWebRequest)WebRequest.Create(action.Url);

            request.Method    = "GET";
            request.Timeout   = action.TimeOut == 0 ? Timeout.Infinite : action.TimeOut;
            request.KeepAlive = action.TimeOut == 0;

            try {
                using (var response = (HttpWebResponse)request.GetResponse()) {
                    using (var responseStream = response.GetResponseStream()) {
                        if (responseStream == null)
                        {
                            return new ActionResponse {
                                       Code = (int)response.StatusCode, Action = action
                            }
                        }
                        ;
                        var reader = new StreamReader(responseStream);
                        return(new ActionResponse((int)response.StatusCode, reader.ReadToEnd())
                        {
                            Action = action
                        });
                    }
                }
            } catch (Exception e) {
                return(new ActionResponse(500, e.Message)
                {
                    Action = action
                });
            }
        }
Ejemplo n.º 2
0
        public static ActionResponse GetData(Action action)
        {
            var request = (HttpWebRequest)WebRequest.Create(action.Url);

            request.Method    = "GET";
            request.Timeout   = action.TimeOut == 0 ? Timeout.Infinite : action.TimeOut;
            request.KeepAlive = action.TimeOut == 0;

            try {
                using (var response = (HttpWebResponse)request.GetResponse()) {
                    using (var responseStream = response.GetResponseStream()) {
                        if (responseStream == null)
                        {
                            return new ActionResponse {
                                       Code = (int)response.StatusCode, Action = action
                            }
                        }
                        ;

                        var reader = new MemoryStream();
                        responseStream.CopyTo(reader);

                        return(new ActionResponse((int)response.StatusCode, "Data")
                        {
                            Action = action, Data = reader.ToArray()
                        });
                    }
                }
            } catch (Exception e) {
                return(new ActionResponse(500, e.Message)
                {
                    Action = action
                });
            }
        }
 public PipelineAction(
     Action action,
     IServiceProvider serviceProvider
     )
 {
     _action          = action;
     _serviceProvider = serviceProvider;
 }
 public RemoteUnload(IContext context, Action action)
 {
     _context  = context;
     _response = new ActionResponse(200, "Ok")
     {
         Action = action
     };
 }
        public bool Run(Transformalize.Configuration.Action action, IDictionary <string, string> parameters)
        {
            var part = _orchardServices.ContentManager.Get(action.Id).As <PipelineConfigurationPart>();

            if (part == null)
            {
                if (action.Url == string.Empty)
                {
                    const string msg = "The action doesn't refer to a valid 'id' or redirect 'url'.";
                    Logger.Error(msg);
                    _orchardServices.Notifier.Error(T(msg));
                    return(false);
                }
                return(true);
            }

            if (!_orchardServices.Authorizer.Authorize(Permissions.ViewContent, part))
            {
                _orchardServices.Notifier.Warning(T("You do not have permission to run this bulk action."));
                return(false);
            }

            var actionProcess = _processService.Resolve(part);

            actionProcess.Load(part.Configuration, parameters);

            if (actionProcess.Errors().Any())
            {
                foreach (var error in actionProcess.Errors())
                {
                    _orchardServices.Notifier.Add(NotifyType.Error, T(error));
                    Logger.Error(error);
                }
                return(false);
            }

            try {
                _orchardServices.WorkContext.Resolve <IRunTimeExecute>().Execute(actionProcess);
                return(true);
            } catch (Exception ex) {
                Logger.Error(ex, ex.Message);
                _orchardServices.Notifier.Error(T(ex.Message));
                return(false);
            }
        }
Ejemplo n.º 6
0
        public static ActionResponse Post(Action action)
        {
            var request = (HttpWebRequest)WebRequest.Create(action.Url);

            request.Method      = "POST";
            request.Timeout     = action.TimeOut == 0 ? Timeout.Infinite : action.TimeOut;
            request.KeepAlive   = action.TimeOut == 0;
            request.ContentType = "application/x-www-form-urlencoded";

            var byteArray = Encoding.UTF8.GetBytes(action.Body);

            request.ContentLength = byteArray.Length;

            using (var dataStream = request.GetRequestStream()) {
                dataStream.Write(byteArray, 0, byteArray.Length);
            }

            try {
                using (var response = (HttpWebResponse)request.GetResponse()) {
                    using (var responseStream = response.GetResponseStream()) {
                        if (responseStream == null)
                        {
                            return new ActionResponse((int)response.StatusCode)
                                   {
                                       Action = action
                                   }
                        }
                        ;
                        var reader = new StreamReader(responseStream);
                        return(new ActionResponse((int)response.StatusCode, reader.ReadToEnd())
                        {
                            Action = action
                        });
                    }
                }
            } catch (Exception e) {
                return(new ActionResponse(500, e.Message)
                {
                    Action = action
                });
            }
        }
Ejemplo n.º 7
0
        public ActionTransform(IContext context = null) : base(context, "string")
        {
            if (IsMissingContext())
            {
                return;
            }

            if (IsMissing(Context.Operation.Property))
            {
                return;
            }

#if NETS10
            _props = typeof(Action).GetRuntimeProperties().Where(prop => CustomAttributeExtensions.GetCustomAttribute((MemberInfo)prop, typeof(CfgAttribute), (bool)true) != null).Select(prop => prop.Name).ToArray();
#else
            _props = typeof(Action).GetProperties().Where(prop => prop.GetCustomAttributes(typeof(CfgAttribute), true).FirstOrDefault() != null).Select(prop => prop.Name).ToArray();
#endif

            var set = new HashSet <string>(_props, StringComparer.OrdinalIgnoreCase);

            if (!set.Contains(Context.Operation.Property))
            {
                Error($"The action property {Context.Operation.Property} is not allowed.  The allowed properties are {(string.Join(", ", _props))}.");
                Run = false;
                return;
            }

            Context.Operation.Property = set.First(s => s.Equals(Context.Operation.Property, StringComparison.OrdinalIgnoreCase));

            if (Context.Operation.Index < Context.Process.Actions.Count)
            {
                _action = Context.Process.Actions[Context.Operation.Index];
            }
            else
            {
                Run = false;
                Context.Error($"action index {Context.Operation.Index} is out of bounds");
            }
        }
Ejemplo n.º 8
0
 public ExitAction(IContext context, Action action)
 {
     _context = context;
     _action  = action;
 }
 public ContentToFileAction(PipelineContext context, Action action)
 {
     _context = context;
     _action  = action;
 }
Ejemplo n.º 10
0
 public OpenAction(Action action)
 {
     _action = action;
 }
Ejemplo n.º 11
0
 public FileCopyAction(IContext context, Action action)
 {
     _context = context;
     _action  = action;
 }
Ejemplo n.º 12
0
 public FileArchiveAction(IContext context, Action action)
 {
     _context = context;
     _action  = action;
 }
Ejemplo n.º 13
0
 public WebAction(PipelineContext context, Action action)
 {
     _context = context;
     _action  = action;
 }
Ejemplo n.º 14
0
 public PrintAction(Action action)
 {
     _action = action;
     _level  = action.Level.Left(1);
 }