/// <summary>
        /// Handles the Click event of the lbImport control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void lbImport_Click(object sender, EventArgs e)
        {
            if (!fuImport.BinaryFileId.HasValue || !cpImportCategory.SelectedValueAsId().HasValue)
            {
                return;
            }

            using (var rockContext = new RockContext())
            {
                var binaryFileService = new BinaryFileService(rockContext);
                var binaryFile        = binaryFileService.Get(fuImport.BinaryFileId ?? 0);
                var categoryService   = new CategoryService(rockContext);

                var           container = Newtonsoft.Json.JsonConvert.DeserializeObject <ExportedEntitiesContainer>(binaryFile.ContentsToString());
                List <string> messages;

                var decoder = new EntityDecoder(new RockContext());
                decoder.UserValues.Add("WorkflowCategory", categoryService.Get(cpImportCategory.SelectedValueAsId().Value));

                var success = decoder.Import(container, cbDryRun.Checked, out messages);

                ltImportResults.Text = string.Empty;
                foreach (var msg in messages)
                {
                    ltImportResults.Text += string.Format("{0}\n", msg.EncodeHtml());
                }

                pnlImportResults.Visible = true;

                if (success)
                {
                    fuImport.BinaryFileId = null;
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Parses the entity at the current position.
        /// Assumes that there is a <c>&amp;</c> at the current position.
        /// </summary>
        private static string ParseEntity(Subject subj)
        {
            int    match;
            string entity;
            int    numericEntity;
            var    origPos = subj.Position;

            match = Scanner.scan_entity(subj.Buffer, subj.Position, subj.Length - subj.Position, out entity, out numericEntity);
            if (match > 0)
            {
                subj.Position += match;

                if (entity != null)
                {
                    entity = EntityDecoder.DecodeEntity(entity);
                    if (entity != null)
                    {
                        return(entity);
                    }

                    return(subj.Buffer.Substring(origPos, match));
                }
                else if (numericEntity > 0)
                {
                    entity = EntityDecoder.DecodeEntity(numericEntity);
                    if (entity != null)
                    {
                        return(entity);
                    }
                }

                return("\uFFFD");
            }
            else
            {
                subj.Position++;
                return("&");
            }
        }
Exemple #3
0
        protected void mdImport_SaveClick(object sender, EventArgs e)
        {
            if (!fImport.BinaryFileId.HasValue)
            {
                return;
            }

            using (var rockContext = new RockContext())
            {
                var binaryFileService = new BinaryFileService(rockContext);
                var binaryFile        = binaryFileService.Get(fImport.BinaryFileId ?? 0);
                var categoryService   = new CategoryService(rockContext);

                var           container = Newtonsoft.Json.JsonConvert.DeserializeObject <ExportedEntitiesContainer>(binaryFile.ContentsToString());
                List <string> messages;

                var decoder = new EntityDecoder(new RockContext());
                //decoder.UserValues.Add( "EntityTypes",  ddlEntityType );

                var success = decoder.Import(container, false, out messages);

                nbImport.Text = string.Empty;
                foreach (var msg in messages)
                {
                    nbImport.Text += string.Format("{0}<br>", msg.EncodeHtml());
                }

                nbImport.Visible = true;

                if (success)
                {
                    fImport.BinaryFileId = null;
                }

                mdImport.Hide();
                BindGrid();
            }
        }
Exemple #4
0
        /// <summary>
        /// Destructively unescape a string: remove backslashes before punctuation or symbol characters.
        /// </summary>
        /// <param name="url">The string data that will be changed by unescaping any punctuation or symbol characters.</param>
        public static string Unescape(string url)
        {
            // remove backslashes before punctuation chars:
            int  searchPos = 0;
            int  lastPos   = 0;
            int  match;
            char c;

            char[]        search = new[] { '\\', '&' };
            StringBuilder sb     = null;

            while ((searchPos = url.IndexOfAny(search, searchPos)) != -1)
            {
                c = url[searchPos];
                if (c == '\\')
                {
                    searchPos++;

                    if (url.Length == searchPos)
                    {
                        break;
                    }

                    c = url[searchPos];
                    if (Utilities.IsEscapableSymbol(c))
                    {
                        if (sb == null)
                        {
                            sb = new StringBuilder(url.Length);
                        }
                        sb.Append(url, lastPos, searchPos - lastPos - 1);
                        lastPos = searchPos;
                    }
                }
                else if (c == '&')
                {
                    string namedEntity;
                    int    numericEntity;
                    match = Scanner.scan_entity(url, searchPos, url.Length - searchPos, out namedEntity, out numericEntity);
                    if (match == 0)
                    {
                        searchPos++;
                    }
                    else
                    {
                        searchPos += match;

                        if (namedEntity != null)
                        {
                            var decoded = EntityDecoder.DecodeEntity(namedEntity);
                            if (decoded != null)
                            {
                                if (sb == null)
                                {
                                    sb = new StringBuilder(url.Length);
                                }
                                sb.Append(url, lastPos, searchPos - match - lastPos);
                                sb.Append(decoded);
                                lastPos = searchPos;
                            }
                        }
                        else if (numericEntity > 0)
                        {
                            var decoded = EntityDecoder.DecodeEntity(numericEntity);
                            if (decoded != null)
                            {
                                if (sb == null)
                                {
                                    sb = new StringBuilder(url.Length);
                                }
                                sb.Append(url, lastPos, searchPos - match - lastPos);
                                sb.Append(decoded);
                            }
                            else
                            {
                                if (sb == null)
                                {
                                    sb = new StringBuilder(url.Length);
                                }
                                sb.Append(url, lastPos, searchPos - match - lastPos);
                                sb.Append('\uFFFD');
                            }

                            lastPos = searchPos;
                        }
                    }
                }
            }

            if (sb == null)
            {
                return(url);
            }

            sb.Append(url, lastPos, url.Length - lastPos);
            return(sb.ToString());
        }
Exemple #5
0
        /// <summary>
        /// This method is called before the entity is saved and allows any final changes to the
        /// entity before it is stored in the database. Any Guid references that are not standard
        /// properties must also be updated, such as the Actions string of a WorkflowActionForm.
        /// </summary>
        /// <param name="entity">The in-memory entity that is about to be saved.</param>
        /// <param name="encodedEntity">The encoded information that was used to reconstruct the entity.</param>
        /// <param name="data">Custom data that was previously returned by ProcessExportedEntity.</param>
        /// <param name="helper">The helper in charge of the import process.</param>
        protected override void ProcessImportedEntity(WorkflowActionForm entity, EncodedEntity encodedEntity, object data, EntityDecoder helper)
        {
            if (data != null && data is string)
            {
                //
                // Update the Guids in all the action buttons.
                //
                List <string> actions = (( string )data).Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                for (int i = 0; i < actions.Count; i++)
                {
                    var details = actions[i].Split(new char[] { '^' });
                    if (details.Length > 2)
                    {
                        Guid definedValueGuid = details[1].AsGuid();
                        Guid?activityTypeGuid = details[2].AsGuidOrNull();

                        details[1] = helper.FindMappedGuid(definedValueGuid).ToString();
                        if (activityTypeGuid.HasValue)
                        {
                            details[2] = helper.FindMappedGuid(activityTypeGuid.Value).ToString();
                        }

                        actions[i] = string.Join("^", details);
                    }
                }

                entity.Actions = string.Join("|", actions);
            }
        }