Exemplo n.º 1
0
        public ActionResult Create(CmdbItem item)
        {
            if (ModelState.IsValid)
            {
                CmdbRepository.Instance.Graph.AddVertex(item);
                //db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(item);
        }
Exemplo n.º 2
0
        //private void InitDb(CmdbItemCategory applicationCategory, CmdbAttributeDefinition applicationTypeAttribute, CmdbAttributeDefinition languageAttribute, CmdbAttributeDefinition operationSystemAttribute, CmdbAttributeDefinition itOwnerAttribute)
        //{
        //    var RaDaR = new CmdbItem(applicationCategory, 1, "RaDaR") {Description = "Risk Front End"};
        //    RaDaR.Attributes[applicationTypeAttribute.Id] = "Desktop";
        //    RaDaR.Attributes[languageAttribute.Id] = "C#/WPF";
        //    RaDaR.Attributes[operationSystemAttribute.Id] = "Windows";
        //    RaDaR.Attributes[itOwnerAttribute.Id] = "Dave Collis";
        //    var RTS = new CmdbItem(applicationCategory, 2, "RTS") {Description = "Risk Terms Service"};
        //    RTS.Attributes[applicationTypeAttribute.Id] = "Service";
        //    RTS.Attributes[languageAttribute.Id] = "Java";
        //    RTS.Attributes[operationSystemAttribute.Id] = "Linux";
        //    RTS.Attributes[itOwnerAttribute.Id] = "Sam Ratcliff";
        //    var SDS = new CmdbItem(applicationCategory, 3, "SDS") {Description = "Static Data Service"};
        //    SDS.Attributes[applicationTypeAttribute.Id] = "Service";
        //    SDS.Attributes[languageAttribute.Id] = "Java";
        //    SDS.Attributes[operationSystemAttribute.Id] = "Linux";
        //    SDS.Attributes[itOwnerAttribute.Id] = "Ting Hau";
        //    var RaDaR_RTS = new CmdbDependency(1, RaDaR, RTS);
        //    var RTS_SDS = new CmdbDependency(2, RTS, SDS);
        //    _nodesAdapter.Create(RaDaR);
        //    _nodesAdapter.Create(RTS);
        //    _nodesAdapter.Create(SDS);
        //    _edgesAdapter.Create(RaDaR_RTS);
        //    _edgesAdapter.Create(RTS_SDS);
        //}
        public CmdbItem Update(CmdbItem item)
        {
            CmdbItem savedItem;
            lock (_repositoryLock)
            {
                    var currentVertex = Graph.Vertices.FirstOrDefault(v => v.Id == item.Id && v.Version == item.Version);
                    if (currentVertex == null)
                    {
                        throw new Exception();
                    }

                    item.Version = item.Version + 1;
                    //TODO add try/catch to protect the lock
                    savedItem = _nodesAdapter.Update(item);

                    //swap vertices
                    Graph.AddVertex(savedItem);
                    var outEdges = Graph.OutEdges(currentVertex);
                    var inEdges = Graph.InEdges(currentVertex);
                    foreach (var outEdge in outEdges)
                    {
                        outEdge.Source = savedItem;
                        Graph.AddEdge(outEdge);
                    }
                    foreach (var inEdge in inEdges)
                    {
                        inEdge.Target = savedItem;
                        Graph.AddEdge(inEdge);
                    }
                    Graph.RemoveVertex(currentVertex);
            }
            if (savedItem != null)
            {
                Clients.All.updateNode(savedItem);
            }
            return savedItem;
        }
Exemplo n.º 3
0
        public CmdbItem Create(CmdbItem item)
        {
            var nextId = Interlocked.Increment(ref _nodeNextSequenceId);
            var category = (item != null &&  item.Category != null && Categories.ContainsKey(item.Category.Id)) ? item.Category : Categories.First().Value;
            var name = (item != null && item.Name != null) ? item.Name : string.Empty;
            var newItem = new CmdbItem(category, nextId, name) {GraphId = item == null ? Graph.Id : item.GraphId};

            CmdbItem savedItem;
            lock (_repositoryLock)
            {
                savedItem = _nodesAdapter.Create(newItem);
                Graph.AddVertex(newItem);
            }
            if (savedItem != null)
            {
                Clients.All.createNode(newItem);
            }

            return savedItem;
        }
Exemplo n.º 4
0
 public ActionResult Edit(CmdbItem item)
 {
     if (ModelState.IsValid)
     {
         var current = CmdbRepository.Instance.Graph.Vertices.FirstOrDefault(c => c.Id == item.Id);
         //CmdbRepository.Instance.Graph.Replace(item);
         //db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(item);
 }