示例#1
0
        private GenericField CreateGenericField(RightNowFieldAttribute attribute, object value)
        {
            GenericField genericField = new GenericField();

            genericField.name      = attribute.Name;
            genericField.DataValue = new DataValue();

            ItemsChoiceType fieldType = ItemsChoiceType.StringValue;

            if (attribute.FieldType != null)
            {
                fieldType = attribute.FieldType;
            }

            if (fieldType == ItemsChoiceType.NamedIDValue)
            {
                NamedID accountID = new NamedID();
                accountID.ID = new ID();
                long id = 0;
                Int64.TryParse(value.ToString(), out id);
                accountID.ID.id              = id;
                accountID.ID.idSpecified     = true;
                genericField.DataValue.Items = new object[] { accountID };
            }
            else
            {
                genericField.DataValue.Items = new object[] { value };
            }
            genericField.DataValue.ItemsElementName = new ItemsChoiceType[] { fieldType };
            return(genericField);
        }
示例#2
0
        public UpdateResponse UpdateObject <T>(T obj, long uniqueId) where T : class, new()
        {
            Type objType      = typeof(T);
            var  objAttribute = objType.GetCustomAttributes(typeof(RightNowObjectAttribute), true).FirstOrDefault() as RightNowObjectAttribute;

            if (objAttribute == null)
            {
                throw new InvalidOperationException("The type provided is not a RightNow custom object type. Please use the RightNowObjectAttribute to associate the proper metadata with the type");
            }

            GenericObject genericObject = new GenericObject();
            RNObjectType  rnObjType     = new RNObjectType()
            {
                Namespace = objAttribute.PackageName, TypeName = objAttribute.ObjectName
            };

            genericObject.ObjectType = rnObjType;

            List <GenericField> genericFields = new List <GenericField>();

            PropertyInfo[] properties = objType.GetProperties();
            foreach (PropertyInfo property in properties)
            {
                RightNowFieldAttribute attribute = property.GetCustomAttributes(typeof(RightNowFieldAttribute), true).FirstOrDefault() as RightNowFieldAttribute;
                if (attribute != null && attribute.CanUpdate)
                {
                    var propValue = property.GetValue(obj, null);
                    if (!string.IsNullOrWhiteSpace(propValue.ToString()))
                    {
                        genericFields.Add(CreateGenericField(attribute, propValue));
                    }
                }
            }

            genericObject.GenericFields = genericFields.ToArray();
            ID autoID = new ID();

            autoID.id          = uniqueId;
            autoID.idSpecified = true;
            genericObject.ID   = autoID;

            UpdateProcessingOptions options = new UpdateProcessingOptions();

            options.SuppressExternalEvents = false;
            options.SuppressRules          = false;
            UpdateRequest  updateRequest  = new UpdateRequest(this.ClientHeader, new RNObject[] { genericObject }, options);
            UpdateResponse updateResponse = this.GetChannel().Update(updateRequest);

            return(updateResponse);
        }