コード例 #1
0
        public DataTable GetMajors(string application)
        {
            DataTable dt = new DataTable();

            try
            {
                RemoteConfigManagerDTO remoteConfigManagerDto = new RemoteConfigManagerDTO
                {
                    Operation = { Command = "getMajors", Condition = application }
                };

                string URL = System.Configuration.ConfigurationManager.AppSettings["remoteConfigurationManagerUrl"] +
                             "ConfigManagerHandler.ashx";

                MemoryStream  ms  = new MemoryStream();
                XmlSerializer ser = new XmlSerializer(typeof(RemoteConfigManagerDTO));
                ser.Serialize(ms, remoteConfigManagerDto);

                HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(URL);
                req.ContentType      = "text/xml";
                req.Method           = "POST";
                req.Timeout          = 30000;
                req.ReadWriteTimeout = 30000;
                req.ContentLength    = ms.Length;
                req.KeepAlive        = false;

                using (Stream stream = req.GetRequestStream())
                {
                    byte[] buf = ms.ToArray();
                    stream.Write(buf, 0, buf.Length);
                    stream.Close();
                }

                RemoteConfigManagerDTO lstOutput;
                HttpWebResponse        rsp = (HttpWebResponse)req.GetResponse();
                using (Stream stream = rsp.GetResponseStream())
                {
                    lstOutput = (RemoteConfigManagerDTO)ser.Deserialize(stream);
                    stream.Close();
                }

                rsp.Close();

                if (lstOutput.Operation.Result)
                {
                    dt = GetMajors(lstOutput.RemoteConfigSections);
                }
                else
                {
                    LoggerWrapper.Logger.Error(lstOutput.Operation.ResultInfo);
                }
            }
            catch (Exception ex)
            {
                LoggerWrapper.Logger.Error(ex);
            }

            return(dt);
        }
コード例 #2
0
        public bool DeleteConfig(string application, String sectionName)
        {
            String condition = Path.Combine(string.Compare(application, NoAppPath) == 0 ? NoAppPath : application,
                                            sectionName);

            bool result = true;
            RemoteConfigManagerDTO remoteConfigManagerDto = new RemoteConfigManagerDTO();

            remoteConfigManagerDto.Operation.Command   = "deleteConfig";
            remoteConfigManagerDto.Operation.Condition = condition;
            try
            {
                string URL = System.Configuration.ConfigurationManager.AppSettings["remoteConfigurationManagerUrl"] +
                             "ConfigManagerHandler.ashx";

                MemoryStream  ms  = new MemoryStream();
                XmlSerializer ser = new XmlSerializer(typeof(RemoteConfigManagerDTO));
                ser.Serialize(ms, remoteConfigManagerDto);

                HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(URL);
                req.ContentType      = "text/xml";
                req.Method           = "POST";
                req.Timeout          = 30000;
                req.ReadWriteTimeout = 30000;
                req.ContentLength    = ms.Length;
                req.KeepAlive        = false;

                using (Stream stream = req.GetRequestStream())
                {
                    byte[] buf = ms.ToArray();
                    stream.Write(buf, 0, buf.Length);
                    stream.Close();
                }

                RemoteConfigManagerDTO lstOutput;
                HttpWebResponse        rsp = (HttpWebResponse)req.GetResponse();
                using (Stream stream = rsp.GetResponseStream())
                {
                    lstOutput = (RemoteConfigManagerDTO)ser.Deserialize(stream);
                    stream.Close();
                }

                rsp.Close();

                if (!lstOutput.Operation.Result)
                {
                    result = false;
                }
            }
            catch (Exception ex)
            {
                LoggerWrapper.Logger.Error(ex);
            }

            return(result);
        }
コード例 #3
0
        public bool CreateMinor(string application, string sectionName, int major, byte[] cfg)
        {
            try
            {
                RemoteConfigManagerDTO remoteConfigManagerDto = new RemoteConfigManagerDTO
                {
                    Operation =
                    {
                        Command   = "createMinor",
                        Condition = String.Format("{0}/{1}/{2}",application,  sectionName, major),
                        Value     = cfg
                    }
                };

                string URL = System.Configuration.ConfigurationManager.AppSettings["remoteConfigurationManagerUrl"] +
                             "ConfigManagerHandler.ashx";

                MemoryStream  ms  = new MemoryStream();
                XmlSerializer ser = new XmlSerializer(typeof(RemoteConfigManagerDTO));
                ser.Serialize(ms, remoteConfigManagerDto);

                HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(URL);
                req.ContentType      = "text/xml";
                req.Method           = "POST";
                req.Timeout          = 30000;
                req.ReadWriteTimeout = 30000;
                req.ContentLength    = ms.Length;
                req.KeepAlive        = false;

                using (Stream stream = req.GetRequestStream())
                {
                    byte[] buf = ms.ToArray();
                    stream.Write(buf, 0, buf.Length);
                    stream.Close();
                }

                RemoteConfigManagerDTO lstOutput;
                HttpWebResponse        rsp = (HttpWebResponse)req.GetResponse();
                using (Stream stream = rsp.GetResponseStream())
                {
                    lstOutput = (RemoteConfigManagerDTO)ser.Deserialize(stream);
                    stream.Close();
                }

                rsp.Close();

                if (lstOutput.Operation.Result)
                {
                    LoggerWrapper.Logger.Info(string.Format("新建配置:{0}", remoteConfigManagerDto.Operation.Condition));
                }
                else
                {
                    LoggerWrapper.Logger.Error(lstOutput.Operation.ResultInfo);
                }

                return(true);
            }
            catch (Exception ex)
            {
                LoggerWrapper.Logger.Error(ex);
            }

            return(false);
        }