Beispiel #1
0
        private void backgroundWorkerRssLoad_DoWork(object sender, DoWorkEventArgs e)
        {
            string rssUrlAll = String.Format("{0}/{1}",
                Properties.Settings.Default.JenkinsUrl, AdvancedSettings.Default.RssKeywordAll);

            string rssUrlFail = String.Format("{0}/{1}",
                    Properties.Settings.Default.JenkinsUrl, AdvancedSettings.Default.RssKeywordFailures);
            List<System.Xml.XmlNode[]> myChanges = new List<System.Xml.XmlNode[]>();
            try
            {
                DataSet rssDataSet = new DataSet();
                rssDataSet.ReadXml(getHttpStream(rssUrlAll));

                XmlSerializer serializer = new XmlSerializer(typeof(feed));
                feed fd = (feed)serializer.Deserialize(getHttpStream(rssUrlFail));
                List<NotificationData> notifications = new List<NotificationData>();
                if (!Properties.Settings.Default.NotifyAllErrors && Properties.Settings.Default.NotifyMyErrors)
                {
                    foreach (feedEntry fe in fd.entry)
                    {
                        Trace.TraceInformation("Processing feed " + fe.id);
                        try
                        {
                            string data = getHttpData(fe.link.href + "api/xml");
                            //Dirty fix, don't know how to correctly handle this
                            data = data.Replace("mavenBuild",
                                "freeStyleBuild").Replace("mavenModuleSetBuild",
                                "freeStyleBuild").Replace("matrixBuild",
                                "freeStyleBuild").Replace("matrixRun", "freeStyleBuild");

                            byte[] a = System.Text.Encoding.GetEncoding("iso-8859-1").GetBytes(data);
                            System.IO.MemoryStream m = new System.IO.MemoryStream(a);

                            XmlSerializer job = new XmlSerializer(typeof(hudsonmodelFreeStyleBuild));
                            hudsonmodelFreeStyleBuild build = (hudsonmodelFreeStyleBuild)job.Deserialize(m);

                            NotificationData nd = ProcessBuild(build);
                            if (null != nd)
                            {
                                nd.jobUrl = fe.link.href;
                                nd.jobDate = fe.id.Split(new char[] { ':' })[3];
                                nd.jobId = fe.id.Split(new char[] { ':' })[2];
                                notifications.Add(nd);
                            }
                        }
                        catch(Exception feedExp)
                        {
                            Trace.TraceError("Error while processing item in feed, skipping and proceeding with next", feedExp);
                        }
                    }
                }
                else if (Properties.Settings.Default.NotifyAllErrors)
                {
                    foreach (feedEntry fe in fd.entry)
                    {
                        Trace.TraceInformation("Processing feed (no user check)" + fe.id);
                        NotificationData nd = new NotificationData();
                        nd.jobUrl = fe.link.href;
                        nd.jobDate = fe.id.Split(new char[] { ':' })[3];
                        nd.jobId = fe.id.Split(new char[] { ':' })[2];
                        notifications.Add(nd);
                    }
                }

                e.Result = new object[] { rssDataSet, notifications };
            }
            catch (Exception exp)
            {
                Trace.TraceError("Error in loading RSS feeds", exp);
            }
        }
Beispiel #2
0
        private NotificationData ProcessBuild(hudsonmodelFreeStyleBuild build)
        {
            Trace.TraceInformation("Checking build for user activity");
            string username = Environment.GetEnvironmentVariable("USERNAME").ToLower();
            NotificationData nd = null;
            foreach (hudsonscmChangeLogSet changeset in build.changeSet)
            {
                if (changeset.item != null)
                {
                    foreach (object change in changeset.item)
                    {
                        System.Xml.XmlNode[] changedata = (System.Xml.XmlNode[])change;

                        foreach (System.Xml.XmlNode param in changedata)
                        {
                            if (param.Name == "user")
                            {
                                string changedby = param.InnerText;
                                if (changedby.ToLower() == username)
                                {
                                    if (null == nd)
                                    {
                                        nd = new NotificationData();
                                    }
                                    nd = ProcessChangeSet(changedata, nd);
                                }
                            }
                        }
                    }
                }
            }
            return nd;
        }
Beispiel #3
0
 private NotificationData ProcessChangeSet(System.Xml.XmlNode[] data, NotificationData nd)
 {
     Trace.TraceInformation("Checking build for changesets");
     foreach (System.Xml.XmlNode param in data)
     {
         switch (param.Name)
         {
             case "date":
                 nd.date.Add(param.InnerText);
                 break;
             case "msg":
                 nd.msg.Add(param.InnerText);
                 break;
             case "path":
                 nd.paths.Add(param.InnerText);
                 break;
             case "revision":
                 nd.revision.Add(param.InnerText);
                 break;
             case "user":
                 break;
             default:
                 Trace.TraceError("This should never come");
                 break;
         }
     }
     return nd;
 }
        private void backgroundWorkerRssLoad_DoWork(object sender, DoWorkEventArgs e)
        {
            string rssUrlAll = String.Format("{0}/{1}",
                                             Properties.Settings.Default.JenkinsUrl, AdvancedSettings.Default.RssKeywordAll);

            string rssUrlFail = String.Format("{0}/{1}",
                                              Properties.Settings.Default.JenkinsUrl, AdvancedSettings.Default.RssKeywordFailures);
            List <System.Xml.XmlNode[]> myChanges = new List <System.Xml.XmlNode[]>();

            try
            {
                DataSet rssDataSet = new DataSet();
                rssDataSet.ReadXml(getHttpStream(rssUrlAll));

                XmlSerializer           serializer    = new XmlSerializer(typeof(feed));
                feed                    fd            = (feed)serializer.Deserialize(getHttpStream(rssUrlFail));
                List <NotificationData> notifications = new List <NotificationData>();
                if (!Properties.Settings.Default.NotifyAllErrors && Properties.Settings.Default.NotifyMyErrors)
                {
                    foreach (feedEntry fe in fd.entry)
                    {
                        Trace.TraceInformation("Processing feed " + fe.id);
                        try
                        {
                            string data = getHttpData(fe.link.href + "api/xml");
                            //Dirty fix, don't know how to correctly handle this
                            data = data.Replace("mavenBuild",
                                                "freeStyleBuild").Replace("mavenModuleSetBuild",
                                                                          "freeStyleBuild").Replace("matrixBuild",
                                                                                                    "freeStyleBuild").Replace("matrixRun", "freeStyleBuild");

                            byte[] a = System.Text.Encoding.GetEncoding("iso-8859-1").GetBytes(data);
                            System.IO.MemoryStream m = new System.IO.MemoryStream(a);

                            XmlSerializer             job   = new XmlSerializer(typeof(hudsonmodelFreeStyleBuild));
                            hudsonmodelFreeStyleBuild build = (hudsonmodelFreeStyleBuild)job.Deserialize(m);

                            NotificationData nd = ProcessBuild(build);
                            if (null != nd)
                            {
                                nd.jobUrl  = fe.link.href;
                                nd.jobDate = fe.id.Split(new char[] { ':' })[3];
                                nd.jobId   = fe.id.Split(new char[] { ':' })[2];
                                notifications.Add(nd);
                            }
                        }
                        catch (Exception feedExp)
                        {
                            Trace.TraceError("Error while processing item in feed, skipping and proceeding with next", feedExp);
                        }
                    }
                }
                else if (Properties.Settings.Default.NotifyAllErrors)
                {
                    foreach (feedEntry fe in fd.entry)
                    {
                        Trace.TraceInformation("Processing feed (no user check)" + fe.id);
                        NotificationData nd = new NotificationData();
                        nd.jobUrl  = fe.link.href;
                        nd.jobDate = fe.id.Split(new char[] { ':' })[3];
                        nd.jobId   = fe.id.Split(new char[] { ':' })[2];
                        notifications.Add(nd);
                    }
                }

                e.Result = new object[] { rssDataSet, notifications };
            }
            catch (Exception exp)
            {
                Trace.TraceError("Error in loading RSS feeds", exp);
            }
        }