Exemplo n.º 1
0
        /// <summary>
        /// Fills the available command buffer with the current available options.
        /// </summary>
        public static void UpdateCommandBuffer()
        {
            var references = DataHolder.GUIReferences;
            var data       = DataHolder.TerminalData;

            SList.Clear(data.AvailableCommands);

            var currentText = references.Input.value;

            var programName = CommandLineUtil.GetCommandName(currentText);
            var program     = Shell.FindProgramByCommand(programName);

            Action bufferFiller;

            if (program == null)
            {
                bufferFiller = null;
            }
            else
            {
                bufferFiller = Shell.GetProgramBufferFillerMethod(program);
            }

            if (bufferFiller == null)
            {
                FileSystem.FilleCommandBufferWithFileSystem(FillBufferFileSystemOptions.IncludeAll);
            }
            else
            {
                bufferFiller();
            }

            ChangeToAvailableCommandsBuffer();
        }
Exemplo n.º 2
0
        public static void CachePanels(WindowComponent windowComponent)
        {
            SList.Clear(windowComponent.Panels);

            var panels = windowComponent.gameObject.GetComponentsInChildren <UIPanel>(true);

            for (int i = 0; i < panels.Length; i++)
            {
                var panel = panels[i];
                SList.Add(windowComponent.Panels, panel);
            }
        }
Exemplo n.º 3
0
        public static void CacheWidgets(WindowComponent windowComponent)
        {
            SList.Clear(windowComponent.Widgets);

            var widgets = windowComponent.gameObject.GetComponentsInChildren <UIWidget>(true);

            for (int i = 0; i < widgets.Length; i++)
            {
                var widget = widgets[i];
                SList.Add(windowComponent.Widgets, widget);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Returns a list containing all of the dir files.
        /// </summary>
        public static void CacheDirFiles(HashDir dir)
        {
            SList.Clear(dir.Files);
            for (int i = 0; i < dir.FilesId.Count; i++)
            {
                var fileId = dir.FilesId[i];
                var file   = FindFileById(fileId);
                DebugUtil.Assert(file == null, string.Format("THE DIR {0} HAS A INVALID FILE {1}", dir.Name, fileId));

                file.ParentDirId = dir.DirId;
                file.ParentDir   = dir;

                SList.Add(dir.Files, file);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Cache the dirs children based on the ChildsDirid values.
        /// </summary>
        public static void CacheDirChildren(HashDir dir)
        {
            SList.Clear(dir.Childs);
            for (int i = 0; i < dir.ChildsDirId.Count; i++)
            {
                var childId = dir.ChildsDirId[i];
                var child   = FindDirById(childId);

                DebugUtil.Assert(child == null, string.Format("THE DIR {0} HAS A INVALID CHILD {1}", dir.Name, childId));

                child.ParentDirId = dir.DirId;
                child.ParentDir   = dir;

                SList.Add(dir.Childs, child);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Calculates and return the full path of the dir.
        /// </summary>
        public static string GetDirFullPath(HashDir hashDir)
        {
            var    dir = hashDir;
            string path;

            // Root folder is treated differently
            if (dir.ParentDirId == -1)
            {
                DebugUtil.Assert(dir.Name != PathUtil.PathSeparator, string.Format("THE DIR {0} HAS NO PARENT AND IT'S THE ROOT DIR!", dir.DirId));
                path = dir.Name;
            }
            else
            {
#if DEB
                if (dir.ParentDirId == dir.DirId)
                {
                    DebugUtil.Log(string.Format("THE DIR {0} HAS ITSELF AS PARENT!", dir.DirId), Color.red, DebugUtil.DebugCondition.Always,
                                  DebugUtil.LogType.Info);
                    return(null);
                }
#endif
                var pathStack = SList.Create <string>(5);
                SList.Clear(pathStack);
                while (dir.ParentDirId != -1)
                {
                    SList.Push(pathStack, dir.Name);
                    dir = FindDirById(dir.ParentDirId);
                }

                var builder = new StringBuilder(pathStack.Count * 10);
                while (pathStack.Count > 0)
                {
                    var last = SList.Pop(pathStack);
                    builder.Append(PathUtil.AddSeparatorToStart(last));
                }
                path = builder.ToString();

                // since it's a folder, add slash to the end of it
                path = PathUtil.AddSeparatorToEnd(path);
            }

            return(path);
        }
Exemplo n.º 7
0
        public static void FilleCommandBufferWithFileSystem(FillBufferFileSystemOptions option)
        {
            var commandBuffer = DataHolder.TerminalData.AvailableCommands;
            var data          = DataHolder.DeviceData.CurrentDevice.FileSystem;

            SList.Clear(commandBuffer);

            var currentDir = data.CurrentDir;

            if (option == FillBufferFileSystemOptions.IncludeAll || option == FillBufferFileSystemOptions.IncludeDir)
            {
                if (currentDir.ParentDir != null)
                {
                    SList.Add(commandBuffer, "..");
                }

                SList.Add(commandBuffer, ".");

                var childs = GetAllAvailableChild(currentDir);
                for (int i = 0; i < childs.Count; i++)
                {
                    SList.Add(commandBuffer, childs[i].FullPath);
                }
            }

            if (option == FillBufferFileSystemOptions.IncludeAll || option == FillBufferFileSystemOptions.IncludeFile)
            {
                var files = GetAvailableFilesFromDir(currentDir);
                for (int i = 0; i < files.Count; i++)
                {
                    SList.Add(commandBuffer, files[i].FullPath);
                }
            }

            TerminalUtil.ChangeToAvailableCommandsBuffer();
        }
Exemplo n.º 8
0
        /// <summary>
        /// Sets value referenced by path.
        /// </summary>
        /// <param name="target">The relative object for which to set the value.</param>
        /// <param name="value">The value to set on an object along the expression path.</param>
        /// <param name="parameters">Optional parameters for substitution; if a parameter value is null is will be populated with the created instance.</param>
        public void SetValue(object target, object value, Dictionary <string, object> parameters)
        {
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }

            if (this.m_type == null)
            {
                return;
            }

            if (this.m_property == null)
            {
                return;
            }

            if (!this.m_type.IsInstanceOfType(target))
            {
                throw new ArgumentException("target is not an instance of the expected type.", "target", null);
            }

            try
            {
                object thisvalue = this.m_property.GetValue(target, null);

                if (this.m_property.PropertyType.IsGenericType &&
                    typeof(IEnumerable).IsAssignableFrom(this.m_property.PropertyType) &&
                    IsEntityType(this.m_property.PropertyType.GetGenericArguments()[0]))
                {
                    IEnumerable list    = (IEnumerable)thisvalue;
                    object      colitem = null;
                    foreach (object eachelem in list)
                    {
                        // derived class may have its own specific property (e.g. IfcSIUnit, IfcConversionBasedUnit)
                        if (this.m_identifier != null)
                        {
                            // find of specific identifier
                            Type         eachtype = eachelem.GetType();
                            PropertyInfo propElem = GetPropertyDefault(eachtype);
                            if (propElem != null)
                            {
                                object eachname = propElem.GetValue(eachelem, null);

                                if (this.m_identifier.StartsWith("@"))
                                {
                                    // find by parameter
                                    if (parameters != null && parameters.TryGetValue(this.m_identifier.Substring(1), out colitem))
                                    {
                                        break;
                                    }
                                }
                                else if (eachname != null && this.m_identifier.Equals(eachname.ToString()))
                                {
                                    // yes -- drill in
                                    colitem = eachelem;
                                    break;
                                }
                            }
                        }
                        else if (this.m_inner != null)
                        {
                            // find first that matches type
                            if (this.m_inner.Type == null || this.m_inner.Type.IsInstanceOfType(eachelem))
                            {
                                colitem = eachelem;
                                break;
                            }
                        }
                        else
                        {
                            // find first
                            colitem = eachelem;
                            break;
                        }
                    }

                    // now tunnel through
                    if (this.m_inner != null)
                    {
                        if (colitem == null && this.m_inner.Type != null)
                        {
                            if (colitem == null)
                            {
                                colitem = Activator.CreateInstance(this.m_inner.Type);

                                // name the object
                                if (this.m_identifier != null)
                                {
                                    if (this.m_identifier.StartsWith("@") && parameters != null)
                                    {
                                        // record parameter
                                        string paramname = this.m_identifier.Substring(1);
                                        parameters[paramname] = colitem;
                                    }
                                    else
                                    {
                                        PropertyInfo propDefault = GetPropertyDefault(this.m_inner.Type);
                                        if (propDefault != null)
                                        {
                                            propDefault.SetValue(colitem, value);
                                        }
                                    }
                                }
                            }
                            else if (this.m_property.PropertyType.IsClass &&
                                     this.m_property.PropertyType.IsGenericType &&
                                     (this.m_property.PropertyType.GetGenericTypeDefinition() == typeof(ISet <>) || this.m_property.PropertyType.GetGenericTypeDefinition() == typeof(IList <>)))
                            {
                                CollectionAdd(list, colitem);
                            }
                        }

                        if (colitem != null)
                        {
                            this.m_inner.SetValue(colitem, value, parameters);
                        }
                    }
                    else
                    {
                        // reference to an existing object
                        if (list.GetType().GetGenericArguments()[0].IsInstanceOfType(value))
                        {
                            if (!CollectionContains(list, value))
                            {
                                CollectionAdd(list, value);
                            }
                        }
                    }
                }
                else if (this.m_inner != null)
                {
                    // must allocate
                    if (thisvalue == null && this.m_inner.Type != null)
                    {
                        Type convtype = this.m_inner.Type;
                        if (convtype.IsValueType)
                        {
                            // convert type if type converter is defined
                            if (convtype.IsDefined(typeof(TypeConverterAttribute), true))
                            {
                                TypeConverterAttribute attr = (TypeConverterAttribute)convtype.GetCustomAttributes(typeof(TypeConverterAttribute), true)[0];
                                Type typeconv = Type.GetType(attr.ConverterTypeName);
                                if (typeconv != null)
                                {
                                    TypeConverter converter = (TypeConverter)Activator.CreateInstance(typeconv);
                                    value = converter.ConvertFrom(value);
                                    this.Property.SetValue(target, value);
                                }
                            }
                        }
                        else
                        {
                            if (thisvalue == null)
                            {
                                // get type from inner token
                                thisvalue = Activator.CreateInstance(this.m_inner.Type);
                            }
                            this.Property.SetValue(target, thisvalue);
                        }
                    }

                    if (IsEntity(thisvalue))
                    {
                        this.m_inner.SetValue(thisvalue, value, parameters);
                    }
                }
                else
                {
                    // get type converter, set value
                    Type convtype = this.Property.PropertyType;
                    if (convtype.IsInstanceOfType(value))
                    {
                        // set field instead to avoid perf hit
                        this.Property.SetValue(target, value);
                    }
#if false
                    else if (convtype == typeof(IList <IfcLabel>))
                    {
                        // address lines
                        if (value != null)
                        {
                            SList <IfcLabel> listlabel = (SList <IfcLabel>) this.Field.GetValue(target);
                            listlabel.Clear();
                            string   strval = value.ToString();
                            string[] parts  = strval.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                            foreach (string part in parts)
                            {
                                listlabel.Add(new IfcLabel(part));
                            }
                        }
                    }
#endif
                    else
                    {
                        // value
                        if (convtype.IsGenericType && convtype.GetGenericTypeDefinition() == typeof(Nullable <>))
                        {
                            // special case for Nullable types
                            convtype = convtype.GetGenericArguments()[0];
                        }

                        // convert type if type converter is defined
                        if (convtype.IsDefined(typeof(TypeConverterAttribute), true))
                        {
                            TypeConverterAttribute attr = (TypeConverterAttribute)convtype.GetCustomAttributes(typeof(TypeConverterAttribute), true)[0];
                            Type typeconv = Type.GetType(attr.ConverterTypeName);
                            if (typeconv != null)
                            {
                                TypeConverter converter = (TypeConverter)Activator.CreateInstance(typeconv);
                                value = converter.ConvertFrom(value);
                                this.Property.SetValue(target, value);
                            }
                        }
                        else
                        {
                            // log warning
                            System.Diagnostics.Debug.WriteLine("CvtValuePath::SetValue() - " + this.ToString() + " - " + convtype.Name + " has no type converter defined.");
                        }
                    }
                }
            }
            catch (Exception e)
            {
                // log it...
                System.Diagnostics.Debug.WriteLine("CvtValuePath::SetValue exception: " + e.ToString());
            }
        }