0

This is what I want: A method that will concatenate all the returned values into one block. At the moment each result is sent as a single string. current results of my code that I would like concatinated

     static async void NotifyEntriesByWorkSpace(Dictionary<string, List<TimeEntry>> EntriesByWorkspace, string strChatURL)
    {
        foreach (var entry in EntriesByWorkspace)
        {
            var timeEntry = entry.Value;
            string prevStoryId = "";
            string strTitle = "";
            var minsLogged = 0;
            foreach (var item in timeEntry)
            {
                Tuple<string, int, string> entryData = GetEntryData(prevStoryId, item);
                prevStoryId = entryData.Item1;
                minsLogged = minsLogged + entryData.Item2;
                strTitle = entryData.Item3;
            }
            Console.WriteLine(strTitle + ": " + minsLogged + " min(s)");
            await SendEntriesByWorkspaceMessage(strChatURL, strTitle, minsLogged);
        }
    }

    static async Task SendEntriesByWorkspaceMessage(string strChatURL, string strTitle, int minsLogged)
    {
        await sendMessage(strChatURL, strTitle + ": " + minsLogged / 60 + " hour(s)" + " " + minsLogged % 60 + " min(s)");
    }

    static Tuple<string, int, string> GetEntryData(string prevStoryId, TimeEntry item)
    {
        var storyId = item.StoryID;
        string prevStoryId_ = "";
        string strTitle = "";
        var minsLogged = 0;
        strTitle = Workspaces.getWorkspaceFromCache(item.WorkspaceID).Title;
        if (prevStoryId != storyId)
        {
            minsLogged = item.TimeInMinutes;
            prevStoryId_ = storyId;
        }
        else
        {
            minsLogged = minsLogged + item.TimeInMinutes;
        }
        return Tuple.Create(prevStoryId_, minsLogged, strTitle);
    }

1 Answer 1

1
     static async void NotifyEntriesByWorkSpace(Dictionary<string, List<TimeEntry>> EntriesByWorkspace, string strChatURL)
    {
        string block = "";
        foreach (var entry in EntriesByWorkspace)
        {
            var timeEntry = entry.Value;
            string prevStoryId = "";
            string strTitle = "";
            var minsLogged = 0;
            foreach (var item in timeEntry)
            {
                Tuple<string, int, string> entryData = GetEntryData(prevStoryId, item);
                prevStoryId = entryData.Item1;
                minsLogged = minsLogged + entryData.Item2;
                strTitle = entryData.Item3;
            }
            Console.WriteLine(strTitle + ": " + minsLogged + " min(s)");
            block += strTitle + ": " + minsLogged / 60 + " hour(s)" + " " + minsLogged % 60 + " min(s)\n";
        }

        await sendMessage(strChartUrl, block);
    }

The idea is to instead of sendMessage() every entry, collect entries into a string then output it once the whole foreach loop completed.

The string is manually separated by \n, but some ideas like make a entriesList and then eventually String.Join("\n", entriesList) might result in more clear code flow. It depends on your liking.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.