Ejemplo n.º 1
0
        public NuGetListPackagesNode(Workspace workspace) : base(workspace)
        {
            Settings = Inlets.Create <ISettings>(nameof(Settings));
            Repo     = Outlets.Create <string>(nameof(Repo));

            Settings.OnNext(NuGet.Configuration.Settings.LoadDefaultSettings("."));
        }
Ejemplo n.º 2
0
        private void RebuildScript()
        {
            var options = ScriptOptions.Default
                          .AddReferences(
                typeof(DynamicObject).GetTypeInfo().Assembly,
                typeof(CSharpArgumentInfo).GetTypeInfo().Assembly,
                typeof(ExpandoObject).GetTypeInfo().Assembly)
                          .AddImports(typeof(Math).Namespace);

            var usedVars     = new HashSet <string>();
            var removeUnused = false;

            foreach (var diagnostic in CSharpScript.Create(_latestExpression, options).Compile())
            {
                if (diagnostic.Id == "CS0103")
                {
                    var missedVariable = diagnostic.Location.SourceTree.GetCompilationUnitRoot().FindToken(diagnostic.Location.SourceSpan.Start).Text;
                    usedVars.Add(missedVariable);
                    removeUnused = true;
                }
            }

            var unusedVars = new HashSet <string>(_variables.Keys);

            unusedVars.ExceptWith(usedVars);

            var sb = new StringBuilder();

            foreach (var variableName in usedVars)
            {
                if (!_variables.TryGetValue(variableName, out Inlet inlet))
                {
                    inlet = Inlets.Create("var" + Interlocked.Increment(ref _counter));
                    ((IObserver <object>)inlet).OnNext(null);
                    _variables.Add(variableName, inlet);
                    inlet.SetAttribute("title", variableName);
                    inlet.SetAttribute("is-title-editable", "true");
                }

                sb.AppendLine($"dynamic {variableName} = (dynamic)__globals__[\"{variableName}\"];");
            }

            if (removeUnused)
            {
                foreach (var variableName in unusedVars)
                {
                    Inlets.Destroy(_variables[variableName]);
                    _variables.Remove(variableName);
                }
            }

            var script = CSharpScript
                         .Create(sb.ToString(), options, typeof(Globals))
                         .ContinueWith(_latestExpression);

            script.Compile();
            _script = script;
        }
Ejemplo n.º 3
0
 private void SetupAttributtedPins()
 {
     foreach (var propertyInfo in GetType().GetRuntimeProperties())
     {
         var propertyTypeInfo = propertyInfo.PropertyType.GetTypeInfo();
         if (propertyTypeInfo.IsGenericType && propertyTypeInfo.GetGenericTypeDefinition() == typeof(Inlet <>))
         {
             var designerPropertiesAttributes = propertyInfo.GetCustomAttributes <DesignerPropertiesAttribute>();
             var basicInlet = Inlets.Create(propertyInfo.Name);
             basicInlet.SetAttribute("type", propertyTypeInfo.GenericTypeArguments[0].AssemblyQualifiedName);
             var inlet = CastInlet(basicInlet, propertyTypeInfo.GenericTypeArguments[0]);
             propertyInfo.SetValue(this, inlet);
         }
         if (propertyTypeInfo.IsGenericType && propertyTypeInfo.GetGenericTypeDefinition() == typeof(Outlet <>))
         {
             var designerPropertiesAttributes = propertyInfo.GetCustomAttributes <DesignerPropertiesAttribute>();
             var nonTypedOutlet = Outlets.Create(propertyInfo.Name);
             nonTypedOutlet.SetAttribute("type", propertyTypeInfo.GenericTypeArguments[0].AssemblyQualifiedName);
             var outlet = CastOutlet(nonTypedOutlet, propertyTypeInfo.GenericTypeArguments[0]);
             propertyInfo.SetValue(this, outlet);
         }
     }
 }