Exemple #1
0
        public async Task <IActionResult> Grid([FromBody] GridAPI Model)
        {
            if (Model.FirstSequence == null || Model.SecondSequence == null)
            {
                return(BadRequest());
            }
            if (!Regex.IsMatch(Model.FirstSequence, @"^[a-zA-Z]+$") || !Regex.IsMatch(Model.FirstSequence, @"^[a-zA-Z]+$"))
            {
                return(BadRequest());
            }
            //if (Model.FirstSequence.Length <= 20000 || Model.FirstSequence.Length <= 20000)
            //    return BadRequest();

            // Check for earlier exist
            AlignmentJob SeqFound = Repo.AreExist(Model.FirstSequence, Model.SecondSequence, Model.ScoringMatrix, Model.Gap);

            if (SeqFound == null) // Means the user didn't  submit these sequences before.
            {
                string AlignmentID = Guid.NewGuid().ToString();
                // Storing in the database
                await Repo.AddAlignmentJobAsync(new AlignmentJob
                {
                    AlignmentID          = AlignmentID,
                    ScoringMatrix        = Model.ScoringMatrix,
                    Algorithm            = "Edge",
                    FirstSequenceHash    = Helper.SHA1HashStringForUTF8String(Model.FirstSequence),
                    SecondSequenceHash   = Helper.SHA1HashStringForUTF8String(Model.SecondSequence),
                    FirstSequenceName    = "Sequence First Name",
                    SecondSequenceName   = "Sequence Second Name",
                    IsAlignmentCompleted = false,
                    ByteText             = Helper.SetTextGrid(Model.FirstSequence, Model.SecondSequence),
                    UserFK = (await UserManager.FindByEmailAsync(Model.Email)).Id
                });

                // Sending to the Grid, that there is a job is required from you
                // New up instance of SignalR HubConnection with the URL of the SignalR Server Hosting.
                HubConnection connection = new HubConnection(@"http://mtidna.azurewebsites.net");
                // Connect to the Grid SignalR Hub.
                IHubProxy _hub = connection.CreateHubProxy("GridHub");
                // Connecting to the server.
                await connection.Start(); // Start the connection

                await _hub.Invoke("SendToGrid", Newtonsoft.Json.JsonConvert.SerializeObject(new GridInfo {
                    AlignmentJobId = AlignmentID, Email = Model.Email
                }));                                                                                                                                              // Invoke Alignment SignalR Method, and pass the Job Id to the Grid.

                return(Ok("Grid OK"));
            }
            else
            {
                if (SeqFound.IsAlignmentCompleted == false)
                {
                    return(Ok("Grid Wait")); // Returning the same Alignment ID
                }
                else // the grid already alignment them , so no action is required from the grid, the user can download a text file directly.
                {
                    return(Ok("Grid Check History"));
                }
            }
        }
Exemple #2
0
        public string PositionToGrid(Vector3 position)
        {
            if (GridAPI != null)
            {
                string[] g = (string[])GridAPI.CallHook("GetGrid", position);
                return(string.Concat(g));
            }
            else
            {
                // From GrTeleport
                Vector2 r = new Vector2((World.Size / 2) + position.x, (World.Size / 2) + position.z);
                float   x = Mathf.Floor(r.x / 146.3f) % 26;
                float   z = Mathf.Floor(World.Size / 146.3f) - Mathf.Floor(r.y / 146.3f);

                return($"{(char)('A' + x)}{z - 1}");
            }
        }