Beispiel #1
0
    public TOperationSupport (TModelContext context, TEntityAction action)
      : this ()
    {
      /*
      DATA IN
      - action.Id 
      - action.CollectionAction.CategoryRelationCollection

      DATA OUT
      - action.ModelAction (model)
      - action.CollectionAction.ModeCollection {id, model} (for each node)
      */

      if (action.NotNull ()) {
        Id = action.Id;

        if (context.NotNull ()) {
          var descriptors = context.ComponentDescriptor.AsQueryable ()
          .Where (p => p.Id.Equals (Id))
          .ToList ()
        ;

          // found (request Category)
          if (descriptors.Any ()) {
            CategoryValue = descriptors [0].Category;
          }
        }
      }
    }
Beispiel #2
0
    void ChangeSettings (TModelContext context, TEntityAction action)
    {
      /*
      DATA IN
      - action.ModelAction (Settings model)
      */

      try {
        var modelList = context.Settings
          .ToList ()
        ;

        // only one record
        if (modelList.Count.Equals (1)) {
          var model = modelList [0];
          model.Change (action.ModelAction.SettingsModel);

          context.Settings.Update (model);// change Settings model
          context.SaveChanges (); // done

          action.Result = TValidationResult.Success;
        }

        // wrong record count
        else {
          action.Result = new TValidationResult ($"[{action.Operation.CategoryType.Category} - Change Settings] Wrong record count!");
        }
      }

      catch (Exception exception) {
        Models.Infrastructure.THelper.FormatException ("Change - Settings", exception, action);
      }
    }
Beispiel #3
0
    void SelectSettings (TModelContext context, TEntityAction action)
    {
      try {
        var modelList = context.Settings
          .ToList ()
        ;

        if (modelList.Count.Equals (1)) {
          var model = modelList [0];

          if (model.MyName.Equals ("robjuca", StringComparison.InvariantCulture)) {
            action.ModelAction.SettingsModel.CopyFrom (model);

            action.Result = TValidationResult.Success;
          }

          // bad name
          else {
            action.Result = new TValidationResult ($"[{action.Operation.CategoryType.Category} - Settings] My Name can NOT be NULL or EMPTY or VALIDATE!");
          }
        }

        // wrong record count
        else {
          action.Result = new TValidationResult ($"[{action.Operation.CategoryType.Category} - Settings] Wrong record count!");
        }
      }

      catch (Exception exception) {
        Server.Models.Infrastructure.THelper.FormatException ("Select Settings", exception, action);
      }
    }
Beispiel #4
0
    static bool RequestComponent (Guid id, TModelContext context, TEntityAction action, TModelAction modelAction)
    {
      /*
      DATA OUT
      - action.ModelAction (model)
      */

      bool res = false;

      try {
        // info
        var infoList = context.ComponentInfo.AsQueryable()
          .Where (p => p.Id.Equals (id))
          .ToList ()
        ;

        // info found
        if (infoList.Count.Equals (1)) {
          var model = infoList [0];
          modelAction.ComponentInfoModel.CopyFrom (model);

          // update category
          if (action.CategoryType.IsCategory (TCategory.None)) {
            var descList = context.ComponentDescriptor.AsQueryable()
              .Where (p => p.Id.Equals (action.Id))
              .ToList ()
            ;

            // found
            if (descList.Count.Equals (1)) {
              var desc = descList [0];
              action.SelectCategoryType (TCategoryType.Create (TCategoryType.FromValue (desc.Category)));
            }
          }
        }

        // status
        var statusList = context.ComponentStatus.AsQueryable()
          .Where (p => p.Id.Equals (id))
          .ToList ()
        ;

        // status found
        if (statusList.Count.Equals (1)) {
          var model = statusList [0];
          modelAction.ComponentStatusModel.CopyFrom (model);
        }

        res = true;
      }

      catch (Exception exception) {
        THelper.FormatException ("RequestComponent - TOperationSupport", exception, action);
      }

      return (res);
    }
Beispiel #5
0
    void SelectMany (TModelContext context, TEntityAction action)
    {
      /*
       DATA IN
      - action.IdCollection (id) or action.IdDictionaryCollection
      - action.CollectionAction.CategoryRelationCollection

      DATA OUT
      - action.CollectionAction.EntityCollection {id, entityAction} or action.CollectionAction.EntityDictionaryCollection {id, Collection<TEntityAction>} 
      */

      try {
        action.CollectionAction.ModelCollection.Clear ();
        action.CollectionAction.EntityCollection.Clear ();
        action.CollectionAction.EntityDictionary.Clear ();

        // IdCollection
        if (action.IdCollection.Any ()) {
          foreach (var id in action.IdCollection) {
            var entityAction = TEntityAction.CreateDefault;
            entityAction.Id = id;
            entityAction.CollectionAction.SetCollection (action.CollectionAction.CategoryRelationCollection);

            SelectById (context, entityAction);

            action.CollectionAction.EntityCollection.Add (id, entityAction);
          }
        }

        else {
          // IdDictionary
          if (action.IdDictionary.Any ()) {
            foreach (var item in action.IdDictionary) {
              var entityCollection = new Dictionary<Guid, TEntityAction> ();

              foreach (var id in item.Value) {
                var entityAction = TEntityAction.CreateDefault;
                entityAction.Id = id;
                entityAction.CollectionAction.SetCollection (action.CollectionAction.CategoryRelationCollection);

                SelectById (context, entityAction);

                entityCollection.Add (id, entityAction);
              }
              
              action.CollectionAction.EntityDictionary.Add (item.Key, entityCollection);
            }
          }
        }

        action.Result = TValidationResult.Success;
      }

      catch (Exception exception) {
        Server.Models.Infrastructure.THelper.FormatException ("Select Many", exception, action);
      }
    }
Beispiel #6
0
    void SelectById (TModelContext context, TEntityAction action)
    {
      /*
      DATA IN
      - action.Id 
      - action.CollectionAction.CategoryRelationCollection

      DATA OUT
      - action.ModelAction (model)
      - action.CollectionAction.ModeCollection {id, model} (for each node)
      - action.CollectionAction.EntityCollection {id, model} (for each relation)
      */

      try {
        // Id must exist
        if (action.Id.IsEmpty ()) {
          action.Result = new TValidationResult ("[Select ById] Id can NOT be NULL or EMPTY!");
        }

        else {
          action.Result = TValidationResult.Success; // desired result DO NOT MOVE FROM HERE

          // relation by id (use parent)
          action.CollectionAction.SelectComponentOperation (TComponentOperation.TInternalOperation.Id);
          action.ComponentOperation.SelectById (action.Id);

          var operationSupport = new TOperationSupport (context, action);
          operationSupport.RequestComponent (context, action);
          operationSupport.RequestExtension (context, action);
          TOperationSupport.RequestNode (context, action);
          TOperationSupport.RequestRelation (context, action);

          // use Parent relation
          if (action.ComponentOperation.ParentIdCollection.ContainsKey (action.Id)) {
            var componentRelationList = action.ComponentOperation.ParentIdCollection [action.Id];

            foreach (var relation in componentRelationList) {
              var entityAction = TEntityAction.Create (TCategoryType.FromValue (relation.ChildCategory));
              entityAction.CollectionAction.SetCollection (action.CollectionAction.CategoryRelationCollection);
              entityAction.Id = relation.ChildId;

              SelectById (context, entityAction); // my self (tree navigation)

              action.CollectionAction.EntityCollection.Add (relation.ChildId, entityAction);
            }
          }
        }
      }

      catch (Exception exception) {
        Server.Models.Infrastructure.THelper.FormatException ("Select ById", exception, action);
      }
    }
Beispiel #7
0
    internal static void RequestNode (TModelContext context, TEntityAction action)
    {
      /*
       DATA IN
      - action.Id {used as ParentId}

      DATA OUT
       - action.CollectionAction.ExtensionNodeCollection
       - action.CollectionAction.ModelCollection {id, modelAction}    // node model
      */

      if (context.NotNull () && action.NotNull ()) {
        var nodesCollection = context.ExtensionNode.AsQueryable ()
          .Where (p => p.ParentId.Equals (action.Id))
          .ToList ()
        ;

        var nodeReverse = action.ModelAction.ComponentStatusModel.NodeReverse;

        if (nodeReverse) {
          nodesCollection = context.ExtensionNode.AsQueryable ()
            .Where (p => p.ChildId.Equals (action.Id))
            .ToList ()
          ;
        }

        try {
          // node (child)
          foreach (var node in nodesCollection) {
            action.CollectionAction.ExtensionNodeCollection.Add (node);

            var id = nodeReverse ? node.ParentId : node.ChildId;
            var categoryValue = nodeReverse ? node.ParentCategory : node.ChildCategory;

            var modelAction = TModelAction.CreateDefault;

            if (RequestComponent (id, context, action, modelAction)) {
              if (RequestExtension (categoryValue, id, context, action, modelAction)) {
                action.CollectionAction.ModelCollection.Add (id, modelAction);    // add node model
              }
            }
          }
        }

        catch (Exception exception) {
          THelper.FormatException ("RequestNode - TOperationSupport", exception, action);
        }
      }
    }
Beispiel #8
0
    void ChangeContent (TModelContext context, TEntityAction action)
    {
      /*
      DATA IN
      - action.CollectionAction.EntityCollection
      */

      action.Result = TValidationResult.Success;

      foreach (var item in action.CollectionAction.EntityCollection) {
        var entityAction = item.Value;
        entityAction.Id = item.Key;
        entityAction.CollectionAction.SetCollection (action.CollectionAction.CategoryRelationCollection);

        ModifyContent (context, entityAction);
      }
    }
Beispiel #9
0
    public void Invoke (IModelContext modelContext, IEntityAction entityAction, TExtension extension)
    {
      if (modelContext.NotNull ()) {
        var context = TModelContext.CastTo (modelContext);

        var relationList = context.CategoryRelation
          .ToList ()
        ;

        if (entityAction.NotNull ()) {
          var action = TEntityAction.Request (entityAction);
          action.CollectionAction.SetCollection (relationList);

          if (action.Operation.HasExtension) {
            switch (extension) {
              case TExtension.Full: {
                  CollectionFull (context, action);
                }
                break;

              case TExtension.Minimum: {
                  CollectionMinimum (context, action);
                }
                break;

              case TExtension.ById:
              case TExtension.Idle:
              case TExtension.Many:
              case TExtension.Zap: {
                  Models.Infrastructure.THelper.FormatExtensionNotImplementedException (action);
                }
                break;
            }
          }

          else {
            Models.Infrastructure.THelper.FormatExtensionMustExistException (action);
          }
        }
      }
    }
Beispiel #10
0
    void SelectRelation (TModelContext context, TEntityAction action)
    {
      /*
       DATA IN
      - action.ComponentOperation 

      DATA OUT
      - action.ComponentOperation
      */

      try {
        var operationSupport = new TOperationSupport (context, action);
        TOperationSupport.RequestRelation (context, action);

        action.Result = TValidationResult.Success;
      }

      catch (Exception exception) {
        Server.Models.Infrastructure.THelper.FormatException ("Select Relation", exception, action);
      }
    }
Beispiel #11
0
    static void ChangeStatus (TModelContext context, TEntityAction action)
    {
      /*
      DATA IN
      - action.Id (Component id to change)
      - action.ModelAction (Component model) (only Status component)
      */

      var id = action.Id;

      try {
        //Component Id must exist
        if (id.IsEmpty ()) {
          action.Result = new TValidationResult ($"[{action.Operation.CategoryType.Category} - Change - Status] Component Id can NOT be NULL or EMPTY!");
        }

        else {
          // Status 
          var statusList = context.ComponentStatus.AsQueryable ()
            .Where (p => p.Id.Equals (id))
            .ToList ()
          ;

          // Status found
          if (statusList.Count.Equals (1)) {
            var model = statusList [0];
            model.Change (action.ModelAction.ComponentStatusModel);
            context.ComponentStatus.Update (model);// change Status model
          }

          context.SaveChanges (); // save here

          action.Result = TValidationResult.Success;
        }
      }

      catch (Exception exception) {
        Models.Infrastructure.THelper.FormatException ("Change Status", exception, action);
      }
    }
Beispiel #12
0
    void SelectNode (TModelContext context, TEntityAction action)
    {
      /*
      DATA IN
      - action.CollectionAction.CategoryRelationCollection
      - action.ComponentModel (NodeModelCollection)

      DATA OUT
      - action.CollectionAction.ModelCollection {id, model}

      */

      try {
        TOperationSupport.RequestNode (context, action);

        action.Result = TValidationResult.Success;
      }

      catch (Exception exception) {
        Server.Models.Infrastructure.THelper.FormatException ("Select Node", exception, action);
      }
    }
Beispiel #13
0
    public void Invoke (IModelContext modelContext, IEntityAction entityAction, Server.Models.Infrastructure.TExtension extension)
    {
      if (modelContext.NotNull ()) {
        var context = TModelContext.CastTo (modelContext);

        var relationList = context.CategoryRelation
          .ToList ()
        ;

        if (entityAction.NotNull ()) {
          var action = TEntityAction.Request (entityAction);
          action.CollectionAction.SetCollection (relationList);

          if (action.Operation.HasExtension) {
            Server.Models.Infrastructure.THelper.FormatExtensionNotImplementedException (action);
          }

          else {
            Insert (context, action);
          }
        }
      }
    }
Beispiel #14
0
    void CollectionFull (TModelContext context, TEntityAction action)
    {
      /* 
        DATA IN:
          action.Operation.CategoryType.Category  
          action.CollectionAction.CategoryRelationCollection
      */

      try {
        // select Id by Category
        var categoryValue = TCategoryType.ToValue (action.Operation.CategoryType.Category);

        var descriptors = context.ComponentDescriptor.AsQueryable()
          .Where (p => p.Category.Equals (categoryValue))
          .ToList ()
        ;

        // found
        if (descriptors.Any ()) {
          // Component Info, Status
          action.CollectionAction.ComponentInfoCollection.Clear ();
          action.CollectionAction.ComponentStatusCollection.Clear ();

          foreach (var descriptor in descriptors) {
            // Info
            var infoList = context.ComponentInfo.AsQueryable()
              .Where (p => p.Id.Equals (descriptor.Id))
              .ToList ()
            ;

            // Status
            var statusList = context.ComponentStatus.AsQueryable()
              .Where (p => p.Id.Equals (descriptor.Id))
              .ToList ()
            ;

            // info found
            if (infoList.Count.Equals (1)) {
              var infoModel = infoList [0];
              action.CollectionAction.ComponentInfoCollection.Add (infoModel);
            }

            // status found
            if (statusList.Count.Equals (1)) {
              var statusModel = statusList [0];
              action.CollectionAction.ComponentStatusCollection.Add (statusModel);
            }
          }

          // Component Relation
          // by Category
          action.CollectionAction.ComponentOperation.Clear ();
          action.CollectionAction.SelectComponentOperation (TComponentOperation.TInternalOperation.Category);
          action.CollectionAction.ComponentOperation.SelectByCategory (categoryValue);

          var componentRelationFullList = context.ComponentRelation
            .ToList ()
          ;

          foreach (var itemCategory in action.CollectionAction.ComponentOperation.CategoryCollection) {
            // parent 
            var parentList = componentRelationFullList
              .Where (p => p.ParentCategory.Equals (itemCategory))
              .ToList ()
            ;

            action.CollectionAction.ComponentOperation.SelectParent (itemCategory, parentList);

            // child
            var childList = componentRelationFullList
              .Where (p => p.ChildCategory.Equals (itemCategory))
              .ToList ()
            ;

            action.CollectionAction.ComponentOperation.SelectChild (itemCategory, childList);
          }

          // Extension (CategoryRelationCollection)
          var categoryRelationList = action.CollectionAction.CategoryRelationCollection
            .Where (p => p.Category.Equals (categoryValue))
            .ToList ()
          ;

          // found
          if (categoryRelationList.Count.Equals (1)) {
            var categoryRelation = categoryRelationList [0]; // get extension using TComponentExtension

            var extension = TComponentExtension.Create (categoryRelation.Extension);
            extension.Request ();

            foreach (var item in action.CollectionAction.ComponentInfoCollection) {
              var id = item.Id;

              // Status
              var compStatus = Models.Component.ComponentStatus.CreateDefault;

              var statusList = action.CollectionAction.ComponentStatusCollection
                .Where (p => p.Id.Equals (id))
                .ToList ()
              ;

              if (statusList.Count.Equals (1)) {
                compStatus.CopyFrom (statusList [0]);
              }

              foreach (var extensionName in extension.ExtensionList) {
                switch (extensionName) {
                  case TComponentExtensionNames.Document: {
                      //var list = context.ExtensionDocument
                      //  .Where (p => p.Id.Equals (id))
                      //  .ToList ()
                      //;

                      //if (list.Count.Equals (1)) {
                      //  action.CollectionAction.ExtensionDocumentCollection.Add (list [0]);
                      //}
                    }
                    break;

                  case TComponentExtensionNames.Geometry: {
                      var list = context.ExtensionGeometry.AsQueryable()
                        .Where (p => p.Id.Equals (id))
                        .ToList ()
                      ;

                      if (list.Count.Equals (1)) {
                        action.CollectionAction.ExtensionGeometryCollection.Add (list [0]);
                      }
                    }
                    break;

                  case TComponentExtensionNames.Image: {
                      var list = context.ExtensionImage.AsQueryable()
                        .Where (p => p.Id.Equals (id))
                        .ToList ()
                      ;

                      if (list.Count.Equals (1)) {
                        action.CollectionAction.ExtensionImageCollection.Add (list [0]);
                      }
                    }
                    break;

                  case TComponentExtensionNames.Layout: {
                      var list = context.ExtensionLayout.AsQueryable()
                        .Where (p => p.Id.Equals (id))
                        .ToList ()
                      ;

                      if (list.Count.Equals (1)) {
                        action.CollectionAction.ExtensionLayoutCollection.Add (list [0]);
                      }
                    }
                    break;

                  case TComponentExtensionNames.Node: {
                      var nodeModeldList = context.ExtensionNode.AsQueryable()
                        .Where (p => p.ParentId.Equals (id))
                        .ToList ()
                      ;

                      // Node Reverse
                      if (compStatus.NodeReverse) {
                        nodeModeldList = context.ExtensionNode.AsQueryable()
                          .Where (p => p.ChildId.Equals (id))
                          .ToList ()
                        ;
                      }

                      // Node Model
                      if (compStatus.UseNodeModel) {
                        if (nodeModeldList.Count.Equals (1)) {
                          action.ModelAction.ExtensionNodeModel.CopyFrom (nodeModeldList [0]);
                          action.CollectionAction.ExtensionNodeCollection.Add (nodeModeldList [0]);
                        }
                      }

                      // Node Collection
                      if (compStatus.UseNodeCollection) {
                        foreach (var nodeModel in nodeModeldList) {
                          action.CollectionAction.ExtensionNodeCollection.Add (nodeModel);
                        }
                      }
                    }
                    break;

                  case TComponentExtensionNames.Text: {
                      var list = context.ExtensionText.AsQueryable()
                        .Where (p => p.Id.Equals (id))
                        .ToList ()
                      ;

                      if (list.Count.Equals (1)) {
                        action.CollectionAction.ExtensionTextCollection.Add (list [0]);
                      }
                    }
                    break;

                  case TComponentExtensionNames.Content: {
                      var list = context.ExtensionContent.AsQueryable()
                        .Where (p => p.Id.Equals (id))
                        .ToList ()
                      ;

                      if (list.Count.Equals (1)) {
                        action.CollectionAction.ExtensionContentCollection.Add (list [0]);
                      }
                    }
                    break;
                }
              }
            }
          }

          // populate ModelCollection
          action.CollectionAction.ModelCollection.Clear ();

          var componentExtension = TComponentExtension.CreateDefault;
          action.RequestExtension (componentExtension);

          foreach (var item in action.CollectionAction.ComponentInfoCollection) {
            // component
            // Info
            var id = item.Id;
            var models = TModelAction.CreateDefault;

            models.ComponentInfoModel.CopyFrom (item);

            // Status
            var compStatus = ComponentStatus.CreateDefault;

            var statusList = action.CollectionAction.ComponentStatusCollection
              .Where (p => p.Id.Equals (id))
              .ToList ()
            ;

            // found
            if (statusList.Count.Equals (1)) {
              models.ComponentStatusModel.CopyFrom (statusList [0]);
              compStatus.CopyFrom (statusList [0]);
            }

            // extension
            foreach (var extensionName in componentExtension.ExtensionList) {
              switch (extensionName) {
                case TComponentExtensionNames.Document: {
                    //var list = action.CollectionAction.ExtensionDocumentCollection
                    //  .Where (p => p.Id.Equals (id))
                    //  .ToList ()
                    //;

                    //if (list.Count.Equals (1)) {
                    //  models.ExtensionDocumentModel.CopyFrom (list [0]);
                    //}
                  }
                  break;

                case TComponentExtensionNames.Geometry: {
                    var list = action.CollectionAction.ExtensionGeometryCollection
                      .Where (p => p.Id.Equals (id))
                      .ToList ()
                    ;

                    if (list.Count.Equals (1)) {
                      models.ExtensionGeometryModel.CopyFrom (list [0]);
                    }
                  }
                  break;

                case TComponentExtensionNames.Image: {
                    var list = action.CollectionAction.ExtensionImageCollection
                      .Where (p => p.Id.Equals (id))
                      .ToList ()
                    ;

                    if (list.Count.Equals (1)) {
                      models.ExtensionImageModel.CopyFrom (list [0]);
                    }
                  }
                  break;

                case TComponentExtensionNames.Layout: {
                    var list = action.CollectionAction.ExtensionLayoutCollection
                      .Where (p => p.Id.Equals (id))
                      .ToList ()
                    ;

                    if (list.Count.Equals (1)) {
                      models.ExtensionLayoutModel.CopyFrom (list [0]);
                    }
                  }
                  break;

                case TComponentExtensionNames.Node: {
                    var nodeModellist = action.CollectionAction.ExtensionNodeCollection
                      .Where (p => p.ParentId.Equals (id))
                      .ToList ()
                    ;

                    if (compStatus.NodeReverse) {
                      nodeModellist = action.CollectionAction.ExtensionNodeCollection
                        .Where (p => p.ChildId.Equals (id))
                        .ToList ()
                      ;
                    }

                    if (compStatus.UseNodeModel) {
                      if (nodeModellist.Count.Equals (1)) {
                        models.ExtensionNodeModel.CopyFrom (nodeModellist [0]);
                      }
                    }
                  }
                  break;

                case TComponentExtensionNames.Text: {
                    var list = action.CollectionAction.ExtensionTextCollection
                      .Where (p => p.Id.Equals (id))
                      .ToList ()
                    ;

                    if (list.Count.Equals (1)) {
                      models.ExtensionTextModel.CopyFrom (list [0]);
                    }
                  }
                  break;

                case TComponentExtensionNames.Content: {
                    var list = action.CollectionAction.ExtensionContentCollection
                      .Where (p => p.Id.Equals (id))
                      .ToList ()
                    ;

                    if (list.Count.Equals (1)) {
                      models.ExtensionContentModel.CopyFrom (list [0]);
                    }
                  }
                  break;
              }
            }

            action.CollectionAction.ModelCollection.Add (id, models);
          }
        }

        // ComponentOperation - Operation.Category
        if (action.CollectionAction.ComponentOperation.IsComponentOperation (TComponentOperation.TInternalOperation.Category)) {
          action.IdCollection.Clear ();

          var list = new Collection<ComponentRelation> (action.CollectionAction.ComponentOperation.RequestParentCategoryCollection ());

          foreach (var relation in list) {
            if (relation.ChildId.NotEmpty ()) {
              action.IdCollection.Add (relation.ChildId);
            }
          }
        }

        action.Result = TValidationResult.Success;
      }

      catch (Exception exception) {
        Models.Infrastructure.THelper.FormatException ("Collection Full", exception, action);
      }
    }
Beispiel #15
0
    void CollectionMinimum (TModelContext context, TEntityAction action)
    {
      /* 
        DATA IN:
          action.Operation.CategoryType.Category  
          action.CollectionAction.CategoryRelationCollection
      */

      try {
        // select Id by Category
        var categoryValue = TCategoryType.ToValue (action.Operation.CategoryType.Category);

        var descriptors = context.ComponentDescriptor.AsQueryable()
          .Where (p => p.Category.Equals (categoryValue))
          .ToList ()
        ;

        // found
        if (descriptors.Any ()) {
          // Component Info, Status
          action.CollectionAction.ComponentInfoCollection.Clear ();
          action.CollectionAction.ComponentStatusCollection.Clear ();

          foreach (var descriptor in descriptors) {
            // Info
            var infoList = context.ComponentInfo.AsQueryable()
              .Where (p => p.Id.Equals (descriptor.Id))
              .ToList ()
            ;

            // Status
            var statusList = context.ComponentStatus.AsQueryable()
              .Where (p => p.Id.Equals (descriptor.Id))
              .ToList ()
            ;

            // info found
            if (infoList.Count.Equals (1)) {
              var infoModel = infoList [0];
              action.CollectionAction.ComponentInfoCollection.Add (infoModel);
            }

            // status found
            if (statusList.Count.Equals (1)) {
              var statusModel = statusList [0];
              action.CollectionAction.ComponentStatusCollection.Add (statusModel);
            }
          }

          // Extension (CategoryRelationCollection)
          var categoryRelationList = action.CollectionAction.CategoryRelationCollection
            .Where (p => p.Category.Equals (categoryValue))
            .ToList ()
          ;

          // found
          if (categoryRelationList.Count.Equals (1)) {
            var categoryRelation = categoryRelationList [0]; // get extension using TComponentExtension

            var extension = TComponentExtension.Create (categoryRelation.Extension);
            extension.Request ();

            foreach (var item in action.CollectionAction.ComponentInfoCollection) {
              var id = item.Id;

              foreach (var extensionName in extension.ExtensionList) {
                switch (extensionName) {
                  case TComponentExtensionNames.Layout: {
                      var list = context.ExtensionLayout.AsQueryable()
                          .Where (p => p.Id.Equals (id))
                          .ToList ()
                        ;


                      if (list.Count.Equals (1)) {
                        action.CollectionAction.ExtensionLayoutCollection.Add (list [0]);
                      }
                    }
                    break;
                }
              }
            }
          }

          // populate ModelCollection
          action.CollectionAction.ModelCollection.Clear ();

          var componentExtension = TComponentExtension.CreateDefault;
          action.RequestExtension (componentExtension);


          foreach (var item in action.CollectionAction.ComponentInfoCollection) {
            // component
            // Info
            var id = item.Id;
            var models = TModelAction.CreateDefault;

            models.ComponentInfoModel.CopyFrom (item);

            // Status
            var statusList = action.CollectionAction.ComponentStatusCollection
              .Where (p => p.Id.Equals (id))
              .ToList ()
            ;

            // found
            if (statusList.Count.Equals (1)) {
              models.ComponentStatusModel.CopyFrom (statusList [0]);
            }

            // extension
            foreach (var extensionName in componentExtension.ExtensionList) {
              switch (extensionName) {
                case TComponentExtensionNames.Layout: {
                    var list = action.CollectionAction.ExtensionLayoutCollection
                      .Where (p => p.Id.Equals (id))
                      .ToList ()
                    ;

                    if (list.Count.Equals (1)) {
                      models.ExtensionLayoutModel.CopyFrom (list [0]);
                    }
                  }
                  break;
              }
            }

            action.CollectionAction.ModelCollection.Add (id, models);
          }
        }

        action.Result = TValidationResult.Success;
      }

      catch (Exception exception) {
        Models.Infrastructure.THelper.FormatException ("Collection Full", exception, action);
      }
    }
Beispiel #16
0
    internal static void RequestRelation (TModelContext context, TEntityAction action)
    {
      /*
       DATA IN
      - action.ComponentOperation 

      DATA OUT
      - action.ComponentOperation
      */

      if (context.NotNull () && action.NotNull ()) {
        // Component Relation
        var componentRelationFullList = context.ComponentRelation
          .ToList ()
        ;

        // by Category
        if (action.ComponentOperation.IsComponentOperation (TComponentOperation.TInternalOperation.Category)) {
          foreach (var categoryValue in action.ComponentOperation.CategoryCollection) {
            // parent 
            var parentList = componentRelationFullList
              .Where (p => p.ParentCategory.Equals (categoryValue))
              .ToList ()
            ;

            if (parentList.Any ()) {
              action.CollectionAction.ComponentOperation.SelectParent (categoryValue, parentList);
            }

            // child
            var childList = componentRelationFullList
              .Where (p => p.ChildCategory.Equals (categoryValue))
              .ToList ()
            ;

            if (childList.Any ()) {
              action.CollectionAction.ComponentOperation.SelectChild (categoryValue, childList);
            }
          }
        }

        // by Id
        if (action.ComponentOperation.IsComponentOperation (TComponentOperation.TInternalOperation.Id)) {
          foreach (var id in action.ComponentOperation.IdCollection) {
            // parent 
            var parentList = componentRelationFullList
              .Where (p => p.ParentId.Equals (id))
              .ToList ()
            ;

            if (parentList.Any ()) {
              action.CollectionAction.ComponentOperation.SelectParent (id, parentList);
            }

            // child
            var childList = componentRelationFullList
              .Where (p => p.ChildId.Equals (id))
              .ToList ()
            ;

            if (childList.Any ()) {
              action.CollectionAction.ComponentOperation.SelectChild (id, childList);
            }
          }
        }
      }
    }
Beispiel #17
0
    void SelectZap (TModelContext context, TEntityAction action)
    {
      /* 
       DATA IN:
        action.IdCollection {id to zap}
        action.CategoryType  

       DATA OUT:
        action.CollectionAction.ModelCollection [id] {Model}
      */

      try {
        action.CollectionAction.ModelCollection.Clear ();

        var categoryValue = TCategoryType.ToValue (action.CategoryType.Category);

        // search Id by category
        var descriptors = context.ComponentDescriptor.AsQueryable()
          .Where (p => p.Category.Equals (categoryValue))
          .ToList ()
        ;

        // zap
        foreach (var idToZap in action.IdCollection) {
          var zapList = descriptors
            .Where (p => p.Id.Equals (idToZap))
            .ToList ()
          ;

          // found
          if (zapList.Count.Equals (1)) {
            // update descriptors
            descriptors.Remove (zapList [0]);
          }
        }

        // Component Info, Status
        action.CollectionAction.ComponentInfoCollection.Clear ();
        action.CollectionAction.ComponentStatusCollection.Clear ();

        foreach (var descriptor in descriptors) {
          // Info
          var infoList = context.ComponentInfo.AsQueryable()
            .Where (p => p.Id.Equals (descriptor.Id))
            .ToList ()
          ;

          // Status
          var statusList = context.ComponentStatus.AsQueryable()
            .Where (p => p.Id.Equals (descriptor.Id))
            .ToList ()
          ;

          // info found
          if (infoList.Count.Equals (1)) {
            var infoModel = infoList [0];
            action.CollectionAction.ComponentInfoCollection.Add (infoModel);
          }

          // status found
          if (statusList.Count.Equals (1)) {
            var statusModel = statusList [0];
            action.CollectionAction.ComponentStatusCollection.Add (statusModel);
          }
        }

        // Extension (CategoryRelationCollection)
        var categoryRelationList = action.CollectionAction.CategoryRelationCollection
          .Where (p => p.Category.Equals (categoryValue))
          .ToList ()
        ;

        // found
        if (categoryRelationList.Count.Equals (1)) {
          var categoryRelation = categoryRelationList [0]; // get extension using TComponentExtension

          var extension = TComponentExtension.Create (categoryRelation.Extension);
          extension.Request ();

          foreach (var item in action.CollectionAction.ComponentInfoCollection) {
            var id = item.Id;

            foreach (var extensionName in extension.ExtensionList) {
              switch (extensionName) {
                //case TComponentExtensionNames.Document: {
                //    var list = context.ExtensionDocument
                //      .Where (p => p.Id.Equals (id))
                //      .ToList ()
                //    ;

                //    if (list.Count.Equals (1)) {
                //      action.CollectionAction.ExtensionDocumentCollection.Add (list [0]);
                //    }
                //  }
                //  break;

                case TComponentExtensionNames.Geometry: {
                    var list = context.ExtensionGeometry.AsQueryable()
                      .Where (p => p.Id.Equals (id))
                      .ToList ()
                    ;

                    if (list.Count.Equals (1)) {
                      action.CollectionAction.ExtensionGeometryCollection.Add (list [0]);
                    }
                  }
                  break;

                case TComponentExtensionNames.Image: {
                    var list = context.ExtensionImage.AsQueryable().Where (p => p.Id.Equals (id)).ToList ();

                    if (list.Count.Equals (1)) {
                      action.CollectionAction.ExtensionImageCollection.Add (list [0]);
                    }
                  }
                  break;

                case TComponentExtensionNames.Layout: {
                    var list = context.ExtensionLayout.AsQueryable()
                      .Where (p => p.Id.Equals (id))
                      .ToList ()
                    ;

                    if (list.Count.Equals (1)) {
                      action.CollectionAction.ExtensionLayoutCollection.Add (list [0]);
                    }
                  }
                  break;

                case TComponentExtensionNames.Node: {
                    // child first
                    var childList = context.ExtensionNode.AsQueryable()
                      .Where (p => p.ChildId.Equals (id))
                      .ToList ()
                    ;

                    if (childList.Count.Equals (1)) {
                      action.ModelAction.ExtensionNodeModel.CopyFrom (childList [0]);
                      action.CollectionAction.ExtensionNodeCollection.Add (childList [0]);
                    }

                    else {
                      // parent next
                      var parentList = context.ExtensionNode.AsQueryable()
                        .Where (p => p.ParentId.Equals (id))
                        .ToList ()
                      ;

                      foreach (var model in parentList) {
                        action.CollectionAction.ExtensionNodeCollection.Add (model);
                      }
                    }
                  }
                  break;

                case TComponentExtensionNames.Text: {
                    var list = context.ExtensionText.AsQueryable()
                      .Where (p => p.Id.Equals (id))
                      .ToList ()
                    ;

                    if (list.Count.Equals (1)) {
                      action.CollectionAction.ExtensionTextCollection.Add (list [0]);
                    }
                  }
                  break;

                case TComponentExtensionNames.Content: {
                    var list = context.ExtensionContent.AsQueryable()
                      .Where (p => p.Id.Equals (id))
                      .ToList ()
                    ;

                    if (list.Count.Equals (1)) {
                      action.CollectionAction.ExtensionContentCollection.Add (list [0]);
                    }
                  }
                  break;
              }
            }
          }
        }

        // populate ModelCollection
        action.CollectionAction.ModelCollection.Clear ();

        var componentExtension = TComponentExtension.CreateDefault;
        action.RequestExtension (componentExtension);


        foreach (var item in action.CollectionAction.ComponentInfoCollection) {
          // component
          // Info
          var id = item.Id;
          var models = TModelAction.CreateDefault;

          models.ComponentInfoModel.CopyFrom (item);

          // Status
          var statusList = action.CollectionAction.ComponentStatusCollection
            .Where (p => p.Id.Equals (id))
            .ToList ()
          ;

          // found
          if (statusList.Count.Equals (1)) {
            models.ComponentStatusModel.CopyFrom (statusList [0]);
          }

          // extension
          foreach (var extensionName in componentExtension.ExtensionList) {
            switch (extensionName) {
              case TComponentExtensionNames.Document: {
                  //var list = action.CollectionAction.ExtensionDocumentCollection
                  //  .Where (p => p.Id.Equals (id))
                  //  .ToList ()
                  //;

                  //if (list.Count.Equals (1)) {
                  //  models.ExtensionDocumentModel.CopyFrom (list [0]);
                  //}
                }
                break;

              case TComponentExtensionNames.Geometry: {
                  var list = action.CollectionAction.ExtensionGeometryCollection
                    .Where (p => p.Id.Equals (id))
                    .ToList ()
                  ;

                  if (list.Count.Equals (1)) {
                    models.ExtensionGeometryModel.CopyFrom (list [0]);
                  }
                }
                break;

              case TComponentExtensionNames.Image: {
                  var list = action.CollectionAction.ExtensionImageCollection
                    .Where (p => p.Id.Equals (id))
                    .ToList ()
                  ;

                  if (list.Count.Equals (1)) {
                    models.ExtensionImageModel.CopyFrom (list [0]);
                  }
                }
                break;

              case TComponentExtensionNames.Layout: {
                  var list = action.CollectionAction.ExtensionLayoutCollection
                    .Where (p => p.Id.Equals (id))
                    .ToList ()
                  ;

                  if (list.Count.Equals (1)) {
                    models.ExtensionLayoutModel.CopyFrom (list [0]);
                  }
                }
                break;

              case TComponentExtensionNames.Node: {
                  // child
                  var list = action.CollectionAction.ExtensionNodeCollection
                    .Where (p => p.ChildId.Equals (id))
                    .ToList ()
                  ;

                  if (list.Count.Equals (1)) {
                    models.ExtensionNodeModel.CopyFrom (list [0]);
                  }
                }
                break;

              case TComponentExtensionNames.Text: {
                  var list = action.CollectionAction.ExtensionTextCollection
                    .Where (p => p.Id.Equals (id))
                    .ToList ()
                  ;

                  if (list.Count.Equals (1)) {
                    models.ExtensionTextModel.CopyFrom (list [0]);
                  }
                }
                break;

              case TComponentExtensionNames.Content: {
                  var list = action.CollectionAction.ExtensionContentCollection
                    .Where (p => p.Id.Equals (id))
                    .ToList ()
                  ;

                  if (list.Count.Equals (1)) {
                    models.ExtensionContentModel.CopyFrom (list [0]);
                  }
                }
                break;
            }
          }

          action.CollectionAction.ModelCollection.Add (id, models);
        }

        action.Result = TValidationResult.Success;
      }

      catch (Exception exception) {
        Server.Models.Infrastructure.THelper.FormatException ("Select Zap", exception, action);
      }
    }
Beispiel #18
0
    void SelectSummary (TModelContext context, TEntityAction action)
    {
      /*
       DATA IN
      - action.Summary

      DATA OUT
      - action.Summary
      - action.CollectionAction.ComponentInfoCollection
      - action.CollectionAction.ComponentStatusCollection
      */

      try {
        action.CollectionAction.ComponentInfoCollection.Clear ();
        action.CollectionAction.ComponentStatusCollection.Clear ();

        var categoryValue = TCategoryType.ToValue (action.SupportAction.SummaryInfo.Category);

        // search Id by category
        var descriptors = context.ComponentDescriptor.AsQueryable()
          .Where (p => p.Category.Equals (categoryValue))
          .ToList ()
        ;

        foreach (var descriptor in descriptors) {
          // Info
          var infoList = context.ComponentInfo.AsQueryable()
            .Where (p => p.Id.Equals (descriptor.Id))
            .ToList ()
          ;

          // info found
          if (infoList.Count.Equals (1)) {
            var infoModel = infoList [0];
            action.CollectionAction.ComponentInfoCollection.Add (infoModel);
          }

          // Status
          var statusList = context.ComponentStatus.AsQueryable()
            .Where (p => p.Id.Equals (descriptor.Id))
            .ToList ()
          ;

          // status found
          if (statusList.Count.Equals (1)) {
            var statusModel = statusList [0];
            action.CollectionAction.ComponentStatusCollection.Add (statusModel);
          }
        }

        // apply zap
        var enabledZap = new Collection<Guid> ();
        var busyZap = new Collection<Guid> ();

        // zap Enabled = false (disable)
        if (action.SupportAction.SummaryInfo.ZapDisable) {
          foreach (var itemInfo in action.CollectionAction.ComponentInfoCollection) {
            // only Enabled
            if (itemInfo.Enabled.IsFalse ()) {
              enabledZap.Add (itemInfo.Id);
            }
          }
        }

        // zap Busy = true
        if (action.SupportAction.SummaryInfo.ZapBusy) {
          foreach (var itemStatus in action.CollectionAction.ComponentStatusCollection) {
            // only not busy
            if (itemStatus.Busy) {
              busyZap.Add (itemStatus.Id);
            }
          }
        }

        foreach (var id in enabledZap) {
          var list = action.CollectionAction.ComponentInfoCollection
            .Where (p => p.Id.Equals (id))
            .ToList ()
          ;

          if (list.Count.Equals (1)) {
            action.CollectionAction.ComponentInfoCollection.Remove (list [0]);
          }
        }

        foreach (var id in busyZap) {
          var list = action.CollectionAction.ComponentInfoCollection
            .Where (p => p.Id.Equals (id))
            .ToList ()
          ;

          if (list.Count.Equals (1)) {
            action.CollectionAction.ComponentInfoCollection.Remove (list [0]);
          }
        }

        // Extension (CategoryRelationCollection)
        var categoryRelationList = action.CollectionAction.CategoryRelationCollection
          .Where (p => p.Category.Equals (categoryValue))
          .ToList ()
        ;

        // found
        if (categoryRelationList.Count.Equals (1)) {
          var categoryRelation = categoryRelationList [0]; // get extension using TComponentExtension

          var extension = TComponentExtension.Create (categoryRelation.Extension);
          extension.Request ();

          foreach (var item in action.CollectionAction.ComponentInfoCollection) {
            var id = item.Id;
            action.CollectionAction.ExtensionLayoutCollection.Clear ();

            // check for style only
            foreach (var extensionName in extension.ExtensionList) {
              switch (extensionName) {
                case TComponentExtensionNames.Layout: {
                    var list = context.ExtensionLayout.AsQueryable()
                      .Where (p => p.Id.Equals (id))
                      .ToList ()
                    ;

                    if (list.Count.Equals (1)) {
                      action.CollectionAction.ExtensionLayoutCollection.Add (list [0]);
                    }
                  }
                  break;
              }
            }

            foreach (var layout in action.CollectionAction.ExtensionLayoutCollection) {
              action.SupportAction.SummaryInfo.Select (layout.StyleHorizontal, layout.StyleVertical);
            }
          }
        }

        action.Result = TValidationResult.Success;
      }

      catch (Exception exception) {
        Server.Models.Infrastructure.THelper.FormatException ("Select Summary", exception, action);
      }
    }
Beispiel #19
0
 public void RequestExtension (TModelContext context, TEntityAction action)
 {
   if (context.NotNull () && action.NotNull ()) {
     RequestExtension (CategoryValue, Id, context, action, action.ModelAction);
   }
 }
Beispiel #20
0
 internal void RequestComponent (TModelContext context, TEntityAction action)
 {
   if (context.NotNull () && action.NotNull ()) {
     RequestComponent (Id, context, action, action.ModelAction);
   }
 }
Beispiel #21
0
    static void ModifyContent (TModelContext context, TEntityAction action)
    {
      /*
      DATA IN
      - action.Id (Component id to change)
      - action.ModelAction (Component model) (only Content extension)
      */

      var id = action.Id;

      try {
        //Component Id must exist
        if (id.IsEmpty ()) {
          action.Result = new TValidationResult ($"[{action.Operation.CategoryType.Category} - Modify] Component Id can NOT be NULL or EMPTY!");
        }

        else {
          // search Id
          var descriptors = context.ComponentDescriptor.AsQueryable ()
            .Where (p => p.Id.Equals (id))
            .ToList ()
          ;

          // Descriptor found
          if (descriptors.Count.Equals (1)) {
            var descriptor = descriptors [0];
            var categoryValue = descriptor.Category;

            // extensions

            // search for extensions
            var categoryRelationList = action.CollectionAction.CategoryRelationCollection
              .Where (p => p.Category.Equals (categoryValue))
              .ToList ()
            ;

            // found
            if (categoryRelationList.Count.Equals (1)) {
              var categoryRelation = categoryRelationList [0]; // get extension using TComponentExtension

              var extension = TComponentExtension.Create (categoryRelation.Extension);
              extension.Request ();

              foreach (var extensionName in extension.ExtensionList) {
                switch (extensionName) {
                  case TComponentExtensionNames.Content: {
                      var list = context.ExtensionContent.AsQueryable ()
                        .Where (p => p.Id.Equals (id))
                        .ToList ()
                      ;

                      if (list.Count.Equals (1)) {
                        var model = list [0];
                        model.Change (action.ModelAction.ExtensionContentModel);
                        context.ExtensionContent.Update (model); // change model
                      }
                    }
                    break;
                }
              }
            }

            context.SaveChanges (); // update

            action.Result = TValidationResult.Success;
          }
        }
      }

      catch (Exception exception) {
        Models.Infrastructure.THelper.FormatException ("Modify", exception, action);
      }
    }
Beispiel #22
0
    public void Invoke (IModelContext modelContext, IEntityAction entityAction, TExtension extension)
    {
      if (modelContext.NotNull ()) {
        var context = TModelContext.CastTo (modelContext);

        var relationList = context.CategoryRelation
          .ToList ()
        ;

        if (entityAction.NotNull ()) {
          var action = TEntityAction.Request (entityAction);
          action.CollectionAction.SetCollection (relationList);

          if (action.Operation.HasExtension) {
            switch (extension) {
              case TExtension.Settings: {
                  SelectSettings (context, action);
                }
                break;

              case TExtension.ById: {
                  SelectById (context, action);
                }
                break;

              case TExtension.Relation: {
                  SelectRelation (context, action);
                }
                break;

              case TExtension.Many: {
                  SelectMany (context, action);
                }
                break;

              case TExtension.Node: {
                  SelectNode (context, action);
                }
                break;

              case TExtension.Zap: {
                  SelectZap (context, action);
                }
                break;

              case TExtension.Summary: {
                  SelectSummary (context, action);
                }
                break;

              case TExtension.Idle: {
                  //SelectIdle (context, action);
                }
                break;

              case TExtension.Full: {
                  Server.Models.Infrastructure.THelper.FormatExtensionNotImplementedException (action);
                }
                break;
            }
          }

          else {
            Server.Models.Infrastructure.THelper.FormatExtensionMustExistException (action);
          }
        }
      }
    }
Beispiel #23
0
    void Insert (TModelContext context, TEntityAction action)
    {
      /*
       DATA IN:
       - action.Operation.CategoryType.Category
       - action.CollectionAction.CategoryRelationCollection
       - action.ModelAction 
       - action.CollectionAction.ExtensionNodeCollection
       */

      try {
        // Validate Name
        if (ValidateString (action)) {
          //Id
          var id = Guid.NewGuid ();
          var categoryValue = TCategoryType.ToValue (action.Operation.CategoryType.Category);

          // Descriptor
          action.ModelAction.ComponentDescriptorModel.Id = id;
          action.ModelAction.ComponentDescriptorModel.Category = categoryValue;

          var compDescriptor = ComponentDescriptor.CreateDefault;
          compDescriptor.CopyFrom (action.ModelAction.ComponentDescriptorModel);

          context.ComponentDescriptor.Add (compDescriptor);

          // Info
          action.ModelAction.ComponentInfoModel.Id = id;

          var compInfo = ComponentInfo.CreateDefault;
          compInfo.CopyFrom (action.ModelAction.ComponentInfoModel);

          context.ComponentInfo.Add (compInfo);

          // Status
          action.ModelAction.ComponentStatusModel.Id = id;

          var compStatus = ComponentStatus.CreateDefault;
          compStatus.CopyFrom (action.ModelAction.ComponentStatusModel);

          context.ComponentStatus.Add (compStatus);

          // status collection
          foreach (var item in action.CollectionAction.ComponentStatusCollection) {
            var list = context.ComponentStatus.AsQueryable()
              .Where (p => p.Id.Equals (item.Id))
              .ToList ()
            ;

            // already exist (update)
            if (list.Count.Equals (1)) {
              var model = list [0];
              model.Change (item);

              context.ComponentStatus.Update (model);
            }

            // new (add)
            else {
              context.ComponentStatus.Add (item);
            }
          }

          // Component Relation Collection
          foreach (var item in action.CollectionAction.ComponentRelationCollection) {
            // change child status busy to true
            var childList = context.ComponentStatus.AsQueryable()
              .Where (p => p.Id.Equals (item.ChildId))
              .ToList ()
            ;

            // found
            if (childList.Count.Equals (1)) {
              var child = childList [0];
              child.Busy = true;

              context.ComponentStatus.Update (child); // update
            }

            item.ParentId = id;
            context.ComponentRelation.Add (item); // insert new
          }

          // extensions

          // Extension (CategoryRelationCollection)
          var categoryRelationList = action.CollectionAction.CategoryRelationCollection
            .Where (p => p.Category.Equals (categoryValue))
            .ToList ()
          ;

          // found
          if (categoryRelationList.Count.Equals (1)) {
            var categoryRelation = categoryRelationList [0]; // get extension using TComponentExtension

            var extension = TComponentExtension.Create (categoryRelation.Extension);
            extension.Request ();

            foreach (var extensionName in extension.ExtensionList) {
              switch (extensionName) {
                case TComponentExtensionNames.Document: {
                    //action.ModelAction.ExtensionDocumentModel.Id = id;

                    //var extDocument = ExtensionDocument.CreateDefault;
                    //extDocument.CopyFrom (action.ModelAction.ExtensionDocumentModel);

                    //context.ExtensionDocument.Add (extDocument);
                  }
                  break;

                case TComponentExtensionNames.Geometry: {
                    action.ModelAction.ExtensionGeometryModel.Id = id;

                    var extGeometry = ExtensionGeometry.CreateDefault;
                    extGeometry.CopyFrom (action.ModelAction.ExtensionGeometryModel);

                    context.ExtensionGeometry.Add (extGeometry);
                  }
                  break;

                case TComponentExtensionNames.Image: {
                    action.ModelAction.ExtensionImageModel.Id = id;

                    var extImage = ExtensionImage.CreateDefault;
                    extImage.CopyFrom (action.ModelAction.ExtensionImageModel);

                    context.ExtensionImage.Add (extImage);
                  }
                  break;

                case TComponentExtensionNames.Layout: {
                    action.ModelAction.ExtensionLayoutModel.Id = id;

                    var extLayout = ExtensionLayout.CreateDefault;
                    extLayout.CopyFrom (action.ModelAction.ExtensionLayoutModel);

                    context.ExtensionLayout.Add (extLayout);
                  }
                  break;

                case TComponentExtensionNames.Node: {
                    // Node reverse
                    if (compStatus.NodeReverse) {
                      // use Node from ModelAction (only)
                      if (compStatus.UseNodeModel) {
                        action.ModelAction.ExtensionNodeModel.ChildId = id; // update
                        context.ExtensionNode.Add (action.ModelAction.ExtensionNodeModel);

                        // update status
                        var parentId = action.ModelAction.ExtensionNodeModel.ParentId;

                        var statusList = context.ComponentStatus.AsQueryable()
                          .Where (p => p.Id.Equals (parentId))
                          .ToList ()
                        ;

                        // found
                        if (statusList.Count.Equals (1)) {
                          var model = statusList [0];
                          model.Busy = true;

                          context.ComponentStatus.Update (model);
                        }

                        context.SaveChanges (); // update all
                      }
                    }

                    else {
                      // use Node from ModelAction 
                      if (compStatus.UseNodeModel) {
                        action.ModelAction.ExtensionNodeModel.ParentId = id; // update
                        context.ExtensionNode.Add (action.ModelAction.ExtensionNodeModel);
                      }

                      // Use Node Collection
                      if (compStatus.UseNodeCollection) {
                        foreach (var nodeModel in action.CollectionAction.ExtensionNodeCollection) {
                          nodeModel.ParentId = id; // for sure
                          context.ExtensionNode.Add (nodeModel);
                        }
                      }

                      context.SaveChanges (); // update all

                      // update status
                      var nodeList = context.ExtensionNode.AsQueryable()
                        .Where (p => p.ParentId.Equals (id))
                        .ToList ()
                      ;

                      foreach (var node in nodeList) {
                        var statusList = context.ComponentStatus.AsQueryable()
                          .Where (p => p.Id.Equals (node.ChildId))
                          .ToList ()
                        ;

                        // found
                        if (statusList.Count.Equals (1)) {
                          var model = statusList [0];
                          model.Busy = true;

                          context.ComponentStatus.Update (model);
                        }
                      }

                      context.SaveChanges (); // update all
                    }
                  }
                  break;

                case TComponentExtensionNames.Text: {
                    action.ModelAction.ExtensionTextModel.Id = id;

                    var extText = ExtensionText.CreateDefault;
                    extText.CopyFrom (action.ModelAction.ExtensionTextModel);

                    context.ExtensionText.Add (extText);
                  }
                  break;

                case TComponentExtensionNames.Content: {
                    action.ModelAction.ExtensionContentModel.Id = id;

                    var extContent = ExtensionContent.CreateDefault;
                    extContent.CopyFrom (action.ModelAction.ExtensionContentModel);

                    context.ExtensionContent.Add (extContent);
                  }
                  break;
              }
            }
          }

          context.SaveChanges ();

          action.Result = TValidationResult.Success;
        }
      }

      catch (Exception exception) {
        Server.Models.Infrastructure.THelper.FormatException ("Insert", exception, action);
      }
    }
Beispiel #24
0
    static void ChangeFull (TModelContext context, TEntityAction action)
    {
      /*
      DATA IN
      - action.Id (Component id to change)
      - action.ModelAction (Component model)
      */

      //validate Name
      if (ValidateString (action)) {
        var id = action.Id;

        try {
          //Component Id must exist
          if (id.IsEmpty ()) {
            action.Result = new TValidationResult ($"[{action.Operation.CategoryType.Category} - Change Full] Component Id can NOT be NULL or EMPTY!");
          }

          else {
            // search Id
            var descriptors = context.ComponentDescriptor.AsQueryable().AsQueryable()
              .Where (p => p.Id.Equals (id))
              .ToList ()
            ;

            // Descriptor found
            if (descriptors.Count.Equals (1)) {
              var descriptor = descriptors [0];
              var categoryValue = descriptor.Category;

              // Info
              var infoList = context.ComponentInfo.AsQueryable ()
                .Where (p => p.Id.Equals (id))
                .ToList ()
              ;

              // Info found
              if (infoList.Count.Equals (1)) {
                var model = infoList [0];
                model.Change (action.ModelAction.ComponentInfoModel);
                context.ComponentInfo.Update (model);// change Info model
              }

              // Status 
              var compStatus = ComponentStatus.CreateDefault;

              var statusList = context.ComponentStatus.AsQueryable ()
                .Where (p => p.Id.Equals (id))
                .ToList ()
              ;

              // Status found
              if (statusList.Count.Equals (1)) {
                var model = statusList [0];
                model.Change (action.ModelAction.ComponentStatusModel);
                context.ComponentStatus.Update (model);// change Status model

                compStatus.CopyFrom (model);
              }

              // status collection
              foreach (var item in action.CollectionAction.ComponentStatusCollection) {
                var list = context.ComponentStatus.AsQueryable ()
                  .Where (p => p.Id.Equals (item.Id))
                  .ToList ()
                ;

                // Status found
                if (list.Count.Equals (1)) {
                  var model = list [0];
                  model.Change (item);
                  context.ComponentStatus.Update (model);// change Status model
                }
              }

              context.SaveChanges (); // save here

              // Component Relation Collection

              //remove old first (Parent)
              var relationList = context.ComponentRelation.AsQueryable ()
                .Where (p => p.ParentId.Equals (id))
                .ToList ()
              ;

              foreach (var relation in relationList) {
                // change old child status busy to false
                var childList = context.ComponentStatus.AsQueryable ()
                  .Where (p => p.Id.Equals (relation.ChildId))
                  .ToList ()
                ;

                // found
                if (childList.Count.Equals (1)) {
                  var child = childList [0];
                  child.Busy = false;

                  context.ComponentStatus.Update (child); // update
                }

                context.ComponentRelation.Remove (relation); // remove old
              }

              // insert new
              foreach (var item in action.CollectionAction.ComponentRelationCollection) {
                // change child status busy to true
                var childList = context.ComponentStatus.AsQueryable ()
                  .Where (p => p.Id.Equals (item.ChildId))
                  .ToList ()
                ;

                // found
                if (childList.Count.Equals (1)) {
                  var child = childList [0];
                  child.Busy = true;

                  context.ComponentStatus.Update (child); // update
                }

                item.ParentId = id;
                context.ComponentRelation.Add (item); // insert new
              }

              // extensions

              // search for extensions
              var categoryRelationList = action.CollectionAction.CategoryRelationCollection
                .Where (p => p.Category.Equals (categoryValue))
                .ToList ()
              ;

              // found
              if (categoryRelationList.Count.Equals (1)) {
                var categoryRelation = categoryRelationList [0]; // get extension using TComponentExtension

                var extension = TComponentExtension.Create (categoryRelation.Extension);
                extension.Request ();

                foreach (var extensionName in extension.ExtensionList) {
                  switch (extensionName) {
                    //case TComponentExtensionNames.Document: {
                    //    var list = context.ExtensionDocument
                    //      .Where (p => p.Id.Equals (id))
                    //      .ToList ()
                    //    ;

                    //    if (list.Count.Equals (1)) {
                    //      var model = list [0];
                    //      model.Change (action.ModelAction.ExtensionDocumentModel);
                    //      context.ExtensionDocument.Update (model); // change model
                    //    }
                    //  }
                    //  break;

                    case TComponentExtensionNames.Geometry: {
                        var list = context.ExtensionGeometry.AsQueryable ()
                          .Where (p => p.Id.Equals (id))
                          .ToList ()
                        ;

                        if (list.Count.Equals (1)) {
                          var model = list [0];
                          model.Change (action.ModelAction.ExtensionGeometryModel);
                          context.ExtensionGeometry.Update (model);  // change model
                        }
                      }
                      break;

                    case TComponentExtensionNames.Image: {
                        var list = context.ExtensionImage.AsQueryable ()
                          .Where (p => p.Id.Equals (id))
                          .ToList ()
                        ;

                        if (list.Count.Equals (1)) {
                          var model = list [0];
                          model.Change (action.ModelAction.ExtensionImageModel);
                          context.ExtensionImage.Update (model);  // change model
                        }
                      }
                      break;

                    case TComponentExtensionNames.Layout: {
                        var list = context.ExtensionLayout.AsQueryable ()
                          .Where (p => p.Id.Equals (id))
                          .ToList ()
                        ;

                        if (list.Count.Equals (1)) {
                          var model = list [0];
                          model.Change (action.ModelAction.ExtensionLayoutModel);
                          context.ExtensionLayout.Update (model); // change model
                        }
                      }
                      break;

                    case TComponentExtensionNames.Node: {
                        // Node reverse
                        if (compStatus.NodeReverse) {
                          // remove old first (use ChildId)
                          var nodeList = context.ExtensionNode.AsQueryable ()
                            .Where (p => p.ChildId.Equals (id))
                            .ToList ()
                          ;

                          // found
                          if (nodeList.Count.Equals (1)) {
                            var node = nodeList [0];

                            // remove
                            context.ExtensionNode.Remove (node);
                            context.SaveChanges (); // update

                            var nodeListParent = context.ExtensionNode.AsQueryable()
                              .Where (p => p.ParentId.Equals (node.ParentId))
                              .ToList ()
                            ;

                            // just me
                            if (nodeListParent.Count.Equals (1)) {
                              // status
                              var list = context.ComponentStatus.AsQueryable()
                                .Where (p => p.Id.Equals (node.ParentId))
                                .ToList ()
                              ;

                              // found (just one)
                              if (list.Count.Equals (1)) {
                                var model = list [0];
                                model.Busy = false;
                                context.ComponentStatus.Update (model);
                              }
                            }
                          }

                          // next insert new
                          foreach (var node in action.CollectionAction.ExtensionNodeCollection) {
                            // validate same 
                            if (node.ChildId.Equals (id)) {
                              context.ExtensionNode.Add (node);
                              break; // just one
                            }
                          }

                          context.SaveChanges (); // update

                          // update status
                          nodeList = context.ExtensionNode.AsQueryable()
                            .Where (p => p.ChildId.Equals (id))
                            .ToList ()
                          ;

                          // found (just one)
                          if (nodeList.Count.Equals (1)) {
                            var node = nodeList [0];

                            var list = context.ComponentStatus.AsQueryable()
                              .Where (p => p.Id.Equals (node.ParentId))
                              .ToList ()
                            ;

                            // found (just one)
                            if (list.Count.Equals (1)) {
                              var model = list [0];
                              model.Busy = true;
                              
                              context.ComponentStatus.Update (model);
                            }
                          }
                        }

                        else {
                          // remove old first (use ParentId)
                          var nodeList = context.ExtensionNode.AsQueryable()
                            .Where (p => p.ParentId.Equals (id))
                            .ToList ()
                          ;

                          foreach (var node in nodeList) {
                            // status
                            var list = context.ComponentStatus.AsQueryable()
                              .Where (p => p.Id.Equals (node.ChildId))
                              .ToList ()
                            ;

                            // found
                            if (list.Count.Equals (1)) {
                              var model = list [0];
                              model.Busy = false;
                              context.ComponentStatus.Update (model);
                            }

                            // remove Node
                            context.ExtensionNode.Remove (node);
                          }

                          // next insert new
                          foreach (var node in action.CollectionAction.ExtensionNodeCollection) {
                            // validate same parent
                            if (node.ParentId.Equals (id)) {
                              context.ExtensionNode.Add (node);
                            }
                          }

                          context.SaveChanges (); // update

                          // update status
                          nodeList = context.ExtensionNode.AsQueryable()
                            .Where (p => p.ParentId.Equals (id))
                            .ToList ()
                          ;

                          foreach (var node in nodeList) {
                            var list = context.ComponentStatus.AsQueryable()
                              .Where (p => p.Id.Equals (node.ChildId))
                              .ToList ()
                            ;

                            // found
                            if (list.Count.Equals (1)) {
                              var model = list [0];
                              model.Busy = true;
                              context.ComponentStatus.Update (model);
                            }
                          }
                        }
                      }
                      break;

                    case TComponentExtensionNames.Text: {
                        var list = context.ExtensionText.AsQueryable()
                          .Where (p => p.Id.Equals (id))
                          .ToList ()
                        ;

                        if (list.Count.Equals (1)) {
                          var model = list [0];
                          model.Change (action.ModelAction.ExtensionTextModel);
                          context.ExtensionText.Update (model); // change model
                        }
                      }
                      break;

                    case TComponentExtensionNames.Content: {
                        var list = context.ExtensionContent.AsQueryable()
                          .Where (p => p.Id.Equals (id))
                          .ToList ()
                        ;

                        if (list.Count.Equals (1)) {
                          var model = list [0];
                          model.Change (action.ModelAction.ExtensionContentModel);
                          context.ExtensionContent.Update (model); // change model
                        }
                      }
                      break;
                  }
                }
              }

              context.SaveChanges (); // update

              action.Result = TValidationResult.Success;
            }
          }
        }

        catch (Exception exception) {
          Models.Infrastructure.THelper.FormatException ("Change - Full", exception, action);
        }
      }
    }
Beispiel #25
0
    static bool RequestExtension (int categoryValue, Guid id, TModelContext context, TEntityAction action, TModelAction modelAction)
    {
      /*
      DATA OUT
      - action.ModelAction (model)
      - action.CollectionAction.ExtensionNodeCollection
      - action.ComponentModel.NodeModelCollection
      */

      var res = false;

      // Extension (CategoryRelationCollection)
      var categoryRelationList = action.CollectionAction.CategoryRelationCollection
        .Where (p => p.Category.Equals (categoryValue))
        .ToList ()
      ;

      // found
      if (categoryRelationList.Count.Equals (1)) {
        var categoryRelation = categoryRelationList [0]; // get extension using TComponentExtension

        var extension = TComponentExtension.Create (categoryRelation.Extension);
        extension.Request ();

        try {
          foreach (var extensionName in extension.ExtensionList) {
            switch (extensionName) {
              //case TComponentExtensionNames.Document: {
              //    var list = context.ExtensionDocument
              //      .Where (p => p.Id.Equals (id))
              //      .ToList ()
              //    ;

              //    if (list.Count.Equals (1)) {
              //      modelAction.ExtensionDocumentModel.CopyFrom (list [0]);
              //    }
              //  }
              //  break;

              case TComponentExtensionNames.Geometry: {
                  var list = context.ExtensionGeometry.AsQueryable()
                    .Where (p => p.Id.Equals (id))
                    .ToList ()
                  ;

                  if (list.Count.Equals (1)) {
                    modelAction.ExtensionGeometryModel.CopyFrom (list [0]);
                  }
                }
                break;

              case TComponentExtensionNames.Image: {
                  var list = context.ExtensionImage.AsQueryable()
                    .Where (p => p.Id.Equals (id))
                    .ToList ()
                  ;

                  if (list.Count.Equals (1)) {
                    modelAction.ExtensionImageModel.CopyFrom (list [0]);
                  }
                }
                break;

              case TComponentExtensionNames.Layout: {
                  var list = context.ExtensionLayout.AsQueryable()
                    .Where (p => p.Id.Equals (id))
                    .ToList ()
                  ;

                  if (list.Count.Equals (1)) {
                    modelAction.ExtensionLayoutModel.CopyFrom (list [0]);
                  }
                }
                break;

              case TComponentExtensionNames.Node: {
                  // child first
                  var childList = context.ExtensionNode.AsQueryable()
                    .Where (p => p.ChildId.Equals (id))
                    .ToList ()
                  ;

                  if (childList.Count.Equals (1)) {
                    var node = childList [0];
                    modelAction.ExtensionNodeModel.CopyFrom (node);

                    //  check duplicated
                    //var list = action.CollectionAction.ExtensionNodeCollection
                    //  .Where (p => p.ChildId.Equals (id))
                    //  .ToList ()
                    //;

                    //if (list.Count.Equals (0)) {
                    //  action.CollectionAction.ExtensionNodeCollection.Add (node);
                    //  action.ComponentModel.NodeModelCollection.Add (node);
                    //}
                  }

                  //else {
                  //  // parent next
                  //  //var parentList = context.ExtensionNode.AsQueryable()
                  //  //  .Where (p => p.ParentId.Equals (id))
                  //  //  .ToList ()
                  //  //;

                  //  //foreach (var node in parentList) {
                  //  //  //  check duplicated
                  //  //  var list = action.CollectionAction.ExtensionNodeCollection
                  //  //    .Where (p => p.ChildId.Equals (node.ChildId))
                  //  //    .ToList ()
                  //  //  ;

                  //  //  if (list.Count.Equals (0)) {
                  //  //    action.CollectionAction.ExtensionNodeCollection.Add (node);
                  //  //    action.ComponentModel.NodeModelCollection.Add (node);
                  //  //  }
                  //  //}
                  //}
                }
                break;

              case TComponentExtensionNames.Text: {
                  var list = context.ExtensionText.AsQueryable()
                    .Where (p => p.Id.Equals (id))
                    .ToList ()
                  ;

                  if (list.Count.Equals (1)) {
                    modelAction.ExtensionTextModel.CopyFrom (list [0]);
                  }
                }
                break;

              case TComponentExtensionNames.Content: {
                  var list = context.ExtensionContent.AsQueryable()
                    .Where (p => p.Id.Equals (id))
                    .ToList ()
                  ;

                  if (list.Count.Equals (1)) {
                    modelAction.ExtensionContentModel.CopyFrom (list [0]);
                  }
                }
                break;
            }
          }

          res = true;
        }

        catch (Exception exception) {
          THelper.FormatException ("RequestExtension - TOperationSupport", exception, action);
        }
      }

      return (res);
    }
Beispiel #26
0
    void ChangeActive (TModelContext context, TEntityAction action)
    {
      /*
      DATA IN
      - action.Id (Component id to change)
      - action.ModelAction (Component model)
      */

      var id = action.Id;

      try {
        //Component Id must exist
        if (id.IsEmpty ()) {
          action.Result = new TValidationResult ($"[{action.Operation.CategoryType.Category} - Change Active] Component Id can NOT be NULL or EMPTY!");
        }

        else {
          // search Id
          var descriptors = context.ComponentDescriptor.AsQueryable()
            .Where (p => p.Id.Equals (id))
            .ToList ()
          ;

          // Descriptor found
          if (descriptors.Count.Equals (1)) {
            var descriptor = descriptors [0];
            var categoryValue = descriptor.Category;

            // only one component has active status as true
            // reset old
            var statusList = context.ComponentStatus.AsQueryable()
              .Where (p => p.Active.Equals (true))
              .ToList ()
            ;

            if (statusList.Count.Equals (1)) {
              var model = statusList [0];
              model.Active = false; // reset old
              context.ComponentStatus.Update (model);// change Status model
            }

            // status collection
            foreach (var item in action.CollectionAction.ComponentStatusCollection) {
              var list = context.ComponentStatus.AsQueryable()
                .Where (p => p.Active.Equals (true))
                .ToList ()
              ;

              // Status found
              if (list.Count.Equals (1)) {
                var model = list [0];
                model.Active = false; // reset old
                context.ComponentStatus.Update (model);// change Status model

                break;
              }
            }

            // new Status 
            statusList = context.ComponentStatus.AsQueryable()
              .Where (p => p.Id.Equals (id))
              .ToList ()
            ;

            // Status found
            if (statusList.Count.Equals (1)) {
              var model = statusList [0];
              model.Change (action.ModelAction.ComponentStatusModel);
              context.ComponentStatus.Update (model);// change Status model
            }

            // status collection
            foreach (var item in action.CollectionAction.ComponentStatusCollection) {
              var list = context.ComponentStatus.AsQueryable()
                .Where (p => p.Id.Equals (item.Id))
                .ToList ()
              ;

              // Status found
              if (list.Count.Equals (1)) {
                var model = list [0];
                model.Change (item);
                context.ComponentStatus.Update (model);// change Status model

                break;
              }
            }

            context.SaveChanges (); // update

            action.Result = TValidationResult.Success;
          }
        }
      }

      catch (Exception exception) {
        Models.Infrastructure.THelper.FormatException ("Change - Active", exception, action);
      }
    }
Beispiel #27
0
    void Remove (TModelContext context, TEntityAction action)
    {
      /*
      DATA IN
      - action.Id (Component Id to remove)
      */

      var id = action.Id;

      try {
        //Id must exist
        if (id.IsEmpty ()) {
          action.Result = new TValidationResult ($"[{action.Operation.CategoryType.Category} - Remove] Component Id can NOT be NULL or EMPTY!");
        }

        else {
          // search Id
          var descriptors = context.ComponentDescriptor.AsQueryable()
            .Where (p => p.Id.Equals (id))
            .ToList ()
          ;

          // Descriptor found
          if (descriptors.Count.Equals (1)) {
            var descriptor = descriptors [0];
            var categoryValue = descriptor.Category;

            // remove from Info model
            var infoList = context.ComponentInfo.AsQueryable()
              .Where (p => p.Id.Equals (id))
              .ToList ()
            ;

            // Info found
            if (infoList.Count.Equals (1)) {
              var info = infoList [0];
              context.ComponentInfo.Remove (info);// remove from Info model

              // remove from Status model
              var statusList = context.ComponentStatus.AsQueryable()
                .Where (p => p.Id.Equals (id))
                .ToList ()
              ;

              var compStatus = ComponentStatus.CreateDefault;

              // Status found
              if (statusList.Count.Equals (1)) {
                var statusModel = statusList [0];
                context.ComponentStatus.Remove (statusModel);  // remove from Status model

                compStatus.CopyFrom (statusModel);
              }

              // status collection
              foreach (var item in action.CollectionAction.ComponentStatusCollection) {
                var list = context.ComponentStatus.AsQueryable()
                  .Where (p => p.Id.Equals (item.Id))
                  .ToList ()
                ;

                // Status found
                if (list.Count.Equals (1)) {
                  var statusModel = list [0];
                  context.ComponentStatus.Remove (statusModel);  // remove from Status model
                }
              }

              // extensions

              // remove extensions
              var categoryRelationList = action.CollectionAction.CategoryRelationCollection
                .Where (p => p.Category.Equals (categoryValue))
                .ToList ()
              ;

              // found
              if (categoryRelationList.Count.Equals (1)) {
                var categoryRelation = categoryRelationList [0]; // get extension using TComponentExtension

                var extension = TComponentExtension.Create (categoryRelation.Extension);
                extension.Request ();

                foreach (var extensionName in extension.ExtensionList) {
                  switch (extensionName) {
                    case TComponentExtensionNames.Document: {
                        //var list = context.ExtensionDocument
                        //  .Where (p => p.Id.Equals (id))
                        //  .ToList ()
                        //;

                        //if (list.Count.Equals (1)) {
                        //  context.ExtensionDocument.Remove (list [0]);
                        //}
                      }
                      break;

                    case TComponentExtensionNames.Geometry: {
                        var list = context.ExtensionGeometry.AsQueryable()
                          .Where (p => p.Id.Equals (id))
                          .ToList ()
                        ;

                        if (list.Count.Equals (1)) {
                          context.ExtensionGeometry.Remove (list [0]);
                        }
                      }
                      break;

                    case TComponentExtensionNames.Image: {
                        var list = context.ExtensionImage.AsQueryable()
                          .Where (p => p.Id.Equals (id))
                          .ToList ()
                        ;

                        if (list.Count.Equals (1)) {
                          context.ExtensionImage.Remove (list [0]);
                        }
                      }
                      break;

                    case TComponentExtensionNames.Layout: {
                        var list = context.ExtensionLayout.AsQueryable()
                          .Where (p => p.Id.Equals (id))
                          .ToList ()
                        ;

                        if (list.Count.Equals (1)) {
                          context.ExtensionLayout.Remove (list [0]);
                        }
                      }
                      break;

                    case TComponentExtensionNames.Node: {
                        // Node reverse
                        if (compStatus.NodeReverse) {
                          // request for ChildId
                          var nodeList = context.ExtensionNode.AsQueryable()
                            .Where (p => p.ChildId.Equals (id))
                            .ToList ()
                          ;

                          // just one
                          if (nodeList.Count.Equals (1)) {
                            var node = nodeList [0];

                            // status
                            var list = context.ComponentStatus.AsQueryable()
                              .Where (p => p.Id.Equals (node.ParentId))
                              .ToList ()
                            ;

                            // found (just me)
                            if (list.Count.Equals (1)) {
                              var model = list [0];
                              model.Busy = false;
                              context.ComponentStatus.Update (model);
                            }

                            // remove
                            context.ExtensionNode.Remove (node);
                          }
                        }

                        else {
                          // request for ParentId
                          var nodeList = context.ExtensionNode.AsQueryable()
                            .Where (p => p.ParentId.Equals (id))
                            .ToList ()
                          ;

                          foreach (var node in nodeList) {
                            // status
                            var list = context.ComponentStatus.AsQueryable()
                              .Where (p => p.Id.Equals (node.ChildId))
                              .ToList ()
                            ;

                            // found
                            if (list.Count.Equals (1)) {
                              var model = list [0];
                              model.Busy = false;
                              context.ComponentStatus.Update (model);
                            }

                            // remove
                            context.ExtensionNode.Remove (node);
                          }
                        }
                      }
                      break;

                    case TComponentExtensionNames.Text: {
                        var list = context.ExtensionText.AsQueryable()
                          .Where (p => p.Id.Equals (id))
                          .ToList ()
                        ;

                        if (list.Count.Equals (1)) {
                          context.ExtensionText.Remove (list [0]);
                        }
                      }
                      break;

                    case TComponentExtensionNames.Content: {
                        var list = context.ExtensionContent.AsQueryable()
                          .Where (p => p.Id.Equals (id))
                          .ToList ()
                        ;

                        if (list.Count.Equals (1)) {
                          context.ExtensionContent.Remove (list [0]);
                        }
                      }
                      break;
                  }
                }
              }

              // remove from Descriptor model
              context.ComponentDescriptor.Remove (descriptor);

              context.SaveChanges (); // update

              action.Result = TValidationResult.Success;
            }
          }
        }
      }

      catch (Exception exception) {
        Server.Models.Infrastructure.THelper.FormatException ("Remove", exception, action);
      }
    }