示例#1
0
        public void Save(string username, string?info, DateTime?lastModified, string token)
        {
            var maxId  = _storageDb.StorageDb.AsEnumerable().Select(r => r.Id).DefaultIfEmpty(0).Max();
            var saveId = username + (maxId + 1);

            if (lastModified == null)
            {
                lastModified = DateTime.Now;
            }
            var newRecord = new DbRecord
            {
                User         = username,
                SaveId       = saveId,
                LastModified = lastModified.Value,
                Info         = info
            };

            try
            {
                _storageDb.Add(newRecord);
                _storageDb.SaveChanges();
            }
            catch (DbUpdateException e)
            {
                throw new StorageException("Adding failed to database", e);
            }

            RepoRequest.SaveRepo(saveId, token);
        }
示例#2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();

            services.AddDbContext <StorageDbContext>(options =>
                                                     options.UseSqlite(Configuration.GetConnectionString("DefaultConnection")));

            services.AddScoped <StorageService, StorageService>();

            RepoRequest.SetClient(Configuration["GatewayHost"], int.Parse(Configuration["GatewayPort"]));

            services.AddSwaggerGen(options =>
            {
                options.SwaggerDoc("v1", new OpenApiInfo
                {
                    Title       = "REAL.NET Storage API",
                    Version     = "v1",
                    Description = "Web API to store saves of REAL.NET Repository",
                });

                var basePath = AppContext.BaseDirectory;

                //Set the comments path for the swagger json and ui.
                var xmlPath = Path.Combine(basePath, "Storage.xml");
                options.IncludeXmlComments(xmlPath);
            });
        }
示例#3
0
        /// <summary>
        /// Implements actions before the request for Github's GraphQL API to determine if the request is ready to be made.
        /// </summary>
        /// <returns><c>true</c>, if request was befored, <c>false</c> otherwise.</returns>
        /// <param name="repoRequest">Repo request.</param>
        /// <param name="httpRequest">Http request.</param>
        public bool BeforeRequest(RepoRequest repoRequest, HttpRequestMessage httpRequest)
        {
            // For GraphQL, we're always a post and the same endpoint.
            httpRequest.RequestUri = s_ghGQLEndpoint;
            httpRequest.Method     = HttpMethod.Post;

            if (repoRequest is PullRequestRequest)
            {
                PullRequestRequest prRequest = (PullRequestRequest)repoRequest;

                // Add in the request query string post - check for the first time to use the prRequest
                string specificRepo = _currentKey;
                if (string.IsNullOrEmpty(_currentKey))
                {
                    _currentKey = prRequest.RepoName;
                }
                httpRequest.Content = new StringContent(GetJSONQueryString(prRequest.Organization, _nextCursor, _currentKey, prRequest.State), Encoding.UTF8, "application/json");

                return(true);
            }
            else
            {
                return(false);
            }
        }
        public void LoadModelTest()
        {
            RepoRequest.SetClient("localhost", 8000);
            var model = new RepoLoader().LoadModel("AirSimModel");

            Assert.AreEqual("AirSimModel", model.Name);
            Assert.AreEqual(19, model.Elements.Count());
        }
示例#5
0
 public void LoadRepo(string saveId, string token)
 {
     try
     {
         var toLoad = _storageDb.StorageDb.AsEnumerable().First(r => r.SaveId.Equals(saveId)).SaveId;
         RepoRequest.LoadRepo(toLoad, token);
     }
     catch (InvalidOperationException e)
     {
         throw new StorageException($"Save Id is not found: {saveId}", e);
     }
 }
        /// <summary>
        /// Implements actions before the request for Github's REST API to determine if the request is ready to be made.
        /// </summary>
        /// <returns><c>true</c>, if request was befored, <c>false</c> otherwise.</returns>
        /// <param name="repoRequest">Repo request.</param>
        /// <param name="httpRequest">Http request.</param>
        public bool BeforeRequest(RepoRequest repoRequest, HttpRequestMessage httpRequest)
        {
            if (repoRequest is PullRequestRequest)
            {
                PullRequestRequest prRequest = (PullRequestRequest)repoRequest;

                // First time this is false because no notion of making another request yet.
                Uri requestUri = null;
                if (!_makeAnotherRequest)
                {
                    // If no repo name, first get the list of repos and we'll need to go again
                    if (string.IsNullOrEmpty(prRequest.RepoName))
                    {
                        requestUri          = CreateRequestUri(prRequest.Organization);
                        _makeAnotherRequest = true;
                    }
                    // Otherwise, this will get them 'all' and pagination can decide for more
                    else
                    {
                        _repoList.Add(prRequest.RepoName);
                        requestUri = CreateRequestUri(prRequest.Organization, prRequest.RepoName, prRequest.State.ToString());
                    }
                }
                // Otherwise make we need to make the repo request and check pagination
                else
                {
                    // No next page, so don't request pagination
                    if (_nextPage == null)
                    {
                        // Nothing to do and no more repos
                        if (_repoList.Count < 1)
                        {
                            return(false);
                        }
                        requestUri = CreateRequestUri(prRequest.Organization, _repoList[0], prRequest.State.ToString());
                    }
                    else
                    {
                        requestUri = _nextPage;
                    }
                }

                httpRequest.RequestUri = requestUri;

                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#7
0
 private void LoadElements(string modelName,
                           ICollection <int> elementIds, ICollection <int> edgeIds)
 {
     foreach (var elementId in elementIds)
     {
         if (edgeIds.Contains(elementId))
         {
             var elementJson = RepoRequest.GetEdgeAsString(modelName, elementId);
             var element     = JsonConvert.DeserializeObject <Edge>(elementJson);
             _elementMap.Add(elementId, element);
         }
         else
         {
             var elementJson = RepoRequest.GetElementAsString(modelName, elementId);
             var element     = JsonConvert.DeserializeObject <Node>(elementJson);
             _elementMap.Add(elementId, element);
         }
     }
 }
示例#8
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            RepoRequest.SetClient(Configuration["GatewayHost"], int.Parse(Configuration["GatewayPort"]));

            services.AddControllers();

            services.AddSwaggerGen(options =>
            {
                options.SwaggerDoc("v1", new OpenApiInfo
                {
                    Title       = "REAL.NET Storage API",
                    Version     = "v1",
                    Description = "Web API to generate artifacts of REAL.NET",
                });

                var basePath = AppContext.BaseDirectory;

                //Set the comments path for the swagger json and ui.
                var xmlPath = Path.Combine(basePath, "Generator.xml");
                options.IncludeXmlComments(xmlPath);
            });
        }
示例#9
0
        public Model LoadModel(string modelName)
        {
            var modelJson = RepoRequest.GetModelAsString(modelName);
            var model     = JsonConvert.DeserializeObject <Model>(modelJson);

            if (!model.MetamodelName.Equals("InfrastructureMetamodel"))
            {
                LoadModel(model.MetamodelName);
            }

            var edgeIds    = model.Edges.Select(node => node.Id).ToList();
            var elementIds = model.Elements.Select(node => node.Id).ToList();

            LoadElements(modelName, elementIds, edgeIds);

            RestoreElements(elementIds, edgeIds);
            model.Elements = model.Elements.Select(element => _elementMap[element.Id]).ToList();
            model.Nodes    = model.Nodes.Select(element => (Node)_elementMap[element.Id]).ToList();
            model.Edges    = model.Edges.Select(element => (Edge)_elementMap[element.Id]).ToList();

            return(model);
        }
示例#10
0
 public bool BeforeRequest(RepoRequest repoRequest, HttpRequestMessage httpRequest)
 {
     httpRequest.RequestUri = new Uri("http://localhost:5000");
     return(!AbortRequest);
 }
示例#11
0
 public RepoLoader(string token)
 {
     RepoRequest.SetToken(token);
 }