public void SetPackageTest()
        {
            PageInstanceCollection pic;
            PageInstance           pi;
            Package package;


            //
            // Setup the test.
            //
            package = new Package();
            pic     = new PageInstanceCollection(null);
            pi      = new PageInstance();
            pic.Add(pi);

            //
            // Run the test.
            //
            pic.Owner = package;

            //
            // Verify the test.
            //
            Assert.AreSame(package, pi.Package);
        }
        public void RemoveItemTest()
        {
            PageInstanceCollection pic;
            PageInstance           pi;
            Package package;


            //
            // Setup the test.
            //
            package = new Package();
            pic     = new PageInstanceCollection(package);
            pi      = new PageInstance();
            pic.Add(pi);

            //
            // Run the test.
            //
            pic.Remove(pi);

            //
            // Verify the test.
            //
            Assert.AreEqual(null, pi.Package);
            Assert.AreEqual(0, pic.Count);
        }
Exemplo n.º 3
0
        protected override void OnInit(EventArgs e)
        {
            try
            {
                typeId = null;
                if (string.IsNullOrWhiteSpace(typeId))
                {
                    typeId = PageParameter("typeId");
                }

                entity = "Rock.Core.DefinedValue";
                entityQualifierColumn = "DefinedTypeId";
                canConfigure          = PageInstance.Authorized("Configure", CurrentUser);

                BindFilter();

                if (canConfigure)
                {
                    //assign types grid actions
                    rGridType.DataKeyNames            = new string[] { "id" };
                    rGridType.GridRebind             += new GridRebindEventHandler(rGridType_GridRebind);
                    rGridType.Actions.EnableAdd       = true;
                    rGridType.Actions.ClientAddScript = "editType(0)";

                    //assign type values grid actions
                    rGridValue.DataKeyNames            = new string[] { "id" };
                    rGridValue.GridRebind             += new GridRebindEventHandler(rGridValue_GridRebind);
                    rGridValue.Actions.EnableAdd       = true;
                    rGridValue.Actions.ClientAddScript = "editValue(0)";

                    //assign attributes grid actions
                    rGridAttribute.DataKeyNames            = new string[] { "id" };
                    rGridAttribute.GridRebind             += new GridRebindEventHandler(rGridAttribute_GridRebind);
                    rGridAttribute.Actions.EnableAdd       = true;
                    rGridAttribute.Actions.ClientAddScript = "editAttribute(0)";

                    string script = string.Format(@"
                        Sys.Application.add_load(function () {{
                            $('td.grid-icon-cell.delete a').click(function(){{
                                return confirm('Are you sure you want to delete this setting?');
                            }});
                        }});
                    ", rGridType.ClientID);

                    this.Page.ClientScript.RegisterStartupScript(this.GetType(), string.Format("grid-confirm-delete-{0}", rGridValue.ClientID), script, true);
                }
                else
                {
                    DisplayError("You are not authorized to configure this page");
                }
            }
            catch (SystemException ex)
            {
                DisplayError(ex.Message);
            }

            base.OnInit(e);
        }
        public static void CutImage(DataPool pool, Field sourceField, Document targetDocument)
        {
            if (sourceField.State == DataState.Empty)
            {
                return;
            }
            if (sourceField.Zone.Height == 0 && sourceField.Zone.Width == 0)
            {
                return;
            }
            OCCSinglePage pageRef = null;
            OCCSinglePage pageOcr = null;

            foreach (ImageSource ims in sourceField.ParentDocument.Sources)
            {
                if (ims.Url != sourceField.Sources[0].Url)
                {
                    continue;
                }
                pageRef = new OCCSinglePage(ims.SelectInstance("ref").Url,
                                            (ims.SelectInstance("ref") as ImageVariantInstance).Orientation);
                pageOcr = new OCCSinglePage(ims.SelectInstance("ocr").Url,
                                            (ims.SelectInstance("ocr") as ImageVariantInstance).Orientation);
            }

            byte[] tmpImageRef = pageRef.GetSnippet(sourceField.Zone);
            byte[] tmpImageOcr = pageOcr.GetSnippet(sourceField.Zone);
            string name        = sourceField.Name;
            string extension   = "tif";
            string cacheFolder = DataPool.CacheFolder;

            // Save image twice
            // 1) als original
            string destFileName = Path.Combine(cacheFolder, String.Format("{0}.{1}", name, extension));

            File.WriteAllBytes(destFileName, tmpImageRef);
            string destFileNameRef = Path.Combine(cacheFolder, String.Format("{0}_REF.{1}", name, extension));

            File.WriteAllBytes(destFileNameRef, tmpImageRef);
            // 2) als default ("ocr") to bring it into the PDF
            string destFileNameOcr = Path.Combine(cacheFolder, String.Format("{0}_OCR.{1}", name, extension));

            File.WriteAllBytes(destFileNameOcr, tmpImageOcr);

            ImageSourceInstance instance = new ImageSourceInstance(targetDocument.OwnerDataPool, destFileName);

            targetDocument.OwnerDataPool.RootNode.SourceInstances.Add(instance);
            PageInstance         pageInstance = instance.CreatePageInstance(1);
            ImageVariantInstance variantRef   = new ImageVariantInstance(targetDocument.OwnerDataPool, destFileNameRef);

            variantRef.VariantName = "ref";
            pageInstance.Variants.Add(variantRef);
            ImageVariantInstance varianOcr = new ImageVariantInstance(targetDocument.OwnerDataPool, destFileNameOcr);

            varianOcr.VariantName = "ocr";
            pageInstance.Variants.Add(varianOcr);
            targetDocument.Sources.Add(pageInstance.GetSource());
        }
Exemplo n.º 5
0
        protected override void OnInit(EventArgs e)
        {
            try
            {
                int pageId = Convert.ToInt32(PageParameter("EditPage"));
                _page = Rock.Web.Cache.Page.Read(pageId);

                if (_page != null)
                {
                    canConfigure = _page.Authorized("Configure", CurrentUser);
                }
                else
                {
                    canConfigure = PageInstance.Authorized("Configure", CurrentUser);
                }

                if (canConfigure)
                {
                    rGrid.DataKeyNames      = new string[] { "id" };
                    rGrid.Actions.EnableAdd = true;
                    rGrid.Actions.AddClick += rGrid_GridAdd;
                    rGrid.GridReorder      += new GridReorderEventHandler(rGrid_GridReorder);
                    rGrid.GridRebind       += new GridRebindEventHandler(rGrid_GridRebind);

                    string script = string.Format(@"
        Sys.Application.add_load(function () {{
            $('td.grid-icon-cell.delete a').click(function(){{
                return confirm('Are you sure you want to delete this page?');
                }});
        }});
    ", rGrid.ClientID);

                    this.Page.ClientScript.RegisterStartupScript(this.GetType(), string.Format("grid-confirm-delete-{0}", rGrid.ClientID), script, true);
                }
                else
                {
                    DisplayError("You are not authorized to configure this page");
                }
            }
            catch (SystemException ex)
            {
                DisplayError(ex.Message);
            }

            base.OnInit(e);
        }