private void CreateHeaderGeneric(IReportable item, int row)
        {
            IEnumerable <PropertyInfo> itemProperties = item.GetType().GetProperties()
                                                        .Where(p => p.IsDefined(typeof(ReportHeaderPropertyAttribute), false));

            ////InsertRow(row); - THE INSERTION IS MADE BY THE OVERLOADS HOLDING IT, so it can specify styles if necessary
            foreach (var property in itemProperties)
            {
                var attr = (ReportHeaderPropertyAttribute)Attribute.GetCustomAttribute(property, typeof(ReportHeaderPropertyAttribute));

                string address     = string.Empty;
                string firstColumn = attr.Column;
                if (attr.Merged)
                {
                    //to merge cells if neccessary
                    string lastColumn = attr.LastColumn;
                    address = firstColumn + row + ":" + lastColumn + row;
                }
                else
                {
                    address = firstColumn + row;
                }

                Cells[address].Value = attr.Value;
                Cells[address].Merge = attr.Merged;
            }
        }
        void WriteReportable(IReportable reportable, int currentIndentLevel = 0)
        {
            if (reportable == null)
            {
                throw new ArgumentNullException(nameof(reportable));
            }

            var performances = new [] {
                ReportableType.Success,
                ReportableType.SuccessWithResult,
                ReportableType.Failure,
                ReportableType.FailureWithError,
            };

            if (reportable.Type == ReportableType.GainAbility)
            {
                WriteGainAbility(reportable, currentIndentLevel);
            }
            else if (performances.Contains(reportable.Type))
            {
                WritePerformance(reportable, currentIndentLevel);
            }
            else
            {
                throw new ArgumentException(Resources.ExceptionFormats.ReportableMustBeGainAbilityOrPerformance);
            }
        }
Beispiel #3
0
 public async Task ValidateReportViolationAsync(IReportable reportObject)
 {
     if (!await CanReportViolationAsync(reportObject))
     {
         throw buildException();
     }
 }
Beispiel #4
0
        public IEnumerable <string> GetTags(IReportable reportable, IExecutionContext context)
        {
            if (configuration.Tags.HasFlag(Tags.Category))
            {
                foreach (var category in reportable.Category)
                {
                    yield return(category);
                }
            }
            if (configuration.Tags.HasFlag(Tags.Url))
            {
                yield return(GetFormattedUrl(context.Driver));
            }
            if (configuration.Tags.HasFlag(Tags.Topic))
            {
                yield return(context.TopicId);
            }

            if (configuration.CustomTags != null)
            {
                foreach (var tag in configuration.CustomTags)
                {
                    yield return(tag);
                }
            }
        }
        void WritePerformance(IReportable reportable, int currentIndentLevel)
        {
            WriteIndent(currentIndentLevel);
            WritePerformanceType(reportable, currentIndentLevel);

            writer.Write(reportable.Report);
            writer.WriteLine();

            if (reportable.Type == ReportableType.SuccessWithResult)
            {
                WriteResult(reportable, currentIndentLevel);
            }
            else if (reportable.Type == ReportableType.Failure)
            {
                WriteFailure(reportable, currentIndentLevel);
            }
            else if (reportable.Type == ReportableType.FailureWithError && !reportable.Reportables.Any())
            {
                WriteFailure(reportable, currentIndentLevel);
            }

            foreach (var child in reportable.Reportables)
            {
                WriteReportable(child, currentIndentLevel + 1);
            }
        }
        protected ExcelRow CreateTableHeader(IReportable item, int row, int copyStylesFromRow)
        {
            ExcelRow resultRow = InsertRow(row, copyStylesFromRow);

            CreateHeaderGeneric(item, row);

            return(resultRow);
        }
        protected ExcelRow PopulateLine(IReportable item, int row, ExcelNamedStyleXml namedStyle)
        {
            ExcelRow resultRow = InsertRow(row, namedStyle);

            PopulateLineGeneric(item, row);

            return(resultRow);
        }
        protected ExcelRow PopulateLine(IReportable item, int row, ExcelRow copyStylesFromRow)
        {
            ExcelRow resultRow = InsertRow(row, copyStylesFromRow);

            PopulateLineGeneric(item, row);

            return(resultRow);
        }
        protected ExcelRow CreateTableHeader(IReportable item, int row, ExcelNamedStyleXml namedStyle)
        {
            ExcelRow resultRow = InsertRow(row, namedStyle);

            CreateHeaderGeneric(item, row);

            return(resultRow);
        }
        void WriteGainAbility(IReportable reportable, int currentIndentLevel)
        {
            WriteIndent(currentIndentLevel);
            WritePerformanceType(reportable, currentIndentLevel);

            writer.Write(reportable.Report);
            writer.WriteLine();
        }
        protected ExcelRow PopulateLine(IReportable item, int row)
        {
            ExcelRow resultRow = InsertRow(row);

            this.PopulateLineGeneric(item, row);

            return(resultRow);
        }
Beispiel #12
0
        public static FinderToken GetFinderToken(this IReportable @object)
        {
            var implementation = @object.Select(
                (v => v is Commentary, Implementation.COMMENTARY),
                (v => v is Profile, Implementation.PROFILE),
                (v => v is Post, Implementation.POST)).Single();

            return(new FinderToken(Interface.MODERATABLE_OBJECT, implementation, @object.Id));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="T:CSF.Screenplay.Reporting.Models.ReportableModel"/> class.
        /// </summary>
        /// <param name="reportable">Reportable.</param>
        public ReportableModel(IReportable reportable)
        {
            if (reportable == null)
            {
                throw new ArgumentNullException(nameof(reportable));
            }

            this.reportable = reportable;
        }
Beispiel #14
0
        /// <inheritdoc />
        /// <exception cref="T:System.Exception">
        /// ServiceConsumerFactory.Create returned null/invalid IHmsCloudService reference.
        /// Check WCF HMS configuration.
        /// </exception>
        public void SendCasinoDataReport(IReportable reportable)
        {
            var dataReport = reportable as CasinoDataReport;

            if (null == dataReport)
            {
                return;
            }

            using (
                var cloudServiceProxy = ServiceConsumerFactory.Create <IHmsCloudService>(() => new HmsCloudServerProxy())
                )
            {
                try
                {
                    if (cloudServiceProxy?.Operations == null)
                    {
                        throw new Exception(
                                  "ServiceConsumerFactory.Create returned null/invalid IHmsCloudService reference. Check WCF HMS configuration.");
                    }

                    // The TransactionScope here will provide behavior such that - if/when the call to
                    // DataAggregator.SuccessfulCasinoDataReport fails for some reason (e.g., problem
                    // writing to the database) - the transactional WCF/MSMQ message delivery will be
                    // rolled back (i.e., the messages will be discarded from the client-side MQ)
                    var txnOptions = new TransactionOptions {
                        IsolationLevel = IsolationLevel.RepeatableRead
                    };
                    using (var txnScope = new TransactionScope(TransactionScopeOption.Required, txnOptions))
                    {
                        cloudServiceProxy.Operations.ReportCasinoData(dataReport);
                        DataAggregator.SuccessfulCasinoDataReport(reportable.ReportGuid);

                        txnScope.Complete();
                    }
                }
                catch (FaultException fe)
                {
                    Logger.Warn($"Service operation ReportCasinoData threw a fault: [{fe.Message}]");
                    DataAggregator.UnsuccessfulCasinoDataReport(reportable.ReportGuid);
                }
                catch (Exception ex)
                {
                    Logger.Warn(
                        $"An unexpected error occurred while calling the ReportCasinoData service operation: [{ex.Message}]");
                    var innerEx = ex.InnerException;
                    while (null != innerEx)
                    {
                        Logger.Warn($"[{innerEx.Message}]");
                        innerEx = innerEx.InnerException;
                    }

                    DataAggregator.UnsuccessfulCasinoDataReport(reportable.ReportGuid);
                    Logger.Warn($"Stack Trace: [{Environment.StackTrace}]");
                }
            }
        }
Beispiel #15
0
        /// <summary>
        /// Sends the casino data report.
        /// </summary>
        /// <param name="reportable">The casino data report.</param>
        /// <inheritdoc />
        public void SendCasinoDataReport(IReportable reportable)
        {
            var casinoDataReport = reportable as CasinoDataReport;

            if (null == casinoDataReport)
            {
                return;
            }

            ExportCasinoDataReportAsJson(casinoDataReport);
        }
Beispiel #16
0
        private void AddDeviceChangeEvent(IReportable reportable, State state, DateTime dateTime)
        {
            if (!_eventStorage.ContainsKey(reportable))
            {
                _eventStorage.Add(reportable,
                                  new List <KeyValuePair <DateTime, State> > {
                    new KeyValuePair <DateTime, State>(dateTime, state)
                });
            }

            _eventStorage[reportable].Add(new KeyValuePair <DateTime, State>(dateTime, state));
        }
        void WriteFailure(IReportable reportable, int currentIndentLevel)
        {
            WriteResultOrFailureIndent(currentIndentLevel);

            if (reportable.Error == null)
            {
                writer.WriteLine("FAILED");
                return;
            }

            writer.WriteLine("FAILED: {0}", reportable.Error);
        }
Beispiel #18
0
        async Task <IActionResult> reportAsync(IReportable reportObject)
        {
            await S.Permissions.ValidateReportAsync(reportObject);

            Report report;
            var    reportingUser = await S.UserManager.GetUserAsync(User);

            if (reportObject is Post post)
            {
                report = new Report(reportingUser, post.Author, reportObject);
            }
            else if (reportObject is Profile profile)
            {
                var owner = await S.Db.Users.FirstOrDefaultAsync(u => u.Profile.Id == profile.Id);

                report = new Report(reportingUser, owner, reportObject);
            }
            else if (reportObject is Commentary commentary)
            {
                report = new Report(reportingUser, commentary.Author, reportObject);
                commentary.IsHidden = commentary.IsHidden
                    ? true
                    : S.Decisions.ShouldHide(commentary);
            }
            else
            {
                throw new InvalidOperationException("Can't create report for object of such type");
            }

            S.Db.Reports.Add(report);
            await S.Repository.AddUserActionAsync(reportingUser, new UserAction(ActionType.REPORT, reportObject));

            if (S.Decisions.ShouldReportToModerator(reportObject))
            {
                var moderators   = reportObject.Author.ModeratorsInChargeGroup;
                var alreadyAdded = moderators.EntitiesToCheck.FirstOrDefault(e => e.Entity == reportObject);
                if (alreadyAdded == null)
                {
                    moderators.AddEntityToCheck(reportObject, CheckReason.TOO_MANY_REPORTS);
                }
                else
                {
                    alreadyAdded.AddTime = DateTime.UtcNow;
                }
            }
            await S.Db.SaveChangesAsync();

            LayoutModel.AddMessage("Report has been submitted");

            return(Redirect(S.History.GetLastURL()));
        }
Beispiel #19
0
        public async Task <bool> CanReportViolationAsync(IReportable reportObject)
        {
            var currentUser = await getCurrentUserOrNullAsync();

            if (currentUser == null || currentUser.Status.State != ProfileState.ACTIVE)
            {
                return(false);
            }
            else
            {
                return(await isNotDeletedAsync(reportObject) &&
                       currentUser.Id != reportObject.Author.Id &&
                       currentUser.Role >= Role.MODERATOR &&
                       (reportObject.As <IModeratable>()?.ModerationInfo?.State ?? ModerationState.MODERATED) == ModerationState.MODERATED);
            }
        }
Beispiel #20
0
        public async Task <bool> CanReportAsync(IReportable reportObject)
        {
            var currentUser = await getCurrentUserOrNullAsync();

            if (currentUser == null || currentUser.Status.State != ProfileState.ACTIVE)
            {
                return(false);
            }
            else
            {
                return(await isNotDeletedAsync(reportObject) &&
                       currentUser.Id != reportObject.Author.Id &&
                       !reportObject.Reports.Any(r => r.Reporter.Id == currentUser.Id) && // Already reported
                       (reportObject.As <IModeratable>()?.ModerationInfo?.State ?? ModerationState.MODERATED) == ModerationState.MODERATED &&
                       currentUser.Role == Role.USER);
            }
        }
        public void Report(IReportable reportable, int[] affectedUserIds)
        {
            _activityLogService.LogActivity(reportable);

            var notification = reportable.Compose(_serviceProvider);

            foreach (int userId in affectedUserIds)
            {
                _notificationSenderService.SendNotificationAsync(new CreateUserNotificationDto
                {
                    isLink  = notification.isLink,
                    Link    = notification.Link,
                    Message = notification.Message,
                    Subject = notification.Subject,
                    UserId  = userId
                });
            }
        }
Beispiel #22
0
        public static void Add(string name, IReportable obj)
        {
            Dictionary <string, IReportable> obj2;

            Monitor.Enter(obj2 = reportableObjects);
            try
            {
                if (reportableObjects.ContainsKey(name))
                {
                    reportableObjects[name] = obj;
                }
                else
                {
                    reportableObjects.Add(name, obj);
                }
            }
            finally
            {
                Monitor.Exit(obj2);
            }
        }
Beispiel #23
0
        public ReportModel(IReportable engine, ActivityModel activityModel)
        {
            _activityModel = activityModel;

            _engine = engine;
            _engine.StatusUpdate   += engine_StatusUpdate;
            _engine.MessageUpdate  += engine_MessageUpdate;
            _engine.GotTick        += engine_GotTick;
            _engine.GotFill        += engine_GotFill;
            _engine.GotOrder       += engine_GotOrder;
            _engine.GotPosition    += engine_GotPosition;
            _engine.GotPlot        += engine_GotPlot;
            _engine.GotIndicators  += engine_GotIndicators;
            _engine.EngineReset    += engine_Reset;
            _engine.EngineComplete += engine_Complete;

            // Default each dispatchable type to the current thread's dispatcher.  Any controls which register a dispatcher will change this.
            var dispatchValues = Enum.GetValues(typeof(DispatchableType)).Cast <DispatchableType>();

            foreach (var _value in dispatchValues)
            {
                _dispatchingMap[_value] = Dispatcher.CurrentDispatcher;
            }
        }
Beispiel #24
0
 public Long(IReportable implementation) : base(implementation)
 {
 }
Beispiel #25
0
 /// <summary>
 /// Report a single, named, reportable value.
 /// </summary>
 public static void Value([Localizable(true)] string name, IReportable reportable)
 {
     CountCallsToValues.Increment();
     reportable.ReportValue(0, name);
 }
 void WriteResult(IReportable reportable, int currentIndentLevel)
 {
     WriteResultOrFailureIndent(currentIndentLevel);
     writer.WriteLine("Result: " + reportable.Result);
 }
 void WritePerformanceType(IReportable reportable, int currentIndentLevel)
 {
     writer.Write("{0,5} ", GetPerformanceTypeString(reportable.Category, currentIndentLevel));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ApplicationEventMessage" /> class.
 /// </summary>
 /// <param name="reportableObject">
 /// An object representing the reportable event.
 /// </param>
 /// <param name="correlationIdentifier">
 /// A unique identifier that is assigned to related messages.
 /// </param>
 /// <param name="identifier">
 /// A unique identifier for the message.
 /// </param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="reportableObject" /> is <see langword="null" />.
 /// </exception>
 /// <exception cref="ArgumentOutOfRangeException">
 /// <paramref name="correlationIdentifier" /> is equal to <see cref="Guid.Empty" /> -or- <paramref name="identifier" /> is
 /// equal to <see cref="Guid.Empty" />.
 /// </exception>
 public ApplicationEventMessage(IReportable reportableObject, Guid correlationIdentifier, Guid identifier)
     : this(reportableObject.RejectIf().IsNull(nameof(reportableObject)).TargetArgument.ComposeReportableEvent(), correlationIdentifier, identifier)
 {
     return;
 }
Beispiel #29
0
 protected Report(IReportable implementation)
 {
     Implementation = implementation;
 }
Beispiel #30
0
 public Violation(User reporter, User reportObjectOwner, IReportable reportObject, string description) : base(reporter, reportObjectOwner, reportObject)
 {
     Description = description ?? throw new ArgumentNullException(nameof(description));
 }