コード例 #1
0
        public GenericField createGenericField(RightNowCustomObjectFieldAttribute 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.dataType = (ConnectService.DataTypeEnum)fieldType;
            genericField.DataValue.ItemsElementName = new ItemsChoiceType[] { fieldType };
            return(genericField);
        }
コード例 #2
0
        /********************/


        public UpdateResponse UpdateObject <T>(T obj, long uniqueId) where T : class, new()
        {
            UpdateResponse updateResponse = null;

            try
            {
                Type objType      = typeof(T);
                var  objAttribute = objType.GetCustomAttributes(typeof(RightNowCustomObjectAttribute), true).FirstOrDefault() as RightNowCustomObjectAttribute;
                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)
                {
                    RightNowCustomObjectFieldAttribute attribute = property.GetCustomAttributes(typeof(RightNowCustomObjectFieldAttribute), true).FirstOrDefault() as RightNowCustomObjectFieldAttribute;
                    if (attribute != null && attribute.CanUpdate)
                    {
                        var propValue = property.GetValue(obj, null);
                        //if (!string.IsNullOrWhiteSpace(propValue.ToString())) && !string.IsNullOrWhiteSpace(propValue.ToString())
                        if (propValue != null && !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(getClientInfoHeader(), new RNObject[] { genericObject }, options);
                updateResponse = this.getChannel().Update(updateRequest);
            }
            catch (Exception ex)
            {
                Logger.Logger.Log.Error("RightNowObjectProvider: Update failed", ex);
            }
            return(updateResponse);
        }
コード例 #3
0
        public CreateResponse CreateObject <T>(T obj) where T : class, new()
        {
            Type objType      = typeof(T);
            var  objAttribute = objType.GetCustomAttributes(typeof(RightNowCustomObjectAttribute), true).FirstOrDefault() as RightNowCustomObjectAttribute;

            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)
            {
                object attribute = property.GetCustomAttributes(typeof(RightNowCustomObjectFieldAttribute), true).FirstOrDefault();
                if (attribute != null)
                {
                    RightNowCustomObjectFieldAttribute rightNowAttribute = attribute as RightNowCustomObjectFieldAttribute;
                    if (rightNowAttribute.CanUpdate)
                    {
                        var propValue = property.GetValue(obj, null);
                        if (propValue != null && !string.IsNullOrWhiteSpace(propValue.ToString()))
                        {
                            genericFields.Add(createGenericField(rightNowAttribute, propValue));
                        }
                    }
                }
            }

            genericObject.GenericFields = genericFields.ToArray();
            CreateProcessingOptions options = new CreateProcessingOptions();

            options.SuppressExternalEvents = false;
            options.SuppressRules          = false;
            CreateRequest  createRequest   = new CreateRequest(getClientInfoHeader(), new RNObject[] { genericObject }, options);
            CreateResponse createResponcse = this.getChannel().Create(createRequest);

            return(createResponcse);
        }