Пример #1
0
        /// <summary>
        /// Gelper method for getting the value from form parameter
        /// </summary>
        /// <param name="fieldName"></param>
        /// <param name="formSubmitContext"></param>
        /// <returns></returns>
        //private string GetValue(string fieldName, FormSubmitContext formSubmitContext)
        //{
        //    string val = string.Empty;
        //    //var postedFormData = formSubmitContext.PostedFormData;
        //    var field = formSubmitContext.Fields.FirstOrDefault(f => f.Name.Equals(fieldName));
        //    if (field != null)
        //    {
        //        var property = field.GetType().GetProperty("Value");
        //        if (property != null)
        //        {
        //            var postedVal = property.GetValue(field);
        //            val = postedVal != null ? postedVal.ToString() : string.Empty;
        //        }
        //    }

        //    return val;
        //}

        protected string GetValue(string fieldName, FormSubmitContext formSubmitContext)
        {
            IViewModel postedField = formSubmitContext.Fields.FirstOrDefault(f => f.Name.Equals(fieldName));

            Assert.ArgumentNotNull((object)postedField, "postedField");
            IValueField  valueField = postedField as IValueField;
            PropertyInfo property   = postedField.GetType().GetProperty("Value");
            object       obj;

            if (property == null)
            {
                obj = (object)null;
            }
            else
            {
                IViewModel viewModel = postedField;
                obj = property.GetValue((object)viewModel);
            }
            object postedValue = obj;

            if (postedValue == null)
            {
                return(string.Empty);
            }
            string parsedValue = ParseFieldValue(postedValue);

            return(parsedValue);
        }
 public FieldMouseDragger(IValueField <T> drivenField)
 {
     m_DrivenField = drivenField;
     m_DragElement = null;
     m_DragHotZone = new Rect(0, 0, -1, -1);
     dragging      = false;
 }
Пример #3
0
 public FieldMouseDragger(IValueField <T> drivenField)
 {
     this.m_DrivenField = drivenField;
     this.m_DragElement = null;
     this.m_DragHotZone = new Rect(0f, 0f, -1f, -1f);
     this.dragging      = false;
 }
Пример #4
0
 public VFXFieldMouseDragger(IValueField <T> drivenField, Action onDragFinished = null)
 {
     m_DrivenField    = drivenField;
     m_DragElement    = null;
     m_DragHotZone    = new Rect(0, 0, -1, -1);
     m_OnDragFinished = onDragFinished;
     dragging         = false;
 }
        /// <summary>
        /// Executes the action with the specified <paramref name="data" />.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <param name="formSubmitContext">The form submit context.</param>
        /// <returns>
        ///   <c>true</c> if the action is executed correctly; otherwise <c>false</c>
        /// </returns>
        protected override bool Execute(string data, FormSubmitContext formSubmitContext)
        {
            Assert.ArgumentNotNull(formSubmitContext, nameof(formSubmitContext));
            Assert.ArgumentNotNullOrEmpty(_connectionstring, nameof(_connectionstring));

            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(_connectionstring);
            CloudQueueClient    queueClient    = storageAccount.CreateCloudQueueClient();

            // Retrieve a reference to a container. use only lowercase!!
            CloudQueue queue = queueClient.GetQueueReference("stockpickformsqueue");

            // Create the queue if it doesn't already exist
            queue.CreateIfNotExists();

            // Create a message
            var message = new FormFields
            {
                FormId = formSubmitContext.FormId.ToString(),
                Fields = new List <FormFieldSmall>()
            };

            foreach (var viewModel in formSubmitContext.Fields)
            {
                var          postedField = (IValueField)viewModel;
                IValueField  valueField  = postedField as IValueField;
                PropertyInfo property    = postedField.GetType().GetProperty("Value");
                object       postedValue =
                    (object)property != null?property.GetValue((object)postedField) : (object)null;

                property = postedField.GetType().GetProperty("Title");
                object postedTitle =
                    (object)property != null?property.GetValue((object)postedField) : (object)null;

                if (valueField.AllowSave && postedValue != null && postedTitle != null)
                {
                    message.Fields.Add(new FormFieldSmall()
                    {
                        Name   = viewModel.Name,
                        Title  = postedTitle.ToString(),
                        ItemId = viewModel.ItemId,
                        Value  = postedValue.ToString()
                    });
                }
            }

            // Create a queue message with JSON and add it to the queue.
            CloudQueueMessage queuemessage = new CloudQueueMessage(JsonConvert.SerializeObject(message));

            queue.AddMessage(queuemessage);
            return(true);
        }
Пример #6
0
        public static KeyValuePair <string, object> GetFieldData(IViewModel postedField)
        {
            Assert.ArgumentNotNull((object)postedField, "postedField");
            IValueField valueField = postedField as IValueField;

            if ((valueField != null ? (valueField.AllowSave ? 1 : 0) : 0) == 0)
            {
                return(GenerateKeyValuePair(postedField.Name));
            }

            var fileProperty = postedField.GetType().GetProperty("File");

            var file = fileProperty?.GetValue(postedField);

            if (fileProperty == null)
            {
                PropertyInfo property2 = postedField.GetType().GetProperty("Value");
                object       postedValue2;
                postedValue2 = property2.GetValue((object)postedField);

                return(GenerateKeyValuePair(postedField.Name, postedValue2));
            }
            else
            {
                if (file != null)
                {
                    var property = ((HttpPostedFileWrapper)fileProperty.GetValue(postedField)).InputStream;
                    fileName = ((HttpPostedFileWrapper)fileProperty.GetValue(postedField)).FileName;
                    var    propertylenght = ((HttpPostedFileWrapper)fileProperty.GetValue(postedField)).ContentLength;
                    byte[] fileData       = null;
                    using (var binaryReader = new BinaryReader(property))
                    {
                        fileData = binaryReader.ReadBytes(propertylenght);
                    }
                    object postedValue;
                    postedValue = fileData;
                    return(GenerateKeyValuePair(postedField.ItemId, postedValue));
                }
                else
                {
                    return(GenerateKeyValuePair(postedField.ItemId, null));
                }
            }
        }
        protected static IList <Guid> GetCommittedFileIds(IViewModel postedField)
        {
            Assert.ArgumentNotNull((object)postedField, nameof(postedField));
            List <Guid> committedFileIds = new List <Guid>();
            IValueField valueField       = postedField as IValueField;

            if (valueField == null || !valueField.AllowSave)
            {
                return((IList <Guid>)committedFileIds);
            }
            PropertyInfo property = postedField.GetType().GetProperty("Value");
            object       obj      = (object)property != null?property.GetValue((object)postedField) : (object)null;

            if (obj == null)
            {
                return((IList <Guid>)committedFileIds);
            }
            (obj as List <StoredFileInfo>)?.ForEach((Action <StoredFileInfo>)(fileInfo => committedFileIds.Add(fileInfo.FileId)));
            return((IList <Guid>)committedFileIds);
        }
        private static void AddFieldData(IViewModel viewModel, FormFields message)
        {
            var          postedField = (IValueField)viewModel;
            IValueField  valueField  = postedField as IValueField;
            PropertyInfo property    = postedField.GetType().GetProperty("Value");
            object       postedValue =
                (object)property != null?property.GetValue((object)postedField) : (object)null;

            property = postedField.GetType().GetProperty("Title");
            object postedTitle =
                (object)property != null?property.GetValue((object)postedField) : (object)null;

            if (valueField.AllowSave && postedValue != null && postedTitle != null)
            {
                message.Fields.Add(new FormFieldSmall()
                {
                    Name   = viewModel.Name,
                    Title  = postedTitle.ToString(),
                    ItemId = viewModel.ItemId,
                    Value  = ParseFieldValue(postedValue)
                });
            }
        }
        protected override bool Execute(string data, FormSubmitContext formSubmitContext)
        {
            Assert.ArgumentNotNull(formSubmitContext, nameof(formSubmitContext));

            if (formSubmitContext.Canceled || formSubmitContext.HasErrors)
            {
                return(false);
            }

            string name        = string.Empty;
            string description = string.Empty;
            string place       = string.Empty;
            string startDate   = string.Empty;
            string endDate     = string.Empty;
            string eventtypes  = string.Empty;

            foreach (IViewModel field in formSubmitContext.Fields)
            {
                Assert.ArgumentNotNull((object)field, "postedField");

                IValueField valueField = field as IValueField;

                if (valueField != null)
                {
                    PropertyInfo fieldTitle = field.GetType().GetProperty("Title");
                    PropertyInfo fieldValue = field.GetType().GetProperty("Value");


                    if ((object)fieldTitle == null)
                    {
                        return(false);
                    }
                    else
                    {
                        var fieldValueString = fieldTitle.GetValue((object)field).ToString();
                        switch (fieldValueString)
                        {
                        case "Name":
                            name = fieldValueString;
                            break;

                        case "Description":
                            description = fieldValueString;
                            break;

                        case "Place":
                            place = fieldValueString;
                            break;

                        case "Start Date":
                            startDate = fieldValueString;
                            break;

                        case "End Date":
                            endDate = fieldValueString;
                            break;

                        case "Event Types":
                            eventtypes = fieldValueString;
                            break;

                        default:
                            break;
                        }
                    }
                }
            }

            if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(description) && !string.IsNullOrEmpty(place) && !string.IsNullOrEmpty(eventtypes))
            {
                using (new Sitecore.SecurityModel.SecurityDisabler()) {
                    CreateItem(name, description, place, startDate, endDate, eventtypes);
                }
                return(true);
            }
            else
            {
                formSubmitContext.Errors.Add(new FormActionError
                {
                    ErrorMessage = "OhOh! You have some problems!!"
                });
                return(false);
            }
        }
Пример #10
0
        protected override bool Execute(string data, FormSubmitContext formSubmitContext)
        {
            Assert.ArgumentNotNull(formSubmitContext, nameof(formSubmitContext));

            if (formSubmitContext.Canceled || formSubmitContext.HasErrors)
            {
                return(false);
            }

            string name        = string.Empty;
            string description = string.Empty;
            string location    = string.Empty;

            foreach (IViewModel field in formSubmitContext.Fields)
            {
                Assert.ArgumentNotNull((object)field, "postedField");

                IValueField valueField = field as IValueField;

                if (valueField != null)
                {
                    PropertyInfo fieldTitle = field.GetType().GetProperty("Title");
                    PropertyInfo fieldValue = field.GetType().GetProperty("Value");


                    if ((object)fieldTitle == null)
                    {
                        return(false);
                    }
                    else
                    {
                        var fieldValueString = fieldTitle.GetValue((object)field).ToString();

                        if (fieldValueString == "Name")
                        {
                            name = fieldValueString;
                        }
                        else if (fieldValueString == "Description")
                        {
                            description = fieldValueString;
                        }
                        else if (fieldValueString == "Location")
                        {
                            location = fieldValueString;
                        }
                    }
                }
            }

            if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(description) && !string.IsNullOrEmpty(location))
            {
                using (new Sitecore.SecurityModel.SecurityDisabler()) {
                    CreateItem(name, description, location);
                }
                return(true);
            }
            else
            {
                formSubmitContext.Errors.Add(new FormActionError
                {
                    ErrorMessage = "OhOh! You have some problems!!"
                });
                return(false);
            }
        }
Пример #11
0
        protected override bool Execute(string data, FormSubmitContext formSubmitContext)
        {
            Assert.ArgumentNotNull(formSubmitContext, nameof(formSubmitContext));

            if (formSubmitContext.Canceled || formSubmitContext.HasErrors)
            {
                return(false);
            }

            string username = string.Empty;
            string password = string.Empty;
            string email    = string.Empty;

            foreach (IViewModel field in formSubmitContext.Fields)
            {
                Assert.ArgumentNotNull((object)field, "postedField");

                IValueField valueField = field as IValueField;

                if (valueField != null)
                {
                    PropertyInfo fieldTitle = field.GetType().GetProperty("Title");
                    PropertyInfo fieldValue = field.GetType().GetProperty("Value");


                    if ((object)fieldTitle == null)
                    {
                        return(false);
                    }
                    else
                    {
                        if (fieldTitle.GetValue((object)field).ToString() == "Username")
                        {
                            username = fieldValue.GetValue((object)field).ToString();
                        }

                        if (fieldTitle.GetValue((object)field).ToString() == "Password")
                        {
                            password = fieldValue.GetValue((object)field).ToString();
                        }

                        if (fieldTitle.GetValue((object)field).ToString() == "Email")
                        {
                            email = fieldValue.GetValue((object)field).ToString();
                        }
                    }
                }
            }

            if (!User.Exists(@"mydomain\" + username))
            {
                System.Web.Security.Membership.CreateUser(@"mydomain\" + username, password, email);
                using (new Sitecore.SecurityModel.SecurityDisabler()) {
                    CreateItem(username, email);
                }
                return(true);
            }
            else
            {
                formSubmitContext.Errors.Add(new FormActionError
                {
                    ErrorMessage = "OhOh! You have some problems!!"
                });
                return(false);
            }
        }