Ejemplo n.º 1
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            _activeContextIdOnLoad = UserSettings.Settings.CurrentContextId;

            // set shield icon if not an admin
            if (SystemInformation.IsAdmin())
            {
                // no shield if we're an admin...
                imageShield.Visibility = Visibility.Collapsed;
            }
            else
            {
                // .. otherwise get the correct shield icon for the platform
                imageShield.Source = ClientUtils.GetShieldIconAsBitmapSource();
            }

            _contextValidation          = new ContextValidation(_clientLogic.ClientTimeoutInSeconds / 60);
            tabItemAdvanced.DataContext = _contextValidation;

            UpdateProyControl();

            buttonTestData.Visibility = Visibility.Collapsed;

            if (!DesignerProperties.GetIsInDesignMode(this))
            {
                _clientLogic.ClientLogicUI    += new EventHandler <ClientLogicUIEventArgs>(_clientLogic_ClientLogicUI);
                _clientLogic.ClientLogicError += new EventHandler <ClientLogicErrorEventArgs>(_clientLogic_ClientLogicError);
                _clientLogic.RefreshContextSettings();
            }
        }
Ejemplo n.º 2
0
        private static UsagePointAdapterTRuDI LoadDataFile(string filename)
        {
            try
            {
                var xml = XDocument.Load(filename);

                Ar2418Validation.ValidateSchema(xml);
                var model = XmlModelParser.ParseHanAdapterModel(xml.Root?.Descendants());
                ModelValidation.ValidateHanAdapterModel(model);
                ContextValidation.ValidateContext(model, null);

                return(model);
            }
            catch (AggregateException ex)
            {
                foreach (var err in ex.InnerExceptions)
                {
                    Console.WriteLine(err.Message);
                }

                return(null);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(null);
            }
        }
Ejemplo n.º 3
0
        private static UsagePointAdapterTRuDI RunValidations(XDocument xml, AdapterContext ctx)
        {
            Ar2418Validation.ValidateSchema(xml);
            var model = XmlModelParser.ParseHanAdapterModel(xml.Root?.Descendants());

            ModelValidation.ValidateHanAdapterModel(model);
            ContextValidation.ValidateContext(model, ctx);
            return(model);
        }
Ejemplo n.º 4
0
        private void LoadFromScript()
        {
            // convert the script to a string
            StringBuilder sb = new StringBuilder();

            foreach (StackHashScriptLine line in _scriptSettings.Script)
            {
                sb.Append(line.Command);

                if (!string.IsNullOrEmpty(line.Comment))
                {
                    sb.Append(string.Format(CultureInfo.CurrentCulture,
                                            " {0} {1}",
                                            ScriptCommentSeparator,
                                            line.Comment));
                }

                sb.Append(Environment.NewLine);
            }

            int initialNameIndex = -1;

            if (!_add)
            {
                // find the index of this script name so we can detect duplicates later
                for (int i = 0; i < _clientLogic.ScriptData.Count; i++)
                {
                    if (string.Compare(_scriptSettings.Name, _clientLogic.ScriptData[i].Name, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        initialNameIndex = i;
                        break;
                    }
                }
            }

            _contextValidation = new ContextValidation(_clientLogic.ScriptData,
                                                       initialNameIndex,
                                                       _scriptSettings.Name,
                                                       sb.ToString(),
                                                       _scriptSettings.RunAutomatically,
                                                       _scriptSettings.IsReadOnly,
                                                       _scriptSettings.DumpType);

            this.DataContext = _contextValidation;
        }
Ejemplo n.º 5
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            // save the current host/port to use on cancel
            _originalHost            = UserSettings.Settings.ServiceHost;
            _originalPort            = UserSettings.Settings.ServicePort;
            _originalContext         = UserSettings.Settings.CurrentContextId;
            _originalServiceUsername = UserSettings.Settings.ServiceUsername;
            _originalServicePassword = UserSettings.Settings.ServicePassword;
            _originalServiceDomain   = UserSettings.Settings.ServiceDomain;

            // set current proxy server settings
            proxySettingsControl.ProxySettings = new ProxySettings(UserSettings.Settings.UseProxyServer,
                                                                   UserSettings.Settings.UseProxyServerAuthentication,
                                                                   UserSettings.Settings.ProxyHost,
                                                                   UserSettings.Settings.ProxyPort,
                                                                   UserSettings.Settings.ProxyUsername,
                                                                   UserSettings.Settings.ProxyPassword,
                                                                   UserSettings.Settings.ProxyDomain);

            bool is64 = SystemInformation.Is64BitSystem();

            labelDebuggerAmd64.IsEnabled   = is64;
            textBoxDebuggerAmd64.IsEnabled = is64;
            buttonBrowseAmd64.IsEnabled    = is64;

            _contextValidation = new ContextValidation(UserSettings.Settings.DebuggerPathX86,
                                                       UserSettings.Settings.DebuggerPathAmd64,
                                                       UserSettings.Settings.DebuggerPathVisualStudio,
                                                       UserSettings.Settings.DefaultDebugTool,
                                                       is64,
                                                       UserSettings.Settings.DiagnosticLogEnabled,
                                                       UserSettings.Settings.ServiceHost,
                                                       UserSettings.Settings.ServicePort,
                                                       UserSettings.Settings.EventPageSize);

            this.DataContext = _contextValidation;

            if (!DesignerProperties.GetIsInDesignMode(this))
            {
                _clientLogic.ClientLogicUI   += new EventHandler <ClientLogicUIEventArgs>(_clientLogic_ClientLogicUI);
                _clientLogic.PropertyChanged += new PropertyChangedEventHandler(_clientLogic_PropertyChanged);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Sets the hit threshold
        /// </summary>
        /// <param name="hitThreshold">Hit threshold</param>
        /// <param name="isGlobal">True if this is the global threshold</param>
        /// <param name="isOverride">True if the provided value is an override for a product</param>
        public void SetHitThreshold(int hitThreshold, bool isGlobal, bool isOverride)
        {
            _contextValidation = new ContextValidation(hitThreshold);
            this.DataContext   = _contextValidation;

            _isGlobal = isGlobal;

            if (_isGlobal)
            {
                textDisplayFilter.Visibility     = Visibility.Visible;
                checkBoxDisplayFilter.Visibility = Visibility.Hidden;
            }
            else
            {
                textDisplayFilter.Visibility     = Visibility.Hidden;
                checkBoxDisplayFilter.Visibility = Visibility.Visible;
            }

            checkBoxDisplayFilter.IsChecked = isOverride;

            UpdateState();
        }
        public override int Run()
        {
            var connectResult = this.Connect();

            if (connectResult.error != null)
            {
                Console.WriteLine("Connect failed: {0}", connectResult.error);
                return(2);
            }

            var hanAdapter = this.CommonCommunicationConfiguration.HanAdapter;

            var contractsResult = hanAdapter.LoadAvailableContracts(
                this.CommonCommunicationConfiguration.CreateCancellationToken(),
                this.ProgressCallback).Result;

            if (contractsResult.error != null)
            {
                Console.WriteLine("LoadAvailableContracts failed: {0}", contractsResult.error);
                return(2);
            }

            var contract = contractsResult.contracts.FirstOrDefault(
                c =>
            {
                if (!string.IsNullOrWhiteSpace(this.currentRegistersConfiguration.UsagePointId))
                {
                    if (this.currentRegistersConfiguration.UsagePointId != c.MeteringPointId)
                    {
                        return(false);
                    }
                }

                if (c.TafId == TafId.Taf6)
                {
                    return(false);
                }

                return(this.currentRegistersConfiguration.TariffName == c.TafName);
            });

            if (contract == null)
            {
                Console.WriteLine("Es wurde kein passender TAF gefunden.");
                return(2);
            }

            var currentRegisterResult = hanAdapter.GetCurrentRegisterValues(
                contract,
                this.CommonCommunicationConfiguration.CreateCancellationToken(),
                this.ProgressCallback).Result;


            if (currentRegisterResult.error != null)
            {
                Console.WriteLine("GetCurrentRegisterValues failed: {0}", currentRegisterResult.error);
                return(2);
            }

            try
            {
                if (this.currentRegistersConfiguration.SkipValidation)
                {
                    Ar2418Validation.ValidateSchema(currentRegisterResult.trudiXml);
                    var model = XmlModelParser.ParseHanAdapterModel(currentRegisterResult.trudiXml.Root?.Descendants());
                    ModelValidation.ValidateHanAdapterModel(model);
                    ContextValidation.ValidateContext(model, null);
                }
            }
            catch (AggregateException ex)
            {
                foreach (var err in ex.InnerExceptions)
                {
                    Console.WriteLine(err.Message);
                }

                return(2);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(2);
            }

            if (string.IsNullOrWhiteSpace(this.CommonOptions.OutputFile))
            {
                return(0);
            }

            currentRegisterResult.trudiXml.Save(this.CommonOptions.OutputFile);
            return(0);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Sets the policies used by the control
        /// </summary>
        /// <param name="cabPolicy">Cab collection policy</param>
        /// <param name="eventPolicy">Event collection policy (optional)</param>
        /// <param name="level">The actual level of this CollectionPolicyControl</param>
        /// <param name="overrideId">The Id of the object that will apply to any possible override</param>
        public void SetPolicies(StackHashCollectionPolicy cabPolicy, StackHashCollectionPolicy eventPolicy, StackHashCollectionObject level, int overrideId)
        {
            if (cabPolicy == null)
            {
                throw new ArgumentNullException("cabPolicy");
            }
            // OK for eventPolicy to be null

            _cabPolicy         = cabPolicy;
            _level             = level;
            _rootIdForOverride = overrideId;

            int hitThreshold = 0;

            // use labels / checkboxes depending on level
            if (level == StackHashCollectionObject.Global)
            {
                textCabCollectionPolicy.Visibility       = Visibility.Visible;
                textEventPolicy.Visibility               = Visibility.Visible;
                checkBoxCabCollectionPolicy.Visibility   = Visibility.Collapsed;
                checkBoxEventCollectionPolicy.Visibility = Visibility.Collapsed;
            }
            else
            {
                textCabCollectionPolicy.Visibility       = Visibility.Collapsed;
                textEventPolicy.Visibility               = Visibility.Collapsed;
                checkBoxCabCollectionPolicy.Visibility   = Visibility.Visible;
                checkBoxEventCollectionPolicy.Visibility = Visibility.Visible;
            }

            // hide event policy if not specified
            if (eventPolicy == null)
            {
                _eventPolicy = null;

                textEventPolicy.Visibility               = Visibility.Collapsed;
                labelHitThreshold.Visibility             = Visibility.Collapsed;
                textBoxEventHitThreshold.Visibility      = Visibility.Collapsed;
                checkBoxEventCollectionPolicy.Visibility = Visibility.Collapsed;
            }
            else
            {
                _eventPolicy = eventPolicy;

                hitThreshold = _eventPolicy.Minimum;

                labelHitThreshold.Visibility        = Visibility.Visible;
                textBoxEventHitThreshold.Visibility = Visibility.Visible;
            }

            _contextValidation = new ContextValidation(_cabPolicy.Percentage,
                                                       _cabPolicy.Maximum,
                                                       hitThreshold,
                                                       _cabPolicy.CollectLarger,
                                                       _cabPolicy.CollectionOrder);
            this.DataContext = _contextValidation;

            switch (_cabPolicy.CollectionType)
            {
            case StackHashCollectionType.All:
            default:
                radioButtonAll.IsChecked = true;
                break;

            case StackHashCollectionType.Count:
                radioButtonCount.IsChecked = true;
                break;

            case StackHashCollectionType.Percentage:
                radioButtonPercentage.IsChecked = true;
                break;

            case StackHashCollectionType.None:
                radioButtonNone.IsChecked = true;
                break;
            }

            // determine if the policies are set at this level or inherited
            if (_cabPolicy.RootObject == _level)
            {
                checkBoxCabCollectionPolicy.IsChecked = true;
                _providedCabPolicyIsAtThisLevel       = true;
            }

            if ((_eventPolicy != null) && (_eventPolicy.RootObject == _level))
            {
                checkBoxEventCollectionPolicy.IsChecked = true;
                _providedEventPolicyIsAtThislevel       = true;
            }
        }
Ejemplo n.º 9
0
        private void LoadDataFromXml(XDocument raw, AdapterContext ctx)
        {
            Log.Information("Loading XML file");
            this.LastErrorMessages.Clear();

            try
            {
                this.CurrentDataResult = new XmlDataResult {
                    Raw = raw
                };

                Log.Information("Validating XSD schema");
                Ar2418Validation.ValidateSchema(raw);

                Log.Information("Parsing model");
                this.CurrentDataResult.Model = XmlModelParser.ParseHanAdapterModel(this.CurrentDataResult?.Raw?.Root?.Descendants());

                Log.Information("Validating model");
                ModelValidation.ValidateHanAdapterModel(this.CurrentDataResult.Model);

                Log.Information("Validating model using the adapter context");
                ContextValidation.ValidateContext(this.CurrentDataResult.Model, ctx);

                if (this.CurrentSupplierFile?.Model != null)
                {
                    Log.Information("Validating model using supplier file model");
                    ContextValidation.ValidateContext(this.CurrentDataResult.Model, this.CurrentSupplierFile.Model, ctx);

                    Log.Information("Loading TAF adapter: {0}", this.CurrentSupplierFile.Model.AnalysisProfile.TariffUseCase);
                    var tafAdapter = TafAdapterRepository.LoadAdapter(this.CurrentSupplierFile.Model.AnalysisProfile.TariffUseCase);
                    this.CurrentSupplierFile.TafData = tafAdapter.Calculate(this.CurrentDataResult.Model, this.CurrentSupplierFile.Model);
                }
            }
            catch (UnknownTafAdapterException ex)
            {
                Log.Error(ex, "Unknown TAF adapter: {0}", ex.TafId);
                this.LastErrorMessages.Add($"Die Berechnung des Tarifanwendungsfall {ex.TafId} wird nicht unterstützt.");
                throw;
            }
            catch (AggregateException ex)
            {
                foreach (var err in ex.InnerExceptions)
                {
                    Log.Error(err, err.Message);
                    this.LastErrorMessages.Add(err.Message);
                }

                throw;
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Loading XML data failed: {0}", ex.Message);
                this.LastErrorMessages.Add(ex.Message);
                throw;
            }

            var originalValueLists =
                this.CurrentDataResult.Model.MeterReadings.Where(mr => mr.IsOriginalValueList()).Select(mr => new OriginalValueList(mr, this.CurrentDataResult.Model.ServiceCategory.Kind ?? Kind.Electricity)).ToList();

            var meterReadings = this.CurrentDataResult.Model.MeterReadings.Where(mr => !mr.IsOriginalValueList()).ToList();

            meterReadings.Sort((a, b) => string.Compare(a.ReadingType.ObisCode, b.ReadingType.ObisCode, StringComparison.InvariantCultureIgnoreCase));

            var ovlRegisters = originalValueLists.Where(ovl => ovl.MeterReading?.IntervalBlocks?.FirstOrDefault()?.Interval.Duration == 0).ToList();

            meterReadings.AddRange(ovlRegisters.Select(ovl => ovl.MeterReading));

            if (ovlRegisters.Count < originalValueLists.Count)
            {
                ovlRegisters.ForEach(ovl => originalValueLists.Remove(ovl));
            }

            foreach (var ovl in originalValueLists)
            {
                Log.Information("Original value list: meter: {0}, OBIS: {1}, {2} values", ovl.Meter, ovl.Obis, ovl.ValueCount);
            }

            foreach (var mr in meterReadings)
            {
                Log.Information("Meter reading: {@Meters}, OBIS: {1}", mr.Meters, mr.ReadingType.ObisCode);
            }

            this.CurrentDataResult.OriginalValueLists = originalValueLists;
            this.CurrentDataResult.MeterReadings      = meterReadings;
            this.CurrentDataResult.Begin = meterReadings.FirstOrDefault()?.IntervalBlocks?.FirstOrDefault()?.Interval?.Start;

            if (this.CurrentDataResult.Begin != null)
            {
                var duration = meterReadings.FirstOrDefault()?.IntervalBlocks?.FirstOrDefault()?.Interval?.Duration;
                if (duration != null)
                {
                    this.CurrentDataResult.End = this.CurrentDataResult.Begin + TimeSpan.FromSeconds(duration.Value);
                }
            }

            // If the analysis profile is missing, add it based on the contract info
            if (this.CurrentDataResult.Model.AnalysisProfile == null && ctx?.Contract != null)
            {
                this.AddAnalysisProfile(ctx);
            }
        }
Ejemplo n.º 10
0
        public override int Run()
        {
            var connectResult = this.Connect();

            if (connectResult.error != null)
            {
                Console.WriteLine("Connect failed: {0}", connectResult.error);
                return(2);
            }

            var hanAdapter = this.CommonCommunicationConfiguration.HanAdapter;

            var contractsResult = hanAdapter.LoadAvailableContracts(
                this.CommonCommunicationConfiguration.CreateCancellationToken(),
                this.ProgressCallback).Result;

            if (contractsResult.error != null)
            {
                Console.WriteLine("LoadAvailableContracts failed: {0}", contractsResult.error);
                return(2);
            }

            var ctx = new AdapterContext();

            ctx.WithLogdata = true;

            ctx.Contract = contractsResult.contracts.FirstOrDefault(
                c =>
            {
                if (!string.IsNullOrWhiteSpace(this.loadDataConfiguration.UsagePointId))
                {
                    if (this.loadDataConfiguration.UsagePointId != c.MeteringPointId)
                    {
                        return(false);
                    }
                }

                if (this.loadDataConfiguration.UseTaf6 && c.TafId != TafId.Taf6)
                {
                    return(false);
                }

                return(this.loadDataConfiguration.TariffName == c.TafName);
            });

            if (ctx.Contract == null)
            {
                Console.WriteLine("Es wurde kein passender TAF gefunden.");
                return(2);
            }

            if (ctx.Contract.TafId != TafId.Taf7)
            {
                if (ctx.Contract.BillingPeriods == null || ctx.Contract.BillingPeriods.Count
                    <= this.loadDataConfiguration.BillingPeriodIndex)
                {
                    Console.WriteLine("Angegebene Abrechnungsperiode nicht gefunden.");
                    return(2);
                }

                ctx.BillingPeriod = ctx.Contract.BillingPeriods[this.loadDataConfiguration.BillingPeriodIndex];

                if (this.loadDataConfiguration.Start != null)
                {
                    ctx.Start = this.loadDataConfiguration.Start.Value;
                }
                else
                {
                    ctx.Start = ctx.BillingPeriod.Begin;
                }

                if (this.loadDataConfiguration.End != null)
                {
                    ctx.End = this.loadDataConfiguration.End.Value;
                }
                else if (ctx.BillingPeriod.End != null)
                {
                    ctx.End = ctx.BillingPeriod.End.Value;
                }
                else
                {
                    ctx.End = DateTime.Now;
                }
            }
            else
            {
                if (this.loadDataConfiguration.Start == null || this.loadDataConfiguration.End == null)
                {
                    Console.WriteLine("Bei TAF-7 muss ein Start- und End-Zeitpunkt angegeben werden.");
                    return(2);
                }

                ctx.Start = this.loadDataConfiguration.Start.Value;
                ctx.End   = this.loadDataConfiguration.End.Value;
            }

            var loadDataResult = hanAdapter.LoadData(
                ctx,
                this.CommonCommunicationConfiguration.CreateCancellationToken(),
                this.ProgressCallback).Result;


            if (loadDataResult.error != null)
            {
                Console.WriteLine("LoadData failed: {0}", loadDataResult.error);
                return(2);
            }

            try
            {
                if (this.loadDataConfiguration.SkipValidation)
                {
                    Ar2418Validation.ValidateSchema(loadDataResult.trudiXml);
                    var model = XmlModelParser.ParseHanAdapterModel(loadDataResult.trudiXml.Root?.Descendants());
                    ModelValidation.ValidateHanAdapterModel(model);
                    ContextValidation.ValidateContext(model, ctx);
                }
            }
            catch (AggregateException ex)
            {
                foreach (var err in ex.InnerExceptions)
                {
                    Console.WriteLine(err.Message);
                }

                return(2);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(2);
            }

            if (string.IsNullOrWhiteSpace(this.CommonOptions.OutputFile))
            {
                return(0);
            }

            loadDataResult.trudiXml.Save(this.CommonOptions.OutputFile);
            return(0);
        }