Exemple #1
0
 public Model(DBandMES dbandMES, Logger log)
 {
     m_log        = log;
     m_dbandMES   = dbandMES;
     this.StrConn = "";
     ReadConfig();
 }
Exemple #2
0
        /// <summary>
        /// 创建WebService,生成客户端代理程序集文件
        /// </summary>
        /// <param name="error">错误信息</param>
        /// <returns>返回:true或false</returns>
        public static bool CreateWebService(DBandMES dbandMES, out string error)
        {
            bool result = false;

            try {
                error = string.Empty;
                m_OutputDllFilename = dbandMES.WebServiceName + ".dll";
                m_ProxyClassName    = dbandMES.WebServiceName;
                m_Methods           = dbandMES.GetMethodArray();
                string webServiceUrl = dbandMES.WebServiceAddress;
                string strWSDL       = dbandMES.WebServiceWSDL;

                // 如果程序集已存在,直接使用
                if (File.Exists(Path.Combine(Environment.CurrentDirectory, m_OutputDllFilename)))
                {
                    BuildMethods(dbandMES.GetMethodArray());
                    return(true);
                }

                if (dbandMES.UseURL)
                {
                    // 使用 WebClient 下载 WSDL 信息。
                    WebClient web    = new WebClient();
                    Stream    stream = web.OpenRead(webServiceUrl);
                    if (stream != null)
                    {
                        // 通过加载stream流来格式化WSDL
                        ServiceDescription description = ServiceDescription.Read(stream);
                        // 编译输出 WebService 程序集
                        result = CreateWebServiceAssembly(description, dbandMES, ref error);
                    }
                    else
                    {
                        error = "打开WebServiceUrl失败";
                    }
                    web.Dispose();
                    stream.Close();
                    stream.Dispose();
                }
                else
                {
                    if (strWSDL != "")
                    {
                        // 通过加载xml文件来格式化WSDL
                        ServiceDescription description = ServiceDescription.Read(strWSDL);
                        // 编译输出 WebService 程序集
                        result = CreateWebServiceAssembly(description, dbandMES, ref error);
                    }
                    else
                    {
                        error = "WSDL文件路径不能为空";
                    }
                }
            } catch (Exception ex) {
                error = ex.Message;
            }
            return(result);
        }
Exemple #3
0
        public void SaveDBandMES(DBandMES dBandMES)
        {
            this.DBandMES = dBandMES;
            XmlSerializer xmlSerializer = new XmlSerializer(typeof(DBandMES));

            using (TextWriter writer = new StreamWriter(m_dbandMES_xml)) {
                xmlSerializer.Serialize(writer, this.DBandMES);
                writer.Close();
            }
        }
Exemple #4
0
        private static bool CreateWebServiceAssembly(ServiceDescription description, DBandMES dbandMES, ref string error)
        {
            // 创建客户端代理类。
            ServiceDescriptionImporter importer = new ServiceDescriptionImporter {
                ProtocolName          = "Soap",
                Style                 = ServiceDescriptionImportStyle.Client,
                CodeGenerationOptions =
                    CodeGenerationOptions.GenerateProperties | CodeGenerationOptions.GenerateNewAsync
            };

            // 添加 WSDL 文档。
            importer.AddServiceDescription(description, null, null);

            //使用 CodeDom 编译客户端代理类。
            CodeNamespace   nmspace = new CodeNamespace();
            CodeCompileUnit unit    = new CodeCompileUnit();

            unit.Namespaces.Add(nmspace);

            ServiceDescriptionImportWarnings warning = importer.Import(nmspace, unit);

            error += "ServiceDescriptionImportWarnings\"" + GetWarningMeaning(warning) + "\", ";

            using (CodeDomProvider provider = CodeDomProvider.CreateProvider("CSharp")) {
                CompilerParameters parameter = new CompilerParameters {
                    GenerateExecutable = false,
                    // 指定输出dll文件名。
                    OutputAssembly = m_OutputDllFilename
                };

                parameter.ReferencedAssemblies.Add("System.dll");
                parameter.ReferencedAssemblies.Add("System.XML.dll");
                parameter.ReferencedAssemblies.Add("System.Web.Services.dll");
                parameter.ReferencedAssemblies.Add("System.Data.dll");

                // 编译输出程序集
                CompilerResults result = provider.CompileAssemblyFromDom(parameter, unit);

                // 使用 Reflection 调用 WebService。
                if (!result.Errors.HasErrors)
                {
                    BuildMethods(dbandMES.GetMethodArray());
                    if (error.Length > 0)
                    {
                        error = error.Substring(0, error.Length - 3);
                    }
                    return(true);
                }
                else
                {
                    error += "反射生成dll文件时异常";
                }
            }
            return(false);
        }
Exemple #5
0
 public DBandMES LoadDBandMES()
 {
     try {
         XmlSerializer serializer = new XmlSerializer(typeof(DBandMES));
         using (FileStream reader = new FileStream(m_dbandMES_xml, FileMode.Open)) {
             DBandMES = (DBandMES)serializer.Deserialize(reader);
             reader.Close();
         }
     } catch (Exception e) {
         m_log.TraceError("Using default DB and MES settings because of failed to load them, reason: " + e.Message);
         DBandMES = new DBandMES();
     }
     return(DBandMES);
 }
Exemple #6
0
        private void ToolStripBtnSettings_Click(object sender, EventArgs e)
        {
            Settings     commSettings = m_obdInterface.CommSettings;
            DBandMES     dbandMES     = m_obdInterface.DBandMES;
            SettingsForm settingsForm = new SettingsForm(commSettings, dbandMES);

            settingsForm.ShowDialog();
            m_obdInterface.SaveCommSettings(commSettings);
            m_obdInterface.SaveDBandMES(dbandMES);
            StatusLabelCommProtocol.Text = m_obdInterface.GetProtocol().ToString();
            StatusLabelDeviceType.Text   = m_obdInterface.GetDevice().ToString();
            if (commSettings.AutoDetect)
            {
                StatusLabelPort.Text = "自动探测";
            }
            else
            {
                StatusLabelPort.Text = commSettings.ComPortName;
            }
            settingsForm.Dispose();
        }
Exemple #7
0
 public SettingsForm(Settings settings, DBandMES dbandMES)
 {
     InitializeComponent();
     m_settings = settings;
     m_dbandMES = dbandMES;
 }