Beispiel #1
0
        /// <summary>
        /// Register a host object for a particular task/target pair.
        /// Overwrites any existing host object.
        /// </summary>
        public void RegisterHostObject(string projectFile, string targetName, string taskName, ITaskHost hostObject)
        {
/* Unmerged change from project 'Microsoft.Build (netcoreapp2.1)'
 * Before:
 *          ErrorUtilities.VerifyThrowArgumentNull(projectFile, "projectFile");
 *          ErrorUtilities.VerifyThrowArgumentNull(targetName, "targetName");
 * After:
 *          ErrorUtilities.VerifyThrowArgumentNull(projectFile, "projectFile));
 *          ErrorUtilities.VerifyThrowArgumentNull(targetName, "targetName));
 */
            ErrorUtilities.VerifyThrowArgumentNull(projectFile, nameof(projectFile));
            ErrorUtilities.VerifyThrowArgumentNull(targetName, nameof(targetName));
            ErrorUtilities.VerifyThrowArgumentNull(taskName, nameof(taskName));

            // We can only set the host object to a non-null value if the affinity for the project is not out of proc, or if it is, it is only implicitly
            // out of proc, in which case it will become in-proc after this call completes.  See GetNodeAffinity.
            bool isExplicit;
            bool hasExplicitOutOfProcAffinity = (GetNodeAffinity(projectFile, out isExplicit) == NodeAffinity.OutOfProc) && isExplicit;

            ErrorUtilities.VerifyThrowInvalidOperation(!hasExplicitOutOfProcAffinity || hostObject == null, "InvalidHostObjectOnOutOfProcProject");
            _hostObjectMap ??= new Dictionary <string, HostObjects>(StringComparer.OrdinalIgnoreCase);

            HostObjects hostObjects = GetHostObjectsFromMapByKeyOrCreateNew(projectFile);

            hostObjects.RegisterHostObject(targetName, taskName, hostObject);
        }
Beispiel #2
0
 public SqlPackage()
 {
     PackageId = "javascript_sql_factory";
     ScriptUri = "JavaScript.Manager.Sql.Scripts.sql.js";
     HostObjects.Add(new HostObject {
         Name = "xHost", Target = new ExtendedHostFunctions()
     });
 }
Beispiel #3
0
 public HttpPackage()
 {
     PackageId = "javascript_request_factory_http";
     HostObjects.Add(new HostObject {
         Name = "javascript_request_factory_http", Target = new NodeHttp()
     });
     //HostTypes.Add(new HostType{ Name="Buffer", Type = typeof(NodeBuffer)});
 }
 public TimerPackageExecutor()
 {
     PackageId = "javascript_timer_factory_timerExecutor";
     HostObjects.Add(new HostObject
     {
         Name   = "javascript_timer_factory_timerExecutor",
         Target = new TimerHelper()
     });
 }
Beispiel #5
0
        private HostObjects GetHostObjectsFromMapByKeyOrCreateNew(string projectFile)
        {
            if (!_hostObjectMap.TryGetValue(projectFile, out var hostObjects))
            {
                hostObjects = new HostObjects();
                _hostObjectMap[projectFile] = hostObjects;
            }

            return(hostObjects);
        }
Beispiel #6
0
 public HttpPackage()
 {
     PackageId = "http";
     HostObjects.Add(new HostObject {
         Name = "http", Target = new NodeHttp()
     });
     HostTypes.Add(new HostType {
         Name = "Buffer", Type = typeof(NodeBuffer)
     });
 }
Beispiel #7
0
        /// <summary>
        /// Register a remote host object for a particular task/target pair.
        /// The remote host object require registered in Running Object Table(ROT) already.
        /// Overwrites any existing host object.
        ///
        /// It's caller's responsibly:
        /// To maintain the live cycle of the host object.
        /// Register and unregister from ROT.
        /// Ensure the host object has appropriate COM interface that can be used in task.
        /// </summary>
        /// <param name="projectFile">project file name</param>
        /// <param name="targetName">target name</param>
        /// <param name="taskName">task name</param>
        /// <param name="monikerName">the Moniker used to register host object in ROT</param>
        public void RegisterHostObject(string projectFile, string targetName, string taskName, string monikerName)
        {
            ErrorUtilities.VerifyThrowArgumentNull(projectFile, nameof(projectFile));
            ErrorUtilities.VerifyThrowArgumentNull(targetName, nameof(targetName));
            ErrorUtilities.VerifyThrowArgumentNull(taskName, nameof(taskName));
            ErrorUtilities.VerifyThrowArgumentNull(monikerName, nameof(monikerName));

            _hostObjectMap ??= new Dictionary <string, HostObjects>(StringComparer.OrdinalIgnoreCase);

            HostObjects hostObjects = GetHostObjectsFromMapByKeyOrCreateNew(projectFile);

            hostObjects.RegisterHostObject(targetName, taskName, monikerName);
        }
Beispiel #8
0
        /// <summary>
        /// Register a remote host object for a particular task/target pair.
        /// The remote host object require registered in Running Object Table(ROT) already.
        /// Overwrites any existing host object.
        ///
        /// It's caller's responsibly:
        /// To maintain the live cycle of the host object.
        /// Register and unregister from ROT.
        /// Ensure the host object has appropriate COM interface that can be used in task.
        /// </summary>
        /// <param name="monikerName">the Moniker used to register host object in ROT</param>
        public void RegisterHostObject(string projectFile, string targetName, string taskName, string monikerName)
        {
            ErrorUtilities.VerifyThrowArgumentNull(projectFile, "projectFile");
            ErrorUtilities.VerifyThrowArgumentNull(targetName, "targetName");
            ErrorUtilities.VerifyThrowArgumentNull(taskName, "taskName");
            ErrorUtilities.VerifyThrowArgumentNull(monikerName, "monikerName");

            if (Environment.Is64BitProcess)
            {
                throw new PlatformNotSupportedException("RegisterHostObject with monikerName is only supported in 32 bit");
            }

            _hostObjectMap = _hostObjectMap ?? new Dictionary <string, HostObjects>(StringComparer.OrdinalIgnoreCase);

            HostObjects hostObjects = GetHostObjectsFromMapByKeyOrCreateNew(projectFile);

            hostObjects.RegisterHostObject(targetName, taskName, monikerName);
        }
 public LogExcutorPackage(object logExecutory = null)
 {
     PackageId = "javascript_log_factory_logExecutor";
     if (logExecutory != null)
     {
         var type = logExecutory as Type;
         if (type != null)
         {
             var isTarget = typeof(ILogExecutor).IsAssignableFrom(type);
             if (!isTarget)
             {
                 throw new NotSupportedException(type.Name + " is not implements ILogExecutor");
             }
             HostObjects.Add(new HostObject
             {
                 Name   = "javascript_log_factory_logExecutor",
                 Target = Activator.CreateInstance(type)
             });
         }
         else
         {
             var isTarget = typeof(AbstractLogExcutor).IsAssignableFrom(logExecutory.GetType());
             if (!isTarget)
             {
                 throw new NotSupportedException(logExecutory.GetType().Name + " is not implements AbstractLogExcutor");
             }
             HostObjects.Add(new HostObject
             {
                 Name   = "javascript_log_factory_logExecutor",
                 Target = logExecutory
             });
         }
     }
     else
     {
         HostObjects.Add(new HostObject {
             Name = "javascript_log_factory_logExecutor", Target = new ConsoleLogExecutor()
         });
     }
 }
Beispiel #10
0
        public WebViewExcutorPackage(object webViewExecutor)
        {
            PackageId = "javascript_webview_factory_webviewExecutor";
            var type = webViewExecutor as Type;

            if (type != null)
            {
                HostObjects.Add(new HostObject
                {
                    Name   = "javascript_webview_factory_webviewExecutor",
                    Target = Activator.CreateInstance(type)
                });
            }
            else
            {
                HostObjects.Add(new HostObject
                {
                    Name   = "javascript_webview_factory_webviewExecutor",
                    Target = webViewExecutor
                });
            }
        }
Beispiel #11
0
 public SqlExecutor(object sqlExecutory)
 {
     PackageId = "javascript_sql_factory_sqlExecutor";
     if (sqlExecutory != null)
     {
         var type = sqlExecutory as Type;
         if (type != null)
         {
             var isTarget = typeof(IDbExecutor).IsAssignableFrom(type);
             if (!isTarget)
             {
                 throw new NotSupportedException(type.Name + " is not implements IDbExecutor");
             }
             HostObjects.Add(new HostObject
             {
                 Name   = "javascript_sql_factory_sqlExecutor",
                 Target = Activator.CreateInstance(type)
             });
         }
         else
         {
             var isTarget = typeof(AbstractDbDefaultExecutor).IsAssignableFrom(sqlExecutory.GetType());
             if (!isTarget)
             {
                 throw new NotSupportedException(sqlExecutory.GetType().Name + " is not implements AbstractDbDefaultExecutor");
             }
             HostObjects.Add(new HostObject
             {
                 Name   = "javascript_sql_factory_sqlExecutor",
                 Target = sqlExecutory
             });
         }
     }
     else
     {
         throw new ArgumentException("sqlExecutory");
     }
 }
Beispiel #12
0
        /// <summary>
        /// Register a host object for a particular task/target pair.
        /// Overwrites any existing host object.
        /// </summary>
        public void RegisterHostObject(string projectFile, string targetName, string taskName, ITaskHost hostObject)
        {
            ErrorUtilities.VerifyThrowArgumentNull(projectFile, "projectFile");
            ErrorUtilities.VerifyThrowArgumentNull(targetName, "targetName");
            ErrorUtilities.VerifyThrowArgumentNull(taskName, "taskName");

            // We can only set the host object to a non-null value if the affinity for the project is not out of proc, or if it is, it is only implicitly
            // out of proc, in which case it will become in-proc after this call completes.  See GetNodeAffinity.
            bool isExplicit;
            bool hasExplicitOutOfProcAffinity = (GetNodeAffinity(projectFile, out isExplicit) == NodeAffinity.OutOfProc) && (isExplicit == true);

            ErrorUtilities.VerifyThrowInvalidOperation(!hasExplicitOutOfProcAffinity || hostObject == null, "InvalidHostObjectOnOutOfProcProject");
            _hostObjectMap = _hostObjectMap ?? new Dictionary <string, HostObjects>(StringComparer.OrdinalIgnoreCase);

            HostObjects hostObjects;

            if (!_hostObjectMap.TryGetValue(projectFile, out hostObjects))
            {
                hostObjects = new HostObjects();
                _hostObjectMap[projectFile] = hostObjects;
            }

            hostObjects.RegisterHostObject(targetName, taskName, hostObject);
        }
Beispiel #13
0
        void ITranslatable.Translate(ITranslator translator)
        {
            if (translator.Mode == TranslationDirection.ReadFromStream)
            {
                int count = translator.Reader.ReadInt32();

                var hostObjectMap = new Dictionary <string, HostObjects>();
                for (int i = 0; i < count; i++)
                {
                    var pairKey = translator.Reader.ReadString();
                    var hostObjectMapPairKeyTargetName    = translator.Reader.ReadString();
                    var hostObjectMapPairKeyTaskName      = translator.Reader.ReadString();
                    var hostObjectMapPairValueMonikerName = translator.Reader.ReadString();
                    var targetTaskKey = new HostObjects.TargetTaskKey(hostObjectMapPairKeyTargetName, hostObjectMapPairKeyTaskName);
                    if (!hostObjectMap.TryGetValue(pairKey, out HostObjects hostObject))
                    {
                        hostObject             = new HostObjects();
                        hostObjectMap[pairKey] = hostObject;
                    }

                    if (!hostObject._hostObjects.ContainsKey(targetTaskKey))
                    {
                        hostObject._hostObjects.Add(targetTaskKey, new MonikerNameOrITaskHost(hostObjectMapPairValueMonikerName));
                    }
                }
                _hostObjectMap = hostObjectMap;
            }

            if (translator.Mode == TranslationDirection.WriteToStream)
            {
                if (_hostObjectMap == null)
                {
                    translator.Writer.Write(0);
                }
                else
                {
                    var count = 0;
                    foreach (var pair in _hostObjectMap)
                    {
                        foreach (var hostObjectMapPair in pair.Value._hostObjects)
                        {
                            if (hostObjectMapPair.Value.IsMoniker)
                            {
                                count++;
                            }
                        }
                    }

                    translator.Writer.Write(count);

                    foreach (var pair in _hostObjectMap)
                    {
                        foreach (var hostObjectMapPair in pair.Value._hostObjects)
                        {
                            if (hostObjectMapPair.Value.IsMoniker)
                            {
                                translator.Writer.Write(pair.Key);
                                translator.Writer.Write(hostObjectMapPair.Key._targetName);
                                translator.Writer.Write(hostObjectMapPair.Key._taskName);
                                translator.Writer.Write(hostObjectMapPair.Value.MonikerName);
                            }
                        }
                    }
                }
            }
        }