Esempio n. 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;
                }
            }
        }
Esempio n. 2
0
        public void UpdateTerpTaskFile()
        {
            while (vlakno != null && vlakno.Status != System.Threading.Tasks.TaskStatus.RanToCompletion)
            {
                Thread.Sleep(50);
            }
            if (!InvokeRequired)
            {
                timer_ClearInfo.Stop();
            }
            else
            {
                this.BeginInvoke(new Action(() => timer_ClearInfo.Stop()));
            }
            infoBox.Text = jazyk.Message_TerpUpdate;

            //updatovat tasky podle načtení a přidat ty, co původně jsou uložené navíc
            while (terpTaskFileLock)
            {
                Thread.Sleep(250);
            }
            try
            {
                Logni("Updatuji terpTask soubor", Form1.LogMessage.INFO);
                terpFile = new NbtFile();
                terpFile.LoadFromFile(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Ticketnik\\terpTask");

                foreach (MyTimeTerp mtt in GetAllMyTerps())
                {
                    if (terpFile.RootTag.Get <NbtCompound>(mtt.Label) == null)
                    {
                        terpFile.RootTag.Add(new NbtCompound(mtt.Label));
                        terpFile.RootTag.Get <NbtCompound>(mtt.Label).Add(new NbtString("ID", mtt.ID));
                        terpFile.RootTag.Get <NbtCompound>(mtt.Label).Add(new NbtString("Label", mtt.Label));
                        terpFile.RootTag.Get <NbtCompound>(mtt.Label).Add(new NbtString("Name", mtt.Name == null ? "" : mtt.Name));
                        terpFile.RootTag.Get <NbtCompound>(mtt.Label).Add(new NbtString("Number", mtt.Number));
                        terpFile.RootTag.Get <NbtCompound>(mtt.Label).Add(new NbtCompound("Tasks"));
                    }

                    foreach (MyTimeTask mtta in mtt.Tasks)
                    {
                        if (terpFile.RootTag.Get <NbtCompound>(mtt.Label).Get <NbtCompound>("Tasks").Get <NbtCompound>(mtta.Label) == null)
                        {
                            terpFile.RootTag.Get <NbtCompound>(mtt.Label).Get <NbtCompound>("Tasks").Add(new NbtCompound(mtta.Label));
                            terpFile.RootTag.Get <NbtCompound>(mtt.Label).Get <NbtCompound>("Tasks").Get <NbtCompound>(mtta.Label).Add(new NbtString("ID", mtta.ID));
                            terpFile.RootTag.Get <NbtCompound>(mtt.Label).Get <NbtCompound>("Tasks").Get <NbtCompound>(mtta.Label).Add(new NbtString("Label", mtta.Label));
                            terpFile.RootTag.Get <NbtCompound>(mtt.Label).Get <NbtCompound>("Tasks").Get <NbtCompound>(mtta.Label).Add(new NbtString("Name", mtta.Name == null ? "" : mtta.Name));
                            terpFile.RootTag.Get <NbtCompound>(mtt.Label).Get <NbtCompound>("Tasks").Get <NbtCompound>(mtta.Label).Add(new NbtList("Types", NbtTagType.String));
                        }

                        foreach (string mtty in mtta.TypeLabels)
                        {
                            bool found = false;
                            foreach (NbtString mttys in terpFile.RootTag.Get <NbtCompound>(mtt.Label).Get <NbtCompound>("Tasks").Get <NbtCompound>(mtta.Label).Get <NbtList>("Types"))
                            {
                                if (mttys.Value == mtty)
                                {
                                    found = true;
                                    break;
                                }
                            }
                            if (!found)
                            {
                                terpFile.RootTag.Get <NbtCompound>(mtt.Label).Get <NbtCompound>("Tasks").Get <NbtCompound>(mtta.Label).Get <NbtList>("Types").Add(new NbtString(mtty));
                            }
                        }
                    }
                }

                if (terpFile.RootTag.Get <NbtCompound>("Custom") != null)
                {
                    foreach (NbtCompound customTerpy in terpFile.RootTag.Get <NbtCompound>("Custom").Tags)
                    {
                        MyTimeTerp customTerp = GetTerpData(customTerpy.Get <NbtString>("ID").Value);
                        foreach (MyTimeTask customTask in customTerp.Tasks)
                        {
                            if (terpFile.RootTag.Get <NbtCompound>("Custom").Get <NbtCompound>(customTerp.Label).Get <NbtCompound>(customTask.Label) == null)
                            {
                                terpFile.RootTag.Get <NbtCompound>("Custom").Get <NbtCompound>(customTerp.Label).Get <NbtCompound>("Tasks").Add(new NbtCompound(customTask.Label));
                                terpFile.RootTag.Get <NbtCompound>("Custom").Get <NbtCompound>(customTerp.Label).Get <NbtCompound>("Tasks").Get <NbtCompound>(customTask.Label).Add(new NbtString("ID", customTask.ID));
                                terpFile.RootTag.Get <NbtCompound>("Custom").Get <NbtCompound>(customTerp.Label).Get <NbtCompound>("Tasks").Get <NbtCompound>(customTask.Label).Add(new NbtString("Label", customTask.Label));
                                terpFile.RootTag.Get <NbtCompound>("Custom").Get <NbtCompound>(customTerp.Label).Get <NbtCompound>("Tasks").Get <NbtCompound>(customTask.Label).Add(new NbtString("Name", customTask.Name == null ? "" : customTask.Name));
                                terpFile.RootTag.Get <NbtCompound>("Custom").Get <NbtCompound>(customTerp.Label).Get <NbtCompound>("Tasks").Get <NbtCompound>(customTask.Label).Add(new NbtList("Types", NbtTagType.String));
                            }

                            foreach (string customType in customTask.TypeLabels)
                            {
                                if (terpFile.RootTag.Get <NbtCompound>("Custom").Get <NbtCompound>(customTerp.Label).Get <NbtCompound>("Tasks").Get <NbtCompound>(customTask.Label).Get <NbtList>("Types")[customType] == null)
                                {
                                    terpFile.RootTag.Get <NbtCompound>("Custom").Get <NbtCompound>(customTerp.Label).Get <NbtCompound>("Tasks").Get <NbtCompound>(customTask.Label).Get <NbtList>("Types").Add(new NbtString(customType));
                                }
                            }
                        }
                    }
                }

                terpFile.SaveToFile(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Ticketnik\\terpTask", NbtCompression.GZip);
                Logni("TerpTask soubor aktualizován", Form1.LogMessage.INFO);

                LoadTerptaskFile();
            }
            catch (Exception e)
            {
                Logni("Updatování terpTask souboru selhalo\r\n" + e.Message, Form1.LogMessage.WARNING);
                Logni("Updatování terpTask souboru selhalo\r\n" + e.Message + "\r\n\r\n" + e.StackTrace, Form1.LogMessage.ERROR);
            }
            terpTaskFileLock = false;

            if (vlakno.Status != System.Threading.Tasks.TaskStatus.Running || vlakno.Status != System.Threading.Tasks.TaskStatus.WaitingForActivation ||
                vlakno.Status != System.Threading.Tasks.TaskStatus.WaitingForChildrenToComplete || vlakno.Status != System.Threading.Tasks.TaskStatus.WaitingToRun ||
                vlakno.Status != System.Threading.Tasks.TaskStatus.Created)
            {
                if (!InvokeRequired)
                {
                    timer_ClearInfo.Start();
                }
                else
                {
                    this.BeginInvoke(new Action(() => timer_ClearInfo.Start()));
                }
            }
        }
Esempio n. 3
0
        public void UpdateTerpTaskFile(string terpNumber)
        {
            while (vlakno != null && vlakno.Status != System.Threading.Tasks.TaskStatus.RanToCompletion)
            {
                Thread.Sleep(50);
            }
            if (!InvokeRequired)
            {
                timer_ClearInfo.Stop();
            }
            else
            {
                this.BeginInvoke(new Action(() => timer_ClearInfo.Stop()));
            }
            infoBox.Text = jazyk.Message_TerpUpdate;
            //vzít file jak je a updatovat nebo přidat jen task z parametru
            while (terpTaskFileLock)
            {
                Thread.Sleep(250);
            }
            terpTaskFileLock = true;

            try
            {
                Logni("Updatuji terpTask soubor, terp " + terpNumber, Form1.LogMessage.INFO);
                terpFile = new NbtFile();
                terpFile.LoadFromFile(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Ticketnik\\terpTask");

                if (terpFile.RootTag.Get <NbtCompound>("Custom") == null)
                {
                    terpFile.RootTag.Add(new NbtCompound("Custom"));
                }

                MyTimeTerp customTerp = GetTerpData(terpNumber);

                //file.RootTag.Get<NbtCompound>(mtt.Label).Add(new NbtString("Number", mtt.Number));


                foreach (MyTimeTask customTask in customTerp.Tasks)
                {
                    if (terpFile.RootTag.Get <NbtCompound>("Custom").Get <NbtCompound>(customTerp.Label) == null)
                    {
                        terpFile.RootTag.Get <NbtCompound>("Custom").Get <NbtCompound>(customTerp.Label).Get <NbtCompound>("Tasks").Add(new NbtCompound(customTask.Label));
                        terpFile.RootTag.Get <NbtCompound>("Custom").Get <NbtCompound>(customTerp.Label).Get <NbtCompound>("Tasks").Get <NbtCompound>(customTask.Label).Add(new NbtString("ID", customTask.ID));
                        terpFile.RootTag.Get <NbtCompound>("Custom").Get <NbtCompound>(customTerp.Label).Get <NbtCompound>("Tasks").Get <NbtCompound>(customTask.Label).Add(new NbtString("Label", customTask.Label));
                        terpFile.RootTag.Get <NbtCompound>("Custom").Get <NbtCompound>(customTerp.Label).Get <NbtCompound>("Tasks").Get <NbtCompound>(customTask.Label).Add(new NbtString("Name", customTask.Name == null ? "" : customTask.Name));
                        terpFile.RootTag.Get <NbtCompound>("Custom").Get <NbtCompound>(customTerp.Label).Get <NbtCompound>("Tasks").Get <NbtCompound>(customTask.Label).Add(new NbtList("Types", NbtTagType.String));
                    }

                    foreach (string customType in customTask.TypeLabels)
                    {
                        if (terpFile.RootTag.Get <NbtCompound>("Custom").Get <NbtCompound>(customTerp.Label).Get <NbtCompound>("Tasks").Get <NbtCompound>(customTask.Label).Get <NbtList>("Types")[customType] == null)
                        {
                            terpFile.RootTag.Get <NbtCompound>("Custom").Get <NbtCompound>(customTerp.Label).Get <NbtCompound>("Tasks").Get <NbtCompound>(customTask.Label).Get <NbtList>("Types").Add(new NbtString(customType));
                        }
                    }
                }


                terpFile.SaveToFile(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Ticketnik\\terpTask", NbtCompression.GZip);
                Logni("TerpTask soubor aktualizován", Form1.LogMessage.INFO);
            }
            catch (Exception e)
            {
                Logni("Updatování terpTask souboru selhalo\r\n" + e.Message, Form1.LogMessage.WARNING);
                Logni("Updatování terpTask souboru selhalo\r\n" + e.Message + "\r\n\r\n" + e.StackTrace, Form1.LogMessage.ERROR);
            }
            terpTaskFileLock = false;
        }
Esempio n. 4
0
        public MyTimeTerp GetTerpData(string terpID)
        {
            terpLoaderBrowser.Navigate(new Uri("https://mytime.tieto.com/autocomplete/projects/by_number?mode=all&term=" + terpID));
            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/by_number?mode=all&term=" + terpID));
                while (!terpLoaderReady)
                {
                    Thread.Sleep(100);
                }
                terpLoaderReady = false;
            }

            JsonTextReader reader = new JsonTextReader(new StringReader(result));
            string         tmpId = "", tmpName = "", tmpLabel = "", tmpNumber = "";
            MyTimeTerp     myTimeTerp = 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 == "project_name")
                    {
                        reader.Read();
                        tmpName = (string)reader.Value;
                    }
                    else if (reader.TokenType == JsonToken.PropertyName && (string)reader.Value == "label")
                    {
                        reader.Read();
                        tmpLabel = (string)reader.Value;
                    }
                    else if (reader.TokenType == JsonToken.PropertyName && (string)reader.Value == "project_number")
                    {
                        reader.Read();
                        tmpNumber = reader.Value.ToString();
                    }

                    if (tmpId != "" && tmpLabel != "" && tmpName != "")
                    {
                        myTimeTerp       = new MyTimeTerp(tmpId, tmpLabel, tmpName, tmpNumber);
                        myTimeTerp.Tasks = GetTerpTasks(myTimeTerp.ID);
                        tmpId            = tmpLabel = tmpName = "";
                    }
                }
            }

            return(myTimeTerp);
        }