Ejemplo n.º 1
0
        /// <summary>
        /// Executes the command.
        /// </summary>
        public override void Execute()
        {
            this.ValidateObject();

            tracer.Info(
                Resources.CreateViewElementsCommand_TraceInitial, this.CurrentElement.InstanceName);

            // Ensure the pattern model file exists
            var reference = SolutionArtifactLinkReference.GetResolvedReferences(this.CurrentElement.AsElement(), this.UriService).FirstOrDefault();

            if (reference != null)
            {
                using (tracer.StartActivity(Resources.CreateViewElementsCommand_TraceAddingViews, this.CurrentElement.InstanceName))
                {
                    ViewSchemaHelper.WithPatternModel(reference.PhysicalPath, (pm, docData) =>
                    {
                        pm.Pattern.Views.ForEach(v =>
                        {
                            var viewName = ((INamedElementSchema)v).Name;
                            tracer.Info(
                                Resources.CreateViewElementsCommand_TraceCreatingView, this.CurrentElement.InstanceName, viewName);

                            this.CurrentElement.Views.CreateViewModel(viewName);
                        });
                    }, false);
                }
            }
            else
            {
                tracer.Warn(
                    Resources.CreateViewElementsCommand_TraceReferenceNotFound, this.CurrentElement.InstanceName);
            }
        }
        /// <summary>
        /// Returns the provided result.
        /// </summary>
        /// <remarks></remarks>
        public override object Evaluate()
        {
            this.ValidateObject();

            tracer.Info(
                "Evaluating RequestFieldIsInRouteProvider on current element '{0}'", this.CurrentElement.InstanceName);

            var result = false;

            var requestField = this.CurrentElement.As <IRequestField>();
            var verb         = requestField.Parent.Parent;
            var route        = verb.Route;

            var matches = Regex.Match(route, VerbRouteValidator.RouteRegEx, RegexOptions.IgnoreCase);

            if (matches.Success)
            {
                var fieldNames = matches.Groups[VerbRouteValidator.RouteRegExFieldName].Captures.Cast <Capture>();
                return(fieldNames.Any(fn => fn.Value.Trim(VerbRouteValidator.RouteRegExFieldDelimiters)
                                      .Equals(requestField.InstanceName, StringComparison.InvariantCulture)));
            }

            tracer.Info(
                "Evaluated RequestFieldIsInRouteProvider on current element '{0}', as '{1}'", this.CurrentElement.InstanceName, result);

            return(result);
        }
Ejemplo n.º 3
0
        public override void Execute()
        {
            this.ValidateObject();

            tracer.Info(
                Resources.SaveArtifactCommand_TraceInitial, this, CurrentElement.InstanceName);

            var tagFilter = new Func <IReference, bool>(x => true);

            if (!string.IsNullOrEmpty(this.Tag))
            {
                tagFilter = r => r.ContainsTag(this.Tag);
            }

            var items = SolutionArtifactLinkReference.GetResolvedReferences(this.CurrentElement, this.UriReferenceService, tagFilter)
                        .OfType <IItem>().ToList();

            foreach (var item in items)
            {
                try
                {
                    tracer.Info(
                        Resources.SaveArtifactCommand_TraceSave, this.CurrentElement.InstanceName, item.GetLogicalPath());

                    item.Save();
                }
                catch (Exception e)
                {
                    tracer.Warn(
                        Resources.SaveArtifactCommand_TraceSaveFailed, this.CurrentElement.InstanceName, item.GetLogicalPath(), e);
                }
            }
        }
        public void LoadShapePositions(string solutionFolder)
        {
            FilePath = Path.Combine(solutionFolder, "DiagramShapePositions.json");

            tracer.Verbose("Loading shape positions from {0}", FilePath);

            // Load shape positions from file
            try
            {
                if (File.Exists(FilePath))
                {
                    var fileContent = File.ReadAllText(FilePath);
                    ShapePositions = JsonConvert.DeserializeObject <Dictionary <Guid, Point> >(fileContent);
                    tracer.Info("Loaded shape positions from {0}", FilePath);
                }
                else
                {
                    tracer.Info("Could not find shape positions file at {0}", FilePath);
                }
            }
            catch (Exception ex)
            {
                tracer.Error(ex, "Cannot load shape positions from {0}.", FilePath);
            }

            // If File not exists or an error ocurred
            if (ShapePositions == null)
            {
                ShapePositions = new Dictionary <Guid, Point>();
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Evaluates the violations for the rule.
        /// </summary>
        /// <remarks></remarks>
        public override IEnumerable <ValidationResult> Validate()
        {
            List <ValidationResult> errors = new List <ValidationResult>();

            this.ValidateObject();

            tracer.Info(
                Resources.PropertyStringValueForbiddenCharsValidationRule_TraceInitial, this.CurrentProperty.DefinitionName, this.ForbiddenChars);

            if (this.CurrentProperty.Info.Type.Equals(typeof(string).FullName, StringComparison.OrdinalIgnoreCase))
            {
                var propertyValue = this.CurrentProperty.Value.ToString();
                if (!string.IsNullOrEmpty(propertyValue) &&
                    !string.IsNullOrEmpty(this.ForbiddenChars))
                {
                    if (propertyValue.IndexOfAny(this.ForbiddenChars.ToCharArray()) != -1)
                    {
                        errors.Add(new ValidationResult(
                                       string.Format(CultureInfo.CurrentCulture,
                                                     Resources.PropertyStringValueForbiddenCharsValidationRule_ContainsForbiddenChars,
                                                     this.CurrentProperty.DefinitionName, this.CurrentProperty.Owner.InstanceName, this.ForbiddenChars)));
                    }
                }
            }

            tracer.Info(
                Resources.PropertyStringValueForbiddenCharsValidationRule_TraceEvaluation, this.CurrentProperty.DefinitionName, this.ForbiddenChars, !errors.Any());

            return(errors);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Transforms the Templates
        /// </summary>
        public override void Execute()
        {
            this.ValidateObject();

            tracer.Info(
                Resources.SetBuildActionCommand_TraceInitial, this, CurrentElement.InstanceName, this.TargetPath, this.BuildAction);

            var resolver = new PathResolver(this.CurrentElement, this.UriService,
                                            this.TargetPath, this.CurrentElement.InstanceName);

            resolver.Resolve();

            if (!string.IsNullOrEmpty(resolver.Path))
            {
                var item = this.Solution.Find <IItem>(resolver.Path).FirstOrDefault();
                if (item == null)
                {
                    throw new InvalidOperationException(
                              string.Format(CultureInfo.CurrentCulture, Resources.SetBuildActionCommand_ErrorTargetPathNotAnItem, this.CurrentElement.InstanceName, this.TargetPath));
                }
                else
                {
                    tracer.Info(
                        Resources.SetBuildActionCommand_TraceBuildAction, this, CurrentElement.InstanceName, this.BuildAction, item.GetLogicalPath());

                    item.Data.ItemType = BuildAction.ToString();
                }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Evaluates the violations for the rule.
        /// </summary>
        /// <remarks></remarks>
        public override IEnumerable <ValidationResult> Validate()
        {
            List <ValidationResult> errors = new List <ValidationResult>();

            this.ValidateObject();

            tracer.Info(
                Resources.ValidateGuidanceDocument_TraceInitial, this.CurrentElement.InstanceName);

            // Get guidance document path
            var documentFilePath = GuidanceDocumentHelper.GetDocumentPath(tracer,
                                                                          this.CurrentElement.AsElement(), this.UriReferenceService);

            if (this.processor == null)
            {
                this.processor = new TocGuidanceProcessor(documentFilePath,
                                                          this.CurrentElement.Parent.Parent.PatternToolkitInfo.Identifier, this.CurrentElement.ProjectContentPath);
            }

            // Validate document
            errors.AddRange(this.processor.ValidateDocument());

            tracer.Info(
                Resources.ValidateGuidanceDocument_TraceValidation, this.CurrentElement.InstanceName, !errors.Any());

            return(errors);
        }
        /// <summary>
        /// Evaluates the condition by matching the event arguments property name with the specified value.
        /// </summary>
        public override bool Evaluate()
        {
            this.ValidateObject();

            if (this.Event == null ||
                !(this.Event.EventArgs is PropertyChangedEventArgs))
            {
                return(false);
            }

            var propertyChangedArgs = (PropertyChangedEventArgs)this.Event.EventArgs;

            if (propertyChangedArgs == null)
            {
                return(false);
            }

            tracer.Info(
                Resources.PropertyChangedEventArgsMatchesPropertyNameCondition_TraceInitial, this.PropertyName);

            var result = propertyChangedArgs.PropertyName == this.PropertyName;

            tracer.Info(
                Resources.PropertyChangedEventArgsMatchesPropertyNameCondition_TraceEvaluate, this.PropertyName, result);

            return(result);
        }
        /// <summary>
        /// Evaluates this provider.
        /// </summary>
        public override object Evaluate()
        {
            this.ValidateObject();

            tracer.Info(
                Resources.RegisteredMachineUserValueProvider_TraceInitial, RegKey, RegKeyValue);

            var value = this.reader.ReadValue();

            if (value == null)
            {
                tracer.Warn(
                    Resources.RegisteredMachineUserValueProvider_TraceNoValue, RegKey, RegKeyValue);
                return(string.Empty);
            }
            else
            {
                if (string.IsNullOrEmpty(value.ToString()))
                {
                    value = UnknownOrganization;
                }
                else
                {
                    value = value.ToString();
                }

                tracer.Info(
                    Resources.RegisteredMachineUserValueProvider_TraceEvaluation, RegKey, RegKeyValue, value);
                return(value.ToString());
            }
        }
        public async Task ExecuteAsync(string clientId, IPacket input, IMqttChannel <IPacket> channel)
        {
            if (input.Type != MqttPacketType.Disconnect)
            {
                return;
            }

            await Task.Run(() =>
            {
                Disconnect disconnect = input as Disconnect;

                _tracer.Info(ServerProperties.DisconnectFlow_Disconnecting(clientId));

                _willRepository.Delete(clientId);

                ClientSession session = _sessionRepository.Read(clientId);

                if (session == null)
                {
                    throw new MqttException(ServerProperties.SessionRepository_ClientSessionNotFound(clientId));
                }

                if (session.Clean)
                {
                    _sessionRepository.Delete(session.Id);

                    _tracer.Info(ServerProperties.Server_DeletedSessionOnDisconnect(clientId));
                }

                _connectionProvider.RemoveConnection(clientId);
            });
        }
        /// <summary>
        /// Returns the result of evaluation of this provider.
        /// </summary>
        public override object Evaluate()
        {
            this.ValidateObject();

            var productElement = this.CurrentElement as IProductElement;
            var elementName    = (productElement != null) ? productElement.InstanceName : this.CurrentElement.Info.DisplayName;

            tracer.Info(
                Resources.RemoveForbiddenCharsExpressionValueProvider_TraceInitial, this.Expression, this.ForbiddenChars, elementName);

            var result = ExpressionEvaluator.Evaluate(this.CurrentElement, this.Expression);

            if (result == null)
            {
                tracer.Warn(
                    Resources.RemoveForbiddenCharsExpressionValueProvider_TraceResolvedNullExpression, this.Expression, elementName);
            }
            else
            {
                //Remove forbidden chars
                if (!string.IsNullOrEmpty(this.ForbiddenChars) &&
                    !string.IsNullOrEmpty(result))
                {
                    foreach (var character in this.ForbiddenChars)
                    {
                        result = result.Replace(character.ToString(), string.Empty);
                    }
                }
            }

            tracer.Info(
                Resources.RemoveForbiddenCharsExpressionValueProvider_TraceEvaluation, this.Expression, this.ForbiddenChars, elementName, result);

            return(result);
        }
Ejemplo n.º 12
0
        public async Task ExecuteAsync(string clientId, IPacket input, IMqttChannel <IPacket> channel)
        {
            if (input.Type != MqttPacketType.Disconnect)
            {
                return;
            }

            await Task.Run(() => {
                var disconnect = input as Disconnect;

                tracer.Info(Server.Properties.Resources.DisconnectFlow_Disconnecting, clientId);

                willRepository.Delete(clientId);

                var session = sessionRepository.Read(clientId);

                if (session == null)
                {
                    throw new MqttException(string.Format(Properties.Resources.SessionRepository_ClientSessionNotFound, clientId));
                }

                if (session.Clean)
                {
                    sessionRepository.Delete(session.Id);

                    tracer.Info(Server.Properties.Resources.Server_DeletedSessionOnDisconnect, clientId);
                }

                connectionProvider.RemoveConnection(clientId);
            });
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Evaluates the violations for the rule.
        /// </summary>
        /// <remarks></remarks>
        public override IEnumerable <ValidationResult> Validate()
        {
            var errors = new List <ValidationResult>();

            this.ValidateObject();

            tracer.Info(
                "Validating VerbIdRequestFieldValidator on current element '{0}'", this.CurrentElement.InstanceName);

            var verb = this.CurrentElement.As <IVerb>();
            var hasIdRequestField = (verb.RequestContract != null) &&
                                    verb.RequestContract.RequestFields.Any(rf => rf.InstanceName.Equals(IdFieldName, StringComparison.InvariantCulture) &&
                                                                           rf.DataType.Equals(typeof(string).FullName, StringComparison.OrdinalIgnoreCase));

            if (((verb.VerbType.Equals("GET") && !verb.HasMany) ||
                 (verb.VerbType.Equals("PUT") ||
                  verb.VerbType.Equals("DELETE"))) && !hasIdRequestField)
            {
                errors.Add(new ValidationResult(
                               string.Format(CultureInfo.CurrentCulture, Resources.VerbIdRequestFieldValidator_IdRequestFieldMissing,
                                             this.CurrentElement.InstanceName, IdFieldName, typeof(string).FullName)));
            }

            tracer.Info(
                "Validated VerbIdRequestFieldValidator on current element '{0}', as '{1}'", this.CurrentElement.InstanceName, !errors.Any());

            return(errors);
        }
        /// <summary>
        /// Evaluates the condition by verifying the existance of the property and whether it has a value.
        /// </summary>
        public override bool Evaluate()
        {
            this.ValidateObject();

            tracer.Info(
                Resources.ElementPropertyExistsCondition_TraceInitial, this.CurrentElement.InstanceName, this.PropertyName, this.MustHaveValue);

            var property = this.CurrentElement.Properties.FirstOrDefault(
                prop => prop.Info.Name == this.PropertyName);

            if (property != null)
            {
                var result = this.MustHaveValue ? !string.IsNullOrEmpty(property.RawValue) : true;

                tracer.Info(
                    Resources.ElementPropertyExistsCondition_TraceEvaluation, this.CurrentElement.InstanceName, this.PropertyName, this.MustHaveValue, result);

                return(result);
            }

            tracer.Info(
                Resources.ElementPropertyExistsCondition_TraceNoProperty, this.PropertyName, this.CurrentElement.Info.Name);

            return(false);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Executes the creation command.
        /// </summary>
        public override void Execute()
        {
            try
            {
                this.ValidateObject();

                tracer.Info(
                    Resources.CreateAutomationLibraryExtensionCommand_TraceInital, this.CurrentElement.InstanceName);

                // Create Automation Library
                if (this.CurrentElement.AutomationLibrary == null)
                {
                    var collection   = this.CurrentElement.AsCollection();
                    var instanceName = collection.Info.ExtensionPoints
                                       .FirstOrDefault(e => e.Name == typeof(AutomationLibrary).Name).DisplayName;

                    tracer.Info(
                        Resources.CreateAutomationLibraryExtensionCommand_TraceCreatingInstance, this.CurrentElement.InstanceName, instanceName);

                    this.CurrentElement.CreateAutomationLibrary(
                        instanceName,
                        AutomationLibraryToolkitInfo.ProductId,
                        AutomationLibraryToolkitInfo.ToolkitId);
                }
            }
            catch (Exception)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture,
                                                                  Resources.CreateAutomationLibraryExtensionCommand_ErrorFailedInstantiation, this.CurrentElement.InstanceName, AutomationLibraryToolkitInfo.RegistrationName));
            }
        }
Ejemplo n.º 16
0
        public override void Execute()
        {
            var app       = this.CurrentElement.Root.As <IApplication>();
            var component = this.CurrentElement.As <IComponent>();

            if (CheckIsDeployed)
            {
                var isDeployed = app.Design.Endpoints.GetAll()
                                 .Any(ep => ep.EndpointComponents.AbstractComponentLinks.Any(cl => cl.ComponentReference.Value == component));

                if (!isDeployed)
                {
                    tracer.Info("Component not deployed. Not unfolding T4 file.");
                    return;
                }
            }

            if (CheckIsNotUnfoldedCustomCode)
            {
                if (component.UnfoldedCustomCode)
                {
                    tracer.Info("Component custom code already unfolded. Not unfolding T4 file.");
                    return;
                }
            }

            base.Execute();
        }
Ejemplo n.º 17
0
        /// <summary>
        /// 发生配置变化后约30秒延迟时间才会全部重启完成。
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void TaskConfigChanged(object sender, FileSystemEventArgs e)
        {
            try
            {
                //Note:线程锁定
                lock (this)
                {
                    _log.Info($"■■■■■■ 文件{e.Name}发生变化。变化类型:{e.ChangeType} ■■■■■■");
                    _watcher.Stop();

                    //原任务全部移除
                    foreach (var task in Tasks)
                    {
                        task.ChangeStatus(TaskRunStatusType.Removing);
                    }
                    TryRemoveTask();

                    TaskSetting          = TaskConfig.GetInstance(true);
                    TaskSetting.Changed += TaskConfigChanged; //只保留一次的事件

                    //Note:初始化计时器
                    //_watcher = new Timer(cfg.WatchTimer.DelayMillisecond); //Note:第一次运行不按间隔时间执行。
                    _watcher.Interval = ((TimeSpan)TaskSetting.WatchTimer.WorkingInterval).TotalMilliseconds;
                    _watcher.Start(); //启动工作回调
                    _log.Info($"■■■■■■ 更新配置后的工作间隔为{TimeSpan.FromMilliseconds(_watcher.Interval)}后 ■■■■■■");
                }
            }
            catch (Exception ex)
            {
                _log.Debug("重载任务配置发生异常", ex);
                throw;
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Process each dragged file.
        /// </summary>
        /// <param name="filePath"></param>
        public virtual bool ImportFileToSolution(string filePath)
        {
            // Cache added item
            this.AddedItems.Add(filePath, filePath);

            //Ensure filepath is unique name in the container folder.
            var uniqueName = EnsureItemNameUniqueInTargetContainer(filePath);

            if (!uniqueName.Equals(filePath, StringComparison.OrdinalIgnoreCase))
            {
                tracer.Verbose(
                    Resources.WindowsFileImporter_TraceRenamingAddedFile, filePath, uniqueName);

                // Update added filename
                this.AddedItems[filePath] = uniqueName;
            }

            // Add file to the solution
            var addedFile = this.TargetContainer.Add(filePath, this.AddedItems[filePath], true, false);

            tracer.Info(
                Resources.WindowsFileImporter_TraceImportComplete, filePath, this.currentElement.InstanceName, addedFile.GetLogicalPath());

            return(true);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Executes this instance.
        /// </summary>
        public override void Execute()
        {
            this.ValidateObject();

            tracer.Info(
                Resources.ValidatePatternModelCommand_TraceInitial, this.CurrentElement.InstanceName, this.TargetPath);

            var resolver = new PathResolver(this.CurrentElement, this.UriService,
                                            this.TargetPath);

            resolver.Resolve();

            if (!string.IsNullOrEmpty(resolver.Path))
            {
                var itemContainer = this.Solution.Find(resolver.Path).FirstOrDefault();

                if (itemContainer != null)
                {
                    tracer.Info(
                        Resources.ValidatePatternModelCommand_TraceValidating, this.CurrentElement.InstanceName, itemContainer.PhysicalPath);

                    if (!PatternModelDocHelper.ValidateDocument(itemContainer.PhysicalPath))
                    {
                        tracer.Info(
                            Resources.ValidatePatternModelCommand_TraceOpeningForResolution, this.CurrentElement.InstanceName, itemContainer.Name);
                    }
                }
            }
            else
            {
                tracer.Warn(
                    Resources.ValidatePatternModelCommand_TraceDesignerNotFound, this.CurrentElement.InstanceName);
            }
        }
Ejemplo n.º 20
0
        public override void Execute()
        {
            Validator.ValidateObject(this, new ValidationContext(this, null, null));

            tracer.Info(
                Resources.VerifyElementIsValid_TraceInitial, this.CurrentElement.InstanceName, this.ValidateDescendants);

            var instances = this.ValidateDescendants ? this.CurrentElement.Traverse().OfType <IInstanceBase>() : new[] { this.CurrentElement };

            instances = instances.Concat(this.ValidateAscendants ? RecursiveElementParent(this.CurrentElement.Parent) : Enumerable.Empty <IInstanceBase>());

            var elements = instances.Concat(instances.OfType <IProductElement>().SelectMany(e => e.Properties));

            var result = this.ProductManager.Validate(elements);

            tracer.Info(
                Resources.VerifyElementIsValid_TraceEvaluation, this.CurrentElement.InstanceName, this.ValidateDescendants, result);

            if (!result)
            {
                var format = this.ValidateDescendants ?
                             Resources.VerifyElementIsValid_ElementOrDescendentNotValid :
                             Resources.VerifyElementIsValid_ElementNotValid;

                var message = String.Format(CultureInfo.CurrentCulture, format, this.CurrentElement.InstanceName);

                throw new OperationCanceledException(message);
            }
        }
Ejemplo n.º 21
0
 private static ITracer createTracer(Assembly assembly)
 {
     if (assembly == (Assembly)null)
         throw new ArgumentNullException(nameof(assembly));
     string traceFileName = GlobalTracer.getTraceFileName(assembly);
     int result;
     if (!int.TryParse(GlobalConfiguration.AppSettings["LogLevel"], out result))
         result = !GlobalConfiguration.Debug ? 2 : 4;
     ITracer tracer = (ITracer)new FileTracer(traceFileName)
     {
         LogLevel = result
     };
     if (GlobalConfiguration.GetBoolean("EnableServerLog") && GlobalConfiguration.CurrentSession != null && tracer is FileTracer)
         (tracer as FileTracer).ServerTracer = GlobalTracer.createServerTracer(GlobalConfiguration.CurrentSession, assembly);
     if (tracer == null)
         throw new Exception("Init tracer failed.");
     GlobalTracer.initTrace(tracer);
     try
     {
         tracer.Info(string.Format("The assembly:{0}, version:{1} was initialized.", (object)assembly.GetName().Name, (object)assembly.GetName().Version));
         tracer.Info(string.Format("The Utility4, version:{0} was loaded.", (object)typeof(GlobalTracer).Assembly.GetName().Version));
     }
     catch (Exception ex)
     {
     }
     return tracer;
 }
        void PublishXaml(string fileName)
        {
            // Make sure we can read it as XML, just to safeguard the client.
            try {
                using (var reader = XmlReader.Create(fileName)) {
                    var xdoc = XDocument.Load(reader);
                    // Strip the x:Class attribute since it doesn't make
                    // sense for the deserialization and might break stuff.
                    var xclass = xdoc.Root.Attribute("{http://schemas.microsoft.com/winfx/2009/xaml}Class");
                    if (xclass != null)
                    {
                        xclass.Remove();
                    }
                    xclass = xdoc.Root.Attribute("{http://schemas.microsoft.com/winfx/2006/xaml}Class");
                    if (xclass != null)
                    {
                        xclass.Remove();
                    }

                    var xml = xdoc.ToString(SaveOptions.DisableFormatting);
                    tracer.Info("!Publishing XAML payload");

                    proxy.Invoke("Xaml", SessionId, xml)
                    .ContinueWith(t =>
                                  tracer.Error(t.Exception.InnerException, "Failed to publish XAML payload."),
                                  CancellationToken.None,
                                  TaskContinuationOptions.OnlyOnFaulted,
                                  TaskScheduler.Default);
                }
            } catch (XmlException) {
                return;
            }
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Evaluates the violations for the rule.
        /// </summary>
        /// <remarks></remarks>
        public override IEnumerable <ValidationResult> Validate()
        {
            List <ValidationResult> errors = new List <ValidationResult>();

            // Verify all [Required] and [Import]ed properties have valid values.
            this.ValidateObject();

            // Make initial trace statement for this rule
            tracer.Info(
                "Validating $safeitemname$ on property '{0}' of element '{1}' with AProperty '{2}'", this.CurrentProperty.DefinitionName, this.CurrentProperty.Owner.InstanceName, this.AProperty);

            // TODO: Implement provider automation code to determine the violations
            errors.Add(new ValidationResult(
                           string.Format(CultureInfo.CurrentCulture,
                                         "The value of property '{0}' for element '{1}' is not valid in some way. <Some prescriptive action to make it valid.>",
                                         this.CurrentProperty.DefinitionName, this.CurrentProperty.Owner.InstanceName)));

            // TODO: Use tracer.Warn() to note expected and recoverable errors
            // TODO: Use tracer.Verbose() to note internal execution logic decisions
            // TODO: Use tracer.Info() to note key results of execution
            // TODO: Raise exceptions for all other errors

            tracer.Info(
                "Validated $safeitemname$ on property '{0}' of element '{1}' with AProperty '{2}', as '{3}'", this.CurrentProperty.DefinitionName, this.CurrentProperty.Owner.InstanceName, this.AProperty, !errors.Any());

            return(errors);
        }
        private void LoadDataFromKafka2Db(IMessageFlow messageFlow,
                                          IReadOnlyCollection <Type> dataObjectTypes,
                                          DataConnection dataConnection,
                                          int batchSize,
                                          int bulkReplaceCommandTimeoutSec)
        {
            var actors = CreateActors(dataObjectTypes,
                                      dataConnection,
                                      new BulkCopyOptions
            {
                BulkCopyTimeout = bulkReplaceCommandTimeoutSec
            });

            var initialStats = _kafkaMessageFlowInfoProvider.GetFlowStats(messageFlow)
                               .ToDictionary(x => x.TopicPartition, x => new MessageFlowStats(x.TopicPartition, x.End, Offset.Unset));

            using var receiver = _receiverFactory.Create(messageFlow);

            while (true)
            {
                var batch = receiver.ReceiveBatch(batchSize);

                var bulkCommands = _commandFactory.CreateCommands(batch);
                if (bulkCommands.Count > 0)
                {
                    using var scope = new TransactionScope(TransactionScopeOption.RequiresNew, new TransactionOptions { IsolationLevel = IsolationLevel.Serializable, Timeout = TimeSpan.Zero });
                    foreach (var actor in actors)
                    {
                        actor.ExecuteCommands(bulkCommands);
                    }
                    scope.Complete();
                }

                receiver.CompleteBatch(batch);

                var batchStats = batch
                                 .GroupBy(x => x.TopicPartition)
                                 .ToDictionary(x => x.Key, x => x.Max(y => y.Offset.Value));
                foreach (var batchStat in batchStats)
                {
                    if (!initialStats.TryGetValue(batchStat.Key, out var initialStat))
                    {
                        throw new KeyNotFoundException(batchStat.Key.ToString());
                    }

                    var currentStat = new MessageFlowStats(batchStat.Key, initialStat.End, batchStat.Value + 1);
                    _tracer.Info($"Topic {currentStat.TopicPartition}, End: {currentStat.End}, Offset: {currentStat.Offset}, Lag: {currentStat.Lag}");

                    initialStats[batchStat.Key] = currentStat;
                }

                var complete = initialStats.Values.All(x => x.Lag <= 0);
                if (complete)
                {
                    _tracer.Info($"Kafka state init for flow {messageFlow.Description} complete");
                    break;
                }
            }
        }
Ejemplo n.º 25
0
        public async Task ExecuteAsync(string clientId, IPacket input, IMqttChannel <IPacket> channel)
        {
            if (input.Type != MqttPacketType.Connect)
            {
                return;
            }

            var connect = input as Connect;

            if (!authenticationProvider.Authenticate(clientId, connect.UserName, connect.Password))
            {
                throw new MqttConnectionException(MqttConnectionStatus.BadUserNameOrPassword);
            }

            var session        = sessionRepository.Read(clientId);
            var sessionPresent = connect.CleanSession ? false : session != null;

            if (connect.CleanSession && session != null)
            {
                sessionRepository.Delete(session.Id);
                session = null;

                tracer.Info(Server.Properties.Resources.Server_CleanedOldSession, clientId);
            }

            var sendPendingMessages = false;

            if (session == null)
            {
                session = new ClientSession(clientId, connect.CleanSession);

                sessionRepository.Create(session);

                tracer.Info(Server.Properties.Resources.Server_CreatedSession, clientId);
            }
            else
            {
                sendPendingMessages = true;
            }

            if (connect.Will != null)
            {
                var connectionWill = new ConnectionWill(clientId, connect.Will);

                willRepository.Create(connectionWill);
            }

            await channel.SendAsync(new ConnectAck (MqttConnectionStatus.Accepted, sessionPresent))
            .ConfigureAwait(continueOnCapturedContext: false);

            if (sendPendingMessages)
            {
                await SendPendingMessagesAsync(session, channel)
                .ConfigureAwait(continueOnCapturedContext: false);
                await SendPendingAcknowledgementsAsync(session, channel)
                .ConfigureAwait(continueOnCapturedContext: false);
            }
        }
        public async Task ExecuteAsync(string clientId, IPacket input, IMqttChannel <IPacket> channel)
        {
            if (input.Type != MqttPacketType.Connect)
            {
                return;
            }

            Connect connect = input as Connect;

            if (!_authenticationProvider.Authenticate(clientId, connect.UserName, connect.Password))
            {
                throw new MqttConnectionException(MqttConnectionStatus.BadUserNameOrPassword);
            }

            ClientSession session        = _sessionRepository.Read(clientId);
            bool          sessionPresent = connect.CleanSession ? false : session != null;

            _tracer.Info($"Client connecting with protocol level {connect.ProtocolLelvel}.");

            if (connect.CleanSession && session != null)
            {
                _sessionRepository.Delete(session.Id);
                session = null;

                _tracer.Info(ServerProperties.Server_CleanedOldSession(clientId));
            }

            bool sendPendingMessages = false;

            if (session == null)
            {
                session = new ClientSession(clientId, connect.CleanSession);

                _sessionRepository.Create(session);

                _tracer.Info(ServerProperties.Server_CreatedSession(clientId));
            }
            else
            {
                sendPendingMessages = true;
            }

            if (connect.Will != null)
            {
                ConnectionWill connectionWill = new ConnectionWill(clientId, connect.Will);

                _willRepository.Create(connectionWill);
            }

            await channel.SendAsync(new ConnectAck( MqttConnectionStatus.Accepted, sessionPresent ));

            if (sendPendingMessages)
            {
                await SendPendingMessagesAsync(session, channel);
                await SendPendingAcknowledgementsAsync(session, channel);
            }
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Evaluates this provider.
        /// </summary>
        public override object Evaluate()
        {
            this.ValidateObject();

            tracer.Info(
                Resources.ProjectGuidValueProvider_TraceInitial, this.CurrentElement.InstanceName, this.ProjectPath, this.Format);

            return(base.Evaluate());
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Evaluates the condition
        /// </summary>
        public override bool Evaluate()
        {
            this.ValidateObject();

            tracer.Info(
                Resources.DropFileCondition_TraceInitial, this.Extension);

            return(base.Evaluate());
        }
        private void LoadDataFromKafka2Db(IMessageFlow messageFlowForKafkaTopic,
                                          IReadOnlyCollection <Type> dataObjectTypes,
                                          DataConnection dataConnection,
                                          int batchSize,
                                          int bulkReplaceCommandTimeoutSec)
        {
            var targetMessageFlowDescription = messageFlowForKafkaTopic.GetType().Name;

            var actors = CreateActors(dataObjectTypes,
                                      dataConnection,
                                      new BulkCopyOptions
            {
                BulkCopyTimeout = bulkReplaceCommandTimeoutSec
            });

            using var receiver = _receiverFactory.Create(messageFlowForKafkaTopic);
            // retry добавлен из-за https://github.com/confluentinc/confluent-kafka-dotnet/issues/86
            var lastTargetMessageOffset =
                Policy.Handle <KafkaException>(exception => exception.Error.Code == ErrorCode.LeaderNotAvailable)
                .WaitAndRetryForever(i => TimeSpan.FromSeconds(5),
                                     (exception, waitSpan) =>
                                     _tracer.Warn(exception,
                                                  $"Can't get size of kafka topic. Message flow: {targetMessageFlowDescription}. Wait span: {waitSpan}"))
                .ExecuteAndCapture(() => _kafkaMessageFlowInfoProvider.GetFlowSize(messageFlowForKafkaTopic) - 1)
                .Result;

            _tracer.Info($"Receiving messages from kafka for flow: {targetMessageFlowDescription}. Last target message offset: {lastTargetMessageOffset}");

            var resolvedCommandFactories = _commandFactories.Where(f => f.AppropriateFlows.Contains(messageFlowForKafkaTopic))
                                           .ToList();

            for (var distance = lastTargetMessageOffset; distance > 0;)
            {
                var batch = receiver.ReceiveBatch(batchSize);

                var lastMessageOffset = batch.Last().Offset.Value;
                distance = lastTargetMessageOffset - lastMessageOffset;

                _tracer.Info($"Flow: {targetMessageFlowDescription}. Received messages: {batch.Count}. Last message offset for received batch: {lastMessageOffset}. Target and current offsets distance: {distance}");

                var bulkCommands = resolvedCommandFactories.SelectMany(factory => factory.CreateCommands(batch)).ToList();
                if (bulkCommands.Count > 0)
                {
                    using var scope = new TransactionScope(TransactionScopeOption.RequiresNew, new TransactionOptions { IsolationLevel = IsolationLevel.Serializable, Timeout = TimeSpan.Zero });
                    foreach (var actor in actors)
                    {
                        actor.ExecuteCommands(bulkCommands);
                    }
                    scope.Complete();
                }

                receiver.CompleteBatch(batch);
            }

            _tracer.Info($"Receiving messages from kafka for flow: {targetMessageFlowDescription} finished");
        }
Ejemplo n.º 30
0
        void IKafkaMessageFlowReceiver.CompleteBatch(IEnumerable <ConsumeResult <Ignore, byte[]> > batch)
        {
            var result = batch.OrderByDescending(x => x.Offset.Value).FirstOrDefault();

            if (result != null)
            {
                _consumer.StoreOffset(result);
                _tracer.Info($"KafkaAudit - offset stored {result.TopicPartitionOffset}");
            }
        }
Ejemplo n.º 31
0
        /// <summary>
        /// Synchronizes the targets file on disk with targets file in this version of the toolkit.
        /// </summary>
        internal static void SyncTargets(ITracer tracer, TargetsInfo targetsInfo)
        {
            try
            {
                tracer.Info(Resources.AuthoringPackage_TraceSyncTargetsInitial);

                //Write updated targets file
                WriteUpdatedTargets(tracer, targetsInfo);
            }
            catch (Exception ex)
            {
                tracer.Error(ex, Resources.AuthoringPackage_FailedSyncTargets);
            }
        }
Ejemplo n.º 32
0
        private void Run(ITracer tracer, long repeat)
        {
            var e = new ManualResetEventSlim();
            var watch = Stopwatch.StartNew();

            for (int i = 1; i <= repeat; i++)
            {
                var current = i;
                Task.Factory.StartNew(() =>
                {
                    tracer.Info(Guid.NewGuid());
                    if (current == repeat)
                        e.Set();
                });
            }

            e.Wait();

            Console.WriteLine("{0}: {1}", tracer.GetType().Name, watch.ElapsedTicks / repeat);
        }
Ejemplo n.º 33
0
        private static void WriteUpdatedTargets(ITracer tracer, TargetsInfo targetsInfo)
        {
            tracer.Info(Resources.AuthoringPackage_TraceSyncTargetsWritingNewTargets, targetsInfo.TargetsPath, targetsInfo.ToolkitVersion);

            //Delete file if exists
            if (File.Exists(targetsInfo.TargetsPath))
            {
                File.Delete(targetsInfo.TargetsPath);
            }

            // Ensure directory exists
            var targetsFolder = Path.GetDirectoryName(targetsInfo.TargetsPath);
            if (!Directory.Exists(targetsFolder))
            {
                Directory.CreateDirectory(targetsFolder);
            }

            // Write new targets
            PopulateTargets(targetsInfo);
        }
Ejemplo n.º 34
0
	public virtual void TestInitialize()
	{
		UIThreadInvoker.Initialize();

		// Causes devenv to initialize
		var devEnv = Clide.DevEnv.Get(new Guid(IntegrationPackage.Constants.PackageGuid));

		this.tracer = Tracer.Get(this.GetType());
		this.strings = new StringBuilder();
		this.listener = new TextWriterTraceListener(new StringWriter(this.strings));

		// Just in case, re-set the tracers.
		Tracer.Manager.SetTracingLevel(TracerManager.DefaultSourceName, SourceLevels.All);
		Tracer.Manager.AddListener(TracerManager.DefaultSourceName, this.listener);

		tracer.Info("Running test from: " + this.TestContext.TestDeploymentDir);

		if (Dte != null)
		{
			Dte.SuppressUI = false;
			Dte.MainWindow.Visible = true;
			Dte.MainWindow.WindowState = EnvDTE.vsWindowState.vsWindowStateNormal;
		}

		var shellEvents = new ShellEvents(ServiceProvider);
		var initialized = shellEvents.IsInitialized;
		while (!initialized)
		{
			System.Threading.Thread.Sleep(10);
		}

		tracer.Info("Shell initialized successfully");
		if (VsIdeTestHostContext.ServiceProvider == null)
			VsIdeTestHostContext.ServiceProvider = new VsServiceProvider();

		cleanupFolders = new List<string>();
	}
Ejemplo n.º 35
0
        /// <summary>
        /// Initializes driver with settings object.
        /// </summary>
        /// <param name="tracer">Tracer sink</param>
        /// <param name="settings">Arbitrary settings object, type specific to implementation</param>
        /// <seealso cref="IStorageDriverFactory.Create"/>
        /// <seealso cref="IStorageDriverFactory.GetDriverConfig"/>
        public void Initialize(ITracer tracer, object settings)
        {
            if (m_initialized)
            {
                throw new InvalidOperationException("Already initialized");
            }

            if (tracer == null)
            {
                throw new ArgumentNullException("tracer");
            }

            m_tracer = tracer;
            if (m_tracer.IsDebugEnabled)
            {
                m_tracer.Debug(string.Concat("Initializing RAM storage driver for settings string: ", settings));
            }

            m_changesets = new ConcurrentDictionary<long, RamDriverChangeset>();

            var initString = settings as string;
            if (!string.IsNullOrEmpty(initString))
            {
                m_settings = new RamDriverSettings();
                if (0 == StringComparer.OrdinalIgnoreCase.Compare("demo", initString))
                {
                    m_settings.InitializationCommand = initString;
                }
                else
                {
                    m_settings.StorageRoot = initString;
                }
            }
            else
            {
                m_settings = new RamDriverSettings(settings as RamDriverSettings);
            }

            CheckInitialized();

            if (m_tracer.IsInfoEnabled)
            {
                m_tracer.Info("RAM storage driver ready");
            }
        }
Ejemplo n.º 36
-1
 /// <summary>
 /// Gets the path to the guidance document from the current element.
 /// </summary>
 /// <remarks>
 /// Returns the first artifact link with a *.doc extension of the current element.
 /// </remarks>
 public static string GetDocumentPath(ITracer tracer, IProductElement element, IUriReferenceService uriService)
 {
     // Return path of first reference
     var references = SolutionArtifactLinkReference.GetResolvedReferences(element, uriService);
     if (!references.Any())
     {
         tracer.Warn(String.Format(CultureInfo.CurrentCulture,
             Resources.GuidanceDocumentPathProvider_NoLinksFound, element.InstanceName));
         return string.Empty;
     }
     else
     {
         var reference = references.FirstOrDefault(r => r.PhysicalPath.EndsWith(GuidanceDocumentExtension));
         if (reference == null)
         {
             tracer.Warn(String.Format(CultureInfo.CurrentCulture,
                 Resources.GuidanceDocumentPathProvider_NoDocumentLinkFound, element.InstanceName));
             return string.Empty;
         }
         else
         {
             tracer.Info(String.Format(CultureInfo.CurrentCulture,
                 Resources.GuidanceDocumentPathProvider_LinkFound, element.InstanceName, reference.PhysicalPath));
             return reference.PhysicalPath;
         }
     }
 }