예제 #1
0
        public void Merge(Directives other)
        {
            if (Ignore != null && other.Ignore != null)
            {
                Ignore.Merge(other.Ignore);
            }
            else if (other.Ignore != null)
            {
                Ignore = other.Ignore;
            }

            if (other.UseTortoiseMerge != null)
            {
                UseTortoiseMerge = other.UseTortoiseMerge;
            }

            if (Include != null && other.Include != null)
            {
                Include.Merge(other.Include);
            }
            else if (other.Include != null)
            {
                Include = other.Include;
            }

            if (other.DefaultCompression != null)
            {
                DefaultCompression = other.DefaultCompression;
            }
            if (other.ExternalDiff != null)
            {
                ExternalDiff = other.ExternalDiff;
            }
            if (other.ExternalMerge != null)
            {
                ExternalMerge = other.ExternalMerge;
            }
            if (other.ExternalMerge2Way != null)
            {
                ExternalMerge2Way = other.ExternalMerge2Way;
            }
            if (other.NonBlockingDiff != null)
            {
                NonBlockingDiff = other.NonBlockingDiff;
            }
            if (other.m_UserName != null)
            {
                m_UserName = other.m_UserName;
            }
            if (!string.IsNullOrEmpty(other.ObjectStorePath))
            {
                ObjectStorePath = other.ObjectStorePath;
            }

            if (other.Externals != null)
            {
                if (Externals == null)
                {
                    Externals = new Dictionary <string, Extern>();
                }
                foreach (var x in other.Externals)
                {
                    Externals[x.Key] = x.Value;
                }
            }

            foreach (var x in other.Tokens)
            {
                Newtonsoft.Json.Linq.JToken prior;
                if (Tokens.TryGetValue(x.Key, out prior))
                {
                    if (prior.Type == Newtonsoft.Json.Linq.JTokenType.Array && x.Value.Type == Newtonsoft.Json.Linq.JTokenType.Array)
                    {
                        Newtonsoft.Json.Linq.JArray array = prior as Newtonsoft.Json.Linq.JArray;
                        Newtonsoft.Json.Linq.JArray merge = x.Value as Newtonsoft.Json.Linq.JArray;
                        foreach (var y in merge)
                        {
                            array.Add(y);
                        }
                        continue;
                    }
                }
                Tokens[x.Key] = x.Value;
            }

            if (other.Hooks != null)
            {
                if (Hooks != null)
                {
                    foreach (var x in other.Hooks)
                    {
                        Hooks.Add(x);
                    }
                }
                else
                {
                    Hooks = other.Hooks;
                }
            }

            if (other.Sparse.Count > 0)
            {
                Sparse = Sparse.Concat(other.Sparse).ToList();
            }
            if (other.Excludes.Count > 0)
            {
                Excludes = Excludes.Concat(other.Excludes).ToList();
            }

            if (other.TagPresets != null)
            {
                if (TagPresets == null)
                {
                    TagPresets = new List <TagPreset>();
                }
                TagPresets.AddRange(other.TagPresets);
                TagPresets = TagPresets.Distinct().ToList();
            }
        }