Esempio n. 1
0
    public void Join(BlobController other)
    {
        foreach (var split in GetComponentsInChildren <BlobSplitInteractible>())
        {
            split.enabled = false;
        }
        GetComponent <BlobSplitInteractible>().enabled = false;
        var blobs = new Stack <BlobController>();

        blobs.Push(other.root);
        while (blobs.Count > 0)
        {
            var cur = blobs.Pop();
            if (!cur.IsFull)
            {
                cur.AddChild(this);
                //cur.CalcJoints();
                return;
            }
            else
            {
                cur.children.ForEach(child => blobs.Push(child));
            }
        }
    }
Esempio n. 2
0
    public void Inherit(BlobController other)
    {
        this.damping        = other.damping;
        this.frequency      = other.frequency;
        this.size           = other.size;
        this.distance       = other.distance;
        this.force          = other.force;
        this.parent         = other;
        this.blobPrefab     = other.blobPrefab;
        this.ballGrowth     = other.ballGrowth;
        this.ballSize       = other.ballSize;
        this.horizontalCtrl = other.horizontalCtrl;
        this.fireButton     = other.fireButton;
        this.jumpButton     = other.jumpButton;
        this.layer          = other.layer;
        this.material       = other.material;
        this.dropMaterial   = other.dropMaterial;

        gameObject.layer = layer;
        foreach (Transform child in transform.GetComponentsInChildren <Transform>())
        {
            child.gameObject.layer = layer;
        }
        foreach (MeshRenderer renderer in transform.GetComponentsInChildren <MeshRenderer>())
        {
            renderer.material = material;
        }
        transform.parent = other.transform;
    }
Esempio n. 3
0
    public void OnAction(BlobController blob)
    {
        var dir = new Vector3(Input.GetAxis(blob.horizontalCtrl) / 2f, 1f, 0f);
        var vec = (dir).normalized * force;

        blob.GetComponent <Rigidbody2D>().AddForce(vec);
    }
Esempio n. 4
0
    public void CreateBlob(bool createJoint = true)
    {
        Debug.Log($"{gameObject.name}{transform.position}");
        if (this.IsFull)
        {
            int            min   = children.Min(child => child.Count);
            BlobController least = children.Find(child => child.Count == min);
            least.CreateBlob();
            return;
        }

        var newObj = new GameObject($"{this.gameObject.name}{children.Count}");

        newObj.name = $"{this.gameObject.name}{children.Count}";
        var blob     = newObj.AddComponent <BlobController>();
        var collider = newObj.AddComponent <CircleCollider2D>();
        var body     = newObj.AddComponent <Rigidbody2D>();
        var split    = newObj.AddComponent <BlobSplitInteractible>();
        var newModel = Instantiate(blobPrefab, blob.transform);

        split.enabled = false;
        blob.model    = newModel.transform;

        Debug.Log($"{newObj.name}{newObj.transform.position}");
        collider.sharedMaterial     = GetComponent <CircleCollider2D>().sharedMaterial;
        body.sharedMaterial         = GetComponent <Rigidbody2D>().sharedMaterial;
        body.interpolation          = GetComponent <Rigidbody2D>().interpolation;
        body.isKinematic            = GetComponent <Rigidbody2D>().isKinematic;
        body.collisionDetectionMode = GetComponent <Rigidbody2D>().collisionDetectionMode;
        AddChild(blob, createJoint);
        newObj.transform.localPosition = new Vector3(Random.Range(-1f, 1f) * size, size, 0f);
    }
Esempio n. 5
0
        public List <MonitoringFile> GetCollectedLogsForSession(string sessionId, string blobSasUri)
        {
            var filesCollected = new List <MonitoringFile>();

            if (string.IsNullOrWhiteSpace(blobSasUri))
            {
                string folderName = CpuMonitoring.GetLogsFolderForSession(sessionId);
                if (FileSystemHelpers.DirectoryExists(folderName))
                {
                    var logFiles = FileSystemHelpers.GetFilesInDirectory(folderName, "*.dmp", false, SearchOption.TopDirectoryOnly);
                    foreach (var fileName in logFiles)
                    {
                        string relativePath = MonitoringFile.GetRelativePath(sessionId, Path.GetFileName(fileName));
                        filesCollected.Add(new MonitoringFile(fileName, relativePath));
                    }
                }
            }
            else
            {
                string        directoryPath = Path.Combine("Monitoring", "Logs", sessionId);
                List <string> files         = new List <string>();
                var           dir           = BlobController.GetBlobDirectory(directoryPath, blobSasUri);
                foreach (
                    IListBlobItem item in
                    dir.ListBlobs(useFlatBlobListing: true))
                {
                    var    relativePath = item.Uri.ToString().Replace(item.Container.Uri.ToString() + "/", "");
                    string fileName     = item.Uri.Segments.Last();
                    filesCollected.Add(new MonitoringFile(fileName, relativePath));
                }
            }
            return(filesCollected);
        }
Esempio n. 6
0
    void Update()
    {
        if (isHidden)
        {
            return;
        }

        if (Input.GetMouseButton(0))
        {
            Vector2 swipe = (Vector2)Input.mousePosition - touchStart;

            // Change arrow rotation
            float angle = Vector2.SignedAngle(Vector2.up, swipe);
            arrowPivot.transform.rotation = Quaternion.Euler(0f, 0f, angle);

            // Change arrow size based on swipe magnitude
            float ySize = Mathf.Min(swipe.sqrMagnitude / minDragDistance, 1f);
            arrowPivot.transform.localScale = new Vector3(1f, ySize);

            // Change arrow color if angle is illegal
            if (BlobController.CheckJumpAngle(facingDirection, swipe,
                                              angleLimit))
            {
                arrowSprite.color = Color.white;
            }
            else
            {
                arrowSprite.color = Color.red;
            }
        }
    }
        public void TestFileUploadWrongDataScenario()
        {
            // Arrange
            using (BlobController controller = new BlobController(new BlobBL(new Blob())))
            {
                // Act
                string filePath = Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(Directory.GetCurrentDirectory())), "ProfileIcon.png");
                using (MultipartFormDataContent form = new MultipartFormDataContent())
                {
                    using (var fileContent = new ByteArrayContent(File.ReadAllBytes(filePath)))
                    {
                        fileContent.Headers.ContentType        = new MediaTypeWithQualityHeaderValue("application/json");
                        fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
                        {
                            FileName = "ProfileIcon.png"
                        };
                        form.Add(fileContent);

                        controller.Request = new HttpRequestMessage
                        {
                            Method  = HttpMethod.Post,
                            Content = form
                        };

                        var response = controller.FileUpload().Result;

                        //Assert
                        Assert.AreEqual(HttpStatusCode.UnsupportedMediaType, response.StatusCode);
                    }
                }
            }
        }
        public void TestFileUploadException()
        {
            // Arrange
            using (BlobController controller = new BlobController(new ToDoMockBlobService()))
            {
                // Act
                string filePath = Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(Directory.GetCurrentDirectory())), "ProfileIcon.png");
                using (MultipartFormDataContent form = new MultipartFormDataContent())
                {
                    using (var fileContent = new ByteArrayContent(File.ReadAllBytes(filePath)))
                    {
                        fileContent.Headers.ContentType        = new MediaTypeWithQualityHeaderValue("image/png");
                        fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
                        {
                            FileName = "ProfileIcon.png"
                        };
                        form.Add(fileContent);

                        controller.Request = new HttpRequestMessage
                        {
                            Method  = HttpMethod.Post,
                            Content = form
                        };

                        var response = controller.FileUpload().Result;

                        //Assert
                        Assert.AreEqual(HttpStatusCode.InternalServerError, response.StatusCode);
                    }
                }
            }
        }
 public void TestFixureSetup()
 {
     _userElasticsearch = new UserElasticsearch();
     _userRepository    = new UserRepository();
     // _userService = new UserService(_userElasticsearch,_userRepository,_breweryElasticsearch,_breweryRepository);
     _blobController = new BlobController(_userService);
 }
        public void TestDeleteWithContainerNameDefaultFile()
        {
            #region AddFile

            // Arrange
            using (BlobController controller1 = new BlobController(new BlobBL(new Blob())))
            {
                // Act
                string filePath = Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(Directory.GetCurrentDirectory())), "ProfileIcon.png");
                using (Stream stream = File.OpenRead(filePath))
                {
                    MyTestPostedFileBase file = new MyTestPostedFileBase(stream, "image/png", "ProfileIcon.png");
                    controller1.FileUpload(file);
                }
            }
            #endregion


            // Arrange
            using (BlobController controller = new BlobController(new BlobBL(new Blob())))
            {
                // Act
                var result = controller.DeleteFile(_defaultContainer);

                //Assert
                Assert.IsFalse(result.Data.ToString() == "error", "Exception occur so error.");
            }
        }
Esempio n. 11
0
        public static void DecideOnSensedClosestObject(BlobController blobController, SensedObjectModel sensedObject)
        {
            switch (sensedObject.Tag)
            {
            case TAG_WALL:
                blobController.RunAwayFrom(sensedObject.ContactPoint);
                Debug.Log(blobController.name + " running from wall");
                return;

            case TAG_FOOD:
                blobController.MoveTowards(sensedObject.ContactPoint);
                return;

            case TAG_BLOB:

                var otherBlob = sensedObject.Collider.GetComponent <BlobController>();

                if (blobController.CanEat(otherBlob))
                {
                    blobController.MoveTowards(sensedObject.ContactPoint);
                    return;
                }

                if (otherBlob.CanEat(blobController))
                {
                    blobController.RunAwayFrom(sensedObject.ContactPoint);
                    return;
                }

                return;
            }
        }
Esempio n. 12
0
 public void OnAction(BlobController blob)
 {
     /*
      * if (!IsGrounded) return;
      * var diff = -(transform.position - blob.root.transform.position).normalized;
      * var vec = new Vector3(diff.x * force, diff.y * force, 0f);
      * blob.GetComponent<Rigidbody2D>().AddForce(vec);
      * Debug.Log($"Applying force {vec.ToString()}");*/
 }
Esempio n. 13
0
 public void OnCollideWithBlob(BlobController other)
 {
     if (picked)
     {
         return;
     }
     other.ParentObject(gameObject);
     parent = other;
     picked = true;
 }
Esempio n. 14
0
        public void BlobUploadView_Test()
        {
            //Arrange
            var controller = new BlobController();

            //Actual
            ViewResult result = controller.UploadView() as ViewResult;

            //Assert
            Assert.IsNotNull(result);
        }
Esempio n. 15
0
    public void OnCollideWithBlob(BlobController other)
    {
        if (picked)
        {
            return;
        }
        other.CreateBlob();

        picked = true;
        Destroy(gameObject);
    }
Esempio n. 16
0
        public void BlobIndex_Test()
        {
            //Arrange
            var controller = new BlobController();

            //Actual
            ViewResult result = controller.Index(appDevBusiness) as ViewResult;

            //Assert
            Assert.IsNotNull(result);
        }
Esempio n. 17
0
        public static void RegisterConfiguration()
        {
            var storage        = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings[DefaultCloudConfigurationName].ConnectionString);
            var initialization = Task.WhenAll(
                BlobController.OneTimeInitializeAsync(storage),
                InboxController.OneTimeInitializeAsync(storage),
                WindowsPushNotificationClientController.OneTimeInitializeAsync(storage),
                AddressBookController.OneTimeInitializeAsync(storage));

            initialization.Wait();
        }
Esempio n. 18
0
 public bool HasSpringTo(BlobController other)
 {
     foreach (var spring in gameObject.GetComponents <SpringJoint2D>())
     {
         if (spring.connectedBody.GetComponent <BlobController>() == this)
         {
             return(true);
         }
     }
     return(false);
 }
        public void TestGetFileName()
        {
            // Arrange
            using (BlobController controller = new BlobController(new BlobBL(new Blob())))
            {
                // Act
                var result = controller.GetFileName();

                //Assert
                Assert.IsFalse(result.Data.ToString() == "error", "Exception occur so error.");
            }
        }
        public void TestDeleteWithContainerNameFile()
        {
            // Arrange
            using (BlobController controller = new BlobController(new BlobBL(new Blob())))
            {
                // Act
                var result = controller.DeleteFile(_testContainer);

                //Assert
                Assert.IsFalse(result.Data.ToString() == "error", "Exception occur so error.");
            }
        }
Esempio n. 21
0
        private void MoveToPermanentStorage(string sessionId, string sourceFile, string fileName, string blobSasUri)
        {
            if (string.IsNullOrWhiteSpace(blobSasUri))
            {
                var sessionDirectory = GetLogsFolderForSession(sessionId);
                var collectFileName  = Path.Combine(sessionDirectory, fileName);
                AppendToMonitoringLog($"Copying file from temp folders to [{collectFileName}]", true);
                try
                {
                    FileSystemHelpers.CopyFile(sourceFile, collectFileName);
                    AppendToMonitoringLog($"Copied file from temp folders to [{collectFileName}]", true);
                }
                catch (Exception ex)
                {
                    Logger.LogCpuMonitoringErrorEvent("Failed while moving file to Permanent FileSystem storage", ex, sessionId);
                }
            }
            else
            {
                try
                {
                    string relativeFilePath = Path.Combine("Monitoring", "Logs", sessionId, fileName);
                    Lease  lease            = Infrastructure.LeaseManager.TryGetLease(relativeFilePath, blobSasUri);
                    if (lease == null)
                    {
                        // This instance is already running this collector
                        Logger.LogCpuMonitoringVerboseEvent($"Could not get lease to upload the memory dump - {relativeFilePath}", sessionId);
                    }

                    AppendToMonitoringLog($"Copying {fileName} from temp folders to Blob Storage", true);
                    var accessCondition = AccessCondition.GenerateLeaseCondition(lease.Id);
                    var taskToUpload    = Task.Run(() =>
                    {
                        FileStream fileStream = new FileStream(sourceFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                        var blockBlob         = BlobController.GetBlobForFile(relativeFilePath, blobSasUri);
                        blockBlob.UploadFromStream(fileStream, accessCondition);
                    });

                    while (!taskToUpload.IsCompleted)
                    {
                        lease.Renew();
                        Logger.LogCpuMonitoringVerboseEvent($"Renewing lease to the blob file", sessionId);
                        Thread.Sleep(Infrastructure.Settings.LeaseRenewalTime);
                    }
                    lease.Release();
                    AppendToMonitoringLog($"Copied {fileName} from temp folders to Blob Storage", true);
                }
                catch (Exception ex)
                {
                    Logger.LogCpuMonitoringErrorEvent("Failed copying file to blob storage", ex, sessionId);
                }
            }
        }
        public void TestGetFileNameException()
        {
            // Arrange
            using (BlobController controller = new BlobController(new ToDoMockBlobService()))
            {
                // Act
                var result = controller.GetFileName();

                //Assert
                Assert.IsTrue(result.Data.ToString() == "error", "Exception occur so error.");
            }
        }
Esempio n. 23
0
        public void GetIndex()
        {
            BlobController controller = GetBlobController();

            ActionResult result = controller.Index();

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(ViewResult));

            ViewResult viewResult = (ViewResult)result;

            Assert.IsInstanceOfType(viewResult.ViewData.Model, typeof(IEnumerable <BlobViewModel>));
        }
Esempio n. 24
0
    public void OnCollideWithBlob(BlobController blob)
    {
        if (pickedUp)
        {
            return;
        }
        var pickup = Instantiate(pickUp, transform);

        pickup.GetComponent <WingInteractible>().OnCollideWithBlob(blob);

        Destroy(gameObject);
        pickedUp = true;
    }
        public void TestDeleteWithContainerNameDefaultFile()
        {
            #region AddFile

            // Arrange
            using (BlobController controllerBlob = new BlobController(new BlobBL(new Blob())))
            {
                // Act
                string filePath = Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(Directory.GetCurrentDirectory())), "ProfileIcon.png");
                using (MultipartFormDataContent form = new MultipartFormDataContent())
                {
                    using (var fileContent = new ByteArrayContent(File.ReadAllBytes(filePath)))
                    {
                        fileContent.Headers.ContentType        = new MediaTypeWithQualityHeaderValue("image/png");
                        fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
                        {
                            FileName = "ProfileIcon.png"
                        };
                        form.Add(fileContent);

                        controllerBlob.Request = new HttpRequestMessage
                        {
                            Method  = HttpMethod.Post,
                            Content = form
                        };

                        var response1 = controllerBlob.FileUpload().Result;
                    }
                }
            }


            #endregion


            // Arrange
            using (BlobController controller = new BlobController(new BlobBL(new Blob())))
            {
                controller.Request = new HttpRequestMessage
                {
                    Method = HttpMethod.Delete
                };

                // Act
                var response = controller.DeleteFile(_defaultContainer);

                //Assert
                Assert.IsTrue(response.IsSuccessStatusCode);
                Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            }
        }
Esempio n. 26
0
        public void GetDetails()
        {
            MockBlobService service    = new MockBlobService();
            BlobController  controller = GetBlobController(service);
            var             id         = service.GetBlobs().First().BlobId;

            ActionResult result = controller.Details(id);

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(ViewResult));

            ViewResult viewResult = (ViewResult)result;

            Assert.IsInstanceOfType(viewResult.ViewData.Model, typeof(BlobViewModel));
        }
Esempio n. 27
0
    public void AddChild(BlobController child, bool createJoint = true)
    {
        GetEveryConnectedBlob().ForEach(blob => blob.GetComponent <Rigidbody2D>().constraints = RigidbodyConstraints2D.FreezeAll);
        _children.Add(child);
        child.parent           = this;
        child.transform.parent = transform;
        child.name             = $"{gameObject.name}{children.Count}";

        child.Inherit(this);

        if (createJoint)
        {
            CreateSpring(child.GetComponent <Rigidbody2D>());
        }
        GetEveryConnectedBlob().ForEach(blob => blob.GetComponent <Rigidbody2D>().constraints = RigidbodyConstraints2D.None);
    }
Esempio n. 28
0
    public void OnCollideWithBlob(BlobController other)
    {
        if (picked)
        {
            return;
        }
        other.ParentObject(gameObject);
        var rigidBody = GetComponent <Rigidbody2D>();

        if (rigidBody)
        {
            Destroy(rigidBody);
        }
        parent = other;
        picked = true;
    }
        public void TestGetFileNameException()
        {
            // Arrange
            using (BlobController controller = new BlobController(new ToDoMockBlobService()))
            {
                controller.Request = new HttpRequestMessage
                {
                    Method = HttpMethod.Get
                };

                // Act
                var response = controller.GetFileName();

                //Assert
                Assert.AreEqual(HttpStatusCode.InternalServerError, response.StatusCode);
            }
        }
        public void TestFileUpload()
        {
            // Arrange
            using (BlobController controller = new BlobController(new BlobBL(new Blob())))
            {
                // Act
                string filePath = Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(Directory.GetCurrentDirectory())), "ProfileIcon.png");
                using (Stream stream = File.OpenRead(filePath))
                {
                    MyTestPostedFileBase obj = new MyTestPostedFileBase(stream, "image/png", "ProfileIcon.png");
                    var result = controller.FileUpload(obj, _defaultContainer);

                    //Assert
                    Assert.IsFalse(result.Data.ToString() == "error", "Exception occur so error.");
                }
            }
        }
		public void Enter (Enemy enemy)
		{
			this.enemy = (BlobController) enemy;
		}
Esempio n. 32
0
 void Start()
 {
     _blob = FindObjectOfType<BlobController>();
 }