Exemplo n.º 1
0
        public Fiche            CreateFiche(FichesDB _database, string _title, Uri _URL)
        {
            // Patch any empty title
            if (_title == null)
            {
                _title = "";
            }

            // Extract any tags from the title and fetch or create the tags ourselves
            string[]     tags      = WebHelpers.ExtractTags(_title);
            List <Fiche> tagFiches = new List <Fiche>();

            foreach (string tag in tags)
            {
                Fiche tagFiche = _database.Sync_FindOrCreateTagFiche(tag);
                tagFiches.Add(tagFiche);
            }

            // Create the descriptor
            Fiche F = _database.Sync_CreateFicheDescriptor(Fiche.TYPE.REMOTE_ANNOTABLE_WEBPAGE, _title, _URL, tagFiches.ToArray(), null);

            // Load the web page and save the fiche when ready
            uint maxScrollsCount = Fiche.ChunkWebPageSnapshot.ms_maxWebPagePieces;                      // @TODO: make that depend on the domain, like tweets shouldn't have any comments and a single screen should suffice, for example...

            _database.Async_LoadContentAndSaveFiche(F, maxScrollsCount, true);

            return(F);
        }
Exemplo n.º 2
0
//      protected	Fiche( FichesDB _database, string _title ) {
//          m_GUID = CreateGUID();
//          m_title = _title;
//
//          Database = _database;
//      }
        public Fiche(FichesDB _database, TYPE _type, string _title, Uri _URL, Fiche[] _tags, string _HTMLContent)
        {
            m_GUID  = _database.CreateGUID();
            m_type  = _type;
            m_title = _title;
            m_URL   = _URL;
            AddTags(_tags);
            m_HTMLContent = _HTMLContent;

            Database = _database;
            m_status = STATUS.READY;
        }
Exemplo n.º 3
0
        public Fiche CreateFiche(FichesDB _database, string _format, object _data)
        {
            MemoryStream S = _data as MemoryStream;

            if (S == null)
            {
                throw new Exception("Provided data is not the expected MemoryStream type!");
            }

            _format = _format.ToLower();
            bool isUnicode = _format == "text/x-moz-url" || _format == "uniformresourcelocatorw";

// string	debug = "Length = " + S.Length + "\r\n<bold>";
// for ( int i=0; i < S.Length; i++ ) {
//  debug += S.ReadByte().ToString( "X2" );
// }
// BrainForm.Debug( debug );
//string	HTML = "<body>" + debug + "</bold></body>";

            // Assume the memory stream contains a unicode string
            int stringLength = (int)S.Length;

            System.Text.Encoding encoding = isUnicode ? System.Text.Encoding.Unicode : System.Text.Encoding.ASCII;

            if (isUnicode)
            {
                if ((stringLength & 1) != 0)
                {
                    throw new Exception("Expected an even size! Apparently we're not really dealing with a unicode string...");
                }
                stringLength >>= 1;
            }

            char[] URLchars = new char[stringLength];
            using (StreamReader R = new StreamReader(S, encoding)) {
                R.Read(URLchars, 0, URLchars.Length);
            }

            string title  = null;
            string strURL = new string( URLchars );

            string[] URLLines = strURL.Split('\n');
            if (URLLines.Length > 1)
            {
                // URL is multi-part: must have a title after the actual link...
                strURL = URLLines[0];
                title  = URLLines[1];
            }

            Uri URL = WebHelpers.CreateCanonicalURL(strURL);

            return(CreateURLFiche(_database, title, URL));
        }
Exemplo n.º 4
0
        public ValidateUnRecognizedTagsForm(FichesDB _database, string[] _unRecognizedTagNames)
        {
            InitializeComponent();

            m_database = _database;

            labelInfo.Text = "The following tag names are unrecognized: do you want to create them?";

            checkedListBox.SuspendLayout();
            foreach (string tagName in _unRecognizedTagNames)
            {
                checkedListBox.Items.Add(tagName, true);
            }
            checkedListBox.ResumeLayout();
        }
Exemplo n.º 5
0
        public Fiche CreateFiche(FichesDB _database, string _format, object _data)
        {
            string text = _data.ToString();

            // Check if it's not a URL in disguise, in which case we'll create a webpage instead...
            if (URLHandler.CanHandleURLScheme(text))
            {
                return(URLHandler.CreateURLFiche(_database, null, WebHelpers.CreateCanonicalURL(text)));
            }

            string title = text;                // Do better?
            string HTML  = WebHelpers.BuildHTMLDocument(title, text);
            Fiche  F     = _database.Sync_CreateFicheDescriptor(Fiche.TYPE.LOCAL_EDITABLE_WEBPAGE, text, null, null, HTML);

            _database.Async_SaveFiche(F, true, true);
            return(F);
        }
Exemplo n.º 6
0
        public static Fiche     CreateURLFiche(FichesDB _database, string _title, Uri _URL)
        {
            if (_URL == null)
            {
                throw new Exception("Invalid null URL to create fiche!");
            }
            if (!Uri.IsWellFormedUriString(_URL.AbsoluteUri, UriKind.Absolute))
            {
                throw new Exception("Invalid URL to create fiche!");
            }

            // Attempt to create the fiche itself
            string candidateURL = _URL.AbsoluteUri.ToLower();

            foreach (IScheme scheme in Schemes)
            {
                if (scheme.SupportsURL(candidateURL))
                {
                    return(scheme.CreateFiche(_database, _title, _URL));
                }
            }

            return(null);
        }
Exemplo n.º 7
0
            public Bookmark(FichesDB _database, Bookmark _parent, WebServices.JSON.JSONObject _JSON, List <Bookmark> _bookmarks)
            {
                m_database = _database;
                m_parent   = _parent;
                if (_JSON == null || !_JSON.IsDictionary)
                {
                    throw new Exception("Invalid JSON object type!");
                }

                Dictionary <string, object> dictionary = _JSON.AsDictionary;

                foreach (string key in dictionary.Keys)
                {
                    switch (key)
                    {
                    case "name":
                        m_name = dictionary[key] as string;
                        break;

                    case "date_added":
                        // From https://stackoverflow.com/questions/19074423/how-to-parse-the-date-added-field-in-chrome-bookmarks-file
                        string strTicks = dictionary[key] as string;
                        long   microseconds;
                        if (long.TryParse(strTicks, out microseconds))
                        {
                            long milliseconds = microseconds / 1000;
                            long seconds      = milliseconds / 1000;
                            long minutes      = seconds / 60;
                            long hours        = minutes / 60;
                            long days         = hours / 24;

                            TimeSpan delay = new TimeSpan((int)days, (int)(hours % 24), (int)(minutes % 60), (int)(seconds % 60), (int)(milliseconds % 1000));
                            m_dateAdded = new DateTime(1601, 1, 1) + delay;
                        }
                        break;

                    case "guid":
                        string strGUID = dictionary[key] as string;
                        Guid.TryParse(strGUID, out m_GUID);
                        break;

                    case "url":
                        string strURL = dictionary[key] as string;
                        m_URL = WebHelpers.CreateCanonicalURL(strURL);
                        break;

                    case "children":
                        RecurseImportBookmarks(this, dictionary[key] as WebServices.JSON.JSONObject, _bookmarks);
                        break;

                    case "type":
                        string strType = dictionary[key] as string;
                        switch (strType)
                        {
                        case "url": m_type = TYPE.URL; break;

                        case "folder": m_type = TYPE.FOLDER; break;
                        }
                        break;

                    default:
                        // Try import children...
                        RecurseImportBookmarks(this, dictionary[key] as WebServices.JSON.JSONObject, _bookmarks);
                        break;
                    }
                }
            }
Exemplo n.º 8
0
        public BrainForm()
        {
            ms_singleton = this;

            InitializeComponent();


            this.TopMost = false;



            DEFAULT_OPACITY = this.Opacity;

            try {
                m_database = new FichesDB();
                m_database.FicheSuccessOccurred += database_FicheSuccessOccurred;
                m_database.FicheWarningOccurred += database_FicheWarningOccurred;
                m_database.FicheErrorOccurred   += database_FicheErrorOccurred;
                m_database.Log += database_Log;

                // Setup the fiches' default dimensions to the primary monitor's dimensions
                Rectangle primaryScreenRect = Screen.PrimaryScreen.Bounds;
                Fiche.ChunkWebPageSnapshot.ms_defaultWebPageWidth  = (uint)primaryScreenRect.Width;
                Fiche.ChunkWebPageSnapshot.ms_defaultWebPageHeight = (uint)primaryScreenRect.Height;
                Fiche.ChunkWebPageSnapshot.ms_maxWebPagePieces     = (uint)Math.Ceiling(20000.0 / primaryScreenRect.Height);

                Rectangle desktopBounds = Interop.GetDesktopBounds();

                // Create the modeless forms
                m_logForm          = new LogForm();
                m_logForm.Location = new Point(desktopBounds.Right - m_logForm.Width, desktopBounds.Bottom - m_logForm.Height);                         // Spawn in bottom-right corner of the desktop to avoid being annoying...

                m_preferenceForm = new PreferencesForm(this);
                m_preferenceForm.RootDBFolderChanged += preferenceForm_RootDBFolderChanged;
                m_preferenceForm.Visible              = false;

                m_ficheWebPageEditorForm                 = new FicheWebPageEditorForm(this);
                m_ficheWebPageEditorForm.Visible         = false;
                m_ficheWebPageEditorForm.VisibleChanged += ficheWebPageEditorForm_VisibleChanged;

                m_ficheWebPageAnnotatorForm                 = new FicheWebPageAnnotatorForm(this);
                m_ficheWebPageAnnotatorForm.Visible         = false;
                m_ficheWebPageAnnotatorForm.VisibleChanged += ficheWebPageAnnotatorForm_VisibleChanged;

                m_fastTaggerForm         = new FastTaggerForm(this);
                m_fastTaggerForm.Visible = false;

                m_notificationForm         = new NotificationForm(this);
                m_notificationForm.Visible = false;

                // Parse fiches and load database
                DirectoryInfo rootDBFolder = new DirectoryInfo(m_preferenceForm.RootDBFolder);
                if (!rootDBFolder.Exists)
                {
                    rootDBFolder.Create();
                    rootDBFolder.Refresh();

                    int waitCount = 0;
                    while (!rootDBFolder.Exists)
                    {
                        System.Threading.Thread.Sleep(100);
                        if (waitCount++ > 10)                           // Wait for a full second
                        {
                            throw new Exception("Failed to create root DB folder \"" + rootDBFolder + "\"! Time elapsed...");
                        }
                    }
                }

                m_database.LoadFichesDescriptions(rootDBFolder);


//SelectedFiche = URLHandler.CreateURLFiche( m_database, null, WebHelpers.CreateCanonicalURL( "https://twitter.com/HMaler/status/1217484876372480008" ) );	// OK!
//SelectedFiche = URLHandler.CreateURLFiche( m_database, null, WebHelpers.CreateCanonicalURL( "https://twitter.com/SylvieGaillard/status/1211726353726394379" ) );	// OK!
//SelectedFiche = URLHandler.CreateURLFiche( m_database, null, WebHelpers.CreateCanonicalURL( "https://twitter.com/MFrippon/status/1134377488233226245" ) );	// OK!

//SelectedFiche = URLHandler.CreateURLFiche( m_database, null, WebHelpers.CreateCanonicalURL( "https://stackoverflow.com/questions/4964205/non-transparent-click-through-form-in-net" ) );	// OK!
//SelectedFiche = URLHandler.CreateURLFiche( m_database, null, WebHelpers.CreateCanonicalURL( "http://www.patapom.com/" ) );	// OK!
//SelectedFiche = URLHandler.CreateURLFiche( m_database, null, WebHelpers.CreateCanonicalURL( "https://www.monde-diplomatique.fr/2020/03/HOLLAR/61546" ) );	// OK!
//SelectedFiche = URLHandler.CreateURLFiche( m_database, null, WebHelpers.CreateCanonicalURL( "https://docs.google.com/document/d/1_iJeEDcoDJS8EUyaprAL4Eu67Tbox_DnYnzQPFiTsa0/edit#heading=h.bktvm5f5g3wf" ) );	// OK!
//SelectedFiche = URLHandler.CreateURLFiche( m_database, null, WebHelpers.CreateCanonicalURL( "https://www.breakin.se/mc-intro/" ) );	// OK!
//SelectedFiche = URLHandler.CreateURLFiche( m_database, null, WebHelpers.CreateCanonicalURL( "https://www.frontiersin.org/articles/10.3389/fpsyg.2017.02124/full" ) );	// OK!

// Ici on a un crash de temps en temps quand la fiche est sauvée et que les images sont disposed alors que l'éditeur tente de les lire pour en faire des bitmaps! C'est très très chiant à repro!
//SelectedFiche = URLHandler.CreateURLFiche( m_database, null, WebHelpers.CreateCanonicalURL( "https://en.wikipedia.org/wiki/Quantum_mind" ) );	// Crash bitmap copy

// Content rectangles still off
// Sur le premier lien c'est un bandeau dynamique qui doit foutre la merde
// Sur mediapart aussi apparemment (ça se voit uniquement en mode "incognito" sinon je suis loggé avec mon compte et l'article est complet)
//SelectedFiche = URLHandler.CreateURLFiche( m_database, null, WebHelpers.CreateCanonicalURL( "http://variances.eu/?p=3221" ) );
                SelectedFiche = URLHandler.CreateURLFiche(m_database, null, WebHelpers.CreateCanonicalURL("https://www.mediapart.fr/journal/economie/040320/la-banque-publique-d-investissement-va-eponger-les-pertes-du-cac-40"));

/*
 * Essayer ça:
 * https://www.republicain-lorrain.fr/edition-thionville-hayange/2020/03/05/ces-frontaliers-qui-laissent-tomber-le-train?preview=true&amp;fbclid=IwAR3jgJaj0wjepYYTEHNiXbJzQ4B9giZ4htO6gge4q7BwXUGQrvSpql8Sh9M
 *
 * Exemple d'article "parfait" avec un court résumé au début et des liens "bio" sur les gens et les organisations:
 * (pourrait-on tenter de créer ce genre de digests automatiquement?)
 * https://www.ftm.nl/dutch-multinationals-funded-climate-sceptic
 *
 * Tester blog jean Chon "questions à charge" où la page se charge au fur
 *
 *
 * Tester ça avec les trucs à droite qui s'updatent bizarrement + cleanup d'URL
 * https://www.huffingtonpost.fr/entry/agnes-buzyn-livre-des-confessions-accablantes-sur-le-coronavirus_fr_5e70b8cec5b6eab7793c6642?ncid=other_twitter_cooo9wqtham&utm_campaign=share_twitter
 */

                m_logForm.Show();
            }
            catch (FichesDB.DatabaseLoadException _e) {
                // Log errors...
                foreach (Exception e in _e.m_errors)
                {
                    LogError(e);
                }
            } catch (Exception _e) {
                MessageBox("Error when creating forms!\r\n\n", _e);
//              Close();
//				Application.Exit();
            }

            try {
                // Attempt to retrieve containing monitor
                IntPtr hMonitor;
                Screen screen;
                Interop.GetMonitorFromPosition(Control.MousePosition, out screen, out hMonitor);

                // Rescale window to fullscreen overlay
                this.SetDesktopBounds(screen.Bounds.X, screen.Bounds.Y, screen.Bounds.Width, screen.Bounds.Height);

                // Create fullscreen windowed device
                m_device.Init(this.Handle, false, true);

                m_CB_main   = new ConstantBuffer <CB_Main>(m_device, 0);
                m_CB_camera = new ConstantBuffer <CB_Camera>(m_device, 1);
                m_CB_camera.m._camera2World = new float4x4();
                m_CB_camera.m._camera2Proj  = new float4x4();

                // Create primitives and shaders
                m_shader_displayCube = new Shader(m_device, new System.IO.FileInfo("./Shaders/DisplayCube.hlsl"), VERTEX_FORMAT.P3N3, "VS", null, "PS", null);

                BuildCube();

                m_startTime       = DateTime.Now;
                Application.Idle += Application_Idle;

                // Register global shortcuts
                m_preferenceForm.RegisterHotKeys();

                Focus();
            } catch (Exception _e) {
                MessageBox("Error when creating D3D device!\r\n\n", _e);
                Close();
//				Application.Exit();
            }
        }
Exemplo n.º 9
0
 /// <summary>
 /// Internal and protected fiche creation
 /// Shouldn't be called manually, only the database should use this method
 /// </summary>
 /// <param name="_database"></param>
 internal Fiche(FichesDB _database)
 {
     m_database = _database;
 }
Exemplo n.º 10
0
 public Fiche(FichesDB _database, BinaryReader _reader)
 {
     Read(_reader);
     Database = _database;               // Register afterward so our registration data (e.g. GUID, URL, title, etc.) are ready
 }