/// <summary>
        /// The read properties list.
        /// </summary>
        /// <returns>List of properties.</returns>
        protected virtual SearchableSortableBindingList <PresentedProperties> ReadPropertiesList()
        {
            SearchableSortableBindingList <PresentedProperties> result = null;

            if (File.Exists(this.theFullPath))
            {
                var lastWriteTime = new FileInfo(this.theFullPath).LastWriteTime;

                if (this.lastReadTime < lastWriteTime)
                {
                    this.lastReadTime = lastWriteTime;
                    result            = ReadPropertiesListFromFile(this.theFullPath);
                    if (this.Modified != null)
                    {
                        this.Modified(this, null);
                    }

                    if (this.theFullPath != this.currentModel.GetInfo().ModelPath + this.propertiesFileName)
                    {
                        this.XmlWriteProperties(this.propertiesList);
                    }
                }
            }

            return(result);
        }
예제 #2
0
        /// <summary>Makes a new properties file from other files shown properties.</summary>
        /// <param name="shown">New properties.</param>
        /// <param name="all">File from which visible new properties is done.</param>
        /// <returns><c>false.</c> if write to file fails.</returns>
        public static bool MakeFileFromOtherFilesHiddenProperties(
            ref PresentedPropertiesXml shown, ref PresentedPropertiesXml all)
        {
            // unordered list of shown properties to be constructed
            var newShownProperties =
                new SearchableSortableBindingList <PresentedProperties>();

            // add all non-hidden properties to the shown list
            foreach (var allProperty
                     in all.PropertiesList.Where(allProperty => !allProperty.Hidden))
            {
                newShownProperties.Add(allProperty);
            }

            // ordered list of shown properties to be constructed
            var orderedNewShownProperties =
                new SearchableSortableBindingList <PresentedProperties>();

            // copy original ordering from shown.PropertiesList to orderedNewShownProperties
            foreach (var shownProperty in shown.PropertiesList)
            {
                for (var i = 0; i < newShownProperties.Count; i++)
                {
                    // Compares to Name
                    if (!newShownProperties[i].Equals(shownProperty))
                    {
                        continue;
                    }

                    orderedNewShownProperties.Add(newShownProperties[i]);
                    newShownProperties.RemoveAt(i);
                    break;
                }
            }

            // put newly shown properties to the end of the list
            foreach (var shownProperty
                     in newShownProperties.Where(shownProperty => !orderedNewShownProperties.Contains(shownProperty)))
            {
                orderedNewShownProperties.Add(shownProperty);
            }

            shown.PropertiesList = orderedNewShownProperties;

            return(shown.XmlWriteProperties(shown.PropertiesList));
        }
        /// <summary>Sort BindingList by property.</summary>
        /// <param name="list">The list value.</param>
        /// <param name="direction">The direction.</param>
        /// <param name="property">The property.</param>
        public static void SortBindingList(
            ref BindingList <object> list, ListSortDirection direction, PropertyDescriptor property)
        {
            var sortableList = new SearchableSortableBindingList <object>();

            foreach (var adapter in list)
            {
                sortableList.Add(adapter);
            }

            sortableList.Sort(property, direction);

            list.Clear();

            foreach (var adapter in sortableList)
            {
                list.Add(adapter);
            }
        }
        /// <summary>
        /// Creates the default file.
        /// </summary>
        private void CreateDefaultFile()
        {
            var defaults = CsIniDefaultAttributes.Split('|');

            this.propertiesList = new SearchableSortableBindingList <PresentedProperties>();

            foreach (var property in defaults)
            {
                var splitChar = new char[1];
                splitChar[0] = ' ';
                var tmpProperty = property.Split(splitChar, StringSplitOptions.RemoveEmptyEntries);
                if (tmpProperty.Length <= 0)
                {
                    continue;
                }

                var defaultProp = new PresentedProperties(
                    tmpProperty[0],
                    tmpProperty[0],
                    string.Empty,
                    tmpProperty[7],
                    2,
                    PresentedProperties.DefaultWidth,
                    false);
                this.propertiesList.Add(defaultProp);
            }

            // Example of formula
            var formulaExample = new PresentedProperties(
                "Rebar Group Weight",
                "WEIGHT * NUMBER",
                string.Empty,
                "calc",
                2,
                PresentedProperties.DefaultWidth,
                false);

            this.propertiesList.Add(formulaExample);
            this.XmlWriteProperties(this.propertiesList);
        }
        /// <summary>Reads the properties list from file.</summary>
        /// <param name="fileName">Name of the file.</param>
        /// <returns>List of properties.</returns>
        public static SearchableSortableBindingList <PresentedProperties> ReadPropertiesListFromFile(string fileName)
        {
            SearchableSortableBindingList <PresentedProperties> result = null;

            var xmlFileInfo = new FileInfo(fileName);

            if (xmlFileInfo.Length > 0)
            {
                try
                {
                    // To allow any root name.
                    var xmlDocument = new XmlDocument();
                    xmlDocument.Load(fileName);
                    if (xmlDocument.DocumentElement != null)
                    {
                        var defaultNameSpace = xmlDocument.DocumentElement.Name;

                        var serializer =
                            new XmlSerializer(
                                typeof(SearchableSortableBindingList <PresentedProperties>),
                                new XmlRootAttribute(defaultNameSpace));
                        TextReader xmlReader = new StreamReader(fileName);
                        result = (SearchableSortableBindingList <PresentedProperties>)serializer.Deserialize(xmlReader);
                        xmlReader.Close();
                    }
                }
                catch (IOException ioe)
                {
                    Debug.WriteLine(ioe);
                }
                catch (XmlException xmle)
                {
                    Debug.WriteLine(xmle);
                }
            }

            return(result);
        }
        /// <summary>Merges all properties list from PropertiesToMerge to this instance properties list.</summary>
        /// <param name="propertiesToMerge">Properties to merge.</param>
        public void MergeProperties(PresentedPropertiesXml propertiesToMerge)
        {
            var propertiesExists =
                new SearchableSortableBindingList <PresentedProperties>();

            foreach (var property in propertiesToMerge.PropertiesList)
            {
                foreach (var oldProperty in this.PropertiesList)
                {
                    if (oldProperty.Equals(property))
                    {
                        oldProperty.Copy(property);
                        propertiesExists.Add(property);
                    }
                }
            }

            foreach (var property
                     in propertiesToMerge.PropertiesList.Where(property => !propertiesExists.Contains(property)))
            {
                this.PropertiesList.Add(property);
            }
        }
 /// <summary>The refresh dgw.</summary>
 /// <param name="reallyRefreshList">The really refresh list.</param>
 public void RefreshDGW(SearchableSortableBindingList <PresentedProperties> reallyRefreshList)
 {
     this.ShownPropertiesDGW.DataSource = this.newShownPresentedPropertiesXmlInstance.PropertiesList = reallyRefreshList;
     this.ShownPropertiesDGW.Refresh();
 }
 /// <summary>
 /// Ensures that file is read when properties list is next used.
 /// </summary>
 public void ForceReadFile()
 {
     this.visiblePropertiesList = null;
     this.lastReadTime          = DateTime.MinValue;
     this.readOnlyOnce          = 0;
 }