Exemple #1
0
        public WFTarget(WFTargetData wftargetdata, string assemblycache)
        {
            if (WFTarget.TargetQueues == null)
                WFTarget.TargetQueues = new Dictionary<string, IWFMessageQueue>();

            if (wftargetdata.AssemblyType != string.Empty && wftargetdata.AssemblyDll != string.Empty)
            {
                this.AssemblyPath = Directory.GetCurrentDirectory();

            //				if (wftargetdata.AssemblyType != "ProcessorData" && !string.IsNullOrEmpty(assemblycache))
                if (!string.IsNullOrEmpty(assemblycache))
                    this.AssemblyPath = string.Format(@"{0}\{1}", assemblycache, Path.GetFileNameWithoutExtension(wftargetdata.AssemblyDll));

                Assembly assembly = string.IsNullOrEmpty(wftargetdata.AssemblyDll) ? Assembly.GetExecutingAssembly() : Assembly.LoadFrom(this.AssemblyPath + @"\" + wftargetdata.AssemblyDll);
                if (assembly != null)
                {
                    //The AssemblyResolve event is called when the common language runtime tries to bind to the assembly and fails.
                    AppDomain currentDomain = AppDomain.CurrentDomain;
                    currentDomain.AssemblyResolve += new ResolveEventHandler(currentDomain_AssemblyResolve);
                    try
                    {
                        this.AssemblyType = assembly.GetType(assembly.GetTypes().Where(x => (x.Name.ToUpper() == wftargetdata.AssemblyType.ToUpper()) || (x.FullName.ToUpper() == wftargetdata.AssemblyType.ToUpper())).Select(x => x.FullName).FirstOrDefault());
                        this.AssemblyTypeInstance = assembly.CreateInstance(this.AssemblyType.FullName);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("", ex);
                    }
                    finally
                    {
                        currentDomain.AssemblyResolve -= new ResolveEventHandler(currentDomain_AssemblyResolve);
                    }
                }
                else
                    throw new Exception("");
            }

            if (wftargetdata.QueueName != string.Empty)
            {
                string ip = string.Empty;
                if (WFUtilities.SetHostAndIPAddress(wftargetdata.QueueHost, ref ip))
                {
                    Type type = null;
                    int port = 0;
                    WFMessageQueueType publisherorconsumer = WFMessageQueueType.None;

                    switch (wftargetdata.QueueType)
                    {
                        case ".netqueue":
                            type = typeof(System.Collections.Queue);
                            break;

                        case "msmq":
                            type = typeof(MessageQueue);
                            break;

                        case "rabbitmq":
                            type = typeof(QueueingBasicConsumer);
                            port = 5672;
                            publisherorconsumer = WFMessageQueueType.Publisher;
                            if (this is WFSrc)
                                publisherorconsumer = WFMessageQueueType.Consumer;
                            break;

                        default:
                            break;
                    }

                    if (WFTarget.TargetQueues.ContainsKey(wftargetdata.QueueName))
                        this.MessageQueue = WFTarget.TargetQueues[wftargetdata.QueueName];
                    else
                    {
                        Type genericqueuetype = typeof(IWFMessageQueueFactory<,>).MakeGenericType(new[] { type, this.AssemblyType == null ? typeof(ProcessorData) : this.AssemblyType });
                        this.MessageQueue = (IWFMessageQueue)genericqueuetype.GetMethod(WFTarget.CreateWFMessageQueue, new object[] { ip, port, wftargetdata.QueueName, publisherorconsumer }.Select(p => p.GetType()).ToArray()).Invoke(null, new object[] { ip, port, wftargetdata.QueueName, publisherorconsumer });
                        WFTarget.TargetQueues[wftargetdata.QueueName] = this.MessageQueue;
                    }
                    //					genericqueuetype = typeof(WFMessageQueue<>).MakeGenericType(new[] { this.AssemblyType });
                    //					this.GenericQueue = Activator.CreateInstance(genericqueuetype, new object[] { @"FormatName:Direct=TCP:" + ip + @"\Private$\" + queuename });
                    //					this.MessageQueue = (System.Messaging.MessageQueue)genericqueuetype.GetProperty("MessageQueue").GetGetMethod().Invoke(this.GenericQueue, new object[0]);
                }
                else
                    throw new Exception("");
            }
        }
Exemple #2
0
        public WFTarget(WFTargetData wftargetdata, string assemblycache)
        {
            if (WFTarget.TargetQueues == null)
            {
                WFTarget.TargetQueues = new Dictionary <string, IWFMessageQueue>();
            }

            if (wftargetdata.AssemblyType != string.Empty && wftargetdata.AssemblyDll != string.Empty)
            {
                this.AssemblyPath = Directory.GetCurrentDirectory();

//				if (wftargetdata.AssemblyType != "ProcessorData" && !string.IsNullOrEmpty(assemblycache))
                if (!string.IsNullOrEmpty(assemblycache))
                {
                    this.AssemblyPath = string.Format(@"{0}\{1}", assemblycache, Path.GetFileNameWithoutExtension(wftargetdata.AssemblyDll));
                }

                Assembly assembly = string.IsNullOrEmpty(wftargetdata.AssemblyDll) ? Assembly.GetExecutingAssembly() : Assembly.LoadFrom(this.AssemblyPath + @"\" + wftargetdata.AssemblyDll);
                if (assembly != null)
                {
                    //The AssemblyResolve event is called when the common language runtime tries to bind to the assembly and fails.
                    AppDomain currentDomain = AppDomain.CurrentDomain;
                    currentDomain.AssemblyResolve += new ResolveEventHandler(currentDomain_AssemblyResolve);
                    try
                    {
                        this.AssemblyType         = assembly.GetType(assembly.GetTypes().Where(x => (x.Name.ToUpper() == wftargetdata.AssemblyType.ToUpper()) || (x.FullName.ToUpper() == wftargetdata.AssemblyType.ToUpper())).Select(x => x.FullName).FirstOrDefault());
                        this.AssemblyTypeInstance = assembly.CreateInstance(this.AssemblyType.FullName);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("", ex);
                    }
                    finally
                    {
                        currentDomain.AssemblyResolve -= new ResolveEventHandler(currentDomain_AssemblyResolve);
                    }
                }
                else
                {
                    throw new Exception("");
                }
            }

            if (wftargetdata.QueueName != string.Empty)
            {
                string ip = string.Empty;
                if (WFUtilities.SetHostAndIPAddress(wftargetdata.QueueHost, ref ip))
                {
                    Type type = null;
                    int  port = 0;
                    WFMessageQueueType publisherorconsumer = WFMessageQueueType.None;

                    switch (wftargetdata.QueueType)
                    {
                    case ".netqueue":
                        type = typeof(System.Collections.Queue);
                        break;

                    case "msmq":
                        type = typeof(MessageQueue);
                        break;

                    case "rabbitmq":
                        type = typeof(QueueingBasicConsumer);
                        port = 5672;
                        publisherorconsumer = WFMessageQueueType.Publisher;
                        if (this is WFSrc)
                        {
                            publisherorconsumer = WFMessageQueueType.Consumer;
                        }
                        break;

                    default:
                        break;
                    }

                    if (WFTarget.TargetQueues.ContainsKey(wftargetdata.QueueName))
                    {
                        this.MessageQueue = WFTarget.TargetQueues[wftargetdata.QueueName];
                    }
                    else
                    {
                        Type genericqueuetype = typeof(IWFMessageQueueFactory <,>).MakeGenericType(new[] { type, this.AssemblyType == null ? typeof(ProcessorData) : this.AssemblyType });
                        this.MessageQueue = (IWFMessageQueue)genericqueuetype.GetMethod(WFTarget.CreateWFMessageQueue, new object[] { ip, port, wftargetdata.QueueName, publisherorconsumer }.Select(p => p.GetType()).ToArray()).Invoke(null, new object[] { ip, port, wftargetdata.QueueName, publisherorconsumer });
                        WFTarget.TargetQueues[wftargetdata.QueueName] = this.MessageQueue;
                    }
                    //					genericqueuetype = typeof(WFMessageQueue<>).MakeGenericType(new[] { this.AssemblyType });
                    //					this.GenericQueue = Activator.CreateInstance(genericqueuetype, new object[] { @"FormatName:Direct=TCP:" + ip + @"\Private$\" + queuename });
                    //					this.MessageQueue = (System.Messaging.MessageQueue)genericqueuetype.GetProperty("MessageQueue").GetGetMethod().Invoke(this.GenericQueue, new object[0]);
                }
                else
                {
                    throw new Exception("");
                }
            }
        }