コード例 #1
0
ファイル: FileSysWatchDog.cs プロジェクト: hangmiao/DBLike
        // Define the event handlers.
        private static void OnChanged(object source, FileSystemEventArgs e)
        {
            if (Configuration.flag.polling == true)
            {
                return;
            }
            string eventType;

            Program.ClientForm.addtoConsole("Event triggered:" + e.ChangeType);
            Program.ClientForm.addtoConsole("Event triggered on:" + e.FullPath);

            /*
            if (onchnageToggler==true)
            {
                onchnageToggler = false;
            }
            else
            {
                onchnageToggler = true;
                return;
            }
            */
            //MessageBox.Show("OnChanged Event Raised", "Client");
            //Thread.Sleep(1000);
            try
            {
                //watcher.EnableRaisingEvents = false;
                //MessageBox.Show("OnChangedFun : File: " + e.FullPath + " " + e.ChangeType);
                if(File.Exists(e.FullPath))
                {

                    // let it sleep to avoid multiple "change" detection
                    // b/c IO is much slower than thread!
                    // but for large files, this needs to be patched
                    //Thread.Sleep(500);
                    if (e.ChangeType == WatcherChangeTypes.Changed)
                    {

                        eventType = "change";
                    }
                    else
                    {

                        eventType = "create";

                        // add file metadata to file list
                        Client.LocalFileSysAccess.FileListMaintain fileMaintain = new Client.LocalFileSysAccess.FileListMaintain();
                        fileMaintain.addSingleFileToFileList(e.FullPath);
                    }

                    LocalFileSysAccess.getFileAttributes timestamp = new LocalFileSysAccess.getFileAttributes(e.FullPath);
                    fileBeingUsed.eventDetails eventdet = new fileBeingUsed.eventDetails();
                    eventdet.datetime = timestamp.lastModified;
                    eventdet.filepath = e.FullPath;
                    eventdet.eventType = eventType;
                    if(Client.Program.filesInUse.alreadyPresent(eventdet))
                    {
                        return;
                    }
                    else
                    {
                        Client.Program.filesInUse.addToList(eventdet);
                    }

                    Uploader upload = new Uploader();
                    //if (e.ChangeType == WatcherChangeTypes.Changed)
                    //{
                        upload.start(e.FullPath, eventType, null, timestamp.lastModified);
                        Program.ClientForm.addtoConsole("Uploader thread started");

                    //}
                    //else
                    //{
                      // upload.start(e.FullPath, "create", null);
                    //}
                }
                else
                {

                    Program.ClientForm.addtoConsole("File does not exist.");
                }

            }
            finally
            {
                //watcher.EnableRaisingEvents = true;
            }
        }
コード例 #2
0
ファイル: FileSysWatchDog.cs プロジェクト: hangmiao/DBLike
        private static void OnRenamed(object source, RenamedEventArgs e)
        {
            Program.ClientForm.addtoConsole("Event triggered:" + e.ChangeType);
            Program.ClientForm.addtoConsole("Event triggered on:" + e.FullPath);
            //MessageBox.Show("OnRenameed Event Raised", "Client");
            //MessageBox.Show("File: " + e.OldFullPath + " renamed to " + e.FullPath);
            string eventType = "rename";
            LocalFileSysAccess.getFileAttributes timestamp = new LocalFileSysAccess.getFileAttributes(e.FullPath);
            fileBeingUsed.eventDetails eventdet = new fileBeingUsed.eventDetails();
            eventdet.datetime = timestamp.lastModified;
            eventdet.filepath = e.FullPath;
            eventdet.eventType = eventType;
            if (Client.Program.filesInUse.alreadyPresent(eventdet))
            {
                return;
            }
            else
            {
                Client.Program.filesInUse.addToList(eventdet);
            }
            //Client.MessageClasses.changedFile renamedFile = new Client.MessageClasses.changedFile(e.OldFullPath, e.FullPath, e.OldName, e.Name);
            string renamedStr = "<" + e.OldFullPath + ">:<" + e.FullPath + ">:<" + e.OldName + ">:<" + e.Name + ">";

            Uploader upload = new Uploader();
            upload.start(e.OldFullPath, "rename", renamedStr,timestamp.lastModified);
            Program.ClientForm.addtoConsole("Uploader thread started");
        }
コード例 #3
0
ファイル: Poll.cs プロジェクト: hangmiao/DBLike
        private bool ListWithContainerUri()
        {
            try
            {

                CloudBlobContainer container = new CloudBlobContainer(new Uri(sasUri));

                string blobPrefix = null;
                bool useFlatBlobListing = true;
                var blobs = container.ListBlobs(blobPrefix, useFlatBlobListing, BlobListingDetails.None);
                foreach (IListBlobItem item in blobs)
                {
                    if (item is CloudBlobDirectory)
                    {
                        Console.WriteLine("this is folder");
                        Console.WriteLine(item.Uri);
                    }
                    else
                    {
                        CloudBlockBlob file = (CloudBlockBlob)item;
                        file.FetchAttributes();
                        string fileFullPath = clientSynFolderPath + @"\"+ file.Metadata["filePath"];
                        DateTime blobDataTime = new DateTime();
                        Program.ClientForm.addtoConsole("file.MetaData: " + (file.Metadata["timestamp"]).ToString());
                        //Program.ClientForm.addtoConsole("using parser:" + DateTime.Parse((file.Metadata["timestamp"]).ToString()));
                        //blobDataTime = DateTime.ParseExact(file.Metadata["timestamp"], "MM/dd/yyyy HH:mm:ss", CultureInfo.InvariantCulture);
                        blobDataTime = DateTime.Parse(file.Metadata["timestamp"]);
                        if(File.Exists(fileFullPath))
                        {
                            getFileAttributes fileAttributes = new getFileAttributes(fileFullPath);
                            /*
                            DateTime blobDataTime = new DateTime();
                            blobDataTime = DateTime.ParseExact(file.Metadata["timestamp"], "MM-dd-yyyy HH:mm:ss",
                                                                null);
                             */
                            // if need to poll
                            Program.ClientForm.addtoConsole("Comparing Datetime for "+fileFullPath);
                            Program.ClientForm.addtoConsole("blobDateTime: "+blobDataTime);
                            Program.ClientForm.addtoConsole("lastModified: "+ fileAttributes.lastModified.ToUniversalTime() );
                            if (DateTime.Compare(blobDataTime, fileAttributes.lastModified.ToUniversalTime()) > 0)
                            {
                                Program.ClientForm.addtoConsole("Comparing HashValue");
                                Program.ClientForm.addtoConsole("Remote: " + file.Metadata["hashValue"]);
                                Program.ClientForm.addtoConsole("Local: "+ fileAttributes.md5Value);
                                if (fileAttributes.md5Value != file.Metadata["hashValue"])
                                {
                                    //it means there some change at server
                                    Program.ClientForm.addtoConsole("Poll function called");
                                    pollFile(file, fileFullPath, blobDataTime);
                                }
                                Program.ClientForm.addtoConsole("Hash Value Matched.No need to Download");
                            }
                            else if(DateTime.Compare(blobDataTime, fileAttributes.lastModified.ToUniversalTime()) < 0)
                            {
                                Program.ClientForm.addtoConsole("Comparing HashValue");
                                Program.ClientForm.addtoConsole("Remote: " + file.Metadata["hashValue"]);
                                Program.ClientForm.addtoConsole("Local: " + fileAttributes.md5Value);
                                if (fileAttributes.md5Value != file.Metadata["hashValue"])
                                {
                                    //it means there is some change at client which has yet not uploaded
                                    string eventType = "change";
                                    //LocalFileSysAccess.getFileAttributes timestamp = new LocalFileSysAccess.getFileAttributes(file);
                                    fileBeingUsed.eventDetails eventdet = new fileBeingUsed.eventDetails();
                                    eventdet.datetime = fileAttributes.lastModified;
                                    eventdet.filepath = fileFullPath;
                                    eventdet.eventType = eventType;
                                    if (Client.Program.filesInUse.alreadyPresent(eventdet))
                                    {
                                        //return;
                                        Program.ClientForm.addtoConsole("Already Present in the event list");
                                    }
                                    else
                                    {
                                        Client.Program.filesInUse.addToList(eventdet);
                                        Uploader upload = new Uploader();
                                        upload.start(fileFullPath, "change", null,fileAttributes.lastModified);
                                        Program.ClientForm.addtoConsole("Upload Thread Started for:"+ fileFullPath);
                                    }

                                }
                                Program.ClientForm.addtoConsole("Hash Value Matched.No need to upload");
                            }
                            Program.ClientForm.addtoConsole("Timestamp Matched.");
                        }
                        else
                        {
                            Program.ClientForm.addtoConsole("File Doesnot Exist");
                            Program.ClientForm.addtoConsole("Poll function Called");
                            pollFile(file, fileFullPath, blobDataTime);
                        }
                    }

                }

            }
            catch (Exception e)
            {
                Program.ClientForm.addtoConsole("Poll Exception:" + e.Message);
                Console.WriteLine(e.Message);
                MessageBox.Show(e.Message);
                return false;
            }

            return true;
        }
コード例 #4
0
ファイル: FileSysWatchDog.cs プロジェクト: hangmiao/DBLike
        /*
        // Define the event handlers.
        private static void OnCreated(object source, FileSystemEventArgs e)
        {

            //MessageBox.Show("OnCreatedFun: File: " + e.FullPath + " " + e.ChangeType);
            //MessageBox.Show("File: " + e.FullPath + " " + e.ChangeType);
            try
            {
                //watcher.EnableRaisingEvents = false;
                if (File.Exists(e.FullPath))
                {
                    Uploader upload = new Uploader();
                    upload.start(e.FullPath, "create", null);
                }
                else
                {
                    MessageBox.Show("File does not exist.");
                }
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {

            }

        }
         */
        // Define the event handlers.
        private static void OnDeleted(object source, FileSystemEventArgs e)
        {
            if (Configuration.flag.polling == true)
            {
                return;
            }

            Program.ClientForm.addtoConsole("Event triggered:" + e.ChangeType);
            Program.ClientForm.addtoConsole("Event triggered on:" + e.FullPath);

            //MessageBox.Show("OnDeleted Event Raised", "Client");
            //MessageBox.Show("File: " + e.FullPath + " " + e.ChangeType);
            /*
            string eventType = "delete";
            LocalFileSysAccess.getFileAttributes timestamp = new LocalFileSysAccess.getFileAttributes(e.FullPath);
            fileBeingUsed.eventDetails eventdet = new fileBeingUsed.eventDetails();
            eventdet.datetime = timestamp.lastModified;
            eventdet.filepath = e.FullPath;
            eventdet.eventType = eventType;
            if (Client.Program.filesInUse.alreadyPresent(eventdet))
            {
                return;
            }
            else
            {
                Client.Program.filesInUse.addToList(eventdet);
            }
             */
            Uploader upload = new Uploader();
            upload.start(e.FullPath, "delete", null,DateTime.Now);
            Program.ClientForm.addtoConsole("Uploader thread started");
        }
コード例 #5
0
ファイル: SignUp.cs プロジェクト: hangmiao/DBLike
        static void uploadeverything(string path)
        {
            string filepath = path;
            string[] files;
            string[] directories;

            files = Directory.GetFiles(path);
            foreach (string file in files)
            {
                // Process each file
                string eventType = "signUpStart";
                LocalFileSysAccess.getFileAttributes timestamp = new LocalFileSysAccess.getFileAttributes(file);
                fileBeingUsed.eventDetails eventdet = new fileBeingUsed.eventDetails();
                eventdet.datetime = timestamp.lastModified;
                eventdet.filepath = file;
                eventdet.eventType = eventType;
                if (Client.Program.filesInUse.alreadyPresent(eventdet))
                {
                    //return;
                }
                else
                {
                    Client.Program.filesInUse.addToList(eventdet);
                    Uploader upload = new Uploader();
                    upload.start(file, "signUpStart", null, timestamp.lastModified);
                }

            }

            directories = Directory.GetDirectories(path);
            foreach (string directory in directories)
            {
                // Process each directory recursively
                uploadeverything(directory);
            }
        }