示例#1
0
 private XmlNode Yandex()
 {
     if (DateTime.Now >= _cTemplate.dtNext)
     {
         int nBuild;
         XmlNode cResult;
         XmlNode[] aItems;
         XmlDocument cXmlDocument = new XmlDocument();
         cXmlDocument.LoadXml((new System.Net.WebClient() { Encoding = Encoding.UTF8 }).DownloadString("http://news.yandex.ru/index.rss"));
         nBuild = cXmlDocument.NodeGet("rss/channel/lastBuildDate").InnerText.GetHashCode();
         if (_cTemplate.nBuild != nBuild)
         {
             aItems = cXmlDocument.NodesGet("rss/channel/item", false);
             if (null != aItems)
             {
                 _cTemplate.nBuild = nBuild;
                 cXmlDocument = new XmlDocument();
                 cResult = cXmlDocument.CreateNode(XmlNodeType.Element, "result", null);
                 XmlNode cXNItem;
                 foreach (string sItem in aItems.Select(o => o.NodeGet("title").InnerText).ToArray())
                 {
                     cXNItem = cXmlDocument.CreateNode(XmlNodeType.Element, "item", null);
                     cXNItem.InnerText = sItem.StripTags() + ".    ";
                     cResult.AppendChild(cXNItem);
                 }
                 _cTemplate.cValue = cResult;
                 _cTemplate.dt = DateTime.Now;
             }
             else
                 (new Logger()).WriteWarning("can't get any news from rss");
         }
     }
     return _cTemplate.cValue;
 }
示例#2
0
                private XmlNode Yahoo()
                {
                    if (DateTime.Now >= _cTemplate.dtNext)
                    {
                        int nBuild;
                        XmlNode cResult, cXN, cXNChild;
                        XmlAttribute cXA;
                        XmlNode[] aItems;
                        XmlDocument cXmlDocument = new XmlDocument();
                        cXmlDocument.LoadXml((new System.Net.WebClient() { Encoding = Encoding.UTF8 }).DownloadString("https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(%22%5EIPSA%22%2C%22%5ESSEC%22%2C%22%5EFCHI%22%2C%22%5EHSI%22%2C%22%5EJKSE%22%2C%22%5EN225%22%2C%22%5EKLSE%22%2C%22%5EAEX%22%2C%22%5EKS11%22%2C%22%5ESSMI%22%2C%22%5ETNX%22%2C%22%5EIRX%22%2C%22%5ETYX%22%2C%22%5EFVX%22%2C%22%5EFTSE%22%2C%22%5EATX%22%2C%22ASX%22%2C%22BSE%22%2C%22%5ESTI%22%2C%22DOW%22%2C%22RTS.RS%22)%0A&diagnostics=false&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys"));
                        nBuild = cXmlDocument.InnerText.GetHashCode();
                        if (_cTemplate.nBuild != nBuild)
                        {
                            aItems = cXmlDocument.NodesGet("query/results/quote", false);
							string sValue;
                            if (null != aItems)
                            {
                                _cTemplate.nBuild = nBuild;
                                cXmlDocument = new XmlDocument();
                                cResult = cXmlDocument.CreateNode(XmlNodeType.Element, "result", null);
                                foreach (XmlNode cXNQuote in aItems)
                                {
									if ((sValue = cXNQuote.NodeGet("Open").InnerText).IsNullOrEmpty())
										continue;
                                    cXN = cXmlDocument.CreateNode(XmlNodeType.Element, "item", null);

                                    cXNChild = cXmlDocument.CreateNode(XmlNodeType.Element, "item", null);
                                    cXA = cXmlDocument.CreateAttribute("id");
                                    cXA.Value = "ticker";
                                    cXNChild.Attributes.Append(cXA);
                                    cXNChild.InnerText = cXNQuote.AttributeValueGet("symbol").Replace("^", "");
                                    cXN.AppendChild(cXNChild);

                                    cXNChild = cXmlDocument.CreateNode(XmlNodeType.Element, "item", null);
                                    cXA = cXmlDocument.CreateAttribute("id");
                                    if(cXNQuote.NodeGet("Change").InnerText.StartsWith("-"))
                                        cXA.Value = "negative";
                                    else
                                        cXA.Value = "positive";
                                    cXNChild.Attributes.Append(cXA);
									cXNChild.InnerText = " " + sValue;

                                    cXN.AppendChild(cXNChild);

                                    cResult.AppendChild(cXN);
                                }
                                _cTemplate.cValue = cResult;
                                _cTemplate.dt = DateTime.Now;
                            }
                            else
                                (new Logger()).WriteWarning("can't get currencies");
                        }
                    }
                    return _cTemplate.cValue;
                }
示例#3
0
		public Preferences(string sWorkFolder, string sData)
        {
			nTop = nLeft = 0;
			bCUDA = true;
			if (!Directory.Exists(_sFolderFootages = Path.Combine(_sWorkFolder = sWorkFolder, "footages")))
				Directory.CreateDirectory(_sFolderFootages);
			if (!Directory.Exists(_sFolderPoll = Path.Combine(_sFolderFootages, "polls")))
				Directory.CreateDirectory(_sFolderPoll);

			XmlDocument cXmlDocument = new XmlDocument();
			cXmlDocument.Load(Path.Combine(sWorkFolder, "preferences.xml"));

			if(null == (
				//берем самое старое голосование
				_cPoll = cXmlDocument.NodesGet("preferences/polls/poll").Select(o => new Poll()
						{
							sName = o.AttributeValueGet("name", false),
							dtLast = o.AttributeGet<DateTime>("dt", false),
							sDescription = o.NodeGet("description").InnerText,
							aCandidates = o.NodesGet("candidate").Select(o1 => new Poll.Candidate() {
								sName = o1.AttributeValueGet("name").ToLower(),
								sImage = o1.AttributeValueGet("image"),
								sDescription = o1.AttributeValueGet("description"),
								nVotesQty = 0
							}).ToArray()
						}).Where(o => 1 > _aPollsPreparing.Count(o1 => o1.nID == o.nID)).OrderBy(o => (x.ToDT(null) > o.dtLast ? o.dtLast.Ticks : 0)).FirstOrDefault()
					?? _aPollsPreparing.OrderBy(o => (x.ToDT(null) > o.dtLast ? o.dtLast.Ticks : 0)).FirstOrDefault()
			))
				throw new Exception("no poll specified");
			XmlNode cXmlNode = cXmlDocument.NodeGet("preferences/blender");
			sFolderBlender = cXmlNode.AttributeValueGet("folder");

			XmlDocument cXD = new XmlDocument();
			XmlAttribute cXA;


			XmlNode cXNBlend = cXmlNode.NodeGet("mat");
			cMat = cXD.CreateElement("data");
			cXA = cXD.CreateAttribute("effect");
			cXA.Value = "render";
			cMat.Attributes.Append(cXA);
			cXA = cXD.CreateAttribute("blend");
			cXA.Value = Path.Combine(sWorkFolder, "blender", cXNBlend.AttributeValueGet("blend"));
			cMat.Attributes.Append(cXA);
			cXA = cXD.CreateAttribute("threads");
			cXA.Value = cXNBlend.AttributeValueGet("threads");
			cMat.Attributes.Append(cXA);

			XmlNode cPython = cXD.CreateElement("python");
			cPython.InnerText = cXNBlend.InnerText.
				Replace("{%_IMAGE_LEFT_%}", _cPoll.aCandidates[0].sImage).
				Replace("{%_IMAGE_RIGHT_%}", _cPoll.aCandidates[1].sImage).
				Replace("{%_TEXT_TOP_ARRAY_%}", "\"" + _cPoll.sDescription.Remove("\r").Split('\n').Select(o => o.Trim().Replace("\"", "\\\"")).Where(o => !o.IsNullOrEmpty()).Aggregate((r, o) => r += "\",\"" + o) + "\"").
				Replace("{%_TEXT_LEFT_%}", _cPoll.aCandidates[0].sDescription).
				Replace("{%_TEXT_RIGHT_%}", _cPoll.aCandidates[1].sDescription);
			cMat.AppendChild(cPython);

			cXNBlend = cXmlNode.NodeGet("votes");
			cVotes = cXD.CreateElement("data");
			cXA = cXD.CreateAttribute("effect");
			cXA.Value = "render";
			cVotes.Attributes.Append(cXA);
			cXA = cXD.CreateAttribute("blend");
			cXA.Value = Path.Combine(sWorkFolder, "blender", cXNBlend.AttributeValueGet("blend"));
			cVotes.Attributes.Append(cXA);
			cXA = cXD.CreateAttribute("threads");
			cXA.Value = cXNBlend.AttributeValueGet("threads");
			cVotes.Attributes.Append(cXA);
			cPython = cXD.CreateElement("python");
			cPython.InnerText = cXNBlend.InnerText;
			cVotes.AppendChild(cPython);

			if (!Directory.Exists(_sFolderPoll = Path.Combine(_sFolderPoll, (cMat.InnerText + cVotes.InnerText).GetHashCode().ToStr())))
				Directory.CreateDirectory(_sFolderPoll);

			cXA = cXD.CreateAttribute("output");
			cXA.Value = "*" + (sFolderMat = Path.Combine(_sFolderPoll, "mat"));
			cMat.Attributes.Append(cXA);
			cMat.InnerXml = cMat.InnerXml.Replace("{%_PATH_%}", sFolderMat.Replace("\\", "/"));
			if (!Directory.Exists(sFolderMat))
				Directory.CreateDirectory(sFolderMat);

			cXA = cXD.CreateAttribute("output");

			cXA.Value = "*" + (sFolderVotes = Path.Combine(_sFolderPoll, "votes"));
			cVotes.Attributes.Append(cXA);
			cVotes.InnerXml = cVotes.InnerXml.Replace("{%_PATH_%}", sFolderVotes.Replace("\\", "/"));
			if (!Directory.Exists(sFolderVotes))
				Directory.CreateDirectory(sFolderVotes);

			cXmlDocument.LoadXml(sData);
			cXmlNode = cXmlDocument.NodeGet("data");
			nLeft = cXmlNode.AttributeGet<short>("left");
			nTop = cXmlNode.AttributeGet<short>("top");
			bCUDA = cXmlNode.AttributeGet<bool>("cuda");
			nLayer = cXmlNode.AttributeGet<ushort>("layer");
		}
示例#4
0
                private XmlNode CBR()
                {
                    if (DateTime.Now >= _cTemplate.dtNext)
                    {
                        int nBuild;
                        XmlNode cResult, cXN, cXNChild;
                        XmlAttribute cXA;
                        XmlNode[] aItems;
                        XmlDocument cXmlDocument = new XmlDocument();
                        cXmlDocument.LoadXml((new System.Net.WebClient() { Encoding = Encoding.GetEncoding("windows-1251") }).DownloadString("http://www.cbr.ru/scripts/XML_daily.asp"));
                        nBuild = cXmlDocument.InnerText.GetHashCode();
                        if (_cTemplate.nBuild != nBuild)
                        {
                            aItems = cXmlDocument.NodesGet("ValCurs/Valute", false); //[Nominal=1]
                            if (null != aItems)
                            {
                                _cTemplate.nBuild = nBuild;
                                cXmlDocument = new XmlDocument();
                                cResult = cXmlDocument.CreateNode(XmlNodeType.Element, "result", null);
                                foreach (XmlNode cXNCurrency in aItems)
                                {
                                    cXN = cXmlDocument.CreateNode(XmlNodeType.Element, "item", null);

                                    cXNChild = cXmlDocument.CreateNode(XmlNodeType.Element, "item", null);
                                    cXA = cXmlDocument.CreateAttribute("id");
                                    cXA.Value = "code";
                                    cXNChild.Attributes.Append(cXA);
                                    cXNChild.InnerText = cXNCurrency.NodeGet("CharCode").InnerText;
                                    cXN.AppendChild(cXNChild);

                                    cXNChild = cXmlDocument.CreateNode(XmlNodeType.Element, "item", null);
                                    cXA = cXmlDocument.CreateAttribute("id");
                                    cXA.Value = "value";
                                    cXNChild.Attributes.Append(cXA);
                                    cXNChild.InnerText = " " + cXNCurrency.NodeGet("Value").InnerText;
                                    cXN.AppendChild(cXNChild);

                                    cResult.AppendChild(cXN);
                                }
                                _cTemplate.cValue = cResult;
                                _cTemplate.dt = DateTime.Now;
                            }
                            else
                                (new Logger()).WriteWarning("can't get currencies");
                        }
                    }
                    return _cTemplate.cValue;
                }
示例#5
0
		public void PollUpdate()
		{
			string sFile = Path.Combine(_sWorkFolder, "preferences.xml");
			XmlDocument cXmlDocument = new XmlDocument();
			cXmlDocument.Load(sFile);
			XmlNode cXNPoll = cXmlDocument.NodesGet("preferences/polls/poll").Where(o => (new Poll()
			{
				sName = o.AttributeValueGet("name", false),
				dtLast = o.AttributeGet<DateTime>("dt", false),
				sDescription = o.NodeGet("description").InnerText,
				aCandidates = o.NodesGet("candidate").Select(o1 => new Poll.Candidate()
				{
					sName = o1.AttributeValueGet("name").ToLower(),
					sImage = o1.AttributeValueGet("image"),
					sDescription = o1.AttributeValueGet("description"),
					nVotesQty = 0
				}).ToArray()
			}).nID == _cPoll.nID).FirstOrDefault();

			if (null == cXNPoll)
				throw new Exception("cannot find target poll");
			cXNPoll.AttributeAdd("dt", _cPoll.dtLast = DateTime.Now);
			cXmlDocument.Save(sFile);
		}