コード例 #1
0
ファイル: Importer.cs プロジェクト: fire-eggs/GEDKeeper
        public bool LoadRawData(string fileName)
        {
            fRawContents.Clear();

            fFileName = fileName;
            string ext = SysUtils.GetFileExtension(fileName);

            if (ext == ".txt")
            {
                return(LoadRawText());
            }
            else if (ext == ".doc")
            {
                #if !NO_DEPEND
                return(LoadRawWord());
                #else
                return(false);
                #endif
            }
            else if (ext == ".xls")
            {
                #if !NO_DEPEND
                return(LoadRawExcel());
                #else
                return(false);
                #endif
            }
            else
            {
                throw new ImporterException(fLangMan.LS(ILS.LSID_FormatUnsupported));
            }
        }
コード例 #2
0
        public override void Generate(bool show)
        {
            if (fRoot == null)
            {
                AppHost.StdDialogs.ShowError(LangMan.LS(LSID.LSID_NotSelectedPerson));
                return;
            }

            string availableFormats = LangMan.LS(LSID.LSID_HTMLFilter) + "|" + LangMan.LS(LSID.LSID_RTFFilter);

            availableFormats += "|" + LangMan.LS(LSID.LSID_PDFFilter);

            fPath = AppHost.StdDialogs.GetSaveFile(availableFormats);
            if (string.IsNullOrEmpty(fPath))
            {
                return;
            }

            string ext = SysUtils.GetFileExtension(fPath);

            CustomWriter writer;

            if (string.Equals(ext, ".html"))
            {
                writer = new HTMLWriter();
            }
            else if (string.Equals(ext, ".rtf"))
            {
                writer = new RTFWriter();
            }
            else
            {
                writer = new PDFWriter();
            }

            bool success = Generate(writer);

            #if !CI_MODE
            if (!success)
            {
                AppHost.StdDialogs.ShowError(LangMan.LS(LSID.LSID_GenerationFailed));
            }
            else
            {
                if (show)
                {
                    ShowResult();
                }
            }
            #endif
        }
コード例 #3
0
        public static GEDCOMMultimediaFormat RecognizeFormat(string fileName)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                return(GEDCOMMultimediaFormat.mfUnknown);
            }

            string ext = SysUtils.GetFileExtension(fileName);

            if (!string.IsNullOrEmpty(ext) && ext[0] == '.')
            {
                ext = ext.Remove(0, 1);
            }

            GEDCOMMultimediaFormat result = GEDCOMUtils.GetMultimediaFormatVal(ext);

            return(result);
        }
コード例 #4
0
        /* TODO(zsv): Need to find an appropriate icon in the general style
         * for the main toolbar - screenshot capture for windows with charts. */
        public void SaveSnapshot(string fileName)
        {
            string ext = SysUtils.GetFileExtension(fileName);

            ExtSize imageSize = GetImageSize();

            if ((ext == ".bmp" || ext == ".jpg") && imageSize.Width >= 65535)
            {
                AppHost.StdDialogs.ShowError(LangMan.LS(LSID.LSID_TooMuchWidth));
            }
            else
            {
                ImageFormat imFmt = ImageFormat.Png;
                if (ext == ".bmp")
                {
                    imFmt = ImageFormat.Bitmap;
                }

                /*else
                 *  if (ext == ".emf") { imFmt = ImageFormat.Emf; }*/
                else
                if (ext == ".png")
                {
                    imFmt = ImageFormat.Png;
                }
                else
                if (ext == ".gif")
                {
                    imFmt = ImageFormat.Gif;
                }
                else
                if (ext == ".jpg")
                {
                    imFmt = ImageFormat.Jpeg;
                }

                /*Image pic;
                 * if (Equals(imFmt, ImageFormat.Emf)) {
                 *  using (var gfx = CreateGraphics()) {
                 *      pic = new Metafile(fileName, gfx.GetHdc());
                 *  }
                 * } else {
                 *  pic = new Bitmap(imageSize.Width, imageSize.Height, PixelFormat.Format24bppRgb);
                 * }*/
                Bitmap pic = new Bitmap(imageSize.Width, imageSize.Height, PixelFormat.Format24bppRgb);

                try
                {
                    //using (Graphics gfx = Graphics.FromImage(pic)) {
                    using (Graphics gfx = new Graphics(pic)) {
                        RenderStaticImage(gfx, false);
                    }

                    ((Bitmap)pic).Save(fileName, imFmt);
                }
                finally
                {
                    pic.Dispose();
                }
            }
        }
コード例 #5
0
        public void SysUtils_Tests()
        {
            #if __MonoCS__
            Assert.IsTrue(SysUtils.IsUnix());
            Assert.AreEqual(PlatformID.Unix, SysUtils.GetPlatformID());
            Assert.IsFalse(string.IsNullOrEmpty(SysUtils.GetMonoVersion()));
            Assert.AreNotEqual(DesktopType.Windows, SysUtils.GetDesktopType());
            #else
            Assert.IsFalse(SysUtils.IsUnix());
            Assert.AreEqual(PlatformID.Win32NT, SysUtils.GetPlatformID());
            Assert.IsTrue(string.IsNullOrEmpty(SysUtils.GetMonoVersion()));
            Assert.AreEqual(DesktopType.Windows, SysUtils.GetDesktopType());
            #endif

            //

            Assert.IsTrue(SysUtils.IsUnicodeEncoding(Encoding.UTF8));
            Assert.IsFalse(SysUtils.IsUnicodeEncoding(Encoding.ASCII));

            //

            int days = SysUtils.DaysBetween(new DateTime(1990, 10, 10), new DateTime(1990, 10, 13));
            Assert.AreEqual(3, days);

            days = SysUtils.DaysBetween(new DateTime(1990, 10, 10), new DateTime(1990, 10, 02));
            Assert.AreEqual(-8, days);

            Assert.AreEqual(31, SysUtils.DaysInAMonth(1990, 5));

            //

            Assert.AreEqual(true, SysUtils.IsSetBit(3, 0));
            Assert.AreEqual(true, SysUtils.IsSetBit(3, 1));
            Assert.AreEqual(false, SysUtils.IsSetBit(3, 4));

            //

            Assert.AreEqual(495, SysUtils.Trunc(495.575));

            Assert.AreEqual(3.0f, SysUtils.SafeDiv(9.0f, 3.0f));
            Assert.AreEqual(0.0f, SysUtils.SafeDiv(9.0f, 0.0f));

            //

            Assert.Throws(typeof(ArgumentNullException), () => { SysUtils.FirstOrDefault <int>(null); });
            int N = SysUtils.FirstOrDefault(new int[] { 5, 7, 10 });
            Assert.AreEqual(5, N);

            Assert.Throws(typeof(ArgumentNullException), () => { SysUtils.LastOrDefault <int>(null); });
            N = SysUtils.LastOrDefault(new int[] { 5, 7, 10 });
            Assert.AreEqual(10, N);

            // other
            string st = "ivan";
            st = SysUtils.NormalizeName(st);
            Assert.AreEqual("Ivan", st);

            st = SysUtils.NormalizeName(null);
            Assert.AreEqual("", st);

            //
            Assert.AreEqual("", SysUtils.GetFileExtension("testfile"));
            Assert.AreEqual(".ext", SysUtils.GetFileExtension("testfile.eXt"));

            Assert.IsFalse(SysUtils.IsRemovableDrive(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)));

            Assembly asm   = this.GetType().Assembly;
            var      attr1 = SysUtils.GetAssemblyAttribute <AssemblyTitleAttribute>(asm);
            Assert.IsNotNull(attr1);
            Assert.AreEqual("GKTests", attr1.Title);

            Assert.Throws(typeof(ArgumentNullException), () => { SysUtils.GetAssemblyAttribute <AssemblyTitleAttribute>(null); });
        }
コード例 #6
0
ファイル: CustomChart.cs プロジェクト: fire-eggs/GEDKeeper
        /* TODO(zsv): Need to find an appropriate icon in the general style
         * for the main toolbar - screenshot capture for windows with charts. */
        public void SaveSnapshot(string fileName)
        {
            string ext = SysUtils.GetFileExtension(fileName);

            ExtSize imageSize = GetImageSize();

            if (ext == ".svg")
            {
                try {
                    SetSVGMode(true, fileName, imageSize.Width, imageSize.Height);

                    using (var gfx = CreateGraphics()) {
                        RenderStaticImage(gfx, OutputType.SVG);
                    }
                } finally {
                    SetSVGMode(false, "", 0, 0);
                }

                return;
            }

            if ((ext == ".bmp" || ext == ".jpg") && imageSize.Width >= 65535)
            {
                AppHost.StdDialogs.ShowError(LangMan.LS(LSID.LSID_TooMuchWidth));
            }
            else
            {
                ImageFormat imFmt = ImageFormat.Png;
                if (ext == ".bmp")
                {
                    imFmt = ImageFormat.Bmp;
                }
                else
                if (ext == ".emf")
                {
                    imFmt = ImageFormat.Emf;
                }
                else
                if (ext == ".png")
                {
                    imFmt = ImageFormat.Png;
                }
                else
                if (ext == ".gif")
                {
                    imFmt = ImageFormat.Gif;
                }
                else
                if (ext == ".jpg")
                {
                    imFmt = ImageFormat.Jpeg;
                }

                Image pic;
                if (Equals(imFmt, ImageFormat.Emf))
                {
                    using (var gfx = CreateGraphics()) {
                        pic = new Metafile(fileName, gfx.GetHdc());
                    }
                }
                else
                {
                    pic = new Bitmap(imageSize.Width, imageSize.Height, PixelFormat.Format24bppRgb);
                }

                try
                {
                    using (Graphics gfx = Graphics.FromImage(pic)) {
                        RenderStaticImage(gfx, OutputType.StdFile);
                    }

                    pic.Save(fileName, imFmt);
                }
                finally
                {
                    pic.Dispose();
                }
            }
        }