Ejemplo n.º 1
0
        /// <summary>
        /// Reads the value definded by the watch Rule
        /// </summary>
        /// <param name="field">The field.</param>
        /// <returns></returns>
        /// <exception cref="System.InvalidOperationException">The WatchField Query returns more then one collection result. Please check the Where Clause</exception>
        private object ReadValue(WatchField field)
        {
            ManagementObjectSearcher   mosObj;
            ManagementObjectCollection resultCollection;

            //Generate Object Searcher with build WQL query
            mosObj = new ManagementObjectSearcher(BuildQuery(field));

            //Exec Query for result collection
            resultCollection = mosObj.Get();

            //check if only one instance is in collection
            if (resultCollection.Count == 1)
            {
                //exception with this way of getting the first  entry
                //var obj = (resultCollection.GetEnumerator().Current as ManagementObject);

                ManagementObject obj = null;

                //other solution
                foreach (ManagementObject entry in resultCollection)
                {
                    obj = entry;
                }

                return(ExtractValue(obj, activWatchRule.WatchField.WatchProperty));
            }
            else
            {
                //otherwise throw exception
                throw new InvalidOperationException("The WatchField Query returns more then one " +
                                                    "collection result. Please check the Where Clause");
            }
        }
Ejemplo n.º 2
0
        public RemResMessage GetWatchData(RemResMessage message)
        {
            GetWatchData       convertedMessage;
            WatchDataSet       resultSet    = new WatchDataSet();
            IList <IWatchTask> tempTaskList = new List <IWatchTask>();

            if (!(message is GetWatchData))
            {
                throw new InvalidOperationException("The message type for this messagehandler method is invalid.");
            }

            convertedMessage = (message as GetWatchData);

            if (string.IsNullOrEmpty(convertedMessage.Name) && convertedMessage.WatchField == null)
            {
                //return all data
                tempTaskList = lstAktivWatchTasks;
            }

            if (!string.IsNullOrEmpty(convertedMessage.Name))
            {
                //return data for watch rule name
                tempTaskList = lstAktivWatchTasks.Where(t => t.Rule.Name.Equals(convertedMessage.Name)).ToList();
            }

            if (convertedMessage.WatchField != null)
            {
                //return data for all rules with given field
                tempTaskList = lstAktivWatchTasks.Where(t => t.Rule.WatchField.WatchObject.Equals(convertedMessage.WatchField.WatchObject) &&
                                                        t.Rule.WatchField.WatchProperty.Equals(convertedMessage.WatchField.WatchProperty)).ToList();
            }

            // ReSharper disable once LoopCanBeConvertedToQuery
            foreach (var task in tempTaskList)
            {
                WatchField tempField = new WatchField
                {
                    Type             = task.Rule.WatchField.Type,
                    WatchObject      = task.Rule.WatchField.WatchObject,
                    WatchProperty    = task.Rule.WatchField.WatchProperty,
                    WhereClause      = task.Rule.WatchField.WhereClause,
                    WatchFieldValues = task.WatchData.ToList()
                };

                resultSet.Add(tempField);
            }

            return(new GetWatchDataResult()
            {
                WatchDataSet = resultSet
            });
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Builds the query for the given Watch Field.
 /// </summary>
 /// <param name="field">The field.</param>
 /// <returns></returns>
 private ObjectQuery BuildQuery(WatchField field)
 {
     if (string.IsNullOrEmpty(activWatchRule.WatchField.WhereClause))
     {
         return(new ObjectQuery(
                    String.Format("Select {0} from {1}",
                                  field.WatchProperty,
                                  field.WatchObject)));
     }
     else
     {
         return(new ObjectQuery(
                    String.Format("Select {0} from {1} where {2}",
                                  field.WatchProperty,
                                  field.WatchObject,
                                  field.WhereClause)));
     }
 }
Ejemplo n.º 4
0
    public void Init(
        MonoBehaviour watchMonoBehaviour,
        IEnumerable <FieldInfo> watchFields,
        WatchOptionsAttribute.DisplayType displayType
        )
    {
        _watchGameObject = watchMonoBehaviour.gameObject;
        _watchPlayer     = FindObjectOfType <WatchPlayer>();
        _rectTransform   = GetComponent <RectTransform>();
        Header.text      = watchMonoBehaviour.name;

        if (displayType == WatchOptionsAttribute.DisplayType.WorldSpace)
        {
            // TODO: Move this into a separate Prefab, and instantiate the WorldSpace prefab from WatchManager.
            GameObject container = new GameObject();
            _canvas                    = container.AddComponent <Canvas>();
            _canvas.renderMode         = RenderMode.WorldSpace;
            _canvas.transform.position = _watchGameObject.transform.position;

            // TODO: Expose this scaling to the user, to allow them to control how the UI should look when using
            //       WorldSpace display.
            _canvas.transform.localScale = new Vector3(-0.005f, 0.005f, 1);

            _rectTransform.anchorMax = new Vector2(0.5f, 0);
            _rectTransform.anchorMin = new Vector2(0.5f, 0);
            _rectTransform.pivot     = new Vector2(0.5f, 0);

            transform.SetParent(container.transform, false);
        }

        foreach (var watchField in watchFields)
        {
            WatchField watchFieldGameObject = Helpers.InstantiatePrefab <WatchField>("WatchField");
            watchFieldGameObject.transform.SetParent(WatchFieldsContainer.transform, false);

            watchFieldGameObject.Init(watchMonoBehaviour, watchField);
        }
    }