Ejemplo n.º 1
0
        public void MethodDumpIsValid()
        {
            // Act.
            ChangeAdd sut = new ChangeAdd(DistinguishedName, LdifAttributes);

            Assert.Equal(Dump, sut.Dump());
        }
Ejemplo n.º 2
0
        private static void Main()
        {
            using (FileStream fileStream = new FileStream("output.ldif", FileMode.Create))
                using (TextWriter textWriter = new StreamWriter(fileStream, Encoding.ASCII))
                    using (DirectorySearcher directorySearcher = new DirectorySearcher())
                    {
                        foreach (SearchResult searchResult in directorySearcher.FindAll())
                        {
                            List <LdifAttribute> ldifAttributes = new List <LdifAttribute>();
                            foreach (DictionaryEntry dictionaryEntry in searchResult.Properties)
                            {
                                List <object> values = new List <object>();
                                foreach (object value in (ResultPropertyValueCollection)dictionaryEntry.Value)
                                {
                                    /*
                                     * The library does not make assumptions on what the string representation of an object should be.
                                     * All types must be converted to either a string or byte[] before being boxed.
                                     */
                                    values.Add(value is byte[] ? value : value.ToString());
                                }

                                ldifAttributes.Add(new LdifAttribute((string)dictionaryEntry.Key, values));
                            }

                            ChangeAdd changeAdd = new ChangeAdd(searchResult.Path.Substring(7), ldifAttributes);
                            textWriter.WriteLine(changeAdd.Dump());
                        }
                    }
        }
Ejemplo n.º 3
0
    private void redo(List <Sync <T> > syncs)
    {
        List <Change <T> > changes = new List <Change <T> >();

        {
            for (int syncCount = 0; syncCount < syncs.Count; syncCount++)
            {
                Sync <T> sync = syncs[syncCount];
                switch (sync.getType())
                {
                case Sync <T> .Type.Set:
                {
                    SyncSet <T> syncSet = (SyncSet <T>)sync;
                    // Make change
                    ChangeSet <T> changeSet = new ChangeSet <T>();
                    {
                        changeSet.index = syncSet.index;
                        changeSet.values.AddRange(syncSet.news);
                    }
                    changes.Add(changeSet);
                }
                break;

                case Sync <T> .Type.Add:
                {
                    SyncAdd <T> syncAdd = (SyncAdd <T>)sync;
                    // Make change
                    ChangeAdd <T> changeAdd = new ChangeAdd <T>();
                    {
                        changeAdd.index = syncAdd.index;
                        changeAdd.values.AddRange(syncAdd.values);
                    }
                    changes.Add(changeAdd);
                }
                break;

                case Sync <T> .Type.Remove:
                {
                    SyncRemove <T> syncRemove = (SyncRemove <T>)sync;
                    // Make change
                    ChangeRemove <T> changeRemove = new ChangeRemove <T>();
                    {
                        changeRemove.index  = syncRemove.index;
                        changeRemove.number = syncRemove.values.Count;
                    }
                    changes.Add(changeRemove);
                }
                break;

                default:
                    Logger.LogError("unknown type: " + sync.getType() + "; " + this);
                    break;
                }
            }
        }
        if (changes.Count > 0)
        {
            this.processChange(changes);
        }
    }
Ejemplo n.º 4
0
        public void PropertyCountIsValid()
        {
            // Act.
            ChangeAdd sut = new ChangeAdd(DistinguishedName, LdifAttributes);

            // Assert.
            Assert.Equal(LdifAttributes.Length, sut.Count);
        }
Ejemplo n.º 5
0
        public void PropertyTypesIsValid()
        {
            // Act.
            ChangeAdd sut = new ChangeAdd(DistinguishedName, LdifAttributes);

            // Assert.
            Assert.Equal(AttributeTypes, sut.AttributeTypes);
        }
Ejemplo n.º 6
0
        public void CtorParameterAttributesNullCollectionIsValid()
        {
            // Act.
            ChangeAdd sut = new ChangeAdd(DistinguishedName, null);

            // Assert.
            Assert.NotNull(sut.LdifAttributes);
            Assert.Equal(0, sut.Count);
        }
Ejemplo n.º 7
0
        public void PropertyAttributesIsValid()
        {
            // Act.
            ChangeAdd sut = new ChangeAdd(DistinguishedName, LdifAttributes);

            Assert.Equal(LdifAttributes, sut);
            Assert.Equal(LdifAttributes, sut.LdifAttributes);
            Assert.Equal(sut, sut.LdifAttributes);
        }
Ejemplo n.º 8
0
        public void CollectionIndexerIsValid()
        {
            // Act.
            ChangeAdd sut = new ChangeAdd(DistinguishedName, LdifAttributes);

            // Assert.
            Assert.Equal(AttributeValuesObjectClass, sut[AttributeTypeObjectClass]);
            Assert.Equal(AttributeValuesDisplayName, sut[AttributeTypeDisplayName]);
            Assert.Equal(AttributeValuesGivenName, sut[AttributeTypeGivenName]);
            Assert.Equal(AttributeValuesSn, sut[AttributeTypeSn]);
        }
Ejemplo n.º 9
0
        public void MethodTryGetAttributeIsValid()
        {
            // Act.
            ChangeAdd sut = new ChangeAdd(DistinguishedName, LdifAttributes);

            // Assert.
            Assert.True(sut.TryGetAttribute(AttributeTypeObjectClass, out LdifAttribute _));
            Assert.True(sut.TryGetAttribute(AttributeTypeDisplayName, out LdifAttribute _));
            Assert.True(sut.TryGetAttribute(AttributeTypeGivenName, out LdifAttribute _));
            Assert.True(sut.TryGetAttribute(AttributeTypeSn, out LdifAttribute _));
        }
Ejemplo n.º 10
0
        public void MethodContainsIsValid()
        {
            // Act.
            ChangeAdd sut = new ChangeAdd(DistinguishedName, LdifAttributes);

            // Assert.
            Assert.True(sut.Contains(AttributeTypeObjectClass));
            Assert.True(sut.Contains(AttributeTypeDisplayName));
            Assert.True(sut.Contains(AttributeTypeGivenName));
            Assert.True(sut.Contains(AttributeTypeSn));
        }
Ejemplo n.º 11
0
    public void insert(int index, T property)
    {
        List <Change <T> > changes = new List <Change <T> >();

        {
            ChangeAdd <T> changeAdd = new ChangeAdd <T>();
            {
                changeAdd.index = index;
                changeAdd.values.Add(property);
            }
            changes.Add(changeAdd);
        }
        this.processChange(changes);
    }
Ejemplo n.º 12
0
    public void add(List <T> properties)
    {
        List <Change <T> > changes = new List <Change <T> >();

        {
            ChangeAdd <T> changeAdd = new ChangeAdd <T>();
            {
                changeAdd.index = this.vs.Count;
                changeAdd.values.AddRange(properties);
            }
            changes.Add(changeAdd);
        }
        this.processChange(changes);
    }
Ejemplo n.º 13
0
    public void add(T property, bool needOrder = false)
    {
        List <Change <T> > changes = new List <Change <T> >();

        {
            ChangeAdd <T> changeAdd = new ChangeAdd <T>();
            {
                // index
                {
                    // find
                    int index = this.vs.Count;
                    {
                        if (needOrder)
                        {
                            if (this.vs.Count > 0)
                            {
                                Data newData = property as Data;
                                for (int i = this.vs.Count - 1; i >= 0; i--)
                                {
                                    Data check = this.vs[i] as Data;
                                    if (check != null)
                                    {
                                        if (newData.uid > check.uid)
                                        {
                                            index = i + 1;
                                            break;
                                        }
                                        else
                                        {
                                            index = i;
                                        }
                                    }
                                    else
                                    {
                                        Logger.LogError("check null: " + this);
                                    }
                                }
                            }
                        }
                    }
                    // set
                    changeAdd.index = index;
                }
                changeAdd.values.Add(property);
            }
            changes.Add(changeAdd);
        }
        this.processChange(changes);
    }
Ejemplo n.º 14
0
    public void add(T property)
    {
        List <Change <T> > changes = new List <Change <T> >();

        {
            ChangeAdd <T> changeAdd = new ChangeAdd <T>();
            {
                // index
                {
                    // find
                    int index = this.vs.Count;
                    // set
                    changeAdd.index = index;
                }
                changeAdd.values.Add(property);
            }
            changes.Add(changeAdd);
        }
        this.processChange(changes);
    }
Ejemplo n.º 15
0
    public static void refresh <T>(LO <T> listProperty, IList <T> syncList)
    {
        if (listProperty == null || syncList == null)
        {
            Debug.LogError("IdentityUtils null error");
            return;
        }
        // find listChange
        List <Change <T> > changes = new List <Change <T> >();

        {
            // make the same count
            {
                // remove excess value
                if (listProperty.getValueCount() > syncList.Count)
                {
                    ChangeRemove <T> changeRemove = new ChangeRemove <T>();
                    {
                        changeRemove.index  = syncList.Count;
                        changeRemove.number = listProperty.getValueCount() - syncList.Count;
                    }
                    changes.Add(changeRemove);
                }
                // need insert
                else if (listProperty.getValueCount() < syncList.Count)
                {
                    ChangeAdd <T> changeAdd = new ChangeAdd <T>();
                    {
                        changeAdd.index = listProperty.getValueCount();
                        for (int i = listProperty.getValueCount(); i < syncList.Count; i++)
                        {
                            changeAdd.values.Add(syncList[i]);
                        }
                    }
                    changes.Add(changeAdd);
                }
            }
            // Copy each value
            {
                // oldChangeSet
                ChangeSet <T> oldChangeSet = null;
                // minCount
                int minCount = System.Math.Min(listProperty.getValueCount(), syncList.Count);
                // get changes
                for (int i = 0; i < minCount; i++)
                {
                    T oldValue = (T)listProperty.getValue(i);
                    T newValue = syncList[i];
                    if (!object.Equals(newValue, oldValue))
                    {
                        // get changeSet
                        ChangeSet <T> changeSet = null;
                        {
                            // setIdex: set position in list
                            int setIndex = i;
                            // check old
                            if (oldChangeSet != null)
                            {
                                if (oldChangeSet.index + oldChangeSet.values.Count == setIndex)
                                {
                                    changeSet = oldChangeSet;
                                }
                            }
                            // make new
                            if (changeSet == null)
                            {
                                changeSet = new ChangeSet <T>();
                                {
                                    changeSet.index = setIndex;
                                }
                                changes.Add(changeSet);
                                // set new old
                                oldChangeSet = changeSet;
                            }
                        }
                        // add value
                        changeSet.values.Add(newValue);
                    }
                }
            }
        }
        // Change
        if (changes.Count > 0)
        {
            listProperty.processChange(changes);
        }
    }
Ejemplo n.º 16
0
    public void processChange(List <Change <T> > changes)
    {
        if (changes.Count > 0)
        {
            // Make list change
            List <Sync <T> > syncs = new List <Sync <T> >();
            {
                for (int syncCount = 0; syncCount < changes.Count; syncCount++)
                {
                    Change <T> change = changes[syncCount];
                    switch (change.getType())
                    {
                    case Change <T> .Type.Set:
                    {
                        ChangeSet <T> changeSet = (ChangeSet <T>)change;
                        // keep old SyncSet
                        SyncSet <T> oldSyncSet = null;
                        if (changeSet.index >= 0 && changeSet.index + changeSet.values.Count <= this.vs.Count)
                        {
                            for (int i = 0; i < changeSet.values.Count; i++)
                            {
                                int setIndex = changeSet.index + i;
                                T   oldValue = this.vs[setIndex];
                                // check is different
                                bool isDifferent = true;
                                {
                                    if (object.Equals(oldValue, changeSet.values[i]))
                                    {
                                        isDifferent = false;
                                    }
                                    else
                                    {
                                        if (((Data)(object)changeSet.values[i]).uid == ((Data)(object)oldValue).uid)
                                        {
                                            isDifferent = false;
                                        }
                                    }
                                }
                                // Make change
                                if (isDifferent)
                                {
                                    // Change
                                    {
                                        // Set parent
                                        {
                                            ((Data)(object)oldValue).p            = null;
                                            ((Data)(object)changeSet.values[i]).p = this;
                                        }
                                        // add
                                        this.vs[setIndex] = changeSet.values[i];
                                    }
                                    // Make Sync
                                    {
                                        // get changeSet
                                        SyncSet <T> syncSet = null;
                                        {
                                            // check old
                                            if (oldSyncSet != null)
                                            {
                                                if (oldSyncSet.index + oldSyncSet.olds.Count == setIndex)
                                                {
                                                    syncSet = oldSyncSet;
                                                }
                                            }
                                            // make new
                                            if (syncSet == null)
                                            {
                                                syncSet = new SyncSet <T>();
                                                {
                                                    syncSet.index = setIndex;
                                                }
                                                syncs.Add(syncSet);
                                                // set new old
                                                oldSyncSet = syncSet;
                                            }
                                        }
                                        // add value
                                        {
                                            syncSet.olds.Add(oldValue);
                                            syncSet.news.Add(changeSet.values[i]);
                                        }
                                    }
                                }
                                else
                                {
                                    // Debug.LogError("why the same: " + oldValue + "; " + changeSet.values[i]);
                                }
                            }
                        }
                        else
                        {
                            Logger.LogError("index error: " + changeSet.index + "; " + this.vs.Count + "; " + this);
                        }
                    }
                    break;

                    case Change <T> .Type.Add:
                    {
                        ChangeAdd <T> changeAdd = (ChangeAdd <T>)change;
                        // Add
                        if (changeAdd.index >= 0 && changeAdd.index <= this.vs.Count)
                        {
                            // Change
                            {
                                // set parent
                                {
                                    foreach (T value in changeAdd.values)
                                    {
                                        if (value != null)
                                        {
                                            ((Data)(object)value).p = this;
                                        }
                                        else
                                        {
                                            Logger.LogError("why value null: " + this);
                                        }
                                    }
                                }
                                this.vs.InsertRange(changeAdd.index, changeAdd.values);
                            }
                            // Make Sync
                            {
                                SyncAdd <T> syncAdd = new SyncAdd <T>();
                                {
                                    syncAdd.index = changeAdd.index;
                                    syncAdd.values.AddRange(changeAdd.values);
                                }
                                syncs.Add(syncAdd);
                            }
                        }
                        else
                        {
                            Logger.LogError("index error: " + changeAdd.index + "; " + this.vs.Count + "; " + this);
                        }
                    }
                    break;

                    case Change <T> .Type.Remove:
                    {
                        ChangeRemove <T> changeRemove = (ChangeRemove <T>)change;
                        // Check index
                        if (changeRemove.number > 0 && changeRemove.index >= 0 && changeRemove.index + changeRemove.number <= this.vs.Count)
                        {
                            // Make sync: phai make sync truoc moi lay duoc oldValues
                            SyncRemove <T> syncRemove = new SyncRemove <T>();
                            {
                                syncRemove.index = changeRemove.index;
                                for (int i = 0; i < changeRemove.number; i++)
                                {
                                    syncRemove.values.Add(this.vs[changeRemove.index + i]);
                                }
                            }
                            syncs.Add(syncRemove);
                            // Change
                            {
                                // set parent
                                {
                                    foreach (T value in syncRemove.values)
                                    {
                                        if (value != null)
                                        {
                                            ((Data)(object)value).p = null;
                                        }
                                        else
                                        {
                                            Logger.LogError("why value null: " + this);
                                        }
                                    }
                                }
                                // Remove
                                this.vs.RemoveRange(changeRemove.index, changeRemove.number);
                            }
                        }
                        else
                        {
                            Logger.LogError("index error: " + this);
                        }
                    }
                    break;

                    default:
                        Logger.LogError("unknown change type: " + change.getType() + "; " + this);
                        break;
                    }
                }
            }
            // CallBack
            if (syncs.Count > 0)
            {
                foreach (ValueChangeCallBack callBack in p.callBacks.ToArray())
                {
                    callBack.onUpdateSync(this, syncs);
                }
            }
            else
            {
                // Debug.LogError("why don't have syncCount: " + this);
            }
        }
        else
        {
            Logger.LogError("why don't have changes: " + this);
        }
    }
Ejemplo n.º 17
0
 public override void copyWrapProperty(WrapProperty otherWrapProperty)
 {
     if (otherWrapProperty is LD <T> )
     {
         LD <T> otherLD = (LD <T>)otherWrapProperty;
         // find listChange
         List <Change <T> > changes = new List <Change <T> >();
         {
             // make the same count
             {
                 // remove excess value
                 if (this.getValueCount() > otherLD.getValueCount())
                 {
                     ChangeRemove <T> changeRemove = new ChangeRemove <T>();
                     {
                         changeRemove.index  = otherLD.getValueCount();
                         changeRemove.number = this.getValueCount() - otherLD.getValueCount();
                     }
                     changes.Add(changeRemove);
                 }
                 // need insert
                 else if (this.getValueCount() < otherLD.getValueCount())
                 {
                     ChangeAdd <T> changeAdd = new ChangeAdd <T>();
                     {
                         changeAdd.index = this.getValueCount();
                         for (int i = this.getValueCount(); i < otherLD.getValueCount(); i++)
                         {
                             Data oldData = (Data)(object)otherLD.vs[i];
                             changeAdd.values.Add((T)(object)DataUtils.cloneData(oldData));
                         }
                     }
                     changes.Add(changeAdd);
                 }
             }
             // Copy each value
             {
                 // oldChangeSet
                 ChangeSet <T> oldChangeSet = null;
                 // minCount
                 int minCount = Math.Min(this.getValueCount(), otherLD.getValueCount());
                 for (int i = 0; i < minCount; i++)
                 {
                     T oldValue = this.vs[i];
                     T newValue = otherLD.vs[i];
                     // get new add data
                     T    needAddData = default(T);
                     bool needAdd     = false;
                     {
                         // Get Data
                         Data oldData = oldValue != null ? (Data)(object)oldValue : null;
                         Data newData = newValue != null ? (Data)(object)newValue : null;
                         // Check need new
                         bool needNew = true;
                         {
                             if (oldData != null && newData != null)
                             {
                                 if (oldData.GetType() == newData.GetType())
                                 {
                                     if (oldData.uid == newData.uid)
                                     {
                                         needNew = false;
                                     }
                                 }
                             }
                         }
                         if (needNew)
                         {
                             needAdd     = true;
                             needAddData = (T)(object)DataUtils.cloneData(newData);
                         }
                         else
                         {
                             // update
                             DataUtils.copyData(oldData, newData);
                         }
                     }
                     // Make changeSet
                     if (needAdd)
                     {
                         // get changeSet
                         ChangeSet <T> changeSet = null;
                         {
                             // setIdex: set position in list
                             int setIndex = i;
                             // check old
                             if (oldChangeSet != null)
                             {
                                 if (oldChangeSet.index + oldChangeSet.values.Count == setIndex)
                                 {
                                     changeSet = oldChangeSet;
                                 }
                             }
                             // make new
                             if (changeSet == null)
                             {
                                 changeSet = new ChangeSet <T>();
                                 {
                                     changeSet.index = setIndex;
                                 }
                                 changes.Add(changeSet);
                                 // set new old
                                 oldChangeSet = changeSet;
                             }
                         }
                         // add value
                         changeSet.values.Add(needAddData);
                     }
                 }
             }
         }
         // Change
         if (changes.Count > 0)
         {
             this.processChange(changes);
         }
     }
     else
     {
         Logger.LogError("why not the same type wrapProperty: " + this + "; " + otherWrapProperty);
     }
 }
Ejemplo n.º 18
0
    public void copyList(List <T> list)
    {
        // find listChange
        List <Change <T> > changes = new List <Change <T> >();

        {
            // make the same count
            {
                // remove excess value
                if (this.getValueCount() > list.Count)
                {
                    ChangeRemove <T> changeRemove = new ChangeRemove <T>();
                    {
                        changeRemove.index  = list.Count;
                        changeRemove.number = this.getValueCount() - list.Count;
                    }
                    changes.Add(changeRemove);
                }
                // need insert
                else if (this.getValueCount() < list.Count)
                {
                    ChangeAdd <T> changeAdd = new ChangeAdd <T>();
                    {
                        changeAdd.index = this.getValueCount();
                        for (int i = this.getValueCount(); i < list.Count; i++)
                        {
                            changeAdd.values.Add(list[i]);
                        }
                    }
                    changes.Add(changeAdd);
                }
            }
            // Copy each value
            {
                // oldChangeSet
                ChangeSet <T> oldChangeSet = null;
                // minCount
                int minCount = Math.Min(this.getValueCount(), list.Count);
                for (int i = 0; i < minCount; i++)
                {
                    T oldValue = this.vs[i];
                    T newValue = list[i];
                    // get new add data
                    T    needAddData = default(T);
                    bool needAdd     = false;
                    {
                        if (!object.Equals(newValue, oldValue))
                        {
                            needAdd     = true;
                            needAddData = newValue;
                        }
                    }
                    // Make changeSet
                    if (needAdd)
                    {
                        // get changeSet
                        ChangeSet <T> changeSet = null;
                        {
                            // setIdex: set position in list
                            int setIndex = i;
                            // check old
                            if (oldChangeSet != null)
                            {
                                if (oldChangeSet.index + oldChangeSet.values.Count == setIndex)
                                {
                                    changeSet = oldChangeSet;
                                }
                            }
                            // make new
                            if (changeSet == null)
                            {
                                changeSet = new ChangeSet <T>();
                                {
                                    changeSet.index = setIndex;
                                }
                                changes.Add(changeSet);
                                // set new old
                                oldChangeSet = changeSet;
                            }
                        }
                        // add value
                        changeSet.values.Add(needAddData);
                    }
                }
            }
        }
        // Change
        if (changes.Count > 0)
        {
            this.processChange(changes);
        }
    }
Ejemplo n.º 19
0
 public override void copyWrapProperty(WrapProperty otherWrapProperty)
 {
     if (otherWrapProperty is LO <T> )
     {
         LO <T> otherLP = (LO <T>)otherWrapProperty;
         // find listChange
         List <Change <T> > changes = new List <Change <T> >();
         {
             // make the same count
             {
                 // remove excess value
                 if (this.getValueCount() > otherLP.getValueCount())
                 {
                     ChangeRemove <T> changeRemove = new ChangeRemove <T>();
                     {
                         changeRemove.index  = otherLP.getValueCount();
                         changeRemove.number = this.getValueCount() - otherLP.getValueCount();
                     }
                     changes.Add(changeRemove);
                 }
                 // need insert
                 else if (this.getValueCount() < otherLP.getValueCount())
                 {
                     ChangeAdd <T> changeAdd = new ChangeAdd <T>();
                     {
                         changeAdd.index = this.getValueCount();
                         for (int i = this.getValueCount(); i < otherLP.getValueCount(); i++)
                         {
                             changeAdd.values.Add(otherLP.vs[i]);
                         }
                     }
                     changes.Add(changeAdd);
                 }
             }
             // Copy each value
             {
                 // oldChangeSet
                 ChangeSet <T> oldChangeSet = null;
                 // minCount
                 int minCount = Math.Min(this.getValueCount(), otherLP.getValueCount());
                 for (int i = 0; i < minCount; i++)
                 {
                     T oldValue = this.vs[i];
                     T newValue = otherLP.vs[i];
                     // get new add data
                     T    needAddData = default(T);
                     bool needAdd     = false;
                     {
                         if (!object.Equals(newValue, oldValue))
                         {
                             needAdd     = true;
                             needAddData = newValue;
                         }
                     }
                     // Make changeSet
                     if (needAdd)
                     {
                         // get changeSet
                         ChangeSet <T> changeSet = null;
                         {
                             // setIdex: set position in list
                             int setIndex = i;
                             // check old
                             if (oldChangeSet != null)
                             {
                                 if (oldChangeSet.index + oldChangeSet.values.Count == setIndex)
                                 {
                                     changeSet = oldChangeSet;
                                 }
                             }
                             // make new
                             if (changeSet == null)
                             {
                                 changeSet = new ChangeSet <T>();
                                 {
                                     changeSet.index = setIndex;
                                 }
                                 changes.Add(changeSet);
                                 // set new old
                                 oldChangeSet = changeSet;
                             }
                         }
                         // add value
                         changeSet.values.Add(needAddData);
                     }
                 }
             }
         }
         // Change
         if (changes.Count > 0)
         {
             this.processChange(changes);
         }
     }
     else
     {
         Logger.LogError("why not the same type wrapProperty: " + this + "; " + otherWrapProperty);
     }
 }