public bool Remove(IEntity entity)
        {
            entity = entity.MustNotBeNull(nameof(entity));

            switch (entity)
            {
            case Node node:
                if (node.Equals(HomeNode))
                {
                    HomeNode = null;
                }
                return(Nodes.Remove(node));

            case Reflector reflector:
                return(Reflectors.Remove(reflector));

            case Obstacle obstacle:
                return(Obstacles.Remove(obstacle));

            case StorageRow storageRow:
                return(StorageRows.Remove(storageRow));

            case StorageLocation storageLocation:
                return(StorageLocations.Remove(storageLocation));

            case VirtualPoint virtualPoint:
                return(VirtualPoints.Remove(virtualPoint));

            case NodeLink nodeLink:
                return(NodeLinks.Remove(nodeLink));

            default:
                return(false);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Reads a byte array from an S3 bucket
        /// </summary>
        /// <param name="location">The location of the data you want to read</param>
        /// <param name="guid">The guid of the content you're reading</param>
        /// <returns>A byte array interpretation of the data</returns>
        public byte[] ReadByteArray(StorageLocations location, string guid)
        {
            var keyName = string.Format("{0}/{1}.onx", StorageLocationToString(location), guid);
            var request = new GetObjectRequest().WithBucketName(Bucket).WithKey(keyName);

            return(VariousFunctions.StreamToByteArray(_client.GetObject(request).ResponseStream));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Reads a byte array from an S3 bucket
        /// </summary>
        /// <param name="location">The location of the data you want to read</param>
        /// <param name="guid">The guid of the content you're reading</param>
        /// <returns>A byte array interpretation of the data</returns>
        public byte[] ReadByteArray(StorageLocations location, string guid)
        {
            var keyName = string.Format("{0}/{1}.onx", StorageLocationToString(location), guid);
            var request = new GetObjectRequest().WithBucketName(Bucket).WithKey(keyName);

            return VariousFunctions.StreamToByteArray(_client.GetObject(request).ResponseStream);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Reads a string from an S3 bucket
        /// </summary>
        /// <param name="location">The location of the data you want to read</param>
        /// <param name="guid">The guid of the content you're reading</param>
        /// <returns>A string interpretation of the data</returns>
        public string ReadString(StorageLocations location, string guid)
        {
            var keyName = string.Format("{0}/{1}.onx", StorageLocationToString(location), guid);
            var request = new GetObjectRequest().WithBucketName(Bucket).WithKey(keyName);

            return new StreamReader(_client.GetObject(request).ResponseStream, Encoding.ASCII).ReadToEnd();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Method for retrieving the game storage - results of the questionnaire
        /// </summary>
        /// <returns> Dictionary containing the group as key and the value of the questionnaire, is possible - null otherwise </returns>
        internal Dictionary <string, double> getQuestionnaireResultFromGameStorage()
        {
            StorageLocations       storageLocation = StorageLocations.Local;
            GameStorageClientAsset gameStorage     = getGameStorageAsset();

            String model = "PlayerProfilingAsset_" + ((PlayerProfilingAssetSettings)getPPA().Settings).PlayerId + "_" + getQuestionnaireData().id;

            Boolean isStructureRestored = gameStorage.LoadStructure(model, storageLocation, SerializingFormat.Xml);
            Boolean isDataRestored      = gameStorage.LoadData(model, StorageLocations.Local, SerializingFormat.Xml);

            if (isStructureRestored && isDataRestored)
            {
                loggingPPA("Questionnaire results were restored from local file.");
                Dictionary <string, double> results = new Dictionary <string, double>();
                foreach (Node node in storage[model].Children)
                {
                    results.Add(node.Name, (double)node.Value);
                }
                questionnaireResults = results;
                return(results);
            }
            else
            {
                loggingPPA("Questionnaire results could not be restored from local file!");
                return(null);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Reads a string from an S3 bucket
        /// </summary>
        /// <param name="location">The location of the data you want to read</param>
        /// <param name="guid">The guid of the content you're reading</param>
        /// <returns>A string interpretation of the data</returns>
        public string ReadString(StorageLocations location, string guid)
        {
            var keyName = string.Format("{0}/{1}.onx", StorageLocationToString(location), guid);
            var request = new GetObjectRequest().WithBucketName(Bucket).WithKey(keyName);


            return(new StreamReader(_client.GetObject(request).ResponseStream, Encoding.ASCII).ReadToEnd());
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Creates container in given location with given name (optional)
        /// Notice that provisioning of container can take up to 15 minutes
        /// </summary>
        /// <param name="bearerKey">authentication key. - for now pass through constructor.</param>
        /// <param name="subscriptionKey">user authentication key from Veracity portal</param>
        /// <param name="baseProvisioningApiUrl">url to Veracity ProvisioningAPI</param>
        /// <param name="location">StoraLocation where container will be stored</param>
        /// <param name="containerName">name of container, optional</param>
        /// <returns></returns>
        static async Task CreateContainer(string bearerKey, string subscriptionKey, string baseProvisioningApiUrl,
                                          StorageLocations location, string containerName = null)
        {
            var provisioningApi = new ProvisioningApi(bearerKey, subscriptionKey, baseProvisioningApiUrl);
            var provision       = await provisioningApi.ProvisionContainer(location, containerName);

            Console.WriteLine(provision);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Writes byte array data into an S3 Bucket
        /// </summary>
        /// <param name="data">The byte array data to write to the bucket.</param>
        /// <param name="location">The location as to where you want to save the data</param>
        /// <param name="guid">The guid of the content you're uploading</param>
        public void WriteObject(string data, StorageLocations location, string guid)
        {
            var keyName = string.Format("{0}/{1}.onx", StorageLocationToString(location), guid);

            var request = new PutObjectRequest();

            request.WithContentBody(data)
            .WithBucketName(Bucket)
            .WithKey(keyName);

            S3Response response = _client.PutObject(request);

            response.Dispose();
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Turns a StorageLocations enum into a key path
        /// </summary>
        /// <param name="location">The storage location enum</param>
        /// <returns>Corresponding key path</returns>
        private static string StorageLocationToString(StorageLocations location)
        {
            switch (location)
            {
            case StorageLocations.Solution:
                return("solutions");

            case StorageLocations.Stfs:
                return("stfs");

            default:
                throw new InvalidOperationException();
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Writes byte array data into an S3 Bucket
        /// </summary>
        /// <param name="data">The byte array data to write to the bucket.</param>
        /// <param name="location">The location as to where you want to save the data</param>
        /// <param name="guid">The guid of the content you're uploading</param>
        public void WriteObject(byte[] data, StorageLocations location, string guid)
        {
            // Do upload
            var stream  = new MemoryStream(data);
            var keyName = string.Format("{0}/{1}.onx", StorageLocationToString(location), guid);
            var request = new PutObjectRequest();

            request.WithBucketName(Bucket).WithKey(keyName).WithInputStream(stream);

            // Response
            S3Response response = _client.PutObject(request);

            response.Dispose();
            stream.Dispose();
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Method for storing data via game storage
        /// </summary>
        /// <param name="results"> Dictionary containing the group as key and the value of the questionnaire </returns>
        internal void storeQuestionnaireResultViaGameStorage(Dictionary <string, double> results)
        {
            StorageLocations       storageLocation = StorageLocations.Local;
            GameStorageClientAsset gameStorage     = getGameStorageAsset();

            String model = "PlayerProfilingAsset_" + ((PlayerProfilingAssetSettings)getPPA().Settings).PlayerId + "_" + getQuestionnaireData().id;

            foreach (String group in results.Keys)
            {
                gameStorage[model].AddChild(group, storageLocation).Value = results[group];
            }


            gameStorage.SaveStructure(model, storageLocation, SerializingFormat.Xml);
            gameStorage.SaveData(model, storageLocation, SerializingFormat.Xml);
        }
        /// <summary>
        /// Creates new storage container in given location with optionally given name
        /// </summary>
        /// <param name="storageLocation">location of storage container</param>
        /// <param name="containerShortName">container name, optional</param>
        /// <returns>Error if operation failed, Accepted - when success</returns>
        public async Task <string> ProvisionContainer(StorageLocations storageLocation, string containerShortName = null)
        {
            var uri = $"{_baseProvisioningApiUrl}container";

            var containerInput = new ContainerInput
            {
                ContainerShortName     = containerShortName,
                MayContainPersonalData = false,
                StorageLocation        = storageLocation.ToString()
            };

            var response = await _httpClient.PostAsync(uri, new StringContent(JsonConvert.SerializeObject(containerInput), Encoding.UTF8, "application/json"));

            var responseContent = await response.Content.ReadAsStringAsync();

            return(response.IsSuccessStatusCode ? response.ReasonPhrase : responseContent);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Creates new storage container in given location with optionally given name
        /// </summary>
        /// <param name="storageLocation">location of storage container</param>
        /// <param name="containerShortName">container name, optional</param>
        /// <returns>Error if operation failed, Accepted - when success</returns>
        public async Task <string> ProvisionContainer(StorageLocations storageLocation, string containerShortName = null)
        {
            var queryString = HttpUtility.ParseQueryString(string.Empty);

            if (!string.IsNullOrEmpty(containerShortName))
            {
                queryString["containerShortName"] = containerShortName;
            }

            var requestCode = Guid.NewGuid().ToString();

            var uri  = $"{_baseProvisioningApiUrl}container?storageLocation={storageLocation}&requestCode={requestCode}&{queryString}";
            var body = JsonConvert.SerializeObject(new { StorageLocation = storageLocation.ToString(), RequestCode = requestCode, ContainerShortName = containerShortName });

            var response = await _httpClient.PostAsync(uri, new StringContent(body, Encoding.UTF8, "application/json"));

            var responseContent = await response.Content.ReadAsStringAsync();

            return(response.IsSuccessStatusCode ? response.ReasonPhrase : responseContent);
        }
Ejemplo n.º 14
0
 public void CreateStorageLocations(StorageLocations StorageLocations)
 {
     _context.Add(StorageLocations);
     _context.SaveChanges();
 }
Ejemplo n.º 15
0
        /// <summary>
        /// Writes byte array data into an S3 Bucket
        /// </summary>
        /// <param name="data">The byte array data to write to the bucket.</param>
        /// <param name="location">The location as to where you want to save the data</param>
        /// <param name="guid">The guid of the content you're uploading</param>
        public void WriteObject(byte[] data, StorageLocations location, string guid)
        {
            // Do upload
            var stream = new MemoryStream(data);
            var keyName = string.Format("{0}/{1}.onx", StorageLocationToString(location), guid);
            var request = new PutObjectRequest();
            request.WithBucketName(Bucket).WithKey(keyName).WithInputStream(stream);

            // Response
            S3Response response = _client.PutObject(request);
            response.Dispose();
            stream.Dispose();
        }
Ejemplo n.º 16
0
 public void DeleteStorageLocations(StorageLocations StorageLocations)
 {
     StorageLocations.IsDeleted = true;
     _context.StorageLocations.Update(StorageLocations);
     _context.SaveChanges();
 }
 public void  UpdateStorageLocations([FromBody] StorageLocations StorageLocations)
 {
     _repository.UpdateStorageLocations(StorageLocations);
 }
Ejemplo n.º 18
0
        /// <summary>
        /// Turns a StorageLocations enum into a key path
        /// </summary>
        /// <param name="location">The storage location enum</param>
        /// <returns>Corresponding key path</returns>
        private static string StorageLocationToString(StorageLocations location)
        {
            switch (location)
            {
                case StorageLocations.Solution:
                    return "solutions";
                case StorageLocations.Stfs:
                    return "stfs";

                default:
                    throw new InvalidOperationException();
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Writes byte array data into an S3 Bucket
        /// </summary>
        /// <param name="data">The byte array data to write to the bucket.</param>
        /// <param name="location">The location as to where you want to save the data</param>
        /// <param name="guid">The guid of the content you're uploading</param>
        public void WriteObject(string data, StorageLocations location, string guid)
        {
            var keyName = string.Format("{0}/{1}.onx", StorageLocationToString(location), guid);

            var request = new PutObjectRequest();
            request.WithContentBody(data)
                .WithBucketName(Bucket)
                .WithKey(keyName);

            S3Response response = _client.PutObject(request);
            response.Dispose();
        }
 public void  DeleteStorageLocations([FromBody] StorageLocations StorageLocations)
 {
     _repository.DeleteStorageLocations(StorageLocations);
 }
Ejemplo n.º 21
0
 public void UpdateStorageLocations(StorageLocations StorageLocations)
 {
     _context.StorageLocations.Update(StorageLocations);
     _context.SaveChanges();
 }