Example #1
0
        public void MergeProfiles(Profile targetProfile, RcfProfile rcfProfile, FideProfile fideProfile)
        {
            using (var db = new Ri2Context())
            {
                targetProfile = db.Profiles.FirstOrDefault(x => x.Id == targetProfile.Id);
                if (targetProfile == null)
                {
                    return;
                }
                if (rcfProfile != null)
                {
                    rcfProfile = db.RcfProfiles.FirstOrDefault(x => x.Id == rcfProfile.Id);
                }
                if (fideProfile != null)
                {
                    fideProfile = db.FideProfiles.FirstOrDefault(x => x.Id == fideProfile.Id);
                }
                if (rcfProfile != null)
                {
                    targetProfile.RcfProfile = rcfProfile;
                }
                if (fideProfile != null)
                {
                    targetProfile.FideProfile = fideProfile;
                    if (rcfProfile != null)
                    {
                        rcfProfile.FideProfile = fideProfile;
                    }
                }

                db.SaveChanges();
            }
        }
Example #2
0
        public async Task MergeGroups(Group from, Group to)
        {
            using (var db = new Ri2Context())
            {
                var origin = db.Groups.FirstOrDefault(x => x.Id == from.Id);
                if (origin == null)
                {
                    return;
                }
                var target = db.Groups.FirstOrDefault(x => x.Id == to.Id);
                if (target == null)
                {
                    return;
                }
                await Task.Run(() =>
                {
                    foreach (var profile in origin.Profiles)
                    {
                        profile.Group = target;
                    }
                }).ConfigureAwait(false);

                db.SaveChanges();
            }
        }
Example #3
0
        public void ImportAsync(IEnumerable <int> ids, Group group, ProfileType profileType)
        {
            var profiles = new List <Profile>();

            using (var db = new Ri2Context())
            {
                var gr = db.Groups.FirstOrDefault(x => x.Id == group.Id);
                if (gr == null)
                {
                    return;
                }
                foreach (var ind in ids)
                {
                    if (profileType == ProfileType.Rcf)
                    {
                        var pr = db.RcfProfiles.FirstOrDefault(x => x.RcfId == ind);
                        if (pr == null)
                        {
                            File.AppendAllText("err.log",
                                               DateTime.Now.ToShortTimeString() + "|ImportService|RcfId" + ind + "not found" +
                                               Environment.NewLine);
                            continue;
                        }

                        if (db.Profiles.Any(x => x.RcfProfileId == pr.Id))
                        {
                            continue;
                        }
                        profiles.Add(new Profile {
                            RcfProfile = pr, FideProfile = pr.FideProfile, Group = gr
                        });
                    }
                    else
                    {
                        var pr = db.FideProfiles.FirstOrDefault(profile => profile.FideId == ind);
                        if (pr == null)
                        {
                            File.AppendAllText("err.log",
                                               DateTime.Now.ToShortTimeString() + "|ImportService|FideId " + ind + "not found" +
                                               Environment.NewLine);
                            continue;
                        }

                        var rcf = db.RcfProfiles.FirstOrDefault(profile => profile.FideProfileId == pr.Id);
                        if (db.Profiles.Any(x => x.FideProfileId == pr.Id))
                        {
                            continue;
                        }
                        profiles.Add(new Profile {
                            FideProfile = pr, RcfProfile = rcf, Group = gr
                        });
                    }
                }

                db.Profiles.AddRange(profiles);
                db.SaveChanges();
                //await db.SaveChangesAsync().ConfigureAwait(false);
            }
        }
Example #4
0
 public void DeleteProfile(int id)
 {
     using (var db = new Ri2Context())
     {
         db.Profiles.Remove(
             db.Profiles.SingleOrDefault(x => x.Id == id) ?? throw new InvalidOperationException());
         db.SaveChanges();
     }
 }
Example #5
0
 public void CreateGroup(Group gr)
 {
     using (var db = new Ri2Context())
     {
         gr.Id = 0;
         db.Groups.Attach(gr);
         db.Entry(gr).State = EntityState.Added;
         db.SaveChanges();
     }
 }
Example #6
0
 public void DeleteGroup(Group gr)
 {
     using (var db = new Ri2Context())
     {
         var tmp = db.Groups.Include(x => x.Profiles).FirstOrDefault(x => x.Id == gr.Id);
         if (tmp == null || tmp.Profiles.Count != 0)
         {
             return;
         }
         db.Groups.Remove(tmp);
         db.SaveChanges();
     }
 }
Example #7
0
 public void UpdateGroup(Group gr)
 {
     using (var db = new Ri2Context())
     {
         var tmp = db.Groups.FirstOrDefault(x => x.Id == gr.Id);
         if (tmp == null)
         {
             return;
         }
         tmp.Name = gr.Name;
         db.SaveChanges();
     }
 }
Example #8
0
 public void SaveProfile(Profile profile)
 {
     using (var db = new Ri2Context())
     {
         var pr = db.Profiles.FirstOrDefault(x => x.Id == profile.Id);
         if (pr == null)
         {
             throw new Exception("profile");
         }
         var gr = db.Groups.FirstOrDefault(x => x.Id == profile.Group.Id);
         pr.Group = gr ?? throw new Exception("group");
         db.SaveChanges();
     }
 }
Example #9
0
 public void DeleteGroupWithProfiles(int id)
 {
     using (var db = new Ri2Context())
     {
         var gr = db.Groups.Include(x => x.Profiles).FirstOrDefault(x => x.Id == id);
         if (gr == null)
         {
             return;
         }
         db.Profiles.RemoveRange(gr.Profiles);
         db.Groups.Remove(gr);
         db.SaveChanges();
     }
 }
Example #10
0
        private static void CheckProfiles()
        {
            using (var ri2 = new Ri2Context())
            {
                foreach (var profile in ri2.Profiles.Include("RcfProfile").Include("FideProfile"))
                {
                    if (profile.FideProfileId.HasValue && profile.RcfProfileId.HasValue)
                    {
                        continue;
                    }

                    if (profile.RcfProfileId.HasValue)
                    {
                        if (profile.RcfProfile.FideProfileId.HasValue)
                        {
                            profile.FideProfile = profile.RcfProfile.FideProfile;
                        }
                        continue;
                    }

                    if (!profile.FideProfileId.HasValue)
                    {
                        continue;
                    }
                    var id  = profile.FideProfileId.Value;
                    var rcf = ri2.RcfProfiles.FirstOrDefault(x => x.FideProfileId.Value == id);
                    if (rcf == null)
                    {
                        continue;
                    }
                    profile.RcfProfile = rcf;
                }

                ri2.SaveChanges();
            }
        }
Example #11
0
        private static void ProcessFide()
        {
            var query = SimpleXmlStream.SimpleStreamAxis(FideFilePath, FideXmlElements.Player);
            var add   = new List <FideProfile>(100000);
            var mod   = new List <FideProfile>(100000);
            Dictionary <int, int> t;

            using (var db = new Ri2Context {
                Configuration = { AutoDetectChangesEnabled = false }
            })
            {
                t = db.FideProfiles.Select(x => new { x.FideId, x.Id })
                    .ToDictionary(o => o.FideId, o => o.Id);
            }

            foreach (var profile in query)
            {
                if (!Settings.Current.Filter.Contains(profile.Element(FideXmlElements.Country)?.Value))
                {
                    continue;
                }
                if (profile.Element(FideXmlElements.Name)?.Value == "")
                {
                    continue;
                }
                var pr = new FideProfile
                {
                    Name = (profile.Element(FideXmlElements.Name)?.Value == ""
                               ? "_"
                               : profile.Element(FideXmlElements.Name)?.Value) ?? "_",
                    FideId = Convert.ToInt32((profile.Element(FideXmlElements.FideId)?.Value == ""
                                                 ? "0"
                                                 : profile.Element(FideXmlElements.FideId)?.Value) ?? "0"),
                    Std = Convert.ToInt32((profile.Element(FideXmlElements.Std)?.Value == ""
                                              ? "0"
                                              : profile.Element(FideXmlElements.Std)?.Value) ?? "0"),
                    Rpd = Convert.ToInt32((profile.Element(FideXmlElements.Rpd)?.Value == ""
                                              ? "0"
                                              : profile.Element(FideXmlElements.Rpd)?.Value) ?? "0"),
                    Blz = Convert.ToInt32((profile.Element(FideXmlElements.Blz)?.Value == ""
                                              ? "0"
                                              : profile.Element(FideXmlElements.Blz)?.Value) ?? "0"),
                    Birth = Convert.ToInt32((profile.Element(FideXmlElements.Birth)?.Value == ""
                                                ? "0"
                                                : profile.Element(FideXmlElements.Birth)?.Value) ?? "0")
                };
                if (pr.Birth < Settings.Current.BirthCutoff)
                {
                    continue;
                }
                //File.AppendAllText("log.txt",pr.FideId+Environment.NewLine);
                //using (var ri2 = new Ri2Context {Configuration = {AutoDetectChangesEnabled = false}})
                {
                    //var t = ri2.FideProfiles.FirstOrDefault(cp => cp.FideId == pr.FideId);
                    //if (t != null)
                    if (t.ContainsKey(pr.FideId))
                    {
                        //pr.Id = t.Id;
                        pr.Id = t[pr.FideId];
                        mod.Add(pr);
                    }
                    else
                    {
                        add.Add(pr);
                    }
                }
            }

            using (var db = new Ri2Context())
            {
                EFBatchOperation.For(db, db.FideProfiles).InsertAll(add);
                db.SaveChanges();
            }

            using (var db = new Ri2Context())
            {
                EFBatchOperation.For(db, db.FideProfiles).UpdateAll(mod,
                                                                    x => x.ColumnsToUpdate(c => c.Name, c => c.Birth, c => c.Std, c => c.Rpd, c => c.Blz));
                db.SaveChanges();
            }
        }
Example #12
0
        private static void ProcessRcf()
        {
            var fi = new FileInfo(RcfFilePath);

            using (var pkg = new ExcelPackage(fi))
            {
                var ws    = pkg.Workbook.Worksheets[1];
                var start = ws.Dimension.Start;
                var end   = ws.Dimension.End;
                var add   = new List <RcfProfile>(75000);
                var mod   = new List <RcfProfile>(75000);
                Dictionary <int, int> tf;
                Dictionary <int, int> t;
                using (var db = new Ri2Context {
                    Configuration = { AutoDetectChangesEnabled = false }
                })
                {
                    tf = db.FideProfiles.Select(x => new { x.FideId, x.Id })
                         .ToDictionary(o => o.FideId, o => o.Id);
                    t = db.RcfProfiles.Select(x => new { x.RcfId, x.Id })
                        .ToDictionary(o => o.RcfId, o => o.Id);
                }

                for (var i = start.Row + 1; i <= end.Row; i++)
                {
                    var pr = new RcfProfile
                    {
                        RcfId = ws.Cells[i, RcfColumns.RcfId].GetValue <int>(),
                        Name  = ws.Cells[i, RcfColumns.Name].GetValue <string>(),
                        Birth = ws.Cells[i, RcfColumns.Birth].GetValue <string>() != ""
                            ? ws.Cells[i, RcfColumns.Birth].GetValue <int>()
                            : 0,
                        Std = ws.Cells[i, RcfColumns.Std].GetValue <string>() != ""
                            ? ws.Cells[i, RcfColumns.Std].GetValue <int>()
                            : 0,
                        Rpd = ws.Cells[i, RcfColumns.Rpd].GetValue <string>() != ""
                            ? ws.Cells[i, RcfColumns.Rpd].GetValue <int>()
                            : 0,
                        Blz = ws.Cells[i, RcfColumns.Blz].GetValue <string>() != ""
                            ? ws.Cells[i, RcfColumns.Blz].GetValue <int>()
                            : 0
                    };
                    if (pr.Birth < Settings.Current.BirthCutoff)
                    {
                        continue;
                    }
                    var fideId = ws.Cells[i, RcfColumns.FideId].GetValue <int?>();

                    //using (var ri2 = new Ri2Context {Configuration = {AutoDetectChangesEnabled = false}})
                    {
                        if (fideId.HasValue)
                        {
                            if (tf.ContainsKey(fideId.Value))
                            {
                                pr.FideProfileId = tf[fideId.Value];
                            }
                        }

                        //var t = ri2.RcfProfiles.FirstOrDefault(cp => cp.RcfId == pr.RcfId);
                        if (t.ContainsKey(pr.RcfId))
                        {
                            pr.Id = t[pr.RcfId];
                            mod.Add(pr);
                        }
                        else
                        {
                            add.Add(pr);
                        }
                    }
                }

                using (var ri2 = new Ri2Context())
                {
                    EFBatchOperation.For(ri2, ri2.RcfProfiles).InsertAll(add);
                    EFBatchOperation.For(ri2, ri2.RcfProfiles).UpdateAll(mod,
                                                                         x => x.ColumnsToUpdate(c => c.Name, c => c.Birth, c => c.Std, c => c.Rpd, c => c.Blz,
                                                                                                c => c.FideProfileId));
                    ri2.SaveChanges();
                }
            }
        }