Exemplo n.º 1
0
        public SqlPreCommand SynchronizationScript(bool interactive = true, bool schemaOnly = false, string replaceDatabaseName = null)
        {
            OnBeforeDatabaseAccess();

            if (Synchronizing == null)
            {
                return(null);
            }

            using (CultureInfoUtils.ChangeBothCultures(ForceCultureInfo))
                using (ExecutionMode.Global())
                {
                    Replacements replacements = new Replacements()
                    {
                        Interactive = interactive, ReplaceDatabaseName = replaceDatabaseName, SchemaOnly = schemaOnly
                    };
                    SqlPreCommand command = Synchronizing
                                            .GetInvocationListTyped()
                                            .Select(e =>
                    {
                        try
                        {
                            return(e(replacements));
                        }
                        catch (Exception ex)
                        {
                            return(new SqlPreCommandSimple("-- Exception on {0}.{1}\r\n{2}".FormatWith(e.Method.DeclaringType.Name, e.Method.Name, ex.Message.Indent(2, '-'))));
                        }
                    })
                                            .Combine(Spacing.Triple);

                    return(command);
                }
        }
Exemplo n.º 2
0
        public SqlPreCommand?SynchronizationScript(bool interactive = true, bool schemaOnly = false, string?replaceDatabaseName = null)
        {
            OnBeforeDatabaseAccess();

            if (Synchronizing == null)
            {
                return(null);
            }

            using (CultureInfoUtils.ChangeBothCultures(ForceCultureInfo))
                using (ExecutionMode.Global())
                {
                    Replacements replacements = new Replacements()
                    {
                        Interactive         = interactive,
                        ReplaceDatabaseName = replaceDatabaseName,
                        SchemaOnly          = schemaOnly
                    };
                    SqlPreCommand?command = Synchronizing
                                            .GetInvocationListTyped()
                                            .Select(e =>
                    {
                        try
                        {
                            SafeConsole.WriteColor(ConsoleColor.White, e.Method.DeclaringType !.TypeName());
                            Console.Write(".");
                            SafeConsole.WriteColor(ConsoleColor.DarkGray, e.Method.MethodName());
                            Console.Write("...");

                            var result = e(replacements);

                            if (result == null)
                            {
                                SafeConsole.WriteLineColor(ConsoleColor.Green, "OK");
                            }
                            else
                            {
                                SafeConsole.WriteLineColor(ConsoleColor.Yellow, "Changes");
                            }

                            return(result);
                        }
                        catch (Exception ex)
                        {
                            SafeConsole.WriteColor(ConsoleColor.Red, "Error");
                            SafeConsole.WriteLineColor(ConsoleColor.DarkRed, " (...it's probably ok, execute this script and try again)");

                            return(new SqlPreCommandSimple("-- Exception on {0}.{1}\r\n{2}".FormatWith(e.Method.DeclaringType !.Name, e.Method.Name, ex.Message.Indent(2, '-'))));
                        }
                    })
                                            .Combine(Spacing.Triple);

                    return(command);
                }
        }
Exemplo n.º 3
0
        public void Evaluate(int spreadMax)
        {
            Synchronizing?.Invoke(this, EventArgs.Empty);

            var buildResult = FBuildResult;

            if (buildResult.Error != null)
            {
                // This way the vvvv plugin node stays red
                PluginHost.LastRuntimeError = buildResult.Error;
                return;
            }
            else if (!string.IsNullOrEmpty(buildResult.SymbolError))
            {
                PluginHost.LastRuntimeError = buildResult.SymbolError;
            }

            var runtimeHost = FRuntimeHost;

            if (runtimeHost.Mode == RunMode.Paused || runtimeHost.Mode == RunMode.Stopped)
            {
                if (FMessages.Errors.Any())
                {
                    PluginHost.LastRuntimeError = FMessages.Errors.FirstOrDefault().What;
                }
                return;
            }

            var x = Clocks.FrameClock.Time; // hack. make sure that somebody is interested in time. otherwise HDEFrameClock observable will not trigger.

            try
            {
                RuntimeGraph.HandleException(NodeId);

                spreadMax = StreamUtils.GetSpreadMax(FInStreams);

                // Prepare internal state
                if (FInstances.Length != spreadMax)
                {
                    var instanceType = buildResult.InstanceType;
                    if (instanceType != null)
                    {
                        FInstances.Resize(spreadMax, () => buildResult.Factory.CreateInstance(instanceType, FInstanceId), value => Dispose(value));
                    }
                    else
                    {
                        FInstances.Resize(spreadMax, () => null, value => Dispose(value));
                    }
                }

                buildResult.EvaluateAction(spreadMax, FInstances, FInStreams, FOutStreams);
            }
            catch (RuntimeException exception)
            {
                // Collect the exception messages
                foreach (var p in exception.ExtractElementMessages(runtimeHost.Compilation.Compilation))
                {
                    FMessages.Add(p.Key.TracingId, MessageSeverity.Error, p.Value);
                }
                // Let others know about it
                runtimeHost.RaiseOnException(exception);
                // And finally tell vvvv about it
                throw exception.Original;
            }
            finally
            {
                Flushing?.Invoke(this, EventArgs.Empty);
            }
        }