示例#1
0
        protected void Write(string command)
        {
            Arguments     args      = new Arguments(this);
            OptionSet     optionSet = CreateOptionSet(args);
            List <string> values    = ParseCommand(optionSet, command);

            IPAddress address = ParseAddress(values[0]);

            if (args.Command == Command.Set)
            {
                SetParameterCheck(values);
            }
            List <Variable> variables = BuildVariableList(args.Command, values);
            IPEndPoint      receiver  = CreateReceiver(address);

            if (args.Version != VersionCode.V3)
            {
                ProcessOldVersion(args, receiver, variables);
            }
            else
            {
                ProviderPair record  = SecurityCheck(args);
                ISnmpMessage request = IssueCommand(args, receiver, record, variables);
                ProcessResponse(args, request, receiver);
            }
        }
        private void Delete(bool execute, ProviderPair targetPair, Dictionary <Qualifier.Unique, LocalizationAudit> sourceAudits, Dictionary <Qualifier.Unique, LocalizationAudit> targetAudits, QualifiedValue targetQualifiedValue, SynchronizationResult result)
        {
            if (execute)
            {
                if (sourceAudits.ContainsKey(targetQualifiedValue.Qualifier))
                {
                    targetAudits[targetQualifiedValue.Qualifier] = sourceAudits[targetQualifiedValue.Qualifier];
                }

                targetPair.ValueManager.DeleteValue(targetQualifiedValue.Qualifier);
            }
            result.Removed.Add(new Removal(targetPair.Name, targetQualifiedValue.Qualifier.ToString(), targetQualifiedValue.Value));
        }
        private void Create(bool execute, ProviderPair targetPair, Dictionary <Qualifier.Unique, LocalizationAudit> sourceAudits, Dictionary <Qualifier.Unique, LocalizationAudit> targetAudits, QualifiedValue sourceQualifiedValue, SynchronizationResult result)
        {
            if (execute)
            {
                if (sourceAudits.ContainsKey(sourceQualifiedValue.Qualifier))
                {
                    targetAudits[sourceQualifiedValue.Qualifier] = sourceAudits[sourceQualifiedValue.Qualifier];
                }

                targetPair.ValueManager.CreateValue(sourceQualifiedValue.Qualifier, sourceQualifiedValue.Value);
            }
            result.Created.Add(new Creation(targetPair.Name, sourceQualifiedValue.Qualifier.ToString(), sourceQualifiedValue.Value));
        }
示例#4
0
        private ISnmpMessage IssueCommand(Arguments args, IPEndPoint receiver, ProviderPair record, List <Variable> variables)
        {
            Discovery     discovery = new Discovery(1, 101);
            ReportMessage report    = discovery.GetResponse(args.Timeout, receiver);

            if (args.Command == Command.Get)
            {
                return(new GetRequestMessage(VersionCode.V3, 100, 0, new OctetString(args.UserName), variables, record, report));
            }
            else
            {
                return(new SetRequestMessage(VersionCode.V3, 100, 0, new OctetString(args.UserName), variables, record, report));
            }
        }
示例#5
0
        public ProviderPair CreateProviderPair(String providerConfigName)
        {
            var providerConfig = ProviderConfig.ProviderPairs.Single(vp => vp.Name == providerConfigName);

            var valueProviderType = Type.GetType(providerConfig.ValueProvider.Type);

            if (valueProviderType == null)
            {
                throw new Exception("Cannot find type \"" + providerConfig.ValueProvider.Type + "\"");
            }
            if (!typeof(ILocalizedValueManager).IsAssignableFrom(valueProviderType))
            {
                throw new Exception("Type \"" + valueProviderType + "\" does not implement " + typeof(ILocalizedValueManager).Name + "!");
            }

            var valueProvider = ConstructProvider(valueProviderType, providerConfig.ValueProvider.ConstructorArguments.Cast <ConstructorArgumentElement>().ToArray());

            if (valueProvider == null)
            {
                throw new Exception("Could not initialize value provider, incorrect constructor arguments!");
            }

            if (providerConfig.LogProvider.IsValueProvider)
            {
                return(new ProviderPair(providerConfigName, valueProvider as ILocalizedValueManager, valueProvider as ILocalizationLogger));
            }

            var logProviderType = Type.GetType(providerConfig.LogProvider.Type);

            if (logProviderType == null)
            {
                throw new Exception("Cannot find type \"" + providerConfig.LogProvider.Type + "\"");
            }
            if (!typeof(ILocalizationLogger).IsAssignableFrom(logProviderType))
            {
                throw new Exception("Type \"" + logProviderType + "\" does not implement " + typeof(ILocalizationLogger).Name + "!");
            }

            var logProvider = ConstructProvider(logProviderType, providerConfig.LogProvider.ConstructorArguments.Cast <ConstructorArgumentElement>().ToArray());

            if (logProvider == null)
            {
                throw new Exception("Could not initialize log provider, incorrect constructor arguments!");
            }

            var pair = new ProviderPair(providerConfigName, valueProvider as ILocalizedValueManager, logProvider as ILocalizationLogger);

            pair.ValueManager.Reload();
            return(pair);
        }