예제 #1
0
        public static IRabbitPushed CreatePushed(PublishMethod method)
        {
            RabbitObjFactory rabbitObjFactory = new RabbitObjFactory(0);
            var pushed = rabbitObjFactory.GetPushed(method);

            return(pushed);
        }
예제 #2
0
        /// <summary>
        ///     Publish website using MSDeploy or Ftp
        /// </summary>
        /// <param name="siteRoot"></param>
        /// <param name="siteName"></param>
        /// <param name="publishMethod"></param>
        /// <param name="siteRootRelativePath"></param>
        /// <param name="deleteExisting"></param>
        /// <param name="paramResolverFunc"></param>
        /// <returns></returns>
        public bool PublishWebSite(string siteRoot, string siteName, PublishMethod publishMethod = PublishMethod.MSDeploy, string siteRootRelativePath = "", bool deleteExisting = true, Func <string, string> paramResolverFunc = null)
        {
            if (!Directory.Exists(siteRoot))
            {
                throw new DirectoryNotFoundException(string.Format("Publishing error: site directory '{0}' does not exist.", siteRoot));
            }

            var result = true;

            TestEasyLog.Instance.Info(string.Format("Publishing web site '{0}'", siteName));

            var publishProfile = GetPublishingProfile(siteName, publishMethod);

            switch (publishMethod)
            {
            case PublishMethod.MSDeploy:
                WebDeployHelper.DeployWebSite(siteRoot, siteName, publishProfile.GetWebDeployUrl(), publishProfile.UserName, publishProfile.UserPassword, deleteExisting, paramResolverFunc);
                break;

            case PublishMethod.Ftp:
                result = FtpHelper.Authorize(publishProfile.UserName, publishProfile.UserPassword)
                         .UploadDir(siteRoot, publishProfile.PublishUrl, siteRootRelativePath);
                break;

            default:
                throw new Exception(string.Format("Deployment method '{0}' is not supported.", publishMethod));
            }

            return(result);
        }
예제 #3
0
        public static IConsumer CreateConsumer(PublishMethod method)
        {
            RabbitObjFactory rabbitObjFactory = new RabbitObjFactory(1);

            var consumer = rabbitObjFactory.GetConsumer(method);

            return(consumer);
        }
예제 #4
0
        /// <summary>
        ///     Publishes the specified action.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="publishMethod">The publishMethod.</param>
        /// <param name="options">The options.</param>
        /// <param name="publishToOriginator">if set to <c>true</c>, the message will be published to the originator also.</param>
        /// <param name="mergeAction">The merge action.</param>
        public void Publish(T message, PublishMethod publishMethod, PublishOptions options = PublishOptions.None, bool publishToOriginator = false, Action <T, T> mergeAction = null)
        {
            Publish_Impl((msg, opt, originator) =>
            {
                var pubResult = PublishMessage((subscriber, bytes, flags) =>
                {
                    subscriber.Publish(ChannelName, bytes, flags);
                    return(null);
                }, message, options, publishToOriginator);

                return(pubResult);
            }, message, publishMethod, options, publishToOriginator, mergeAction);
        }
예제 #5
0
        /// <summary>
        ///     Publishes the message asynchronously.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="publishMethod">The publish method.</param>
        /// <param name="options">The options.</param>
        /// <param name="publishToOriginator">if set to <c>true</c>, the message will be published to the originator also.</param>
        /// <param name="mergeAction">The merge action.</param>
        /// <returns></returns>
        public Task <long> PublishAsync(T message, PublishMethod publishMethod, PublishOptions options = PublishOptions.None, bool publishToOriginator = false, Action <T, T> mergeAction = null)
        {
            var result = Publish_Impl((msg, opt, originator) =>
            {
                var pubResult = PublishMessage((subscriber, bytes, flags) =>
                {
                    var innerResult = subscriber.PublishAsync(ChannelName, bytes, flags);
                    return(innerResult);
                }, message, options, publishToOriginator) ?? Task.FromResult <long>(0);

                return(pubResult);
            }, message, publishMethod, options, publishToOriginator, mergeAction) ?? Task.FromResult <long>(0);

            return(result);
        }
예제 #6
0
 public static void Publish(TMessage message, PublishMethod method)
 {
     switch (method)
     {
         case PublishMethod.SyncSameThread:
             DoPublishSynchronouslyOnSameThread(message);
             break;
         case PublishMethod.CreateAndStartTask:
             DoPublishAsynchronouslyByStartingNewTask(message);
             break;
         case PublishMethod.BeginInvoke:
             DoPublishAsynchronouslyByBeginInvoke(message);
             break;
     }
 }
예제 #7
0
        /// <summary>
        ///     Publish website using MSDeploy or Ftp
        /// </summary>
        /// <param name="file"></param>
        /// <param name="siteName"></param>
        /// <param name="publishMethod"></param>
        /// <param name="siteRootRelativePath"></param>
        /// <param name="deleteExisting"></param>
        /// <param name="paramResolverFunc"></param>
        /// <returns></returns>
        public bool PublishFile(string file, string siteName, PublishMethod publishMethod = PublishMethod.MSDeploy, string siteRootRelativePath = "", bool deleteExisting = true, Func <string, string> paramResolverFunc = null)
        {
            if (!File.Exists(file))
            {
                throw new FileNotFoundException(string.Format("Publishing error: file '{0}' does not exist.", file));
            }

            var result           = true;
            var publishProfile   = GetPublishingProfile(siteName, publishMethod);
            var fileRelativePath = siteName + "/";

            if (!string.IsNullOrEmpty(siteRootRelativePath))
            {
                fileRelativePath += (siteRootRelativePath + "/");
            }

            fileRelativePath += Path.GetFileName(file);

            TestEasyLog.Instance.Info(string.Format("Publishing file '{0}' to web site '{1}'", file, siteName));

            switch (publishMethod)
            {
            case PublishMethod.MSDeploy:
                WebDeployHelper.DeployFile(file, fileRelativePath, publishProfile.GetWebDeployUrl(), publishProfile.UserName, publishProfile.UserPassword, deleteExisting, paramResolverFunc);
                break;

            case PublishMethod.Ftp:
                result = FtpHelper.Authorize(publishProfile.UserName, publishProfile.UserPassword)
                         .UploadFile(file, Path.Combine(publishProfile.PublishUrl, fileRelativePath));
                break;

            default:
                throw new Exception(string.Format("Deployment method '{0}' is not supported.", publishMethod));
            }

            return(result);
        }
예제 #8
0
 /// <summary>
 /// Publishes a message/event to subscribers using the <see cref="PublishMethod"/> specified
 /// </summary>
 /// <typeparam name="TMessage">The type of message/event to publish</typeparam>
 /// <param name="message">The message/event to publish</param>
 /// <param name="method">The <see cref="PublishMethod"/> to use when publishing the message to subscribers</param>
 public void Publish<TMessage>(TMessage message, PublishMethod method)
 {
     MessageDistributor<TMessage>.Publish(message, method);
 }
예제 #9
0
 /// <summary>
 ///     Get publishing profiles for MSDeploy and Ftp
 /// </summary>
 /// <param name="webSpaceName"></param>
 /// <param name="siteName"></param>
 /// <param name="publishMethod"></param>
 /// <returns></returns>
 public WebSiteGetPublishProfileResponse.PublishProfile GetPublishingProfile(string webSpaceName, string siteName, PublishMethod publishMethod = PublishMethod.MSDeploy)
 {
     TestEasyLog.Instance.Info(string.Format("Getting publishing profile for web site '{0}'", siteName));
     return(GetPublishingProfiles(webSpaceName, siteName).FirstOrDefault(p => p.PublishMethod.Equals(publishMethod.ToString(), StringComparison.OrdinalIgnoreCase)));
 }
예제 #10
0
 /// <summary>
 ///     Get publishing profiles for MSDeploy and Ftp
 /// </summary>
 /// <param name="siteName"></param>
 /// <param name="publishMethod"></param>
 /// <returns></returns>
 public WebSiteGetPublishProfileResponse.PublishProfile GetPublishingProfile(string siteName, PublishMethod publishMethod = PublishMethod.MSDeploy)
 {
     return(GetPublishingProfile(_webSpace, siteName, publishMethod));
 }
예제 #11
0
        /// <summary>
        ///     Publish directory using MSDeploy or Ftp
        /// </summary>
        /// <param name="directory"></param>
        /// <param name="siteName"></param>
        /// <param name="publishMethod"></param>
        /// <param name="siteRootRelativePath"></param>
        /// <param name="deleteExisting"></param>
        /// <param name="paramResolverFunc"></param>
        /// <returns></returns>
        public bool PublishDirectory(string directory, string siteName, PublishMethod publishMethod = PublishMethod.MSDeploy, string siteRootRelativePath = "",
                                     bool deleteExisting = true, Func<string, string> paramResolverFunc = null)
        {
            if (!Directory.Exists(directory))
            {
                throw new DirectoryNotFoundException(string.Format("Publishing error: directory '{0}' does not exist.", directory));
            }

            var result = true;

            var levelUpRequested = 0;
            if (!string.IsNullOrEmpty(siteRootRelativePath))
            {
                // remove .., / and \ from relative path 
                siteRootRelativePath = siteRootRelativePath.Trim('\\').Trim('/');
                if (siteRootRelativePath.StartsWith(".."))
                {
                    while (siteRootRelativePath.StartsWith("..") || siteRootRelativePath.StartsWith("/") ||
                           siteRootRelativePath.StartsWith("\\"))
                    {
                        levelUpRequested++;
                        siteRootRelativePath = siteRootRelativePath.Trim('.').Trim('\\').Trim('/');
                    }

                    siteRootRelativePath = siteRootRelativePath.Trim('.');

                    if (levelUpRequested > 2)
                    {
                        levelUpRequested = 2;
                    }
                }
            }

            var publishProfile = GetPublishingProfile(siteName, publishMethod);

            switch (publishMethod)
            {
                case PublishMethod.MSDeploy:
                {
                    var dirRelativePath = siteName + "/";
                    if (!string.IsNullOrEmpty(siteRootRelativePath))
                    {
                        dirRelativePath += (siteRootRelativePath + "/");
                    }

                    var destinationUrl = publishProfile.GetWebDeployUrl();
                    TestEasyLog.Instance.Info(string.Format("Publishing directory '{0}' to website path '{1}'", directory, destinationUrl));

                    WebDeployHelper.DeployDirectory(directory, dirRelativePath, destinationUrl, publishProfile.UserName,
                        publishProfile.UserPassword, deleteExisting, paramResolverFunc);
                    break;
                }
                case PublishMethod.Ftp:
                {
                    var publishUrl = publishProfile.PublishUrl;
                    while (levelUpRequested > 0)
                    {
                        var index = publishUrl.LastIndexOf('/');
                        publishUrl = publishUrl.Substring(0, index);
                        levelUpRequested--;
                    }

                    result = FtpHelper.Authorize(publishProfile.UserName, publishProfile.UserPassword)
                        .UploadDir(directory, publishUrl, siteRootRelativePath);
                    break;
                }
                default:
                    throw new Exception(string.Format("Deployment method '{0}' is not supported.", publishMethod));
            }

            return result;
        }
예제 #12
0
        /// <summary>
        ///     Publish website using MSDeploy or Ftp
        /// </summary>
        /// <param name="file"></param>
        /// <param name="siteName"></param>
        /// <param name="publishMethod"></param>
        /// <param name="siteRootRelativePath"></param>
        /// <param name="deleteExisting"></param>
        /// <param name="paramResolverFunc"></param>
        /// <returns></returns>
        public bool PublishFile(string file, string siteName, PublishMethod publishMethod = PublishMethod.MSDeploy, string siteRootRelativePath = "", bool deleteExisting = true, Func<string, string> paramResolverFunc = null)
        {
            if (!File.Exists(file))
            {
                throw new FileNotFoundException(string.Format("Publishing error: file '{0}' does not exist.", file));
            }

            var result = true;
            var publishProfile = GetPublishingProfile(siteName, publishMethod);
            var fileRelativePath = siteName + "/";
            if (!string.IsNullOrEmpty(siteRootRelativePath))
            {
                fileRelativePath += (siteRootRelativePath + "/");
            }

            fileRelativePath += Path.GetFileName(file);

            TestEasyLog.Instance.Info(string.Format("Publishing file '{0}' to web site '{1}'", file, siteName));           

            switch (publishMethod)
            {
                case PublishMethod.MSDeploy:
                    WebDeployHelper.DeployFile(file, fileRelativePath, publishProfile.GetWebDeployUrl(), publishProfile.UserName, publishProfile.UserPassword, deleteExisting, paramResolverFunc);
                    break;
                case PublishMethod.Ftp:
                    result = FtpHelper.Authorize(publishProfile.UserName, publishProfile.UserPassword)
                             .UploadFile(file, Path.Combine(publishProfile.PublishUrl, fileRelativePath));
                    break;
                default:
                    throw new Exception(string.Format("Deployment method '{0}' is not supported.", publishMethod));
            }

            return result;
        }
예제 #13
0
        /// <summary>
        ///     Publish website using MSDeploy or Ftp
        /// </summary>
        /// <param name="siteRoot"></param>
        /// <param name="siteName"></param>
        /// <param name="publishMethod"></param>
        /// <param name="siteRootRelativePath"></param>
        /// <param name="deleteExisting"></param>
        /// <param name="paramResolverFunc"></param>
        /// <returns></returns>
        public bool PublishWebSite(string siteRoot, string siteName, PublishMethod publishMethod = PublishMethod.MSDeploy, string siteRootRelativePath = "", bool deleteExisting = true, Func<string, string> paramResolverFunc = null)
        {
            if (!Directory.Exists(siteRoot))
            {
                throw new DirectoryNotFoundException(string.Format("Publishing error: site directory '{0}' does not exist.", siteRoot));
            }

            var result = true;
            TestEasyLog.Instance.Info(string.Format("Publishing web site '{0}'", siteName));

            var publishProfile = GetPublishingProfile(siteName, publishMethod);
            switch (publishMethod)
            {
                case PublishMethod.MSDeploy:
                    WebDeployHelper.DeployWebSite(siteRoot, siteName, publishProfile.GetWebDeployUrl(), publishProfile.UserName, publishProfile.UserPassword, deleteExisting, paramResolverFunc);
                    break;
                case PublishMethod.Ftp:
                    result = FtpHelper.Authorize(publishProfile.UserName, publishProfile.UserPassword)
                             .UploadDir(siteRoot, publishProfile.PublishUrl, siteRootRelativePath);
                    break;
                default:
                    throw new Exception(string.Format("Deployment method '{0}' is not supported.", publishMethod));
            }

            return result;
        }
예제 #14
0
 /// <summary>
 ///     Get publishing profiles for MSDeploy and Ftp
 /// </summary>
 /// <param name="webSpaceName"></param>
 /// <param name="siteName"></param>
 /// <param name="publishMethod"></param>
 /// <returns></returns>
 public WebSiteGetPublishProfileResponse.PublishProfile GetPublishingProfile(string webSpaceName, string siteName, PublishMethod publishMethod = PublishMethod.MSDeploy)
 {
     TestEasyLog.Instance.Info(string.Format("Getting publishing profile for web site '{0}'", siteName));
     return GetPublishingProfiles(webSpaceName, siteName).FirstOrDefault(p => p.PublishMethod.Equals(publishMethod.ToString(), StringComparison.OrdinalIgnoreCase));
 }
예제 #15
0
 /// <summary>
 ///     Get publishing profiles for MSDeploy and Ftp
 /// </summary>
 /// <param name="siteName"></param>
 /// <param name="publishMethod"></param>
 /// <returns></returns>
 public WebSiteGetPublishProfileResponse.PublishProfile GetPublishingProfile(string siteName, PublishMethod publishMethod = PublishMethod.MSDeploy)
 {
     return GetPublishingProfile(_webSpace, siteName, publishMethod);
 }
예제 #16
0
 /// <summary>
 /// Creates a new MessageBus
 /// </summary>
 public MessageBus()
 {
     DefaultPublishMethod = PublishMethod.BeginInvoke;
 }
예제 #17
0
            public System.Threading.Tasks.Task <long> PublishAsync(T message, PublishMethod publishMethod, PublishOptions options = PublishOptions.None, bool publishToOriginator = false, Action <T, T> mergeAction = null)
            {
                PublishedMessages.Add(message);

                return(Task.FromResult <long>(0));
            }
예제 #18
0
 public PublishAttribute(PublishMethod method)
     : base()
 {
     _method = method;
 }
예제 #19
0
        /// <summary>
        ///     Publish_s the implementation.
        /// </summary>
        /// <param name="callback">The callback.</param>
        /// <param name="message">The message.</param>
        /// <param name="publishMethod">The publish method.</param>
        /// <param name="options">The options.</param>
        /// <param name="publishToOriginator">if set to <c>true</c> [publish to originator].</param>
        /// <param name="mergeAction">The merge action.</param>
        /// <returns></returns>
        private Task <long> Publish_Impl(Func <T, PublishOptions, bool, Task <long> > callback, T message, PublishMethod publishMethod, PublishOptions options = PublishOptions.None, bool publishToOriginator = false, Action <T, T> mergeAction = null)
        {
            if (Equals(message, default(T)))
            {
                return(null);
            }

            if (Suppression.IsActive( ))
            {
                return(null);
            }

            DeferredChannelMessageContext deferredMessageContext = null;

            try
            {
                /////
                // If running in a delayed context, use the current message store.
                /////
                if (publishMethod == PublishMethod.Deferred)
                {
                    deferredMessageContext = DeferredChannelMessageContext.GetContext( );

                    if (deferredMessageContext.ContextType != ContextType.Attached && !DeferredChannelMessageContext.SuppressNoContextWarning)
                    {
                        EventLog.Application.WriteWarning("Channel {0} has been created with PublishMethod.Deferred with no DeferredChannelMessageContext set. Messages will be sent immediately. Either set a DeferredChannelMessageContext or publish the message with PublishMethod.Immediate.", ChannelName);
                    }
                }

                if (deferredMessageContext != null &&
                    deferredMessageContext.ContextType == ContextType.Attached)
                {
                    deferredMessageContext.AddOrUpdateMessage(ChannelName, message, mergeAction);
                }
                else
                {
                    return(callback(message, options, publishToOriginator));
                }
            }
            finally
            {
                if (deferredMessageContext != null)
                {
                    deferredMessageContext.Dispose( );
                }
            }

            return(null);
        }
예제 #20
0
 internal IRabbitPushed GetPushed(PublishMethod method)
 {
     return(_dicPubshed[method]);
 }
예제 #21
0
 internal IConsumer GetConsumer(PublishMethod method)
 {
     return(_dicConsumer[method]);
 }
예제 #22
0
        /// <summary>
        ///     Publish directory using MSDeploy or Ftp
        /// </summary>
        /// <param name="directory"></param>
        /// <param name="siteName"></param>
        /// <param name="publishMethod"></param>
        /// <param name="siteRootRelativePath"></param>
        /// <param name="deleteExisting"></param>
        /// <param name="paramResolverFunc"></param>
        /// <returns></returns>
        public bool PublishDirectory(string directory, string siteName, PublishMethod publishMethod = PublishMethod.MSDeploy, string siteRootRelativePath = "",
                                     bool deleteExisting = true, Func <string, string> paramResolverFunc = null)
        {
            if (!Directory.Exists(directory))
            {
                throw new DirectoryNotFoundException(string.Format("Publishing error: directory '{0}' does not exist.", directory));
            }

            var result = true;

            var levelUpRequested = 0;

            if (!string.IsNullOrEmpty(siteRootRelativePath))
            {
                // remove .., / and \ from relative path
                siteRootRelativePath = siteRootRelativePath.Trim('\\').Trim('/');
                if (siteRootRelativePath.StartsWith(".."))
                {
                    while (siteRootRelativePath.StartsWith("..") || siteRootRelativePath.StartsWith("/") ||
                           siteRootRelativePath.StartsWith("\\"))
                    {
                        levelUpRequested++;
                        siteRootRelativePath = siteRootRelativePath.Trim('.').Trim('\\').Trim('/');
                    }

                    siteRootRelativePath = siteRootRelativePath.Trim('.');

                    if (levelUpRequested > 2)
                    {
                        levelUpRequested = 2;
                    }
                }
            }

            var publishProfile = GetPublishingProfile(siteName, publishMethod);

            switch (publishMethod)
            {
            case PublishMethod.MSDeploy:
            {
                var dirRelativePath = siteName + "/";
                if (!string.IsNullOrEmpty(siteRootRelativePath))
                {
                    dirRelativePath += (siteRootRelativePath + "/");
                }

                var destinationUrl = publishProfile.GetWebDeployUrl();
                TestEasyLog.Instance.Info(string.Format("Publishing directory '{0}' to website path '{1}'", directory, destinationUrl));

                WebDeployHelper.DeployDirectory(directory, dirRelativePath, destinationUrl, publishProfile.UserName,
                                                publishProfile.UserPassword, deleteExisting, paramResolverFunc);
                break;
            }

            case PublishMethod.Ftp:
            {
                var publishUrl = publishProfile.PublishUrl;
                while (levelUpRequested > 0)
                {
                    var index = publishUrl.LastIndexOf('/');
                    publishUrl = publishUrl.Substring(0, index);
                    levelUpRequested--;
                }

                result = FtpHelper.Authorize(publishProfile.UserName, publishProfile.UserPassword)
                         .UploadDir(directory, publishUrl, siteRootRelativePath);
                break;
            }

            default:
                throw new Exception(string.Format("Deployment method '{0}' is not supported.", publishMethod));
            }

            return(result);
        }
예제 #23
0
 public void Publish(T message, PublishMethod publishMethod, PublishOptions options = PublishOptions.None, bool publishToOriginator = false, Action <T, T> mergeAction = null)
 {
     PublishedMessages.Add(message);
 }