Example #1
0
        public async Task InitGuild(IGuild guild)
        {
            if (Languages.ContainsKey(guild.Id)) // If somehow InitGuild is called 2 times for the same guild we ignore it
            {
                return;
            }
            string guildIdStr = guild.Id.ToString();

            if (await R.Db(dbName).Table("Guilds").GetAll(guildIdStr).Count().Eq(0).RunAsync <bool>(conn))
            {
                await R.Db(dbName).Table("Guilds").Insert(R.HashMap("id", guildIdStr)
                                                          .With("Prefix", "s.")
                                                          .With("Language", "en")
                                                          .With("Availability", defaultAvailability)
                                                          ).RunAsync(conn);
            }
            dynamic json = await R.Db(dbName).Table("Guilds").Get(guildIdStr).RunAsync(conn);

            Languages.Add(guild.Id, (string)json.Language);
            Prefixs.Add(guild.Id, (string)json.Prefix);
            string availability = (string)json.Availability;

            if (availability == null)
            {
                Availability.Add(guild.Id, defaultAvailability);
            }
            else
            {
                string newAvailability = availability;
                while (newAvailability.Length < defaultAvailability.Length)
                {
                    newAvailability += "1";
                }
                Availability.Add(guild.Id, newAvailability);
            }
            string anonymize = (string)json.Anonymize;

            if (anonymize != null)
            {
                Anonymize.Add(guild.Id, bool.Parse(anonymize));
            }
            else
            {
                Anonymize.Add(guild.Id, false);
            }
            string anime = (string)json.animeSubscription;

            if (anime != null && anime != "0")
            {
                AnimeSubscription.Add((await guild.GetTextChannelAsync(ulong.Parse(anime)), null));
            }
            string nhentai = (string)json.nhentaiSubscription;

            if (nhentai != null && nhentai != "0")
            {
                NHentaiSubscription.Add((await guild.GetTextChannelAsync(ulong.Parse(nhentai)), Subscription.SubscriptionTags.ParseSubscriptionTags(json.nhentaiSubscriptionTags.ToObject <string[]>(), false)));
            }
        }
Example #2
0
        public async Task InitGuild(ulong guildId)
        {
            if (Languages.ContainsKey(guildId)) // If somehow InitGuild is called 2 times for the same guild we ignore it
            {
                return;
            }
            string guildIdStr = guildId.ToString();

            if (await R.Db(dbName).Table("Guilds").GetAll(guildIdStr).Count().Eq(0).RunAsync <bool>(conn))
            {
                await R.Db(dbName).Table("Guilds").Insert(R.HashMap("id", guildIdStr)
                                                          .With("Prefix", "s.")
                                                          .With("Language", "en")
                                                          .With("Availability", defaultAvailability)
                                                          ).RunAsync(conn);
            }
            dynamic json = await R.Db(dbName).Table("Guilds").Get(guildIdStr).RunAsync(conn);

            Languages.Add(guildId, (string)json.Language);
            Prefixs.Add(guildId, (string)json.Prefix);
            string availability = (string)json.Availability;

            if (availability == null)
            {
                Availability.Add(guildId, defaultAvailability);
            }
            else
            {
                string newAvailability = availability;
                while (newAvailability.Length < defaultAvailability.Length)
                {
                    newAvailability += "1";
                }
                Availability.Add(guildId, newAvailability);
            }
        }
Example #3
0
        private void btnGenerate_Click(object sender, RoutedEventArgs e)
        {
            ReportTable = null;
            avReport    = null;
            dgReportGrid.DataContext = null;
            dgReportGrid.Visibility  = Visibility.Visible;
            if (cmbReportSelector.SelectedIndex == 0)
            {
                ReportTable = dataAccess.GetReportData(dpFrom.SelectedDate.Value, dpTo.SelectedDate.Value);

                dgReportGrid.DataContext = ReportTable;
            }
            else if (cmbReportSelector.SelectedIndex == 1)
            {
                avReport = new AvailabilityReport();
                int[] lineids = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
                foreach (Shift s in shifts)
                {
                    if (s.Name != "GEN_SHIFT")
                    {
                        String date = String.Empty;
                        foreach (Session se in s.Sessions)
                        {
                            DateTime f = new DateTime(dpFrom.SelectedDate.Value.Year,
                                                      dpFrom.SelectedDate.Value.Month,
                                                      dpFrom.SelectedDate.Value.Day,
                                                      TimeSpan.Parse(se.StartTime).Hours,
                                                      TimeSpan.Parse(se.StartTime).Minutes,
                                                      TimeSpan.Parse(se.StartTime).Seconds
                                                      );


                            DateTime t = new DateTime(dpTo.SelectedDate.Value.Year,
                                                      dpTo.SelectedDate.Value.Month,
                                                      dpTo.SelectedDate.Value.Day,
                                                      TimeSpan.Parse(se.EndTime).Hours,
                                                      TimeSpan.Parse(se.EndTime).Minutes,
                                                      TimeSpan.Parse(se.EndTime).Seconds
                                                      );
                            if (s.Name == "THIRD SHIFT" && se.Name != "FIRST HOUR")
                            {
                                f    = f.AddDays(1);
                                t    = t.AddDays(1);
                                date = t.ToShortDateString();
                            }
                            else
                            {
                                date = f.ToShortDateString();
                            }
                            foreach (int n in lineids)
                            {
                                DataTable dt = dataAccess.GetHourlyReportData(n, f, t);
                                if (dt.Rows.Count == 0)
                                {
                                    continue;
                                }
                                Availability av = new Availability();
                                for (int j = 0; j < dt.Rows.Count; j++)
                                {
                                    IssueDetails issueDetail = new IssueDetails();
                                    issueDetail.Line      = (int)dt.Rows[j]["LINE"];
                                    issueDetail.Station   = (int)dt.Rows[j]["STATION"];
                                    issueDetail.Tolerance = (int)dt.Rows[j]["Tolerance"];
                                    issueDetail.Raised    = (TimeSpan)dt.Rows[j]["Raised"];
                                    if (dt.Rows[j]["Resolved"] == DBNull.Value)
                                    {
                                        issueDetail.Resolved = TimeSpan.Parse(se.EndTime);
                                    }
                                    else
                                    {
                                        issueDetail.Resolved = (TimeSpan)dt.Rows[j]["Resolved"];
                                        if (issueDetail.Resolved > TimeSpan.Parse(se.EndTime))
                                        {
                                            issueDetail.Resolved = TimeSpan.Parse(se.EndTime);
                                        }
                                    }

                                    TimeSpan ToleranceLimit = new TimeSpan(0, issueDetail.Tolerance, 0);
                                    if (issueDetail.Resolved - issueDetail.Raised > ToleranceLimit)
                                    {
                                        av.Add(issueDetail);
                                    }
                                }
                                avReport.Add(new AvailabilityRecord((string)dt.Rows[0]["LINENAME"],
                                                                    date, f.ToShortTimeString() + "-" + t.ToShortTimeString(),
                                                                    av.getAvailability(f.TimeOfDay, t.TimeOfDay).ToString(), av.EffectiveDowntime.ToString()));
                            }
                        }
                    }
                }
                dgReportGrid.AutoGenerateColumns = true;
                dgReportGrid.DataContext         = avReport;
            }
        }
        private void btnGenerate_Click(object sender, RoutedEventArgs e)
        {
            ReportTable = null;
            avReport = null;
            dgReportGrid.DataContext = null;
            dgReportGrid.Visibility = Visibility.Visible;
            if (cmbReportSelector.SelectedIndex == 0)
            {

                ReportTable = dataAccess.GetReportData(dpFrom.SelectedDate.Value, dpTo.SelectedDate.Value);

                dgReportGrid.DataContext = ReportTable;

                
            }
            else if (cmbReportSelector.SelectedIndex == 1)
            {
                avReport = new AvailabilityReport();
                int[] lineids = {1,2,3,4,5,6,7,8,9,10};
                foreach (Shift s in shifts)
                {
                    if (s.Name != "GEN_SHIFT")
                    {
                        String date = String.Empty;
                        foreach (Session se in s.Sessions)
                        {
                            DateTime f = new DateTime(dpFrom.SelectedDate.Value.Year,
                                dpFrom.SelectedDate.Value.Month,
                                dpFrom.SelectedDate.Value.Day,
                                TimeSpan.Parse(se.StartTime).Hours,
                                TimeSpan.Parse(se.StartTime).Minutes,
                                TimeSpan.Parse(se.StartTime).Seconds
                                );
                            
                                
                            DateTime t = new DateTime(dpTo.SelectedDate.Value.Year,
                                dpTo.SelectedDate.Value.Month,
                                dpTo.SelectedDate.Value.Day,
                                TimeSpan.Parse(se.EndTime).Hours,
                                TimeSpan.Parse(se.EndTime).Minutes,
                                TimeSpan.Parse(se.EndTime).Seconds
                                );
                            if (s.Name == "THIRD SHIFT" && se.Name != "FIRST HOUR")
                            {
                                t = t.AddDays(1);
                                date = t.ToShortDateString();
                            }
                            else
                                date = f.ToShortDateString();
                            foreach(int n in lineids)
                            {
                                
                                DataTable dt = dataAccess.GetHourlyReportData(n, f, t);
                                if (dt.Rows.Count == 0) continue;
                                Availability av = new Availability();
                                for (int j = 0; j < dt.Rows.Count; j++)
                                {

                                    IssueDetails issueDetail = new IssueDetails();
                                    issueDetail.Line = (int)dt.Rows[j]["LINE"];
                                    issueDetail.Station = (int)dt.Rows[j]["STATION"];
                                    issueDetail.Tolerance = (int)dt.Rows[j]["Tolerance"];
                                    issueDetail.Raised = (TimeSpan)dt.Rows[j]["Raised"];
                                    if (dt.Rows[j]["Resolved"] == DBNull.Value)
                                        issueDetail.Resolved = TimeSpan.Parse(se.EndTime);
                                    else
                                    {
                                        issueDetail.Resolved = (TimeSpan)dt.Rows[j]["Resolved"];
                                        if (issueDetail.Resolved > TimeSpan.Parse(se.EndTime))
                                        {
                                            issueDetail.Resolved = TimeSpan.Parse(se.EndTime);
                                        }
                                    }

                                    TimeSpan ToleranceLimit = new TimeSpan(0, issueDetail.Tolerance, 0);
                                    if (issueDetail.Resolved - issueDetail.Raised > ToleranceLimit)
                                    {
                                        av.Add(issueDetail);
                                    }
                                }
                                avReport.Add(new AvailabilityRecord((string)dt.Rows[0]["LINENAME"],
                                    date, f.ToShortTimeString() + "-" + t.ToShortTimeString(),
                                    av.getAvailability( f.TimeOfDay, t.TimeOfDay).ToString()));



                            }
                        }
                    }
                }
                dgReportGrid.AutoGenerateColumns = true;
                dgReportGrid.DataContext = avReport;
            }



        }