private bool ValidateAttributeEntry1()
        {
            string attributeName = txtAttributeName1.Text.Trim();

            // string attributeDesc = txtDescription1.Text.Trim();

            //// check uniqueness
            //for (int i = 0; i < dlAttributes.Items.Count; i++)
            //{
            foreach (DataListItem li in dlAttributes.Items)
            {
                if (((Literal)li.FindControl("litAttributeName")).Text.Trim().ToLower() == attributeName.ToLower())
                {
                    ShowError("Attribute name already exists.");
                    return(false);
                }
            }



            // check characters
            if (!ObjectAttribute.IsValidAttributeName(attributeName))
            {
                ShowError("Attribute name is invalid.");
                return(false);
            }

            return(true);
        }
        private bool ValidateAttributeEntry(DataListCommandEventArgs e)
        {
            TextBox txtAttributeName = e.Item.FindControl("txtAttributeName") as TextBox;
            //TextBox txtDescription = e.Item.FindControl("txtDescription") as TextBox;
            //DropDownList ddlAttributeValueType = e.Item.FindControl("ddlAttributeValueType") as DropDownList;

            string attributeName = txtAttributeName.Text.Trim();

            //string attributeDesc = txtDescription.Text.Trim();

            // check uniqueness
            for (int i = 0; i < dlAttributes.Items.Count; i++)
            {
                if (i != e.Item.ItemIndex)
                {
                    if (((Literal)dlAttributes.Items[i].FindControl("litAttributeName")).Text.Trim().ToLower() == attributeName.ToLower())
                    {
                        ShowError("Attribute name already exists.");
                        return(false);
                    }
                }
            }

            // check characters
            if (!ObjectAttribute.IsValidAttributeName(attributeName))
            {
                ShowError("Attribute name is invalid.");
                return(false);
            }

            return(true);
        }
예제 #3
0
        private void EditAttributeValue()
        {
            ListViewItem selectedItem = WinFormsUtils.GetSingleSelectedItem(ListViewAttributes);

            if (selectedItem == null)
            {
                return;
            }

            ObjectAttribute objectAttribute = (ObjectAttribute)selectedItem.Tag;

            string attributeName = selectedItem.Text;

            byte[] attributeValue = (objectAttribute.CannotBeRead) ? new byte[0] : objectAttribute.GetValueAsByteArray();

            using (HexEditor hexEditor = new HexEditor(attributeName, attributeValue))
            {
                if (hexEditor.ShowDialog() == DialogResult.OK)
                {
                    AttributeModified = true;
                    ObjectAttribute updatedObjectAttribute = new ObjectAttribute(objectAttribute.Type, hexEditor.Bytes);
                    _pkcs11Slot.SaveObjectAttributes(_pkcs11ObjectInfo, new List <ObjectAttribute>()
                    {
                        updatedObjectAttribute
                    });
                    selectedItem.Tag = updatedObjectAttribute;
                    ReloadListView();
                }
            }
        }
예제 #4
0
        public static bool GetObjectAttribute(DisplayableObject singleObj, out ObjectAttribute sObjectAttribute)
        {
            sObjectAttribute = new ObjectAttribute();
            try
            {
                //取得Non-SelfCheck的Excel屬性
                try { sObjectAttribute.singleObjExcel = singleObj.GetStringAttribute(CaxME.DimenAttr.AssignExcelType); }
                catch (System.Exception ex) { sObjectAttribute.singleObjExcel = ""; }

                //取得SelfCheck的Excel屬性
                try { sObjectAttribute.singleSelfCheckExcel = singleObj.GetStringAttribute(CaxME.DimenAttr.SelfCheckExcel); }
                catch (System.Exception ex) { sObjectAttribute.singleSelfCheckExcel = ""; }

                //取得keyChara、productName、customerBalloon、SPCControl
                try { sObjectAttribute.keyChara = singleObj.GetStringAttribute(CaxME.DimenAttr.KC); }
                catch (System.Exception ex) { sObjectAttribute.keyChara = ""; }

                try { sObjectAttribute.productName = singleObj.GetStringAttribute(CaxME.DimenAttr.Product); }
                catch (System.Exception ex) { sObjectAttribute.productName = ""; }

                try { sObjectAttribute.customerBalloon = singleObj.GetStringAttribute(CaxME.DimenAttr.CustomerBalloon); }
                catch (System.Exception ex) { sObjectAttribute.customerBalloon = ""; }

                try { sObjectAttribute.spcControl = singleObj.GetStringAttribute(CaxME.DimenAttr.SpcControl); }
                catch (System.Exception ex) { sObjectAttribute.spcControl = ""; }
            }
            catch (System.Exception ex)
            {
                return(false);
            }
            return(true);
        }
예제 #5
0
        public void _01_DisposeAttributeTest()
        {
            Helpers.CheckPlatform();

            // Unmanaged memory for attribute value stored in low level CK_ATTRIBUTE struct
            // is allocated by constructor of ObjectAttribute class.
            ObjectAttribute attr1 = new ObjectAttribute(CKA.CKA_CLASS, CKO.CKO_DATA);

            // Do something interesting with attribute

            // This unmanaged memory is freed by Dispose() method.
            attr1.Dispose();


            // ObjectAttribute class can be used in using statement which defines a scope
            // at the end of which an object will be disposed (and unmanaged memory freed).
            using (ObjectAttribute attr2 = new ObjectAttribute(CKA.CKA_CLASS, CKO.CKO_DATA))
            {
                // Do something interesting with attribute
            }


            #pragma warning disable 0219

            // Explicit calling of Dispose() method can also be ommitted.
            ObjectAttribute attr3 = new ObjectAttribute(CKA.CKA_CLASS, CKO.CKO_DATA);

            // Do something interesting with attribute

            // Dispose() method will be called (and unmanaged memory freed) by GC eventually
            // but we cannot be sure when will this occur.

            #pragma warning restore 0219
        }
        public void _06_ByteArrayAttributeTest()
        {
            if (Platform.UnmanagedLongSize != 8 || Platform.StructPackingSize != 0)
            {
                Assert.Inconclusive("Test cannot be executed on this platform");
            }

            byte[] value = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09 };

            // Create attribute with byte array value
            using (ObjectAttribute attr = new ObjectAttribute(CKA.CKA_ID, value))
            {
                Assert.IsTrue(attr.Type == (ulong)CKA.CKA_ID);
                Assert.IsTrue(Convert.ToBase64String(attr.GetValueAsByteArray()) == Convert.ToBase64String(value));
            }

            value = null;

            // Create attribute with null byte array value
            using (ObjectAttribute attr = new ObjectAttribute(CKA.CKA_ID, value))
            {
                Assert.IsTrue(attr.Type == (ulong)CKA.CKA_ID);
                Assert.IsTrue(attr.GetValueAsByteArray() == value);
            }
        }
예제 #7
0
        private static List <Tuple <ObjectAttribute, ClassAttribute> > GetDefaultAttributes(ClassAttributesDefinition classAttributes, ulong?objectType, bool createObject)
        {
            if (classAttributes == null)
            {
                throw new ArgumentNullException("classAttributes");
            }

            List <Tuple <ObjectAttribute, ClassAttribute> > objectAttributes = new List <Tuple <ObjectAttribute, ClassAttribute> >();

            foreach (ClassAttribute classAttribute in classAttributes.CommonAttributes)
            {
                ObjectAttribute objectAttribute = (createObject) ? GetDefaultAttribute(classAttribute.Value, classAttribute.CreateDefaultValue) : GetDefaultAttribute(classAttribute.Value, classAttribute.GenerateDefaultValue);
                objectAttributes.Add(new Tuple <ObjectAttribute, ClassAttribute>(objectAttribute, classAttribute));
            }

            if ((objectType != null) && (classAttributes.TypeSpecificAttributes.ContainsKey(objectType.Value)))
            {
                foreach (ClassAttribute classAttribute in classAttributes.TypeSpecificAttributes[objectType.Value])
                {
                    ObjectAttribute objectAttribute = (createObject) ? GetDefaultAttribute(classAttribute.Value, classAttribute.CreateDefaultValue) : GetDefaultAttribute(classAttribute.Value, classAttribute.GenerateDefaultValue);
                    objectAttributes.Add(new Tuple <ObjectAttribute, ClassAttribute>(objectAttribute, classAttribute));
                }
            }

            return(objectAttributes);
        }
예제 #8
0
        private void EditAttributeValue()
        {
            ListView activeListView = GetActiveListView();

            ListViewItem selectedItem = WinFormsUtils.GetSingleSelectedItem(activeListView);

            if (selectedItem == null)
            {
                return;
            }

            ObjectAttribute objectAttribute = (ObjectAttribute)selectedItem.Tag;

            string attributeName = selectedItem.Text;

            byte[] attributeValue = objectAttribute.GetValueAsByteArray() ?? new byte[0];

            using (HexEditor hexEditor = new HexEditor(attributeName, attributeValue))
            {
                if (hexEditor.ShowDialog() == DialogResult.OK)
                {
                    ObjectAttribute updatedObjectAttribute = new ObjectAttribute(objectAttribute.Type, hexEditor.Bytes);
                    selectedItem.Tag = updatedObjectAttribute;
                    ReloadListView(activeListView);
                }
            }
        }
        public void _05_StringAttributeTest()
        {
            if (Platform.UnmanagedLongSize != 8 || Platform.StructPackingSize != 0)
            {
                Assert.Inconclusive("Test cannot be executed on this platform");
            }

            string value = "Hello world";

            // Create attribute with string value
            using (ObjectAttribute attr = new ObjectAttribute(CKA.CKA_LABEL, value))
            {
                Assert.IsTrue(attr.Type == (ulong)CKA.CKA_LABEL);
                Assert.IsTrue(attr.GetValueAsString() == value);
            }

            value = null;

            // Create attribute with null string value
            using (ObjectAttribute attr = new ObjectAttribute(CKA.CKA_LABEL, value))
            {
                Assert.IsTrue(attr.Type == (ulong)CKA.CKA_LABEL);
                Assert.IsTrue(attr.GetValueAsString() == value);
            }
        }
예제 #10
0
        private static ObjectAttribute GetDefaultAttribute(ulong type, string defaultValue)
        {
            ObjectAttribute objectAttribute = null;

            if (defaultValue == null)
            {
                objectAttribute = new ObjectAttribute(type);
            }
            else
            {
                if (defaultValue.StartsWith("ULONG:"))
                {
                    string ulongString = defaultValue.Substring("ULONG:".Length);
                    ulong  ulongValue  = Convert.ToUInt64(ulongString);
                    objectAttribute = new ObjectAttribute(type, ulongValue);
                }
                else if (defaultValue.StartsWith("BOOL:"))
                {
                    string boolString = defaultValue.Substring("BOOL:".Length);

                    bool boolValue = false;
                    if (0 == string.Compare(boolString, "TRUE", true))
                    {
                        boolValue = true;
                    }
                    else if (0 == string.Compare(boolString, "FALSE", true))
                    {
                        boolValue = false;
                    }
                    else
                    {
                        throw new Exception("Unable to parse default value of class attribute");
                    }

                    objectAttribute = new ObjectAttribute(type, boolValue);
                }
                else if (defaultValue.StartsWith("STRING:"))
                {
                    string strValue = defaultValue.Substring("STRING:".Length);
                    objectAttribute = new ObjectAttribute(type, strValue);
                }
                else if (defaultValue.StartsWith("BYTES:"))
                {
                    string hexString = defaultValue.Substring("BYTES:".Length);
                    byte[] bytes     = ConvertUtils.HexStringToBytes(hexString);
                    objectAttribute = new ObjectAttribute(type, bytes);
                }
                else if (defaultValue.StartsWith("DATE:"))
                {
                    // TODO
                    throw new NotImplementedException();
                }
                else
                {
                    throw new Exception("Unable to parse default value of class attribute");
                }
            }

            return(objectAttribute);
        }
        public void _01_DisposeAttributeTest()
        {
            // Unmanaged memory for attribute value stored in low level CK_ATTRIBUTE struct
            // is allocated by constructor of ObjectAttribute class.
            ObjectAttribute attr1 = new ObjectAttribute(CKA.CKA_CLASS, CKO.CKO_DATA);

            // Do something interesting with attribute

            // This unmanaged memory is freed by Dispose() method.
            attr1.Dispose();


            // ObjectAttribute class can be used in using statement which defines a scope 
            // at the end of which an object will be disposed (and unmanaged memory freed).
            using (ObjectAttribute attr2 = new ObjectAttribute(CKA.CKA_CLASS, CKO.CKO_DATA))
            {
                // Do something interesting with attribute
            }


            #pragma warning disable 0219

            // Explicit calling of Dispose() method can also be ommitted.
            ObjectAttribute attr3 = new ObjectAttribute(CKA.CKA_CLASS, CKO.CKO_DATA);

            // Do something interesting with attribute

            // Dispose() method will be called (and unmanaged memory freed) by GC eventually
            // but we cannot be sure when will this occur.

            #pragma warning restore 0219
        }
예제 #12
0
        public List <Tuple <ObjectAttribute, ClassAttribute> > ImportCertificate(string fileName, byte[] fileContent)
        {
            X509CertificateParser x509CertificateParser = new X509CertificateParser();
            X509Certificate       x509Certificate       = x509CertificateParser.ReadCertificate(fileContent);

            List <Tuple <ObjectAttribute, ClassAttribute> > objectAttributes = StringUtils.GetCreateDefaultAttributes(Pkcs11Admin.Instance.Config.CertificateAttributes, (ulong)CKC.CKC_X_509);

            for (int i = 0; i < objectAttributes.Count; i++)
            {
                ObjectAttribute objectAttribute = objectAttributes[i].Item1;
                ClassAttribute  classAttribute  = objectAttributes[i].Item2;

                if (objectAttribute.Type == (ulong)CKA.CKA_LABEL)
                {
                    string label = fileName;
                    Dictionary <string, List <string> > subject = Utils.ParseX509Name(x509Certificate.SubjectDN);
                    if (subject.ContainsKey(X509ObjectIdentifiers.CommonName.Id) && (subject[X509ObjectIdentifiers.CommonName.Id].Count > 0))
                    {
                        label = subject[X509ObjectIdentifiers.CommonName.Id][0];
                    }

                    objectAttributes[i] = new Tuple <ObjectAttribute, ClassAttribute>(new ObjectAttribute(CKA.CKA_LABEL, label), classAttribute);
                }
                else if (objectAttribute.Type == (ulong)CKA.CKA_START_DATE)
                {
                    objectAttributes[i] = new Tuple <ObjectAttribute, ClassAttribute>(new ObjectAttribute(CKA.CKA_START_DATE, x509Certificate.NotBefore), classAttribute);
                }
                else if (objectAttribute.Type == (ulong)CKA.CKA_END_DATE)
                {
                    objectAttributes[i] = new Tuple <ObjectAttribute, ClassAttribute>(new ObjectAttribute(CKA.CKA_END_DATE, x509Certificate.NotAfter), classAttribute);
                }
                else if (objectAttribute.Type == (ulong)CKA.CKA_SUBJECT)
                {
                    objectAttributes[i] = new Tuple <ObjectAttribute, ClassAttribute>(new ObjectAttribute(CKA.CKA_SUBJECT, x509Certificate.SubjectDN.GetDerEncoded()), classAttribute);
                }
                else if (objectAttribute.Type == (ulong)CKA.CKA_ID)
                {
                    byte[] thumbPrint = null;
                    using (SHA1Managed sha1Managed = new SHA1Managed())
                        thumbPrint = sha1Managed.ComputeHash(x509Certificate.GetEncoded());

                    objectAttributes[i] = new Tuple <ObjectAttribute, ClassAttribute>(new ObjectAttribute(CKA.CKA_ID, thumbPrint), classAttribute);
                }
                else if (objectAttribute.Type == (ulong)CKA.CKA_ISSUER)
                {
                    objectAttributes[i] = new Tuple <ObjectAttribute, ClassAttribute>(new ObjectAttribute(CKA.CKA_ISSUER, x509Certificate.IssuerDN.GetDerEncoded()), classAttribute);
                }
                else if (objectAttribute.Type == (ulong)CKA.CKA_SERIAL_NUMBER)
                {
                    objectAttributes[i] = new Tuple <ObjectAttribute, ClassAttribute>(new ObjectAttribute(CKA.CKA_SERIAL_NUMBER, new DerInteger(x509Certificate.SerialNumber).GetDerEncoded()), classAttribute);
                }
                else if (objectAttribute.Type == (ulong)CKA.CKA_VALUE)
                {
                    objectAttributes[i] = new Tuple <ObjectAttribute, ClassAttribute>(new ObjectAttribute(CKA.CKA_VALUE, x509Certificate.GetEncoded()), classAttribute);
                }
            }

            return(objectAttributes);
        }
예제 #13
0
		private void DoGetAttribute(ObjectAttribute mAttribute){
			if(mAttribute != null){
				maxValue.Value=mAttribute.MaxValue;
				_value.Value=mAttribute.Value;
				curValue.Value=mAttribute.CurrentValue;
				tempValue.Value=mAttribute.TemporaryValue;
			}
		}
        public void IsValid_succeeds_when_value_is_null()
        {
            var attribute = new ObjectAttribute();

            var result = attribute.IsValid(value: null);

            result.Should().BeTrue();
        }
예제 #15
0
        public void SaveDeletedAttributes(string objectName, int itemId)
        {
            List <string> deleteAttributes;

            Dictionary <string, AttributeValue> attributeValues = GetEnteredAttributeValues(out deleteAttributes);

            ObjectAttribute.DeleteAttributes(objectName, itemId, deleteAttributes);
        }
예제 #16
0
 public static int GetFieldIndex([NotNull] ITable table,
                                 [NotNull] ObjectAttribute objectAttribute,
                                 [CanBeNull] IFieldIndexCache fieldIndexCache = null)
 {
     return
         (fieldIndexCache?.GetFieldIndex(table, objectAttribute.Name, objectAttribute.Role) ??
          GetFieldIndex(table, objectAttribute.Name, objectAttribute.Role));
 }
예제 #17
0
 protected ListMessageElement GetAttribute(ObjectAttribute attribute)
 {
     return(new ListMessageElement().AddElements(
                new StringMessageElement(attribute.Type)
                ).AddElements(
                GetAttributeValues(attribute)
                ));
 }
 public void _02_EmptyAttributeTest()
 {
     // Create attribute without the value
     using (ObjectAttribute attr = new ObjectAttribute(CKA.CKA_CLASS))
     {
         Assert.IsTrue(attr.Type == (ulong)CKA.CKA_CLASS);
         Assert.IsTrue(attr.GetValueAsByteArray() == null);
     }
 }
예제 #19
0
 public void _02_EmptyAttributeTest()
 {
     // Create attribute without the value
     using (ObjectAttribute attr = new ObjectAttribute(CKA.CKA_CLASS))
     {
         Assert.IsTrue(attr.Type == (ulong)CKA.CKA_CLASS);
         Assert.IsTrue(attr.GetValueAsByteArray() == null);
     }
 }
예제 #20
0
        public void FillObject(int Row, object Obj)
        {
            ObjectAttribute oa = new ObjectAttribute(Obj);

            for (int i = 0; i < this.DataTable.Columns.Count; i++)
            {
                string ColName = this.DataTable.Columns[i].ColumnName;
                oa.SetAttibute(ColName, this.DataTable.Rows[Row][ColName].ToString());
            }
        }
예제 #21
0
 public bool ContainsAttribute(ObjectAttribute attribute, AttributeType attributeType)
 {
     try
     {
         //return this._attrs.Any(oa => oa.AttributeID == (int)attribute && oa.AttributeType == (int)attributeType);
     }
     catch (Exception ex) {
         throw ex;
     }
     return false;
 }
예제 #22
0
        public void _07_DateTimeAttributeTest()
        {
            DateTime value = new DateTime(2012, 1, 30, 0, 0, 0, DateTimeKind.Utc);

            // Create attribute with DateTime value
            using (ObjectAttribute attr = new ObjectAttribute(CKA.CKA_START_DATE, value))
            {
                Assert.IsTrue(attr.Type == (ulong)CKA.CKA_START_DATE);
                Assert.IsTrue(attr.GetValueAsDateTime() == value);
            }
        }
예제 #23
0
        public void _04_BoolAttributeTest()
        {
            bool value = true;

            // Create attribute with bool value
            using (ObjectAttribute attr = new ObjectAttribute(CKA.CKA_TOKEN, value))
            {
                Assert.IsTrue(attr.Type == (ulong)CKA.CKA_TOKEN);
                Assert.IsTrue(attr.GetValueAsBool() == value);
            }
        }
예제 #24
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         this.BaseLoad();
         DataTable objects = ObjectAttribute.GetObjects();
         PopulateObjects(objects);
         LoadObjects(objects);
         PopulateAttributes();
     }
 }
예제 #25
0
 public void StartDocument(string filePath)
 {
     currentElement   = null;
     currentAttribute = null;
     if (model == null)
     {
         model            = new CIMModel();
         model.SourcePath = filePath;
     }
     inLevel = Level.Root;
 }
예제 #26
0
        public void _02_EmptyAttributeTest()
        {
            Helpers.CheckPlatform();

            // Create attribute without the value
            using (ObjectAttribute attr = new ObjectAttribute(CKA.CKA_CLASS))
            {
                Assert.IsTrue(attr.Type == NativeLongUtils.ConvertFromCKA(CKA.CKA_CLASS));
                Assert.IsTrue(attr.GetValueAsByteArray() == null);
            }
        }
예제 #27
0
        private static ObjectAttribute GetOriginFK([NotNull] IRelationshipClass relClass,
                                                   [NotNull] IObjectDataset objectDataset)
        {
            ObjectAttribute originFK = objectDataset.GetAttribute(relClass.OriginForeignKey);

            Assert.NotNull(originFK, "origin foreign key not found on dataset {0}: {1}",
                           objectDataset.Name,
                           relClass.OriginForeignKey);

            return(originFK);
        }
예제 #28
0
        public void _03_UintAttributeTest()
        {
            ulong value = (ulong)CKO.CKO_DATA;

            // Create attribute with ulong value
            using (ObjectAttribute attr = new ObjectAttribute(CKA.CKA_CLASS, value))
            {
                Assert.IsTrue(attr.Type == (ulong)CKA.CKA_CLASS);
                Assert.IsTrue(attr.GetValueAsUlong() == value);
            }
        }
예제 #29
0
파일: Builder.cs 프로젝트: swgshaw/f-spot
        void BindFields(object target, Type type)
        {
            System.Reflection.BindingFlags flags = System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.DeclaredOnly;
            if (target != null)
            {
                flags |= System.Reflection.BindingFlags.Instance;
            }
            else
            {
                flags |= System.Reflection.BindingFlags.Static;
            }

            do
            {
                System.Reflection.FieldInfo[] fields = type.GetFields(flags);
                if (fields == null)
                {
                    return;
                }

                foreach (System.Reflection.FieldInfo field in fields)
                {
                    object[] attrs = field.GetCustomAttributes(typeof(ObjectAttribute), false);
                    if (attrs == null || attrs.Length == 0)
                    {
                        continue;
                    }
                    // The widget to field binding must be 1:1, so only check
                    // the first attribute.
                    ObjectAttribute attr = (ObjectAttribute)attrs[0];
                    GLib.Object     gobject;
                    if (attr.Specified)
                    {
                        gobject = GetObject(attr.Name);
                    }
                    else
                    {
                        gobject = GetObject(field.Name);
                    }

                    if (gobject != null)
                    {
                        try {
                            field.SetValue(target, gobject, flags, null, null);
                        } catch (Exception e) {
                            Console.WriteLine("Unable to set value for field " + field.Name);
                            throw e;
                        }
                    }
                }
                type = type.BaseType;
            }while (type != typeof(object) && type != null);
        }
예제 #30
0
        public BaseObjectAttributes()
        {
            RegEx_Id = new ObjectAttribute(baseRegEx.RegEx_Id, baseRegEx.RegEx_IdClass.NodeLeft, attributeTypes.RegEx, 1)
            {
                Val_String = "[A-Za-z0-9]{8}[A-Za-z0-9]{4}[A-Za-z0-9]{4}[A-Za-z0-9]{4}[A-Za-z0-9]{12}"
            };

            RegEx = new List <ObjectAttribute>
            {
                RegEx_Id
            };
        }
예제 #31
0
        public static Association CreateAssociation(
            [NotNull] IRelationshipClass relClass,
            [NotNull] IObjectDataset destinationDataset,
            [NotNull] IObjectDataset originDataset,
            [NotNull] Model model)
        {
            bool unqualifyDatasetName = !model.HarvestQualifiedElementNames;

            string relClassName = DatasetUtils.GetName(relClass);

            AssociationCardinality cardinality = GetCardinality(relClass);
            ObjectAttribute        originPK    = GetOriginPK(relClass, originDataset);

            string associationName = !unqualifyDatasetName
                                                         ? relClassName
                                                         : ModelElementNameUtils.GetUnqualifiedName(relClassName);

            if (!relClass.IsAttributed &&
                relClass.Cardinality != esriRelCardinality.esriRelCardinalityManyToMany)
            {
                ObjectAttribute originFK = GetOriginFK(relClass,
                                                       destinationDataset);

                return(new ForeignKeyAssociation(associationName,
                                                 cardinality,
                                                 originFK,
                                                 originPK)
                {
                    Model = model
                });
            }

            ObjectAttribute destinationPK = GetDestinationPK(
                relClass, destinationDataset);

            var           relTable          = (ITable)relClass;
            esriFieldType destinationFKType = DatasetUtils.GetField(
                relTable,
                relClass.DestinationForeignKey).Type;
            esriFieldType originFKType = DatasetUtils.GetField(
                relTable, relClass.OriginForeignKey).Type;

            return(new AttributedAssociation(
                       associationName,
                       cardinality,
                       relClass.DestinationForeignKey, (FieldType)destinationFKType,
                       destinationPK,
                       relClass.OriginForeignKey, (FieldType)originFKType,
                       originPK)
            {
                Model = model
            });
        }
예제 #32
0
 public override void StartDocument()
 {
     currentElement   = null;
     currentAttribute = null;
     embeddedElement  = null;
     if (model == null)
     {
         model            = new CIMModel();
         model.SourcePath = this.filePath;
     }
     childrenOf = new Dictionary <string, Stack <CIMObject> >();
     inLevel    = Level.Root;
 }
예제 #33
0
        public void _03_UintAttributeTest()
        {
            Helpers.CheckPlatform();

            NativeULong value = NativeLongUtils.ConvertFromCKO(CKO.CKO_DATA);

            // Create attribute with NativeULong value
            using (ObjectAttribute attr = new ObjectAttribute(CKA.CKA_CLASS, value))
            {
                Assert.IsTrue(attr.Type == NativeLongUtils.ConvertFromCKA(CKA.CKA_CLASS));
                Assert.IsTrue(attr.GetValueAsNativeUlong() == value);
            }
        }
예제 #34
0
        public void _07_DateTimeAttributeTest()
        {
            Helpers.CheckPlatform();

            DateTime value = new DateTime(2012, 1, 30, 0, 0, 0, DateTimeKind.Utc);

            // Create attribute with DateTime value
            using (ObjectAttribute attr = new ObjectAttribute(CKA.CKA_START_DATE, value))
            {
                Assert.IsTrue(attr.Type == NativeLongUtils.ConvertFromCKA(CKA.CKA_START_DATE));
                Assert.IsTrue(attr.GetValueAsDateTime() == value);
            }
        }
예제 #35
0
	public void OnAttributeChange(ObjectAttribute attribute){
		maxValue = (ratio==DesiplayRatio.CurrentToValue?(attribute.Value + attribute.TemporaryValue):(attribute.MaxValue + attribute.TemporaryValue));
		curValue = (ratio==DesiplayRatio.CurrentToValue?attribute.CurrentValue:attribute.Value);

		//Debug.Log (attribute.AttributeName+" "+(float)curValue +" "+ (float)maxValue);
		if (currentValue != null) {
			currentValue.text = curValue.ToString ();
		}
		if (maximumValue != null) {
			maximumValue.text = maxValue.ToString ();
		}
		if (attributeName != null) {
			attributeName.text = attribute.AttributeName;
		}
	}
예제 #36
0
		public override void OnEnter ()
		{
			if (gameObject.Value == null) {
				Debug.Log (this.Root.Name);
			}
			handler = gameObject.Value.GetComponent<AttributeHandler> ();
			attr=handler.GetAttribute(attribute.Value);
			if (attr != null) {
				attr.OnChange.AddListener(DoGetAttribute);
				DoGetAttribute (attr);
			}

			Finish ();
	
		}
        public void _09_UintArrayAttributeTest()
        {
            List<ulong> originalValue = new List<ulong>();
            originalValue.Add(333333);
            originalValue.Add(666666);
            
            // Create attribute with ulong array value
            using (ObjectAttribute attr = new ObjectAttribute(CKA.CKA_ALLOWED_MECHANISMS, originalValue))
            {
                Assert.IsTrue(attr.Type == (ulong)CKA.CKA_ALLOWED_MECHANISMS);

                List<ulong> recoveredValue = attr.GetValueAsUlongList();
                for (int i = 0; i < recoveredValue.Count; i++)
                    Assert.IsTrue(originalValue[i] == recoveredValue[i]);
            }

            originalValue = null;

            // Create attribute with null ulong array value
            using (ObjectAttribute attr = new ObjectAttribute(CKA.CKA_ALLOWED_MECHANISMS, originalValue))
            {
                Assert.IsTrue(attr.Type == (ulong)CKA.CKA_ALLOWED_MECHANISMS);
                Assert.IsTrue(attr.GetValueAsUlongList() == originalValue);
            }

            originalValue = new List<ulong>();

            // Create attribute with empty ulong array value
            using (ObjectAttribute attr = new ObjectAttribute(CKA.CKA_ALLOWED_MECHANISMS, originalValue))
            {
                Assert.IsTrue(attr.Type == (ulong)CKA.CKA_ALLOWED_MECHANISMS);
                Assert.IsTrue(attr.GetValueAsUlongList() == null);
            }
        }
        public void _04_BoolAttributeTest()
        {
            bool value = true;

            // Create attribute with bool value
            using (ObjectAttribute attr = new ObjectAttribute(CKA.CKA_TOKEN, value))
            {
                Assert.IsTrue(attr.Type == (ulong)CKA.CKA_TOKEN);
                Assert.IsTrue(attr.GetValueAsBool() == value);
            }
        }
        public void _05_StringAttributeTest()
        {
            string value = "Hello world";

            // Create attribute with string value
            using (ObjectAttribute attr = new ObjectAttribute(CKA.CKA_LABEL, value))
            {
                Assert.IsTrue(attr.Type == (ulong)CKA.CKA_LABEL);
                Assert.IsTrue(attr.GetValueAsString() == value);
            }

            value = null;

            // Create attribute with null string value
            using (ObjectAttribute attr = new ObjectAttribute(CKA.CKA_LABEL, value))
            {
                Assert.IsTrue(attr.Type == (ulong)CKA.CKA_LABEL);
                Assert.IsTrue(attr.GetValueAsString() == value);
            }
        }
        public void _06_ByteArrayAttributeTest()
        {
            byte[] value = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09 };

            // Create attribute with byte array value
            using (ObjectAttribute attr = new ObjectAttribute(CKA.CKA_ID, value))
            {
                Assert.IsTrue(attr.Type == (ulong)CKA.CKA_ID);
                Assert.IsTrue(Convert.ToBase64String(attr.GetValueAsByteArray()) == Convert.ToBase64String(value));
            }

            value = null;

            // Create attribute with null byte array value
            using (ObjectAttribute attr = new ObjectAttribute(CKA.CKA_ID, value))
            {
                Assert.IsTrue(attr.Type == (ulong)CKA.CKA_ID);
                Assert.IsTrue(attr.GetValueAsByteArray() == value);
            }
        }
        public void _07_DateTimeAttributeTest()
        {
            DateTime value = new DateTime(2012, 1, 30, 0, 0, 0, DateTimeKind.Utc);

            // Create attribute with DateTime value
            using (ObjectAttribute attr = new ObjectAttribute(CKA.CKA_START_DATE, value))
            {
                Assert.IsTrue(attr.Type == (ulong)CKA.CKA_START_DATE);
                Assert.IsTrue(attr.GetValueAsDateTime() == value);
            }
        }
        public void _08_AttributeArrayAttributeTest()
        {
            ObjectAttribute nestedAttribute1 = new ObjectAttribute(CKA.CKA_TOKEN, true);
            ObjectAttribute nestedAttribute2 = new ObjectAttribute(CKA.CKA_PRIVATE, true);

            List<ObjectAttribute> originalValue = new List<ObjectAttribute>();
            originalValue.Add(nestedAttribute1);
            originalValue.Add(nestedAttribute2);

            // Create attribute with attribute array value
            using (ObjectAttribute attr = new ObjectAttribute(CKA.CKA_WRAP_TEMPLATE, originalValue))
            {
                Assert.IsTrue(attr.Type == (ulong)CKA.CKA_WRAP_TEMPLATE);

                List<ObjectAttribute> recoveredValue = attr.GetValueAsObjectAttributeList();
                Assert.IsTrue(recoveredValue.Count == 2);
                Assert.IsTrue(recoveredValue[0].Type == (ulong)CKA.CKA_TOKEN);
                Assert.IsTrue(recoveredValue[0].GetValueAsBool() == true);
                Assert.IsTrue(recoveredValue[1].Type == (ulong)CKA.CKA_PRIVATE);
                Assert.IsTrue(recoveredValue[1].GetValueAsBool() == true);
            }

            if (Platform.UnmanagedLongSize == 4)
            {
                if (Platform.StructPackingSize == 0)
                {
                    // There is the same pointer to unmanaged memory in both nestedAttribute1 and recoveredValue[0] instances
                    // therefore private low level attribute structure needs to be modified to prevent double free.
                    // This special handling is needed only in this synthetic test and should be avoided in real world application.
                    HLA40.ObjectAttribute objectAttribute40a = (HLA40.ObjectAttribute)typeof(ObjectAttribute).GetField("_objectAttribute40", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(nestedAttribute1);
                    LLA40.CK_ATTRIBUTE ckAttribute40a = (LLA40.CK_ATTRIBUTE)typeof(HLA40.ObjectAttribute).GetField("_ckAttribute", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(objectAttribute40a);
                    ckAttribute40a.value = IntPtr.Zero;
                    ckAttribute40a.valueLen = 0;
                    typeof(HLA40.ObjectAttribute).GetField("_ckAttribute", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(objectAttribute40a, ckAttribute40a);

                    // There is the same pointer to unmanaged memory in both nestedAttribute2 and recoveredValue[1] instances
                    // therefore private low level attribute structure needs to be modified to prevent double free.
                    // This special handling is needed only in this synthetic test and should be avoided in real world application.
                    HLA40.ObjectAttribute objectAttribute40b = (HLA40.ObjectAttribute)typeof(ObjectAttribute).GetField("_objectAttribute40", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(nestedAttribute2);
                    LLA40.CK_ATTRIBUTE ckAttribute40b = (LLA40.CK_ATTRIBUTE)typeof(HLA40.ObjectAttribute).GetField("_ckAttribute", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(objectAttribute40b);
                    ckAttribute40b.value = IntPtr.Zero;
                    ckAttribute40b.valueLen = 0;
                    typeof(HLA40.ObjectAttribute).GetField("_ckAttribute", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(objectAttribute40b, ckAttribute40b);
                }
                else
                {
                    // There is the same pointer to unmanaged memory in both nestedAttribute1 and recoveredValue[0] instances
                    // therefore private low level attribute structure needs to be modified to prevent double free.
                    // This special handling is needed only in this synthetic test and should be avoided in real world application.
                    HLA41.ObjectAttribute objectAttribute41a = (HLA41.ObjectAttribute)typeof(ObjectAttribute).GetField("_objectAttribute41", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(nestedAttribute1);
                    LLA41.CK_ATTRIBUTE ckAttribute41a = (LLA41.CK_ATTRIBUTE)typeof(HLA41.ObjectAttribute).GetField("_ckAttribute", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(objectAttribute41a);
                    ckAttribute41a.value = IntPtr.Zero;
                    ckAttribute41a.valueLen = 0;
                    typeof(HLA41.ObjectAttribute).GetField("_ckAttribute", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(objectAttribute41a, ckAttribute41a);

                    // There is the same pointer to unmanaged memory in both nestedAttribute2 and recoveredValue[1] instances
                    // therefore private low level attribute structure needs to be modified to prevent double free.
                    // This special handling is needed only in this synthetic test and should be avoided in real world application.
                    HLA41.ObjectAttribute objectAttribute41b = (HLA41.ObjectAttribute)typeof(ObjectAttribute).GetField("_objectAttribute41", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(nestedAttribute2);
                    LLA41.CK_ATTRIBUTE ckAttribute41b = (LLA41.CK_ATTRIBUTE)typeof(HLA41.ObjectAttribute).GetField("_ckAttribute", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(objectAttribute41b);
                    ckAttribute41b.value = IntPtr.Zero;
                    ckAttribute41b.valueLen = 0;
                    typeof(HLA41.ObjectAttribute).GetField("_ckAttribute", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(objectAttribute41b, ckAttribute41b);
                }
            }
            else
            {
                if (Platform.StructPackingSize == 0)
                {
                    // There is the same pointer to unmanaged memory in both nestedAttribute1 and recoveredValue[0] instances
                    // therefore private low level attribute structure needs to be modified to prevent double free.
                    // This special handling is needed only in this synthetic test and should be avoided in real world application.
                    HLA80.ObjectAttribute objectAttribute80a = (HLA80.ObjectAttribute)typeof(ObjectAttribute).GetField("_objectAttribute80", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(nestedAttribute1);
                    LLA80.CK_ATTRIBUTE ckAttribute80a = (LLA80.CK_ATTRIBUTE)typeof(HLA80.ObjectAttribute).GetField("_ckAttribute", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(objectAttribute80a);
                    ckAttribute80a.value = IntPtr.Zero;
                    ckAttribute80a.valueLen = 0;
                    typeof(HLA80.ObjectAttribute).GetField("_ckAttribute", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(objectAttribute80a, ckAttribute80a);

                    // There is the same pointer to unmanaged memory in both nestedAttribute2 and recoveredValue[1] instances
                    // therefore private low level attribute structure needs to be modified to prevent double free.
                    // This special handling is needed only in this synthetic test and should be avoided in real world application.
                    HLA80.ObjectAttribute objectAttribute80b = (HLA80.ObjectAttribute)typeof(ObjectAttribute).GetField("_objectAttribute80", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(nestedAttribute2);
                    LLA80.CK_ATTRIBUTE ckAttribute80b = (LLA80.CK_ATTRIBUTE)typeof(HLA80.ObjectAttribute).GetField("_ckAttribute", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(objectAttribute80b);
                    ckAttribute80b.value = IntPtr.Zero;
                    ckAttribute80b.valueLen = 0;
                    typeof(HLA80.ObjectAttribute).GetField("_ckAttribute", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(objectAttribute80b, ckAttribute80b);
                }
                else
                {
                    // There is the same pointer to unmanaged memory in both nestedAttribute1 and recoveredValue[0] instances
                    // therefore private low level attribute structure needs to be modified to prevent double free.
                    // This special handling is needed only in this synthetic test and should be avoided in real world application.
                    HLA81.ObjectAttribute objectAttribute81a = (HLA81.ObjectAttribute)typeof(ObjectAttribute).GetField("_objectAttribute81", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(nestedAttribute1);
                    LLA81.CK_ATTRIBUTE ckAttribute81a = (LLA81.CK_ATTRIBUTE)typeof(HLA81.ObjectAttribute).GetField("_ckAttribute", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(objectAttribute81a);
                    ckAttribute81a.value = IntPtr.Zero;
                    ckAttribute81a.valueLen = 0;
                    typeof(HLA81.ObjectAttribute).GetField("_ckAttribute", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(objectAttribute81a, ckAttribute81a);

                    // There is the same pointer to unmanaged memory in both nestedAttribute2 and recoveredValue[1] instances
                    // therefore private low level attribute structure needs to be modified to prevent double free.
                    // This special handling is needed only in this synthetic test and should be avoided in real world application.
                    HLA81.ObjectAttribute objectAttribute81b = (HLA81.ObjectAttribute)typeof(ObjectAttribute).GetField("_objectAttribute81", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(nestedAttribute2);
                    LLA81.CK_ATTRIBUTE ckAttribute81b = (LLA81.CK_ATTRIBUTE)typeof(HLA81.ObjectAttribute).GetField("_ckAttribute", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(objectAttribute81b);
                    ckAttribute81b.value = IntPtr.Zero;
                    ckAttribute81b.valueLen = 0;
                    typeof(HLA81.ObjectAttribute).GetField("_ckAttribute", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(objectAttribute81b, ckAttribute81b);
                }
            }

            originalValue = null;

            // Create attribute with null attribute array value
            using (ObjectAttribute attr = new ObjectAttribute(CKA.CKA_WRAP_TEMPLATE, originalValue))
            {
                Assert.IsTrue(attr.Type == (ulong)CKA.CKA_WRAP_TEMPLATE);
                Assert.IsTrue(attr.GetValueAsObjectAttributeList() == originalValue);
            }

            originalValue = new List<ObjectAttribute>();

            // Create attribute with empty attribute array value
            using (ObjectAttribute attr = new ObjectAttribute(CKA.CKA_WRAP_TEMPLATE, originalValue))
            {
                Assert.IsTrue(attr.Type == (ulong)CKA.CKA_WRAP_TEMPLATE);
                Assert.IsTrue(attr.GetValueAsObjectAttributeList() == null);
            }
        }
예제 #43
0
 public object ValueOf(ObjectAttribute attribute, AttributeType attributeType)
 {
     //var res = this._attrs.FirstOrDefault (oa => oa.AttributeID == (int)attribute && oa.AttributeType == (int)attributeType);
     //if (res != null)
     //	return res.Value;
     //else
         return new OAttribute ().Value;
 }
        public void _10_MechanismArrayAttributeTest()
        {
            List<CKM> originalValue = new List<CKM>();
            originalValue.Add(CKM.CKM_RSA_PKCS);
            originalValue.Add(CKM.CKM_AES_CBC);

            // Create attribute with mechanism array value
            using (ObjectAttribute attr = new ObjectAttribute(CKA.CKA_ALLOWED_MECHANISMS, originalValue))
            {
                Assert.IsTrue(attr.Type == (ulong)CKA.CKA_ALLOWED_MECHANISMS);
                
                List<CKM> recoveredValue = attr.GetValueAsCkmList();
                for (int i = 0; i < recoveredValue.Count; i++)
                    Assert.IsTrue(originalValue[i] == recoveredValue[i]);
            }
            
            originalValue = null;
            
            // Create attribute with null mechanism array value
            using (ObjectAttribute attr = new ObjectAttribute(CKA.CKA_ALLOWED_MECHANISMS, originalValue))
            {
                Assert.IsTrue(attr.Type == (ulong)CKA.CKA_ALLOWED_MECHANISMS);
                Assert.IsTrue(attr.GetValueAsCkmList() == originalValue);
            }
            
            originalValue = new List<CKM>();
            
            // Create attribute with empty mechanism array value
            using (ObjectAttribute attr = new ObjectAttribute(CKA.CKA_ALLOWED_MECHANISMS, originalValue))
            {
                Assert.IsTrue(attr.Type == (ulong)CKA.CKA_ALLOWED_MECHANISMS);
                Assert.IsTrue(attr.GetValueAsCkmList() == null);
            }
        }
        public void _03_UintAttributeTest()
        {
            ulong value = (ulong)CKO.CKO_DATA;

            // Create attribute with ulong value
            using (ObjectAttribute attr = new ObjectAttribute(CKA.CKA_CLASS, value))
            {
                Assert.IsTrue(attr.Type == (ulong)CKA.CKA_CLASS);
                Assert.IsTrue(attr.GetValueAsUlong() == value);
            }
        }
예제 #46
0
파일: Effects.cs 프로젝트: GSazheniuk/HOO
 public bool ContainsEffect(ObjectAttribute attribute)
 {
     return this._effects.ContainsKey ((int)attribute);
 }