Example #1
0
        /// <summary>
        /// Parse IATI XML data from IATI data store and converts from v1 to v2
        /// </summary>
        /// <returns></returns>
        private static void ParseIATI()
        {

            //Get list of FundSource from AIMS DB
            AimsDAL _AimsDAL = new AimsDAL();
            var fundSources = _AimsDAL.GetFundSources();//.FindAll(q => q.IATICode == "SE-0");

            int i = 1;
            foreach (var fundSource in fundSources)
            {

                Thread th = new Thread(new ThreadStart(() =>
                {
                    Parser p = new Parser();
                    p.Parse(fundSources.Count, i++, fundSource);
                    p = null;
                }));
                th.Start();

                th.Join();
            }
        }
Example #2
0
        private List<iatiactivity> GetMappedAimsProjects(string dp)
        {
            var mappedProjectIds = (from a in dbContext.Activities
                                    let isMapped = a.ProjectId > 0 || a.MappedProjectId > 0
                                    where a.AssignedOrgId == dp && isMapped && a.IsIgnore != true
                                    select (a.ProjectId > 0 ? a.ProjectId :
                                    a.MappedProjectId)).ToList();


            var aimsActivities = new AimsDAL().GetMappedAIMSProjectsInIATIFormat(dp, mappedProjectIds);
            return aimsActivities;
        }
Example #3
0
        public ProjectFieldMapModel GetTransactionMismatchedActivity(string iatiIdentifier)
        {
            var q = (from a in dbContext.Activities
                     let isMapped = a.ProjectId > 0 || a.MappedProjectId > 0 || a.MappedTrustFundId > 0
                     where a.IatiIdentifier == iatiIdentifier && isMapped
                     select new ActivityModel
                     {
                         IatiActivity = a.IatiActivity,
                         OrgId = a.OrgId,
                         ProjectId = a.ProjectId,
                         MappedProjectId = a.MappedProjectId,
                         MappedTrustFundId = a.MappedTrustFundId,
                         IsInclude = a.IsInclude
                     }).FirstOrDefault();

            if (q == null) return null;

            var iatiActivity = ParseXMLAndResolve(new List<ActivityModel> { q }).FirstOrDefault();

            LoadChildActivities(iatiActivity);

            var aimsProject = new AimsDAL().GetAIMSProjectInIATIFormat(q.ProjectId > 0 ? q.ProjectId :
                                    q.MappedProjectId > 0 ? q.MappedProjectId :
                                    0);

            foreach (var aimsTransaction in aimsProject.transaction)
            {
                var isFoundInIati = iatiActivity.transaction.Any(a => a.transactiontype?.code == aimsTransaction.transactiontype?.code
                    && a.transactiondate?.isodate == aimsTransaction.transactiondate?.isodate
                    && Math.Floor(a.ValUSD) == Math.Floor(aimsTransaction.ValUSD));

                aimsTransaction.IsConflicted = !isFoundInIati;
            }

            return new ProjectFieldMapModel(iatiActivity, aimsProject);
        }
Example #4
0
        public iatiactivityContainer GetAllActivities(string dp)
        {
            var q = (from a in dbContext.Activities
                     where a.AssignedOrgId == dp
                     orderby a.IatiIdentifier
                     select new ActivityModel
                     {
                         IatiActivity = a.IatiActivity,
                         OrgId = a.OrgId,
                         ProjectId = a.ProjectId,
                         MappedProjectId = a.MappedProjectId,
                         MappedTrustFundId = a.MappedTrustFundId,
                         IsInclude = a.IsInclude
                     }).ToList();

            var iatiActivities = ParseXMLAndResolve(q);


            var aimsActivities = new AimsDAL().GetAIMSProjectsInIATIFormat(dp);

            return new iatiactivityContainer
            {
                iatiActivities = iatiActivities,
                AimsProjects = aimsActivities
            };
        }
Example #5
0
        public int SaveAtivities(List<Activity> activities, List<iatiactivity> iatiActivities, tblFundSource fundSource)
        {

            foreach (var activity in activities)
            {
                var a = dbContext.Activities.FirstOrDefault(x => x.IatiIdentifier == activity.IatiIdentifier);
                if (a != null)
                {
                    a.OrgId = activity.OrgId;

                    a.IatiActivityPrev = a.IatiActivity;
                    a.IatiActivity = activity.IatiActivity;

                    a.Hierarchy = activity.Hierarchy;
                    a.ParentHierarchy = activity.ParentHierarchy;

                    a.DownloadDatePrev = a.DownloadDate;
                    a.DownloadDate = DateTime.Now;

                    //update aimsdb
                    if (a.ProjectId > 0 || a.MappedProjectId > 0)
                    {
                        var aimsDAL = new AimsDAL();

                        //step 1: project structure
                        var iactivities = new List<iatiactivity>();
                        if (a.Hierarchy == 1)
                            iactivities = ImportLogic.LoadH1ActivitiesWithChild(iatiActivities); // here pass all activities to find out their child activities
                        else
                            iactivities = ImportLogic.LoadH2ActivitiesWithParent(iatiActivities);

                        //step 2: get mapped iatiActivity and aimsProject
                        var iatiActivity = iactivities.Find(f => f.IatiIdentifier == a.IatiIdentifier);
                        // SetExchangedValues
                        SetExchangedValues(iatiActivity);
                        iatiActivity.childActivities.ForEach(ra => SetExchangedValues(ra));

                        var aimsProject = new iatiactivity();

                        if (a.ProjectId > 0)
                        {
                            aimsProject = aimsDAL.GetAIMSProjectInIATIFormat(a.ProjectId);
                            if (aimsProject != null)
                            {
                                //step 3: get general preference
                                var generalPreference = GetFieldMappingPreferenceGeneral(a.OrgId);

                                //step 4: create a ProjectFieldMapModel using iatiActivity, aimsProject and generalPreference
                                var ProjectFieldMapModel = new ProjectFieldMapModel(iatiActivity, aimsProject, generalPreference);

                                //step 5: SetFieldMappingPreferences
                                var ProjectFieldMapModels = new List<ProjectFieldMapModel>(); // here we make a list just to use existing method (e.g existing method require a List parameter)
                                ProjectFieldMapModels.Add(ProjectFieldMapModel);

                                ImportLogic.SetFieldMappingPreferences(ProjectFieldMapModels, ProjectFieldMapModel);

                                //step 6: merge iatiActivity and aimsProject; and get an new merged activity
                                var mergedActivities = ImportLogic.MergeProjects(ProjectFieldMapModels); //now it will allways return a list containing single activity
                                mergedActivities.n(0).AllID = fundSource.Id + "~" + a.OrgId + "~"
                                        + (int)ExecutingAgencyType.DP + "~"
                                        + fundSource.FundSourceCategoryId;
                                //step 7: update aims database with margedActivities
                                aimsDAL.UpdateProjects(mergedActivities, "system");
                            }
                            else
                            {
                                dbContext.Logs.Add(new Log
                                {
                                    IatiIdentifier = activity.IatiIdentifier,
                                    OrgId = activity.OrgId,
                                    ProjectId = a.MappedProjectId,
                                    Message = "The mapped project is not found in AIMS database",
                                    LogType = (int)LogType.AimsProjectNotFound,
                                    DateTime = DateTime.Now
                                });
                            }
                        }
                        else if (a.MappedProjectId > 0) //for co-finance projects
                        {
                            aimsProject = aimsDAL.GetAIMSProjectInIATIFormat(a.MappedProjectId);

                            if (aimsProject != null)
                            {
                                iatiActivity.AllID = fundSource.Id + "~" + a.OrgId + "~"
                                        + (int)ExecutingAgencyType.DP + "~"
                                        + fundSource.FundSourceCategoryId;


                                aimsProject.MatchedProjects.Add(iatiActivity);
                                //step 7: update aims database with margedActivities
                                aimsDAL.UpdateCofinanceProjects(new List<iatiactivity> { aimsProject }, "system");
                            }
                            else
                            {
                                dbContext.Logs.Add(new Log
                                {
                                    IatiIdentifier = activity.IatiIdentifier,
                                    OrgId = activity.OrgId,
                                    ProjectId = a.MappedProjectId,
                                    Message = "The mapped project is not found in AIMS database",
                                    LogType = (int)LogType.AimsProjectNotFound,
                                    DateTime = DateTime.Now
                                });
                            }

                        }

                    }

                }
                else
                {
                    activity.DownloadDate = DateTime.Now;
                    dbContext.Activities.Add(activity);

                    dbContext.Logs.Add(new Log
                    {
                        IatiIdentifier = activity.IatiIdentifier,
                        OrgId = activity.OrgId,
                        Message = "Imported new activity",
                        LogType = (int)LogType.AddedNewActivity,
                        DateTime = DateTime.Now
                    });
                }

            }

            return dbContext.SaveChanges();
        }
Example #6
0
        private List<ProjectFieldMapModel> PrepareMappedActivities(List<iatiactivity> iatiActivities, Activity a, AimsDAL aimsDAL)
        {
            //step 1: project structure
            var iactivities = new List<iatiactivity>();
            if (a.Hierarchy == 1)
                iactivities = ImportLogic.LoadH1ActivitiesWithChild(iatiActivities); // here pass all activities to find out their child activities
            else
                iactivities = ImportLogic.LoadH2ActivitiesWithParent(iatiActivities);

            //step 2: get mapped iatiActivity and aimsProject
            var iatiActivity = iactivities.Find(f => f.IatiIdentifier == a.IatiIdentifier);
            // SetExchangedValues
            SetExchangedValues(iatiActivity);
            iatiActivity.childActivities.ForEach(ra => SetExchangedValues(ra));

            var aimsProject = new iatiactivity();
            if (a.ProjectId > 0)
            {
                aimsProject = aimsDAL.GetAIMSProjectInIATIFormat(a.ProjectId);
            }
            else if (a.MappedProjectId > 0) //for co-finance projects
            {
                aimsProject = aimsDAL.GetAIMSProjectInIATIFormat(a.MappedProjectId);
            }

            //step 3: get general preference
            var generalPreference = GetFieldMappingPreferenceGeneral(a.OrgId);

            //step 4: create a ProjectFieldMapModel using iatiActivity, aimsProject and generalPreference
            var ProjectFieldMapModel = new ProjectFieldMapModel(iatiActivity, aimsProject, generalPreference);

            //step 5: SetFieldMappingPreferences
            var ProjectFieldMapModels = new List<ProjectFieldMapModel>(); // here we make a list just to use existing method (e.g existing method require a List parameter)
            ProjectFieldMapModels.Add(ProjectFieldMapModel);

            ImportLogic.SetFieldMappingPreferences(ProjectFieldMapModels, ProjectFieldMapModel);
            return ProjectFieldMapModels;
        }