IEnumerable<FailureReason> ParseMessage (string message)
		{
			var reasons = message.Split (new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);

			var results = new FailureReason[reasons.Length];

			for (int i = 0; i < reasons.Length; i++) {
				var reason = reasons [i];
				var listBeginsAtIndex = reason.LastIndexOf (":");
				var explanation = reason.Substring (0, listBeginsAtIndex);
				var listGlob = reason.Trim().Substring (listBeginsAtIndex + 2 /* because there's a space that follows the colon. */);
				var ids = listGlob.Split (new[] { ", " }, StringSplitOptions.RemoveEmptyEntries);

				results [i] = new FailureReason { Message = explanation, RelatedIds = ids };
			}

			return results;
		}
 public LoginException(FailureReason reason, string message)
     : base(message)
 {
     Reason = reason;
 }
示例#3
0
        private void ExceptionTestHelper(
            ExceptionCondition exceptionCondition,
            RuntimeConditions runtimeConditions,
            FailureReason expectedExitReason = FailureReason.ExceptionsDidNotHaltAnalysis,
            AnalyzeOptions analyzeOptions = null)
        {
            AnalyzeCommand.DefaultRuleAssemblies = new Assembly[] { typeof(ExceptionRaisingRule).Assembly };
            ExceptionRaisingRule.s_exceptionCondition = exceptionCondition;
            analyzeOptions = analyzeOptions ?? new AnalyzeOptions()
            {
                BinaryFileSpecifiers = new string[0]
            };

            var command = new AnalyzeCommand();
            int result = command.Run(analyzeOptions);

            int expectedResult =
                (runtimeConditions & RuntimeConditions.Fatal) == RuntimeConditions.NoErrors ?
                    AnalyzeCommand.SUCCESS : AnalyzeCommand.FAILURE;

            Assert.Equal(runtimeConditions, command.RuntimeErrors);
            Assert.Equal(expectedResult, result);

            if (expectedExitReason != FailureReason.ExceptionsDidNotHaltAnalysis)
            {
                Assert.NotNull(command.ExecutionException);

                if (expectedExitReason != FailureReason.UnhandledExceptionInEngine)
                {
                    var eax = command.ExecutionException as ExitApplicationException<FailureReason>;
                    Assert.NotNull(eax);
                }
            }
            else
            {
                Assert.Null(command.ExecutionException);
            }
            ExceptionRaisingRule.s_exceptionCondition = ExceptionCondition.None;
            AnalyzeCommand.DefaultRuleAssemblies = null;
        }
示例#4
0
 public void ParseFailed(Language lang, Word word, FailureReason reason, Allomorph allomorph, object failureObj)
 {
     ((Trace) word.CurrentTrace).Children.Add(new Trace(TraceType.ParseFailed, lang) {Output = word, FailureReason = reason});
 }
示例#5
0
 public void MorphologicalRuleNotApplied(IMorphologicalRule rule, int subruleIndex, Word input, FailureReason reason, object failureObj)
 {
     ((Trace) input.CurrentTrace).Children.Add(new Trace(TraceType.MorphologicalRuleSynthesis, rule) {SubruleIndex = subruleIndex, Input = input, FailureReason = reason});
 }
示例#6
0
		public void MorphologicalRuleNotApplied(IMorphologicalRule rule, int subruleIndex, Word input, FailureReason reason, object failureObj)
		{
			var trace = new XElement("MorphologicalRuleSynthesisTrace",
				CreateMorphologicalRuleElement(rule));
			var aprule = rule as AffixProcessRule;
			if (aprule != null)
				trace.Add(CreateAllomorphElement(subruleIndex == -1 ? aprule.Allomorphs.Last() : aprule.Allomorphs[subruleIndex]));
			trace.Add(new XElement("Output", "*None*"));
			switch (reason)
			{
				case FailureReason.RequiredSyntacticFeatureStruct:
					Debug.Assert(aprule != null);
					var requiredFS = (FeatureStruct) failureObj;
					var requiredPos = requiredFS.GetValue<SymbolicFeatureValue>("pos");
					var inputPos = input.SyntacticFeatureStruct.GetValue<SymbolicFeatureValue>("pos");
					if (requiredPos.Values.Intersect(inputPos.Values).Any())
					{
						trace.Add(new XElement("FailureReason", new XAttribute("type", "inflFeats"),
							CreateInflFeaturesElement("InflFeatures", input.SyntacticFeatureStruct),
							CreateInflFeaturesElement("RequiredInflFeatures", requiredFS)));
					}
					else
					{
						trace.Add(new XElement("FailureReason", new XAttribute("type", "pos"),
							new XElement("Pos", string.Join(", ", inputPos.Values.Select(s => s.Description))),
							new XElement("RequiredPos", string.Join(", ", requiredPos.Values.Select(s => s.Description)))));
					}
					break;

				case FailureReason.StemName:
					trace.Add(new XElement("FailureReason", new XAttribute("type", "fromStemName"),
						new XElement("StemName", failureObj)));
					break;

				case FailureReason.RequiredMprFeatures:
					Debug.Assert(aprule != null);
					var group = (MprFeatureGroup) failureObj;
					trace.Add(group.Name == "lexEntryInflTypes" ? new XElement("FailureReason", new XAttribute("type", "requiredInflType"))
						: CreateMprFeaturesFailureElement(true, group, aprule.Allomorphs[subruleIndex].RequiredMprFeatures, input));
					break;

				case FailureReason.ExcludedMprFeatures:
					trace.Add(new XElement("FailureReason", new XAttribute("type", "excludedInflType")));
					break;

				case FailureReason.Pattern:
					Debug.Assert(aprule != null);
					var env = (string) aprule.Allomorphs[subruleIndex].Properties["Env"];
					var prefixEnv = (string) aprule.Allomorphs[subruleIndex].Properties["PrefixEnv"];
					var suffixEnv = (string) aprule.Allomorphs[subruleIndex].Properties["SuffixEnv"];
					if (env != null || prefixEnv != null || suffixEnv != null)
					{
						var reasonElem = new XElement("FailureReason", new XAttribute("type", "environment"));
						if (env != null)
							reasonElem.Add(new XElement("Environment", env));
						if (prefixEnv != null)
							reasonElem.Add(new XElement("Environment", env));
						if (suffixEnv != null)
							reasonElem.Add(new XElement("Environment", env));
						trace.Add(reasonElem);
					}
					else
					{
						trace.Add(new XElement("FailureReason", new XAttribute("type", "affixProcess")));
					}
					break;

				default:
					return;
			}
			((XElement) input.CurrentTrace).Add(trace);
		}
 public FailureDetail(FailureReason reason, params KeyValuePair <string, object>[] messages) : this(reason, null, messages)
 {
 }
 public override void OnFileShareFailure(string fileName, FailureReason failureReason)
 {
     Debug.Log("Failed to share file " + fileName + " for reason " + failureReason);
 }
 public override void OnSharedFileDownloadFailure(ulong sharedFileID, FailureReason failureReason)
 {
     Debug.Log("Failed to download file with ID " + sharedFileID + " for reason " + failureReason);
     userID = null;
 }
示例#10
0
 public FetchException(FailureReason reason, string message, Exception innerException) :
     base(message, innerException)
 {
     Reason = reason;
 }
示例#11
0
        internal async Task <HttpOperationResponse> SetReasonInternalAsync(
            string analysisName,
            string analysisType,
            string job,
            FailureReason reason,
            string workitem,
            CancellationToken cancellationToken = default
            )
        {
            if (string.IsNullOrEmpty(analysisName))
            {
                throw new ArgumentNullException(nameof(analysisName));
            }

            if (string.IsNullOrEmpty(analysisType))
            {
                throw new ArgumentNullException(nameof(analysisType));
            }

            if (string.IsNullOrEmpty(job))
            {
                throw new ArgumentNullException(nameof(job));
            }

            if (reason == default)
            {
                throw new ArgumentNullException(nameof(reason));
            }

            if (string.IsNullOrEmpty(workitem))
            {
                throw new ArgumentNullException(nameof(workitem));
            }


            var _path = "/api/2018-03-14/analysis/{job}/{analysisType}/reason";

            _path = _path.Replace("{job}", Client.Serialize(job));
            _path = _path.Replace("{analysisType}", Client.Serialize(analysisType));

            var _query = new QueryBuilder();

            if (!string.IsNullOrEmpty(workitem))
            {
                _query.Add("workitem", Client.Serialize(workitem));
            }
            if (!string.IsNullOrEmpty(analysisName))
            {
                _query.Add("analysisName", Client.Serialize(analysisName));
            }

            var _uriBuilder = new UriBuilder(Client.BaseUri);

            _uriBuilder.Path  = _uriBuilder.Path.TrimEnd('/') + _path;
            _uriBuilder.Query = _query.ToString();
            var _url = _uriBuilder.Uri;

            HttpRequestMessage  _req = null;
            HttpResponseMessage _res = null;

            try
            {
                _req = new HttpRequestMessage(HttpMethod.Put, _url);

                string _requestContent = null;
                if (reason != default)
                {
                    _requestContent = Client.Serialize(reason);
                    _req.Content    = new StringContent(_requestContent, Encoding.UTF8)
                    {
                        Headers =
                        {
                            ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8"),
                        },
                    };
                }

                if (Client.Credentials != null)
                {
                    await Client.Credentials.ProcessHttpRequestAsync(_req, cancellationToken).ConfigureAwait(false);
                }

                _res = await Client.SendAsync(_req, cancellationToken).ConfigureAwait(false);

                string _responseContent;
                if (!_res.IsSuccessStatusCode)
                {
                    _responseContent = await _res.Content.ReadAsStringAsync().ConfigureAwait(false);

                    var ex = new RestApiException(
                        new HttpRequestMessageWrapper(_req, _requestContent),
                        new HttpResponseMessageWrapper(_res, _responseContent));
                    HandleFailedSetReasonRequest(ex);
                    HandleFailedRequest(ex);
                    Client.OnFailedRequest(ex);
                    throw ex;
                }
                _responseContent = await _res.Content.ReadAsStringAsync().ConfigureAwait(false);

                return(new HttpOperationResponse
                {
                    Request = _req,
                    Response = _res,
                });
            }
            catch (Exception)
            {
                _req?.Dispose();
                _res?.Dispose();
                throw;
            }
        }
示例#12
0
 public FetchException(FailureReason reason, string message) : base(message)
 {
     Reason = reason;
 }
示例#13
0
 public override void OnLobbyDataRetrieveFailure(GalaxyID lobbyID, FailureReason failureReason)
 {
     Debug.LogWarning("LobbyDataRetrieveListenerBrowsing failure reason: " + failureReason);
 }
 public FailureDetail(FailureReason reason, Exception exception, params KeyValuePair <string, object>[] messages)
 {
     Reason    = reason;
     Exception = exception;
     Messages  = messages;
 }
示例#15
0
 public LoginException(FailureReason reason, string message, Exception innerException)
     : base(message, innerException)
 {
     Reason = reason;
 }
示例#16
0
 public void MorphologicalRuleNotApplied(IMorphologicalRule rule, int subruleIndex, Word input, FailureReason reason, object failureObj)
 {
     ((Trace)input.CurrentTrace).Children.Add(new Trace(TraceType.MorphologicalRuleSynthesis, rule)
     {
         SubruleIndex = subruleIndex, Input = input, FailureReason = reason
     });
 }
示例#17
0
		public void PhonologicalRuleNotApplied(IPhonologicalRule rule, int subruleIndex, Word input, FailureReason reason, object failureObj)
		{
			var pruleTrace = new XElement("PhonologicalRuleSynthesisTrace",
				CreateHCRuleElement("PhonologicalRule", rule),
				CreateWordElement("Input", input, false),
				CreateWordElement("Output", input, false));

			var rewriteRule = rule as RewriteRule;
			if (rewriteRule != null)
			{
				RewriteSubrule sr = rewriteRule.Subrules[subruleIndex];
				switch (reason)
				{
					case FailureReason.RequiredSyntacticFeatureStruct:
						pruleTrace.Add(new XElement("FailureReason", new XAttribute("type", "category"),
							new XElement("Category", (FeatureSymbol) input.SyntacticFeatureStruct.GetValue<SymbolicFeatureValue>("pos")),
							new XElement("RequiredCategories", sr.RequiredSyntacticFeatureStruct.GetValue<SymbolicFeatureValue>("pos")
								.Values.Select(pos => new XElement("Category", pos)))));
						break;

					case FailureReason.RequiredMprFeatures:
						pruleTrace.Add(CreateMprFeaturesFailureElement(true, (MprFeatureGroup) failureObj, sr.RequiredMprFeatures, input));
						break;

					case FailureReason.ExcludedMprFeatures:
						pruleTrace.Add(CreateMprFeaturesFailureElement(false, (MprFeatureGroup) failureObj, sr.ExcludedMprFeatures, input));
						break;
				}
			}

			((XElement) input.CurrentTrace).Add(pruleTrace);
		}
        /// <summary>
        /// A helper method that performs the checks and updates associated with password failure 
        /// tracking.
        /// </summary>
        /// <param name="username">The username to update the failure count for.</param>
        /// <param name="reason">The reason why we wish to update the failure count.</param>
        private void UpdateFailureCount(string username, FailureReason reason)
        {
            // The required SQL
            string sql = @"
                            SELECT
                                FailPwdAttemptCount,
                                FailPwdAttemptWindowStart,
                                FailPwdAnswerAttemptCount,
                                FailPwdAnswerAttemptWindowStart
                            FROM
                                aspnet_Membership,
                                aspnet_Users,
                                aspnet_Applications
                            WHERE
                                aspnet_Users.LoweredUsername               = ?
                            AND aspnet_Applications.LoweredApplicationName = ?
                            AND aspnet_Users.UserId                        = aspnet_Membership.UserId
                            AND aspnet_Membership.ApplicationId            = aspnet_Applications.ApplicationId
                           ";

            // Instantiate an Ingres command (using the current connection and transaction) with the SQL
            IngresCommand cmd = new IngresCommand(sql, this.conn);
            cmd.Transaction = this.tran;
            cmd.CommandTimeout = this.config.CommandTimeout;

            // Add the required parameters
            cmd.Parameters.Add("LoweredUsername", DbType.String).Value = username.ToLower();
            cmd.Parameters.Add("LoweredApplicationName", DbType.String).Value = this.config.ApplicationName.ToLower();

            DateTime windowStart = new DateTime();
            int failureCount     = 0;

            // Execute the command as a reader
            IngresDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow);

            if (reader.HasRows)
            {
                reader.Read();

                if (reason == FailureReason.Password)
                {
                    failureCount = DBUtil.ColValAsInt32(reader, "FailPwdAttemptCount");

                    try
                    {
                        windowStart = DBUtil.ColValAsDateTime(reader, "FailPwdAttemptWindowStart");
                    }
                    catch
                    {
                        windowStart = DateTime.Now;
                    }
                }

                if (reason == FailureReason.PasswordAnswer)
                {
                    failureCount = DBUtil.ColValAsInt32(reader,    "FailPwdAnswerAttemptCount");
                    windowStart  = DBUtil.ColValAsDateTime(reader, "FailPwdAnswerAttemptWindowStart");
                }
            }

            // Close the reader and build up a new command
            reader.Close();

            cmd = new IngresCommand();
            cmd.Connection = this.conn;
            cmd.Transaction = this.tran;
            cmd.CommandTimeout = this.config.CommandTimeout;

            DateTime windowEnd = windowStart.AddMinutes(this.config.PasswordAttemptWindow);

            if (failureCount == 0 || DateTime.Now > windowEnd)
            {
                // Start a new failure count and window
                if (reason == FailureReason.Password)
                {
                    // For password failed attempts:
                    cmd.CommandText = @"
                                        UPDATE aspnet_Membership
                                        FROM
                                            aspnet_Applications,
                                            aspnet_Users
                                        SET FailPwdAttemptCount       = ?,
                                            FailPwdAttemptWindowStart = ?
                                        WHERE
                                            LoweredUsername                   = ?
                                        AND LoweredApplicationName            = ?
                                        AND aspnet_Applications.ApplicationId = aspnet_Membership.ApplicationId
                                        AND aspnet_Membership.UserId          = aspnet_Users.UserId
                                       ";
                }

                if (reason == FailureReason.PasswordAnswer)
                {
                    // For password answer failed attempts:
                    cmd.CommandText = @"
                                        UPDATE aspnet_Membership
                                        FROM
                                            aspnet_Applications,
                                            aspnet_Users
                                        SET FailPwdAnswerAttemptCount       = ?,
                                            FailPwdAnswerAttemptWindowStart = ?
                                        WHERE
                                            aspnet_Users.LoweredUsername               = ?
                                        AND aspnet_Applications.LoweredApplicationName = ?
                                        AND aspnet_Applications.ApplicationId          = aspnet_Membership.ApplicationId
                                        AND aspnet_Membership.UserId                   = aspnet_Users.UserId
                                       ";
                }

                // Ad the required parameters
                cmd.Parameters.Add("Count",                  DbType.Int32).Value    = 1;
                cmd.Parameters.Add("WindowStart",            DbType.DateTime).Value = DateTime.Now;
                cmd.Parameters.Add("LoweredUsername",        DbType.String).Value   = username.ToLower();
                cmd.Parameters.Add("LoweredApplicationName", DbType.String).Value   = this.config.ApplicationName.ToLower();

                // Execute the query and ensure that one row was updated
                if (cmd.ExecuteNonQuery() != 1)
                {
                    throw new ProviderException(Messages.UnableToUpdateFailureCountAndWindowStart);
                }
            }
            else
            {   // Not the first failure or still inside the window

                // If the failure accout is now greater than or equal to the max attempts allowed
                // then lock the user out
                if (failureCount++ >= this.config.MaxInvalidPasswordAttempts)
                {
                    // Password attempts have exceeded the failure threshold. Lock out
                    // the user.
                    cmd.CommandText = @"
                                        UPDATE aspnet_Membership
                                        FROM
                                            aspnet_Applications,
                                            aspnet_Users
                                        SET IsLockedOut       = ?,
                                            LastLockoutDate   = ?
                                        WHERE
                                            aspnet_Users.LoweredUsername               = ?
                                        AND aspnet_Applications.LoweredApplicationName = ?
                                        AND aspnet_Applications.ApplicationId          = aspnet_Membership.ApplicationId
                                        AND aspnet_Membership.UserId                   = aspnet_Users.UserId
                                       ";

                    cmd.Parameters.Clear();

                    cmd.Parameters.Add("IsLockedOut",            DbType.String).Value   = '1';
                    cmd.Parameters.Add("LastLockoutDate",        DbType.DateTime).Value = DateTime.Now;
                    cmd.Parameters.Add("LoweredUsername",        DbType.String).Value   = username.ToLower();
                    cmd.Parameters.Add("LoweredApplicationName", DbType.String).Value   = this.config.ApplicationName.ToLower();

                    if (cmd.ExecuteNonQuery() < 0)
                    {
                        throw new ProviderException("Unable to lock out user.");
                    }
                }
                else
                {
                    // Otherwise just save the incremented failure count.
                    if (reason == FailureReason.Password)
                    {
                        cmd.CommandText = @"
                                            UPDATE aspnet_Membership
                                            FROM
                                                aspnet_Applications,
                                                aspnet_Users
                                            SET FailPwdAttemptCount = ?
                                            WHERE
                                                aspnet_Users.LoweredUsername               = ?
                                            AND aspnet_Applications.LoweredApplicationName = ?
                                            AND aspnet_Applications.ApplicationId          = aspnet_Membership.ApplicationId
                                            AND aspnet_Membership.UserId                   = aspnet_Users.UserId
                                           ";
                    }

                    if (reason == FailureReason.PasswordAnswer)
                    {
                        cmd.CommandText = @"
                                            UPDATE aspnet_Membership
                                            FROM
                                                aspnet_Applications,
                                                aspnet_Users
                                            SET FailPwdAnswerAttemptCount = ?
                                            WHERE
                                                aspnet_Users.LoweredUsername               = ?
                                            AND aspnet_Applications.LoweredApplicationName = ?
                                            AND aspnet_Applications.ApplicationId          = aspnet_Membership.ApplicationId
                                            AND aspnet_Membership.UserId                   = aspnet_Users.UserId
                                           ";
                    }

                    cmd.Parameters.Clear();

                    cmd.Parameters.Add("Count",                  DbType.Int32).Value  = failureCount;
                    cmd.Parameters.Add("LoweredUsername",        DbType.String).Value = username.ToLower();
                    cmd.Parameters.Add("LoweredApplicationName", DbType.String).Value = this.config.ApplicationName.ToLower();

                    if (cmd.ExecuteNonQuery() != 1)
                    {
                        throw new ProviderException(Messages.UnableToUpdateFailureCount);
                    }
                }
            }
        }
示例#19
0
		public void ParseFailed(Language lang, Word word, FailureReason reason, Allomorph allomorph, object failureObj)
		{
			XElement trace;
			switch (reason)
			{
				case FailureReason.ExcludedAllomorphCoOccurrences:
					var alloRule = (AllomorphCoOccurrenceRule) failureObj;
					trace = CreateParseCompleteElement(word,
						new XElement("FailureReason", new XAttribute("type", "adhocProhibitionRule"),
							new XElement("RuleType", "Allomorph"),
							CreateAllomorphElement(allomorph),
							new XElement("Others", alloRule.Others.Select(CreateAllomorphElement)),
							new XElement("Adjacency", alloRule.Adjacency)));
					break;

				case FailureReason.ExcludedMorphemeCoOccurrences:
					var morphemeRule = (MorphemeCoOccurrenceRule) failureObj;
					trace = CreateParseCompleteElement(word,
						new XElement("FailureReason", new XAttribute("type", "adhocProhibitionRule"),
							new XElement("RuleType", "Morpheme"),
							CreateMorphemeElement(allomorph.Morpheme),
							new XElement("Others", morphemeRule.Others.Select(CreateMorphemeElement)),
							new XElement("Adjacency", morphemeRule.Adjacency)));
					break;

				case FailureReason.RequiredEnvironments:
					trace = CreateParseCompleteElement(word,
						new XElement("FailureReason", new XAttribute("type", "environment"),
							CreateAllomorphElement(allomorph),
							new XElement("Environment", failureObj)));
					break;

				case FailureReason.SurfaceFormMismatch:
					trace = CreateParseCompleteElement(word, new XElement("FailureReason", new XAttribute("type", "formMismatch")));
					break;

				case FailureReason.RequiredSyntacticFeatureStruct:
					trace = CreateParseCompleteElement(word,
						new XElement("FailureReason", new XAttribute("type", "affixInflFeats"),
							CreateAllomorphElement(allomorph),
							CreateInflFeaturesElement("InflFeatures", word.SyntacticFeatureStruct),
							CreateInflFeaturesElement("RequiredInflFeatures", (FeatureStruct) failureObj)));
					break;

				case FailureReason.StemName:
					trace = CreateParseCompleteElement(word,
						new XElement("FailureReason", new XAttribute("type", "stemName"),
							CreateAllomorphElement(allomorph),
							new XElement("StemName", failureObj)));
					break;

				case FailureReason.BoundRoot:
					trace = CreateParseCompleteElement(word, new XElement("FailureReason", new XAttribute("type", "boundStem")));
					break;

				case FailureReason.DisjunctiveAllomorph:
					trace = CreateParseCompleteElement(word,
						new XElement("FailureReason", new XAttribute("type", "disjunctiveAllomorph"),
							CreateWordElement("Word", (Word) failureObj, false)));
					break;

				case FailureReason.PartialParse:
					trace = CreateParseCompleteElement(word, new XElement("FailureReason", new XAttribute("type", "partialParse")));
					break;

				default:
					return;
			}
			((XElement) word.CurrentTrace).Add(trace);
		}
 /// <summary>
 ///   Initializes a new instance of the <see cref="EventHubsException"/> class.
 /// </summary>
 ///
 /// <param name="isTransient"><c>true</c> if the exception should be considered transient; otherwise, <c>false</c>.</param>
 /// <param name="eventHubName">The name of the Event Hub to which the exception is associated.</param>
 /// <param name="reason">The reason for the failure that resulted in the exception.</param>
 ///
 public EventHubsException(bool isTransient,
                           string eventHubName,
                           FailureReason reason) : this(isTransient, eventHubName, null, reason, null)
 {
 }