예제 #1
0
        public int Split(string filename, string password)
        {
            var src  = GetSource(filename);
            var info = IO.Get(src);
            var name = info.BaseName;
            var ext  = info.Extension;
            var dest = Path(Args(name));

            IO.Copy(src, IO.Combine(dest, $"{name}-01{ext}"), true);

            using (var w = new DocumentSplitter(IO))
            {
                var op = new OpenOption {
                    SaveMemory = false
                };
                w.Add(new DocumentReader(src, password, op));
                w.Save(dest);

                var n   = w.Results.Count;
                var cmp = IO.GetFiles(dest).Length;
                Assert.That(cmp, Is.EqualTo(n + 1));
                Assert.That(IO.Exists(IO.Combine(dest, $"{name}-01 (1){ext}")));

                w.Reset();
                Assert.That(w.Results.Count, Is.EqualTo(0));

                return(n);
            }
        }
예제 #2
0
        public static OpenOption[] ConvertOpenMode(OpenMode mode)
        {
            OpenOption[] options;
            switch (mode.innerEnumValue)
            {
            case Org.Neo4j.Io.fs.OpenMode.InnerEnum.READ:
                options = new OpenOption[] { READ };
                break;

            case Org.Neo4j.Io.fs.OpenMode.InnerEnum.READ_WRITE:
                options = new OpenOption[] { CREATE, READ, WRITE };
                break;

            case Org.Neo4j.Io.fs.OpenMode.InnerEnum.SYNC:
                options = new OpenOption[] { CREATE, READ, WRITE, SYNC };
                break;

            case Org.Neo4j.Io.fs.OpenMode.InnerEnum.DSYNC:
                options = new OpenOption[] { CREATE, READ, WRITE, DSYNC };
                break;

            default:
                throw new System.ArgumentException("Unsupported mode: " + mode);
            }
            return(options);
        }
예제 #3
0
        public int Attach(string doc, string file)
        {
            var op = new OpenOption {
                SaveMemory = false
            };
            var src  = GetSource(doc);
            var r0   = new DocumentReader(src, "", op);
            var r1   = IO.Get(GetSource(file));
            var dest = Path(Args(r0.File.BaseName, r1.BaseName));

            using (var w = new DocumentWriter())
            {
                w.Add(r0);
                w.Add(r0.Attachments);
                w.Attach(new Attachment(r1.FullName, IO));
                w.Attach(new Attachment(r1.FullName, IO)); // Skip duplicated object.
                w.Save(dest);
            }

            using (var r = new DocumentReader(dest, "", op))
            {
                var items = r.Attachments;
                Assert.That(items.Any(x => x.Name.FuzzyEquals(file)), Is.True);
                foreach (var obj in items)
                {
                    Assert.That(obj.Length, Is.AtLeast(1));
                }
                return(items.Count());
            }
        }
예제 #4
0
        public void Rotate_Failed()
        {
            var src  = GetSource("Sample.pdf");
            var dest = Path(Args("Sample"));
            var op   = new OpenOption {
                SaveMemory = false
            };
            var degree = 90;

            using (var w = new DocumentWriter(IO))
            {
                var r = new DocumentReader(src, "", op);

                w.UseSmartCopy = true;
                w.Set(r.Metadata);
                w.Set(r.Encryption);
                w.Add(Rotate(r.Pages, degree), r);
                w.Save(dest);
            }

            using (var r = new DocumentReader(dest))
            {
                foreach (var page in r.Pages)
                {
                    Assert.That(page.Rotation, Is.Not.EqualTo(degree));
                }
            }
        }
예제 #5
0
        public static void log(string message, string extra, bool newLine, int index, bool time)
        {
            int num = (int)newLine;

            try
            {
                extra = new StringBuilder().append("{").append(new SimpleDateFormat("MM/dd|HH:mm:ss").format(Calendar.getInstance().getTime())).append("}=> ").append(extra).append(": ").toString();
                System.get_out().println(new StringBuilder().append(extra).append(message).toString());
                if (file_logging)
                {
                    File file = new File(new StringBuilder().append(log_path).append(file_name).append((index > 0) ? Integer.valueOf(index) : "").append(".log").toString());
                    if (!file.exists())
                    {
                        File.__ <clinit>();
                        new File(log_path).mkdirs();
                        file.createNewFile();
                    }
                    OpenOption[] optionArray1 = new OpenOption[] { StandardOpenOption.APPEND };
                    Files.write(file.toPath(), String.instancehelper_getBytes(new StringBuilder().append(extra).append(message).append((num == 0) ? "" : "\r\n").toString(), "utf-8"), optionArray1);
                }
            }
            catch (Exception exception1)
            {
                if (ByteCodeHelper.MapException <Exception>(exception1, 2) == null)
                {
                    throw;
                }
                return;
            }
        }
예제 #6
0
        /* ----------------------------------------------------------------- */
        ///
        /// ExtractImages
        ///
        /// <summary>
        /// Extracts images from the specified PDF document.
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        private KeyValuePair <int, int> ExtractImages(IProgress <Message <int> > progress)
        {
            var query   = new Query <string>(e => throw new NotSupportedException());
            var options = new OpenOption {
                IO = IO, FullAccess = true
            };

            using (var reader = new DocumentReader(Source, query, options))
            {
                ExtractImages(reader, progress);
                return(KeyValuePair.Create(reader.Pages.Count(), _core.Count));
            }
        }
예제 #7
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public static java.io.OutputStream openAsOutputStream(java.nio.file.Path path, boolean append) throws java.io.IOException
        public static Stream OpenAsOutputStream(Path path, bool append)
        {
            OpenOption[] options;
            if (append)
            {
                options = new OpenOption[] { CREATE, WRITE, APPEND };
            }
            else
            {
                options = new OpenOption[] { CREATE, WRITE };
            }
            return(Files.newOutputStream(path, options));
        }
예제 #8
0
        /* ----------------------------------------------------------------- */
        ///
        /// Create
        ///
        /// <summary>
        /// Creates a new instance of the DocumentRenderer class with the
        /// specified arguments.
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        private DocumentRenderer Create(string src, string password)
        {
            var opt = new OpenOption {
                IO = _io, FullAccess = true
            };
            var dest = password.HasValue() ?
                       new DocumentRenderer(src, password, opt) :
                       new DocumentRenderer(src, _query(), opt);

            dest.RenderOption.Background = Color.White;
            dest.RenderOption.Annotation = true;
            return(dest);
        }
예제 #9
0
        /* ----------------------------------------------------------------- */
        ///
        /// Add
        ///
        /// <summary>
        /// Adds the collection of Pages to the specified writer.
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        private void Add(DocumentWriter src, string path, SaveOption so)
        {
            var io    = Settings.IO;
            var value = Settings.Value;

            if (value.SaveOption != so || !io.Exists(path))
            {
                return;
            }

            var options = new OpenOption {
                IO = io, SaveMemory = true
            };
            var password = value.Encryption.Enabled ?
                           value.Encryption.OwnerPassword :
                           string.Empty;

            src.Add(new DocumentReader(path, password, options));
        }
예제 #10
0
        public int Merge_Image(string doc, string image, int degree)
        {
            var op = new OpenOption {
                SaveMemory = false
            };
            var r0   = new DocumentReader(GetSource(doc), "", op);
            var dest = Path(Args(r0.File.BaseName, IO.Get(image).BaseName));

            using (var w = new DocumentWriter(IO))
                using (var r = new DocumentReader(GetSource(doc), "", op))
                {
                    foreach (var p in r0.Pages)
                    {
                        w.Add(Rotate(p, degree));
                    }
                    w.Add(Rotate(IO.GetImagePages(GetSource(image)), degree));
                    w.Save(dest);
                }
            return(Count(dest, "", degree));
        }
예제 #11
0
        public int Merge(string f0, string f1, int degree)
        {
            var op = new OpenOption {
                SaveMemory = false
            };
            var r0   = new DocumentReader(GetSource(f0), "", op);
            var r1   = new DocumentReader(GetSource(f1), "", op);
            var dest = Path(Args(r0.File.BaseName, r1.File.BaseName));

            using (var w = new DocumentWriter(IO))
            {
                foreach (var p in r0.Pages)
                {
                    w.Add(Rotate(p, degree), r0);
                }
                w.Add(Rotate(r1.Pages, degree), r1);
                w.Save(dest);
            }
            return(Count(dest, "", degree));
        }
예제 #12
0
        public int Overwrite(string filename, string password, int degree)
        {
            var dest = Path(Args(filename));

            IO.Copy(GetSource(filename), dest, true);

            var op = new OpenOption {
                SaveMemory = false
            };
            var r = new DocumentReader(dest, password, op);

            using (var w = new DocumentWriter(IO))
            {
                w.UseSmartCopy = false;
                w.Set(r.Metadata);
                w.Set(r.Encryption);
                w.Add(Rotate(r.Pages, degree), r);
                w.Save(dest);
            }
            return(Count(dest, password, degree));
        }
예제 #13
0
        public void TestCalculatePLs()
        {
            OptionCombination optComb = new OptionCombination();

            OpenOption openOpt = new OpenOption();
            openOpt.ContractNo = 10;
            openOpt.PurchaseDate = new DateTime(2013, 05, 17);
            openOpt.PurchasePrice = 23.75m;
            openOpt.Option = new Option() { Symbol = "NFLX", IsCall = true, Strike = 250, ExpiryDate = new DateTime(2013, 09, 21) };
            optComb.Options.Add(openOpt);

            //openOpt = new OpenOption();
            //openOpt.ContractNo = -10;
            //openOpt.PurchaseDate = new DateTime(2013, 05, 17);
            //openOpt.PurchasePrice = 9.90m;
            //openOpt.Option = new Option() { Symbol = "NFLX", IsCall = true, Strike = 300, ExpiryDate = new DateTime(2013, 09, 21) };
            //optComb.Options.Add(openOpt);

            Calculator calculator = new Calculator();
            var plSerious = calculator.CalculatePLs(optComb, new DateTime(2013, 07, 01), 100m, 380m, 0.003m, 0.5);
        }
예제 #14
0
        public void SetEncryption(EncryptionMethod method, long permission)
        {
            var src  = GetSource("Sample.pdf");
            var dest = Path(Args(method, permission));
            var op   = new OpenOption {
                SaveMemory = false
            };
            var cmp = new Encryption
            {
                OwnerPassword    = "******",
                UserPassword     = "******",
                OpenWithPassword = true,
                Method           = method,
                Enabled          = true,
                Permission       = new Permission(permission),
            };

            using (var w = new DocumentWriter(IO))
            {
                w.Set(cmp);
                w.Add(new DocumentReader(src, "", op));
                w.Save(dest);
            }

            using (var r = new DocumentReader(dest, cmp.OwnerPassword))
            {
                Assert.That(r.Encryption.Enabled, Is.True);
                Assert.That(r.Encryption.OwnerPassword, Is.EqualTo(cmp.OwnerPassword));
                Assert.That(r.Encryption.Method, Is.EqualTo(cmp.Method));

                var x = r.Encryption.Permission;
                var y = cmp.Permission;
                Assert.That(x.Print, Is.EqualTo(y.Print), nameof(x.Print));
                Assert.That(x.CopyContents, Is.EqualTo(y.CopyContents), nameof(x.CopyContents));
                Assert.That(x.ModifyContents, Is.EqualTo(y.ModifyContents), nameof(x.ModifyContents));
                Assert.That(x.ModifyAnnotations, Is.EqualTo(y.ModifyAnnotations), nameof(x.ModifyAnnotations));
                Assert.That(x.InputForm, Is.EqualTo(y.InputForm), nameof(x.InputForm));
                Assert.That(x.Accessibility, Is.EqualTo(y.Accessibility), nameof(x.Accessibility));
            }
        }
예제 #15
0
        public void SetMetadata(string value)
        {
            var src  = GetSource("Sample.pdf");
            var dest = Path(Args(value));
            var op   = new OpenOption {
                SaveMemory = false
            };
            var cmp = new Metadata
            {
                Title    = value,
                Author   = value,
                Subject  = value,
                Keywords = value,
                Creator  = value,
                Producer = value,
                Version  = new PdfVersion(1, 5),
                Options  = ViewerOption.TwoColumnLeft,
            };

            using (var w = new DocumentWriter(IO))
            {
                w.Set(cmp);
                w.Add(new DocumentReader(src, "", op));
                w.Save(dest);
            }

            using (var r = new DocumentReader(dest, "", op))
            {
                var m = r.Metadata;
                Assert.That(m.Title, Is.EqualTo(cmp.Title), nameof(m.Title));
                Assert.That(m.Author, Is.EqualTo(cmp.Author), nameof(m.Author));
                Assert.That(m.Subject, Is.EqualTo(cmp.Subject), nameof(m.Subject));
                Assert.That(m.Keywords, Is.EqualTo(cmp.Keywords), nameof(m.Keywords));
                Assert.That(m.Creator, Is.EqualTo(cmp.Creator), nameof(m.Creator));
                Assert.That(m.Producer, Does.StartWith("iTextSharp"));
                Assert.That(m.Version.Major, Is.EqualTo(cmp.Version.Major));
                Assert.That(m.Version.Minor, Is.EqualTo(cmp.Version.Minor));
                Assert.That(m.Options, Is.EqualTo(cmp.Options));
            }
        }
예제 #16
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void mustCloseAllStoresIfNeoStoresFailToOpen()
        public virtual void MustCloseAllStoresIfNeoStoresFailToOpen()
        {
            PageCache              pageCache      = Rules.pageCache();
            DatabaseLayout         databaseLayout = Rules.directory().databaseLayout();
            Config                 config         = Config.defaults();
            FileSystemAbstraction  fs             = Rules.fileSystem();
            IdGeneratorFactory     idGenFactory   = new DefaultIdGeneratorFactory(fs);
            LogProvider            logProvider    = NullLogProvider.Instance;
            VersionContextSupplier versions       = EmptyVersionContextSupplier.EMPTY;
            RecordFormats          formats        = Standard.LATEST_RECORD_FORMATS;

            (new RecordFormatPropertyConfigurator(formats, config)).configure();
            bool create = true;

            StoreType[]  storeTypes  = StoreType.values();
            OpenOption[] openOptions = new OpenOption[0];
            NeoStores    neoStores   = new NeoStores(databaseLayout, config, idGenFactory, pageCache, logProvider, fs, versions, formats, create, storeTypes, openOptions);
            File         schemaStore = neoStores.SchemaStore.StorageFile;

            neoStores.Close();

            // Make the schema store inaccessible, to sabotage the next initialisation we'll do.
            assumeTrue(schemaStore.setReadable(false));
            assumeTrue(schemaStore.setWritable(false));

            try
            {
                // This should fail due to the permissions we changed above.
                // And when it fails, the already-opened stores should be closed.
                new NeoStores(databaseLayout, config, idGenFactory, pageCache, logProvider, fs, versions, formats, create, storeTypes, openOptions);
                fail("Opening NeoStores should have thrown.");
            }
            catch (Exception)
            {
            }

            // We verify that the successfully opened stores were closed again by the failed NeoStores open,
            // by closing the page cache, which will throw if not all files have been unmapped.
            pageCache.Close();
        }
예제 #17
0
        /* ----------------------------------------------------------------- */
        ///
        /// InvokeItext
        ///
        /// <summary>
        /// Invokes iTextSharp operations.
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        private void InvokeItext(string src)
        {
            var io    = Settings.IO;
            var value = Settings.Value;
            var tmp   = io.Combine(io.Get(src).DirectoryName, Guid.NewGuid().ToString("D"));

            using (var writer = new DocumentWriter(io))
            {
                value.Encryption.Method = GetEncryptionMethod(value.Metadata.Version);
                writer.Set(value.Metadata);
                writer.Set(value.Encryption);
                Add(writer, value.Destination, SaveOption.MergeTail);
                var options = new OpenOption {
                    IO = io, SaveMemory = false
                };
                writer.Add(new DocumentReader(src, string.Empty, options));
                Add(writer, value.Destination, SaveOption.MergeHead);
                writer.Save(tmp);
            }

            io.Move(tmp, src, true);
        }
예제 #18
0
 extern static private Result sqlite3_open_v2([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8Marshaller))] string filename,
                                              out IntPtr connectionHandle, OpenOption options, IntPtr vfs);
예제 #19
0
 internal MuninnPageCacheNoChannelStripingTest()
 {
     // Think of this as calling a super constructor accepting this argument. See more comments on this field declaration.
     openOptions = new OpenOption[] { PageCacheOpenOptions.NO_CHANNEL_STRIPING };
 }
예제 #20
0
        /// <summary>
        /// MainWindowのViewModelを初期化します。
        /// </summary>
        public MainWindowViewModel()
        {
            //キーボード入力取得クラスのインスタンスを生成・イベントハンドラーの設定
            this.KeyboardUtil = new Models.KeyboardUtil(this);
            this.KeyboardUtil.KeyHookKeyUp        += this.KeyHookKeyUp_Handler;
            this.KeyboardUtil.KeyHookKeyDown      += this.KeyHookKeyDown_Handler;
            this.KeyboardUtil.KeyHookShiftKeyUp   += this.KeyHookShiftKeyUp_Handler;
            this.KeyboardUtil.KeyHookShiftKeyDown += this.KeyHookShiftKeyDown_Handler;
            this.KeyboardUtil.KeyHookAltKeyUp     += this.KeyHookAltKeyUp_Handler;
            this.KeyboardUtil.KeyHookAltKeyDown   += this.KeyHookAltKeyDown_Handler;

            //設定ファイル
            SettingsModel = new AppSettingsModel();

            //キーボード入力表示クラスのインスタンスを生成・プロパティの割当
            KeyboardDisplay          = new KeyBoardDisplay(SettingsModel.SelectedSkinSettingFilePath, 1D); //設定ファイルのパスを与えて初期化
            KeyDisplayInfoCollection = KeyboardDisplay.KeyDisplayInfoCollection;

            //キー入力統計情報
            KeyInputStatistics = new KeyInputStatistics();
            this.KeyboardUtil.KeyHookKeyDown      += KeyInputStatistics.KeyDownCount;
            this.KeyboardUtil.KeyHookShiftKeyDown += KeyInputStatistics.KeyDownCount;
            this.KeyboardUtil.KeyHookAltKeyDown   += KeyInputStatistics.KeyDownCount;
            MainWindowViewModel vm = this;

            _keyInputPropertyChanged = new PropertyChangedProxy <KeyInputStatistics, string>(
                KeyInputStatistics,
                keyStatic => keyStatic.ElapsedTimeString,
                elapsedTime => vm.OnPropertyChanged(nameof(elapsedTime))
                );
            _keyInputPropertyChangedKeyDownSum = new PropertyChangedProxy <KeyInputStatistics, int>(
                KeyInputStatistics,
                keyStatic => keyStatic.KeyDownSum,
                KeyDownSum => vm.OnPropertyChanged(nameof(KeyDownSum))
                );
            _keyInputPropertyChangedCurrentKPM = new PropertyChangedProxy <KeyInputStatistics, double>(
                KeyInputStatistics,
                keyStatic => keyStatic.CurrentKPM,
                CurrentKPM => vm.OnPropertyChanged(nameof(CurrentKPM))
                );
            _keyInputPropertyChangedMaxKPM = new PropertyChangedProxy <KeyInputStatistics, double>(
                KeyInputStatistics,
                keyStatic => keyStatic.MaxKPM,
                MaxKPM => vm.OnPropertyChanged(nameof(MaxKPM))
                );
            //_baseKeyBoardPicChanged = new PropertyChangedProxy<AppSettingsModel, string>(
            //    SettingsModel,
            //    setting => setting.SelectedSkinBaseKeyboardPicFilePath,
            //    SelectedSkinBaseKeyboardPicFilePath => vm.OnPropertyChanged(nameof(SelectedSkinBaseKeyboardPicFilePath))
            //);

            //最初の入力にセパレータは不要
            this.IsInsertSeparatorSymbol = false;

            //Shiftキー初期化
            this.IsShiftPressed = false;

            //バージョン情報を取得し、タイトルへ反映する
            this.TitleString = Models.General.GetTitleString();

            ClearInput  = new ClearInput_Imp(this);
            OpenOption  = new OpenOption(this);
            WindowClose = new MenuCloseButtonInput(this);


            SettingsModel.PropertyChanged += SettingsModel_PropertyChanged;
        }
예제 #21
0
        private void btnOptionCMD_Click(object sender, RoutedEventArgs e)
        {
            Button btn = sender as Button;

            if (string.Compare(btn.Name, "btnSave", true) == 0)
            {
                OpenOption openOpt = new OpenOption();

                openOpt.ContractNo = Convert.ToInt32(this.txtContract.Text);
                openOpt.PurchasePrice = Convert.ToDecimal(this.txtPrice.Text);
                openOpt.Option = new Option()
                {
                    Strike = Convert.ToDecimal(this.txtStrike.Text),
                    ExpiryDate = Convert.ToDateTime(this.txtExpiryDate.Text),
                    IsCall = this.chkCall.IsChecked.Value
                };

                this._openOptions.Add(openOpt);

                ClearOptionInput();
            }
            else if (string.Compare(btn.Name, "btnClear", true) == 0)
            {
                ClearOptionInput();
            }
            else if (string.Compare(btn.Name, "btnDelete", true) == 0)
            {
                if (this.lvOptions.SelectedItem != null)
                {
                    OpenOption openOpt = this.lvOptions.SelectedItem as OpenOption;
                    this._openOptions.Remove(openOpt);
                }
                ClearOptionInput();
            }
        }
예제 #22
0
 static public Result OpenV2(string filename, out IntPtr connectionHandle, OpenOption options)
 {
     return(sqlite3_open_v2(filename, out connectionHandle, options, IntPtr.Zero));
 }