Exemplo n.º 1
0
        private void OnMessage(FROM from, OscMessage message)
        {
            //ばもきゃ
            if (from == FROM.VMC && message.Address == "/VMC/Ext/OK")
            {
                calib = (int)message[1];
                Console.WriteLine(message);
            }
            if (from == FROM.VMC && message.Address == "/VMC/Ext/Tra/Pos/Local" && (string)message[0] == "LHR-B38070EB")
            {
                if (calib == 1)
                {
                    tx = (float)message[1];
                    ty = (float)message[2];
                    tz = (float)message[3];
                }
                //Console.WriteLine(message);
            }
            //Waidayo
            if (from == FROM.Waidayo && message.Address == "/VMC/Ext/Bone/Pos" && (string)message[0] == "Head")
            {
                float qx = (float)message[4];
                float qy = (float)message[5];
                float qz = (float)message[6];
                float qw = (float)message[7];

                object[]   arg = new object[] { "HeadLockTracker", tx, ty, tz, -qx, qy, -qz, qw };
                OscMessage m   = new OscMessage("/VMC/Ext/Tra/Pos", arg);
                OSCtoVMC.Send(m);
                Console.WriteLine(m);
            }
        }
Exemplo n.º 2
0
        private void OnBundle(FROM from, OscBundle bundle)
        {
            for (int i = 0; i < bundle.Count; i++)
            {
                switch (bundle[i])
                {
                //Messageを受信した
                case OscMessage msg:
                    OnMessage(from, msg);
                    break;

                default:
                    //Do noting
                    break;
                }
            }
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Branch([Required] string dbFrom, [Required] string dbTo)
        {
            if (!ModelState.IsValid)
            {
                return(base.BadRequest(ModelState));
            }
            if (dbFrom == dbTo)
            {
                return(base.BadRequest("新老数据库不能一样。"));
            }
            this.logger.LogInformation("Backup {0} to {1}", dbFrom, dbTo);

            string backPath = await GetBackupDirectory(this.db);

            string dataPath = await GetDataDirectory(this.db);

            string backFile = Path.Combine(backPath, $"{dbFrom}_{DateTime.Now:yyyyMMdd_HHmm}.bak");

            await this.db.ExecuteAsync(L("BACKUP DATABASE @dbName TO DISK=@location WITH INIT"), new
            {
                DbName   = dbFrom,
                Location = backFile,
            });

            var files = this.db
                        .Query(L("RESTORE FILELISTONLY FROM DISK = @backFile"), new { BackFile = backFile })
                        .Select(x => new { Name = (string)x.LogicalName, Path = (string)x.PhysicalName });
            string moves = string.Join(", ", files.Select(x =>
            {
                string newFileName = Regex.Replace(Path.GetFileName(x.Path), dbFrom, dbTo, RegexOptions.IgnoreCase);
                string dest        = Path.Combine(dataPath, $"{newFileName}");
                return($"\nMOVE N'{x.Name}' TO N'{dest}'");
            }));

            await this.db.ExecuteAsync(L(@$ "
                IF DB_ID(@to) IS NULL CREATE DATABASE {dbTo}
                ALTER DATABASE {dbTo} SET SINGLE_USER WITH ROLLBACK IMMEDIATE
                RESTORE DATABASE {dbTo} FROM DISK=@location WITH {moves}, REPLACE"), new
Exemplo n.º 4
0
        public HttpResponseMessage Get(string query, string accesstoken = "", double myLat = double.MaxValue, double myLon = double.MaxValue, double distance = double.MaxValue, FROM from = FROM.Services)
        {
            try
            {
                user usr = null;

                Session u = Server.currentUser.FirstOrDefault(z => z.accessToken == accesstoken);
                if (u != null)
                {
                    usr = u.user;
                }

                switch (from)
                {
                case FROM.Services:
                {
                    ICollection <service> result;
                    if (string.IsNullOrWhiteSpace(query))
                    {
                        result = Server.database.services.ToArray();
                    }
                    else
                    {
                        result = Server.database.services.Where(z => z.name.Contains(query)).ToArray();
                    }

                    if (result.Count == 0)
                    {
                        return(ControllerContext.Request.CreateResponse(HttpStatusCode.NotFound, "nothing found"));
                    }

                    if (myLat == double.MaxValue || myLon == double.MaxValue)
                    {
                        return(selectServicesDataToReturn(result, usr));
                    }


                    if (distance < 0)
                    {
                        return(ControllerContext.Request.CreateResponse(HttpStatusCode.BadRequest, "distance must by bigger then 0"));
                    }

                    return(selectServicesDataToReturn(
                               result.Where(z => ConvertCoordinatesToMeters(myLat, myLon, z.laititude ?? double.MaxValue, z.longitude ?? double.MaxValue) <= distance).ToArray(), usr));
                }

                case FROM.Offers:
                {
                    ICollection <offer> result;
                    if (string.IsNullOrWhiteSpace(query))
                    {
                        result = Server.database.offers.ToArray();
                    }
                    else
                    {
                        result = Server.database.offers.Where(z => z.name.Contains(query)).ToArray();
                    }
                    if (result.Count == 0)
                    {
                        return(ControllerContext.Request.CreateResponse(HttpStatusCode.NotFound, "nothing found"));
                    }
                    return(selectIoffersDataToReturn(result, usr));
                }

                case FROM.Users:
                {
                    if (string.IsNullOrWhiteSpace(query))
                    {
                        return(ControllerContext.Request.CreateResponse(HttpStatusCode.BadRequest, "the query can't be empty"));
                    }

                    if (Server.database.users.Where(z => z.username.Contains(query) ||
                                                    z.user_details.name.Contains(query) || z.user_details.lastname.Contains(query)).Count() == 0)
                    {
                        return(ControllerContext.Request.CreateResponse(HttpStatusCode.NotFound, "nothing found"));
                    }

                    return(ControllerContext.Request.CreateResponse(HttpStatusCode.OK,
                                                                    Server.database.users.Where(z => z.username.Contains(query) || z.user_details.name.Contains(query) ||
                                                                                                z.user_details.lastname.Contains(query)).ToArray().Select(
                                                                        z => new
                        {
                            username = z.username,
                            name = z.user_details.name,
                            lastname = z.user_details.lastname ?? "",
                            type = z.user_details.type,
                            followed = usr != null && usr.follows.Contains(z)
                        })));
                }

                default:
                    return(ControllerContext.Request.CreateResponse(HttpStatusCode.BadRequest, "Bad action"));
                }
            }
            catch (Exception ex)
            {
                Server.Loger(DateTime.Now + " - SearchController - " + ex.Message);
                return(ControllerContext.Request.CreateResponse(HttpStatusCode.InternalServerError, "internal server error"));
            }
        }
Exemplo n.º 5
0
        private void NextVector(Vertices v)
        {
            Vector2 up = new Vector2(0, -1) + f;
               Vector2 down = new Vector2(0, 1) + f;
               Vector2 left = new Vector2(-1, 0) + f;
               Vector2 right = new Vector2(1, 0) + f;

               int upf = 0, downf = 0, leftf = 0, rightf = 0;
               upf = CountFree(up);
               downf = CountFree(down);
               leftf = CountFree(left);
               rightf = CountFree(right);

               if (from == FROM.fromLeft)
               {
            if (downf != 0) { f += new Vector2(0, 1); from = FROM.fromUp; return; }
            if (!existXY(down, v) && getXY(down)) { f += new Vector2(0, 1); from = FROM.fromUp; return; }
            if (rightf != 0) { f += new Vector2(1, 0); from = FROM.fromLeft; return; }
            if (!existXY(right, v) && getXY(right)) { f += new Vector2(1, 0); from = FROM.fromLeft; return; }
            if (upf != 0) { f += new Vector2(0, -1); from = FROM.fromDown; return; }
            if (!existXY(up, v) && getXY(up)) { f += new Vector2(0, -1); from = FROM.fromDown; return; }

            if (maxInd(downf, rightf, upf) == 1 && downf != 0) { f += new Vector2(0, 1); from = FROM.fromUp; return; }
            if (maxInd(downf, rightf, upf) == 2 && rightf != 0) { f += new Vector2(1, 0); from = FROM.fromLeft; return; }
            if (maxInd(downf, rightf, upf) == 3 && upf != 0) { f += new Vector2(0, -1); from = FROM.fromDown; return; }

            if (leftf != 0) { f += new Vector2(-1, 0); from = FROM.fromRight; return; }
            if (getXY(left)) { f += new Vector2(-1, 0); from = FROM.fromRight; return; }
               }
               if (from == FROM.fromRight)
               {
            if (upf != 0) { f += new Vector2(0, -1); from = FROM.fromDown; return; }
            if (!existXY(up, v) && getXY(up)) { f += new Vector2(0, -1); from = FROM.fromDown; return; }
            if (leftf != 0) { f += new Vector2(-1, 0); from = FROM.fromRight; return; }
            if (!existXY(left, v) && getXY(left)) { f += new Vector2(-1, 0); from = FROM.fromRight; return; }
            if (downf != 0) { f += new Vector2(0, 1); from = FROM.fromUp; return; }
            if (!existXY(down, v) && getXY(down)) { f += new Vector2(0, 1); from = FROM.fromUp; return; }

            if (maxInd(upf, leftf, downf) == 1 && upf != 0) { f += new Vector2(0, -1); from = FROM.fromDown; return; }
            if (maxInd(upf, leftf, downf) == 2 && leftf != 0) { f += new Vector2(-1, 0); from = FROM.fromRight; return; }
            if (maxInd(upf, leftf, downf) == 3 && downf != 0) { f += new Vector2(0, 1); from = FROM.fromUp; return; }

            if (rightf != 0) { f += new Vector2(1, 0); from = FROM.fromLeft; return; }
            if (getXY(right)) { f += new Vector2(1, 0); from = FROM.fromLeft; return; }
               }
               if (from == FROM.fromUp)
               {
            if (leftf != 0) { f += new Vector2(-1, 0); from = FROM.fromRight; return; }
            if (!existXY(left, v) && getXY(left)) { f += new Vector2(-1, 0); from = FROM.fromRight; return; }
            if (downf != 0) { f += new Vector2(0, 1); from = FROM.fromUp; return; }
            if (!existXY(down, v) && getXY(down)) { f += new Vector2(0, 1); from = FROM.fromUp; return; }
            if (rightf != 0) { f += new Vector2(1, 0); from = FROM.fromLeft; return; }
            if (!existXY(right, v) && getXY(right)) { f += new Vector2(1, 0); from = FROM.fromLeft; return; }

            if (maxInd(leftf, downf, rightf) == 1 && leftf != 0) { f += new Vector2(-1, 0); from = FROM.fromRight; return; }
            if (maxInd(leftf, downf, rightf) == 2 && downf != 0) { f += new Vector2(0, 1); from = FROM.fromUp; return; }
            if (maxInd(leftf, downf, rightf) == 3 && rightf != 0) { f += new Vector2(1, 0); from = FROM.fromLeft; return; }

            if (upf != 0) { f += new Vector2(0, -1); from = FROM.fromDown; return; }
            if (getXY(up)) { f += new Vector2(0, -1); from = FROM.fromDown; return; }
               }
               if (from == FROM.fromDown)
               {
            if (rightf != 0) { f += new Vector2(1, 0); from = FROM.fromLeft; return; }
            if (!existXY(right, v) && getXY(right)) { f += new Vector2(1, 0); from = FROM.fromLeft; return; }
            if (upf != 0) { f += new Vector2(0, -1); from = FROM.fromDown; return; }
            if (!existXY(up, v) && getXY(up)) { f += new Vector2(0, -1); from = FROM.fromDown; return; }
            if (leftf != 0) { f += new Vector2(-1, 0); from = FROM.fromRight; return; }
            if (!existXY(left, v) && getXY(left)) { f += new Vector2(-1, 0); from = FROM.fromRight; return; }

            if (maxInd(rightf, upf, leftf) == 1 && rightf != 0) { f += new Vector2(1, 0); from = FROM.fromLeft; return; }
            if (maxInd(rightf, upf, leftf) == 2 && upf != 0) { f += new Vector2(0, -1); from = FROM.fromDown; return; }
            if (maxInd(rightf, upf, leftf) == 3 && leftf != 0) { f += new Vector2(-1, 0); from = FROM.fromRight; return; }

            if (downf != 0) { f += new Vector2(0, 1); from = FROM.fromUp; return; }
            if (getXY(down)) { f += new Vector2(0, 1); from = FROM.fromUp; return; }
               }
        }
Exemplo n.º 6
0
    // Method to print the process of reducing the adjacent and distinct letter
    private static List <string> ReduceAdjacentLetter(string inputString, FROM fromEnum)
    {
        int            minLength = inputString.Length;
        List <string>  step      = new List <string>();
        Queue <string> myQueue   = new Queue <string>();

        myQueue.Enqueue(inputString);
        bool allLetterAreSame = false;

        while (myQueue.Count > 0)
        {
            if (allLetterAreSame == true)
            {
                return(step);

                break;
            }

            string tempString = myQueue.Dequeue();
            char[] tempChar   = tempString.ToCharArray();

            // Update the minimum length of string required and Print the reduced string
            if (tempString.Length < minLength)
            {
                minLength = tempString.Length;
                step.Add(tempString);

                allLetterAreSame = true;
                for (int i = 0; i < tempString.Length - 1; i++)
                {
                    if (tempChar[i] != tempChar[i + 1])
                    {
                        allLetterAreSame = false;
                    }
                }
            }

            switch (fromEnum)
            {
            case FROM.FRONT:
                // Check the adjacent distinct letter from front
                for (int j = 0; j < tempString.Length; j++)
                {
                    if (j < tempString.Length - 1)
                    {
                        string substring = tempChar[j].ToString() + tempChar[j + 1].ToString();

                        if (substring == "ab" || substring == "ba")
                        {
                            string substring2 = "";

                            for (int k = 0; k < j; k++)
                            {
                                substring2 = string.Concat(substring2, tempChar[k].ToString());
                            }

                            // Change the adjacent and distinct letter
                            substring2 = string.Concat(substring2, "c");

                            for (int k = j + 2; k < tempChar.Length; k++)
                            {
                                substring2 = string.Concat(substring2, tempChar[k].ToString());
                            }

                            myQueue.Enqueue(substring2);
                        }
                        else if (substring == "bc" || substring == "cb")
                        {
                            string substring2 = "";

                            for (int k = 0; k < j; k++)
                            {
                                substring2 = string.Concat(substring2, tempChar[k].ToString());
                            }

                            // Change the adjacent and distinct letter
                            substring2 = string.Concat(substring2, "a");

                            for (int k = j + 2; k < tempChar.Length; k++)
                            {
                                substring2 = string.Concat(substring2, tempChar[k].ToString());
                            }

                            myQueue.Enqueue(substring2);
                        }
                        else if (substring == "ac" || substring == "ca")
                        {
                            string substring2 = "";

                            for (int k = 0; k < j; k++)
                            {
                                substring2 = string.Concat(substring2, tempChar[k].ToString());
                            }

                            // Change the adjacent and distinct letter
                            substring2 = string.Concat(substring2, "b");

                            for (int k = j + 2; k < tempString.Length; k++)
                            {
                                substring2 = string.Concat(substring2, tempChar[k].ToString());
                            }

                            myQueue.Enqueue(substring2);
                        }
                    }
                }
                break;

            case FROM.BACK:
                // Check the adjacent distinct letter from back
                for (int j = tempString.Length - 1; j >= 0; j--)
                {
                    if (j > 0)
                    {
                        string substring = tempChar[j].ToString() + tempChar[j - 1].ToString();

                        if (substring == "ab" || substring == "ba")
                        {
                            string substring2 = "";

                            for (int k = 0; k < j - 1; k++)
                            {
                                substring2 = string.Concat(substring2, tempChar[k].ToString());
                            }

                            // Change the adjacent and distinct letter
                            substring2 = string.Concat(substring2, "c");

                            for (int k = j + 1; k < tempChar.Length; k++)
                            {
                                substring2 = string.Concat(substring2, tempChar[k].ToString());
                            }

                            myQueue.Enqueue(substring2);
                        }
                        else if (substring == "bc" || substring == "cb")
                        {
                            string substring2 = "";

                            for (int k = 0; k < j - 1; k++)
                            {
                                substring2 = string.Concat(substring2, tempChar[k].ToString());
                            }

                            // Change the adjacent and distinct letter
                            substring2 = string.Concat(substring2, "a");

                            for (int k = j + 1; k < tempChar.Length; k++)
                            {
                                substring2 = string.Concat(substring2, tempChar[k].ToString());
                            }

                            myQueue.Enqueue(substring2);
                        }
                        else if (substring == "ac" || substring == "ca")
                        {
                            string substring2 = "";

                            for (int k = 0; k < j - 1; k++)
                            {
                                substring2 = string.Concat(substring2, tempChar[k].ToString());
                            }

                            // Change the adjacent and distinct letter
                            substring2 = string.Concat(substring2, "b");

                            for (int k = j + 1; k < tempChar.Length; k++)
                            {
                                substring2 = string.Concat(substring2, tempChar[k].ToString());
                            }

                            myQueue.Enqueue(substring2);
                        }
                    }
                }
                break;
            }
        }

        return(step);
    }