Exemplo n.º 1
0
        private ProtectedBinary OpenBinaryDataLegacy(string name, ProtectedBinary binary)
        {
            ProtectedBinary modifiedData = null;

            var data = binary.ReadData();

            var dataClass = BinaryDataClassifier.Classify(name, data);

            if (DataEditorForm.SupportsDataType(dataClass))
            {
                var editor = new DataEditorForm();
                editor.InitEx(name, data);
                editor.ShowDialog();

                if (editor.EditedBinaryData != null)
                {
                    modifiedData = new ProtectedBinary(binary.IsProtected, editor.EditedBinaryData);
                }

                UIUtil.DestroyForm(editor);
            }
            else
            {
                var viewer = new DataViewerForm();
                viewer.InitEx(name, data);
                UIUtil.ShowDialogAndDestroy(viewer);
            }

            return(modifiedData);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Show the datatable content on a form
 /// </summary>
 /// <param name="dt">Datatable</param>
 public static void Show(this DataTable dt)
 {
     try
     {
         DataViewerForm DVF = new DataViewerForm();
         DVF.Data = dt;
         DVF.ShowDialog();
     }
     catch
     {
     }
 }
Exemplo n.º 3
0
        private static BinaryDataHandler ChooseHandler(string strName,
                                                       byte[] pbData, BinaryDataOpenOptions opt)
        {
            BinaryDataClass bdc = BinaryDataClassifier.Classify(strName, pbData);

            if (DataEditorForm.SupportsDataType(bdc) && !opt.ReadOnly)
            {
                return(BinaryDataHandler.InternalEditor);
            }

            if (DataViewerForm.SupportsDataType(bdc))
            {
                return(BinaryDataHandler.InternalViewer);
            }

            return(BinaryDataHandler.ExternalApp);
        }
Exemplo n.º 4
0
        public static ProtectedBinary Open(string strName, ProtectedBinary pb,
                                           BinaryDataOpenOptions opt)
        {
            if (string.IsNullOrEmpty(strName))
            {
                Debug.Assert(false); return(null);
            }
            if (pb == null)
            {
                Debug.Assert(false); return(null);
            }
            if (opt == null)
            {
                opt = new BinaryDataOpenOptions();
            }

            byte[] pbData = pb.ReadData();
            if (pbData == null)
            {
                Debug.Assert(false); return(null);
            }

            BinaryDataHandler h = opt.Handler;

            if (h == BinaryDataHandler.Default)
            {
                h = ChooseHandler(strName, pbData, opt);
            }

            byte[] pbModData = null;
            if (h == BinaryDataHandler.InternalViewer)
            {
                DataViewerForm dvf = new DataViewerForm();
                dvf.InitEx(strName, pbData);
                UIUtil.ShowDialogAndDestroy(dvf);
            }
            else if (h == BinaryDataHandler.InternalEditor)
            {
                DataEditorForm def = new DataEditorForm();
                def.InitEx(strName, pbData);
                def.ShowDialog();

                if (def.EditedBinaryData != null)
                {
                    pbModData = def.EditedBinaryData;
                }

                UIUtil.DestroyForm(def);
            }
            else if (h == BinaryDataHandler.ExternalApp)
            {
                pbModData = OpenExternal(strName, pbData, opt);
            }
            else
            {
                Debug.Assert(false);
            }

            if ((pbModData != null) && !MemUtil.ArraysEqual(pbData, pbModData) &&
                !opt.ReadOnly)
            {
                return(new ProtectedBinary(pb.IsProtected, pbModData));
            }
            return(null);
        }
Exemplo n.º 5
0
        public static ProtectedBinary Open(string strName, ProtectedBinary pb,
                                           BinaryDataOpenOptions opt)
        {
            if (string.IsNullOrEmpty(strName))
            {
                Debug.Assert(false); return(null);
            }
            if (pb == null)
            {
                Debug.Assert(false); return(null);
            }
            if (opt == null)
            {
                opt = new BinaryDataOpenOptions();
            }

            byte[] pbData = pb.ReadData();
            if (pbData == null)
            {
                Debug.Assert(false); return(null);
            }

            BinaryDataHandler h = opt.Handler;

            if (h == BinaryDataHandler.Default)
            {
                h = ChooseHandler(strName, pbData, opt);
            }

            byte[] pbModData = null;
            if (h == BinaryDataHandler.InternalViewer)
            {
                DataViewerForm dvf = new DataViewerForm();
                dvf.InitEx(strName, pbData);
                UIUtil.ShowDialogAndDestroy(dvf);
            }
            else if (h == BinaryDataHandler.InternalEditor)
            {
                DataEditorForm def = new DataEditorForm();
                def.InitEx(strName, pbData);
                def.ShowDialog();

                if (def.EditedBinaryData != null)
                {
                    pbModData = def.EditedBinaryData;
                }

                UIUtil.DestroyForm(def);
            }
            else if (h == BinaryDataHandler.ExternalApp)
            {
                pbModData = OpenExternal(strName, pbData, opt);
            }
            else
            {
                Debug.Assert(false);
            }

            ProtectedBinary r = null;

            if ((pbModData != null) && !MemUtil.ArraysEqual(pbData, pbModData) &&
                !opt.ReadOnly)
            {
                if (FileDialogsEx.CheckAttachmentSize(pbModData.LongLength,
                                                      KPRes.AttachFailed + MessageService.NewParagraph + strName))
                {
                    r = new ProtectedBinary(pb.IsProtected, pbModData);
                }
            }

            if (pb.IsProtected)
            {
                MemUtil.ZeroByteArray(pbData);
            }
            return(r);
        }