Beispiel #1
0
        private void SubmitBTN_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var login       = LoginTB.Text;
                var password    = PasswordTB.Text;
                var name        = NameTB.Text;
                var lastname    = LastNameTB.Text;
                var age         = AgeTB.Text;
                var joiningdate = DataLB.Content;


                if (string.IsNullOrEmpty(name))
                {
                    MessageBox.Show("Pole 'Podaj swoje imię' nie może być puste. Proszę wpisz swoje imię.", "Błąd", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                else if (string.IsNullOrEmpty(lastname))
                {
                    MessageBox.Show("Pole 'Podaj swoje nazwisko' nie może być puste. Proszę wpisz swoje nazwisko.", "Błąd", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                else if (string.IsNullOrEmpty(age))
                {
                    MessageBox.Show("Pole 'Podaj swój wiek' nie może być puste. Proszę wpisz swój wiek.", "Błąd", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                else
                {
                    SaveToDB.SaveInfo(login, password, name, lastname, age, joiningdate.ToString());
                    MessageBox.Show($"Pomyślnie zarejestrowano użytkownika {login}! Zapisano go w bazie danych!", "Powodzenie", MessageBoxButton.OK, MessageBoxImage.Information);
                    MainWindow mwnd = new MainWindow();
                    mwnd.Show();
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex);

                MessageBox.Show("Coś poszło nie tak, spróbuj ponownie później.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        public ActionResult Index(string id = null, SiteModel model = null)
        {
            if ((model == null) && (id == null))
            {
                SiteModel newmodel = new SiteModel();
                return(View(newmodel));
            }

            //É para quando receber um codigo de algum site, redirecionar para esse site
            if (id != null)
            {
                SaveToDB save        = new SaveToDB();
                string   originalUrl = save.get_originalUrl_from_redis(id);
                save.increment_access_count(originalUrl);

                return((!originalUrl.Contains("http")) ? Redirect("http://" + originalUrl) : Redirect(originalUrl));
            }
            return(View(model));
        }
Beispiel #3
0
 /// <summary>
 /// Collector Agent for Life data Aquesition
 /// </summary>
 /// <param name="actorPaths"></param>
 /// <param name="time">Current time span</param>
 /// <param name="debug">Parameter to activate Debug Messages on Agent level</param>
 public Collector(ActorPaths paths
                  , ICollectorBehaviour collectorBehaviour
                  , IMessageHub msgHub
                  , Configuration configuration
                  , long time
                  , List <Type> streamTypes)
     : base(time: time, channels: streamTypes)
 {
     Console.WriteLine(value: "I'm alive: " + Self.Path.ToStringWithAddress());
     collectorBehaviour.Collector = this;
     Behaviour        = collectorBehaviour;
     messageHub       = msgHub;
     Config           = configuration;
     actorPaths       = paths;
     simulationId     = Config.GetOption <SimulationId>();
     simulationNumber = Config.GetOption <SimulationNumber>();
     simulationKind   = Config.GetOption <SimulationKind>();
     saveToDB         = Config.GetOption <SaveToDB>();
 }
Beispiel #4
0
 /// <summary>
 /// Collector Agent for Life data Aquesition
 /// </summary>
 /// <param name="actorPaths"></param>
 /// <param name="time">Current time span</param>
 /// <param name="debug">Parameter to activate Debug Messages on Agent level</param>
 public Collector(ActorPaths paths
                  , ICollectorBehaviour collectorBehaviour
                  , IMessageHub msgHub
                  , Configuration configuration
                  , long time
                  , List <Type> streamTypes)
     : base(time: time, channels: streamTypes)
 {
     collectorBehaviour.Collector = this;
     Behaviour        = collectorBehaviour;
     messageHub       = msgHub;
     Config           = configuration;
     actorPaths       = paths;
     simulationId     = Config.GetOption <SimulationId>();
     simulationNumber = Config.GetOption <SimulationNumber>();
     simulationKind   = Config.GetOption <SimulationKind>();
     saveToDB         = Config.GetOption <SaveToDB>();
     maxTime          = Config.GetOption <SimulationEnd>().Value;
     messageHub.SendToAllClients(msg: "Collector initialized: " + Self.Path.ToStringWithAddress());
 }
Beispiel #5
0
        /// <summary>
        /// Сохранить параметр
        /// </summary>
        /// <param name="doc">Документ в который сохраняется параметр</param>
        /// <returns>Узел в котором сохранен параметр</returns>
        public XmlNode Save(XmlDocument doc)
        {
            try
            {
                XmlNode root = doc.CreateElement(parameterRoot);

                XmlNode nameNode = doc.CreateElement(parameterName);
                XmlNode descNode = doc.CreateElement(descriptionName);

                XmlNode unitsNode = doc.CreateElement(unitsName);
                XmlNode alarmNode = doc.CreateElement(alarmValueName);

                XmlNode blockingNode     = doc.CreateElement(blockingValueName);
                XmlNode controlAlarmNode = doc.CreateElement(controlAlarmName);

                XmlNode controlBlockingNode = doc.CreateElement(controlBlockingName);
                XmlNode rangeNode           = range.Save(doc);

                XmlNode isSaveToDBNode     = doc.CreateElement(saveToDBName);
                XmlNode intervalToSaveNode = doc.CreateElement(intervalToSaveName);

                XmlNode thresholdToBDNode = doc.CreateElement(thresholdToBDName);
                //XmlNode channelNumberNode = doc.CreateElement(channelNumberName);

                XmlNode currentValueNode = doc.CreateElement(currentValueName);
                XmlNode selfIndexNode    = doc.CreateElement(selfIndexName);

                XmlNode guidNode = doc.CreateElement(guidName);

                XmlNode devManindexNode       = doc.CreateElement(devManindexName);
                XmlNode devManDescriptionNode = doc.CreateElement(devManDescriptionName);
                XmlNode decimalPointsNode     = doc.CreateElement(decimalPointsName);

                XmlNode transformationNode = null;
                if (transformation != null)
                {
                    transformationNode = transformation.CreateXmlNode(doc);
                }

                nameNode.InnerText = Name;
                descNode.InnerText = Description;

                unitsNode.InnerText = Units;
                alarmNode.InnerText = Alarm.ToString();

                blockingNode.InnerText     = Blocking.ToString();
                controlAlarmNode.InnerText = IsControlAlarm.ToString();

                controlBlockingNode.InnerText = IsControlBlocking.ToString();
                isSaveToDBNode.InnerText      = SaveToDB.ToString();

                intervalToSaveNode.InnerText = IntervalToSaveToDB.ToString();
                thresholdToBDNode.InnerText  = ThresholdToBD.ToString();

                //channelNumberNode.InnerText = channelNumber.ToString();
                currentValueNode.InnerText = CalculatedValue.ToString();

                //selfIndexNode.InnerText = selfIndex.ToString();
                guidNode.InnerText = identifier.ToString();

                devManindexNode.InnerText       = devManindex.ToString();
                devManDescriptionNode.InnerText = devManDescription;

                decimalPointsNode.InnerText = decimalPoints.ToString();

                root.AppendChild(nameNode);
                root.AppendChild(descNode);

                root.AppendChild(unitsNode);
                root.AppendChild(alarmNode);

                root.AppendChild(blockingNode);
                root.AppendChild(controlAlarmNode);

                root.AppendChild(controlBlockingNode);
                if (rangeNode != null)
                {
                    root.AppendChild(rangeNode);
                }

                root.AppendChild(isSaveToDBNode);
                root.AppendChild(intervalToSaveNode);

                root.AppendChild(thresholdToBDNode);
                //root.AppendChild(channelNumberNode);

                root.AppendChild(currentValueNode);
                //root.AppendChild(selfIndexNode);

                root.AppendChild(devManindexNode);
                root.AppendChild(devManDescriptionNode);

                root.AppendChild(decimalPointsNode);

                root.AppendChild(guidNode);
                if (transformationNode != null)
                {
                    root.AppendChild(transformationNode);
                }

                return(root);
            }
            catch { }
            return(null);
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            if (args.Length != 0)
            {
                string[] commands = { "-a", "-l", "-r", "-c", "-u" };
                if (commands.Any(elem => elem.Equals(args[0])))
                {
                    string dbName = "MyDatabase.sqlite";

                    if (File.Exists(dbName))
                    {
                        //Console.WriteLine("Database already exist, connect to database...");
                        sqliteConnection = new SQLiteConnection("Data Source=" + dbName + ";Version=3;");
                        sqliteConnection.Open();
                        //Console.WriteLine("Connected to database");
                    }
                    else
                    {
                        //Console.WriteLine("Create database...");
                        SQLiteConnection.CreateFile(dbName);
                        //Console.WriteLine("Database created");
                        //Console.WriteLine("Connect to database");
                        sqliteConnection = new SQLiteConnection("Data Source=" + dbName + ";Version=3;");
                        sqliteConnection.Open();
                        //Console.WriteLine("Connected to database");
                    }
                    string        createTable = @"CREATE TABLE IF NOT EXISTS Todos(
                                           id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
                                           text NVARCHAR(2048) NOT NULL,
                                           createdAt DATETIME NOT NULL,
                                           completedAt DATETIME)";
                    SQLiteCommand command     = new SQLiteCommand(createTable, sqliteConnection);
                    command.ExecuteNonQuery();

                    switch (args[0])
                    {
                    case "-a":
                        if (args.Length == 1)
                        {
                            Console.WriteLine("Unable to add: no task provided");
                        }
                        else if (args.Length == 2)
                        {
                            TODO t = new TODO(args[1]);
                            SaveToDB.Save(t);
                        }
                        else
                        {
                            List <TODO> t = new List <TODO>();
                            for (int i = 1; i < args.Length; i++)
                            {
                                t.Add(new TODO(args[i].ToString()));
                            }
                            SaveToDB.SaveAll(t);
                        }
                        break;

                    case "-l":
                        if (args.Length == 1)
                        {
                            SaveToDB.LoadAll();
                        }
                        else
                        {
                            try
                            {
                                int x = Convert.ToInt32(args[1]);
                                try
                                {
                                    SaveToDB.Load(x);
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine(e.Message);
                                }
                            }
                            catch
                            {
                                string loadText = "";
                                for (int i = 1; i < args.Length; i++)
                                {
                                    if (i != args.Length - 1)
                                    {
                                        loadText += args[i].ToString() + " ";
                                    }
                                    else
                                    {
                                        loadText += args[i].ToString();
                                    }
                                }
                                try
                                {
                                    SaveToDB.Load(loadText);
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine(e.Message);
                                }
                            }
                        }
                        break;

                    case "-r":
                        if (args.Length == 1)
                        {
                            Console.WriteLine("Unable to remove: no index provided");
                        }
                        else
                        {
                            try
                            {
                                int x = Convert.ToInt32(args[1]);
                                try
                                {
                                    SaveToDB.RemoveElement(x);
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine(e.Message);
                                }
                            }
                            catch
                            {
                                throw new Exception("Unable to remove: index is not a number");
                            }
                        }
                        break;

                    case "-c":
                        if (args.Length == 1)
                        {
                            Console.WriteLine("Unable to check: no index provided");
                        }
                        else if (args.Length == 2)
                        {
                            try
                            {
                                int x = Convert.ToInt32(args[1]);
                                try
                                {
                                    SaveToDB.CheckCompleted(x);
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine(e.Message);
                                }
                            }
                            catch
                            {
                                throw new Exception("Unable to remove: index is not a number");
                            }
                        }
                        else
                        {
                            Console.WriteLine("Too much arguments");
                        }
                        break;

                    case "-u":
                        if (args.Length == 1)
                        {
                            Console.WriteLine("Unable to update: no id defined");
                        }
                        else if (args.Length == 3)
                        {
                            try
                            {
                                int x = Convert.ToInt32(args[1]);
                                try
                                {
                                    SaveToDB.UpdateElement(x, args[2]);
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine(e.Message);
                                }
                            }
                            catch
                            {
                                Console.WriteLine("");
                            }
                        }
                        else
                        {
                            Console.WriteLine("Too much arguments");
                        }
                        break;

                    default:
                        break;
                    }


                    sqliteConnection.Close();
                }
                else
                {
                    Console.WriteLine(args[0] + " nem egy létező paraméter");
                }
            }
            else
            {
                todos = new List <TODO>();
                bool tovabb = true;

                while (tovabb)
                {
                    string command = Console.ReadLine();
                    string arg     = "";
                    if (command.Length >= 2)
                    {
                        arg = command.Substring(0, 2);
                    }
                    string   parameter  = "";
                    string[] parameters = new string[0];
                    if (command.ToLower() != "exit")
                    {
                        string restArg = "";
                        if (command.Length >= 4)
                        {
                            restArg = command.Substring(3);
                        }

                        List <string> tempParamsList = new List <string>();
                        while (restArg != "")
                        {
                            if (restArg.IndexOf('"') == -1)
                            {
                                if (restArg.IndexOf(' ') == -1)
                                {
                                    parameter = restArg;
                                    tempParamsList.Add(parameter);
                                    parameters = new string[0];
                                    restArg    = "";
                                }
                                else
                                {
                                    parameters = restArg.Split(' ');
                                    foreach (string param in parameters)
                                    {
                                        tempParamsList.Add(param);
                                    }
                                    restArg = "";
                                }
                            }
                            else
                            {
                                if (restArg.Count(x => x == '"') % 2 == 0)
                                {
                                    if (restArg.IndexOf(' ') == -1)
                                    {
                                        parameter = restArg.Substring(1, restArg.Length - 2);
                                        tempParamsList.Add(parameter);
                                        restArg = "";
                                    }
                                    else
                                    {
                                        if (restArg.IndexOf('"') != 0 && restArg.ElementAt(restArg.IndexOf('"') - 1) != ' ')
                                        {
                                            restArg = restArg.Substring(0, restArg.IndexOf('"')) + " " + restArg.Substring(restArg.IndexOf('"'), restArg.Length - restArg.IndexOf('"'));
                                        }
                                        string tempStr;
                                        string tempSub = "";
                                        if (restArg.IndexOf('"') < restArg.IndexOf(" "))
                                        {
                                            tempSub = restArg.Substring(1);
                                            tempStr = tempSub.Substring(0, tempSub.IndexOf('"'));
                                            tempParamsList.Add(tempStr);
                                            if (tempSub.IndexOf('"') + 1 <= tempSub.Length - 1)
                                            {
                                                if (tempSub.ElementAt(tempSub.IndexOf('"') + 1) != ' ')
                                                {
                                                    tempSub = tempSub.Substring(0, tempSub.IndexOf('"') + 1) + ' ' + tempSub.Substring(tempSub.IndexOf('"'), tempSub.Length - tempSub.IndexOf('"'));
                                                }
                                                restArg = tempSub.Substring(tempSub.IndexOf('"') + 2, tempSub.Length - tempSub.IndexOf('"') - 2);
                                            }
                                            else
                                            {
                                                restArg = "";
                                            }
                                        }
                                        else if (restArg.IndexOf(" ") == -1)
                                        {
                                            if (tempSub.ElementAt(tempSub.IndexOf('"') + 1) != ' ')
                                            {
                                                tempSub = tempSub.Substring(0, tempSub.IndexOf('"') + 1) + ' ' + tempSub.Substring(tempSub.IndexOf('"'), tempSub.Length - tempSub.IndexOf('"'));
                                            }
                                            restArg = tempSub.Substring(tempSub.IndexOf('"') + 2, tempSub.Length - tempSub.IndexOf('"') - 2);
                                        }
                                        else
                                        {
                                            tempStr = restArg.Substring(0, restArg.IndexOf(' '));
                                            tempParamsList.Add(tempStr);
                                            restArg = restArg.Substring(restArg.IndexOf(' ') + 1);
                                        }
                                    }

                                    parameter = "";
                                }
                                else
                                {
                                    Console.WriteLine("Not right input format: Invalid number of \"");
                                    restArg = "";
                                }
                            }
                            // Console.WriteLine("itt tartunk");
                        }
                        parameters = tempParamsList.ToArray();
                    }
                    else
                    {
                        tovabb = false;
                    }



                    //string[] parameters;
                    TODO2._0.WorkInList workInList = new TODO2._0.WorkInList();
                    switch (arg)
                    {
                    case "-a":
                        if (parameters.Length == 1)
                        {
                            TODO t = new TODO(parameters[0]);
                            workInList.Save(t);
                        }
                        else if (parameters.Length != 0)
                        {
                            List <TODO> sa = new List <TODO>();
                            foreach (string task in parameters)
                            {
                                TODO t = new TODO(task);
                                sa.Add(t);
                            }
                            workInList.SaveAll(sa);
                        }
                        else
                        {
                            Console.WriteLine("Can not add items to the list: no task text specified");
                        }
                        break;

                    case "-l":
                        if (parameters.Length == 1)
                        {
                            try
                            {
                                int x = Convert.ToInt32(parameter);
                                try
                                {
                                    workInList.Load(x);
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine(e.Message);
                                }
                            }
                            catch
                            {
                                try
                                {
                                    workInList.Load(parameter);
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine(e.Message);
                                }
                            }
                        }
                        else if (parameters.Length == 0)
                        {
                            Console.WriteLine("List every task:");
                            workInList.LoadAll();
                        }
                        else
                        {
                            Console.WriteLine("Query failed: too much arguments specified, one or less needed (id- integer, string- text contains, nothing- for all)");
                        }
                        break;

                    case "-c":
                        if (parameters.Length == 0)
                        {
                            Console.WriteLine("No id specified");
                        }
                        else if (parameters.Length == 1)
                        {
                            try
                            {
                                int x = Convert.ToInt32(parameter);
                                try
                                {
                                    workInList.CheckCompleted(x);
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine(e.Message);
                                }
                            }
                            catch
                            {
                                Console.WriteLine($"Check failed: id must be an integer");
                            }
                        }
                        else
                        {
                            Console.WriteLine("Check failed: Too much argument specified only one id needed (integer- id of task)");
                        }
                        break;

                    case "-r":
                        if (parameters.Length == 0)
                        {
                            Console.WriteLine("Not right input format: You have to use id (integer) to remove an element");
                        }
                        else if (parameters.Length == 1)
                        {
                            try
                            {
                                int x = Convert.ToInt32(parameter);
                                try
                                {
                                    workInList.RemoveElement(x);
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine(e.Message);
                                }
                            }
                            catch
                            {
                                Console.WriteLine("Not right input format: You have to use id (integer) to remove an element");
                            }
                        }
                        else
                        {
                            Console.WriteLine("Not right input format: You have to use only one parameter (integer as id)");
                        }
                        break;

                    case "-u":
                        if (parameters.Length <= 1)
                        {
                            Console.WriteLine("Not enough parameters specified: you need to specify an id (integer) and a text (string) to update an element");
                        }
                        else if (parameters.Length == 2)
                        {
                            try
                            {
                                int x = Convert.ToInt32(parameters[0]);
                                try
                                {
                                    workInList.UpdateElement(x, parameters[1]);
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine(e.Message);
                                }
                            }
                            catch
                            {
                                Console.WriteLine("Update failed: first parameter must be an integer (id of the task)");
                            }
                        }
                        else
                        {
                            Console.WriteLine("Two much argument specified, you should use \" to update to more than one word");
                        }
                        break;

                    default:
                        Console.WriteLine($"No such a keyword: {arg}");
                        break;
                    }
                }
                Console.WriteLine("Nem adott meg paramétert");
            }

            /* try
             * {
             *   string[] lines = ReadLines("todo.txt");
             * }
             * catch (Exception e)
             * {
             *   Console.WriteLine(e);
             * }*/
            //Console.ReadKey();
        }