Inheritance: IConverterIATI
Example #1
0
        public XmlResultv2 ConvertIATI(string org, string country)
        {
            string activitiesURL;
            IParserIATI parserIATI;
            XmlResultv2 returnResult2 = null;
            XmlResultv1 returnResult1 = null;

            try
            {
                activitiesURL = "http://datastore.iatistandard.org/api/1/access/activity.xml?recipient-country=" + country + "&reporting-org=" + org + "&stream=True";
                //Parser v2.01
                parserIATI = new ParserIATIv2();

                returnResult2 = (XmlResultv2)parserIATI.ParseIATIXML(activitiesURL);

                var iatiactivityArray = returnResult2?.iatiactivities?.iatiactivity;
                if (iatiactivityArray != null && iatiactivityArray.n()[0].AnyAttr.n()[0].Value.StartsWith("1.0"))
                {
                    //Parser v1.05
                    parserIATI = new ParserIATIv1();
                    returnResult1 = (XmlResultv1)parserIATI.ParseIATIXML(activitiesURL);

                    //Conversion
                    ConvertIATIv2 convertIATIv2 = new ConvertIATIv2();
                    returnResult2 = convertIATIv2.ConvertIATI105to201XML(returnResult1, returnResult2);
                }
            }
            catch (Exception ex)
            {
                returnResult2.n().Value = ex.Message;
            }

            return returnResult2;
            //return Newtonsoft.Json.JsonConvert.SerializeObject(returnResult2);
        }
Example #2
0
        public void Parse(int fundSourcesCount, int i, tblFundSource fundSource)
        {



            IParserIATI parserIATI;
            //IConverterIATI converterIATI;
            string activitiesURL;
            XmlResultv2 returnResult2;
            XmlResultv1 returnResult1;
            try
            {
                Logger.Write("");
                Logger.Write(i + "/" + fundSourcesCount + " " + fundSource.FundSourceName + " (" + fundSource.IATICode + ")");
                Logger.Write("-------------------->");
                Logger.Write("INFO: Downloading...");

                #region Convert Data from v1.05 to v2.01

                //Parser v2.01
                parserIATI = new ParserIATIv2();
                //activitiesURL = "http://datastore.iatistandard.org/api/1/access/activity.xml?recipient-country=BD&reporting-org=CA-3&stream=True" //"http://localhost:1000/UploadedFiles/activity_GB-1_2.xml";
                //single activity : "http://datastore.iatistandard.org/api/1/access/activity.xml?iati-identifier=CA-3-A035529001
                //Params: activity.xml or activity.json, recipient-country=BD, reporting-org=CA-3
                activitiesURL = Common.iati_url + "recipient-country=" + Common.iati_recipient_country + "&reporting-org=" + fundSource.IATICode + "&stream=" + Common.iati_stream;
                returnResult2 = (XmlResultv2)parserIATI.ParseIATIXML(activitiesURL);

                Logger.Write("INFO: " + "Parsing...");

                var iatiactivityArray = returnResult2?.iatiactivities?.iatiactivity;
                if (iatiactivityArray != null && iatiactivityArray.n()[0].AnyAttr.n()[0].Value.StartsWith("1.0")) //1.04, 1.05
                {
                    //Parser v1.05
                    parserIATI = new ParserIATIv1();
                    //activitiesURL = "http://datastore.iatistandard.org/api/1/access/activity.xml?recipient-country=BD&reporting-org=GB-1&stream=True"; //"http://localhost:1000/UploadedFiles/activity_GB-1_2.xml";
                    //Params: activity.xml or activity.json, recipient-country=BD, reporting-org=GB-1 or XM-DAC-12-1
                    returnResult1 = (XmlResultv1)parserIATI.ParseIATIXML(activitiesURL);

                    Logger.Write("INFO: " + "Parsing completed!");

                    //Conversion
                    ConvertIATIv2 convertIATIv2 = new ConvertIATIv2();
                    returnResult2 = convertIATIv2.ConvertIATI105to201XML(returnResult1, returnResult2);
                    Logger.Write("INFO: " + "Convertion completed!");
                }

                #endregion

                iatiactivityArray = returnResult2?.iatiactivities?.iatiactivity;
                if (iatiactivityArray != null)
                {
                    SaveToDB(fundSource, iatiactivityArray);
                }
            }
            catch (DbEntityValidationException ex)
            {
                string messages = "";
                foreach (var validationErrors in ex.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        messages += string.Format("\nProperty: {0} Error: {1}",
                                                validationError.PropertyName,
                                                validationError.ErrorMessage);
                    }
                }
                Logger.WriteToDbAndFile(ex, LogType.ValidationError, fundSource.IATICode, null, messages);

            }
            catch (Exception ex)
            {
                Logger.WriteToDbAndFile(ex, LogType.Error, fundSource.IATICode);
            }
        }