Exemplo n.º 1
0
 public HashSet <Topic> GetTopics(string actor)
 {
     if (Topics.ContainsKey(actor))
     {
         return(Topics[actor]);
     }
     return(new HashSet <Topic>());
 }
Exemplo n.º 2
0
        public void SelectTopic(string topic)
        {
            if (!Topics.ContainsKey(topic))
            {
                throw new ArgumentException($"Could not find a topic with name: {topic}.");
            }

            SecretWord = Topics[topic].PickRandom();
            RefreshGame();
        }
Exemplo n.º 3
0
 public void AddTopic(string topic, string subtopic = null)
 {
     if (subtopic == null)
     {
         subtopic = string.Empty;
     }
     if (!Topics.ContainsKey(topic))
     {
         Topics[topic] = new HashSet <string>();
     }
     Topics[topic].Add(subtopic);
     Confirmations[topic] = 0;
 }
 protected async Task  BrokerCancellationReg(string topic)
 {
     if (Topics.ContainsKey(topic))
     {
         if (Topics[topic].Count() == 0)
         {
             await _mqttBrokerEntryManger.CancellationReg(topic, NetUtils.GetHostAddress());
         }
     }
     else
     {
         await _mqttBrokerEntryManger.CancellationReg(topic, NetUtils.GetHostAddress());
     }
 }
Exemplo n.º 5
0
 public bool KnowsTopic(string id)
 {
     return(Topics.ContainsKey(id));
 }
Exemplo n.º 6
0
        protected override bool RenderInternal(ref MemoryStream chunk, out string mime)
        {
            mime = null;
            var  tmpfilename           = String.Format("{0}.xlsx", Guid.NewGuid().ToString());
            var  cutoff                = this.DateGenerated;
            bool with_detailed_history = PresentationOptions.HasFlag(ReportPresentationOptions.ShowSubrecords);
            bool suppress_zerolines    = PresentationOptions.HasFlag(ReportPresentationOptions.Suppresszero);

            try
            {
                /* 1. convert the flat data into a less entropic form */
                var emps = new Employees();
                var tops = new Topics();
                /* 1a. persons */
                DataTable tab_pers = Data.Tables[ReportDatatableIdentifiers.REPORT_DATATABLE_TRA001_OVERVIEW_PER];
                foreach (DataRow dr in tab_pers.Rows)
                {
                    var middlename  = dr["Middlename"].ToString();
                    var orgabbrev   = dr["OrgAbbrev"].ToString();
                    var orgshortcap = dr["OrgShortCap"].ToString(); /* (not used) */
                    var orglongcap  = dr["OrgLongCap"].ToString();
                    var orgcap      = orgabbrev;
                    if (orglongcap != orgabbrev)
                    {
                        orgcap = String.Format("{0} {1}", orgcap, orglongcap).TrimEnd();
                    }
                    var emp = new Employee()
                    {
                        PerID     = Convert.ToInt32(dr["PerID"]),
                        Lastname  = dr["Lastname"].ToString(),
                        Firstname = dr["Firstname"].ToString(),
                        PersNr    = dr["PersNr"].ToString(),
                        Company   = dr["Companyname"].ToString(),
                        OrgCap    = orgcap,
                    };
                    if (String.IsNullOrEmpty(middlename) == false)
                    {
                        emp.Lastname = String.Format("{0} {1}", middlename, emp.Lastname).TrimEnd(); /* van den Bosch */
                    }
                    emps.Add(emp.PerID, emp);
                }
                /* alleviate memory pressure */
                Data.Tables.Remove(tab_pers);
                tab_pers = null;
                /* 1b. all the rest (topics, participations) */
                DataTable tab_patn = Data.Tables[ReportDatatableIdentifiers.REPORT_DATATABLE_TRA001_OVERVIEW_PTN];
                foreach (DataRow dr in tab_patn.Rows)
                {
                    /* harvest */
                    var      PerID          = Convert.ToInt32(dr["PerID"]);
                    var      TopicID        = Convert.ToInt32(dr["TopicID"]);
                    var      Caption        = dr["Caption"].ToString();
                    DateTime DateTraining   = dr["DateTraining"].Equals(DBNull.Value) ? Convert.ToDateTime(dr["DateMeasure"]) : Convert.ToDateTime(dr["DateTraining"]);
                    DateTime?dateattended   = dr["DateAttended"].Equals(DBNull.Value) ? (DateTime?)null : Convert.ToDateTime(dr["DateAttended"]);
                    var      hasattended    = Convert.ToInt32(dr["HasAttended"]) > 0;
                    int?     validityfactor = null;
                    Timeunit?validityunit   = null;
                    if (dr["RequirementValidityFactor"].Equals(DBNull.Value) == false)
                    {
                        validityfactor = Convert.ToInt32(dr["RequirementValidityFactor"]);
                        validityunit   = (Timeunit)Convert.ToInt32(dr["RequirementValidityUnit"]);
                    }
                    /* logic rule: if attended, but no specific date given, value with assumption training date = attendance date */
                    if (hasattended && dateattended.HasValue == false)
                    {
                        dateattended = DateTraining;
                    }
                    /* logic rule: if a date attended is given, but the checkmark is not set, it may not count (C-1512-0454.1) */
                    if (hasattended == false && dateattended.HasValue)
                    {
                        dateattended = null;
                    }

                    /* slotify:
                     * 1c. the employee */
                    if (emps.ContainsKey(PerID))
                    {
                        var empX = emps[PerID];
                        if (empX.Attendances.Count(a => a.Key.Item1 == DateTraining && a.Key.Item2 == TopicID) == 0) /* [dlatikay 20170131] previously, this had only been checking for date, causing follow-up troubles mdettmarg @ C-1611-0558 */
                        {
                            var attendancestatus = StatisticalAttendanceStatus.WHITENotPlanned;
                            if (dateattended.HasValue)
                            {
                                attendancestatus = StatisticalAttendanceStatus.GREENAttended;
                            }
                            else
                            {
                                if (DateTraining >= cutoff)
                                {
                                    attendancestatus = StatisticalAttendanceStatus.WHITEPlanned;
                                }
                                else
                                {
                                    attendancestatus = StatisticalAttendanceStatus.REDOverdue;
                                }
                            }
                            var attx = new Attendance()
                            {
                                PerID         = PerID,
                                attended_when = dateattended,
                                DateTraining  = DateTraining,
                                TopicID       = TopicID,
                                Participation = attendancestatus
                            };
                            empX.Attendances.Add(new Tuple <DateTime, int>(DateTraining, TopicID), attx);

                            /* is this a (better) most recent attendance of this person?
                            * [dlatikay 20160402] likely the site of C-1512-0454.II.N */
                            if ((attx.attended_when ?? attx.DateTraining) <= cutoff && attx.Participation != StatisticalAttendanceStatus.WHITENotPlanned)
                            {
                                if (empX.MostRecentAttendance.ContainsKey(TopicID) == false)
                                {
                                    empX.MostRecentAttendance.Add(TopicID, attx);
                                }
                                else
                                {
                                    var cand = empX.MostRecentAttendance[TopicID];
                                    if ((cand.attended_when ?? cand.DateTraining) < (attx.attended_when ?? attx.DateTraining))
                                    {
                                        empX.MostRecentAttendance.Remove(TopicID);
                                        empX.MostRecentAttendance.Add(TopicID, attx);
                                    }
                                }
                            }
                        }
                    }
                    /* 1d. the topic */
                    if (tops.ContainsKey(TopicID) == false)
                    {
                        tops.Add(TopicID, new Topic()
                        {
                            TopicID        = TopicID,
                            Caption        = Caption,
                            ValidityFactor = validityfactor ?? ValidityFactorDefault,
                            ValidityUnit   = validityunit ?? ValidityUnitDefault
                        });
                    }
                    var top = tops[TopicID];
                    if (top.AttendanceSlots.Contains(DateTraining) == false)
                    {
                        top.AttendanceSlots.Add(DateTraining);
                    }
                }
                /* alleviate */
                Data.Tables.Remove(tab_patn);
                tab_patn = null;
                /* 2. instantiate the epplus templating engine */
                var template = new FileInfo(Path.Combine(CustomAbsPath, String.Format("{0}.xlsx", ResultFileBasename)));
                var dest     = new FileInfo(Path.Combine(RptTmpBasepath, tmpfilename));
                using (var package = new ExcelPackage(dest, template))
                {
                    ExcelWorkbook  wbk = package.Workbook;
                    ExcelWorksheet sht = wbk.Worksheets[1];
                    /* 2. populate the template into the new file */
                    //var dt = Data.Tables[ReportDatatableIdentifiers.REPORT_DATATABLE_HARDCOPY_SAFETY_003].Rows[0];
                    wbk.Names["Title"].Value       = m(5483);                       /* Excel® Training Overview */
                    wbk.Names["lCriteria"].Value   = m(4494, ReportQueryDateLocal); /* Data as per {0} */
                    wbk.Names["PersNr"].Value      = m(588);                        /* Employee # */
                    wbk.Names["Name"].Value        = m(744);                        /* Name */
                    wbk.Names["lFirstname"].Value  = m(478);                        /* First name */
                    wbk.Names["lDepartment"].Value = m(2279);                       /* Department */
                    wbk.Names["Company"].Value     = m(746);                        /* Company */
                    /* 2a. write the topics with their date slot headings horizontally */
                    var columnmap = new Dictionary <int, Dictionary <DateTime, int> >();
                    var col       = 6;
                    foreach (var top in from t in tops.Values orderby t.Caption, t.TopicID select t)
                    {
                        /* write topic header, 1 = most recent */
                        var spanning = 1 + top.AttendanceSlots.Count;
                        sht.Cells[4, col].Value = top.Caption;
                        sht.Cells[5, col].Value = "Letzte absolvierte Unterweisung";
                        columnmap.Add(top.TopicID, new Dictionary <DateTime, int>());
                        columnmap[top.TopicID].Add(DateTime.MinValue, col); /* this maps to the current topic's "most recent training" column */
                        ++col;
                        /* write topic date slots */
                        if (with_detailed_history)
                        {
                            bool first = true;
                            foreach (var dat in from d in top.AttendanceSlots orderby d select d)
                            {
                                if (dat >= DateFrom && dat <= DateTo)
                                {
                                    if (first)
                                    {
                                        sht.Cells[5, col].Value = "Plandatum";
                                        first = false;
                                    }
                                    sht.Cells[5, col].Value = dat;
                                    columnmap[top.TopicID].Add(dat, col); /* this maps to that "planned date" column of the current topic */
                                    sht.Cells[5, col].Style.Numberformat.Format = "dd.mm.yyyy";
                                    sht.Cells[5, col].Style.TextRotation        = 90;
                                    ++col;
                                }
                            }
                        }
                    }
                    /* 2b. write the employee names and static associated data vertically, omitting those with no data if we should */
                    int row = 7;
                    foreach (var emp in from e in emps.Values orderby e.Lastname, e.Firstname, e.PersNr, e.PerID select e)
                    {
                        if (suppress_zerolines == false || emp.Attendances.Count > 0)
                        {
                            sht.Cells[row, 1].Value = emp.PersNr;
                            sht.Cells[row, 2].Value = emp.Lastname;
                            sht.Cells[row, 3].Value = emp.Firstname;
                            sht.Cells[row, 4].Value = emp.OrgCap;
                            sht.Cells[row, 5].Value = emp.Company;

                            /* fill the topic/date slot-matrix body;
                             * write date of most recent training per topic */
                            foreach (var mra in from mrae in emp.MostRecentAttendance select mrae)
                            {
                                var topicid = mra.Key;
                                col = columnmap[topicid][DateTime.MinValue];
                                var status = emp.MostRecentAttendanceStatus(tops[topicid], cutoff);
                                if (status != StatisticalAttendanceStatusRecent.WHITENeverPlannedNorAttended)
                                {
                                    sht.Cells[row, col].Value = mra.Value.attended_when ?? mra.Value.DateTraining;
                                    sht.Cells[row, col].Style.Numberformat.Format = "dd.mm.yyyy";
                                    if (status == StatisticalAttendanceStatusRecent.GREENDoneAndValidToday)
                                    {
                                        sht.Cells[row, col].Style.Fill.PatternType = ExcelFillStyle.Solid;
                                        sht.Cells[row, col].Style.Fill.BackgroundColor.SetColor(Color.Green);
                                    }
                                    else if (status == StatisticalAttendanceStatusRecent.REDDoneButExpired)
                                    {
                                        sht.Cells[row, col].Style.Fill.PatternType = ExcelFillStyle.Solid;
                                        sht.Cells[row, col].Style.Fill.BackgroundColor.SetColor(Color.Red);
                                    }
                                }
                            }
                            /* if asked for, render the entire topic history of that empoyee */
                            if (with_detailed_history)
                            {
                                foreach (var att in from a in emp.Attendances.Values select a)
                                {
                                    if (att.DateTraining >= DateFrom && att.DateTraining <= DateTo)
                                    {
                                        col = columnmap[att.TopicID][att.DateTraining];
                                        if (att.Participation != StatisticalAttendanceStatus.WHITENotPlanned)
                                        {
                                            sht.Cells[row, col].Value = att.attended_when ?? att.DateTraining;
                                            sht.Cells[row, col].Style.Numberformat.Format = "dd.mm.yyyy";
                                            if (att.Participation == StatisticalAttendanceStatus.REDOverdue)
                                            {
                                                sht.Cells[row, col].Style.Fill.PatternType = ExcelFillStyle.Solid;
                                                sht.Cells[row, col].Style.Fill.BackgroundColor.SetColor(Color.Red);
                                            }
                                            else if (att.Participation == StatisticalAttendanceStatus.GREENAttended)
                                            {
                                                sht.Cells[row, col].Style.Fill.PatternType = ExcelFillStyle.Solid;
                                                sht.Cells[row, col].Style.Fill.BackgroundColor.SetColor(Color.Green);
                                            }
                                        }
                                    }
                                }
                            }
                            /* outer (pers/employee) advance */
                            ++row;
                        }
                    }
                    /* format properly */
                    sht.Cells.AutoFitColumns();
                    sht.View.FreezePanes(7, 1);
                    /* limit column 4=D in width */
                    sht.Column(4).Width = 38.29;
                    /* increase line 5 in height */
                    sht.Row(5).Height = 66.75;
                    /* 3. render the report into the desired format */
                    package.SaveAs(chunk);
                    if (chunk.CanSeek)
                    {
                        chunk.Seek(0, SeekOrigin.Begin);
                    }
                    GeneratedFileType = FileType.ft_xls;
                    mime           = sherm.core.formatting.mime.GetMIMEFromFiletype(Outputformat);
                    TargetFilename = String.Format("{0}{1}", ResultFileBasename, template.Extension);
                }
                /* succeeded */
                return(true);
            }
            catch (Exception ex)
            {
                /* some error */
                OnBuiltinReportError(ex.Message, ex);
                return(false);
            }
            finally
            {
                /* cleanup */
                try
                {
                    if (File.Exists(tmpfilename))
                    {
                        File.Delete(tmpfilename);
                    }
                }
                catch (Exception ef)
                {
                    Tracing.ErrorBkg("{0}", ef.ToString());
                }
            }
        }