예제 #1
0
        public static XProfile Load(XDocument document)
        {
            XProfile profile = new XProfile();

            XElement propertiesElement = document.Root.Element("Properties");
            XElement diffTypeElement   = propertiesElement?.Element("DiffType");
            XElement syncTypeElement   = propertiesElement?.Element("SyncType");
            XElement exclusionsElement = propertiesElement?.Element("Exclusions");
            XElement referencesElement = propertiesElement?.Element("References");

            // Load references
            XElement[] referenceElements = referencesElement?.Elements()?.ToArray();
            if (referenceElements != null)
            {
                foreach (XElement referenceElement in referenceElements)
                {
                    switch (referenceElement.Name.LocalName)
                    {
                    case "Assembly":
                        string file = referenceElement.Attribute("Path").Value;
                        string path = file;

                        if (!Path.IsPathRooted(path))
                        {
                            path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), path);
                        }

                        try
                        {
                            Assembly assembly = Assembly.LoadFile(path);
                        }
                        catch
                        {
                            throw new Exception("Could not find referenced assembly " + file);
                        }
                        break;
                    }
                }
            }

            // Decode properties
            DiffType diffType;

            if (diffTypeElement != null)
            {
                if (!Enum.TryParse(diffTypeElement.Value, out diffType))
                {
                    throw new FormatException("Could not parse the specified diff type");
                }

                profile.diffType = diffType;
            }

            SyncType syncType;

            if (syncTypeElement != null)
            {
                if (!Enum.TryParse(syncTypeElement.Value, out syncType))
                {
                    throw new FormatException("Could not parse the specified sync type");
                }

                profile.syncType = syncType;
            }

            List <string> exclusions = new List <string>();

            if (exclusionsElement != null)
            {
                foreach (XElement exclusionElement in exclusionsElement.Elements("Exclusion"))
                {
                    exclusions.Add(exclusionElement.Value);
                }
            }
            profile.exclusions = exclusions.ToArray();

            // TODO: Handle assembly references

            // Decode storages
            XElement leftElement = document.Root.Element("Left");

            if (leftElement == null)
            {
                throw new Exception("Sync profiles must define left storage");
            }
            profile.left = ReadStorage(leftElement);

            XElement rightElement = document.Root.Element("Right");

            if (rightElement == null)
            {
                throw new Exception("Sync profiles must define right storage");
            }
            profile.right = ReadStorage(rightElement);

            return(profile);
        }
예제 #2
0
        public static XProfile Load(XDocument document)
        {
            XProfile profile = new XProfile();

            XElement propertiesElement = document.Root.Element("Properties");
            XElement diffTypeElement = propertiesElement?.Element("DiffType");
            XElement syncTypeElement = propertiesElement?.Element("SyncType");
            XElement exclusionsElement = propertiesElement?.Element("Exclusions");
            XElement referencesElement = propertiesElement?.Element("References");

            // Load references
            XElement[] referenceElements = referencesElement?.Elements()?.ToArray();
            if (referenceElements != null)
            {
                foreach (XElement referenceElement in referenceElements)
                {
                    switch (referenceElement.Name.LocalName)
                    {
                        case "Assembly":
                            string file = referenceElement.Attribute("Path").Value;
                            string path = file;

                            if (!Path.IsPathRooted(path))
                                path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), path);

                            try
                            {
                                Assembly assembly = Assembly.LoadFile(path);
                            }
                            catch
                            {
                                throw new Exception("Could not find referenced assembly " + file);
                            }
                            break;
                    }
                }
            }

            // Decode properties
            DiffType diffType;
            if (diffTypeElement != null)
            {
                if (!Enum.TryParse(diffTypeElement.Value, out diffType))
                    throw new FormatException("Could not parse the specified diff type");

                profile.diffType = diffType;
            }

            SyncType syncType;
            if (syncTypeElement != null)
            {
                if (!Enum.TryParse(syncTypeElement.Value, out syncType))
                    throw new FormatException("Could not parse the specified sync type");

                profile.syncType = syncType;
            }

            List<string> exclusions = new List<string>();
            if (exclusionsElement != null)
            {
                foreach (XElement exclusionElement in exclusionsElement.Elements("Exclusion"))
                    exclusions.Add(exclusionElement.Value);
            }
            profile.exclusions = exclusions.ToArray();

            // TODO: Handle assembly references

            // Decode storages
            XElement leftElement = document.Root.Element("Left");
            if (leftElement == null)
                throw new Exception("Sync profiles must define left storage");
            profile.left = ReadStorage(leftElement);

            XElement rightElement = document.Root.Element("Right");
            if (rightElement == null)
                throw new Exception("Sync profiles must define right storage");
            profile.right = ReadStorage(rightElement);

            return profile;
        }