public void AddMissingTMSTasksToRedmine()
        {
            sw.StartStopwatchAndPrintMessage("Getting TMS tasks from DB and making cache...", output);
            GetherSyncData();

            IdentifiableName p = IdentifiableName.Create <Project>(Consts.PROJECT_NAMES.TMS.MACBI.PROBLEMS); //to-be-changed
            //IdentifiableName u = IdentifiableName.Create<User>(USER_ID);
            //var user = RMManegerService.RMManager.GetObject<User>(USER_ID.ToString(), null);
            IdentifiableName u        = IdentifiableName.Create <IdentifiableName>(USER_ID);
            IdentifiableName priority = IdentifiableName.Create <IdentifiableName>(PRIORITY_HIGH);


            //var newIssue = new Issue { Subject = subject, Project = p, Description = details };
            //RMManegerService.RMManager.CreateObject(newIssue);

            int limit = 5;

            List <string> listOfAddedItems    = new List <string>();
            List <string> listOfNOTAddedItems = new List <string>();

            foreach (TMSItem item in dbTMSDict.GetNotClosedNotUsedAssignedToDEV1ItemList(TeamService.UsersTMSLogin))
            {
                string description = item.Desctiption;
                //check if really there is no such a TMS in RM (maybe it was already closed)
                TMSItem tmsItem = rmTMSDict.Get(item.TMS);

                //redMineTMSList.Contains()
                if (tmsItem == null)
                {
                    string firstLine = null;

                    if (description.Contains("\r\n") || description.Contains("."))
                    {
                        firstLine = description.Substring(0, description.Contains("\r\n") ? description.IndexOf("\r\n") : description.IndexOf("."));
                    }
                    else
                    {
                        firstLine = description;
                    }

                    if (firstLine.Length > 255)
                    {
                        firstLine = firstLine.Substring(0, 240);//255 is max lenght of subject.

                        int lastDotIndex = firstLine.LastIndexOf(".");
                        if (lastDotIndex > -1)
                        {
                            firstLine = firstLine.Substring(0, lastDotIndex);
                        }
                    }

                    string subject  = string.Format("{0} - {1}", item.TMS, firstLine);
                    var    newIssue = new Issue {
                        Subject = subject, Project = p, Description = description, AssignedTo = u, Priority = priority
                    };
                    RMManegerService.RMManager.CreateObject(newIssue);
                    listOfAddedItems.Add(subject);
                }
                else
                {
                    listOfNOTAddedItems.Add(string.Format("{0}", tmsItem));
                    //Console.WriteLine("Item can't be added as it already exists: {0}", tmsItem);
                }

                if (Consts.TEST_MODE)
                {
                    if (--limit == 0)
                    {
                        return;
                    }
                }
            }

            output.WriteLine("List of added items ({0})", listOfAddedItems.Count);
            output.WriteLine("List of NOT added items ({0})", listOfNOTAddedItems.Count);

            if (listOfAddedItems.Count > 0)
            {
                output.WriteLine("Cache needs to be refreshed!");
                rmTMSDict = null;
                GetherSyncData();
            }
            sw.StopStopwatchAndPrintDoneMessageWithElapsedTime(output);
        }
        public void DisplayStatsForTMSSync()
        {
            MainDS ds = new MainDS();
            TMSWithReasonDataTable dt = ds.TMSWithReason;

            output.WriteLine("");
            foreach (string key in outputList.Keys)
            {
                //output.WriteLine("---------------------------");
                //output.WriteLine(key);
                //output.WriteLine("---------------------------");
                foreach (TMS_TP tp in outputList[key])
                {
                    //output.WriteLine(tp.ToString());
                    DataRow r = dt.NewRow();
                    r["Reason"] = key;
                    if (tp.Item1 != null)
                    {
                        r["TMS"]          = tp.Item1.TMS;
                        r["TMS_Assigned"] = tp.Item1.AssignedTo;
                        r["TMS_Status"]   = tp.Item1.Status;
                    }

                    r["TMS_ACT_SHOW"] = "X";
                    r["RM_ACT_SHOW"]  = "X";

                    if (IsAssignedToMe(tp.ToString()))
                    {
                        r["Me"] = "Y";
                    }

                    if (tp.Item2 != null)
                    {
                        r["RM"]          = tp.Item2.RMId;
                        r["RM_Assigned"] = tp.Item2.AssignedTo;
                        r["RM_Status"]   = tp.Item2.Status;
                    }
                    dt.Rows.Add(r);
                }
            }

            output.WriteLine("\r\n-------TMS not exist in RM-------");
            foreach (TMSItem item in dbTMSDict.GetNotClosedNotUsedAssignedToDEV1ItemList(TeamService.UsersTMSLogin))
            {
                output.WriteLine(item.ToString());
                DataRow r = dt.NewRow();
                FillOutputGridRowWithTMSData(item, r, Consts.RFC_NOT_EXISTS_IN_RM);
                dt.Rows.Add(r);
            }

            output.WriteLine("\r\n-------RM duplicated TMS -------");
            Dictionary <string, List <TMSItem> > duplicates = rmTMSDict.GetDuplicates();

            foreach (string tmsNum in duplicates.Keys)
            {
                output.WriteLine(tmsNum);
                foreach (TMSItem item in duplicates[tmsNum])
                {
                    output.WriteLine("   " + item);
                }
            }

            output.WriteLine("\r\n-------ASSIGNED TO ME IN REDMINE-------");
            List <string> me = new List <string>();

            me.Add("Waldemar Dacko");

            foreach (TMSItem item in rmTMSDict.GetNotClosedNotUsedAssignedToDEV1ItemList(me))
            {
                output.WriteLine(item.TMS);

                /*
                 * DataRow r = dt.NewRow();
                 * FillOutputGridRowWithTMSRMData(item, r, Consts.RFC_ASSIGNED_TO_ME_IN_RM);
                 * dt.Rows.Add(r);
                 */
            }


            output.WriteLine("\r\n-------ASSIGNED TO ME IN TMS-------");
            me.Add("WALDEMARD");

            foreach (TMSItem item in dbTMSDict.GetNotClosedNotUsedAssignedToDEV1ItemList(me))
            {
                output.WriteLine(item.TMS);

                DataRow r = dt.NewRow();
                FillOutputGridRowWithTMSData(item, r, Consts.RFC_ASSIGNED_TO_ME_IN_TMS);
                dt.Rows.Add(r);
            }


            output.WriteLine("\r\n----------------------------");

            dt.AcceptChanges();
            output.WriteToGrid(dt);
        }