示例#1
0
        private void CreateStateValues()
        {
            string cname  = _code.Name;
            string ename  = "E_" + cname + "_State";
            Type   tState = CreateEnum(ename, _stateLookup.Count);

            _stateType = tState;
            TypeDescriptor tdState = (TypeDescriptor)tState;
            // do not add type - it will be assigned during post-processing
            //_code.Owner.AddChild(tdState, ename);
            Array enumValues = tState.GetEnumValues();

            foreach (StateInfo si in _stateLookup.Values)
            {
                int i = si.StateIndex;
                si.StateValue            = enumValues.GetValue(i);
                si.StateExpr.PlaceHolder = LiteralReference.CreateConstant(si.StateValue);
            }
            ComponentDescriptor owner = (ComponentDescriptor)_code.Owner;
            string fname   = "m_" + cname + "_State";
            var    initVal = Activator.CreateInstance(tState);
            ISignalOrPortDescriptor sdState = owner.CreateSignalInstance(fname, initVal);
            Type tStateSignal = typeof(Signal <>).MakeGenericType(tState);

            _tComponent = _modBuilder.DefineType(owner.Instance.GetType().FullName, TypeAttributes.Public);
            FieldBuilder fbStateSignal = _tComponent.DefineField(fname, tStateSignal, FieldAttributes.Private);

            _stateSignal = new SignalRef(sdState, SignalRef.EReferencedProperty.Instance);
            _nextStateSignal.PlaceHolder = new SignalRef(sdState, SignalRef.EReferencedProperty.Next);
        }
示例#2
0
        /// <summary>
        /// Synchronizes the specified system's details with the configured <c>Snipe.It</c>
        /// system.
        /// </summary>
        private void SyncHostNameDetails(string hostName)
        {
            // Single Device.
            SnipeItApi snipe =
                SnipeApiExtensions.CreateClient(
                    snipeApiUrl,
                    snipeApiToken);

            if (!String.IsNullOrWhiteSpace(hostName))
            {
                Log.Information($"Retrieving asset details for {hostName}");
                try
                {
                    var asset      = AssetDescriptor.Create(hostName);
                    var components = ComponentDescriptor.Create(hostName);
                    try
                    {
                        Log.Information($"Synchronizing asset details for {hostName}");
                        // The current version of the SnipeSharp API has mapping issues causing the response not de serializing.
                        snipe.SyncAssetWithCompoments(asset, components);
                    }
                    catch (Exception ex)
                    {
                        Log.Error($"Failed to sync asset details for {hostName}");
                        Log.Error(ex.ToString());
                    }
                }
                catch (Exception ex)
                {
                    Log.Error($"Failed to retrieve asset details for {hostName}");
                    Log.Error(ex.ToString());
                }
            }
        }
示例#3
0
        /// <summary>
        /// Synchronizes the specified system's details with the configured <c>Snipe.It</c>
        /// system.
        /// </summary>
        private void SyncHostNameDetails(string hostName)
        {
            // Single Device.
            SnipeItApi snipe =
                SnipeApiExtensions.CreateClient(
                    ConfigurationManager.AppSettings["Snipe:ApiAddress"],
                    ConfigurationManager.AppSettings["Snipe:ApiToken"]);

            if (!String.IsNullOrWhiteSpace(hostName))
            {
                Console.WriteLine($"Retrieving asset details for {hostName}");
                try
                {
                    var asset      = AssetDescriptor.Create(hostName);
                    var components = ComponentDescriptor.Create(hostName);
                    try
                    {
                        Console.WriteLine($"Synchronizing asset details for {hostName}");
                        // The current version of the SnipeSharp API has mapping issues causing the response not de serializing.
                        snipe.SyncAssetWithCompoments(asset, components);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine($"Failed to sync asset details for {hostName}");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Failed to retrieve asset details for {hostName}");
                }
            }
        }
示例#4
0
            public void Refine(DesignContext context, IProject targetProject)
            {
                ComponentDescriptor cd  = (ComponentDescriptor)_pd.Owner;
                Component           rtl = cd.Instance;

                // Remove synthesizing process
                cd.RemoveChild(_pd);
                if (_planProp != null)
                {
                    var owner = (ComponentDescriptor)_pd.Owner;
                    _plan = _planProp.GetValue(owner.Instance, new object[0]) as HLSPlan;
                    if (_plan == null)
                    {
                        StringBuilder sb = new StringBuilder();
                        sb.AppendFormat("HLS error: declaring type {0} with property {1} does not return an appropriate HLS plan",
                                        _pd.Method.DeclaringType.Name, _planProp);
                        throw new InvalidOperationException(sb.ToString());
                    }
                }
                else
                {
                    _plan = HLSPlan.CopyPlan(_pd.GetDesign().GetHLSPlan());
                }
                _plan.Execute(context, rtl, _pd, targetProject);
            }
示例#5
0
        public ComponentBase ReadComponent(Stream s, ComponentDescriptor descriptor, AttributeComponent template = null)
        {
            var objComponent = new ObjectComponent {
                Descriptor = descriptor
            };

            if (descriptor.DoesObjectHaveName)
            {
                objComponent.Name = _obnameReader.ReadOBNAME(s);
            }
            return(objComponent);
        }
示例#6
0
        public void AddComponent(ComponentDescriptor componentDescriptor)
        {
            Type vmType                  = componentDescriptor.ComponentType;
            Type componentType           = BehaviourViewModelFactory.GetBehaviourFromViewModelProxy(vmType);
            BehaviourComponent component = BehaviourFactory.CreateFromType(componentType, entityData);

            entityData.AddComponent(component);
            //Create a viewmodel proxy for our new component
            BehaviourViewModel vm = BehaviourViewModelFactory.GetViewModelProxy(component);

            ComponentAdded?.Invoke(vm);
        }
示例#7
0
 private void AddComponentToCurrentTarget(IComponentContainer target, ComponentDescriptor component)
 {
     try
     {
         target.AddComponent(component);
     }
     catch (Exception e)
     {
         if (ShowMessageBoxOnError)
         {
             MessageBox.Show($"An Error Occured:\n{e.ToString()}");
         }
     }
 }
示例#8
0
        public void ExcludesAbstractClass()
        {
            var component = new ComponentDescriptor("ipsum", new AssemblyWrapper(new List <Type> {
                typeof(Class_A_Abstract)
            }));
            var componentProvider = Mock.Of <IComponentProvider>();

            Mock.Get(componentProvider).Setup(p => p.GetAll()).Returns(new List <ComponentDescriptor> {
                component
            });

            var result = new ContentTypeCreator(componentProvider).Create();

            Assert.Empty(result);
        }
示例#9
0
        private void CreateCoStateValues()
        {
            foreach (var kvp in _coFSMs)
            {
                ITransactionSite target = kvp.Key;
                CoFSMInfo        cfi    = kvp.Value;

                string ename, fname;
                if (target.Name == null)
                {
                    ename = "E_" + target.Host.Descriptor.Name + "_CoState";
                    fname = "m_" + target.Host.Descriptor.Name + "_CoState";
                }
                else
                {
                    ename = "E_" + target.Host.Descriptor.Name + "_" + target.Name + "_CoState";
                    fname = "m_" + target.Host.Descriptor.Name + "_" + target.Name + "_CoState";
                }

                Type                tState  = CreateEnum(ename, cfi.TotalStates);
                TypeDescriptor      tdState = (TypeDescriptor)tState;
                ComponentDescriptor owner   = (ComponentDescriptor)_code.Owner;
                owner.AddChild(tdState, tdState.Name);

                Type         tStateSignal  = typeof(Signal <>).MakeGenericType(tState);
                FieldBuilder fbStateSignal = _tComponent.DefineField(fname, tStateSignal, FieldAttributes.Private);
                Array        enumValues    = tState.GetEnumValues();
                object       initVal;
                if (cfi.HasNeutralTA)
                {
                    initVal = cfi.FirstNeutral.StateValue;
                }
                else
                {
                    initVal = enumValues.GetValue(0);
                }
                var sdState = owner.CreateSignalInstance(fname, initVal);
                cfi.CoStateSignal           = new SignalRef(sdState, SignalRef.EReferencedProperty.Instance);
                cfi.CoStateType             = tStateSignal;
                cfi.NextCoState.PlaceHolder = new SignalRef(sdState, SignalRef.EReferencedProperty.Next);

                foreach (CoStateInfo csi in cfi.StateInfos)
                {
                    csi.StateValue            = enumValues.GetValue(csi.StateIndex);
                    csi.StateExpr.PlaceHolder = LiteralReference.CreateConstant(csi.StateValue);
                }
            }
        }
        public ComponentBase ReadComponent(Stream s, ComponentDescriptor descriptor, AttributeComponent template = null)
        {
            var setComponent = new SetComponent {
                Descriptor = descriptor
            };

            if (descriptor.DoesSetHaveType)
            {
                setComponent.Type = _identReader.ReadIDENT(s);
            }
            if (descriptor.DoesSetHaveName)
            {
                setComponent.Name = _identReader.ReadIDENT(s);
            }
            return(setComponent);
        }
        private void AdaptCalls(CodeDescriptor cd, Dictionary <object, IEnumerable <SignalArgumentDescriptor> > map)
        {
            List <Statement>            stmts = cd.Implementation.Body.GetAtomicStatements();
            IEnumerable <CallStatement> calls = stmts.Select(s => s as CallStatement).Where(s => s != null);
            ComponentDescriptor         owner = (ComponentDescriptor)cd.Owner;

            foreach (CallStatement stmt in calls)
            {
                var fspec = stmt.Callee as FunctionSpec;
                if (fspec == null)
                {
                    continue;
                }
                object key;

                /*if (fspec.SysDOMRep != null)
                 *  key = fspec.SysDOMRep;
                 * else*/
                if (fspec.CILRep != null)
                {
                    key = fspec.CILRep;
                }
                else
                {
                    continue;
                }
                IEnumerable <SignalArgumentDescriptor> addArgs;
                if (!map.TryGetValue(key, out addArgs))
                {
                    continue;
                }
                List <Expression> args = stmt.Arguments.ToList();
                foreach (SignalArgumentDescriptor sad in addArgs)
                {
                    SignalBase sigInst = (SignalBase)sad.Sample;
                    var        sigRef  = sigInst.Descriptor
                                         .AsSignalRef(SignalRef.EReferencedProperty.Instance)
                                         .RelateToComponent(owner);
                    if (sigRef == null)
                    {
                        throw new InvalidOperationException("Signal not found in local component");
                    }
                    args.Add(sigRef);
                }
                stmt.Arguments = args.ToArray();
            }
        }
示例#12
0
        public ComponentBase ReadComponent(Stream s, ComponentDescriptor descriptor, AttributeComponent template = null)
        {
            var label = ReadAttributeLabel(s, descriptor, template);
            var count = ReadAttributeCount(s, descriptor, template);
            var representationCode = ReadAttributeRepresentationCode(s, descriptor, template);
            var units = ReadAttributeUnits(s, descriptor, template);
            var value = ReadAttributeValue(s, descriptor, representationCode, count);

            return(new AttributeComponent
            {
                Descriptor = descriptor,
                Label = label,
                Count = count,
                RepresentationCode = representationCode,
                Units = units,
                Value = value
            });
        }
        public IComponentReader GetReader(ComponentDescriptor descriptor)
        {
            if (descriptor == null)
            {
                return(null);
            }

            return(descriptor.Role switch
            {
                ComponentDescriptor.ABSENT_ATTRIBUTE_ROLE => (IComponentReader)_serviceProvider.GetService <IAttributeComponentReader>(),
                ComponentDescriptor.ATTRIBUTE_ROLE => (IComponentReader)_serviceProvider.GetService <IAttributeComponentReader>(),
                ComponentDescriptor.INVARIANT_ATTRIBUTE_ROLE => (IComponentReader)_serviceProvider.GetService <IAttributeComponentReader>(),
                ComponentDescriptor.OBJECT_ROLE => (IComponentReader)_serviceProvider.GetService <IObjectComponentReader>(),
                ComponentDescriptor.REDUNDANT_SET_ROLE => (IComponentReader)_serviceProvider.GetService <ISetComponentReader>(),
                ComponentDescriptor.REPLACEMENT_SET_ROLE => (IComponentReader)_serviceProvider.GetService <ISetComponentReader>(),
                ComponentDescriptor.SET_ROLE => (IComponentReader)_serviceProvider.GetService <ISetComponentReader>(),
                _ => null,
            });
示例#14
0
        public byte ReadAttributeRepresentationCode(Stream s, ComponentDescriptor descriptor, AttributeComponent template = null)
        {
            if (s == null || s.IsAtEndOfStream())
            {
                return(0);
            }

            var ushortReader = (IUSHORTReader)_valueReaderFactory.GetReader(RepresentationCode.USHORT);

            if (descriptor.DoesAttributeHaveRepresentationCode)
            {
                return(ushortReader.ReadUSHORT(s));
            }
            if (template == null)
            {
                return(DEFAULT_REP_CODE);
            }
            return(template.RepresentationCode);
        }
示例#15
0
        public uint ReadAttributeCount(Stream s, ComponentDescriptor descriptor, AttributeComponent template = null)
        {
            if (s == null || s.IsAtEndOfStream())
            {
                return(0);
            }

            var uvariReader = (IUVARIReader)_valueReaderFactory.GetReader(RepresentationCode.UVARI);

            if (descriptor.DoesAttributeHaveCount)
            {
                return(uvariReader.ReadUVARI(s));
            }
            if (template == null)
            {
                return(DEFAULT_COUNT);
            }
            return(template.Count);
        }
示例#16
0
        public string ReadAttributeUnits(Stream s, ComponentDescriptor descriptor, AttributeComponent template = null)
        {
            if (s == null || s.IsAtEndOfStream())
            {
                return(null);
            }

            var unitsReader = (IUNITSReader)_valueReaderFactory.GetReader(RepresentationCode.UNITS);

            if (descriptor.DoesAttributeHaveUnits)
            {
                return(unitsReader.ReadUNITS(s));
            }
            if (template == null)
            {
                return(DEFAULT_UNITS);
            }
            return(template.Units);
        }
示例#17
0
        public IEnumerable ReadAttributeValue(Stream s, ComponentDescriptor descriptor, byte repCode, uint count)
        {
            if (s == null || s.IsAtEndOfStream())
            {
                return(null);
            }
            if (!descriptor.DoesAttributeHaveValue)
            {
                return(null);
            }

            var valueReader = _valueReaderFactory.GetReader((RepresentationCode)repCode);

            if (valueReader == null)
            {
                throw new Exception($"no value reader found for representation code {repCode}");
            }
            return(valueReader.ReadValues(s, count));
        }
示例#18
0
        public string ReadAttributeLabel(Stream s, ComponentDescriptor descriptor, AttributeComponent template = null)
        {
            if (s == null || s.IsAtEndOfStream())
            {
                return(null);
            }

            var identReader = (IIDENTReader)_valueReaderFactory.GetReader(RepresentationCode.IDENT);

            if (descriptor.DoesAttributeHaveLabel)
            {
                return(identReader.ReadIDENT(s));
            }
            if (template == null)
            {
                return(DEFAULT_LABEL);
            }
            return(template.Label);
        }
示例#19
0
        public void IncludesAbstractClassIfSingleSubclassExists()
        {
            var component = new ComponentDescriptor("ipsum", new AssemblyWrapper(new List <Type> {
                typeof(Class_B_Extends_A)
            }));
            var componentProvider = Mock.Of <IComponentProvider>();

            Mock.Get(componentProvider).Setup(p => p.GetAll()).Returns(new List <ComponentDescriptor> {
                component
            });

            var result = new ContentTypeCreator(componentProvider).Create();

            Assert.Single(result);

            var contentType = result.Single();

            Assert.Equal("lorem", contentType.Id);
            Assert.Same(typeof(Class_B_Extends_A), contentType.Type);
        }
示例#20
0
        /// <summary>
        /// Synchronizes the specified <see cref="ComponentDescriptor"/> details with a
        /// <c>Snipt.It</c> component or creates one if no component matching the specified
        /// serial exists.
        /// </summary>
        /// <param name="snipe">
        ///     The <see cref="SnipeItApi"/> instance used to access the <c>Snipt.It</c>
        ///     web API.
        /// </param>
        /// <param name="component">
        ///     The <see cref="ComponentDescriptor"/> describing the component's details.
        /// </param>
        /// <returns>
        ///      The resulting <c>Snipt.It</c> <see cref="Component"/>.
        /// </returns>
        public static Component SyncComponent(this SnipeItApi snipe, ComponentDescriptor component)
        {
            // Validate parameters.
            if (snipe == null)
            {
                throw new ArgumentNullException("snipe");
            }
            if (component == null)
            {
                throw new ArgumentNullException("component");
            }
            if (String.IsNullOrWhiteSpace(component.Serial))
            {
                throw new ArgumentNullException("component.Serial");
            }

            string    snipeCategory  = SnipeApiExtensions.DefaultSnipeCategoriesMap[component.Category];
            Component snipeComponent = snipe.ComponentManager.FindAll(new SearchFilter {
                Search = component.Serial, Limit = 1
            })?.Rows.FirstOrDefault();
            var manufacturer = SnipeApiExtensions.SyncManufacturer(snipe, component.Manufacturer);
            var category     = SnipeApiExtensions.SyncCategory(snipe, snipeCategory, "component");

            if (snipeComponent == null)
            {
                snipeComponent = new Component()
                {
                    Category = category,
                    Name     = component.Name,
                    //Serial = component.Serial,
                    Quantity = 1
                };
                var response = snipe.ComponentManager.Create(snipeComponent);
                snipeComponent = snipe.ComponentManager.FindAll(new SearchFilter {
                    Search = component.Serial, Limit = 1
                })?.Rows.FirstOrDefault();
            }

            return(snipeComponent);
        }
示例#21
0
        public ComponentBase ReadComponent(Stream dlisStream, AttributeComponent template = null)
        {
            if (dlisStream == null || dlisStream.IsAtEndOfStream())
            {
                return(null);
            }

            var startPosition = dlisStream.Position;

            var descriptor      = new ComponentDescriptor(_ushortReader.ReadUSHORT(dlisStream));
            var componentReader = _componentReaderFactory.GetReader(descriptor);

            if (componentReader == null)
            {
                throw new Exception($"no component reader found for role {descriptor.Role}");
            }

            var component = componentReader.ReadComponent(dlisStream, descriptor, template);

            component.StartPosition = startPosition;

            return(component);
        }
示例#22
0
        private void AddInspectableComponent(IInspectableComponent component)
        {
            InspectableProperty[] properties = component.Properties;
            //Add Container independently of any properties
            ComponentDescriptor descriptor = ComponentDescriptorCache.GetDescriptor(component);
            CategoryContainer   container  = null;

            if (descriptor.Removable)
            {
                container = GetComponentCategoryContainer(component, descriptor.Title);
            }
            else
            {
                container = GetDefaultHeaderCategoryContainer(descriptor.Title);
            }
            foreach (InspectableProperty property in properties)
            {
                InspectablePropertyMetadata propertyMetadata = DefaultPropertyFactory.GetPropertyMetadata(property);

                ListenToPropertyChanged(property);
                AddProperty(property, propertyMetadata, container);
            }
        }
示例#23
0
 /// <summary>
 /// Calculates a component's <see cref="SystemUri"/> from a descriptor
 /// </summary>
 /// <param name="d">The component descriptor</param>
 /// <returns></returns>
 public static SystemUri ToSystemUri(this ComponentDescriptor d)
 => new SystemUri(scheme: "dev",
                  host: SystemNodeIdentifier.Local.Identifier,
                  path: $"{d.AreaId}/{d.SystemId}/{d.ComponentId}",
                  query: $"{nameof(d.Classification)} = {d.Classification}"
                  );