public Task UpdateAsync(IDispatcher dispatcher, IDirectory root) { var dff = SetupDff(dispatcher, root); Action start = () => Running = true; Action stop = () => Running = false; return(Task.Run(() => { if (dispatcher != null) { dispatcher.Execute(start); } else { start(); } Task.WaitAll(dff.FindDuplicates()); if (dispatcher != null) { dispatcher.Execute(stop); } else { stop(); } })); }
public Task FireAsync <TArgument>(ParameterizedTrigger <TTrigger, TArgument> parameterizedTrigger, TArgument argument) { if (IsEnabled) { var tcs = new TaskCompletionSource <bool>(); Action action = () => dispatcher.Execute(async() => { await machine.FireAsync(parameterizedTrigger, argument); tcs.SetResult(true); if (!isInQueue) { RunFromQueueIfNotEmpty(); } }); if (isRunning || isPaused) { lock (actionsQueue) { actionsQueue = actionsQueue.Enqueue(action); queueCount++; } return(tcs.Task); } isRunning = true; action(); return(tcs.Task); } return(TaskCache.FalseTask); }
public virtual void Send <T>(Actor actor, Action <T> consumer, ICompletes?completes, string representation) { var messageIndex = _sendIndex.IncrementAndGet(); var ringSendIndex = (int)(messageIndex % _mailboxSize); int retries = 0; while (ringSendIndex == (int)(_receiveIndex.Get() % _mailboxSize)) { if (++retries >= _mailboxSize) { if (_closed.Get()) { return; } retries = 0; } } _messages[ringSendIndex].Set(actor, consumer, completes, representation); while (_readyIndex.CompareAndSet(messageIndex - 1, messageIndex)) { } if (_notifyOnSend) { _dispatcher.Execute(this); } }
public void Resume(string name) { if (_suspendedDeliveryOverrides.Get() !.Pop(name)) { _dispatcher.Execute(this); } }
public void Send(IMessage message) { queue.Enqueue(message); if (!IsDelivering) { dispatcher.Execute(this); } }
private void NotifyFileScanned(IFile file) { EventHandler onFileScanned = OnFileScanned; Action action = () => onFileScanned(file, new EventArgs()); if (onFileScanned != null) { if (dispatcher != null) { dispatcher.Execute(action); } else { action(); } } }
private void NotifyDuplicateFound(List <IFile> filelist, string hash, IFile file) { DuplicateFound onDuplicateFound = OnDuplicateFound; if (onDuplicateFound != null) { // Since each duplicate file is notified via an // individial event, we need to fire two events // when the first duplicate is detected if (filelist.Count == 2) { foreach (IFile ff in filelist) { Action action = () => onDuplicateFound(hash, filelist.IndexOf(ff) + "-" + ff.Path, ff.GetSize()); if (dispatcher != null) { dispatcher.Execute(action); } else { action(); } } } // After the third or greater is duplicate file // is found, we already know that the prior duplicate files // have had events fired for them, so we only need to // fire one event for the latest file found if (filelist.Count > 2) { Action action = () => onDuplicateFound(hash, filelist.IndexOf(file) + "-" + file.Path, file.GetSize()); if (dispatcher != null) { dispatcher.Execute(action); } else { action(); } } } }
private void NotifyHashBegin(IDispatcher dispatcher, HashProgress notifier) { if (notifier != null) { Action action = () => notifier(Path, 0); if (dispatcher != null) { dispatcher.Execute(action); } else { action(); } } }
private void NotifyHashEnd(IDispatcher dispatcher, HashProgress notifier) { if (notifier != null) { Action action = () => notifier(Path, 100); if (dispatcher != null) { dispatcher.Execute(action); } else { action(); } } }
public void Send(IMessage message) { for (var tries = 0; tries < _totalSendRetries; ++tries) { if (_queue.TryAdd(message)) { if (_notifyOnSend) { _dispatcher.Execute(this); } return; } while (PendingMessages >= _queue.BoundedCapacity) { ; } } throw new InvalidOperationException("Count not enqueue message due to busy mailbox."); }
// GET: Movie public ActionResult Index() { return(View(_dispatcher.Execute <GetMovies, IEnumerable <GetMoviesResult> >(new GetMovies()))); }
public ActionResult Index() { var c = _dispatcher.Execute <Test, bool>(new Test()); return(View()); }
private async Task CalculateHash( IDispatcher d, HashProgress notifier) { if (notifier != null) { Action action = () => notifier(Path, 0); if (d == null) { action(); } else { d.Execute(action); } } //TODO - exception handling StorageFile file = await GetFromRoot(m_path, m_root); int num_chunks = (int)(GetSize() / Chunker.chunk_size) + 1; int hash_size = num_chunks * 32; float current_chunk = 0; var hash_builder = new StringBuilder(hash_size); m_hash = ""; var chunker = new Chunker(GetSize()); foreach (Chunk chunk in chunker.GetChunks()) { using (IRandomAccessStream inputStream = await file.OpenAsync(FileAccessMode.Read)) { using (var dataReader = new DataReader(inputStream.GetInputStreamAt(chunk.Start))) { await dataReader.LoadAsync(chunk.Length); IBuffer buf = dataReader.ReadBuffer(chunk.Length); IBuffer hashed = m_alg.HashData(buf); hash_builder.Append(CryptographicBuffer.EncodeToHexString(hashed)); } } current_chunk++; if (notifier != null) { float percent_done = current_chunk / num_chunks; Action action = () => notifier(Path, percent_done * 100); if (d == null) { action(); } else { d.Execute(action); } } } m_hash = hash_builder.ToString(); if (hash_size > 32) //hash the hash { // Convert the string to UTF8 binary data. IBuffer hashbuf = CryptographicBuffer.ConvertStringToBinary(m_hash, BinaryStringEncoding.Utf8); IBuffer hashed = m_alg.HashData(hashbuf); m_hash = CryptographicBuffer.EncodeToHexString(hashed); } if (notifier != null) { Action action = () => notifier(Path, 100); if (d == null) { action(); } else { d.Execute(action); } } }
private async Task CalculateHash( IDispatcher d, HashProgress notifier) { if (notifier != null) { Action action = () => notifier(Path, 0); if (d == null) { action(); } else { d.Execute(action); } } //TODO - exception handling StorageFile file = await GetFromRoot(m_path, m_root); int num_chunks = (int) (GetSize()/Chunker.chunk_size) + 1; int hash_size = num_chunks*32; float current_chunk = 0; var hash_builder = new StringBuilder(hash_size); m_hash = ""; var chunker = new Chunker(GetSize()); foreach (Chunk chunk in chunker.GetChunks()) { using (IRandomAccessStream inputStream = await file.OpenAsync(FileAccessMode.Read)) { using (var dataReader = new DataReader(inputStream.GetInputStreamAt(chunk.Start))) { await dataReader.LoadAsync(chunk.Length); IBuffer buf = dataReader.ReadBuffer(chunk.Length); IBuffer hashed = m_alg.HashData(buf); hash_builder.Append(CryptographicBuffer.EncodeToHexString(hashed)); } } current_chunk++; if (notifier != null) { float percent_done = current_chunk/num_chunks; Action action = () => notifier(Path, percent_done*100); if (d == null) { action(); } else { d.Execute(action); } } } m_hash = hash_builder.ToString(); if (hash_size > 32) //hash the hash { // Convert the string to UTF8 binary data. IBuffer hashbuf = CryptographicBuffer.ConvertStringToBinary(m_hash, BinaryStringEncoding.Utf8); IBuffer hashed = m_alg.HashData(hashbuf); m_hash = CryptographicBuffer.EncodeToHexString(hashed); } if (notifier != null) { Action action = () => notifier(Path, 100); if (d == null) { action(); } else { d.Execute(action); } } }
public Stream Execute(string typeName, string functionName, string args) { Stream stream = null; if (_isError) { ServerResponse response = new ServerResponse(); response.IsError = true; response.ErrorMessage = "系统初始化时报错!"; stream = response.ToStream(); return(stream); } //如果没有初始化结束,就休眠等待 while (!_initialized) { Thread.Sleep(500); } Dictionary <string, object> dic = null; try { dic = JsonHelper.Deserialize <Dictionary <string, object> >(args); } catch (Exception ex) { ServerResponse response = new ServerResponse(); response.IsError = true; response.StackTrace = ex.StackTrace; response.ErrorMessage = "反序列化传入json字符串时出错!Json:" + args; stream = response.ToStream(); return(stream); } try { stream = _dispatcher.Execute(typeName, functionName, dic, _filterList, enableConsoleMonitor); } catch (Exception ex) { Exception exinner = ex; StringBuilder stacktrace = new StringBuilder(); StringBuilder message = new StringBuilder(); while (exinner.InnerException != null) { stacktrace.Append(exinner.StackTrace); message.Append(exinner.Message); exinner = exinner.InnerException; } StringBuilder log = new StringBuilder(); log.AppendFormat("Message:{0} \r\n Stack Trace:{1}", message.ToString(), stacktrace.ToString()); string logPath = AppDomain.CurrentDomain.BaseDirectory.TrimEnd('\\') + "\\Logs\\"; if (!Directory.Exists(logPath)) { Directory.CreateDirectory(logPath); } File.AppendAllText(logPath + DateTime.Now.ToString("yyMMddHH") + ".log", log.ToString()); ServerResponse response = new ServerResponse(); response.IsError = true; response.StackTrace = ex.StackTrace; response.ErrorMessage = ex.Message; stream = response.ToStream(); return(stream); } return(stream); }
/// <summary> /// Starts the execution. /// </summary> private void StartExecution() { pgBar.Value = 0; Boolean localEnabled = false, remoteEnabled = false; List<IRemoteGateClient> clients = new List<IRemoteGateClient>(); /* Manually control the status of local machine */ foreach (IServer server in m_WorkSpace.Servers) { if (server is LocalServer) { if (server.Enabled) { server.Status = ServerStatus.Running; localEnabled = true; } } if (server is RemoteServer) { if (server.Enabled) { RemoteServer rServer = (RemoteServer)server; server.Status = ServerStatus.Down; IRemoteGateClient newClient = null; if (rServer.ConnectionType == ConnectionType.Http) { if (rServer.SecurityKey != null) newClient = new HttpRemoteGateClient(rServer.Host, rServer.Port, rServer.SecurityKey, 1000); else newClient = new HttpRemoteGateClient(rServer.Host, rServer.Port, 1000); } else if (rServer.ConnectionType == ConnectionType.Tcp) { if (rServer.SecurityKey != null) newClient = new TcpRemoteGateClient(rServer.Host, rServer.Port, rServer.SecurityKey, 1000); else newClient = new TcpRemoteGateClient(rServer.Host, rServer.Port, 1000); } newClient.ConnectedToServer += newClient_ConnectedToServer; newClient.DisconnectedFromServer += newClient_DisconnectedFromServer; rServer.Client = newClient; clients.Add(newClient); remoteEnabled = true; } } } DispatchMode mode = DispatchMode.Combined; if (localEnabled && remoteEnabled) mode = DispatchMode.Combined; else if (localEnabled) mode = DispatchMode.LocalOnly; else if (remoteEnabled) mode = DispatchMode.RemoteOnly; UpdateAllNodes(); /* Runtime creation of Generic type */ Type dynamicDispatcher = typeof(Dispatcher<,,>).MakeGenericType(new Type[] { typeof(CSharpScriptAssembler), m_WorkSpace.LocalBalancer, m_WorkSpace.RemoteBalancer }); m_Dispatcher = (IDispatcher)Activator.CreateInstance(dynamicDispatcher, new Object[] { m_WorkSpace.QueueSize, (m_WorkSpace.NumberOfThreads == 0) ? Environment.ProcessorCount : m_WorkSpace.NumberOfThreads, mode }); m_Dispatcher.AlgorithmProgress += m_dispatcher_AlgorithmProgress; m_Dispatcher.AlgorithmComplete += m_dispatcher_AlgorithmComplete; /* Add remote hosts */ foreach (IRemoteGateClient client in clients) { m_Dispatcher.RegisterGate(client); } m_AlgorithmInstance = m_WorkSpace.Provider.GetAlgorithmInstance(); m_CurrentWorkValue = 0; m_LastWorkValue = 0; m_MaxWorkValue = 0; m_MeasurmentsDone = 0; m_AverageSpeed = 0; m_Finished = false; UpdateStatusLabel(); graphView.AddLine(0, Color.Red).Thickness = 2; m_Dispatcher.Execute(m_AlgorithmInstance); pgBarTimer.Start(); m_IsRunning = true; }
// GET: api/GetSurvey public List <Survey> Get() { return(_dispatcher.Execute <GetSurvey, List <Survey> >(new GetSurvey { BrandName = UserContext.GetUserContext(Request).brand_name })); }