private void MappingTrackers()
        {
            var role  = RoleMap.RoleInfo.MinValidRole;
            var index = (uint)1;

            while (true)
            {
                while (!RoleMap.RoleInfo.IsValidRole(role) || RoleMap.IsRoleMapped(role) || RoleMap.IsRoleBound(role))
                {
                    if (++role > RoleMap.RoleInfo.MaxValidRole)
                    {
                        return;
                    }
                }

                while (ViveRole.GetDeviceClass(index) != ETrackedDeviceClass.GenericTracker || RoleMap.IsDeviceMapped(index) || RoleMap.IsDeviceConnectedAndBound(index))
                {
                    if (++index >= ViveRole.MAX_DEVICE_COUNT)
                    {
                        return;
                    }
                }

                MappingRole(role++, index++);

                if (role > RoleMap.RoleInfo.MaxValidRole || index >= ViveRole.MAX_DEVICE_COUNT)
                {
                    return;
                }
            }
        }
示例#2
0
        /// <summary>
        /// Get ActorRoles mapped to roles held in RoleFilter Flags
        /// </summary>
        /// <param name="role">RoleFilter</param>
        /// <returns>List of IfcActorRole</returns>
        private List <IfcActorRole> GetActorRoles(RoleFilter role)
        {
            if (RoleMap == null)
            {
                RoleMap = new Dictionary <RoleFilter, IfcActorRole>();
            }

            List <IfcActorRole> actorRoles = new List <IfcActorRole>();

            if (role.HasFlag(RoleFilter.Architectural))
            {
                actorRoles.Add(RoleMap.ContainsKey(RoleFilter.Architectural) ? RoleMap[RoleFilter.Architectural] : MapRole(RoleFilter.Architectural, IfcRole.Architect));
            }
            if (role.HasFlag(RoleFilter.Mechanical))
            {
                actorRoles.Add(RoleMap.ContainsKey(RoleFilter.Mechanical) ? RoleMap[RoleFilter.Mechanical] : MapRole(RoleFilter.Mechanical, IfcRole.MechanicalEngineer));
            }
            if (role.HasFlag(RoleFilter.Electrical))
            {
                actorRoles.Add(RoleMap.ContainsKey(RoleFilter.Electrical) ? RoleMap[RoleFilter.Electrical] : MapRole(RoleFilter.Electrical, IfcRole.ElectricalEngineer));
            }
            if (role.HasFlag(RoleFilter.Plumbing))
            {
                actorRoles.Add(RoleMap.ContainsKey(RoleFilter.Plumbing) ? RoleMap[RoleFilter.Plumbing] : MapRole(RoleFilter.Plumbing, IfcRole.UserDefined));
            }
            if (role.HasFlag(RoleFilter.FireProtection))
            {
                actorRoles.Add(RoleMap.ContainsKey(RoleFilter.FireProtection) ? RoleMap[RoleFilter.FireProtection] : MapRole(RoleFilter.FireProtection, IfcRole.UserDefined));
            }
            if (role.HasFlag(RoleFilter.Unknown))
            {
                actorRoles.Add(RoleMap.ContainsKey(RoleFilter.Unknown) ? RoleMap[RoleFilter.Unknown] : MapRole(RoleFilter.Unknown, IfcRole.UserDefined));
            }
            return(actorRoles);
        }
示例#3
0
        public RoleMap GetProjectRoles()
        {
            return(m_cache.ReadThrough($"rolemap_{m_session.Project.Id}", TimeSpan.FromHours(24), () =>
            {
                var allRoles = new List <RoleMapNode>();

                var roles = m_database.SelectFrom <IUserRole>().Join(ur => ur.Members)
                            .Where(ur => ur.ProjectId == m_session.Project.Id).Execute();

                foreach (var role in roles)
                {
                    var model = new RoleMapNode
                    {
                        Id = role.Id,
                        Name = role.Name,
                        ParentRoleId = role.ParentRoleId
                    };

                    model.MemberUserIds.AddRange(role.Members.Select(m => m.MemberId));

                    allRoles.Add(model);
                }

                var map = new RoleMap();
                map.Import(allRoles);

                return map;
            }));
        }
示例#4
0
        private void MappingOthers()
        {
            // try mapping the rest of the devices
            var role        = HandRole.Controller3;
            var deviceIndex = 0u;

            while (role <= HandRole.Controller12 && deviceIndex < ViveRole.MAX_DEVICE_COUNT)
            {
                while (RoleMap.IsRoleMapped(role) || RoleMap.IsRoleBound(role))
                {
                    if (++role > HandRole.Controller12)
                    {
                        return;
                    }
                }

                while (!IsController(deviceIndex) || RoleMap.IsDeviceMapped(deviceIndex))
                {
                    if (++deviceIndex >= ViveRole.MAX_DEVICE_COUNT)
                    {
                        return;
                    }
                }

                MappingRole(role++, deviceIndex++);
            }
        }
        public override void OnConnectedDeviceChanged(uint deviceIndex, ETrackedDeviceClass deviceClass, string deviceSN, bool connected)
        {
            if (RoleMap.IsDeviceBound(deviceSN))
            {
                return;
            }

            if (connected)
            {
                if (deviceClass != ETrackedDeviceClass.GenericTracker)
                {
                    return;
                }

                // find unmapped role
                var role = RoleMap.RoleInfo.MinValidRole;
                while (!RoleMap.RoleInfo.IsValidRole(role) || RoleMap.IsRoleMapped(role))
                {
                    if (++role > RoleMap.RoleInfo.MaxValidRole)
                    {
                        return;
                    }
                }

                MappingRole(role, deviceIndex);
            }
            else
            {
                UnmappingDevice(deviceIndex);
            }
        }
示例#6
0
        public RoleMap GetRolesVisibleForUser(int userId)
        {
            return(m_cache.ReadThrough($"rolemap_{m_session.Project.Id}_rolesvisiblefor_{userId}", TimeSpan.FromHours(24), () =>
            {
                var allRoles = GetProjectRoles();
                var userRoles = GetRoleIdsOfUser(userId);

                var visibleRoles = new List <RoleMapNode>();

                foreach (var rId in userRoles)
                {
                    var r = allRoles.FindRole(rId);
                    if (r == null)
                    {
                        continue;
                    }

                    visibleRoles.Add(r);
                }

                var submap = new RoleMap();
                submap.Import(visibleRoles);

                return submap;
            }));
        }
示例#7
0
 protected void MappingRoleIfUnbound(TRole role, uint deviceIndex)
 {
     if (!RoleMap.IsRoleBound(role) && !RoleMap.IsDeviceConnectedAndBound(deviceIndex))
     {
         MappingRole(role, deviceIndex);
     }
 }
示例#8
0
 public override void OnConnectedDeviceChanged(uint deviceIndex, VRModuleDeviceClass deviceClass, string deviceSN, bool connected)
 {
     if (!RoleMap.IsDeviceBound(deviceSN) && deviceClass != VRModuleDeviceClass.TrackedHand)
     {
         return;
     }
     Refresh();
 }
        public override void OnConnectedDeviceChanged(uint deviceIndex, VRModuleDeviceClass deviceClass, string deviceSN, bool connected)
        {
            if (!RoleMap.IsDeviceBound(deviceSN) && !IsController(deviceClass) && !IsTracker(deviceClass))
            {
                return;
            }

            Refresh();
        }
示例#10
0
        /// <summary>
        /// Get ActorRoles mapped to roles held in RoleFilter Flags
        /// </summary>
        /// <param name="role">RoleFilter</param>
        /// <returns>List of IfcActorRole</returns>
        private List <IIfcActorRole> GetActorRoles(RoleFilter role)
        {
            if (RoleMap == null)
            {
                RoleMap = new Dictionary <RoleFilter, IIfcActorRole>();
            }
            var actorRoles = new List <IIfcActorRole>();

            using (var tx = Model.BeginTransaction("RoleSettings"))
            {
                if (role.HasFlag(RoleFilter.Architectural))
                {
                    actorRoles.Add(
                        RoleMap.ContainsKey(RoleFilter.Architectural)
                        ? RoleMap[RoleFilter.Architectural]
                        : MapRole(RoleFilter.Architectural, IfcRoleEnum.ARCHITECT));
                }
                if (role.HasFlag(RoleFilter.Mechanical))
                {
                    actorRoles.Add(
                        RoleMap.ContainsKey(RoleFilter.Mechanical)
                        ? RoleMap[RoleFilter.Mechanical]
                        : MapRole(RoleFilter.Mechanical, IfcRoleEnum.MECHANICALENGINEER));
                }
                if (role.HasFlag(RoleFilter.Electrical))
                {
                    actorRoles.Add(
                        RoleMap.ContainsKey(RoleFilter.Electrical)
                        ? RoleMap[RoleFilter.Electrical]
                        : MapRole(RoleFilter.Electrical, IfcRoleEnum.ELECTRICALENGINEER));
                }
                if (role.HasFlag(RoleFilter.Plumbing))
                {
                    actorRoles.Add(
                        RoleMap.ContainsKey(RoleFilter.Plumbing)
                        ? RoleMap[RoleFilter.Plumbing]
                        : MapRole(RoleFilter.Plumbing, IfcRoleEnum.USERDEFINED));
                }
                if (role.HasFlag(RoleFilter.FireProtection))
                {
                    actorRoles.Add(
                        RoleMap.ContainsKey(RoleFilter.FireProtection)
                        ? RoleMap[RoleFilter.FireProtection]
                        : MapRole(RoleFilter.FireProtection, IfcRoleEnum.USERDEFINED));
                }
                if (role.HasFlag(RoleFilter.Unknown))
                {
                    actorRoles.Add(
                        RoleMap.ContainsKey(RoleFilter.Unknown)
                        ? RoleMap[RoleFilter.Unknown]
                        : MapRole(RoleFilter.Unknown, IfcRoleEnum.USERDEFINED));
                }
                tx.Commit();
            }

            return(actorRoles);
        }
示例#11
0
        private void MappingOtherControllers()
        {
            // mapping other controllers in order of device index
            var deviceIndex       = 0u;
            var firstFoundTracker = VRModule.INVALID_DEVICE_INDEX;
            var rightIndex        = RoleMap.GetMappedDeviceByRole(HandRole.RightHand);
            var leftIndex         = RoleMap.GetMappedDeviceByRole(HandRole.LeftHand);

            for (var role = RoleInfo.MinValidRole; role <= RoleInfo.MaxValidRole; ++role)
            {
                if (!RoleInfo.IsValidRole(role))
                {
                    continue;
                }
                if (role == HandRole.RightHand || role == HandRole.LeftHand)
                {
                    continue;
                }
                if (RoleMap.IsRoleBound(role))
                {
                    continue;
                }

                // find next valid device
                if (VRModule.IsValidDeviceIndex(deviceIndex))
                {
                    while (!IsController(deviceIndex) || RoleMap.IsDeviceConnectedAndBound(deviceIndex) || deviceIndex == rightIndex || deviceIndex == leftIndex)
                    {
                        if (!VRModule.IsValidDeviceIndex(firstFoundTracker) && IsTracker(deviceIndex))
                        {
                            firstFoundTracker = deviceIndex;
                        }
                        if (!VRModule.IsValidDeviceIndex(++deviceIndex))
                        {
                            break;
                        }
                    }
                }

                if (VRModule.IsValidDeviceIndex(deviceIndex))
                {
                    MappingRole(role, deviceIndex++);
                }
                else
                {
                    UnmappingRole(role);
                }
            }

            // if external camera is not mapped, try mapping first found tracker
            if (!RoleMap.IsRoleMapped(HandRole.ExternalCamera) && VRModule.IsValidDeviceIndex(firstFoundTracker) && !RoleMap.IsDeviceConnectedAndBound(firstFoundTracker))
            {
                MappingRole(HandRole.ExternalCamera, firstFoundTracker);
            }
        }
 private bool NextUnmappedSortedDevice(ref int i)
 {
     while (++i < m_sortedDeviceList.Count)
     {
         if (!RoleMap.IsDeviceMapped(m_sortedDeviceList[i]))
         {
             return(true);
         }
     }
     return(false);
 }
        private bool NextUnmappedRole(ref ControllerRole r)
        {
            const ControllerRole rMax = ControllerRole.Controller15 + 1;

            while (++r < rMax)
            {
                if (!RoleMap.IsRoleValueMapped((int)r))
                {
                    return(true);
                }
            }
            return(false);
        }
示例#14
0
        /// <summary>
        /// 生存している人狼のリストを取得する
        /// (自分が人狼のとき、及びゲーム終了後のみ結果を取得できる)
        /// </summary>
        /// <returns></returns>
        public List <Agent> GetAliveWerewolf()
        {
            List <Agent> ret = new List <Agent>();

            foreach (Agent agent in latestGameInfo.AliveAgentList)
            {
                if (RoleMap.ContainsKey(agent) && RoleMap[agent] == Role.WEREWOLF)
                {
                    ret.Add(agent);
                }
            }

            return(ret);
        }
        public override void OnConnectedDeviceChanged(uint deviceIndex, VRModuleDeviceClass deviceClass, string deviceSN, bool connected)
        {
            if (connected)
            {
                if (RoleMap.IsDeviceBound(deviceSN))
                {
                    return;
                }
            }
            else
            {
                return;
            }

            Refresh();
        }
示例#16
0
        private string GetReferenceRoleValue(RoleMap referenceRole)
        {
            string value = referenceRole.dataType;

            if (string.IsNullOrEmpty(value))
            {
                value = referenceRole.value; // for backward compatibility
            }

            if (string.IsNullOrEmpty(value) || (!value.StartsWith(RDL_PREFIX) && !value.StartsWith(RDL_NS.NamespaceName)))
            {
                throw new Exception("Role map [" + referenceRole.name + "] has invalid class reference.");
            }

            return(value.Replace(RDL_PREFIX, RDL_NS.NamespaceName));
        }
        public override void OnBindingChanged(TrackerRole role, string deviceSN, bool bound)
        {
            if (bound)
            {
                // it's possible that some device will be pushed out when binding
                MappingTrackers();
            }
            else
            {
                if (RoleMap.IsRoleMapped(role))
                {
                    UnmappingRole(role);

                    MappingTrackers();
                }
            }
        }
示例#18
0
        public override void OnBindingChanged(HandRole role, string deviceSN, bool bound)
        {
            if (!bound)
            {
                if (RoleMap.IsRoleMapped(role) && !IsController(RoleMap.GetMappedDeviceByRole(role)))
                {
                    UnmappingRole(role);
                }
            }

            if (handsAreMappedOrBound)
            {
                MappingOthers();
            }
            else
            {
                MappingHandsAndOthers();
            }
        }
示例#19
0
        public override void OnConnectedDeviceChanged(uint deviceIndex, ETrackedDeviceClass deviceClass, string deviceSN, bool connected)
        {
            if (RoleMap.IsDeviceBound(deviceSN) || deviceClass != ETrackedDeviceClass.Controller)
            {
                return;
            }

            if (!connected)
            {
                UnmappingDevice(deviceIndex);
            }

            if (handsAreMappedOrBound)
            {
                MappingOthers();
            }
            else
            {
                MappingHandsAndOthers();
            }
        }
示例#20
0
        private XElement CreatePropertyElement(RoleMap propertyRole, string propertyValue)
        {
            XElement propertyElement = new XElement(TPL_NS + propertyRole.id.Replace(TPL_PREFIX, String.Empty));

            if (String.IsNullOrEmpty(propertyRole.valueListName))
            {
                if (String.IsNullOrEmpty(propertyValue))
                {
                    propertyElement.Add(new XAttribute(RDF_RESOURCE, QUALIFIED_RDF_NIL));
                }
                else
                {
                    propertyElement.Add(new XAttribute(RDF_DATATYPE,
                                                       propertyRole.dataType.Replace(XSD_PREFIX, XSD_NS.NamespaceName)));

                    if (propertyRole.dataType.Contains("dateTime"))
                    {
                        propertyValue = Utility.ToXsdDateTime(propertyValue);
                    }

                    propertyElement.Add(new XText(propertyValue));
                }
            }
            else // resolve value list to uri
            {
                propertyValue = _mapping.ResolveValueList(propertyRole.valueListName, propertyValue);

                if (String.IsNullOrEmpty(propertyValue))
                {
                    return(null);
                }

                propertyValue = propertyValue.Replace(RDL_PREFIX, RDL_NS.NamespaceName);
                propertyElement.Add(new XAttribute(RDF_RESOURCE, propertyValue));
            }

            return(propertyElement);
        }
示例#21
0
 /// <summary>
 /// Convert RoleFilter to IfcActorRole, need to be within a transaction
 /// </summary>
 /// <param name="role">RoleFilter</param>
 /// <param name="ifcRole">IfcRole</param>
 /// <returns></returns>
 private IIfcActorRole MapRole(RoleFilter role, IfcRoleEnum ifcRole)
 {
     if (_fedModel.CurrentTransaction != null)
     {
         var actorRole = _fedModel.Instances.New <IfcActorRole>();
         if (ifcRole == IfcRoleEnum.USERDEFINED)
         {
             actorRole.Role            = IfcRoleEnum.USERDEFINED;
             actorRole.UserDefinedRole = role.ToString();
         }
         else
         {
             actorRole.Role = ifcRole;
         }
         actorRole.Description = role.ToString();
         RoleMap.Add(role, actorRole);
         return(actorRole);
     }
     else
     {
         throw new InvalidOperationException("MapRole: No transaction currently in model");
     }
 }
示例#22
0
 /// <summary>
 /// Convert RoleFilter to IfcActorRole, need to be within a transaction
 /// </summary>
 /// <param name="role">RoleFilter</param>
 /// <param name="ifcRole">IfcRole</param>
 /// <returns></returns>
 private IfcActorRole MapRole(RoleFilter role, IfcRole ifcRole)
 {
     if (_fedModel.IsTransacting)
     {
         IfcActorRole actorRole = _fedModel.Instances.New <IfcActorRole>();
         if (ifcRole == IfcRole.UserDefined)
         {
             actorRole.Role            = IfcRole.UserDefined;
             actorRole.UserDefinedRole = role.ToString();
         }
         else
         {
             actorRole.Role = ifcRole;
         }
         actorRole.Description = role.ToString();
         RoleMap.Add(role, actorRole);
         return(actorRole);
     }
     else
     {
         throw new InvalidOperationException("MapRole: No transaction currently in model");
     }
 }
示例#23
0
        private XElement CreatePropertyElement(RoleMap propertyRole, string propertyValue)
        {
            XElement propertyElement = new XElement(_appNamespace + propertyRole.name);

            propertyElement.Add(new XAttribute(RDL_URI_ATTR, propertyRole.id));

            if (String.IsNullOrEmpty(propertyRole.valueListName))
            {
                if (String.IsNullOrEmpty(propertyValue))
                {
                    propertyElement.Add(new XAttribute(REF_ATTR, RDF_NIL));
                }
                else
                {
                    if (propertyRole.dataType.Contains("dateTime"))
                    {
                        propertyValue = Utility.ToXsdDateTime(propertyValue);
                    }

                    propertyElement.Add(new XText(propertyValue));
                }
            }
            else // resolve value list to uri
            {
                propertyValue = _mapping.ResolveValueList(propertyRole.valueListName, propertyValue);

                if (String.IsNullOrEmpty(propertyValue))
                {
                    return(null);
                }

                propertyValue = propertyValue.Replace(RDL_PREFIX, RDL_NS.NamespaceName);
                propertyElement.Add(new XAttribute(REF_ATTR, propertyValue));
            }

            return(propertyElement);
        }
        private void MappingTrackers()
        {
            var deviceIndex = 0u;

            for (var role = RoleInfo.MinValidRole; role <= RoleInfo.MaxValidRole; ++role)
            {
                if (!RoleInfo.IsValidRole(role))
                {
                    continue;
                }
                if (RoleMap.IsRoleBound(role))
                {
                    continue;
                }

                // find next valid device
                if (VRModule.IsValidDeviceIndex(deviceIndex))
                {
                    while (!IsTracker(deviceIndex) || RoleMap.IsDeviceConnectedAndBound(deviceIndex))
                    {
                        if (!VRModule.IsValidDeviceIndex(++deviceIndex))
                        {
                            break;
                        }
                    }
                }

                if (VRModule.IsValidDeviceIndex(deviceIndex))
                {
                    MappingRole(role, deviceIndex++);
                }
                else
                {
                    UnmappingRole(role);
                }
            }
        }
        public void Refresh()
        {
            // find right/left controller index
            var rightIndex = VRModule.INVALID_DEVICE_INDEX;
            var leftIndex  = VRModule.INVALID_DEVICE_INDEX;

            if (RoleMap.IsRoleValueBound((int)ControllerRole.RightHand))
            {
                rightIndex = RoleMap.GetMappedDeviceByRoleValue((int)ControllerRole.RightHand);
            }
            else
            {
                var index = VRModule.GetRightControllerDeviceIndex();
                if (VRModule.GetDeviceState(index).deviceClass == VRModuleDeviceClass.Controller)
                {
                    rightIndex = index;
                }
            }
            if (RoleMap.IsRoleValueBound((int)ControllerRole.LeftHand))
            {
                leftIndex = RoleMap.GetMappedDeviceByRoleValue((int)ControllerRole.LeftHand);
            }
            else
            {
                var index = VRModule.GetRightControllerDeviceIndex();
                if (VRModule.GetDeviceState(index).deviceClass == VRModuleDeviceClass.Controller)
                {
                    leftIndex = index;
                }
            }
            if (leftIndex == rightIndex)
            {
                leftIndex = VRModule.INVALID_DEVICE_INDEX;
            }

            // find all other unbound controller class devices
            for (uint i = 0u, imax = VRModule.GetDeviceStateCount(); i < imax; ++i)
            {
                if (i == rightIndex)
                {
                    continue;
                }
                if (i == leftIndex)
                {
                    continue;
                }

                var device = VRModule.GetDeviceState(i);
                if (!device.isConnected)
                {
                    continue;
                }
                if (device.deviceClass != VRModuleDeviceClass.Controller)
                {
                    continue;
                }
                if (RoleMap.IsDeviceBound(device.serialNumber))
                {
                    continue;
                }

                m_sortedDeviceList.Add(i);
            }

            // if module didn't hint left/right controllers
            // find left/right most device in m_sortedDeviceList and assigned to leftIndex/rightIndex
            if (m_sortedDeviceList.Count > 0)
            {
                HandRoleHandler.SortDeviceIndicesByDirection(m_sortedDeviceList, VRModule.GetCurrentDeviceState(VRModule.HMD_DEVICE_INDEX).pose);

                if (rightIndex == VRModule.INVALID_DEVICE_INDEX && !RoleMap.IsRoleBound(ControllerRole.RightHand))
                {
                    rightIndex = m_sortedDeviceList[0];
                    m_sortedDeviceList.RemoveAt(0);
                }

                if (m_sortedDeviceList.Count > 0 && leftIndex == VRModule.INVALID_DEVICE_INDEX && !RoleMap.IsRoleBound(ControllerRole.RightHand))
                {
                    leftIndex = m_sortedDeviceList[m_sortedDeviceList.Count - 1];
                    m_sortedDeviceList.RemoveAt(m_sortedDeviceList.Count - 1);
                }
            }

            if (rightIndex != VRModule.INVALID_DEVICE_INDEX)
            {
                MappingRoleIfUnbound(ControllerRole.RightHand, rightIndex);
            }

            if (leftIndex != VRModule.INVALID_DEVICE_INDEX)
            {
                MappingRoleIfUnbound(ControllerRole.LeftHand, leftIndex);
            }

            if (m_sortedDeviceList.Count > 0)
            {
                var otherCtrlIndex = -1;
                var otherRole      = ControllerRole.Controller3 - 1;
                while (NextUnmappedSortedDevice(ref otherCtrlIndex) && NextUnmappedRole(ref otherRole))
                {
                    MappingRole(otherRole, m_sortedDeviceList[otherCtrlIndex]);
                }

                m_sortedDeviceList.Clear();
            }
        }
示例#26
0
        private static void ShowProcessesScreen(FdbSystemStatus status, HistoryMetric current, bool repaint)
        {
            const int BARSZ = 15;

            const int COL0 = 1;
            const int COL1 = COL0 + 18;
            const int COL2 = COL1 + 12;
            const int COL3 = COL2 + 15;
            const int COL4 = COL3 + 11 + BARSZ;
            const int COL5 = COL4 + 8;
            const int COL6 = COL5 + 12 + BARSZ;
            const int COL7 = COL6 + 10 + BARSZ;

            if (repaint)
            {
                Console.Title = "fdbtop - Processes";
                RepaintTopBar();

                Console.ForegroundColor = ConsoleColor.DarkCyan;
                WriteAt(COL0, 5, "Address (port)");
                WriteAt(COL1, 5, "Network in / out (MB/s)");
                WriteAt(COL3, 5, "CPU (%core)");
                WriteAt(COL4, 5, "Memory Free / Total (GB)");
                WriteAt(COL6, 5, "HDD (%busy)");
                WriteAt(COL7, 5, "Roles");

#if DEBUG
                Console.ForegroundColor = ConsoleColor.DarkGray;
                WriteAt(COL0, 6, "0 - - - - - -");
                WriteAt(COL1, 6, "1 - - - - - -");
                WriteAt(COL2, 6, "2 - - - - - -");
                WriteAt(COL3, 6, "3 - - - - - -");
                WriteAt(COL4, 6, "4 - - - - - -");
                WriteAt(COL5, 6, "5 - - - - - -");
                WriteAt(COL6, 6, "6 - - - - - -");
                WriteAt(COL7, 6, "7 - - - - - -");
#endif
            }

            UpdateTopBar(status, current);

            if (status.Cluster.Machines.Count == 0)
            {
                //TODO display error message?
                return;
            }

            var maxVersion = status.Cluster.Processes.Values.Max(p => p.Version);

            int y = 7;
            foreach (var machine in status.Cluster.Machines.Values.OrderBy(x => x.Address, StringComparer.Ordinal))
            {
                var procs = status.Cluster.Processes.Values
                            .Where(p => p.MachineId == machine.Id)
                            .OrderBy(p => p.Address, StringComparer.Ordinal)
                            .ToList();

                var map = new RoleMap();
                foreach (var proc in procs)
                {
                    foreach (var role in proc.Roles)
                    {
                        map.Add(role.Value);
                    }
                }

                Console.ForegroundColor = ConsoleColor.DarkGray;
                WriteAt(1, y,
                        "{0,15} | {0,8} in {0,8} out | {0,6}% {0,15} | {0,5} / {0,5} GB {0,15} | {0,22} | {0,11} |",
                        ""
                        );

                Console.ForegroundColor = ConsoleColor.White;
                //"{0,-15} | net {2,8:N3} in {3,8:N3} out | cpu {4,5:N1}% | mem {5,5:N1} / {7,5:N1} GB {8,-20} | hdd {9,5:N1}% {10,-20}",
                WriteAt(COL0, y, machine.Address);
                WriteAt(COL1, y, "{0,8:N3}", MegaBytes(machine.Network.MegabitsReceived.Hz * 125000));
                WriteAt(COL2, y, "{0,8:N3}", MegaBytes(machine.Network.MegabitsSent.Hz * 125000));
                WriteAt(COL3, y, "{0,6:N1}", machine.Cpu.LogicalCoreUtilization * 100);
                WriteAt(COL4, y, "{0,5:N1}", GigaBytes(machine.Memory.CommittedBytes));
                WriteAt(COL5, y, "{0,5:N1}", GigaBytes(machine.Memory.TotalBytes));
                //WriteAt(COL6, y, "{0,5:N1}", totalDiskBusy * 100);
                WriteAt(COL7, y, "{0,11}", map);

                Console.ForegroundColor = machine.Cpu.LogicalCoreUtilization >= 0.9 ? ConsoleColor.Red : ConsoleColor.Green;
                WriteAt(COL3 + 8, y, "{0,-15}", new string('|', Bar(machine.Cpu.LogicalCoreUtilization, 1, BARSZ)));                 // 1 = all the (logical) cores

                Console.ForegroundColor = machine.Memory.CommittedBytes >= 0.95 * machine.Memory.TotalBytes ? ConsoleColor.Red : ConsoleColor.Green;
                WriteAt(COL5 + 9, y, "{0,-15}", new string('|', Bar(machine.Memory.CommittedBytes, machine.Memory.TotalBytes, BARSZ)));

                //Console.ForegroundColor = totalDiskBusy >= 0.95 ? ConsoleColor.Red : ConsoleColor.Green;
                //WriteAt(COL6 + 7, y, "{0,-15}", new string('|', Bar(totalDiskBusy, 1, BARSZ)));

                ++y;

                //TODO: use a set to map procs ot machines? Where(..) will be slow if there are a lot of machines x processes
                foreach (var proc in procs)
                {
                    int    p    = proc.Address.IndexOf(':');
                    string port = p >= 0 ? proc.Address.Substring(p + 1) : proc.Address;

                    map = new RoleMap();
                    foreach (var role in proc.Roles)
                    {
                        map.Add(role.Value);
                    }
                    Console.ForegroundColor = ConsoleColor.DarkGray;
                    WriteAt(1, y,
                            "{0,7} | {0,5} | {0,8} in {0,8} out | {0,6}% {0,15} | {0,5} / {0,5} GB {0,15} | {0,5}% {0,15} | {0,11} |",
                            ""
                            );

                    Console.ForegroundColor = proc.Version != maxVersion ? ConsoleColor.DarkCyan : ConsoleColor.Gray;
                    WriteAt(1 + 10, y, "{0,5}", proc.Version);

                    Console.ForegroundColor = proc.Excluded ? ConsoleColor.DarkRed : ConsoleColor.Gray;
                    WriteAt(COL0, y, "{0,7}", port);
                    Console.ForegroundColor = ConsoleColor.Gray;
                    WriteAt(COL1, y, "{0,8:N3}", MegaBytes(proc.Network.MegabitsReceived.Hz * 125000));
                    WriteAt(COL2, y, "{0,8:N3}", MegaBytes(proc.Network.MegabitsSent.Hz * 125000));
                    WriteAt(COL3, y, "{0,6:N1}", proc.Cpu.UsageCores * 100);
                    WriteAt(COL4, y, "{0,5:N1}", GigaBytes(proc.Memory.UsedBytes));
                    WriteAt(COL5, y, "{0,5:N1}", GigaBytes(proc.Memory.AvailableBytes));
                    WriteAt(COL6, y, "{0,5:N1}", Math.Min(proc.Disk.Busy * 100, 100));                     // 1 == 1 core, but a process can go a little bit higher
                    WriteAt(COL7, y, "{0,11}", map);

                    Console.ForegroundColor = proc.Cpu.UsageCores >= 0.95 ? ConsoleColor.DarkRed : ConsoleColor.DarkGreen;
                    WriteAt(COL3 + 8, y, "{0,-15}", new string('|', Bar(proc.Cpu.UsageCores, 1, BARSZ)));

                    Console.ForegroundColor = proc.Memory.UsedBytes >= 0.95 * proc.Memory.AvailableBytes ? ConsoleColor.DarkRed : ConsoleColor.DarkGreen;
                    WriteAt(COL5 + 9, y, "{0,-15}", new string('|', Bar(proc.Memory.UsedBytes, proc.Memory.AvailableBytes, BARSZ)));

                    Console.ForegroundColor = proc.Disk.Busy >= 0.95 ? ConsoleColor.DarkRed : ConsoleColor.DarkGreen;
                    WriteAt(COL6 + 7, y, "{0,-15}", new string('|', Bar(proc.Disk.Busy, 1, BARSZ)));

                    ++y;
                }
                ++y;
            }
        }
示例#27
0
        public string ProjectProperty(string[] propertyNameParts, ref Values values)
        {
            string dataPropertyName = String.Empty;

            string className    = propertyNameParts[0];
            string templateName = propertyNameParts[1];
            string roleName     = propertyNameParts[2];
            string classPath    = String.Empty;

            if (className.Contains("$"))
            {
                string[] temp = className.Split('$');
                className = temp[0];
                classPath = temp[1];
            }

            ClassTemplateMap classTemplateMap = _graphMap.classTemplateMaps.Find(
                cm => cm.classMap.name.Replace(" ", "").ToLower() == className.Replace(" ", "").ToLower());

            if (classTemplateMap == null)
            {
                throw new Exception("Classmap [" + className + "] not found.");
            }

            List <TemplateMap> templateMaps = classTemplateMap.templateMaps;
            TemplateMap        templateMap  = templateMaps.Find(tm => tm.name.ToLower() == templateName.ToLower());
            RoleMap            roleMap      = templateMap.roleMaps.Find(rm => rm.name.ToLower() == roleName.ToLower());

            switch (roleMap.type)
            {
            case RoleType.DataProperty:
                dataPropertyName = roleMap.propertyName;
                _valueListName   = null;
                break;

            case RoleType.ObjectProperty:
                dataPropertyName = roleMap.propertyName;
                _valueListName   = roleMap.valueListName;
                break;

            case RoleType.Property:
                //if last part...
                dataPropertyName = roleMap.propertyName;

                if (String.IsNullOrEmpty(roleMap.valueListName))
                {
                    _valueListName = null;
                }
                else
                {
                    _valueListName = roleMap.valueListName;

                    for (int i = 0; i < values.Count; i++)
                    {
                        string       value        = values[i];
                        ValueListMap valueListMap = _mapping.valueListMaps.Find(x => x.name.ToLower() == roleMap.valueListName.ToLower());

                        if (valueListMap != null && valueListMap.valueMaps != null)
                        {
                            /// ValueMap valueMap = valueListMap.valueMaps.Find(x => x.uri == value);

                            ValueMap valueMap = valueListMap.valueMaps.Find(x => x.label == value);

                            if (valueMap != null)
                            {
                                value = valueMap.internalValue;
                            }
                            else
                            {
                                value = valueListMap.valueMaps[0].internalValue;
                            }
                        }

                        values[i] = value;
                    }
                }
                break;

            case RoleType.FixedValue:
            case RoleType.Possessor:
            case RoleType.Reference:
                throw new Exception("Role " + roleName + " can not be projected to property.");
            }

            return(dataPropertyName);
        }
示例#28
0
        private void ProcessInboundTemplates(int dataObjectIndex, List <string> classInstances, List <TemplateMap> templateMaps)
        {
            foreach (TemplateMap templateMap in templateMaps)
            {
                string         possessorRoleId = String.Empty;
                RoleMap        referenceRole   = null;
                List <RoleMap> propertyRoles   = new List <RoleMap>();
                List <RoleMap> classRoles      = new List <RoleMap>();

                // find property roles
                foreach (RoleMap roleMap in templateMap.roleMaps)
                {
                    switch (roleMap.type)
                    {
                    case RoleType.Possessor:
                        possessorRoleId = roleMap.id;
                        break;

                    case RoleType.Reference:
                        if (roleMap.classMap != null)
                        {
                            classRoles.Add(roleMap);
                        }
                        else
                        {
                            referenceRole = roleMap;
                        }
                        break;

                    case RoleType.Property:
                    case RoleType.DataProperty:
                    case RoleType.ObjectProperty:
                        propertyRoles.Add(roleMap);
                        break;
                    }
                }

                string referenceVariable  = String.Empty;
                string referenceRoleId    = String.Empty;
                string referenceRoleValue = String.Empty;
                string referenceEndStmt   = String.Empty;

                if (referenceRole != null)
                {
                    referenceVariable  = BLANK_NODE;
                    referenceRoleId    = referenceRole.id;
                    referenceRoleValue = referenceRole.value;
                    referenceEndStmt   = END_STATEMENT;
                }

                for (int classInstanceIndex = 0; classInstanceIndex < classInstances.Count; classInstanceIndex++)
                {
                    if (classRoles.Count > 0)
                    {
                        foreach (RoleMap classRole in classRoles)
                        {
                            string query = String.Format(SUBCLASS_INSTANCE_QUERY_TEMPLATE, possessorRoleId,
                                                         classInstances[classInstanceIndex], templateMap.id, referenceVariable, referenceRoleId,
                                                         referenceRoleValue, referenceEndStmt, classRole.id);

                            object results = _memoryStore.ExecuteQuery(query);

                            if (results is SparqlResultSet)
                            {
                                SparqlResultSet resultSet         = (SparqlResultSet)results;
                                List <string>   subclassInstances = new List <string>();

                                foreach (SparqlResult result in resultSet)
                                {
                                    string subclassInstance = result.Value("class").ToString();
                                    subclassInstances.Add(subclassInstance);
                                }

                                ProcessInboundClass(dataObjectIndex, classRole.classMap, subclassInstances);
                            }
                        }
                    }
                    else if (propertyRoles.Count > 0) // query for property values
                    {
                        foreach (RoleMap propertyRole in propertyRoles)
                        {
                            List <string> values       = new List <string>();
                            string[]      propertyPath = propertyRole.propertyName.Split('.');
                            string        property     = propertyPath[propertyPath.Length - 1];

                            string query = String.Format(LITERAL_QUERY_TEMPLATE, possessorRoleId, classInstances[classInstanceIndex],
                                                         templateMap.id, referenceVariable, referenceRoleId, referenceRoleValue, referenceEndStmt,
                                                         propertyRole.id);

                            object results = _memoryStore.ExecuteQuery(query);

                            if (results is SparqlResultSet)
                            {
                                SparqlResultSet resultSet = (SparqlResultSet)results;

                                foreach (SparqlResult result in resultSet)
                                {
                                    string value = Regex.Replace(result.ToString(), @".*= ", String.Empty);

                                    if (value == QUALIFIED_RDF_NIL)
                                    {
                                        value = String.Empty;
                                    }
                                    else if (value.Contains("^^"))
                                    {
                                        value = value.Substring(0, value.IndexOf("^^"));
                                    }
                                    else if (!String.IsNullOrEmpty(propertyRole.valueListName))
                                    {
                                        ValueListMap valueListMap = _mapping.valueListMaps.Find(x => x.name.ToLower() == propertyRole.valueListName.ToLower());

                                        if (valueListMap != null && valueListMap.valueMaps != null)
                                        {
                                            ValueMap valueMap = valueListMap.valueMaps.Find(x => x.uri == value);

                                            if (valueMap != null)
                                            {
                                                value = valueMap.internalValue;
                                            }
                                            else
                                            {
                                                value = valueListMap.valueMaps[0].internalValue;
                                            }
                                        }
                                    }

                                    if (propertyPath.Length > 2) // related property
                                    {
                                        values.Add(value);
                                    }
                                    else // direct property
                                    {
                                        _dataRecords[dataObjectIndex][property] = value;
                                    }
                                }

                                if (propertyPath.Length > 2 && values.Count > 0)
                                {
                                    SetRelatedRecords(dataObjectIndex, classInstanceIndex, propertyRole.propertyName, values);
                                }
                            }
                        }
                    }
                }
            }
        }
示例#29
0
        private void MappingLeftRightHands()
        {
            // assign left/right controllers according to the hint
            var rightIndex = VRModule.GetRightControllerDeviceIndex();
            var leftIndex  = VRModule.GetLeftControllerDeviceIndex();

            if (VRModule.GetCurrentDeviceState(rightIndex).isConnected)
            {
                MappingRoleIfUnbound(HandRole.RightHand, rightIndex);
                rightIndex = RoleMap.GetMappedDeviceByRole(HandRole.RightHand);
            }
            else if (RoleMap.IsRoleBound(HandRole.RightHand))
            {
                rightIndex = RoleMap.GetMappedDeviceByRole(HandRole.RightHand);
            }
            else
            {
                rightIndex = VRModule.INVALID_DEVICE_INDEX;
            }

            if (VRModule.GetCurrentDeviceState(leftIndex).isConnected&& leftIndex != rightIndex)
            {
                MappingRoleIfUnbound(HandRole.LeftHand, leftIndex);
                leftIndex = RoleMap.GetMappedDeviceByRole(HandRole.LeftHand);
            }
            else if (RoleMap.IsRoleBound(HandRole.LeftHand))
            {
                leftIndex = RoleMap.GetMappedDeviceByRole(HandRole.LeftHand);
            }
            else
            {
                leftIndex = VRModule.INVALID_DEVICE_INDEX;
            }

            // if not both left/right controllers are assigned, find and assign them with left/right most controller
            if (!VRModule.IsValidDeviceIndex(rightIndex) || !VRModule.IsValidDeviceIndex(leftIndex))
            {
                // find right to left sorted controllers
                // FIXME: GetSortedTrackedDeviceIndicesOfClass doesn't return correct devices count right after device connected
#if __VIU_STEAMVR
                if (VRModule.activeModule == SupportedVRModule.SteamVR)
                {
                    var count  = 0;
                    var system = Valve.VR.OpenVR.System;
                    if (system != null)
                    {
                        count = (int)system.GetSortedTrackedDeviceIndicesOfClass(Valve.VR.ETrackedDeviceClass.Controller, m_sortedDevices, Valve.VR.OpenVR.k_unTrackedDeviceIndex_Hmd);
                    }

                    foreach (var deviceIndex in m_sortedDevices)
                    {
                        if (m_sortedDeviceList.Count >= count)
                        {
                            break;
                        }
                        if (IsController(deviceIndex) && deviceIndex != rightIndex && deviceIndex != leftIndex && !RoleMap.IsDeviceConnectedAndBound(deviceIndex))
                        {
                            m_sortedDeviceList.Add(deviceIndex);
                        }
                    }
                }
                else
#endif
                {
                    for (uint deviceIndex = 1u, imax = VRModule.GetDeviceStateCount(); deviceIndex < imax; ++deviceIndex)
                    {
                        if (IsController(deviceIndex) && deviceIndex != rightIndex && deviceIndex != leftIndex && !RoleMap.IsDeviceConnectedAndBound(deviceIndex))
                        {
                            m_sortedDeviceList.Add(deviceIndex);
                        }
                    }

                    if (m_sortedDeviceList.Count > 1)
                    {
                        SortDeviceIndicesByDirection(m_sortedDeviceList, VRModule.GetCurrentDeviceState(VRModule.HMD_DEVICE_INDEX).pose);
                    }
                }

                if (m_sortedDeviceList.Count > 0 && !VRModule.IsValidDeviceIndex(rightIndex))
                {
                    rightIndex = m_sortedDeviceList[0];
                    m_sortedDeviceList.RemoveAt(0);
                    // mapping right most controller
                    MappingRole(HandRole.RightHand, rightIndex);
                }

                if (m_sortedDeviceList.Count > 0 && !VRModule.IsValidDeviceIndex(leftIndex))
                {
                    leftIndex = m_sortedDeviceList[m_sortedDeviceList.Count - 1];
                    // mapping left most controller
                    MappingRole(HandRole.LeftHand, leftIndex);
                }

                m_sortedDeviceList.Clear();
            }

            if (!VRModule.IsValidDeviceIndex(rightIndex))
            {
                UnmappingRole(HandRole.RightHand);
            }
            if (!VRModule.IsValidDeviceIndex(leftIndex))
            {
                UnmappingRole(HandRole.LeftHand);
            }
        }
		private static void ShowProcessesScreen(FdbSystemStatus status, HistoryMetric current, bool repaint)
		{
			const int BARSZ = 15;

			const int COL0 = 1;
			const int COL1 = COL0 + 18;
			const int COL2 = COL1 + 12;
			const int COL3 = COL2 + 15;
			const int COL4 = COL3 + 11 + BARSZ;
			const int COL5 = COL4 + 8;
			const int COL6 = COL5 + 12 + BARSZ;
			const int COL7 = COL6 + 10 + BARSZ;

			if (repaint)
			{
				Console.Title = "fdbtop - Processes";
				RepaintTopBar();

				Console.ForegroundColor = ConsoleColor.DarkCyan;
				WriteAt(COL0, 5, "Address (port)");
				WriteAt(COL1, 5, "Network in / out (MB/s)");
				WriteAt(COL3, 5, "CPU (%core)");
				WriteAt(COL4, 5, "Memory Free / Total (GB)");
				WriteAt(COL6, 5, "HDD (%busy)");
				WriteAt(COL7, 5, "Roles");

#if DEBUG
				Console.ForegroundColor = ConsoleColor.DarkGray;
				WriteAt(COL0, 6, "0 - - - - - -");
				WriteAt(COL1, 6, "1 - - - - - -");
				WriteAt(COL2, 6, "2 - - - - - -");
				WriteAt(COL3, 6, "3 - - - - - -");
				WriteAt(COL4, 6, "4 - - - - - -");
				WriteAt(COL5, 6, "5 - - - - - -");
				WriteAt(COL6, 6, "6 - - - - - -");
				WriteAt(COL7, 6, "7 - - - - - -");
#endif
			}

			UpdateTopBar(status, current);

			if (status.Cluster.Machines.Count == 0)
			{
				//TODO display error message?
				return;
			}

			var maxVersion = status.Cluster.Processes.Values.Max(p => p.Version);

			int y = 7;
			foreach(var machine in status.Cluster.Machines.Values.OrderBy(x => x.Address, StringComparer.Ordinal))
			{
				var procs = status.Cluster.Processes.Values
					.Where(p => p.MachineId == machine.Id)
					.OrderBy(p => p.Address, StringComparer.Ordinal)
					.ToList();

				var map = new RoleMap();
				foreach(var proc in procs)
				{
					foreach(var role in proc.Roles)
					{
						map.Add(role.Value);
					}
				}

				Console.ForegroundColor = ConsoleColor.DarkGray;
				WriteAt(1, y,
					"{0,15} | {0,8} in {0,8} out | {0,6}% {0,15} | {0,5} / {0,5} GB {0,15} | {0,22} | {0,11} |",
					""
				);

				Console.ForegroundColor = ConsoleColor.White;
				//"{0,-15} | net {2,8:N3} in {3,8:N3} out | cpu {4,5:N1}% | mem {5,5:N1} / {7,5:N1} GB {8,-20} | hdd {9,5:N1}% {10,-20}",
				WriteAt(COL0, y, machine.Address);
				WriteAt(COL1, y, "{0,8:N3}", MegaBytes(machine.Network.MegabitsReceived.Hz * 125000));
				WriteAt(COL2, y, "{0,8:N3}", MegaBytes(machine.Network.MegabitsSent.Hz * 125000));
				WriteAt(COL3, y, "{0,6:N1}", machine.Cpu.LogicalCoreUtilization * 100);
				WriteAt(COL4, y, "{0,5:N1}", GigaBytes(machine.Memory.CommittedBytes));
				WriteAt(COL5, y, "{0,5:N1}", GigaBytes(machine.Memory.TotalBytes));
				//WriteAt(COL6, y, "{0,5:N1}", totalDiskBusy * 100);
				WriteAt(COL7, y, "{0,11}", map);

				Console.ForegroundColor = machine.Cpu.LogicalCoreUtilization >= 0.9 ? ConsoleColor.Red : ConsoleColor.Green;
				WriteAt(COL3 + 8, y, "{0,-15}", new string('|', Bar(machine.Cpu.LogicalCoreUtilization, 1, BARSZ))); // 1 = all the (logical) cores

				Console.ForegroundColor = machine.Memory.CommittedBytes >= 0.95 * machine.Memory.TotalBytes ? ConsoleColor.Red : ConsoleColor.Green;
				WriteAt(COL5 + 9, y, "{0,-15}", new string('|', Bar(machine.Memory.CommittedBytes, machine.Memory.TotalBytes, BARSZ)));

				//Console.ForegroundColor = totalDiskBusy >= 0.95 ? ConsoleColor.Red : ConsoleColor.Green;
				//WriteAt(COL6 + 7, y, "{0,-15}", new string('|', Bar(totalDiskBusy, 1, BARSZ)));

				++y;

				//TODO: use a set to map procs ot machines? Where(..) will be slow if there are a lot of machines x processes
				foreach (var proc in procs)
				{
					int p = proc.Address.IndexOf(':');
					string port = p >= 0 ? proc.Address.Substring(p + 1) : proc.Address;

					map = new RoleMap();
					foreach (var role in proc.Roles)
					{
						map.Add(role.Value);
					}
					Console.ForegroundColor = ConsoleColor.DarkGray;
					WriteAt(1, y,
						"{0,7} | {0,5} | {0,8} in {0,8} out | {0,6}% {0,15} | {0,5} / {0,5} GB {0,15} | {0,5}% {0,15} | {0,11} |",
						""
					);

					Console.ForegroundColor = proc.Version != maxVersion ? ConsoleColor.DarkCyan : ConsoleColor.Gray;
					WriteAt(1 +  10, y, "{0,5}", proc.Version);

					Console.ForegroundColor = proc.Excluded ? ConsoleColor.DarkRed : ConsoleColor.Gray;
					WriteAt(COL0, y, "{0,7}", port);
					Console.ForegroundColor = ConsoleColor.Gray;
					WriteAt(COL1, y, "{0,8:N3}", MegaBytes(proc.Network.MegabitsReceived.Hz * 125000));
					WriteAt(COL2, y, "{0,8:N3}", MegaBytes(proc.Network.MegabitsSent.Hz * 125000));
					WriteAt(COL3, y, "{0,6:N1}", proc.Cpu.UsageCores * 100);
					WriteAt(COL4, y, "{0,5:N1}", GigaBytes(proc.Memory.UsedBytes));
					WriteAt(COL5, y, "{0,5:N1}", GigaBytes(proc.Memory.AvailableBytes));
					WriteAt(COL6, y, "{0,5:N1}", Math.Min(proc.Disk.Busy * 100, 100)); // 1 == 1 core, but a process can go a little bit higher
					WriteAt(COL7, y, "{0,11}", map);

					Console.ForegroundColor = proc.Cpu.UsageCores >= 0.95 ? ConsoleColor.DarkRed : ConsoleColor.DarkGreen;
					WriteAt(COL3 + 8, y, "{0,-15}", new string('|', Bar(proc.Cpu.UsageCores, 1, BARSZ)));

					Console.ForegroundColor = proc.Memory.UsedBytes >= 0.95 * proc.Memory.AvailableBytes ? ConsoleColor.DarkRed : ConsoleColor.DarkGreen;
					WriteAt(COL5 + 9, y, "{0,-15}", new string('|', Bar(proc.Memory.UsedBytes, proc.Memory.AvailableBytes, BARSZ)));

					Console.ForegroundColor = proc.Disk.Busy >= 0.95 ? ConsoleColor.DarkRed : ConsoleColor.DarkGreen;
					WriteAt(COL6 + 7, y, "{0,-15}", new string('|', Bar(proc.Disk.Busy, 1, BARSZ)));

					++y;
				}
				++y;
			}

		}
示例#31
0
        private void CreateTemplateElement(int dataObjectIndex, string startClassName, string startClassIdentifier, string baseUri,
                                           string classIdentifier, int classIdentifierIndex, TemplateMap templateMap, bool classIdentifierHasRelatedProperty)
        {
            string         classInstance       = baseUri + classIdentifier;
            IDataObject    dataObject          = _dataObjects[dataObjectIndex];
            string         templateId          = templateMap.id.Replace(TPL_PREFIX, TPL_NS.NamespaceName);
            List <RoleMap> propertyRoles       = new List <RoleMap>();
            XElement       baseTemplateElement = new XElement(OWL_THING);
            StringBuilder  baseValues          = new StringBuilder(templateMap.id);
            List <RoleMap> classRoles          = new List <RoleMap>();

            baseTemplateElement.Add(new XElement(RDF_TYPE, new XAttribute(RDF_RESOURCE, templateId)));

            foreach (RoleMap roleMap in templateMap.roleMaps)
            {
                string   roleId      = roleMap.id.Substring(roleMap.id.IndexOf(":") + 1);
                XElement roleElement = new XElement(TPL_NS + roleId);

                switch (roleMap.type)
                {
                case RoleType.Possessor:
                    roleElement.Add(new XAttribute(RDF_RESOURCE, classInstance));
                    baseTemplateElement.Add(roleElement);
                    baseValues.Append(classIdentifier);
                    break;

                case RoleType.FixedValue:
                    string dataType = roleMap.dataType.Replace(XSD_PREFIX, XSD_NS.NamespaceName);
                    roleElement.Add(new XAttribute(RDF_DATATYPE, dataType));
                    roleElement.Add(new XText(roleMap.value));
                    baseTemplateElement.Add(roleElement);
                    baseValues.Append(roleMap.value);
                    break;

                case RoleType.Reference:
                    if (roleMap.classMap != null)
                    {
                        classRoles.Add(roleMap);
                    }
                    else
                    {
                        string value = GetReferenceRoleValue(roleMap);
                        roleElement.Add(new XAttribute(RDF_RESOURCE, value));
                        baseTemplateElement.Add(roleElement);
                        baseValues.Append(roleMap.value);
                    }
                    break;

                case RoleType.Property:
                case RoleType.DataProperty:
                case RoleType.ObjectProperty:
                    if (String.IsNullOrEmpty(roleMap.propertyName))
                    {
                        throw new Exception("No data property mapped to role [" + startClassName + "." + templateMap.name + "." + roleMap.name + "]");
                    }
                    propertyRoles.Add(roleMap);
                    break;
                }
            }

            if (propertyRoles.Count > 0)     // property template
            {
                bool isTemplateValid = true; // template is not valid when value list uri is empty
                List <List <XElement> > multiPropertyElements = new List <List <XElement> >();

                // create property elements
                foreach (RoleMap propertyRole in propertyRoles)
                {
                    List <XElement> propertyElements = new List <XElement>();
                    multiPropertyElements.Add(propertyElements);

                    string[] propertyParts = propertyRole.propertyName.Split('.');
                    string   propertyName  = propertyParts[propertyParts.Length - 1];

                    int    lastDotPos = propertyRole.propertyName.LastIndexOf('.');
                    string objectPath = propertyRole.propertyName.Substring(0, lastDotPos);

                    if (propertyParts.Length == 2) // direct property
                    {
                        string   propertyValue   = Convert.ToString(dataObject.GetPropertyValue(propertyName));
                        XElement propertyElement = CreatePropertyElement(propertyRole, propertyValue);

                        if (propertyElement == null)
                        {
                            isTemplateValid = false;
                            break;
                        }

                        propertyElements.Add(propertyElement);
                    }
                    else // related property
                    {
                        string             key            = objectPath + "." + dataObjectIndex;
                        List <IDataObject> relatedObjects = null;

                        if (!_relatedObjectsCache.TryGetValue(key, out relatedObjects))
                        {
                            relatedObjects = GetRelatedObjects(propertyRole.propertyName, dataObject);
                            _relatedObjectsCache.Add(key, relatedObjects);
                        }

                        if (classIdentifierHasRelatedProperty) // reference class identifier has related property
                        {
                            IDataObject relatedObject   = relatedObjects[classIdentifierIndex];
                            string      propertyValue   = Convert.ToString(relatedObject.GetPropertyValue(propertyName));
                            XElement    propertyElement = CreatePropertyElement(propertyRole, propertyValue);

                            if (propertyElement == null)
                            {
                                isTemplateValid = false;
                                break;
                            }

                            propertyElements.Add(propertyElement);
                        }
                        else // related property is property map
                        {
                            foreach (IDataObject relatedObject in relatedObjects)
                            {
                                string   propertyValue   = Convert.ToString(relatedObject.GetPropertyValue(propertyName));
                                XElement propertyElement = CreatePropertyElement(propertyRole, propertyValue);

                                if (propertyElement == null)
                                {
                                    isTemplateValid = false;
                                    break;
                                }

                                propertyElements.Add(propertyElement);
                            }

                            if (!isTemplateValid)
                            {
                                break;
                            }
                        }
                    }
                }

                if (isTemplateValid)
                {
                    // add property elements to template element(s)
                    if (multiPropertyElements.Count > 0 && multiPropertyElements[0].Count > 0)
                    {
                        // enforce dotNetRDF to store/retrieve templates in order as expressed in RDF
                        string hashPrefixFormat = Regex.Replace(multiPropertyElements[0].Count.ToString(), "\\d", "0") + "0";

                        for (int i = 0; i < multiPropertyElements[0].Count; i++)
                        {
                            XElement templateElement = new XElement(baseTemplateElement);
                            _rdfXml.Add(templateElement);

                            StringBuilder templateValue = new StringBuilder(baseValues.ToString());
                            for (int j = 0; j < multiPropertyElements.Count; j++)
                            {
                                XElement propertyElement = multiPropertyElements[j][i];
                                templateElement.Add(propertyElement);

                                if (!String.IsNullOrEmpty(propertyElement.Value))
                                {
                                    templateValue.Append(propertyElement.Value);
                                }
                                else
                                {
                                    templateValue.Append(propertyElement.Attribute(RDF_RESOURCE).Value);
                                }
                            }

                            string hashCode = Utility.MD5Hash(templateValue.ToString());
                            hashCode = i.ToString(hashPrefixFormat) + hashCode.Substring(hashPrefixFormat.Length);
                            templateElement.Add(new XAttribute(RDF_ABOUT, hashCode));
                        }
                    }
                }
            }
            else if (classRoles.Count > 0)    // relationship template with known class role
            {
                bool isTemplateValid = false; // template is valid when there is at least one class referernce identifier that is not null
                Dictionary <RoleMap, List <string> > relatedClassRoles = new Dictionary <RoleMap, List <string> >();

                foreach (RoleMap classRole in classRoles)
                {
                    bool          refClassHasRelatedProperty;
                    List <string> refClassIdentifiers = GetClassIdentifiers(classRole.classMap, dataObjectIndex, out refClassHasRelatedProperty);

                    if (refClassHasRelatedProperty)
                    {
                        relatedClassRoles[classRole] = refClassIdentifiers;
                    }
                    else
                    {
                        string refClassIdentifier = refClassIdentifiers.First();

                        if (!String.IsNullOrEmpty(refClassIdentifier))
                        {
                            isTemplateValid = true;
                            baseValues.Append(refClassIdentifier);

                            string   roleId      = classRole.id.Substring(classRole.id.IndexOf(":") + 1);
                            XElement roleElement = new XElement(TPL_NS + roleId);
                            roleElement.Add(new XAttribute(RDF_RESOURCE, _graphBaseUri +
                                                           Utility.TitleCase(classRole.classMap.name) + "/" + refClassIdentifier));
                            baseTemplateElement.Add(roleElement);
                        }

                        ClassTemplateMap relatedClassTemplateMap = _graphMap.GetClassTemplateMap(classRole.classMap.id, classRole.classMap.index);

                        if (relatedClassTemplateMap != null && relatedClassTemplateMap.classMap != null)
                        {
                            ProcessOutboundClass(dataObjectIndex, startClassName, startClassIdentifier, false, refClassIdentifiers,
                                                 refClassHasRelatedProperty, relatedClassTemplateMap.classMap, relatedClassTemplateMap.templateMaps);
                        }
                    }
                }

                if (relatedClassRoles.Count > 0)
                {
                    string refClassBaseValues = baseValues.ToString();

                    // enforce dotNetRDF to store/retrieve templates in order as expressed in RDF
                    string hashPrefixFormat = Regex.Replace(relatedClassRoles.Count.ToString(), "\\d", "0") + "0";

                    foreach (var pair in relatedClassRoles)
                    {
                        RoleMap       classRole           = pair.Key;
                        List <string> refClassIdentifiers = pair.Value;

                        string roleId = classRole.id.Substring(classRole.id.IndexOf(":") + 1);
                        string baseRelatedClassUri = _graphBaseUri + Utility.TitleCase(classRole.classMap.name) + "/";

                        for (int i = 0; i < refClassIdentifiers.Count; i++)
                        {
                            string refClassIdentifier = refClassIdentifiers[i];

                            if (!String.IsNullOrEmpty(refClassIdentifier))
                            {
                                XElement refBaseTemplateElement = new XElement(baseTemplateElement);

                                string hashCode = Utility.MD5Hash(refClassBaseValues + refClassIdentifier);
                                hashCode = i.ToString(hashPrefixFormat) + hashCode.Substring(hashPrefixFormat.Length);
                                refBaseTemplateElement.Add(new XAttribute(RDF_ABOUT, hashCode));

                                XElement roleElement = new XElement(TPL_NS + roleId);
                                roleElement.Add(new XAttribute(RDF_RESOURCE, baseRelatedClassUri + refClassIdentifier));
                                refBaseTemplateElement.Add(roleElement);
                                _rdfXml.Add(refBaseTemplateElement);
                            }
                        }

                        ClassTemplateMap relatedClassTemplateMap = _graphMap.GetClassTemplateMap(classRole.classMap.id, classRole.classMap.index);

                        if (relatedClassTemplateMap != null && relatedClassTemplateMap.classMap != null)
                        {
                            ProcessOutboundClass(dataObjectIndex, startClassName, startClassIdentifier, false, refClassIdentifiers,
                                                 true, relatedClassTemplateMap.classMap, relatedClassTemplateMap.templateMaps);
                        }
                    }
                }
                else if (isTemplateValid)
                {
                    string hashCode = Utility.MD5Hash(baseValues.ToString());
                    baseTemplateElement.Add(new XAttribute(RDF_ABOUT, hashCode));
                    _rdfXml.Add(baseTemplateElement);
                }
            }
            else // relationship template with no class role (e.g. primary classification template)
            {
                string hashCode = Utility.MD5Hash(baseValues.ToString());
                baseTemplateElement.Add(new XAttribute(RDF_ABOUT, hashCode));
                _rdfXml.Add(baseTemplateElement);
            }
        }