Esempio n. 1
0
 public override string ToString()
 {
     return(string.Format("DEPLOYMENT RESULT: {0} === EXECUTING TYPE: {2} === ERROR: {3}",
                          Successful.ToString(),
                          ExecutingType.Name,
                          Error));
 }
Esempio n. 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));
            }
        }
Esempio n. 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);
        }
Esempio n. 4
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (Successful != false)
            {
                hash ^= Successful.GetHashCode();
            }
            if (ErrorMessage.Length != 0)
            {
                hash ^= ErrorMessage.GetHashCode();
            }
            if (Token.Length != 0)
            {
                hash ^= Token.GetHashCode();
            }
            if (Path.Length != 0)
            {
                hash ^= Path.GetHashCode();
            }
            hash ^= returnItems_.GetHashCode();
            if (File.Length != 0)
            {
                hash ^= File.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Esempio n. 5
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);
        }
Esempio n. 6
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));
            }
        }
Esempio n. 7
0
        // happy path
        public string ToReport()
        {
            var sb = new StringBuilder();

            Successful.OrderByDescending(x => x.Miles).ToList().ForEach(x => sb.AppendLine($"{x.Driver}: {x.Miles:0} miles @ {x.MilesPerHour:0} mph"));
            ZeroMilesDrivers.ForEach(x => sb.AppendLine($"{x}: 0 miles"));
            return(sb.ToString());
        }
Esempio n. 8
0
        private void AsyncCallback(IRestResponse response)
        {
            var doc = ProcessResponse(response);

            if (doc != null)
            {
                Successful?.Invoke(doc);
            }
        }
Esempio n. 9
0
        private async void ROnCourseRegisterUpdate(StudentController.UpdateResult result, string e)
        {
            if (result == StudentController.UpdateResult.Updated)
            {
                var suc = new Successful(e);
                await Navigation.PushModalAsync(suc);

                await suc.Wait();

                return;
            }

            await DisplayAlert("Error", e, "Ok");
        }
Esempio n. 10
0
        /// <summary>
        /// Gets the hash code
        /// </summary>
        /// <returns>Hash code</returns>
        public override int GetHashCode()
        {
            unchecked // Overflow is fine, just wrap
            {
                var hashCode = 41;
                // Suitable nullity checks etc, of course :)

                hashCode = hashCode * 59 + Successful.GetHashCode();
                if (Notes != null)
                {
                    hashCode = hashCode * 59 + Notes.GetHashCode();
                }
                return(hashCode);
            }
        }
        public override string ToString()
        {
            string s = base.ToString() + " ";

            if (item != null)
            {
                s += item.ToString() + "\n";
            }
            s += "success=" + Successful.ToString();
            if (itemError != null)
            {
                s += "\n" + itemError.ToString() + "\n" + itemError.StackTrace;
            }
            return(s);
        }
        public override string ToString()
        {
            string s = base.ToString() + " ";

            s += "success=" + Successful.ToString();
            if (JobError != null)
            {
                s += "\n" + JobError.ToString() + "\n" + JobError.StackTrace;
            }
            if (Stats != null)
            {
                s += "\n" + Stats.ToString();
            }
            return(s);
        }
Esempio n. 13
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);
        }
        public override int GetHashCode()
        {
            int hash = 1;

            if (Successful != false)
            {
                hash ^= Successful.GetHashCode();
            }
            hash ^= addedKeys_.GetHashCode();
            hash ^= replacedKeys_.GetHashCode();
            hash ^= deletedKeys_.GetHashCode();
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Esempio n. 15
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);
        }
Esempio n. 16
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);
        }
Esempio n. 17
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));
        }
Esempio n. 18
0
        public void Execute()
        {
            for (var retry = 0; retry <= retries; retry++)
            {
                try
                {
                    action(retry);
                    Successful?.Invoke(this, new RetryArgs(attempt));
                    attempt = 0;
                    return;
                }
                catch (Exception exception)
                {
                    exceptionAction(exception, retry);
                    attempt = retry;
                }

                Failed?.Invoke(this, new RetryArgs(attempt));
            }
        }
Esempio n. 19
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);
        }
Esempio n. 20
0
        private async Task <MTConnectAssets.Document> ProcessResponse(HttpResponseMessage response)
        {
            if (response != null)
            {
                if (!response.IsSuccessStatusCode)
                {
                    ConnectionError?.Invoke(new Exception(response.ReasonPhrase));
                }
                else if (response.Content != null)
                {
                    string xml = await response.Content.ReadAsStringAsync();

                    if (!string.IsNullOrEmpty(xml))
                    {
                        // Process MTConnectAssets Document
                        var doc = MTConnectAssets.Document.Create(xml);
                        if (doc != null)
                        {
                            doc.UserObject = UserObject;
                            doc.Url        = response.RequestMessage.RequestUri.ToString();
                            Successful?.Invoke(doc);
                            return(doc);
                        }
                        else
                        {
                            // Process MTConnectError Document (if MTConnectDevices fails)
                            var errorDoc = MTConnectError.Document.Create(xml);
                            if (errorDoc != null)
                            {
                                errorDoc.UserObject = UserObject;
                                errorDoc.Url        = response.RequestMessage.RequestUri.ToString();
                                Error?.Invoke(errorDoc);
                            }
                        }
                    }
                }
            }

            return(null);
        }
Esempio n. 21
0
        /// <summary>
        /// Returns true if ContactLogInformationDetails instances are equal
        /// </summary>
        /// <param name="other">Instance of ContactLogInformationDetails to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(ContactLogInformationDetails other)
        {
            if (other is null)
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Successful == other.Successful ||

                     Successful.Equals(other.Successful)
                     ) &&
                 (
                     Notes == other.Notes ||
                     Notes != null &&
                     Notes.Equals(other.Notes)
                 ));
        }
Esempio n. 22
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);
        }
Esempio n. 23
0
 void Start()
 {
     Successful.TryProcess(new SimpleInteraction(null, "crontab", Crontab));
 }
Esempio n. 24
0
 void OnSuccessful(object sender, TEventArgs e)
 {
     Successful?.Invoke(this, e);
 }
Esempio n. 25
0
 protected void OnSuccessful(TEventArgs arg) => Successful?.Invoke(this, arg);
Esempio n. 26
0
 public override string AsString()
 {
     return(Successful.ToString());
 }
Esempio n. 27
0
 public void OnSuccess(Java.Lang.Object result)
 {
     Successful?.Invoke(this, new EventArgs());
 }
Esempio n. 28
0
 => Equals(Successful, other.Successful) && Equals(Failure, other.Failure);