public VisualizeData GetVisualizeData( NodeDataProvider dataProvider, GraphicsInfo graphicsInfo ) { XmlDocument xmlData = dataProvider.XmlDocument; MultyQueryResultInfo queriesResult = dataProvider.QueryResult; VisualizeData result = new VisualizeData { NodeLastUpdated = queriesResult.NodeLastUpdated, NodeLastUpdateDuration = queriesResult.NodeLastUpdateDuration }; if (xmlData != null && xmlData.DocumentElement != null) { result.SourceXml = xmlData.FormatXml(); } ConcreteTemplateNodeDefinition nodeDefinition = dataProvider.NodeDefinition; string xslFileName = GetXslFileName(nodeDefinition); if (xslFileName != null && File.Exists(xslFileName)) { XmlDocument xslDoc = new XmlDocument(); xslDoc.Load(xslFileName); ConnectionGroupInfo connectionGroup = nodeDefinition.Connection; if (AppVersionHelper.IsNotDebug() && !connectionGroup.IsExternal) { CryptoProcessor cryptoProcessor = new CryptoProcessor( this._model.Settings.SystemSettings.PublicKeyXmlSign, this._model.Settings.SystemSettings.PrivateKeyXmlDecrypt ); cryptoProcessor.DecryptXmlDocument(xslDoc); } try { XslPreprocessManager preprocessManager = GetManager( dataProvider, graphicsInfo ); List<PreprocessorAreaData> datas; using (preprocessManager.ExecuteXslPreprocessing(xslDoc, out datas)) { } foreach (PreprocessorAreaData preprocessorAreaData in datas) { preprocessorAreaData.CheckPreprocessors(); } result.PreprocessorAreas = datas.ToList(); } catch (Exception ex) { log.ErrorFormat( "nodeDefinition.TemplateNode.Queries(.Name)='{0}';xslFileName='{1}';Exception:'{2}'", nodeDefinition.TemplateNode.Queries.Select(q => q.QueryName).Join(", "), xslFileName, ex ); } } return result; }
public static Template GetTemplateByFile(string strFileName) { try { XmlDocument doc = new XmlDocument(); doc.Load(strFileName); Template retTemplate; if (AppVersionHelper.IsNotDebug()) { var cryptoProcessor = new CryptoProcessor( Program.Model.Settings.SystemSettings.PublicKeyXmlSign, Program.Model.Settings.SystemSettings.PrivateKeyXmlDecrypt); cryptoProcessor.DecryptXmlDocument(doc); } using (var nodeReader = new XmlNodeReader(doc)) { XmlSerializer serializer = new XmlSerializer(typeof(Template)); using (var xmlReader = XmlReader.Create(nodeReader, XmlUtils.GetXmlReaderSettings())) { retTemplate = (Template)serializer.Deserialize(xmlReader); } } return retTemplate; } catch (Exception ex) { log.Error(ex); } return null; }
/// <summary> /// Load queries from Xml-file /// </summary> /// <param name="fileName">Xml-file name</param> /// <param name="cryptoProcessor">Encoder</param> /// <param name="isExternal">Is opened from user file template</param> /// <returns>List of queries</returns> public static List<QueryInfo> LoadFromXml(string fileName, CryptoProcessor cryptoProcessor, bool isExternal) { if (AppVersionHelper.IsDebug() || isExternal) { if (cryptoProcessor == null) { return LoadFromXml(fileName); } } try { XmlDocument doc = new XmlDocument(); doc.PreserveWhitespace = true; doc.Load(fileName); if (AppVersionHelper.IsRelease() || (AppVersionHelper.IsNotRelease() && cryptoProcessor != null)) { cryptoProcessor.DecryptXmlDocument(doc); } byte[] bytes = Encoding.UTF8.GetBytes(doc.OuterXml); XmlSerializer s = new XmlSerializer(typeof (LoaderRootWrapper)); using (var includingReader = new MemoryStream(bytes)) { using (var xmlReader = XmlReader.Create(includingReader, XmlUtils.GetXmlReaderSettings())) { return GetQueries(((LoaderRootWrapper) s.Deserialize(xmlReader))); } } } catch (Exception exception) { log.Error(exception); if (AppVersionHelper.IsDebug() || isExternal) { return LoadFromXml(fileName); } throw; } }
/// <summary> /// Item1 = name. Item2 = directory. /// </summary> /// <param name="templateID"></param> /// <returns></returns> public static Tuple<string, string> GetTemplateById(string templateID) { string strFileName = string.Empty; string strFolderName = string.Empty; List<Template> retList = new List<Template>(); DirectoryInfo directoryInfo = new DirectoryInfo( Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Program.Model.Settings.TemplateDirectory)); if (directoryInfo.Exists) { try { var serializer = new XmlSerializer(typeof(Template)); var files = directoryInfo.GetFiles("*.xml"); foreach (FileInfo file in files) { try { var doc = new XmlDocument(); doc.Load(file.FullName); if (AppVersionHelper.IsNotDebug()) { var cryptoProcessor = new CryptoProcessor( Program.Model.Settings.SystemSettings.PublicKeyXmlSign, Program.Model.Settings.SystemSettings.PrivateKeyXmlDecrypt); cryptoProcessor.DecryptXmlDocument(doc); } // // #248 - fix memory leaks during XML files processing // // var nodeReader = new XmlNodeReader(doc); using (var nodeReader = new XmlNodeReader(doc)) { using (var xmlReader = XmlReader.Create(nodeReader, XmlUtils.GetXmlReaderSettings())) { var template = (Template)serializer.Deserialize(xmlReader); if (templateID == template.Id) { strFileName = file.Name; strFolderName = file.DirectoryName; } } } } catch (Exception ex) { log.Error(ex); if (file != null) { log.ErrorFormat("File:'{0}'", file); } log.ErrorFormat("Folder:'{0}'", directoryInfo); } } } catch (Exception ex) { log.Error(ex); log.ErrorFormat("Folder:'{0}'", directoryInfo); } } else { log.Error("Folder with models is not exists"); log.ErrorFormat("Folder:'{0}'", directoryInfo); } return new Tuple<string, string>(strFileName, strFolderName); }
//void ReloadConectionGroupInfos() //{ // var filenames = _filesProvider.GetConnectionsFilenames(); // _connections = new List<ConnectionGroupInfo>(); // foreach (var filename in filenames) // { // _connections.AddRange(ConnectionsLoader.LoadFromXml(filename)); // } //} /// <summary> /// Load Template /// </summary> /// <param name="filename">Xml-file name</param> /// <param name="connectionGroup"></param> /// <param name="isExternal">Is opened from user file template</param> /// <returns>Tree template</returns> public TemplateNodeInfo LoadTemplateNodes( string filename, bool isExternal, out string startupTemplateId, out Stack<string> startupTemplateInfoIdStack ) { if (!File.Exists(filename)) { throw new FileNotFoundException("Template needed!"); } var doc = new XmlDocument(); doc.Load(filename); if (AppVersionHelper.IsNotDebug() && !isExternal) { var cryptoProcessor = new CryptoProcessor( this.Settings.SystemSettings.PublicKeyXmlSign, this.Settings.SystemSettings.PrivateKeyXmlDecrypt ); cryptoProcessor.DecryptXmlDocument(doc); } return TemplateNodesLoader.LoadFromXml(this, doc, out startupTemplateId, out startupTemplateInfoIdStack); }