Пример #1
0
        protected override bool Process(IInteraction parameters)
        {
            var dataSource = Closest <IIncomingBodiedInteraction> .From(parameters);

            FileInfo file = GetFileInfo(parameters);

            if (!file.FullName.StartsWith(this.ValidRootPath))
            {
                return(FailForException(parameters, new Exception("File not in root path")));
            }

            if (file.Exists && !MayOverwrite)
            {
                return(FailForException(parameters, new Exception("File already exists")));
            }

            try {
                using (FileStream fileStream = file.OpenWrite()) {
                    Task copyTask = dataSource.IncomingBody.CopyToAsync(fileStream);
                    this.Meanwhile.TryProcess(parameters);
                    copyTask.Wait();
                }
                return((Successful == null) || Successful.TryProcess(parameters));
            } catch (Exception ex) {
                return(FailForException(parameters, ex));
            }
        }
Пример #2
0
        protected override bool Process(IInteraction parameters)
        {
            var dataSink = Closest <IOutgoingBodiedInteraction> .From(parameters);

            FileInfo file = GetFileInfo(parameters);

            if (!file.FullName.StartsWith(this.ValidRootPath))
            {
                return(FailForException(parameters, new Exception("File not in root path")));
            }

            IInteraction fileParameters = new SimpleInteraction(
                parameters, "contentlength", file.Length);

            if (!this.Header.TryProcess(fileParameters))
            {
                return(FailForException(fileParameters, new Exception("Header failed")));
            }

            try {
                using (FileStream fileStream = file.OpenRead()) {
                    Task copyTask = fileStream.CopyToAsync(dataSink.OutgoingBody);
                    Meanwhile.TryProcess(fileParameters);
                    copyTask.Wait();
                }

                return((Successful == null) || Successful.TryProcess(fileParameters));
            } catch (Exception ex) {
                return(FailForException(fileParameters, ex));
            }
        }
Пример #3
0
        protected override bool Process(IInteraction parameters)
        {
            bool successful = true;

            try {
                int      serviceInt   = GetServiceInt(parameters, this.ServiceIdKey);
                Service  foundService = GetServiceById(serviceInt);
                Settings config       = foundService.GetSettings();

                if (Reconfigure)
                {
                    config = GetContextSettings(parameters);

                    if (!Replace)
                    {
                        config = Settings.FromMerge(config, foundService.GetSettings());
                    }
                }

                if (!foundService.SetSettings(config))
                {
                    successful &= Failure.TryProcess(new FailureInteraction(parameters, foundService.InitErrorMessage, foundService.InitErrorDetail));
                }
                else
                {
                    successful &= Successful.TryProcess(MetaServiceInteraction.FromService(parameters, foundService));
                }
            } catch (ControlException ex) {
                successful &= Failure.TryProcess(new FailureInteraction(parameters, ex));
            }

            return(successful);
        }
Пример #4
0
        protected override bool Process(IInteraction parameters)
        {
            int    sourceServiceID = GetServiceInt(parameters, SourceServiceIdKey);
            int    targetServiceID = GetServiceInt(parameters, TargetServiceIdKey);
            string branchName;
            bool   successful;

            try {
                if (parameters.TryGetFallbackString(SourceBranchNameKey, out branchName))
                {
                    Service source = GetServiceById(sourceServiceID);
                    Service target = GetServiceById(targetServiceID);

                    source.Branches [branchName] = target;

                    successful = Successful.TryProcess(new MetaInteraction(
                                                           parameters, source, branchName, target));
                }
                else
                {
                    throw new ControlException(ControlException.Cause.NoBranchSupplied, SourceBranchNameKey);
                }
            } catch (ControlException ex) {
                successful = Failure.TryProcess(new FailureInteraction(parameters, ex));
            }

            return(successful);
        }
Пример #5
0
        protected override bool Process(IInteraction parameters)
        {
            /* return "Basic " + Convert.ToBase64String (
             *      Encoding.ASCII.GetBytes (
             *              string.Format (
             *                      "{0}:{1}",
             *                      Username,
             *                      Password
             *              )
             *      )
             * ); */

            bool successful = true;

            IHttpInteraction httpParameters = (IHttpInteraction)parameters.GetClosest(typeof(IHttpInteraction));
            string           authHeader     = httpParameters.RequestHeaders["Authorization"];

            if ((authHeader != null) && authHeader.StartsWith("Basic "))
            {
                string   encAuthString = authHeader.Substring("Basic ".Length).Trim();
                string   authString    = Encoding.ASCII.GetString(Convert.FromBase64String(encAuthString));
                string[] userPass      = authString.Split(':');

                if (userPass.Length == 2)
                {
                    var credentials = new SimpleInteraction();

                    credentials ["username"] = userPass [0];
                    credentials ["password"] = userPass [1];

                    successful &= Successful.TryProcess(credentials);
                }
                else
                {
                    successful &= Failure.TryProcess(parameters);
                }
            }
            else
            {
                httpParameters.SetStatusCode(401);
                httpParameters.ResponseHeaders ["WWW-Authenticate"] = ResponseHeader;
                successful &= Failure.TryProcess(parameters);
            }

            return(successful);
        }
Пример #6
0
        protected override bool Process(IInteraction parameters)
        {
            IHttpInteraction httpParameters = (IHttpInteraction)parameters.GetClosest(typeof(IHttpInteraction));
            string           authHeader     = httpParameters.RequestHeaders["Authorization"];
            bool             successful     = true;

            if ((authHeader != null) && (authHeader == LoginString))
            {
                successful &= Successful.TryProcess(parameters);
            }
            else
            {
                httpParameters.SetStatusCode(401);
                httpParameters.ResponseHeaders ["WWW-Authenticate"] = ResponseHeader;
                successful &= Failure.TryProcess(parameters);
            }

            return(successful);
        }
Пример #7
0
        protected override bool Process(IInteraction parameters)
        {
            bool successful = true;

            try {
                int     serviceId = GetServiceInt(parameters, ServiceIdKey);
                Service service   = GetServiceById(serviceId);

                KeyValuePair <string, object> pair = GetKeyvalueFromContext(parameters);

                service.GetSettings()[pair.Key] = pair.Value;

                successful &= Successful.TryProcess(parameters);
            } catch (ControlException ex) {
                successful &= Failure.TryProcess(new FailureInteraction(parameters, ex));
            }

            return(successful);
        }
Пример #8
0
        protected override bool Process(IInteraction parameters)
        {
            string password     = "";
            string passwordhash = "";

            if (parameters.TryGetFallbackString(
                    this.PlainVariable, out password))
            {
                if (parameters.TryGetFallbackString(
                        this.HashVariable, out passwordhash))
                {
                    if (BCryptHasher.Verify(password, passwordhash))
                    {
                        return(Successful.TryProcess(parameters));
                    }
                }
            }

            return(Failure.TryProcess(parameters));
        }
Пример #9
0
        protected override bool Process(IInteraction parameters)
        {
            bool         success = true;
            object       dateTimeCandidate;
            IInteraction targetOutgoing;

            if (parameters.TryGetFallback(this.VariableName, out dateTimeCandidate) && dateTimeCandidate is DateTime)
            {
                if (parameters.TryGetClosest(typeof(IOutgoingBodiedInteraction), out targetOutgoing))
                {
                    IOutgoingBodiedInteraction target = (IOutgoingBodiedInteraction)targetOutgoing;
                    DateTime source = (DateTime)dateTimeCandidate;

                    byte[] formatted = target.Encoding.GetBytes(source.ToString(this.DateTimeFormat));
                    target.OutgoingBody.Write(formatted, 0, formatted.Length);

                    success &= (Successful == null) || Successful.TryProcess(parameters);
                }
                else
                {
                    success &= (Failure == null) || Failure.TryProcess(parameters);
                }
            }
            else
            {
                string actualValueType;

                if (dateTimeCandidate == null)
                {
                    actualValueType = "NULL";
                }
                else
                {
                    actualValueType = dateTimeCandidate.GetType().ToString();
                }

                success &= (Failure == null) || Failure.TryProcess(parameters);
            }

            return(success);
        }
Пример #10
0
        protected override bool Process(IInteraction parameters)
        {
            bool   successful = true;
            string uriString;

            if (successful &= TryProduceURI(parameters, out uriString))
            {
                HttpWebRequest request = ProduceRequest(parameters, uriString);

                using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) {
                    int statusInt = (int)response.StatusCode;

                    HTTPResponseInteraction responseInteraction;
                    responseInteraction = new HTTPResponseInteraction(request, response, parameters);

                    successful = (statusInt >= 200) && (statusInt < 300);
                    successful = successful && Successful.TryProcess(responseInteraction);
                    successful = successful || Failure.TryProcess(responseInteraction);
                }
            }

            return(successful);
        }
Пример #11
0
 void Start()
 {
     Successful.TryProcess(new SimpleInteraction(null, "crontab", Crontab));
 }