public override Item HandlePack(ItemIdentifier id)
        {
            var fs   = new Umbraco.Forms.Data.Storage.FormStorage();
            var form = fs.GetForm(Guid.Parse(id.Id));

            if (form == null)
            {
                return(null);
            }

            var item = new UmbracoForm();

            item.ItemId = id;
            item.Name   = form.Name;

            //Handle forms and fields
            var formPath = Umbraco.Forms.Core.Configuration.ContourFolder + "/data/forms/" + id.Id + ".json";

            item.Resources.Add(formPath);

            //handle submit to node id
            if (form.GoToPageOnSubmit > 0)
            {
                item.GoToPageOnSubmitId = ExecutionContext.DatabasePersistence.GetUniqueId(form.GoToPageOnSubmit);
                item.Dependencies.Add(item.GoToPageOnSubmitId.ToString(), ItemProviders.ProviderIDCollection.documentItemProviderGuid);
            }
            //Parse field settings and field prevalue source settings
            foreach (var field in form.AllFields)
            {
                var parsed = ParseSettings(field.FieldType.Settings(), field.Settings, item);
                if (parsed.Count > 0)
                {
                    item.FieldSettings.Add(field.Id, parsed);
                }

                if (field.PreValueSourceId != Guid.Empty && !item.PrevalueSourceSettings.ContainsKey(field.PreValueSourceId))
                {
                    var prvParsed = ParseSettings(field.PreValueSource.Type.Settings(), field.PreValueSource.Settings, item);
                    if (prvParsed.Count > 0)
                    {
                        item.PrevalueSourceSettings.Add(field.PreValueSourceId, prvParsed);
                    }

                    item.Resources.Add(Umbraco.Forms.Core.Configuration.ContourFolder + "/data/prevalueSources/" + field.PreValueSourceId + ".json");
                }
            }



            //parse data source settings
            if (form.HasDataSource())
            {
                using (var dss = new Umbraco.Forms.Data.Storage.DataSourceStorage())
                {
                    var dataSource = dss.GetDataSource(form.DataSource.Id);

                    if (dataSource != null)
                    {
                        var dsParsed = ParseSettings(dataSource.Type.Settings(), dataSource.Settings, item);

                        if (dsParsed.Count > 0)
                        {
                            item.DataSourceSettings = dsParsed;
                        }

                        //add as file to item
                        item.Resources.Add(Umbraco.Forms.Core.Configuration.ContourFolder + "/data/datasources/" + form.DataSource.Id.ToString() + ".json");
                    }
                }
            }

            //Parse workflow settings
            if (form.WorkflowIds.Count > 0)
            {
                using (var wfs = new Umbraco.Forms.Data.Storage.WorkflowStorage())
                {
                    foreach (var wfId in form.WorkflowIds)
                    {
                        var workflow = wfs.GetWorkflow(wfId);
                        if (workflow != null)
                        {
                            var wfParsed = ParseSettings(workflow.Type.Settings(), workflow.Settings, item);
                            if (wfParsed.Count > 0)
                            {
                                item.WorkflowSettings.Add(wfId, wfParsed);
                            }

                            //add file to item
                            item.Resources.Add(Umbraco.Forms.Core.Configuration.ContourFolder + "/data/workflows/" + wfId.ToString() + ".json");
                        }
                    }
                }
            }

            return(item);
        }
        private SerializableDictionary <string, string> ParseSettings(IDictionary <string, Umbraco.Forms.Core.Attributes.Setting> settingsScema, IDictionary <string, string> settings, UmbracoForm item)
        {
            SerializableDictionary <string, string> settingsMap = new SerializableDictionary <string, string>();

            if (settingsScema != null && settings != null)
            {
                foreach (var setting in settingsScema)
                {
                    if (settings.ContainsKey(setting.Key))
                    {
                        var settingValue = settings[setting.Key];

                        if (string.IsNullOrEmpty(settingValue) == false)
                        {
                            //if the settings view is a node picker of some sort
                            if (setting.Value.view.ToLower().StartsWith("pickers."))
                            {
                                //if its a doctype, no conversion needed, just tell it to include the type as a dependency
                                if (setting.Value.view.ToLower() == "pickers.documenttype")
                                {
                                    item.Dependencies.Add(settingValue, ProviderIDCollection.documentTypeItemProviderGuid);
                                }
                                else
                                {
                                    int id = 0;
                                    if (int.TryParse(settingValue, out id))
                                    {
                                        var tuple = ExecutionContext.DatabasePersistence.GetUniqueIdWithType(id);
                                        if (tuple != null)
                                        {
                                            //guid
                                            var itemGuid       = tuple.Item1.ToString();
                                            var nodeObjectType = tuple.Item2;
                                            var itemProvider   = Umbraco.Courier.ItemProviders.NodeObjectTypes.GetCourierProviderFromNodeObjectType(nodeObjectType);
                                            settingsMap[setting.Key] = itemGuid;

                                            if (itemProvider.HasValue)
                                            {
                                                item.Dependencies.Add(itemGuid, itemProvider.Value);
                                            }
                                        }
                                    }
                                }
                            }

                            //if the settings view is a file upload
                            if (setting.Value.view == "file")
                            {
                                item.Resources.Add(settingValue);
                            }
                        }
                    }
                }
            }

            return(settingsMap);
        }
Ejemplo n.º 3
0
        public override Item HandlePack(ItemIdentifier id)
        {
            var fs = new Umbraco.Forms.Data.Storage.FormStorage();

            Forms.Core.Form form;

            var formsDataLocation = GetFormsDataLocation();

            try
            {
                // If there is no form on the target disk or cache this method raises a System.NullReferenceException
                // See https://github.com/umbraco/Umbraco.Courier.FormsProvider/issues/3
                form = fs.GetForm(Guid.Parse(id.Id));
            }
            catch (Exception ex)
            {
                return(null);
            }

            if (form == null)
            {
                return(null);
            }

            var item = new UmbracoForm();

            item.ItemId = id;
            item.Name   = form.Name;

            //Handle forms and fields
            var formPath = formsDataLocation + "/forms/" + id.Id + ".json";

            item.Resources.Add(formPath);

            //handle submit to node id
            if (form.GoToPageOnSubmit > 0)
            {
                item.GoToPageOnSubmitId = ExecutionContext.DatabasePersistence.GetUniqueId(form.GoToPageOnSubmit);
                item.Dependencies.Add(item.GoToPageOnSubmitId.ToString(), ItemProviders.ProviderIDCollection.documentItemProviderGuid);
            }
            //Parse field settings and field prevalue source settings
            foreach (var field in form.AllFields)
            {
                var parsed = ParseSettings(field.FieldType.Settings(), field.Settings, item);
                if (parsed.Count > 0)
                {
                    item.FieldSettings.Add(field.Id, parsed);
                }

                if (field.PreValueSourceId != Guid.Empty && !item.PrevalueSourceSettings.ContainsKey(field.PreValueSourceId))
                {
                    var prvParsed = ParseSettings(field.PreValueSource.Type.Settings(), field.PreValueSource.Settings, item);
                    if (prvParsed.Count > 0)
                    {
                        item.PrevalueSourceSettings.Add(field.PreValueSourceId, prvParsed);
                    }

                    item.Resources.Add(formsDataLocation + "/prevalueSources/" + field.PreValueSourceId + ".json");
                }
            }



            //parse data source settings
            if (form.HasDataSource())
            {
                using (var dss = new Umbraco.Forms.Data.Storage.DataSourceStorage())
                {
                    var dataSource = dss.GetDataSource(form.DataSource.Id);

                    if (dataSource != null)
                    {
                        var dsParsed = ParseSettings(dataSource.Type.Settings(), dataSource.Settings, item);

                        if (dsParsed.Count > 0)
                        {
                            item.DataSourceSettings = dsParsed;
                        }

                        //add as file to item
                        item.Resources.Add(formsDataLocation + "/datasources/" + form.DataSource.Id.ToString() + ".json");
                    }
                }
            }

            //Parse workflow settings
            if (form.WorkflowIds.Count > 0)
            {
                using (var wfs = new Umbraco.Forms.Data.Storage.WorkflowStorage())
                {
                    foreach (var wfId in form.WorkflowIds)
                    {
                        var workflow = wfs.GetWorkflow(wfId);
                        if (workflow != null)
                        {
                            var wfParsed = ParseSettings(workflow.Type.Settings(), workflow.Settings, item);
                            if (wfParsed.Count > 0)
                            {
                                item.WorkflowSettings.Add(wfId, wfParsed);
                            }

                            //add file to item
                            item.Resources.Add(formsDataLocation + "/workflows/" + wfId.ToString() + ".json");
                        }
                    }
                }
            }

            return(item);
        }