Example #1
0
        internal bool TryAddResourceOperation(ResourceObject Resource)
        {
            ObjectSetting objectSetting = settings.Configurations
                                          .Where(c => c.ObjectType == Resource.ObjectTypeName)
                                          .First();

            bool objectExcluded = ProcessingObjectExclusion(ref Resource, objectSetting);

            if (objectExcluded)
            {
                return(false);
            }
            else
            {
                config.Operations.Add(
                    new ResourceOperation()
                {
                    Operation           = ResourceOperationType.Add | ResourceOperationType.Update,
                    ResourceType        = Resource.ObjectType.SystemName,
                    ID                  = GetID(Resource, true),
                    AnchorAttributes    = objectSetting.AnchorAttributes.ToList(),
                    AttributeOperations = GetAttributeOperations(Resource, objectSetting)
                });
                return(true);
            }
        }
Example #2
0
        protected override void BeginProcessing()
        {
            if (RMConverterSetting == null)
            {
                ObjectSetting s = new ObjectSetting()
                {
                    AnchorAttributes            = AnchorAttributes.ToList(),
                    AttributExclusions          = AttributExclusions.ToList(),
                    IDPrefix                    = IDPrefix,
                    IncludeDefaultAttributes    = IncludeDefaultAttributes,
                    IncludeEmptyAttributeValues = IncludeEmptyAttributeValues,
                    ObjectSpecificExlusions     = RMConverterObjectExclusions.ToList(),
                    ObjectType                  = Resources[0].InternalObject.ObjectTypeName
                };

                RMConverterSetting = new ConverterSetting()
                {
                    Configurations = new List <ObjectSetting>()
                    {
                        s
                    }
                };
            }

            rmConfigConverter = new Converter(RMConverterSetting);
        }
Example #3
0
        protected override void ProcessRecord()
        {
            if (ObjectSettings != null)
            {
                this.WriteObject(
                    new ConverterSetting()
                {
                    Configurations = ObjectSettings.ToList()
                });
            }
            else
            {
                ObjectSetting config = new ObjectSetting()
                {
                    AnchorAttributes            = AnchorAttributes?.ToList(),
                    AttributExclusions          = AttributExclusions?.ToList(),
                    IDPrefix                    = IDPrefix,
                    IncludeDefaultAttributes    = IncludeDefaultAttributes.IsPresent,
                    IncludeEmptyAttributeValues = IncludeEmptyAttributeValues.IsPresent,
                    ObjectSpecificExlusions     = ObjectSpecificExlusions?.ToList(),
                    ObjectType                  = ObjectType,
                    ReferenceResolution         = ReferenceResolution.IsPresent
                };

                this.WriteObject(
                    new ConverterSetting()
                {
                    Configurations = new List <ObjectSetting>()
                    {
                        config
                    }
                });
            }
        }
Example #4
0
 internal static string GetFilePath(ResourceObject resourceObject, ObjectSetting objectSetting, string exportDirectory)
 {
     return(Path.Combine(
                exportDirectory,
                resourceObject.ObjectTypeName,
                GetFileName(resourceObject, objectSetting)
                ));
 }
Example #5
0
        private ConfigFile AddXMLReferencedObjects()
        {
            XmlSerializer xmlSerializer = new XmlSerializer(typeof(ConfigFile));
            string        configFile;

            using (StringWriter textWriter = new StringWriter())
            {
                xmlSerializer.Serialize(textWriter, this.config);
                configFile = textWriter.ToString();
            }

            ConfigFile file = new ConfigFile();

            List <ResourceObject> objRefResolutionDone = new List <ResourceObject>();
            List <ResourceObject> objRefNeedResolution = resolvedObject.ToList();

            do
            {
                foreach (ResourceObject r in objRefNeedResolution)
                {
                    ObjectSetting objectSetting = settings.Configurations
                                                  .Where(c => c.ObjectType == r.ObjectTypeName)
                                                  .FirstOrDefault();

                    string refID = GetID(r, true);

                    if (configFile.Contains(String.Format("##xmlref:{0}:ObjectID##", refID)))
                    {
                        file.Operations.Add(
                            new ResourceOperation()
                        {
                            Operation           = ResourceOperationType.None,
                            ResourceType        = r.ObjectType.SystemName,
                            ID                  = GetID(r, true),
                            AnchorAttributes    = objectSetting.AnchorAttributes.ToList(),
                            AttributeOperations = GetAttributeOperations(r, objectSetting, false)
                        });
                    }
                    objRefResolutionDone.Add(r);
                }
                objRefNeedResolution.Clear();

                foreach (ResourceObject r in resolvedObject)
                {
                    if (!objRefResolutionDone.Exists(x => x.ObjectID == r.ObjectID))
                    {
                        objRefNeedResolution.Add(r);
                    }
                }
            } while (objRefNeedResolution.Count != 0);

            file.Operations.AddRange(config.Operations);

            return(file);
        }
Example #6
0
        internal static string GetFileName(ResourceObject resourceObject, ObjectSetting objectSetting)
        {
            string fileName = String.Empty;

            foreach (string s in GetAnchorAttributeValues(resourceObject, objectSetting))
            {
                if (!string.IsNullOrEmpty(fileName))
                {
                    fileName += "-";
                }

                fileName += s;
            }

            return(illegalInFileName.Replace(fileName + ".xml", " "));
        }
Example #7
0
        private bool ProcessingObjectExclusion(ref ResourceObject resource, ObjectSetting objectSetting)
        {
            bool objectExcluded = false;

            // Processing ObjectSpecificExlusions
            if (objectSetting.ObjectSpecificExlusions != null)
            {
                foreach (var objectexclusion in objectSetting.ObjectSpecificExlusions)
                {
                    foreach (var k in objectexclusion.AnchorKeyValueList)
                    {
                        if (k.Value == resource.Attributes[k.Key].StringValue)
                        {
                            if (objectexclusion.AttributExclusions.Contains("*"))
                            {
                                //EXCLUDE OBJECT
                                objectExcluded = true;
                                break;
                            }
                            else
                            {
                                foreach (string ea in objectexclusion.AttributExclusions)
                                {
                                    if (!objectSetting.AnchorAttributes.Contains(ea))
                                    {
                                        resource.Attributes[ea].Value = null;
                                    }
                                }
                            }
                        }
                    }
                    if (objectExcluded)
                    {
                        break;
                    }
                }
            }

            return(objectExcluded);
        }
Example #8
0
        internal static List <string> GetSerializedFiles(ResourceObject resourceObject, ObjectSetting objectSetting, string exportDirectory, List <string> attributeSeparations)
        {
            List <string> list = new List <string>();

            string objFilePath           = GetFilePath(resourceObject, objectSetting, exportDirectory);
            string objectExportDirectory = Path.GetDirectoryName(objFilePath);
            string objFileName           = Path.GetFileName(objFilePath);

            list.Add(objFilePath);


            attributeSeparations?.ForEach(item =>
            {
                if (!resourceObject.Attributes[item].IsNull)
                {
                    list.Add(Path.Combine(objectExportDirectory, item, objFileName));
                }
            });


            return(list);
        }
Example #9
0
        private static List <string> GetAnchorAttributeValues(ResourceObject resourceObject, ObjectSetting objectSetting, List <ResourceObject> ResolvedResourceObjects)
        {
            List <string> anchorValues = new List <string>();

            foreach (string s in objectSetting.AnchorAttributes)
            {
                if (resourceObject.Attributes[s].Attribute.Type == AttributeType.Reference)
                {
                    ResourceObject refObj = null;
                    if (ResolvedResourceObjects != null)
                    {
                        var ob = ResolvedResourceObjects.Where(ro => ro.ObjectID.Value == resourceObject.Attributes[s].ReferenceValue.Value).FirstOrDefault();
                        if (ob != null)
                        {
                            refObj = ob;
                        }
                    }

                    if (refObj == null)
                    {
                        refObj = RmcWrapper.Client.GetResource(resourceObject.Attributes[s].ReferenceValue);
                    }

                    var nameAttribute = refObj.Attributes.FirstOrDefault(a => a.AttributeName == "Name");

                    if (nameAttribute != null)
                    {
                        anchorValues.Add(nameAttribute.StringValue);
                    }
                    else if (!String.IsNullOrEmpty(refObj.DisplayName))
                    {
                        anchorValues.Add(refObj.DisplayName);
                    }
                    else
                    {
                        anchorValues.Add(resourceObject.Attributes[s].StringValue);
                    }
                }
                else
                {
                    anchorValues.Add(resourceObject.Attributes[s].StringValue);
                }
            }
            return(anchorValues);
        }
Example #10
0
 private static List <string> GetAnchorAttributeValues(ResourceObject resourceObject, ObjectSetting objectSetting)
 {
     return(GetAnchorAttributeValues(resourceObject, objectSetting, null));
 }
Example #11
0
 private List <AttributeOperation> GetAttributeOperations(ResourceObject r, ObjectSetting objectSetting)
 {
     return(GetAttributeOperations(r, objectSetting, objectSetting.ReferenceResolution));
 }
Example #12
0
        private List <AttributeOperation> GetAttributeOperations(ResourceObject r, ObjectSetting objectSetting, bool ReferenceResolution)
        {
            List <AttributeOperation> operations = new List <AttributeOperation>();

            if (objectSetting == null)
            {
                objectSetting = ObjectSetting.GetDefaultObjectSetting(r.ObjectTypeName);

                /* Export minimum attributes
                 * minimumAttributes.ForEach(item =>
                 * {
                 *  operations.Add(new AttributeOperation()
                 *  {
                 *      Operation = AttributeOperationType.Replace,
                 *      Name = item,
                 *      Value = r.Attributes[item].StringValue
                 *  });
                 * });
                 *
                 * }
                 * else
                 * {*/
            }
            foreach (var a in r.Attributes)
            {
                // Processing AttributExclusions
                if (!objectSetting.AnchorAttributes.Contains(a.AttributeName))
                {
                    if (objectSetting.AttributExclusions != null)
                    {
                        if (objectSetting.AttributExclusions.Contains(a.AttributeName))
                        {
                            continue;
                        }
                    }

                    // Processing Default Attribute Exclusions
                    if (!objectSetting.IncludeDefaultAttributes)
                    {
                        if (ObjectSetting.DefaultAttributes.Contains(a.AttributeName))
                        {
                            continue;
                        }
                    }


                    // Skipping Empty Attribute Exclusions
                    if (!objectSetting.IncludeEmptyAttributeValues)
                    {
                        if (a.IsNull)
                        {
                            continue;
                        }
                    }
                }

                // Adding empty Add in case of a multiValue attribute
                if (a.Attribute.IsMultivalued)
                {
                    operations.Add(
                        new AttributeOperation()
                    {
                        Operation = AttributeOperationType.Replace,
                        Name      = a.AttributeName,
                    });
                }

                // Processing AttributOperation Conversation if needed
                if (ReferenceResolution)
                {
                    if (objectSetting.ReferenceResolutionAttributExclusions != null)
                    {
                        if (objectSetting.ReferenceResolutionAttributExclusions.Contains(a.AttributeName))
                        {
                            operations.AddRange(GetAttributeOperations(a));
                        }
                        else
                        {
                            operations.AddRange(ResolveReferenceAttribute(a));
                        }
                    }
                    else
                    {
                        operations.AddRange(ResolveReferenceAttribute(a));
                    }
                }
                else
                {
                    operations.AddRange(GetAttributeOperations(a));
                }
            }


            return(operations.OrderBy(a => a.Name).ToList());
        }