public void Detach(IPublish pub) { if (pub != null) { pub.PublishArgs -= eventSubscribeArgs; } }
private static void CreateProxy() { string endpointAddressInString = Common.Config.PublisherEndpointAddres; EndpointAddress endpointAddress = new EndpointAddress(endpointAddressInString); NetTcpBinding netTcpBinding = new NetTcpBinding(); _proxy = ChannelFactory<IPublish>.CreateChannel(netTcpBinding, endpointAddress); }
public PublishChanges(IPublish publisher, ISave nextSave, IDelete nextDelete, IGetById getter) { this.publisher = publisher; this.nextSave = nextSave; this.nextDelete = nextDelete; this.getter = getter; }
/// <summary> /// Publishes an <see cref="IPublish{T}" /> to all subscribed <see cref="IPeer" />s. /// </summary> public void Publish(IPublish <Message> publish) { if (publish == null) { throw new ArgumentNullException("publish"); } // If the publish is done inside a callback handler we know it's a request/response scheme // and therefore the PubSubContext will be initialized. if (PubSubContext.IsInitialized) { string callerId = PubSubContext.Current.Publish.Headers.Get("callerId"); if (!string.IsNullOrEmpty(callerId)) { publish.Headers.Add("callerId", callerId); } } EventQueue.RaiseEvent(new PublishEvent { PipelineArgs = new PublishArgs { Peer = this, Publish = publish } }); }
public MainProccess(IConvert convert, IPublish publish, IValidate validate, IProcess process) { _validate = validate; _convert = convert; _publish = publish; _process = process; }
private void WorkMethod(int taskindex, int threadindex) { string Title = string.Empty, Content = string.Empty; StringBuilder sbContent = new StringBuilder(); if (Model != null) { IPublish iPublish = Utility.GetIPublishByName(Model.PublishName); iPublish.Publish_Init(Model.WebSiteUrl, Model.WebSiteLoginUrl, Model.LoginUserName, Model.LoginUserPwd, 0, string.Empty); iPublish.Publish_OutResult = OPR_SendData; string[] files = Directory.GetFiles(Model.FileSourcePath, "*.html"); int lLen = files.Length; for (int i = 0; i < lLen; i++) { if (IsOpen) { IsOpen = false; try { string file = files[i]; FileInfo fiFile = new FileInfo(file); Title = fiFile.Name.Replace(fiFile.Extension, ""); int l = fiFile.Name.LastIndexOf("_"); if (l > -1) { Title = Title.Substring(0, l); } StreamReader sr = new StreamReader(file, Encoding.Default); sbContent.Append(sr.ReadToEnd()); sr.Close(); if (sbContent.Length >= 300) { //发布文章 ModelGatherItem mGatherItem = new ModelGatherItem(); mGatherItem.Title = Title; mGatherItem.Content = sbContent.ToString(); ModelClassItem mClassList = new ModelClassItem(); mClassList.ClassID = "1"; mClassList.ClassName = "美容知识"; iPublish.Publish_PostData(mGatherItem, mClassList); } sbContent.Remove(0, sbContent.Length); // File.Delete(file); Thread.Sleep(1000);//这个可以自定义时间 } catch (Exception ex) { Log4Helper.Write(LogLevel.Error, "文件发布错误!", ex); continue; } } else { Thread.Sleep(5000); } } } }
/// <summary> /// 加载插件 /// </summary> public static void LoadAllDlls() { #region 发布 try { ListIPublish.Clear(); string[] publishFiles = Directory.GetFiles(PublishModulesPath, "*Modules.dll"); foreach (string str2 in publishFiles) { try { Assembly assembly = Assembly.LoadFrom(str2); FileInfo fi = new FileInfo(str2); string ff = fi.Name.Replace(fi.Extension, ""); ff = ff.Replace("V5.", ""); IPublish item = (IPublish)Activator.CreateInstance(assembly.GetType("V5.DataPlugins." + ff)); ListIPublish.Add(item); continue; } catch (Exception ex) { Log4Helper.Write(LogLevel.Error, ex); continue; } } } catch (Exception ex) { Log4Helper.Write(LogLevel.Error, ex); } #endregion #region PublishContent try { ListIPublishContent.Clear(); string[] publiscContentDirs = Directory.GetDirectories(BaseDirectory + "\\Plugins\\V5.DataPublish.PublishContent\\"); foreach (string dir in publiscContentDirs) { string[] filess = Directory.GetFiles(dir, "*PublishContent.dll"); try { if (filess.Length == 0) { break; } string file = filess[0]; Assembly assembly = Assembly.LoadFrom(file); FileInfo fi = new FileInfo(file); string ff = fi.Name.Replace(fi.Extension, ""); ff = ff.Replace("V5.", ""); IPublishContent item = (IPublishContent)Activator.CreateInstance(assembly.GetType("V5.DataPlugins." + ff)); ListIPublishContent.Add(item); } catch (Exception ex) { Log4Helper.Write(LogLevel.Error, ex); continue; } } } catch (Exception ex) { Log4Helper.Write(LogLevel.Error, ex); } #endregion }
static private void CreateProxy() { string endpointAddressInString = Common.Config.PublisherEndpointAddres; EndpointAddress endpointAddress = new EndpointAddress(endpointAddressInString); NetTcpBinding netTcpBinding = new NetTcpBinding(); _proxy = ChannelFactory <IPublish> .CreateChannel(netTcpBinding, endpointAddress); }
public CommandHandler(IUserList userList, IPublish publish, IReading reading, IFollow follow, IWall wall) { _userList = userList; _publish = publish; _reading = reading; _follow = follow; _wall = wall; }
public void Execute(CallbackArgs args) { IPublish <Message> response = args.Publish; ISubscription subscription = args.Peer.GetSubscription(response.Key); if (subscription == null) { return; } ICachingOptions cachingOptions = subscription.CachingOptions; if (cachingOptions == null || !cachingOptions.EnableCaching) { return; } if (!cachingOptions.HasCacheKey) { return; } string callbackKey = string.Format("callback#{0}#{1}", args.Peer.Node.Contact.NodeId, response.Key); string cacheKey = callbackKey; if (string.Equals(cachingOptions.Key, response.Key)) { string extraKey = cachingOptions.GetCacheKey(response.Message); if (!string.IsNullOrEmpty(extraKey)) { cacheKey = string.Format("{0}#{1}", callbackKey, extraKey); } } CacheManager.Add(cacheKey, args.Publish.Message, cachingOptions); // Request response scheme if (string.Equals(subscription.Key, cachingOptions.Key)) { return; } IPublish <Message> request = CacheManager.Get <IPublish <Message> >(string.Format("publish#{0}#{1}", args.Peer.Node.Contact.NodeId, cachingOptions.Key)); if (request != null && string.Equals(request.Key, cachingOptions.Key)) { string extraKey = cachingOptions.GetCacheKey(request.Message); if (!string.IsNullOrEmpty(extraKey)) { cacheKey = string.Format("{0}#{1}", callbackKey, extraKey); CacheManager.Add(cacheKey, args.Publish.Message, cachingOptions); } } }
public async Task PublisherSimplySendsWithoutQueueReturnsFailure() { IBunny bunny = Bunny.ConnectSingle(ConnectSimple.BasicAmqp); IPublish <TestMessage> publisher = bunny.Publisher <TestMessage>(Exchange); OperationResult <TestMessage> result = await publisher.SendAsync(new TestMessage()); Assert.True(result.IsSuccess); bunny.Dispose(); }
public void Must_be_able_to_publish_a_message() { _userList = new UserList(); _userList.AddUser("Alice"); _sut = new Publish(_userList); _sut.PublishMessage(usersMessage, "Alice"); var user = _userList.GetUser("Alice"); Assert.AreEqual(user._messages.Count, 1); }
/// <summary> /// Builds the current <see cref="PubSubContext" /> using information from the specified <see cref="IPublish{T}" />. /// </summary> /// <param name="publish"></param> internal static void BuildContext(IPublish <Message> publish) { try { Initialize(); Current.Publish = publish; } catch (Exception ex) { Log.Error(ex); } }
public static void RemoveSubscriber(String topicName, IPublish subscriberCallbackReference) { lock (typeof(Filter)) { if (SubscribersList.ContainsKey(topicName)) { if (SubscribersList[topicName].Contains(subscriberCallbackReference)) { SubscribersList[topicName].Remove(subscriberCallbackReference); } } } }
public async Task ForceCreatesTheExchangeIfNotExists() { IBunny bunny = Bunny.ConnectSingle(ConnectSimple.BasicAmqp); IPublish <TestMessage> publisher = bunny.Publisher <TestMessage>("test-exchange"); OperationResult <TestMessage> result = await publisher.SendAsync(new TestMessage(), force : true); Assert.True(result.IsSuccess); bool removed_exchange = await bunny.Setup().DeleteExchangeAsync("test-exchange", force: true); Assert.True(removed_exchange); bunny.Dispose(); }
static public void RemoveSubscriber(String topicName, IPublish subscriberCallbackReference) { lock (typeof(Filter)) { if (SubscribersList.ContainsKey(topicName)) { if (SubscribersList[topicName].Contains(subscriberCallbackReference)) { SubscribersList[topicName].Remove(subscriberCallbackReference); } } } }
/// <summary> /// Is invoked when a relevant <see cref="Message" /> is published. /// </summary> public void Callback(IPublish <Message> publish) { if (publish == null) { throw new ArgumentNullException("publish"); } EventQueue.RaiseEvent(new CallbackEvent { PipelineArgs = new CallbackArgs { Peer = this, Publish = publish } }); }
/// <summary> /// Publishes an <see cref="IPublish{T}" /> to all subscribed <see cref="IPeer" />s and waits for a response. /// </summary> public T Publish <T>(IPublish <Message> publish, TimeSpan timeout) where T : Message { if (publish == null) { throw new ArgumentNullException("publish"); } if (timeout == null) { throw new ArgumentNullException("timeout"); } if (GetSubscription(publish.Key) == null) { Subscribe(new Subscription <T>()); } string callerId = Guid.NewGuid().ToString(); string responseKey = typeof(T).Key(); SemaphoreSlim handle = new SemaphoreSlim(0); string cacheKeyHandle = string.Format("publish#{0}#{1}#handle", responseKey, callerId); string cacheKeyMessage = string.Format("publish#{0}#{1}#message", responseKey, callerId); CacheManager.Add(cacheKeyHandle, handle, new CachingOptions <SemaphoreSlim> { EnableCaching = true, Expiration = timeout + timeout }); publish.Headers.Add("callerId", callerId); ISubscription subscription = new Subscription <T>(); if (!_subscriptions.ContainsKey(subscription.Key)) { Subscribe(subscription); } Publish(publish); handle.Wait(timeout); T message = CacheManager.Get <T>(cacheKeyMessage); CacheManager.Remove(cacheKeyMessage); return(message); }
public static void Publish <TDomainEvent>(this IPublish me, TDomainEvent domainEvent) { if (!(me is IPublish <TDomainEvent>)) { throw new NotSupportedException( string.Format( "{0} has not been configured to publish events of type {1}", me.GetType().FullName, typeof(TDomainEvent).GetType())); } dynamic context = DomainEventAggregation.GlobalContext; context.Aggregate(domainEvent); }
/// <summary> /// 获取分类 /// </summary> private void btnGetClassList_Click(object sender, EventArgs e) { Application.DoEvents(); IPublish iPublish = _Class.Utility.GetIPublishByName(this.cmbPublishName.Text); iPublish.Publish_OutResult = OPR_SendData; iPublish.Publish_Type = PublishType.GetClassList; iPublish.Publish_Init(this.txtWebSiteUrl.Text, this.txtWebSiteLoginUrl.Text, this.txtLoginUserName.Text, this.txtLoginUserPwd.Text, 0, string.Empty); iPublish.Publish_GetClassList(); }
public async Task PublisherSimplySendsWitQueueReturnsSuccess() { IBunny bunny = Bunny.ConnectSingle(ConnectSimple.BasicAmqp); IPublish <TestMessage> publisher = bunny.Publisher <TestMessage>(Exchange); OperationResult <TestMessage> result = await publisher .WithQueueDeclare() .SendAsync(new TestMessage()); bool success = await bunny.Setup().DeleteQueueAsync(typeof(TestMessage).FullName, force: true); Assert.True(result.IsSuccess); Assert.True(success); bunny.Dispose(); }
/// <summary> /// 加载发布模块 /// </summary> /// <param name="publishName"></param> public void LoadPublishModule(string publishName) { if (publishName.IndexOf(".pmod") > -1) { iPublish = new PublishCommon(); iPublish.Publish_OutResult = OPR_SendData; iPublish.Publish_Name = publishName; iPublish.Publish_Model = Load_PublishItem(publishName); } else { iPublish = Utility.ListIPublish.Where(p => p.Publish_Name == ModelWebSite.PublishName).FirstOrDefault(); iPublish.Publish_OutResult = OPR_SendData; iPublish.Publish_Name = ModelWebSite.PublishName; } }
void bwLogin_DoWork(object sender, DoWorkEventArgs e) { this.btnTestStatus.Invoke(new MethodInvoker(delegate() { iPublish = _Class.Utility.GetIPublishByName(this.cmbPublishName.Text); iPublish.Publish_OutResult = OPR_SendData; iPublish.Publish_Type = PublishType.Login; iPublish.Publish_Init(this.txtWebSiteUrl.Text, this.txtWebSiteLoginUrl.Text, this.txtLoginUserName.Text, this.txtLoginUserPwd.Text, 0, string.Empty); iPublish.Publish_Login(); this.btnTestStatus.Enabled = true; })); }
/// <summary> /// Is invoked when a relevant <see cref="Message" /> is published. /// </summary> /// <param name="publish"></param> public void Callback(IPublish <Message> publish) { if (publish == null) { throw new ArgumentNullException("publish"); } try { _peer.Callback(publish); } catch (Exception ex) { Log.Error(ex); } }
public Form1() { InitializeComponent(); Main = this; Publish = IocManager.ServiceProvider.GetRequiredService <IPublish>(); Control.CheckForIllegalCrossThreadCalls = false; queue = new System.Collections.Concurrent.ConcurrentQueue <IpInfo>(); url = "https://www.google.com"; regex = @"\.google\.com"; find = @"<td>(?<ip>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})</td>\s+<td>(?<port>\d+)</td>"; var path = AppDomain.CurrentDomain.BaseDirectory + "config.db"; if (System.IO.File.Exists(path)) { using (System.IO.StreamReader sr = new System.IO.StreamReader(path)) { this.setValue(sr.ReadLine(), sr.ReadLine(), sr.ReadLine()); sr.Close(); } } var list = AppDomain.CurrentDomain.BaseDirectory + "list.db"; if (System.IO.File.Exists(list)) { button7_Click(null, null); } var dictPat = AppDomain.CurrentDomain.BaseDirectory + "Url.db"; if (System.IO.File.Exists(dictPat)) { using (System.IO.StreamReader sr = new System.IO.StreamReader(dictPat)) { while (!sr.EndOfStream) { dictList.Add(new Dict() { url = sr.ReadLine(), regex = sr.ReadLine() }); } } } this.FormClosed += Form1_FormClosed; closeTag = true; }
public void Execute(PublishArgs args) { IEnumerable <ISubscription> subscriptions = args.Peer.Subscriptions .Where(x => x.CachingOptions != null && x.CachingOptions.EnableCaching && x.CachingOptions.HasCacheKey && string.Equals(x.CachingOptions.Key, args.Publish.Key)); IPublish <Message> request = args.Publish; string key = string.Format("publish#{0}#{1}", args.Peer.Node.Contact.NodeId, request.Key); foreach (ISubscription subscription in subscriptions) { CacheManager.Add(key, request, subscription.CachingOptions); } }
/// <summary> /// Publishes an <see cref="IPublish{T}" /> to all subscribed <see cref="IBroker" />s. /// </summary> /// <param name="publish"></param> public void Publish(IPublish <Message> publish) { if (publish == null) { throw new ArgumentNullException("publish"); } try { Peer.Publish(publish); } catch (Exception ex) { Log.Error(ex); throw; } }
private void CreateProxy() { try { EndpointAddress endpointAddres = new EndpointAddress(ConfigurationManager.AppSettings["EndpointAddress"]); NetTcpBinding binding = new NetTcpBinding(); TimeSpan ts = new TimeSpan(1, 0, 0); binding.CloseTimeout = ts; binding.OpenTimeout = ts; binding.SendTimeout = ts; binding.ReceiveTimeout = ts; proxy = ChannelFactory <IPublish> .CreateChannel(binding, endpointAddres); } catch (Exception ex) { CrFSMLogger.CrFSMLogger.Instance.WriteToLog(ex); } }
/// <summary> /// Builds the current <see cref="PubSubContext" /> using information from the specified <see cref="WebOperationContext" />. /// </summary> /// <param name="webOperationContext"></param> internal static void BuildContext(WebOperationContext webOperationContext) { if (webOperationContext == null) { throw new ArgumentNullException("webOperationContext"); } try { IncomingWebRequestContext request = webOperationContext.IncomingRequest; IPublish <Message> publish = ResolvePublish(request); BuildContext(publish); } catch (Exception ex) { Log.Error(ex); } }
static public void AddSubscriber(String topicName, IPublish subscriberCallbackReference) { lock (typeof(Filter)) { if (SubscribersList.ContainsKey(topicName)) { if (!SubscribersList[topicName].Contains(subscriberCallbackReference)) { SubscribersList[topicName].Add(subscriberCallbackReference); } } else { List <IPublish> newSubscribersList = new List <IPublish>(); newSubscribersList.Add(subscriberCallbackReference); SubscribersList.Add(topicName, newSubscribersList); } } }
public static void AddSubscriber(String topicName, IPublish subscriberCallbackReference) { lock (typeof(Filter)) { if (SubscribersList.ContainsKey(topicName)) { if (!SubscribersList[topicName].Contains(subscriberCallbackReference)) { SubscribersList[topicName].Add(subscriberCallbackReference); } } else { List<IPublish> newSubscribersList = new List<IPublish>(); newSubscribersList.Add(subscriberCallbackReference); SubscribersList.Add(topicName, newSubscribersList); } } }
public static void Run() { IPublish <ExampleMessage> queue = Configuration.GetQueue <ExampleMessage>(); int i = 0; while (true) { Reset.WaitOne(); i++; var message = new ExampleMessage(i, "I am number " + i); queue.Send(message); Interlocked.Increment(ref _writeCount); if (i == int.MaxValue) { i = 0; } } }
public Publish_ViewModel_WPF( ILogger Logger_, INavigationService NavigationService_, IDialogService DialogService_, IPublish iPublish_) { if (!IsInDesignModeNet()) { Logger = Logger_; NavigationService = NavigationService_; DialogService = DialogService_; iPublish = iPublish_; CommandDispatcher = new MvxCommand<string>(CmdDispatcher); } else { LearningItem = new LearningItem { Name = "Futurama" }; } }
/// <summary> /// Publishes an <see cref="IPublish{T}" /> to all subscribed <see cref="IBroker" />s and waits for a response. /// Blocks until a <see cref="Message" /> is returned or the specified timeout occurs. /// </summary> /// <typeparam name="T">The expected return type.</typeparam> /// <param name="publish">The <see cref="IPublish{T}" /> to publish.</param> /// <param name="timeout">The amount of time to wait for a response.</param> /// <returns> /// A <see cref="Message" /> of type T if it was published within the specified timeout. Otherwise null is /// returned. /// </returns> public T Publish <T>(IPublish <Message> publish, TimeSpan timeout) where T : Message { if (publish == null) { throw new ArgumentNullException("publish"); } if (timeout == null) { throw new ArgumentNullException("timeout"); } try { return(Peer.Publish <T>(publish, timeout)); } catch (Exception ex) { Log.Error(ex); throw; } }
/// <summary> /// Retrieves a cached <see cref="Message" /> of type T based on the specified <see cref="Message" />. /// Use this method for request/response schemes. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="message"></param> /// <returns></returns> public T GetCachedMessage <T>(Message message) where T : Message { if (message == null) { throw new ArgumentNullException("message"); } string subscriptionKey = typeof(T).Key(); string callbackKey = string.Format("callback#{0}#{1}", Node.Contact.NodeId, subscriptionKey); ISubscription subscription = GetSubscription(subscriptionKey); IPublish <Message> request = CacheManager.Get <IPublish <Message> >(string.Format("publish#{0}#{1}", Node.Contact.NodeId, message.GetType().Key())); if (request == null) { return(null); } string extraKey = subscription.CachingOptions.GetCacheKey(request.Message); string cacheKey = string.Format("{0}#{1}", callbackKey, extraKey); return(CacheManager.Get <T>(cacheKey)); }
private void InitTcp() { if (this.isServiceCkb.Checked) { _service.InitTcpService(); _service.Start(); } serverPort = Convert.ToInt32(ConfigurationSettings.AppSettings["ServerPort"]); _subscriber = new TcpSubscribers(serverIP, serverPort, new TimeSpan(0, 0, 0, 0, 50)); _publish = new TcpPublish(); _publish.Init(serverIP, 10002); }
protected CommandBase( IPublish<IMessage> publisher) { Publisher = publisher; Shell = (IVsUIShell)Package.GetGlobalService(typeof(SVsUIShell)); }
public DeployCommand(IPublish<IMessage> publisher) : base(publisher) { }
async public static Task PublishDomainEvents(this ChangeTracker changeTracker, IPublish publish) { var entitiesWithEvents = changeTracker.Entries <IGeneratesDomainEvents>() .Select(e => e.Entity) .Where(e => e.Events.Any()) .ToArray(); foreach (var entity in entitiesWithEvents) { var events = entity.Events.ToArray(); entity.Events.Clear(); foreach (var domainEvent in events) { await publish.Publish(domainEvent.GetType().Name, JsonConvert.SerializeObject(domainEvent)); } } }
private void InitSocket() { if (this.isServiceCkb.Checked) { //_producterService = new ProducerSocketService(); //_producterService.StartService(); //_subscriberService = new SocketSubscriberService(); //_subscriberService.StartService(); _service.InitSocketService(); _service.Start(); } serverPort = Convert.ToInt32(ConfigurationSettings.AppSettings["ServerPort"]); _subscriber = new MyMq.SocketSubscriber(serverIP, serverPort, new TimeSpan(0, 0, 0, 0, 50)); _publish = new SocketPublish(); _publish.Init(serverIP, 10002); }
public ToolWindowCommand(EventStorePackage package, IPublish<IMessage> publisher) { _package = package; _publisher = publisher; }