Esempio n. 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;
 }
Esempio n. 2
0
        public Preferences(string sData)
        {
            XmlDocument cXmlDocument = new XmlDocument();
            cXmlDocument.LoadXml(sData);
            XmlNode cXmlNode = cXmlDocument.NodeGet("data");

            XmlNode cNodeChild = cXmlNode.NodeGet("playlist");
            _bCuda = cNodeChild.AttributeGet<bool>("cuda");
            _nLayer = cNodeChild.AttributeGet<ushort>("layer");
            cNodeChild = cNodeChild.NodeGet("area");
            _stArea = new Area(
                    cNodeChild.AttributeGet<short>("left"),
                    cNodeChild.AttributeGet<short>("top"),
                    cNodeChild.AttributeGet<ushort>("width"),
                    cNodeChild.AttributeGet<ushort>("height")
                );
        }
Esempio n. 3
0
        public Preferences(string sWorkFolder, string sData)
        {
			_bUseOutput = true;
            XmlDocument cXmlDocument = new XmlDocument();
            XmlNode cXmlNode;
			string sExclamationTarget;
			bool bExclamationExists = false;
			bool bOutput = true;
            if (null == _sPath)
            {
                cXmlDocument.Load(Path.Combine(sWorkFolder, "preferences.xml"));
                cXmlNode = cXmlDocument.NodeGet("preferences/blender");
                _sPath = cXmlNode.AttributeValueGet("path");
                _sCache = cXmlNode.AttributeValueGet("cache");
                if (!Directory.Exists(_sCache))
                    Directory.CreateDirectory(_sCache);
            }
            cXmlDocument.LoadXml(sData);
            cXmlNode = cXmlDocument.NodeGet("data");
            string sValue = cXmlNode.AttributeValueGet("data", false);
            if (null != sValue)
                cData = new Data(this, sValue);
			_sOutputTarget = cXmlNode.AttributeValueGet("output", false);
			if(null != _sOutputTarget && _sOutputTarget.StartsWith("*"))
			{
				_bUseOutput = false;
				if((_sOutputTarget = _sOutputTarget.Substring(1)).IsNullOrEmpty())
					_sOutputTarget = null;
			}
			if ((null == _sOutputTarget))  // ЛЁХ! если output есть, всегда ли надо чтобы было !_bExists  даже если папка существует????????  раньше так было, но правильно ли это????
			{
				bOutput = false;
				int nHash = sData.GetHashCode();
				_sOutputTarget = Path.Combine(_sCache, nHash.ToString());
			}
				
			sExclamationTarget = AddExclamationToFolder(_sOutputTarget);
			lock (_oLock)
			{
				if (!(_bExists = Directory.Exists(_sOutputTarget)))
				{
					bExclamationExists = Directory.Exists(sExclamationTarget);
					if (bExclamationExists && Directory.GetLastWriteTime(sExclamationTarget) < DateTime.Now.AddHours(-3))  // временная папка заброшена
					{
						Directory.Delete(sExclamationTarget, true);
						(new Logger()).WriteWarning("Удалили заброшенную Папку: " + sExclamationTarget);
						bExclamationExists = false;
					}
					if (!bExclamationExists)
						Directory.CreateDirectory(sExclamationTarget);
				}
			}

			if (bExclamationExists)
			{
				_bExists = WaitForTargetFolder(_sOutputTarget);

				if (!_bExists)
					throw new Exception("imposible state - folder vanished: " + _sOutputTarget);
			}

			DateTime dtNow = DateTime.Now;

			if (_bExists)
			{
				try
				{
					Directory.SetLastWriteTime(_sOutputTarget, dtNow);
				}
				catch { }
			}

			if (!bOutput)
			{
				if (!_bExists)
				{
					TimeSpan tsAgeMaximum = TimeSpan.FromDays(7);
					string sFilesDeleted = "", sFilesDeleteFailed = "";
					foreach (FileSystemInfo cFSInf in (new DirectoryInfo(_sCache)).GetFileSystemInfos())
					{
						if (!cFSInf.Attributes.HasFlag(FileAttributes.Directory) || tsAgeMaximum > dtNow.Subtract(cFSInf.LastWriteTime))
							continue;
						try
						{
							Directory.Delete(cFSInf.FullName, true);
							sFilesDeleted += cFSInf.Name + ",";
						}
						catch (Exception ex)
						{
							(new Logger()).WriteError(ex);
							sFilesDeleteFailed += cFSInf.Name + ",";
						}
					}
					if (0 < sFilesDeleted.Length)
						(new Logger()).WriteNotice("Папки удалены из кэша:" + sFilesDeleted.TrimEnd(',') + ". Не удалось удалить:" + sFilesDeleteFailed.TrimEnd(','));//TODO LANG
				}
			}

			XmlNode cChildNode = null;
			_sEngine = cXmlNode.AttributeValueGet("engine", false);
			_sThreads = cXmlNode.AttributeValueGet("threads", false);
			cChildNode = cXmlNode.NodeGet("python", false);
			if (null != cChildNode)
				_sPython = cChildNode.InnerXml.Trim().FromXML();
			_sPythonFile = null;
			_sBlendFile = cXmlNode.AttributeValueGet("blend");

			if (null != (cChildNode = cXmlNode.NodeGet("animation", false)))
			{
				_iVideo = new Animation() { nLoopsQty= (null == (sValue = cChildNode.AttributeValueGet("loops", false)) ? (ushort)1 : sValue.ToUShort()) };
			}
			else if (null != (cChildNode = cXmlNode.NodeGet("video", false)))
			{
				_iVideo = new Video();
			}
			if(null != _iVideo)
			{
				if(null != (sValue = cChildNode.AttributeValueGet("cuda", false)))
					_iVideo.bCUDA = sValue.ToBool();
				if(null != (sValue = cChildNode.AttributeValueGet("opacity", false)))
					_iVideo.bOpacity = sValue.ToBool();
				if(null != (sValue = cChildNode.AttributeValueGet("layer", false)))
					((IEffect)_iVideo).nLayer = sValue.ToUShort();
				if (null != (cChildNode = cChildNode.NodeGet("size", false)))
				{
					_iVideo.stArea = new Area(
									cChildNode.AttributeGet<short>("left"),
									cChildNode.AttributeGet<short>("top"),
									cChildNode.AttributeGet<ushort>("width"),
									cChildNode.AttributeGet<ushort>("height")
									);
				}
			}

            /*
            Plugin
            (all)plugin@file                - обязательный параметр. путь к dll плагина
            (all)plugin@class               - обязательный параметр. название класса плагина
            (chat)plugin/data               - не используется
            (rssroll)plugin/data            - не используется
            (blender)plugin/data            - обязательный параметр. содержит текст python-скрипта
            (blender)plugin/data@effect     - обязательный параметр. может принимать значения: animation, video
            (blender)plugin/data@blend      - обязательный параметр. путь к blend-файлу
            (blender)plugin/data@engine     - необязательный параметр. может принимать значения из списка:  BLENDER_RENDER, BLENDER_GAME, CYCLES
            (blender)plugin/data@threads    - необязательный параметр. кол-во нитей. может принимать значения от 0 до 64. 0 - кол-во нитей равное кол-ву системных процессоров

            пример:
            <plugin file="c:/.../blender.dll" class="Blender">
                <data effect="animation" blend="c:/.../target.blend" engine="CYCLES" threads="0">
                    import bpy
                    bpy.ops.render.render(animation=True)
                </data>
            </plugin>

            */
        }
Esempio n. 4
0
        public Preferences(string sData)
        {
            XmlDocument cXmlDocument = new XmlDocument();
            cXmlDocument.LoadXml(sData);
            XmlNode cXmlNode = cXmlDocument.NodeGet("data");
            sRequest = cXmlNode.AttributeValueGet("request");
            nTemplate = cXmlNode.AttributeGet<byte>("template");
            sValue = cXmlNode.AttributeValueGet("value", false);
            _nCheckInterval = cXmlNode.AttributeGet<int>("interval");

            XmlNode cNodeChild = cXmlNode.NodeGet("roll");
            _eDirection = cNodeChild.AttributeGet<btl.Roll.Direction>("direction");
            _nSpeed = cNodeChild.AttributeGet<float>("speed");
            _bRollCuda = cNodeChild.AttributeGet<bool>("cuda");
            _nLayer = cNodeChild.AttributeGet<ushort>("layer");
            _nQueueLength = cNodeChild.AttributeGet<byte>("queue");
			if (int.MaxValue == (_nPause = cNodeChild.AttributeGet<int>("pause", false)))
				_nPause = 0;
            cNodeChild = cNodeChild.NodeGet("area");
            _stArea = new Area(
                    cNodeChild.AttributeGet<short>("left"),
                    cNodeChild.AttributeGet<short>("top"),
                    cNodeChild.AttributeGet<ushort>("width"),
                    cNodeChild.AttributeGet<ushort>("height")
                );
            _aItems = cXmlNode.NodesGet("item").Select(o => Item.Parse(o)).ToList();
        }
Esempio n. 5
0
				private XmlNode Zed(string sName)
				{
					if (DateTime.Now >= _cTemplate.dtNext)
					{
						int nBuild;
						XmlNode cResult, cXN, cXNChild;
						XmlAttribute cXA;
						XmlNode cXNPoll;
						XmlDocument cXmlDocument = new XmlDocument();
						cXmlDocument.LoadXml((new System.Net.WebClient() { Encoding = Encoding.UTF8 }).DownloadString("http://tvscope2014.agregator.ru/out/out_votings_one_results.phtml?dtStart=01.04.2015&dtEnd=01.04.2016"));
						nBuild = cXmlDocument.InnerXml.GetHashCode();
						if (_cTemplate.nBuild != nBuild)
						{
							string sValue;
							if (null != (cXNPoll = cXmlDocument.NodeGet("votings/voting", false)))
							{
								_cTemplate.nBuild = nBuild;
								cXmlDocument = new XmlDocument();
								cResult = cXmlDocument.CreateNode(XmlNodeType.Element, "result", null);

								if (sName.ToLower() != cXNPoll.AttributeValueGet("name").ToLower())
									throw new Exception("specified poll does not exist");
								foreach (XmlNode cXNVariant in cXNPoll.NodesGet("variant", false))
								{
									cXN = cXmlDocument.CreateNode(XmlNodeType.Element, "item", null);

									cXA = cXmlDocument.CreateAttribute("name");
									cXA.Value = cXNVariant.AttributeValueGet("name");
									cXN.Attributes.Append(cXA);
									cXA = cXmlDocument.CreateAttribute("votes");
									cXA.Value = cXNVariant.AttributeValueGet("votes");
									cXN.Attributes.Append(cXA);

									cResult.AppendChild(cXN);
								}

								_cTemplate.cValue = cResult;
								_cTemplate.dt = DateTime.Now;
							}
							else
								(new Logger()).WriteWarning("can't get any poll");
						}
					}
					return _cTemplate.cValue;
				}
Esempio n. 6
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");
		}