Пример #1
0
        /// <summary>
        /// A method to set Instruction Guid IDs to Empty without Deserializing the collection if possible
        /// </summary>
        public void ClearInstructionIDs()
        {
            lock (this)
            {
                if (_Instructions != null)
                {
                    foreach (Instruction i in _Instructions)
                    {
                        i.ID = Guid.Empty;
                    }
                }

                if (_InstructionDocument != null)
                {
                    foreach (XElement n in _InstructionDocument.Root.Elements())
                    {
                        n.Elements().FirstOrDefault(i => i.Name.LocalName == "ID").Value = Guid.Empty.ToString();
                    }
                }

                if (_SerializationSourceInstructionDocument != null)
                {
                    _InstructionDocument = null;

                    StemStr str = new StemStr(_SerializationSourceInstructionDocument, _SerializationSourceInstructionDocument.Length);

                    int index = 0;
                    while ((index = str.IndexOf(VDClose, index)) > -1)
                    {
                        index += VDClose.Length;

                        int i = str.IndexOf(IDOpen, index);
                        if (i == -1)
                        {
                            continue;
                        }

                        index = i;

                        index += IDOpen.Length;

                        str.Overwrite(Guid.Empty.ToString(), index);
                    }

                    _SerializationSourceInstructionDocument = str.ToString();
                }
            }
        }
Пример #2
0
        /// <summary>
        /// A method to randomize Instruction Guid IDs without Deserializing the collection if possible
        /// </summary>
        public void RandomizeInstructionIDs()
        {
            lock (this)
            {
                List <Guid> ids = new List <Guid>();

                if (_Instructions != null)
                {
                    foreach (Instruction i in _Instructions)
                    {
                        i.ID = Guid.NewGuid();
                        ids.Add(i.ID);
                    }
                }

                if (_InstructionDocument != null)
                {
                    int x = 0;
                    foreach (XElement n in _InstructionDocument.Root.Elements())
                    {
                        if (ids.Count < x + 1)
                        {
                            ids.Add(Guid.NewGuid());
                        }

                        n.Elements().FirstOrDefault(i => i.Name.LocalName == "ID").Value = ids[x].ToString();

                        x++;
                    }
                }

                if (_SerializationSourceInstructionDocument != null)
                {
                    _InstructionDocument = null;

                    StemStr str = new StemStr(_SerializationSourceInstructionDocument, _SerializationSourceInstructionDocument.Length);

                    int index = 0;
                    int x     = 0;
                    while ((index = str.IndexOf(VDClose, index)) > -1)
                    {
                        index += VDClose.Length;

                        int i = str.IndexOf(IDOpen, index);
                        if (i == -1)
                        {
                            continue;
                        }

                        index = i;

                        index += IDOpen.Length;

                        if (ids.Count < x + 1)
                        {
                            ids.Add(Guid.NewGuid());
                        }

                        str.Overwrite(ids[x].ToString(), index);

                        x++;
                    }

                    _SerializationSourceInstructionDocument = str.ToString();
                }
            }
        }