示例#1
0
        private void LoadDefaultProfile()
        {
            AgentProfile first = AgentProfileFactory.Create(Guid.Empty, VersionCode.V1, new IPEndPoint(IPAddress.Loopback, 161), "public", "private", "localhost", string.Empty, string.Empty, 0, 0, string.Empty, 1000);

            AddProfile(first);
            DefaultProfile = first;
        }
示例#2
0
        private void ActAddExecute(object sender, EventArgs e)
        {
            using (FormProfile editor = new FormProfile(null))
            {
                if (editor.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                try
                {
                    Profiles.AddProfile(AgentProfileFactory.Create(Guid.NewGuid(), editor.VersionCode, new IPEndPoint(editor.IP, editor.Port), editor.GetCommunity, editor.SetCommunity, editor.AgentName, editor.AuthenticationPassphrase, editor.PrivacyPassphrase, editor.AuthenticationMethod, editor.PrivacyMethod, editor.UserName, 1000));
                    Profiles.SaveProfiles();
                }
                catch (BrowserException ex)
                {
                    Logger.Info(ex.Message);
                }
            }
        }
示例#3
0
        private int LoadProfilesFromFile()
        {
            if (!File.Exists(SettingFile))
            {
                return(0);
            }

            Guid defaultId = Guid.Empty;

            using (XmlTextReader reader = new XmlTextReader(SettingFile))
            {
                try
                {
                    while (reader.Read())
                    {
                        switch (reader.NodeType)
                        {
                        case XmlNodeType.Element:
                        {
                            if (reader.Name == NameAgent)
                            {
                                defaultId = new Guid(reader.GetAttribute(NameDefaultAgent));
                            }
                            else if (reader.Name == NameAdd)
                            {
                                string      name  = reader.GetAttribute(NameName);
                                Guid        id    = new Guid(reader.GetAttribute(NameId));
                                string[]    parts = reader.GetAttribute(NameBinding).Split(new[] { ':' });
                                IPAddress   def   = IPAddress.Parse(parts[0]);
                                int         port  = int.Parse(parts[1], CultureInfo.InvariantCulture);
                                VersionCode vc    = (VersionCode)int.Parse(reader.GetAttribute(NameVersion), CultureInfo.InvariantCulture);
                                string      get   = reader.GetAttribute(NameGetCommunity);
                                string      set   = reader.GetAttribute(NameSetCommunity);
                                string      authenticationPassphrase = reader.GetAttribute(NameAuthenticationPassphrase);
                                string      privacyPassphrase        = reader.GetAttribute(NamePrivacyPassphrase);
                                string      authenticationMethod     = reader.GetAttribute(NameAuthenticationMethod);
                                string      privacyMethod            = reader.GetAttribute(NamePrivacyMethod);
                                string      userName = reader.GetAttribute(NameUserName);
                                int         timeout  = int.Parse(reader.GetAttribute(NameTimeout), CultureInfo.InvariantCulture);

                                AgentProfile profile = AgentProfileFactory.Create(
                                    id,
                                    vc,
                                    new IPEndPoint(def, port),
                                    get,
                                    set,
                                    name,
                                    authenticationPassphrase,
                                    privacyPassphrase,
                                    string.IsNullOrEmpty(authenticationMethod) ? 0 : int.Parse(authenticationMethod, CultureInfo.InvariantCulture),
                                    string.IsNullOrEmpty(privacyMethod) ? 0 : int.Parse(privacyMethod, CultureInfo.InvariantCulture),
                                    userName,
                                    timeout);
                                if (id == defaultId)
                                {
                                    DefaultProfile = profile;
                                }

                                AddProfile(profile);
                            }

                            break;
                        }

                        default:
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.Info(ex.ToString());
                }
                finally
                {
                    reader.Close();
                }
            }

            return(_profiles.Count);
        }