Example #1
0
        public void CreateXML(SCModel scModel, string xmlPath)
        {
            VelocityEngine     ve = new VelocityEngine();             //模板引擎实例化
            ExtendedProperties ep = new ExtendedProperties();         //模板引擎参数实例化

            ep.AddProperty(RuntimeConstants.RESOURCE_LOADER, "file"); //指定资源的加载类型
            string ss = HttpContext.Current.Server.MapPath(".");

            ep.AddProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, HttpContext.Current.Server.MapPath(".")); //指定资源的加载路径
            //props.AddProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, Path.GetDirectoryName(HttpContext.Current.Request.PhysicalPath));
            ep.AddProperty(RuntimeConstants.INPUT_ENCODING, "utf-8");                                            //输入格式
            ep.AddProperty(RuntimeConstants.OUTPUT_ENCODING, "utf-8");                                           //输出格式

            //模板的缓存设置
            ep.AddProperty(RuntimeConstants.FILE_RESOURCE_LOADER_CACHE, true);            //是否缓存
            ep.AddProperty("file.resource.loader.modificationCheckInterval", (Int64)300); //缓存时间(秒)
            ve.Init(ep);

            //一、加载模板
            Template        template   = ve.GetTemplate("config/XMLTemplate/notify.xml"); //加载模板
            VelocityContext vltContext = new VelocityContext();                           //当前的数据信息载体集合

            //二、填充值
            string serviceID = scModel.ServiceInfo.ServiceID;

            vltContext.Put("servicename", scModel.ServiceInfo.ServiceName);
            vltContext.Put("notifydes", ((DataSourceNotify)scModel.DataSource).NotifyDescription);
            vltContext.Put("pathdes", ((DataSourceNotify)scModel.DataSource).PathDescription);
            //vltContext.Put("pathvalue", ((DataSourceNotify)scModel.DataSource).PathsValue);
            vltContext.Put("perioddes", ((DataSourceNotify)scModel.DataSource).FilesDescription);
            //vltContext.Put("filesvalue", ((DataSourceNotify)scModel.DataSource).FilesValue);
            vltContext.Put("PathFileMate", ((DataSourceNotify)scModel.DataSource).PathFileMate);
            vltContext.Put("SCLinks", scModel.SCLinks);
            vltContext.Put("sourceid", scModel.ServiceInfo.SourceID);
            vltContext.Put("servicegroup", scModel.ServiceInfo.ServiceGroup);

            //三、合并模板输出内容
            var vltWriter = new StringWriter();

            template.Merge(vltContext, vltWriter);//合并数据集合对象到输出流.
            string      innerxml = vltWriter.GetStringBuilder().ToString();
            XmlDocument xmlDoc   = new XmlDocument();

            xmlDoc.InnerXml = innerxml;
            string filexml = xmlPath + serviceID + ".xml";

            xmlDoc.Save(filexml);
        }
Example #2
0
        /// <summary>
        /// 插入监控信息
        /// </summary>
        /// <param name="scModel">scModel</param>
        /// <returns></returns>
        public bool InsertSCNotifyModel(SCModel scModel, User user)
        {
            OpenConn();

            bool result = false;

            OracleTransaction trans = Connection.BeginTransaction();

            List <string>            strSql     = new List <string>();
            List <OracleParameter[]> parameters = new List <OracleParameter[]>();

            StringBuilder strSqlService = new StringBuilder();

            strSqlService.Append("INSERT INTO dictionary.pmsc_business_info(");
            strSqlService.Append(" code, business_id, business_name, data_type, data_desc, monitor_dir, monitor_file, pre_source, business_rac_info");
            strSqlService.Append(") VALUES (");
            strSqlService.Append(" :code, :business_id, :business_name, :data_type, :data_desc, :monitor_dir, :monitor_file, :pre_source, :business_rac_info");
            strSqlService.Append(") ");

            OracleParameter[] parametersService =
            {
                new OracleParameter(":code",              scModel.ServiceInfo.ServiceType),
                new OracleParameter(":business_id",       scModel.ServiceInfo.ServiceID.Substring(2)),
                new OracleParameter(":business_name",     scModel.ServiceInfo.ServiceName),
                new OracleParameter(":data_type",         scModel.DataSourceType),
                new OracleParameter(":data_desc",         ((DataSourceNotify)scModel.DataSource).NotifyDescription),
                new OracleParameter(":monitor_dir",       ((DataSourceNotify)scModel.DataSource).PathsValue),
                new OracleParameter(":monitor_file",      ((DataSourceNotify)scModel.DataSource).FilesValue),
                new OracleParameter(":pre_source",        scModel.ServiceInfo.SourceID),
                new OracleParameter(":business_rac_info", scModel.ServiceInfo.ServiceGroup),
            };

            strSql.Add(strSqlService.ToString());
            parameters.Add(parametersService);


            foreach (SCLink scLink in scModel.SCLinks)
            {
                StringBuilder strSqlLink = new StringBuilder();
                strSqlLink.Append("INSERT INTO dictionary.pmsc_business_link(");
                strSqlLink.Append(" link_id, business_describe, cmd_info, topic_info");
                strSqlLink.Append(") VALUES (");
                strSqlLink.Append(" :link_id, :business_describe, :cmd_info, :topic_info");
                strSqlLink.Append(") ");

                OracleParameter[] parametersLink =
                {
                    new OracleParameter(":link_id",           scLink.LinkID),
                    new OracleParameter(":business_describe", scLink.Description),
                    new OracleParameter(":cmd_info",          scLink.Order),
                    new OracleParameter(":topic_info",        scLink.TopicLink),
                };

                strSql.Add(strSqlLink.ToString());
                parameters.Add(parametersLink);
            }

            //20160808 syy 增加操作记录
            //User user = new User();
            this.InsertOptRecord(strSql, parameters, scModel.ServiceInfo.ServiceID, "Insert", user);

            result = OracleHelper.ExecuteNonQuery(trans, CommandType.Text, strSql, parameters);

            CloseConn();

            return(result);
        }
Example #3
0
        /// <summary>
        /// 更新外部信息
        /// </summary>
        /// <param name="scModel">scModel</param>
        /// <returns></returns>
        public bool UpdateSCOuterModel(SCModel scModel, User user)
        {
            OpenConn();

            bool result = false;

            OracleTransaction trans = Connection.BeginTransaction();

            List <string>            strSql     = new List <string>();
            List <OracleParameter[]> parameters = new List <OracleParameter[]>();

            StringBuilder strSqlService = new StringBuilder();

            strSqlService.Append("UPDATE dictionary.pmsc_business_info SET");
            strSqlService.Append(" business_name = :business_name, data_desc = :data_desc, monitor_dir = :monitor_dir, monitor_file = :monitor_file, pre_source = :pre_source, business_rac_info = :business_rac_info");
            //strSqlService.Append(" business_name = :business_name, data_desc = :data_desc, monitor_dir = :monitor_dir, monitor_file = :monitor_file");
            strSqlService.Append(" WHERE");
            strSqlService.Append(" code = :code AND business_id = :business_id AND data_type = :data_type");

            OracleParameter[] parametersService =
            {
                new OracleParameter(":business_name",     scModel.ServiceInfo.ServiceName),
                new OracleParameter(":data_desc",         ((DataSourceOuter)scModel.DataSource).OuterDescription),
                new OracleParameter(":monitor_dir",       ((DataSourceOuter)scModel.DataSource).OuterPathValue),
                new OracleParameter(":monitor_file",      ((DataSourceOuter)scModel.DataSource).OuterFileValue),
                new OracleParameter(":pre_source",        scModel.ServiceInfo.SourceID),
                new OracleParameter(":business_rac_info", scModel.ServiceInfo.ServiceGroup),
                new OracleParameter(":code",              scModel.ServiceInfo.ServiceType),
                new OracleParameter(":business_id",       scModel.ServiceInfo.ServiceID.Substring(2)),
                new OracleParameter(":data_type",         scModel.DataSourceType),
            };

            strSql.Add(strSqlService.ToString());
            parameters.Add(parametersService);

            /*StringBuilder strSqlLinkDelete = new StringBuilder();
             *
             * strSqlLinkDelete.Append("DELETE FROM dictionary.pmsc_business_link");
             * strSqlLinkDelete.Append(" WHERE SUBSTR(link_id,0,7) = :service_id");
             * OracleParameter[] parametersDelete = {
             *          new OracleParameter(":service_id",  scModel.ServiceInfo.ServiceID ),
             *  };
             *
             * strSql.Add(strSqlLinkDelete.ToString());
             * parameters.Add(parametersDelete);
             *
             * foreach (SCLink scLink in scModel.SCLinks)
             * {
             *  StringBuilder strSqlLink = new StringBuilder();
             *  strSqlLink.Append("INSERT INTO dictionary.pmsc_business_link(");
             *  strSqlLink.Append(" link_id, business_describe, cmd_info, topic_info");
             *  strSqlLink.Append(") VALUES (");
             *  strSqlLink.Append(" :link_id, :business_describe, :cmd_info, :topic_info");
             *  strSqlLink.Append(") ");
             *
             *  OracleParameter[] parametersLink = {
             *          new OracleParameter(":link_id",  scLink.LinkID),
             *          new OracleParameter(":business_describe",  scLink.Description),
             *          new OracleParameter(":cmd_info",  scLink.Order),
             *          new OracleParameter(":topic_info",  scLink.TopicLink),
             *  };
             *
             *  strSql.Add(strSqlLink.ToString());
             *  parameters.Add(parametersLink);
             * }*/

            //20160808 syy 增加操作记录
            //User user = new User();
            this.InsertOptRecord(strSql, parameters, scModel.ServiceInfo.ServiceID, "Update", user);

            result = OracleHelper.ExecuteNonQuery(trans, CommandType.Text, strSql, parameters);
            CloseConn();

            return(result);
        }
Example #4
0
        public SCModel GetSCModel(string path, string file)
        {
            SCModel scModel = new SCModel();

            XDocument xdoc = XDocument.Load(path + file);
            IEnumerable <XElement> services = from service in xdoc.Descendants("service") select service;

            foreach (var service in services)
            {
                ServiceInfo si = new ServiceInfo();
                si.ServiceName      = service.Attribute("name").Value;
                si.ServiceID        = file.Substring(0, 7);
                si.ServiceType      = file.Substring(0, 2);
                scModel.ServiceInfo = si;

                string servicetype = service.Attribute("type").Value;
                if (servicetype == "collection")
                {
                    scModel.DataSourceType = "0";
                    scModel.DataSourceName = "采集";

                    DataSourceCollection dsc = new DataSourceCollection();

                    XElement collection = service.Element("collection");

                    dsc.CollectionDescription = collection.Attribute("description").Value;
                    dsc.StartTimeValue        = collection.Element("start-time").Value;
                    dsc.PeriodValue           = collection.Element("period").Value;
                    dsc.StartTimeDescription  = collection.Element("start-time").Attribute("description").Value; //"hh:mm:ss";
                    dsc.PeriodDescription     = collection.Element("period").Attribute("description").Value;     // "second,0s means just once";
                    scModel.DataSource        = dsc;
                }
                else if (servicetype == "notify")
                {
                    scModel.DataSourceType = "1";
                    scModel.DataSourceName = "监控";

                    DataSourceNotify dsn = new DataSourceNotify();

                    XElement notifyInfo = service.Element("notify");

                    dsn.NotifyDescription = notifyInfo.Attribute("description").Value;
                    dsn.PathDescription   = notifyInfo.Element("paths").Element("path").Attribute("description").Value;
                    dsn.PathsValue        = notifyInfo.Element("paths").Element("path").Attribute("value").Value;
                    dsn.FilesDescription  = notifyInfo.Element("paths").Element("path").Element("files").Attribute("description").Value;
                    dsn.FilesValue        = notifyInfo.Element("paths").Element("path").Element("files").Value;
                    scModel.DataSource    = dsn;
                }
                else
                {
                    scModel.DataSourceType = "2";
                    scModel.DataSourceName = "外部";

                    DataSourceOuter dso = new DataSourceOuter();

                    XElement outerInfo = service.Element("outer");

                    dso.OuterDescription = outerInfo.Attribute("description").Value;
                    dso.OuterPathDes     = outerInfo.Element("path").Attribute("description").Value;
                    dso.OuterPathValue   = outerInfo.Element("path").Attribute("value").Value;
                    dso.OuterFileDes     = outerInfo.Element("path").Element("files").Attribute("description").Value;
                    dso.OuterFileValue   = outerInfo.Element("path").Element("files").Value;
                    scModel.DataSource   = dso;
                }

                IEnumerable <XElement> links   = service.Descendants("link");
                List <SCLink>          scLinks = new List <SCLink>();
                foreach (var link in links)
                {
                    SCLink scLink = new SCLink();

                    scLink.LinkID      = link.Attribute("id").Value;
                    scLink.Description = link.Attribute("description").Value;
                    scLink.Order       = link.Element("order").Value;

                    IEnumerable <XElement> nextlinks   = link.Descendants("next-links");
                    List <SCNextLink>      scNextLinks = new List <SCNextLink>();
                    foreach (var nextlink in nextlinks)
                    {
                        IEnumerable <XElement> topiclinks = nextlink.Descendants("next-link");
                        foreach (var topiclink in topiclinks)
                        {
                            SCNextLink scNextLink = new SCNextLink();

                            scNextLink.Topic  = topiclink.Element("topic").Value;
                            scNextLink.LinkID = topiclink.Element("link-id").Value;

                            scNextLinks.Add(scNextLink);

                            scLink.TopicLink += "(" + scNextLink.Topic + "/" + scNextLink.LinkID + ")" + ",";
                        }
                    }

                    scLink.NextLinks = scNextLinks;
                    if (scLink.TopicLink != null && scLink.TopicLink != "")
                    {
                        scLink.TopicLink = scLink.TopicLink.Substring(0, scLink.TopicLink.Length - 1);
                    }
                    else
                    {
                        scLink.TopicLink = "";
                    }


                    scLinks.Add(scLink);
                }

                scModel.SCLinks = scLinks;
            }

            return(scModel);
        }