Ejemplo n.º 1
0
 private void detach_ccfDomains(ccfDomain entity)
 {
     this.SendPropertyChanging();
     entity.ccfCategory = null;
 }
Ejemplo n.º 2
0
 partial void DeleteccfDomain(ccfDomain instance);
Ejemplo n.º 3
0
 partial void InsertccfDomain(ccfDomain instance);
Ejemplo n.º 4
0
 partial void UpdateccfDomain(ccfDomain instance);
Ejemplo n.º 5
0
        private static void updateDomains(ISACFDataContext db)
        {
            if (db.Transaction == null & db.Connection.State == System.Data.ConnectionState.Closed)
            {
                db.Connection.Open();
            }

            List <ccfCategory> lstCategory = (from e in db.ccfCategories
                                              select e).ToList();

            if (db.Transaction == null & db.Connection.State == System.Data.ConnectionState.Open)
            {
                db.Connection.Close();
            }

            FileInfo DomainsFile = null;

            foreach (ccfCategory Category in lstCategory)
            {
                // Try to free some memory when Category changes.
                GC.Collect();
                DomainsFile = new FileInfo(Path.Combine(clsSettings.serviceSettings.dataDirectory.FullName, string.Format("{0}{1}{2}{1}{3}", xmlDestinationFolderName, Path.DirectorySeparatorChar, Category.name, domainsFileName)));
                if (!File.Exists(DomainsFile.FullName))
                {
                    continue;
                }

                bool      onceAgain  = true;
                int       s          = 0;
                const int rowsToTake = 5000;
                while (onceAgain)
                {
                    List <string> domains = (from e in XDocument.Load(DomainsFile.FullName).Descendants("domain")
                                             select(string) e.Value).Distinct().Skip(s).Take(rowsToTake).ToList();
                    s        += rowsToTake;
                    onceAgain = domains.Count == rowsToTake;

                    if (db == null)
                    {
                        db = new ISACFDataContext();
                    }
                    if (db.Transaction == null & db.Connection.State == System.Data.ConnectionState.Closed)
                    {
                        db.Connection.Open();
                    }

                    foreach (string domain in domains)
                    {
                        if (!isIPAddress(domain))
                        {
                            ccfDomain newDomain = new ccfDomain();
                            newDomain.id_Category = Category.ID;
                            newDomain.domain      = domain;
                            db.ccfDomains.InsertOnSubmit(newDomain);
                            newDomain = null;
                        }
                        else
                        {
                            ccfIPv4 newIPv4 = new ccfIPv4();
                            newIPv4.id_Category = Category.ID;
                            newIPv4.IP          = domain;
                            db.ccfIPv4s.InsertOnSubmit(newIPv4);
                            newIPv4 = null;
                        }
                    }
                    db.SubmitChanges();

                    // Do some Cleanup.
                    if (db.Transaction == null & db.Connection.State == System.Data.ConnectionState.Open)
                    {
                        db.Connection.Close();
                        db = null;
                    }
                    if (domains != null)
                    {
                        domains = null;
                    }
                    // Try to free some memory.
                    GC.Collect();
                }

                // Do some Cleanup.
                if (DomainsFile != null)
                {
                    DomainsFile = null;
                }
                // Try to free some memory.
                GC.Collect();
            }

            if (lstCategory != null)
            {
                lstCategory = null;
            }
            if (db != null)
            {
                if (db.Transaction == null & db.Connection.State == System.Data.ConnectionState.Open)
                {
                    db.Connection.Close();
                    db = null;
                }
            }
            // Try to free some memory.
            GC.Collect();
        }         // End of updateDomains()