예제 #1
0
        public void LoadTerptaskFile()
        {
            while (terpTaskFileLock)
            {
                Thread.Sleep(50);
            }
            if (!terpTaskFileLock)
            {
                if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Ticketnik\\terpTask"))
                {
                    terpTaskFileLock = true;
                    terpFile         = new NbtFile();
                    terpFile.LoadFromFile(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Ticketnik\\terpTask");

                    foreach (NbtCompound mtt in terpFile.RootTag.Tags)
                    {
                        if (mtt.Name != "Custom")
                        {
                            MyTimeTerp myterp = new MyTimeTerp(mtt.Get <NbtString>("ID").Value, mtt.Get <NbtString>("Label").Value, mtt.Get <NbtString>("Name").Value,
                                                               mtt.Get <NbtString>("Number").Value);

                            foreach (NbtCompound mtta in mtt.Get <NbtCompound>("Tasks").Tags)
                            {
                                MyTimeTask mytask = new MyTimeTask(mtta.Get <NbtString>("ID").Value, mtta.Get <NbtString>("Label").Value, mtta.Get <NbtString>("Name").Value);

                                foreach (NbtString mtty in mtta.Get <NbtList>("Types"))
                                {
                                    mytask.TypeLabels.Add(mtty.Value);
                                }
                                myterp.Tasks.Add(mytask);
                            }

                            if (!Terpy.ContainsKey(mtt.Get <NbtString>("Label").Value))
                            {
                                Terpy.Add(myterp.Label, myterp);
                            }
                            else
                            {
                                Terpy[myterp.Label] = myterp;
                            }
                        }
                    }

                    if (terpFile.RootTag.Get <NbtCompound>("Custom") != null)
                    {
                        foreach (NbtCompound customTerpy in terpFile.RootTag.Get <NbtCompound>("Custom").Tags)
                        {
                            MyTimeTerp myterp = new MyTimeTerp(customTerpy.Get <NbtString>("ID").Value, customTerpy.Get <NbtString>("Label").Value, customTerpy.Get <NbtString>("Name").Value,
                                                               customTerpy.Get <NbtString>("Number").Value);

                            foreach (NbtCompound mtta in customTerpy.Get <NbtCompound>("Tasks").Tags)
                            {
                                MyTimeTask mytask = new MyTimeTask(mtta.Get <NbtString>("ID").Value, mtta.Get <NbtString>("Label").Value, mtta.Get <NbtString>("Name").Value);

                                foreach (NbtString mtty in mtta.Get <NbtList>("Types"))
                                {
                                    mytask.TypeLabels.Add(mtty.Value);
                                }
                                myterp.Tasks.Add(mytask);
                            }

                            if (!Terpy.ContainsKey(customTerpy.Get <NbtString>("Label").Value))
                            {
                                Terpy.Add(myterp.Label, myterp);
                            }
                            else
                            {
                                Terpy[myterp.Label] = myterp;
                            }
                        }
                    }

                    terpTaskFileLock = false;
                }
            }
        }
예제 #2
0
        public MyTimeTask GetTerpTaskData(string terpID, string taskID)
        {
            terpLoaderBrowser.Navigate(new Uri("https://mytime.tieto.com/autocomplete/projects/" + terpID + "/tasks?mode=my&term=" + taskID));
            while (!terpLoaderReady)
            {
                Thread.Sleep(100);
            }
            terpLoaderReady = false;

            if (result.Contains("Access denied") || result.Contains("Navigation to the webpage was canceled") || result.Contains("Your session has expired"))
            {
                terpLoaderBrowser.Navigate(new Uri("https://mytime.tieto.com/winlogin?utf8=%E2%9C%93&commit=Log+in"));
                while (!terpLoaderReady)
                {
                    Thread.Sleep(100);
                }
                terpLoaderReady = false;

                terpLoaderBrowser.Navigate(new Uri("https://mytime.tieto.com/autocomplete/projects/" + terpID + "/tasks?mode=my&term=" + taskID));
                while (!terpLoaderReady)
                {
                    Thread.Sleep(100);
                }
                terpLoaderReady = false;
            }

            JsonTextReader reader = new JsonTextReader(new StringReader(result));
            string         tmpId = "", tmpName = "", tmpLabel = "";
            MyTimeTask     myTimeTask = null;

            while (reader.Read())
            {
                if (reader.Value != null)
                {
                    if (reader.TokenType == JsonToken.PropertyName && (string)reader.Value == "id")
                    {
                        reader.Read();
                        tmpId = reader.Value.ToString();
                    }
                    else if (reader.TokenType == JsonToken.PropertyName && (string)reader.Value == "task_description")
                    {
                        reader.Read();
                        tmpName = (string)reader.Value;
                    }
                    else if (reader.TokenType == JsonToken.PropertyName && (string)reader.Value == "label")
                    {
                        reader.Read();
                        tmpLabel = (string)reader.Value;
                    }

                    if (tmpId != "" && tmpLabel != "" && tmpName != "")
                    {
                        myTimeTask = new MyTimeTask(tmpId, tmpLabel, tmpName);
                        tmpId      = tmpLabel = tmpName = "";
                    }
                }
            }
            myTimeTask.TypeLabels = GetTerpTaskTypes(terpID, myTimeTask.ID);

            return(myTimeTask);
        }