コード例 #1
0
ファイル: Certificates.cs プロジェクト: RapidFiring/evemon
        /// <summary>
        /// Generate the certificates datafile.
        /// </summary>        
        internal static void GenerateDatafile()
        {
            Stopwatch stopwatch = Stopwatch.StartNew();
            Util.ResetCounters();

            Console.WriteLine();
            Console.Write(@"Generating certificates datafile... ");

            // Export certificates groups
            List<SerializableCertificateGroup> listOfCertGroups = new List<SerializableCertificateGroup>();

            foreach (InvGroups group in Database.CrtCertificatesTable.GroupBy(x => x.GroupID)
                .Select(x => Database.InvGroupsTable[x.Key]).OrderBy(x => x.Name))
            {
                SerializableCertificateGroup crtGroup = new SerializableCertificateGroup
                {
                    ID = group.ID,
                    Name = group.Name,
                    Description = group.Description
                };

                // Add classes to categories
                crtGroup.Classes.AddRange(ExportCertificateClasses(group).OrderBy(x => x.Name));

                //// Add category
                listOfCertGroups.Add(crtGroup);
            }

            // Serialize
            CertificatesDatafile datafile = new CertificatesDatafile();
            datafile.Groups.AddRange(listOfCertGroups);

            Util.DisplayEndTime(stopwatch);

            Util.SerializeXml(datafile, DatafileConstants.CertificatesDatafile);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: wow4all/evemu_server
        /// <summary>
        /// Generate the certificates datafile.
        /// </summary>        
        private static void GenerateCertificates()
        {
            Console.WriteLine();
            Console.Write(@"Generated certificates datafile... ");

            s_counter = 0;
            s_percentOld = 0;
            s_text = String.Empty;
            s_startTime = DateTime.Now;

            // Export certificates categories
            var listOfCertCategories = new List<SerializableCertificateCategory>();

            foreach (CrtCategories category in s_crtCategories.OrderBy(x => x.CategoryName))
            {
                var crtCategory = new SerializableCertificateCategory
                                      {
                                          ID = category.ID,
                                          Name = category.CategoryName,
                                          Description = category.Description
                                      };

                // Export certificates classes
                var listOfCertClasses = new List<SerializableCertificateClass>();

                int categoryID = 0;
                foreach (CrtClasses certClass in s_crtClasses)
                {
                    // Exclude unused classes
                    int id = certClass.ID;
                    if (id == 104 || id == 106 || id == 111)
                        continue;

                    var crtClasses = new SerializableCertificateClass
                                         {
                                             ID = certClass.ID,
                                             Name = certClass.ClassName,
                                             Description = certClass.Description
                                         };

                    // Export certificates
                    var listOfCertificates = new List<SerializableCertificate>();

                    foreach (var certificate in s_certificates.Where(x => x.ClassID == certClass.ID))
                    {
                        UpdatePercentDone(s_certGenTotal);

                        var crtCertificates = new SerializableCertificate
                                                  {
                                                      ID = certificate.ID,
                                                      Grade = GetGrade(certificate.Grade),
                                                      Description = certificate.Description
                                                  };

                        // Export prerequesities
                        var listOfPrereq = new List<SerializableCertificatePrerequisite>();

                        foreach (CrtRelationships relationship in s_crtRelationships
                            .Where(x => x.ChildID == certificate.ID))
                        {
                            var crtPrerequisites = new SerializableCertificatePrerequisite
                                                       {
                                                           ID = relationship.ID,
                                                       };

                            if (relationship.ParentTypeID != null) // prereq is a skill
                            {
                                var skill = s_types.First(x => x.ID == relationship.ParentTypeID);
                                crtPrerequisites.Kind = SerializableCertificatePrerequisiteKind.Skill;
                                crtPrerequisites.Name = skill.Name;
                                crtPrerequisites.Level = relationship.ParentLevel.ToString();
                            }
                            else // prereq is a certificate
                            {
                                CrtCertificates cert = s_certificates.First(x => x.ID == relationship.ParentID);
                                CrtClasses crtClass = s_crtClasses.First(x => x.ID == cert.ClassID);
                                crtPrerequisites.Kind = SerializableCertificatePrerequisiteKind.Certificate;
                                crtPrerequisites.Name = crtClass.ClassName;
                                crtPrerequisites.Level = GetGrade(cert.Grade).ToString();
                            }

                            // Add prerequisite
                            listOfPrereq.Add(crtPrerequisites);
                        }

                        // Export recommendations
                        var listOfRecom = new List<SerializableCertificateRecommendation>();

                        foreach (CrtRecommendations recommendation in s_crtRecommendations
                            .Where(x => x.CertificateID == certificate.ID))
                        {
                            // Finds the ships name
                            InvType shipName = s_types.First(x => x.ID == recommendation.ShipTypeID);

                            var crtRecommendations = new SerializableCertificateRecommendation
                                                         {
                                                             ID = recommendation.ID,
                                                             Ship = shipName.Name,
                                                             Level = recommendation.Level
                                                         };

                            // Add recommendation
                            listOfRecom.Add(crtRecommendations);
                        }

                        //Add prerequisites to certificate
                        crtCertificates.Prerequisites = listOfPrereq.ToArray();

                        // Add recommendations to certificate
                        crtCertificates.Recommendations = listOfRecom.ToArray();

                        // Add certificate
                        listOfCertificates.Add(crtCertificates);

                        // Storing the certificate categoryID for use in classes
                        categoryID = certificate.CategoryID;
                    }

                    // Grouping certificates according to their classes
                    if (categoryID == category.ID)
                    {
                        // Add certificates to classes
                        crtClasses.Certificates = listOfCertificates.OrderBy(x => x.Grade).ToArray();

                        // Add certificate class
                        listOfCertClasses.Add(crtClasses);
                    }
                }

                // Add classes to categories
                crtCategory.Classes = listOfCertClasses.ToArray();

                // Add category
                listOfCertCategories.Add(crtCategory);
            }

            s_endTime = DateTime.Now;
            Console.WriteLine(String.Format(" in {0}", s_endTime.Subtract(s_startTime)).TrimEnd('0'));

            // Serialize
            var datafile = new CertificatesDatafile();
            datafile.Categories = listOfCertCategories.ToArray();
            Util.SerializeXML(datafile, DatafileConstants.CertificatesDatafile);
        }