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> */ }
static public Data Yandex(XmlNode cXmlNode) { Data cRetVal = null; if (null != cXmlNode) { cRetVal = new Data(); string sCode = cXmlNode.NodeGet("weather_condition").AttributeValueGet("code").ToLower(); #region condition switch (sCode) { case "cloudy-thunderstorms-with-wet-snow": cRetVal.eType = Type.Clouds | Type.RainHeavy; //weather_icn_bkn_+ra_d_pal_c break; case "cloudy": case "thin-high-clouds": cRetVal.eType = Type.Clouds; //weather_icn_bkn_d_pal_c break; case "cloudy-and-showers": case "cloudy-and-wet-snow-showers": case "cloudy-and-rain": case "cloudy-thunderstorms-with-rain": case "cloudy-and-light-rain": case "cloudy-and-light-wet-snow": case "cloudy-thunderstorms-with-snow": cRetVal.eType = Type.Clouds | Type.Rain; //weather_icn_bkn_-ra_d_pal_c break; case "cloudy-and-snow": cRetVal.eType = Type.Clouds | Type.SnowMore; //weather_icn_bkn_sn_d_pal_c break; case "cloudy-and-snow-showers": case "cloudy-and-wet-snow": case "cloudy-and-light-snow": cRetVal.eType = Type.Clouds | Type.Snow; //weather_icn_bkn_-sn_d_pal_c break; case "intermittent-heavy-drizzle": case "intermittent-heavy-rain": case "rain-showers": case "violent-rain-showers": case "continuous-heavy-rain": case "moderate-to-heavy-rain-showers": case "light-rain-showers": case "funnel-clouds-within-sight": case "squalls-within-sight-but-no-precipitation-falling-at-station": cRetVal.eType = Type.CloudsHeavy | Type.RainHeavy; //weather_icn_ovc_+ra_pal_c break; case "heavy-drifting-snow-above-eye-level": cRetVal.eType = Type.CloudsHeavy | Type.SnowHeavy; //weather_icn_ovc_+sn_pal_c break; case "freezing-rain": case "hail-showers": case "heavy-thunderstorm-with-hail": case "moderate-to-heavy-freezing-drizzle": case "moderate-to-heavy-hail-showers": case "moderate-to-heavy-freezing-rain": case "light-snow-ice-pellet-showers": case "light-hail-showers": case "light-freezing-rain": case "light-snow-showers": case "snow-grains": cRetVal.eType = Type.CloudsHeavy | Type.Hail; //weather_icn_ovc_gr_pal_c break; case "visibility-reduced-by-smoke": case "mist": case "clouds-dissolving": case "mostly-clear": case "state-of-sky-unchanged": case "mostly-clear-slight-possibility-of-rain": case "mostly-clear-slight-possibility-of-snow": case "mostly-clear-slight-possibility-of-wet-snow": case "overcast": case "clouds-developing": case "partly-cloudy": case "widespread-dust-in-suspension-not-raised-by-wind": case "dust-or-sand-raised-by-wind": case "dust-or-sand-storm-within-sight-but-not-at-station": case "slight-to-moderate-duststorm-decreasing-in-intensity": case "slight-to-moderate-duststorm-increasing-in-intensity": case "slight-to-moderate-duststorm-no-change": case "well-developed-dust-or-sand-whirls": case "severe-duststorm-decreasing-in-intensity": case "severe-duststorm-increasing-in-intensity": case "severe-duststorm-no-change": cRetVal.eType = Type.CloudsHeavy; //weather_icn_ovc_pal_c break; case "patches-of-fog": case "continuous-shallow-fog": case "fog": case "fog-at-a-distance": case "fog-sky-visible-becoming-thicker": case "fog-sky-visible-no-change": case "fog-sky-visible-thinning": case "patches-of-shallow-fog": case "fog-depositing-rime-sky-visible": cRetVal.eType = Type.Fog; //weather_icn_ovc_fg_pal_c break; case "fog-sky-not-visible-becoming-thicker": case "fog-sky-not-visible-no-change": case "fog-sky-not-visible-thinning": case "fog-depositing-rime-sky-not-visible": cRetVal.eType = Type.FogMore; //weather_icn_ovc_+fg_pal_c break; case "intermittent-moderate-rain": case "intermittent-moderate-drizzle": case "intermittent-light-drizzle": case "intermittent-light-rain": case "continuous-moderate-rain": case "rain": case "continuous-moderate-drizzle": case "overcast-and-showers": case "overcast-and-rain": case "overcast-and-light-rain": case "distant-precipitation-but-not-falling-at-station": case "nearby-precipitation-but-not-falling-at-station": case "precipitation-within-sight-but-not-hitting-ground": case "partly-cloudy-and-showers": case "partly-cloudy-and-rain": case "partly-cloudy-and-light-rain": case "continuous-light-drizzle": case "light-drizzle-and-rain": case "continuous-light-rain": cRetVal.eType = Type.CloudsHeavy | Type.Rain; //weather_icn_ovc_-ra_pal_c break; case "intermittent-heavy-snow": case "overcast-and-snow-showers": case "heavy-drifting-snow-below-eye-level": case "continuous-heavy-snow": cRetVal.eType = Type.CloudsHeavy | Type.SnowMore; //weather_icn_ovc_sn_pal_c break; case "intermittent-light-snow": cRetVal.eType = Type.CloudsHeavy | Type.Snow; //weather_icn_ovc_-sn_pal_c break; case "intermittent-moderate-snow": case "slight-to-moderate-drifting-snow-above-eye-level": case "overcast-and-light-snow": case "overcast-and-snow": case "snow-crystals": case "partly-cloudy-and-snow-showers": case "partly-cloudy-and-light-snow": case "partly-cloudy-and-snow": case "slight-to-moderate-drifting-snow-below-eye-level": case "cold-snap": case "abrupt-cold-snap": case "continuous-heavy-drizzle": case "light-freezing-drizzle": case "continuous-light-snow": case "continuous-moderate-snow": case "snow": cRetVal.eType = Type.CloudsHeavy | Type.Snow; //weather_icn_ovc_-sn_pal_c break; case "light-to-moderate-thunderstorm": case "thunderstorm-but-no-precipitation-falling-at-station": case "thunderstorms": case "light-to-moderate-thunderstorm-with-hail": case "heavy-thunderstorm-with-duststorm": case "overcast-thunderstorms-with-rain": case "heavy-thunderstorm": case "thunderstorm-in-past-hour-currently-only-moderate-to-heavy-snow-or-rain-snow-mix": case "thunderstorm-in-past-hour-currently-only-moderate-to-heavy-rain": case "thunderstorm-in-past-hour-currently-only-light-rain": cRetVal.eType = Type.CloudsHeavy | Type.Thunderstorm | Type.Rain; //weather_icn_ovc_ts_ra_pal_c break; case "lightning-visible-no-thunder-heard": cRetVal.eType = Type.Lighting; //weather_icn_lt_pal_c break; case "rain-and-snow": case "ice-pellets": case "diamond-dust": case "moderate-to-heavy-snow-ice-pellet-showers": case "snow-showers": case "mostly-clear-possible-thunderstorms-with-wet-snow": case "mostly-clear-possible-thunderstorms-with-rain": case "mostly-clear-possible-thunderstorms-with-snow": case "drizzle": case "overcast-and-wet-snow-showers": case "overcast-and-wet-snow": case "overcast-thunderstorms-with-wet-snow": case "overcast-and-light-wet-snow": case "overcast-thunderstorms-with-snow": case "partly-cloudy-possible-thunderstorms-with-wet-snow": case "partly-cloudy-possible-thunderstorms-with-rain": case "partly-cloudy-possible-thunderstorms-with-snow": case "partly-cloudy-and-wet-snow-showers": case "partly-cloudy-and-wet-snow": case "partly-cloudy-and-light-wet-snow": case "moderate-to-heavy-drizzle-and-rain": case "moderate-to-heavy-rain-and-snow": case "moderate-to-heavy-rain-and-snow-showers": case "moderate-to-heavy-snow-showers": case "light-rain-and-snow": case "thunderstorm-in-past-hour-currently-only-light-snow-or-rain-snow-mix": case "light-rain-and-snow-showers": cRetVal.eType = Type.CloudsHeavy | Type.Thunderstorm | Type.Rain | Type.Snow; //weather_icn_ovc_ts_ra_sn_pal_c break; case "haze": cRetVal.eType = Type.Haze; //weather_icn_mst_pal_c break; default: case "abrupt-warming": case "clear": case "clear-skies": cRetVal.eType = Type.Clear; //weather_icn_skc_d_pal_c break; } #endregion condition cRetVal.sDetails = cXmlNode.NodeGet("weather_type").InnerText; XmlNode cXN = cXmlNode.NodeGet("temperature-data", false); if (null != cXN) { cXN = cXN.NodeGet("avg"); cRetVal.nColor = ("0x" + cXN.AttributeValueGet("bgcolor")).ToUInt32(); } else { cXN = cXmlNode.NodeGet("temperature"); cRetVal.nColor = ("0x" + cXN.AttributeValueGet("color")).ToUInt32(); } cRetVal.nTemperature = cXN.InnerText.ToShort(); } return cRetVal; }