コード例 #1
0
        private void cmdAddODBCStorage_Click(object sender, RoutedEventArgs e)
        {
            string val = "Storage_" + (grdStorages.Items.Count + 1);

            if (DotNetSiemensPLCToolBoxLibrary.General.InputBox.Show("Storage-Name", "Name of the Storage", ref val) == DialogResult.OK)
            {
                foreach (var tmp in ProtokollerConfiguration.ActualConfigInstance.Storages)
                {
                    if (tmp.Name.ToLower().Trim() == val.ToLower().Trim())
                    {
                        MessageBox.Show("A Storage with this Name already Exists!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }
                }
                ODBCConfig storage = new ODBCConfig()
                {
                    Name = val
                };
                ProtokollerConfiguration.ActualConfigInstance.Storages.Add(storage);
            }
        }
コード例 #2
0
    private void ConfigServices()
    {
        bool   changed             = false;
        string odbc_plugin_version = Marshal.PtrToStringAnsi(GetSPluginVersion());

        if (m_Config.odbc_plugin_version != odbc_plugin_version)
        {
            m_Config.odbc_plugin_version = odbc_plugin_version;
            changed = true;
        }
        string server_core_version = Version;

        if (m_Config.sp_server_core_version != server_core_version)
        {
            m_Config.sp_server_core_version = server_core_version;
            changed = true;
        }
        ODBCConfig oconfig = new ODBCConfig();

        oconfig.manual_batching = m_Config.manual_batching;
        string json = oconfig.ToJson();
        bool   ok   = SetSPluginGlobalOptions(json);

        string[]      vService = m_Config.services.Split(';');
        List <string> vP       = new List <string>();

        foreach (string s in vService)
        {
            string p_name = s.Trim();
            if (p_name.Length == 0)
            {
                continue;
            }
            if (p_name.Equals("sodbc", StringComparison.OrdinalIgnoreCase) || p_name.Equals("sodbc.dll", StringComparison.OrdinalIgnoreCase))
            {
                continue; //cannot load odbc plugin again
            }
            do
            {
                IntPtr h = DllManager.AddALibrary(p_name);
                if (h.ToInt64() == 0)
                {
                    string message = "Not able to load server plugin " + p_name;
                    UConfig.LogMsg(message, "CSqlPlugin::ConfigServices", 117); //line 117
                    break;
                }
                vP.Add(p_name);
                bool having = m_Config.services_config.ContainsKey(p_name);
                if (!having)
                {
                    changed = true;
                }
                IntPtr addr = GetProcAddress(h, "GetSPluginGlobalOptions");
                if (addr.ToInt64() != 0)
                {
                    try
                    {
                        DGetSPluginGlobalOptions GetSPluginGlobalOptions = (DGetSPluginGlobalOptions)Marshal.GetDelegateForFunctionPointer(addr, typeof(DGetSPluginGlobalOptions));
                        byte[] bytes    = new byte[65536];
                        uint   res      = GetSPluginGlobalOptions(bytes, bytes.Length);
                        string jsonutf8 = System.Text.Encoding.UTF8.GetString(bytes, 0, (int)res);
                        Dictionary <string, object> v = jsonutf8.FromJson <Dictionary <string, object> >();
                        if (m_Config.services_config.ContainsKey(p_name))
                        {
                            Dictionary <string, object> old = m_Config.services_config[p_name];
                            if (old.ContainsKey("version"))
                            {
                                v["version"] = old["version"];
                            }
                            m_Config.services_config[p_name] = v;
                        }
                        else
                        {
                            m_Config.services_config.Add(p_name, v);
                        }
                    }
                    catch (Exception ex)
                    {
                        UConfig.LogMsg(ex.Message, "CSqlPlugin::ConfigServices/GetSPluginGlobalOptions", 152); //line 152
                        m_Config.services_config.Add(p_name, new Dictionary <string, object>());
                    }
                }
                else
                {
                    m_Config.services_config.Add(p_name, new Dictionary <string, object>());
                }
                Dictionary <string, object> jsonDic = m_Config.services_config[p_name];
                if (having && jsonDic.Count > 0)
                {
                    addr = GetProcAddress(h, "SetSPluginGlobalOptions");
                    if (addr.ToInt64() != 0)
                    {
                        try
                        {
                            DSetSPluginGlobalOptions func = (DSetSPluginGlobalOptions)Marshal.GetDelegateForFunctionPointer(addr, typeof(DSetSPluginGlobalOptions));
                            if (!func(jsonDic.ToJson(false)))
                            {
                                UConfig.LogMsg("Not able to set global options for plugin " + p_name, "CSqlPlugin::ConfigServices", 171); //line 171
                            }
                        }
                        catch (Exception ex)
                        {
                            UConfig.LogMsg(ex.Message, "CSqlPlugin::ConfigServices/SetSPluginGlobalOptions", 176); //line 176
                        }
                    }
                }
                //DGetSPluginVersion
                addr = GetProcAddress(h, "GetSPluginVersion");
                if (addr.ToInt64() != 0)
                {
                    try
                    {
                        DGetSPluginVersion func = (DGetSPluginVersion)Marshal.GetDelegateForFunctionPointer(addr, typeof(DGetSPluginVersion));
                        string             v    = Marshal.PtrToStringAnsi(func());
                        string             vOld = null;
                        if (jsonDic.ContainsKey("version") && jsonDic["version"] is string)
                        {
                            vOld = (string)jsonDic["version"];
                        }
                        if (v != null && (vOld == null || v != vOld))
                        {
                            jsonDic["version"] = v;
                            changed            = true;
                        }
                    }
                    catch (Exception ex)
                    {
                        UConfig.LogMsg(ex.Message, "CSqlPlugin::ConfigServices/GetSPluginVersion", 201); //line 201
                    }
                }
            } while (false);
        }
        if (vP.Count != vService.Length)
        {
            string str = "";
            foreach (string item in vP)
            {
                if (str.Length > 0)
                {
                    str += ";";
                }
                str += item;
            }
            m_Config.services = str;
            changed           = true;
        }
        List <string> unused = new List <string>();

        foreach (var entry in m_Config.services_config)
        {
            if (!vP.Contains(entry.Key))
            {
                unused.Add(entry.Key);
            }
        }
        foreach (string key in unused)
        {
            m_Config.services_config.Remove(key);
            changed = true;
        }
        if (changed)
        {
            UConfig.UpdateConfigFile(m_Config);
        }
    }