protected override void ExecuteChannelCore() { if (ProgressGroup == null) { ProgressGroup = new ProgressGroup { SourceChannelId = config.ChannelId } } ; ExecuteOnUIThread(() => ProgressManager.Current.Register(ProgressGroup)); try { PreProcess(); channel.SelectFolder(folder); SetSelectionRange(); var headers = channel.GetHeaders().ToList(); // Channel returned oldest first, turn around and use newest first if (Channel is IReversePagableChannel) { headers.Reverse(); } var headersToDownload = GetHeadersToDownload(headers); if (headersToDownload != null) { Logger.Debug("Got {0} headers from {1}", LogSource.Receive, headersToDownload.Count, config.DisplayName); if (headersToDownload.Count > 0) { ProgressGroup.Status = String.Format("Downloading {0}...", LocalizedFolderNames.GetName(folder.ToStorageFolder())); ProgressGroup.SetMaximum(headersToDownload.Count); // Download details for each header headersToDownload.ForEach(DownloadHeader); } } EventBroker.Publish(AppEvents.ReceiveMessagesFinished); } finally { PostProcess(); } }
void ReceiveFoldersTask_FinishedSuccess(ReceiveFoldersTask foldersTask, ChannelConfiguration config, IClientInputChannel inputChannel) { var gate = new ConcurrencyGate(config.InputChannel.MaxConcurrentConnections); var folders = foldersTask.Folders.OrderByDescending(f => (int)f.FolderType); var group = new ProgressGroup { SourceChannelId = config.ChannelId }; // Folders are pushed by descending order into concurrency gate and then popped again, // this way the Inbox folder is processed before the sent items folder etc. foreach (var folder in folders) { if (folder.FolderType == ChannelFolderType.Inbox || folder.FolderType == ChannelFolderType.SentItems) { gate.Add(new ReceiveMessagesTask(config, inputChannel.Clone(), folder, range)); } else if (folder.FolderType == ChannelFolderType.Trash || folder.FolderType == ChannelFolderType.Spam) { gate.Add(new EnumerateMessagesFolderTask(config, inputChannel.Clone(), folder, range) { ProgressGroup = group }); } else if (folder.FolderType == ChannelFolderType.Label) { if (config.Charasteristics.SupportsLabels) { gate.Add(new EnumerateLabelsFolderTask(config, inputChannel.Clone(), folder, range) { ProgressGroup = group }); } } } gate.Execute(); group.IsCompleted = true; // Process any labels that we might have received if (config.Charasteristics.SupportsLabels) { new ProcessLabelsTask(config).Execute(); } if (inputChannel is IPoolableChannel) { ((IPoolableChannel)inputChannel).FreeAllConnections(); } }
protected virtual void DownloadHeader(ChannelMessageHeader header) { Logger.Debug("Starting task for header {0}", LogSource.Receive, header); var task = new ReceiveMessageDetailsTask(config, channel, header, folder) { ProgressGroup = ProgressGroup }; try { // Execute receive details task synchronously task.Execute(); } catch (Exception ex) { Logger.Error("An exception has occured while getting message data. Exception = {0}", LogSource.Channel, ex); } finally { ProgressGroup.IncrementProgress(); } }
protected override void ExecuteCore() { var access = new ClientMessageAccess(message); var group = new ProgressGroup { Status = Strings.SendingMessage }; ProgressManager.Current.Register(group); var msg = message.DuckCopy <ChannelMessage>(); try { msg.BodyText = access.BodyText.ToStream(); msg.BodyHtml = access.BodyHtml.ToStream(); // Handle attachments foreach (var document in message.Documents) { var attachment = new ChannelAttachment { Filename = document.Filename, ContentType = document.ContentType, ContentStream = new MemoryStream() }; attachment.ContentStream = File.OpenRead( ClientState.Current.Storage.ResolvePhysicalFilename(".", document.StreamName)); msg.Attachments.Add(attachment); } Logger.Debug("Message has {0} attachments", LogSource.BackgroundTask, msg.Attachments.Count); var recipients = BuildRecipients(); try { group.SourceChannelId = message.TargetChannelId; var channel = ChannelsManager.GetChannelObject(message.TargetChannelId); // The messageid itself is not used by the send channel, so inject our friendlyrowkey into that field. // The field is added to the headers collection which in turn is used again to determine if its a sent // item that is allready in your inbox2 sent items folder. msg.MessageIdentifier = message.MessageKey; msg.ConversationId = message.ConversationIdentifier; // Filter only the recipients that belong to this channel msg.To = recipients[message.TargetChannelId].To; msg.CC = recipients[message.TargetChannelId].CC; msg.BCC = recipients[message.TargetChannelId].BCC; Logger.Debug("Sending message. Channel = {0}", LogSource.BackgroundTask, channel.Configuration.DisplayName); if (channel.Configuration.IsConnected) { SendCloudMessage(channel.Configuration, msg); } else { channel.OutputChannel.Send(msg); } Logger.Debug("Send was successfull. Channel = {0}", LogSource.BackgroundTask, channel.Configuration.DisplayName); } catch (Exception ex) { ClientState.Current.ShowMessage( new AppMessage(String.Concat(Strings.UnableToSendMessage, ", ", String.Format(Strings.ServerSaid, ex.Message))) { SourceChannelId = message.TargetChannelId }, MessageType.Error); throw; } EventBroker.Publish(AppEvents.SendMessageFinished); Thread.CurrentThread.ExecuteOnUIThread(() => ClientState.Current.ShowMessage( new AppMessage(Strings.MessageSentSuccessfully) { EntityId = message.MessageId.Value, EntityType = EntityType.Message }, MessageType.Success)); } finally { if (msg.BodyText != null) { msg.BodyText.Dispose(); } if (msg.BodyHtml != null) { msg.BodyHtml.Dispose(); } group.IsCompleted = true; // Close attachment streams foreach (var channelAttachment in msg.Attachments) { channelAttachment.ContentStream.Dispose(); channelAttachment.ContentStream = null; } } }
void Start() { chapter1Animator = chapters[0].GetComponent <Animator>(); chapter2Animator = chapters[1].GetComponent <Animator>(); chapter3Animator = chapters[2].GetComponent <Animator>(); //GameControl.control.Load(); int levelReached = GameControl.control.levelReached; // int levelReached = 22; // for testing int[] numberStarsPerLevel = GameControl.control.numberStarsPerLevel; if (levelReached == 0) { levelReached = 1; GameControl.control.levelReached = 1; } if (levelReached == 20 && numberStarsPerLevel[19] > 0) { levelReached = 21; GameControl.control.levelReached = 21; } /* Resize both the variable and the saved variable if not already so */ if (levelReached > numberStarsPerLevel.Length) { System.Array.Resize <int>(ref numberStarsPerLevel, levelReached); System.Array.Resize <int>(ref GameControl.control.numberStarsPerLevel, levelReached); //GameControl.control.numberStarsPerLevel[levelReached - 1] = 0; //Debug.Log("levelreached " + levelReached); } //foreach(int xx in numberStarsPerLevel){ // count += 1; // Debug.Log(xx); //} //Debug.Log("count " + count); //Debug.Log("numberStars " + numberStarsPerLevel.Length); //Debug.Log("sdf " + numberStarsPerLevel[21]); for (int i = 0; i < levelButtons.Length; i++) { if (i + 1 > levelReached) { levelButtons[i].interactable = false; GameObject go0 = levelButtons[i].gameObject.transform.GetChild(0).gameObject; go0.SetActive(true); GameObject go1 = levelButtons[i].gameObject.transform.GetChild(1).gameObject; go1.SetActive(false); } } for (int i = 0; i < levelReached; i++) { ProgressGroup pg = levelButtons[i].GetComponentInChildren <ProgressGroup>(); pg.progress = numberStarsPerLevel[i]; } }
protected override void ExecuteCore() { var group = new ProgressGroup { Status = Strings.UpdatingStatus }; ProgressManager.Current.Register(group); try { foreach (var config in status.TargetChannels) { var channel = ChannelsManager.GetChannelObject(config.ChannelId); try { group.SourceChannelId = config.ChannelId; ChannelContext.Current.ClientContext = new ChannelClientContext(ClientState.Current.Context, config); Logger.Debug("Updating status. Channel = {0}", LogSource.BackgroundTask, config.DisplayName); if (config.IsConnected) { var data = String.Format("wrap_access_token={0}&channels={1}&inreplyto={2}&body={3}", CloudApi.AccessToken, config.ChannelKey, status.InReplyTo, HttpUtility.UrlEncode(status.Status)); HttpServiceRequest.Post(String.Concat(CloudApi.ApiBaseUrl, "send/statusupdate"), data, true); } else { channel.StatusUpdatesChannel.UpdateMyStatus(status.DuckCopy <ChannelStatusUpdate>()); } } catch (Exception ex) { ClientState.Current.ShowMessage( new AppMessage( String.Concat( String.Format(Strings.ErrorOccuredDuringStatusUpdate, channel.Configuration.DisplayName), String.Format(Strings.ServerSaid, ex.Message))) { SourceChannelId = config.ChannelId }, MessageType.Error); throw; } } Thread.CurrentThread.ExecuteOnUIThread(() => ClientState.Current.ShowMessage( new AppMessage(Strings.StatusUpdatedSuccessfully) { EntityId = status.StatusId, EntityType = EntityType.UserStatus }, MessageType.Success)); } finally { group.IsCompleted = true; } }
protected override void ExecuteChannelCore() { ProgressGroup = new ProgressGroup { SourceChannelId = config.ChannelId }; ExecuteOnUIThread(() => ProgressManager.Current.Register(ProgressGroup)); ProgressGroup.Status = "Connecting..."; var result = channel.Connect(); try { if (result == ConnectResult.Success) { ProgressGroup.Status = "Retreiving folders..."; var cf = channel.GetFolders().ToList(); folders.AddRange(cf.Where(f => !f.Name.ToLower().StartsWithAny(ignore))); foreach (var folder in folders) { Logger.Debug("Folder: {0} {1}", LogSource.Receive, folder.FolderId, folder.FolderType); } if (Channel is IReadStateChannel) { List <Message> messages; // Get dirty messages using (mailbox.Messages.ReaderLock) messages = mailbox.Messages .Where(m => m.TargetChannel == config || m.SourceChannelId == config.ChannelId) .Where(m => m.TargetMessageState.HasValue) .Union(mailbox.Messages .Where(m => m.TargetChannel == config || m.SourceChannelId == config.ChannelId) .Where(m => m.PostLabels.Any())) .ToList(); if (messages.Count > 0) { ProgressGroup.Status = "Syncing readstates..."; foreach (var message in messages) { try { new UpdateMessageStateTask(config, (IReadStateChannel)Channel, folders, message).Execute(); } catch (Exception ex) { Logger.Error("An error has occured while trying to update message state. Message = {0}, Exception = {1}", LogSource.BackgroundTask, message, ex); } finally { message.TargetMessageState = null; ClientState.Current.DataService.Update(message); } } } } } else { ShowChannelError(result, false); } } catch (Exception) { ShowChannelError(result, true); throw; } finally { ProgressGroup.IsCompleted = true; } }