コード例 #1
0
        private InterfaceDeclarationSyntax generateMainDocumentCode(DrcCard document, IEnumerable <Field> drcCardFields)
        {
            InterfaceDeclarationSyntax classDeclaration;

            //  Create a class: (class Order)
            if (document.MainCardId == null)
            {
                classDeclaration = _documentGenerator.generateDocumentInterface(document.DrcCardName, document.Definition);
            }
            else
            {
                string shadowDocumentName = camelCaseDocumentName(document.DrcCardName);
                classDeclaration = _documentGenerator.generateShadowDocumentInterface(document.DrcCardName, shadowDocumentName, document.Definition);
            }

            var fields = documentPropertiesWithAllAttributes(drcCardFields);


            foreach (var property in fields)
            {
                // Add the field, the property and method to the class.
                classDeclaration = classDeclaration.AddMembers(property);
            }

            return(classDeclaration);
        }
コード例 #2
0
        //eğer relation kurulan documanın taşındığı yer orjinal yeri ise shadow oluşturulmaz merge edilir
        private void createShadows(List <DrcCard> collaborationCards, int targetVersionId)
        {
            var targetVersion = _documentTransferUnitOfWork.SubdomainVersionRepository.GetSubdomainVersionCardsWithId(targetVersionId);


            foreach (var card in collaborationCards)
            {
                if (card.MainCardId != null)        //shadow
                {
                    bool needToCreateShadow = true;

                    foreach (var drcDocument in targetVersion.DRCards)
                    {
                        if (drcDocument.Id == (int)card.MainCardId)
                        {
                            needToCreateShadow = false;
                        }
                        else if (drcDocument.MainCardId != null && (int)card.MainCardId == (int)drcDocument.MainCardId)
                        {
                            needToCreateShadow = false;
                        }
                    }

                    if (needToCreateShadow)
                    {
                        var     sourceName    = _documentTransferUnitOfWork.DrcCardRepository.getDrcCardName((int)card.MainCardId);
                        DrcCard newShadowCard = new DrcCard();
                        newShadowCard.Id = 0;
                        newShadowCard.SubdomainVersionId = targetVersionId;
                        newShadowCard.DrcCardName        = sourceName + " Shadow";
                        newShadowCard.MainCardId         = card.MainCardId;
                        _documentTransferUnitOfWork.DrcCardRepository.Add(newShadowCard);
                    }
                }
                else //normal document
                {
                    bool needToCreateShadow = true;
                    foreach (var drcDocument in targetVersion.DRCards)
                    {
                        if (drcDocument.MainCardId == card.Id)
                        {
                            needToCreateShadow = false;
                        }
                    }

                    if (needToCreateShadow)
                    {
                        DrcCard newShadowCard = new DrcCard();
                        newShadowCard.Id                 = 0;
                        newShadowCard.DrcCardName        = card.DrcCardName + " Shadow";
                        newShadowCard.SubdomainVersionId = targetVersionId;
                        newShadowCard.MainCardId         = card.Id;
                        _documentTransferUnitOfWork.DrcCardRepository.Add(newShadowCard);
                    }
                }
            }
        }
コード例 #3
0
        public string AddShadowCard(DrcCard drcCard)
        {
            var version = _drcUnitOfWork.SubdomainVersionRepository.GetSubdomainVersionCardsWithId(drcCard.SubdomainVersionId);

            foreach (var versionCard in version.DRCards.ToList())
            {
                if (versionCard.MainCardId != null && versionCard.MainCardId == (int)drcCard.MainCardId)
                {
                    return("You already have this shadow document with name: " + versionCard.DrcCardName + ". You are not allowed to create second one in same subdomain version.");
                }
            }

            _drcUnitOfWork.DrcCardRepository.Add(drcCard);
            _drcUnitOfWork.Complete();


            return("");
        }
コード例 #4
0
        private bool MoveDocument(int drcCardId, int targetSubdomainVersionId, string newDrcCardName)
        {
            try
            {
                List <DrcCard> collaborationCards = getCollaborationCardsofACard(drcCardId);
                createShadows(collaborationCards, targetSubdomainVersionId); //this will create shadows

                DrcCard document = _documentTransferUnitOfWork.DrcCardRepository.GetById(drcCardId);

                document.SubdomainVersionId = targetSubdomainVersionId;
                document.DrcCardName        = newDrcCardName;
                updateDrcCardCollaborationsAfterMove(drcCardId, targetSubdomainVersionId);
                _documentTransferUnitOfWork.Complete();

                removeUnusedCollaborationsAfterMove(collaborationCards);
                _documentTransferUnitOfWork.Complete();
                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
コード例 #5
0
        private string checkDocumentHasAShadowDocument(DrcCard drcCard)
        {
            var subdomainVersions = _drcUnitOfWork.SubdomainVersionRepository.GetAll();

            ArrayList listOfPossibleShadowAreas = new ArrayList();

            foreach (var subdomainVersion in subdomainVersions)
            {
                var versionWithReferences = _drcUnitOfWork.SubdomainVersionRepository.GetVersionWithReferencesById(subdomainVersion.Id);
                foreach (var versionReference in versionWithReferences.ReferencedSubdomainVersions)
                {
                    if (versionReference.ReferencedVersionId == drcCard.SubdomainVersionId)
                    {
                        listOfPossibleShadowAreas.Add(versionReference.SubdomainVersionId);
                    }
                }
            }
            string shadowUsedVersions = null;

            foreach (int possibleShadowAreaVersion in listOfPossibleShadowAreas)
            {
                var versionDocuments = _drcUnitOfWork.DrcCardRepository.getAllCardsBySubdomainVersion(possibleShadowAreaVersion);

                foreach (var drcDocument in versionDocuments)
                {
                    if (drcDocument.MainCardId == drcCard.Id)
                    {
                        var    version   = _drcUnitOfWork.SubdomainVersionRepository.GetById(drcDocument.SubdomainVersionId);
                        string Subdomain = _drcUnitOfWork.SubdomainRepository.GetSubdomainName(version.SubdomainId);
                        shadowUsedVersions += Subdomain + " > " + version.VersionNumber + " > " + drcDocument.DrcCardName + " ";
                    }
                }
            }

            return(shadowUsedVersions);
        }
コード例 #6
0
        private string GenerateClassString(DrcCard document, string subdomainNamespace)
        {
            //full document template with required libraries
            var fullDocument = _documentGenerator.newFullDocumentTemplate();

            // Create a namespace: (namespace CodeGeneration)
            var @namespace = _documentGenerator.generateNamespaceDeclaration(subdomainNamespace);


            //Document Fields
            var documentFields = _drcUnitOfWork.FieldRepository.getDrcCardAllFieldsWithoutTracking(document.Id).ToList();

            //I need also bring source document fields for shadow documents
            if (document.MainCardId != null)
            {
                var shadowSourceFields = _drcUnitOfWork.FieldRepository.getDrcCardAllFieldsWithoutTracking((int)document.MainCardId).ToList();

                foreach (var shadowField in shadowSourceFields)
                {
                    documentFields.Add(shadowField);
                }
            }

            var mainDocument = generateMainDocumentCode(document, documentFields);

            List <Field> allFieldsToGenerateComplexInterfaces = new List <Field>();

            int codeGenerationLevelSupport = 12;

            //codeGenerationLevelSupport means How many level code generation support do we want.
            //An Field name example:Lines[].DetailLines[].ComplexA.Count=> to generate code for this you need to dig  3 layer
            //An Field name example:Lines[].DetailLines[].ComplexA.ComplexB.Details[].ID=> to generate code for this you need to dig 5 layer
            for (int i = 1; i < codeGenerationLevelSupport; i++)
            {
                var firstFields    = cloneList(documentFields);
                var fieldsForLayer = cloneListByReshapingFieldAttribute(firstFields, i);

                //this will stop digging fields deeper
                if (fieldsForLayer.Count == 0)
                {
                    break;
                }

                foreach (var field in fieldsForLayer)
                {
                    allFieldsToGenerateComplexInterfaces.Add(field);
                }
            }

            //Interfaces that for main document
            List <InterfaceDeclarationSyntax> childInterfacesOfMainDocument = generateChildInterfacesCodeOfMainDocument(allFieldsToGenerateComplexInterfaces);


            var fieldsForEnumGeneration = cloneList(documentFields);

            //I am planning to store enum first then I will compare that enums. Because same enum type could be use
            List <EnumDeclarationSyntax> documentEnumsFromAllLayers = generateEnums(fieldsForEnumGeneration);



            // Add the interface classes to the namespace.
            @namespace = @namespace.AddMembers(mainDocument);

            foreach (var child in childInterfacesOfMainDocument)
            {
                @namespace = @namespace.AddMembers(child);
            }

            foreach (var child in documentEnumsFromAllLayers)
            {
                @namespace = @namespace.AddMembers(child);
            }



            fullDocument = fullDocument.WithMembers(SyntaxFactory.SingletonList <MemberDeclarationSyntax>(@namespace));
            return(fullDocument.NormalizeWhitespace().ToFullString());
        }
コード例 #7
0
        public void CloneSourceVersionToNewVersion(SubdomainVersion subdomainVersion)
        {
            var sourceId = (int)subdomainVersion.SourceVersionId;

            var sourceVersionCards = _drcUnitOfWork.DrcCardRepository.getAllCardsBySubdomainVersion(sourceId);


            IList <SourceNewDrcCardMap> sourceNewDrcCardMaps = new List <SourceNewDrcCardMap>();

            foreach (var sourceVersionCard in sourceVersionCards)
            {
                SourceNewDrcCardMap sourceNewDrcCardMap = new SourceNewDrcCardMap();
                sourceNewDrcCardMap.SourceCardId = sourceVersionCard.Id;

                DrcCard newDrcCard = new DrcCard();
                newDrcCard    = sourceVersionCard;
                newDrcCard.Id = 0;
                newDrcCard.SubdomainVersionId = 0;
                newDrcCard.SubdomainVersion   = subdomainVersion;
                _drcUnitOfWork.DrcCardRepository.Add(newDrcCard);
                _drcUnitOfWork.Complete();
                sourceNewDrcCardMap.NewCardId = newDrcCard.Id;
                sourceNewDrcCardMaps.Add(sourceNewDrcCardMap);
            }

            foreach (var sourceNewDrcCardMap in sourceNewDrcCardMaps)
            {
                var newDrcCard = _drcUnitOfWork.DrcCardRepository.GetById(sourceNewDrcCardMap.NewCardId);
                var sourceCardResponsibilities =
                    _drcUnitOfWork.DrcCardResponsibilityRepository.GetDrcCardResponsibilitiesByDrcCardId(
                        sourceNewDrcCardMap.SourceCardId);

                foreach (var sourceDrcCardResponsibility in sourceCardResponsibilities)
                {
                    Responsibility newResponsibility = new Responsibility();
                    newResponsibility =
                        _drcUnitOfWork.ResponsibilityRepository.GetByIdWithoutTracking(sourceDrcCardResponsibility
                                                                                       .ResponsibilityId);
                    var sourceResponsibilityCollaborations = _drcUnitOfWork.DrcCardResponsibilityRepository.GetResponsibilityCollaborationsByResponsibilityId(newResponsibility.Id);
                    newResponsibility.Id = 0;
                    _drcUnitOfWork.ResponsibilityRepository.Add(newResponsibility);

                    DrcCardResponsibility newDrcCardResponsibility = new DrcCardResponsibility();
                    newDrcCardResponsibility.DrcCard                 = newDrcCard;
                    newDrcCardResponsibility.Responsibility          = newResponsibility;
                    newDrcCardResponsibility.IsRelationCollaboration = false;
                    _drcUnitOfWork.DrcCardResponsibilityRepository.Add(newDrcCardResponsibility);

                    foreach (var sourceResponsibilityCollaboration in sourceResponsibilityCollaborations)
                    {
                        int newDrcCardId = sourceNewDrcCardMaps
                                           .Where(c => c.SourceCardId == sourceResponsibilityCollaboration.DrcCardId)
                                           .Select(c => c.NewCardId).Single();
                        DrcCardResponsibility newResponsibilityCollaboration = new DrcCardResponsibility();
                        newResponsibilityCollaboration.DrcCardId               = newDrcCardId;
                        newResponsibilityCollaboration.Responsibility          = newResponsibility;
                        newResponsibilityCollaboration.IsRelationCollaboration =
                            sourceResponsibilityCollaboration.IsRelationCollaboration;
                        _drcUnitOfWork.DrcCardResponsibilityRepository.Add(newResponsibilityCollaboration);
                        _drcUnitOfWork.Complete();
                    }
                    _drcUnitOfWork.Complete();
                }

                var sourceCardFields = _drcUnitOfWork.DrcCardFieldRepository
                                       .GetDrcCardFieldsByDrcCardId(sourceNewDrcCardMap.SourceCardId);

                foreach (var sourceCardField in sourceCardFields)
                {
                    Field newField = new Field();
                    newField = _drcUnitOfWork.FieldRepository.GetByIdWithoutTracking(sourceCardField.FieldId);
                    var sourceFieldCollaboration =
                        _drcUnitOfWork.DrcCardFieldRepository.GetFieldCollaborationByFieldId(newField.Id);
                    newField.Id = 0;
                    _drcUnitOfWork.FieldRepository.Add(newField);

                    DrcCardField newDrcCardField = new DrcCardField();
                    newDrcCardField.DrcCard = newDrcCard;
                    newDrcCardField.Field   = newField;
                    newDrcCardField.IsRelationCollaboration = false;
                    _drcUnitOfWork.DrcCardFieldRepository.Add(newDrcCardField);

                    if (sourceFieldCollaboration != null)
                    {
                        int newCollaborationDrcCardId = sourceNewDrcCardMaps
                                                        .Where(c => c.SourceCardId == sourceFieldCollaboration.DrcCardId)
                                                        .Select(c => c.NewCardId).Single();

                        DrcCardField newDrcCardFieldCollaboration = new DrcCardField();
                        newDrcCardFieldCollaboration.DrcCardId = newCollaborationDrcCardId;
                        newDrcCardFieldCollaboration.Field     = newField;
                        newDrcCardFieldCollaboration.IsRelationCollaboration = true;
                        _drcUnitOfWork.DrcCardFieldRepository.Add(newDrcCardFieldCollaboration);
                        _drcUnitOfWork.Complete();
                    }
                    _drcUnitOfWork.Complete();
                }

                var sourceCardAuthorizations = _drcUnitOfWork.AuthorizationRepository.GetAuthorizationsByDrcCardId(sourceNewDrcCardMap.SourceCardId);

                foreach (var sourceCardAuthorization in sourceCardAuthorizations)
                {
                    Authorization newAuthorization = new Authorization();
                    newAuthorization = _drcUnitOfWork.AuthorizationRepository.GetByIdWithoutTracking(sourceCardAuthorization.Id);
                    var oldAuthorizationRoles = _drcUnitOfWork.AuthorizationRoleRepository.GetAuthorizationRolesByAuthorizationId(newAuthorization.Id);
                    newAuthorization.Id        = 0;
                    newAuthorization.DrcCardId = 0;
                    newAuthorization.DrcCard   = newDrcCard;
                    _drcUnitOfWork.AuthorizationRepository.Add(newAuthorization);

                    foreach (var oldAuthorizationRole in oldAuthorizationRoles)
                    {
                        AuthorizationRole authorizationRole = new AuthorizationRole();
                        authorizationRole.AuthorizationId = newAuthorization.Id;
                        authorizationRole.RoleId          = oldAuthorizationRole.RoleId;
                        _drcUnitOfWork.AuthorizationRoleRepository.Add(authorizationRole);
                        _drcUnitOfWork.Complete();
                    }
                }
                _drcUnitOfWork.Complete();
            }
        }