Inheritance: System.Data.Linq.DataContext
Ejemplo n.º 1
0
        public void ValidateGrants()
        {
            GetSettings();

            ucsdDataContext = new UCSDDataContext();
            var grants = ucsdDataContext.Grants.Where(g => g.IsVerified == null && g.GrantPrincipals.Any(
                        gp => gp.PrincipalInvestigator != null && gp.PrincipalInvestigator.EmployeeId != null));

            string pause = ConfigurationManager.AppSettings["GrantValidation.Pause"];
            int _pause = 10;
            if (!String.IsNullOrWhiteSpace(pause))
            {
                _pause = Int32.Parse(pause);
            }

            foreach (Grant grant in grants.ToList().Distinct(new GrantAppIdComparer()))
            {
               ValidateGrantOnline(grant);

                if(_pause > 0)
                {
                    log.Info("Pause");
                    Thread.Sleep(_pause * 1000);
                }
            }
        }
Ejemplo n.º 2
0
        public void ImportData(string uri, string orgName = null, string DUNSNumber = null)
        {
            if(!File.Exists(uri))
            {
                return;
            }

            this.orgName = orgName;
            checkOrgName = !String.IsNullOrWhiteSpace(orgName);

            errorsStream = File.CreateText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "errors.txt"));
            errorsStream.AutoFlush = true;
            successStream = File.CreateText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "processed.txt"));
            successStream.AutoFlush = true;

            StartTransaction();
            using (XmlReader reader = XmlReader.Create(uri))
            {
                reader.MoveToContent();
                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element && reader.Name == "row")
                    {
                        Grant grant = new Grant { GrantId = Guid.NewGuid() };

                        XElement row = new XElement("row");
                        bool needContinue = true;
                        try
                        {
                            while (reader.Read() && reader.NodeType != XmlNodeType.EndElement)
                            {
                                if (reader.NodeType == XmlNodeType.Element && !string.IsNullOrEmpty(reader.Name))
                                {
                                    XElement node = XNode.ReadFrom(reader) as XElement;
                                    row.Add(node);
                                    if (!String.IsNullOrWhiteSpace(node.Value))
                                    {
                                        needContinue = UpdateGrant(grant, node);

                                        if(!needContinue)
                                            break;
                                    }
                                }
                            }

                            TotalProcessed++;

                            if (!needContinue || (checkOrgName && !String.Equals(grant.OrgName, this.orgName, StringComparison.OrdinalIgnoreCase)))
                                continue;

                            if (CheckIfGrantExists(grant))
                            {
                                continue;
                            }

                            grant.XML = row.ToString();

                            ValidateGrant(grant);
                            AddGrantToRecordset(grant);
                            AddSuccessGrunt(grant);

                            if (TotalRecords % RecordsPerTransaction == 0)
                            {
                                CompleteTransaction();

                                DataContext = new UCSDDataContext();

                                StartTransaction();

                                log.InfoFormat("Processed {0} rows.", TotalRecords);
                            }
                        }
                        catch (Exception ex)
                        {
                            log.InfoFormat("Error processing row with ApplicationID = {0}. {1}", grant.ApplicationId, ex.Message);
                            log.Debug(String.Format("Error processing row with ApplicationID = {0}\r\n{1}", grant.ApplicationId, ex.Message), ex);

                            AddGrantError(grant, ex);
                        }
                    }
                }
            }

            FlushStream(errorsStream);
            FlushStream(successStream);

            CompleteTransaction();
        }
Ejemplo n.º 3
0
 protected GrantImporterBase(UCSDDataContext dataContext)
 {
     log = LogManager.GetLogger(GetType());
     DataContext = dataContext;
 }
Ejemplo n.º 4
0
 public DataManager()
 {
     log = LogManager.GetLogger(GetType());
     context = new UCSDDataContext();
 }
Ejemplo n.º 5
0
 public WebDownloader()
 {
     DataContext = new UCSDDataContext();
     log = LogManager.GetLogger(GetType());
 }