예제 #1
0
        private static void RespCallback(IAsyncResult AsyncResult)
        {
            GRequestState myState = ((GRequestState)(AsyncResult.AsyncState));

            try
            {
                WebRequest myRequest       = myState.Request;
                string     myDescription   = "";
                string     myContentLength = "";

                HttpWebResponse myResponse = ((HttpWebResponse)(myRequest.EndGetResponse(AsyncResult)));
                myState.Response   = myResponse;
                myDescription      = myResponse.StatusDescription;
                myState.TotalBytes = myState.Response.ContentLength;
                myContentLength    = myState.Response.ContentLength.ToString();

                Stream myResponseStream = myState.Response.GetResponseStream();
                myState.StreamResponse = myResponseStream;

                IAsyncResult myIAsyncResult = myResponseStream.BeginRead(myState.BufferRead, 0, BUFFER_SIZE, new AsyncCallback(ReadCallback), myState);

                return;
            }
            catch (Exception ex)
            {
                ErrorDump.AddError(System.IntPtr.Zero, "GDownload.cs", "RespCallback", ex);
                if (myState.FinishedEvent != null)
                {
                    myState.FinishedEvent(new DriveFinishedEventArgs(false, "Fout bij downloaden", ex));
                }
            }
        }
예제 #2
0
        private void Init()
        {
            sGlobals.DB_File      = Path.Combine(@"G:\", "FDB", "FDB.sqlite");
            sGlobals.DB_Connected = DBConnect.ConnectDB();

            try
            {
                List <Serie>      mySeries       = sGlobals.DB.Series.ToList();
                List <Film>       myFilms        = sGlobals.DB.Films.ToList();
                List <Instelling> myInstellingen = sGlobals.DB.Instellingen.ToList();
            }
            catch (Exception ex)
            {
                ErrorDump.AddError("FormMain.cs", "Init", ex);
            }

            //tcTab.SelectedTab = tabFilm;

            try
            {
                m_FormSeries             = new FormSeries();
                m_FormSeries.TopLevel    = false;
                m_FormSeries.WindowState = FormWindowState.Maximized;
                pnlSeries.Controls.Add(m_FormSeries);
            }
            catch (Exception ex)
            {
                ErrorDump.AddError("FormMain.cs", "Shown", ex);
            }
        }
예제 #3
0
        public bool DownloadFile(Google.Apis.Drive.v2.Data.File myFile, string BestandsNaam)
        {
            bool Succes = false;

            m_File         = myFile;
            m_BestandsNaam = BestandsNaam;

            try
            {
                HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(new Uri(myFile.DownloadUrl));
                m_Authenticator.ApplyAuthenticationToRequest(myRequest);

                m_State             = new GRequestState(BUFFER_SIZE);
                m_State.Request     = myRequest;
                m_State.WriteStream = System.IO.File.OpenWrite(BestandsNaam);

                m_State.ProgressEvent += ProgressEvent;
                m_State.FinishedEvent += FinishedEvent;

                IAsyncResult myResult = (IAsyncResult)myRequest.BeginGetResponse(new AsyncCallback(RespCallback), m_State);
            }
            catch (Exception ex)
            {
                ErrorDump.AddError(System.IntPtr.Zero, "GDownload.cs", "DownloadFile", ex);
                if (FinishedEvent != null)
                {
                    FinishedEvent(new DriveFinishedEventArgs(false, "Fout bij downloaden", ex));
                }
            }

            return(Succes);
        }
예제 #4
0
 private void MyDriveFinishedEvent(DriveFinishedEventArgs e)
 {
     if (this.InvokeRequired)
     {
         this.Invoke(new DelegateDriveFinished(MyDriveFinishedEvent), e);
     }
     else
     {
         try
         {
             StopVoortgang();
             if (e.Succes)
             {
                 Voortgang("Gereed");
             }
             else
             {
                 Voortgang("Mislukt");
             }
         }
         catch (Exception ex)
         {
             ErrorDump.AddError(System.IntPtr.Zero, "FormMain.cs", "MyActionFinishedEvent", ex);
         }
     }
 }
예제 #5
0
        /********************************************** Events *****************************************************************/


        public void myProgressChanged(Google.Apis.Upload.IUploadProgress myProgress)
        {
            try
            {
                if (myProgress.Status == Google.Apis.Upload.UploadStatus.Uploading)
                {
                    double myProcent = myProgress.BytesSent / (m_TotalBytesSize / 100);

                    if (ProgressEvent != null)
                    {
                        ProgressEvent(new DriveProgressEventArgs(myProcent));
                    }
                }
                else if (myProgress.Status == Google.Apis.Upload.UploadStatus.Completed)
                {
                    if (FinishedEvent != null)
                    {
                        FinishedEvent(new DriveFinishedEventArgs(true));
                    }
                }
                else if (myProgress.Status == Google.Apis.Upload.UploadStatus.Failed)
                {
                    if (FinishedEvent != null)
                    {
                        FinishedEvent(new DriveFinishedEventArgs(false));
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorDump.AddError(System.IntPtr.Zero, "GUpload.cs", "myProgressChanged", ex);
            }
        }
예제 #6
0
        public static IAuthorizationState GetAuthorization(NativeApplicationClient Client)
        {
            try
            {
                const string KEY     = "z},drdzf11x9;87";
                string       myScope = DriveService.Scopes.Drive.GetStringValue();

                // Check if there is a cached refresh token available.
                IAuthorizationState myState = AuthorizationMgr.GetCachedRefreshToken(KEY);
                if (myState != null)
                {
                    try
                    {
                        Client.RefreshToken(myState);
                        return(myState); // Yes - we are done.
                    }
                    catch (DotNetOpenAuth.Messaging.ProtocolException ex)
                    {
                        ErrorDump.AddError(System.IntPtr.Zero, "GAuth.cs", "GetAuthorization", ex, "Using existing refresh token failed");
                    }
                }

                // If we get here, there is no stored token. Retrieve the authorization from the user.
                myState = AuthorizationMgr.RequestNativeAuthorization(Client, myScope);
                AuthorizationMgr.SetCachedRefreshToken(KEY, myState);
                return(myState);
            }
            catch (Exception ex)
            {
                ErrorDump.AddError(System.IntPtr.Zero, "GAuth.cs", "GetAuthorization", ex);
                return(null);
            }
        }
예제 #7
0
        private bool DeleteFilesInFolder(Google.Apis.Drive.v2.Data.File Folder)
        {
            bool Succes = false;

            try
            {
                FilesResource.ListRequest myList = m_Drive.Files.List();
                myList.Q = string.Format("trashed = false and '{0}' in parents", Folder.Id);
                Google.Apis.Drive.v2.Data.FileList myFiles = myList.Fetch();

                foreach (Google.Apis.Drive.v2.Data.File myFile in myFiles.Items)
                {
                    FilesResource.DeleteRequest myDelRequest = m_Drive.Files.Delete(myFile.Id);
                    myDelRequest.Fetch();
                }

                Succes = true;
            }
            catch (Exception ex)
            {
                ErrorDump.AddError(System.IntPtr.Zero, "DriveSync.cs", "DeleteFilesInFolder", ex);
                if (FinishedEvent != null)
                {
                    FinishedEvent(new DriveFinishedEventArgs(false, "Fout bij verwijderen oude database", ex));
                }
            }

            return(Succes);
        }
예제 #8
0
        /********************************************** Functions ******************************************************************/

        private void StartConnect()
        {
            try
            {
                m_Connected = (GetPlacesFolder() && GetPlacesBestand());

                m_GDownload = new GDownload(m_Drive.Authenticator);
                m_GDownload.ProgressEvent = ProgressEvent;
                m_GDownload.FinishedEvent = FinishedEvent;

                m_GUpload = new GUpload(m_Drive, m_PlacesFolder);
                m_GUpload.ProgressEvent = ProgressEvent;
                m_GUpload.FinishedEvent = FinishedEvent;
            }
            catch (Exception ex)
            {
                m_Connected = false;
                ErrorDump.AddError(System.IntPtr.Zero, "DriveSync.cs", "Connect", ex);
            }

            if (ConnectEvent != null)
            {
                ConnectEvent(new DriveConnectEventArgs(m_Connected));
            }
        }
예제 #9
0
        /********************************************** Variables ******************************************************************/

        #endregion Variables

        #region Constructor, Load & Closing
        /********************************************** Constructor, Load & Closing ************************************************/

        #endregion Constructor, Load & Closing

        #region Functions
        /********************************************** Functions ******************************************************************/

        public static bool ConnectDB()
        {
            bool bSucces = false;

            try
            {
                Database.SetInitializer(new FDBInitializer());

                SQLiteConnectionStringBuilder mySQLiteConnectionStringBuilder = new SQLiteConnectionStringBuilder();
                mySQLiteConnectionStringBuilder.DataSource = sGlobals.DB_File;

                sGlobals.DB_New = !File.Exists(sGlobals.DB_File);

                SQLiteConnection myConn = new SQLiteConnection(mySQLiteConnectionStringBuilder.ConnectionString);

                sGlobals.DB = new FDB(myConn);
                sGlobals.DB.Database.Initialize(false);

                bSucces = true;
            }
            catch (Exception ex)
            {
                ErrorDump.AddError("DBConnect.cs", "ConnectDB", ex);
            }

            return(bSucces);
        }
예제 #10
0
        public bool DownloadPlaces()
        {
            bool Succes = false;

            try
            {
                m_GDownload.ProgressEvent = ProgressEvent;
                m_GDownload.FinishedEvent = FinishedEvent;

                if (DeleteIfExists(Globals.PlacesFileNieuw))
                {
                    m_GDownload.DownloadFile(m_PlacesBestand, Globals.PlacesFileNieuw);

                    Succes = true;
                }
            }
            catch (Exception ex)
            {
                ErrorDump.AddError(System.IntPtr.Zero, "DriveSync.cs", "DownloadPlaces", ex);
                if (FinishedEvent != null)
                {
                    FinishedEvent(new DriveFinishedEventArgs(false, "Fout bij downloaden", ex));
                }
            }

            return(Succes);
        }
예제 #11
0
        public bool UploadPlaces()
        {
            bool Succes = false;

            try
            {
                if (DeleteFilesInFolder(m_PlacesFolder))
                {
                    m_GUpload.ProgressEvent = ProgressEvent;
                    m_GUpload.FinishedEvent = FinishedEvent;

                    m_GUpload.UploadFile(Globals.PlacesFileNieuw, m_PlacesFolder);

                    Succes = true;
                }
            }
            catch (Exception ex)
            {
                ErrorDump.AddError(System.IntPtr.Zero, "DriveSync.cs", "UploadPlaces", ex);
                if (FinishedEvent != null)
                {
                    FinishedEvent(new DriveFinishedEventArgs(false, "Fout bij uploaden", ex));
                }
            }

            return(Succes);
        }
예제 #12
0
        /********************************************** Functions ******************************************************************/

        private void LaadIDs()
        {
            try
            {
                using (SQLiteCommand cmd = m_Conn.CreateCommand())
                {
                    cmd.CommandText = "SELECT ID FROM moz_places";

                    using (SQLiteDataAdapter myAdapter = new SQLiteDataAdapter(cmd))
                    {
                        using (DataSet ds = new DataSet())
                        {
                            myAdapter.Fill(ds);

                            m_Table = ds.Tables[0];
                        }
                    }
                }

                object myObject = m_Table.Rows[0].ItemArray[0];


                m_IDs = m_Table.Rows.OfType <DataRow>().Select(r => Convert.ToInt32(r.ItemArray[0])).ToList();

                Globals.Log(string.Format("{0} IDs geladen", m_IDs.Count.ToString()));
            }
            catch (Exception ex)
            {
                ErrorDump.AddError(System.IntPtr.Zero, "LiteDB.cs", "Init", ex);
            }
        }
예제 #13
0
        private void Init()
        {
            try
            {
                m_Conn = new SQLiteConnection(string.Format("Data Source={0}", m_FileName));
                m_Conn.Open();

                m_IDs = new List <int>();

                LaadIDs();
            }
            catch (Exception ex)
            {
                ErrorDump.AddError(System.IntPtr.Zero, "LiteDB.cs", "Init", ex);
            }
        }
예제 #14
0
        public static IAuthenticator CreateAuthenticator()
        {
            try
            {
                NativeApplicationClient myClient = new NativeApplicationClient(GoogleAuthenticationServer.Description);
                myClient.ClientIdentifier = Globals.CLIENT_ID;
                myClient.ClientSecret     = Globals.CLIENT_SECRET;

                return(new OAuth2Authenticator <NativeApplicationClient>(myClient, GetAuthorization));
            }
            catch (Exception ex)
            {
                ErrorDump.AddError(System.IntPtr.Zero, "GAuth.cs", "CreateAuthenticator", ex);
                return(null);
            }
        }
예제 #15
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            try
            {
                FormMain fm = new FormMain();
                fm.Visible = false;

                Application.Run(fm);
            }
            catch (Exception ex)
            {
                ErrorDump.AddError("Program.cs", "Main", ex);
            }
        }
예제 #16
0
        private static void ReadCallback(IAsyncResult AsyncResult)
        {
            GRequestState myState = ((GRequestState)(AsyncResult.AsyncState));

            try
            {
                Stream myResponseStream = myState.StreamResponse;

                int myBytesRead = myResponseStream.EndRead(AsyncResult);

                myState.WriteStream.Write(myState.BufferRead, 0, myBytesRead);

                if (myBytesRead > 0)
                {
                    myState.BytesRead += myBytesRead;
                    double myPctComplete = ((double)myState.BytesRead / (double)myState.TotalBytes) * 100.0f;

                    if (myState.ProgressEvent != null)
                    {
                        myState.ProgressEvent(new DriveProgressEventArgs(myPctComplete));
                    }

                    IAsyncResult myIAsyncResult = myResponseStream.BeginRead(myState.BufferRead, 0, BUFFER_SIZE, new AsyncCallback(ReadCallback), myState);
                    return;
                }
                else
                {
                    myState.WriteStream.Close();
                    myState.StreamResponse.Close();
                    myState.Response.Close();

                    if (myState.FinishedEvent != null)
                    {
                        myState.FinishedEvent(new DriveFinishedEventArgs(true));
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorDump.AddError(System.IntPtr.Zero, "GDownload.cs", "ReadCallback", ex);
                if (myState.FinishedEvent != null)
                {
                    myState.FinishedEvent(new DriveFinishedEventArgs(false, "Fout bij downloaden", ex));
                }
            }
        }
예제 #17
0
        /********************************************** Functions ******************************************************************/

        public void UploadFile(string FileName, Google.Apis.Drive.v2.Data.File Folder)
        {
            Google.Apis.Drive.v2.Data.File myFile = new Google.Apis.Drive.v2.Data.File();

            try
            {
                myFile.Title    = "places.sqlite";
                myFile.MimeType = "chemical/x-mdl-sdfile";

                myFile.Parents = new List <ParentReference>()
                {
                    new ParentReference()
                    {
                        Id = Folder.Id
                    }
                };

                byte[]       myByteArray = System.IO.File.ReadAllBytes(FileName);
                MemoryStream myStream    = new MemoryStream(myByteArray);
                myStream.Position = 0;

                FilesResource.InsertMediaUpload myRequest = m_Drive.Files.Insert(myFile, myStream, myFile.MimeType);
                myRequest.ChunkSize = 262144;

                myRequest.ProgressChanged += new Action <Google.Apis.Upload.IUploadProgress>(myProgressChanged);

                m_TotalBytesSize = myStream.Length;

                Action myAsyncAction = () =>
                {
                    myRequest.Upload();
                };

                System.Threading.Thread myThread = new System.Threading.Thread(new System.Threading.ThreadStart(myAsyncAction));
                myThread.Start();
            }
            catch (Exception ex)
            {
                ErrorDump.AddError(System.IntPtr.Zero, "GUpload.cs", "UploadFile", ex);
                if (FinishedEvent != null)
                {
                    FinishedEvent(new DriveFinishedEventArgs(false, "Fout bij uploaden", ex));
                }
            }
        }
예제 #18
0
        private bool DeleteIfExists(string BestandsNaam)
        {
            bool Succes = false;

            try
            {
                if (System.IO.File.Exists(BestandsNaam))
                {
                    System.IO.File.Delete(BestandsNaam);
                }

                Succes = true;
            }
            catch (Exception ex)
            {
                ErrorDump.AddError(System.IntPtr.Zero, "FormMain.cs", "DeleteIfExists", ex);
            }

            return(Succes);
        }
예제 #19
0
        /********************************************** Variables ******************************************************************/

        #endregion Variables

        #region Constructor, Load & Closing
        /********************************************** Constructor, Load & Closing ************************************************/

        public void InitializeDatabase(FDB DB)
        {
            try
            {
                if (sGlobals.DB_New)
                {
                    string myFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Data", "SQL", "Create.SQL");
                    string mySQL  = File.ReadAllText(myFile);

                    DB.Database.ExecuteSqlCommand(mySQL);
                }


                //if versie ongelijk dan update
            }
            catch (Exception ex)
            {
                ErrorDump.AddError("FDBInitializer.cs", "InitializeDatabase", ex);
            }
        }
        public string RetrieveAuthorization(UserAgentClient client, IAuthorizationState authorizationState)
        {
            if (!HttpListener.IsSupported)
            {
                throw new NotSupportedException("HttpListener is not supported by this platform.");
            }

            // Create a HttpListener for the specified url.
            string url = string.Format(LoopbackCallback, GetRandomUnusedPort(), Assembly.GetEntryAssembly().GetName().Name);

            authorizationState.Callback = new Uri(url);
            var webserver = new HttpListener();

            webserver.Prefixes.Add(url);

            // Retrieve the authorization url.
            Uri authUrl = client.RequestUserAuthorization(authorizationState);

            try
            {
                // Start the webserver.
                webserver.Start();

                // Open the browser.
                Process.Start(authUrl.ToString());

                // Wait for the incoming connection, then handle the request.
                return(HandleRequest(webserver.GetContext()));
            }
            catch (HttpListenerException ex)
            {
                ErrorDump.AddError(System.IntPtr.Zero, "LoopbackServerAuthorizationFlow.cs", "RetrieveAuthorization", ex, "The HttpListener threw an exception.");
                return(null);
                //throw new NotSupportedException("The HttpListener threw an exception.", ex);
            }
            finally
            {
                // Stop the server after handling the one request.
                webserver.Stop();
            }
        }
예제 #21
0
파일: DBSave.cs 프로젝트: rajeshwarn/FilmDB
        /********************************************** Functions ******************************************************************/

        private static bool SaveEntity <T>(T[] entity) where T : Entity
        {
            bool bSucces = false;

            try
            {
                if (sGlobals.DB_Connected)
                {
                    sGlobals.DB.Set <T>().AddOrUpdate <T>(entity);
                    sGlobals.DB.SaveChanges();

                    bSucces = true;
                }
            }
            catch (Exception ex)
            {
                ErrorDump.AddError("DBSave.cs", "SaveEntity", ex);
            }

            return(bSucces);
        }
예제 #22
0
        /********************************************** Functions ******************************************************************/

        public Stream DownloadFileSimple(Google.Apis.Drive.v2.Data.File Bestand)
        {
            Stream myFile = null;

            try
            {
                HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(new Uri(Bestand.DownloadUrl));
                m_Authenticator.ApplyAuthenticationToRequest(myRequest);

                HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
                myFile = myResponse.GetResponseStream();
            }
            catch (Exception ex)
            {
                ErrorDump.AddError(System.IntPtr.Zero, "GDownload.cs", "DownloadBestand", ex);
                if (FinishedEvent != null)
                {
                    FinishedEvent(new DriveFinishedEventArgs(false, "Fout bij downloaden", ex));
                }
            }

            return(myFile);
        }
예제 #23
0
        private bool DeleteIfExists(string BestandsNaam)
        {
            bool Succes = false;

            try
            {
                if (System.IO.File.Exists(BestandsNaam))
                {
                    System.IO.File.Delete(BestandsNaam);
                }

                Succes = true;
            }
            catch (Exception ex)
            {
                ErrorDump.AddError(System.IntPtr.Zero, "DriveSync.cs", "DeleteIfExists", ex);
                if (FinishedEvent != null)
                {
                    FinishedEvent(new DriveFinishedEventArgs(false, "Fout bij verwijderen oude database", ex));
                }
            }

            return(Succes);
        }
예제 #24
0
        private bool GetPlacesBestand()
        {
            bool Succes = false;

            try
            {
                FilesResource.ListRequest myList = m_Drive.Files.List();
                myList.Q = string.Format("title = 'places.sqlite' and mimeType = 'application/octet-stream' and trashed = false and '{0}' in parents", m_PlacesFolder.Id);
                Google.Apis.Drive.v2.Data.FileList myFiles = myList.Fetch();

                if (myFiles.Items.Count > 0)
                {
                    m_PlacesBestand = myFiles.Items[0];

                    Succes = true;
                }
            }
            catch (Exception ex)
            {
                ErrorDump.AddError(System.IntPtr.Zero, "DriveSync.cs", "GetPlacesBestand", ex);
            }

            return(Succes);
        }
예제 #25
0
        private bool GetPlacesFolder()
        {
            bool Succes = false;

            try
            {
                FilesResource.ListRequest myList = m_Drive.Files.List();
                myList.Q = "title = 'BookSync' and mimeType = 'application/vnd.google-apps.folder' and trashed = false";
                Google.Apis.Drive.v2.Data.FileList myFiles = myList.Fetch();

                if (myFiles.Items.Count > 0)
                {
                    m_PlacesFolder = myFiles.Items[0];

                    Succes = true;
                }
            }
            catch (Exception ex)
            {
                ErrorDump.AddError(System.IntPtr.Zero, "DriveSync.cs", "GetPlacesFolder", ex);
            }

            return(Succes);
        }