示例#1
0
        public async Task <string> CreateCommand(Req <ExecuteSqlDto> request)
        {
            var helper = GetReadHelper();

            if (new int[] { 1, 2, 3, 5 }.Contains(request.Data.Authority))
            {
                var admin = await helper.FirstOrDefault_Async <DbSysAdmin>(new { Id = request.Data.AdminId, IsDelete = false, IsFrozen = false });

                if (admin == null)
                {
                    return("ERROR:当前用户不存在!");
                }
                var oldp = DataUtil.CreatePassword(admin.Name, admin.Salt, request.Data.Password);
                if (oldp != admin.ManagerPassword)
                {
                    return("ERROR:密码错误!");
                }
            }
            string sql = @"select conn.Id,conn.Name,conn.SqlType,conn.ConnectionString,pass.ReadMaxRows,pass.ChangeMaxRows
from SqlConn conn
inner join SqlConnPass pass on pass.ConnId=conn.Id
inner join SysAdmin_Group g on g.GroupId=pass.AdminGroupId
where conn.IsDelete=0 and pass.IsDelete=0 and g.AdminId=@0 and conn.Id=@1 ";

            if (request.Data.Authority == 1)
            {
                sql += " and pass.CanEdit=1";
            }
            else if (request.Data.Authority == 2)
            {
                sql += " and pass.CanDelete=1";
            }
            else if (request.Data.Authority == 3)
            {
                sql += " and pass.AllPermissions=1";
            }
            else if (request.Data.Authority == 4)
            {
                sql += " and pass.CanDownload=1";
            }
            else if (request.Data.Authority == 5)
            {
                sql += " and pass.CanDownload=1 and pass.AllPermissions=1";
            }
            sql += " limit 1";
            var connDto = await helper.FirstOrDefault_Async <SqlConnDto>(sql, request.Data.AdminId, request.Data.SqlConnId);

            if (connDto == null)
            {
                return("ERROR:该数据库无法访问!");
            }
            var         provider    = SqlCache.Instance.GetSqlCommonProvider(connDto.SqlType);
            var         cmd         = provider.CreateCommand(connDto.ConnectionString, request.Data.Database);
            TempCommand tempCommand = new TempCommand()
            {
                Command       = cmd,
                ReadMaxRows   = connDto.ReadMaxRows,
                ChangeMaxRows = connDto.ChangeMaxRows,
                SqlType       = connDto.SqlType,
                CreateTime    = DateTime.Now,
                Name          = connDto.Name,
                Authority     = request.Data.Authority
            };
            var key = Guid.NewGuid().ToString();

            _commandDict[key] = tempCommand;
            return(key);
        }
示例#2
0
        public static void Part2()
        {
            char[] Line = new char[] { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p' };

            // Test
            //Line = null;
            //Line = new char[] { 'a', 'b', 'c', 'd', 'e' };

            string Input = File.ReadAllText("/Users/jakobbussas/Projects/AdventOfCode/2017/Day16/Day16/Day16.txt");

            // Test
            //Input = "s1,x3/4,pe/b";

            string[] Commands = Input.Split(',');

            // Hilfsvariablen für mehr Übersichtlichkeit
            string TempCommand;
            int    TempA;
            int    TempB;

            // Dance 1000000000 times
            // Idee: Man testet wieviele Iterationen es dauert bis sich das Muster wiederholt
            List <string> SeenLines  = new List <string>();
            string        AfterDance = "abcdefghijklmnop";

            for (int i = 0; i < 40; i++)
            {
                SeenLines.Add(AfterDance);

                foreach (var Command in Commands)
                {
                    switch (Command[0])
                    {
                    case 's':
                        // Spin
                        TempCommand = Command.Substring(1);
                        TempA       = Convert.ToInt32(TempCommand);

                        Spin(ref Line, TempA);
                        break;

                    case 'x':
                        // Exchange
                        TempCommand = Command.Substring(1);
                        string[] TempParts = TempCommand.Split('/');

                        TempA = Convert.ToInt32(TempParts[0]);
                        TempB = Convert.ToInt32(TempParts[1]);

                        Exchange(ref Line, TempA, TempB);
                        break;

                    case 'p':
                        // Partner
                        TempCommand = Command.Substring(1);
                        string[] TempParts2 = TempCommand.Split('/');

                        Partner(ref Line, TempParts2[0][0], TempParts2[1][0]);
                        break;

                    default:
                        throw new Exception("Unknown Command: " + Command[0]);
                    }
                }

                AfterDance = new string(Line);

                if (SeenLines.Contains(AfterDance))
                {
                    Console.WriteLine("HEUREKA! Wiederholung nach " + i + " Dances");
                    break;
                }
            }

            Console.WriteLine();
            Console.Write("After 40 dances: ");
            foreach (var element in Line)
            {
                Console.Write(element);
            }
            Console.WriteLine();

            // Nach 60 Wiederholt sich der Zyklus
            // 1000000000 % 60 = 40
            // Nach 40 Dances
            // gjmiofcnaehpdlbk
        }
示例#3
0
        void ParseRXData()
        {
            if (sw)
            {
                aTimer.Stop();
            }

            string TempCommand;

            if (FindString(LastRXData, "#data") == true)
            {
                TempCommand  = LastRXData.Substring(6, LastRXData.Length - 6);
                ParserBuffer = TempCommand.Split(',');

                int i = 0;
                while (i < ParserBuffer.Length - 1)
                {
                    try
                    {
                        var      tmp     = ParserBuffer[i].Split('-');
                        DateTime tmpdate = new DateTime(2000 + Convert.ToInt16(tmp[0]), Convert.ToInt16(tmp[1]), Convert.ToInt16(tmp[2]), Convert.ToInt16(tmp[3]), Convert.ToInt16(tmp[4]), 0);
                        var      Val1    = Double.Parse(ParserBuffer[i + 1]);
                        var      Val2    = Double.Parse(ParserBuffer[i + 2]);
                        var      Val3    = Double.Parse(ParserBuffer[i + 3]);


                        if (Val1 > 80 || Val1 < -20 || ((Math.Abs(LastVal - Val3) > 30) && (LastVal != 0)))
                        {
                            Console.WriteLine("Out of Range Data : " + Val1.ToString());
                        }
                        else
                        {
                            if (LogRecordArray.Count == 0)
                            {
                                AddData(tmpdate, Val1, Val2, Val3);
                            }
                            else if (LogRecordArray[(LogRecordArray.Count - 1)].GetTime().Hour < tmpdate.Hour)
                            {
                                AddData(tmpdate, Val1, Val2, Val3);
                            }

                            LastVal = Val3;
                        }
                        XAxis++;
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Parse-Add Error > " + e.ToString());
                        Console.WriteLine("Details Time: " + ParserBuffer[i] + ",Value:" + ParserBuffer[i + 1]);
                    }
                    i += 4;
                }
            }

            aTimer          = new System.Timers.Timer();
            aTimer.Interval = 2000;

            // Hook up the Elapsed event for the timer.
            aTimer.Elapsed += result;

            // Have the timer fire repeated events (true is the default)
            aTimer.AutoReset = true;

            // Start the timer
            aTimer.Enabled = true;

            sw = true;
        }
示例#4
0
        public static void Part1()
        {
            char[] Line = new char[] { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p' };

            // Test
            //Line = null;
            //Line = new char[] { 'a', 'b', 'c', 'd', 'e' };

            string Input = File.ReadAllText("/Users/jakobbussas/Projects/AdventOfCode/2017/Day16/Day16/Day16.txt");

            // Test
            //Input = "s1,x3/4,pe/b";

            string[] Commands = Input.Split(',');

            // Hilfsvariablen für mehr Übersichtlichkeit
            string TempCommand;
            int    TempA;
            int    TempB;

            foreach (var Command in Commands)
            {
                switch (Command[0])
                {
                case 's':
                    // Spin
                    TempCommand = Command.Substring(1);
                    TempA       = Convert.ToInt32(TempCommand);

                    Spin(ref Line, TempA);
                    break;

                case 'x':
                    // Exchange
                    TempCommand = Command.Substring(1);
                    string[] TempParts = TempCommand.Split('/');

                    TempA = Convert.ToInt32(TempParts[0]);
                    TempB = Convert.ToInt32(TempParts[1]);

                    Exchange(ref Line, TempA, TempB);
                    break;

                case 'p':
                    // Partner
                    TempCommand = Command.Substring(1);
                    string[] TempParts2 = TempCommand.Split('/');

                    Partner(ref Line, TempParts2[0][0], TempParts2[1][0]);
                    break;

                default:
                    throw new Exception("Unknown Command: " + Command[0]);
                }
            }

            Console.Write("After 1 dance: ");
            foreach (var element in Line)
            {
                Console.Write(element);
            }
            Console.WriteLine();
        }