Esempio n. 1
0
        private void doDelete(GCAction action)
        {
            // find DiskItem
            var rs = from d in db.Table <DiskItem>()
                     where d.Path.Equals(action.Path)
                     select d;

            if (rs.Count() == 0)
            {
                Console.Error.Write("No matching Diskitem when deleting ?", action.Path);
                return;
            }
            DiskItem item = rs.FirstOrDefault();

            var request = newReq("/rest/sync/delete");

            SetUpRequest(request);
            request.AddParameter("docId", action.DiskItemId);
            request.AddParameter("folder", item.Folder);

            var response = client.Execute <DeleteFileMeta>(request);

            if (response.ResponseStatus == ResponseStatus.Completed)
            {
                DeleteFileMeta meta = response.Data;
                if (meta.success)
                {
                    // what do if anything?
                }
            }
        }
Esempio n. 2
0
 internal void equeueGCAction(GCAction action)
 {
     lock (refQueue)
     {
         refQueue.Enqueue(action);
     }
 }
Esempio n. 3
0
        private void DoChanged(GCAction action)
        {
            //Does it still exist?
            if (!FileOrDirectoryExists(action.Path))
            {
                return;                                      // can happen when creating a new folder that immediately gets a different name
            }
            if (ThisIsFromMe(action))
            {
                return;
            }


            // We should already have this file in DB if not then it could be a new folder thats being renamed (it fires a change event as well)
            Object o = FindDiskItem(action);

            if (o == null)
            {
                return;
            }

            if (o is DiskItem)
            {
                DiskItem item = (DiskItem)o;

                // anything changed? (it may be a parent folder)
                if (item.Folder)
                {
                    return;
                }
            }

            // we don't do anything for workspaces
        }
Esempio n. 4
0
        void fsw_Changed(object sender, System.IO.FileSystemEventArgs e)
        {
            if (paused)
            {
                return;
            }
            Console.WriteLine("Changed: FileName - {0}, ChangeType - {1}", e.Name, e.ChangeType);


            GCAction a = new GCAction();

            a.Action = GCAction.CHANGED;
            a.Path   = e.FullPath;
            db.Insert(a);
        }
Esempio n. 5
0
        void fsw_Renamed(object sender, System.IO.RenamedEventArgs e)
        {
            if (paused)
            {
                return;
            }
            Console.WriteLine("Renamed: FileName - {0}, ChangeType - {1}, Old FileName - {2}", e.Name, e.ChangeType, e.OldName);

            GCAction a = new GCAction();

            a.Action  = GCAction.RENAMED;
            a.Path    = e.FullPath;
            a.OldPath = e.OldFullPath;
            db.Insert(a);
        }
Esempio n. 6
0
        void fsw_Created(object sender, System.IO.FileSystemEventArgs e)
        {
            if (paused)
            {
                return;
            }
            Console.WriteLine("Created: FileName - {0}, ChangeType - {1}", e.Name, e.ChangeType);

            // lets not worry about moves just yet

            GCAction a = new GCAction();

            a.Action = GCAction.NEW;
            a.Path   = e.FullPath;
            db.Insert(a);
        }
Esempio n. 7
0
        // We need to check if this GCAction event has occured from a user or from the DownloadMinitor (me) i.e. event arising from files being downloaded/deleted/rename etc on Glasscubes
        private bool ThisIsFromMe(GCAction action)
        {
            Object o = FindDiskItem(action);

            if (o == null)
            {
                return(false);
            }

            if (o is DiskItem)
            {
                DiskItem di = (DiskItem)o;
                // Test to see if its the same file/folder or a different version
                FileInfo fi = new FileInfo(action.Path);
                if (di.Folder)
                {
                    // fuzzy timecheck
                    TimeSpan span = fi.LastAccessTimeUtc - di.UpdatedOnDiskUTC;
                    if (span.TotalMilliseconds < FUZZY_TIMESTAMP_DIFF_MS)
                    {
                        return(true);
                    }
                }
                else
                {
                    var length = fi.Length;
                    if (di.Size == length)
                    {
                        // fuzzy timecheck
                        TimeSpan span = fi.LastAccessTimeUtc - di.UpdatedOnDiskUTC;
                        if (span.Milliseconds < FUZZY_TIMESTAMP_DIFF_MS)
                        {
                            return(true);
                        }
                    }
                }
            }


            if (o is Workspace)
            {
                return(true);
            }

            return(false);
        }
Esempio n. 8
0
        public void Tick()
        {
#if THREAD_SAFT || HOTFIX_ENABLE
            lock (luaEnvLock)
            {
#endif
            lock (refQueue)
            {
                while (refQueue.Count > 0)
                {
                    GCAction gca = refQueue.Dequeue();
                    translator.ReleaseLuaBase(L, gca.Reference, gca.IsDelegate);
                }
            }
            last_check_point = translator.objects.Check(last_check_point, max_check_per_tick, object_valid_checker, translator.reverseMap);
#if THREAD_SAFT || HOTFIX_ENABLE
        }
#endif
        }
Esempio n. 9
0
        public void Tick()
        {
            LuaAPI.xdRunOnce();
#if THREAD_SAFE || HOTFIX_ENABLE
            lock (luaEnvLock)
            {
#endif
            var _L = L;
            lock (refQueue)
            {
                while (refQueue.Count > 0)
                {
                    GCAction gca = refQueue.Dequeue();
                    translator.ReleaseLuaBase(_L, gca.Reference, gca.IsDelegate);
                }
            }
#if !XLUA_GENERAL
            last_check_point = translator.objects.Check(last_check_point, max_check_per_tick, object_valid_checker, translator.reverseMap);
#endif
#if THREAD_SAFE || HOTFIX_ENABLE
        }
#endif
        }
Esempio n. 10
0
        private void DoRenamed(GCAction action)
        {
            //Does it still exist?
            if (!FileOrDirectoryExists(action.Path))
            {
                return;
            }


            if (ThisIsFromMe(action))
            {
                return;
            }

            Object o = FindDiskItem(action);

            // We should already have this file in DB unless its a new folder thats just got renamed
            if (!Directory.Exists(action.Path) && o == null)
            {
                return;
            }

            if (o == null)
            {
                // new folder
                DoNew(action);
                return;
            }

            //        @GET
            // @Path("/rename")
            // @Produces(MediaType.APPLICATION_JSON)
            // @Transactional
            //public FileMetaUpdate rename(
            //        @QueryParam("apiId") String apiId,
            //        @QueryParam("key") String key,
            //        @QueryParam("docId") Long docId,
            //        @QueryParam("filename") String fileName,
            //        @QueryParam("folder") Boolean isFolder) {

            if (o is DiskItem)
            {
                DiskItem item    = (DiskItem)o;
                var      request = newReq("/rest/sync/rename");

                SetUpRequest(request);
                request.AddParameter("docId", item.Id);
                request.AddParameter("folder", item.Folder);
                request.AddParameter("filename", Path.GetFileName(action.Path));

                var response = client.Execute <NewFileMeta>(request);
                if (response.ResponseStatus == ResponseStatus.Completed)
                {
                    NewFileMeta meta = response.Data;
                    if (meta.success)
                    {
                        // what do if anything?
                        return;
                    }
                }
                Console.Error.Write("Could not rename file ? ", action.Path);
            }

            // we do nothing if workspace
            Console.Error.Write("Workspace NOT being renamed ? ", action.Path);
        }
Esempio n. 11
0
        private Object FindParentDiskItem(GCAction action)
        {
            string[] directories = action.Path.Split(Path.DirectorySeparatorChar);

            string    path                = "";
            Workspace workspace           = null;
            DiskItem  parent              = null;
            bool      matchRoot           = true;
            bool      matchWorkspace      = false;
            bool      matchFoldersOrFiles = false;
            int       index               = 1;

            foreach (string p in directories)
            {
                if (path == "")
                {
                    path = p + "\\";
                }
                else
                {
                    path = Path.Combine(path, p);
                }

                if (matchRoot && path == rootDir)
                {
                    matchRoot      = false;
                    matchWorkspace = true;
                }
                else
                if (matchWorkspace)
                {
                    var wrs = from w in db.Table <Workspace>()
                              where w.Path.Equals(p)
                              select w;
                    if (wrs.Count() != 0)
                    {
                        workspace = wrs.FirstOrDefault <Workspace>();
                    }
                    // TODO no workspace?
                    matchWorkspace      = false;
                    matchFoldersOrFiles = true;
                }
                else
                if (matchFoldersOrFiles)
                {
                    if (parent == null)
                    {
                        IEnumerable <DiskItem> d = db.Query <DiskItem>("select * from DiskItem where Path = ? and WorkspaceId = ?", p, workspace.Id);
                        DiskItem it = d.FirstOrDefault <DiskItem>();
                        if (it != null && index + 1 == directories.Length)
                        {
                            parent = it;
                        }
                    }
                    else
                    {
                        IEnumerable <DiskItem> d = db.Query <DiskItem>("select * from DiskItem where Path = ? and WorkspaceId = ? and FolderId = ? ", p, workspace.Id, parent.Id);
                        DiskItem item            = d.FirstOrDefault <DiskItem>();
                        if (item != null && index + 1 == directories.Length)
                        {
                            parent = item;
                        }
                    }
                }
                index++;
            }

            if (parent != null)
            {
                return(parent);
            }
            if (workspace != null)
            {
                return(workspace);
            }


            return(null);
        }
Esempio n. 12
0
        private Object FindDiskItem(GCAction action)
        {
            string path;

            if (action.Action == GCAction.RENAMED)
            {
                path = action.OldPath;
            }
            else
            {
                path = action.Path;
            }

            string[] directories = path.Split(Path.DirectorySeparatorChar);

            path = "";
            Workspace workspace           = null;
            DiskItem  item                = null;
            bool      matchRoot           = true;
            bool      matchWorkspace      = false;
            bool      matchFoldersOrFiles = false;

            foreach (string p in directories)
            {
                if (path == "")
                {
                    path = p + "\\";
                }
                else
                {
                    path = Path.Combine(path, p);
                }

                if (matchRoot && path == rootDir)
                {
                    matchRoot      = false;
                    matchWorkspace = true;
                }
                else
                if (matchWorkspace)
                {
                    var wrs = from w in db.Table <Workspace>()
                              where w.Path.Equals(p)
                              select w;
                    if (wrs.Count() != 0)
                    {
                        workspace = wrs.FirstOrDefault <Workspace>();
                    }
                    // TODO no workspace?
                    matchWorkspace      = false;
                    matchFoldersOrFiles = true;
                }
                else
                if (matchFoldersOrFiles)
                {
                    if (item == null)
                    {
                        IEnumerable <DiskItem> d = db.Query <DiskItem>("select * from DiskItem where Path = ? and WorkspaceId = ?", p, workspace.Id);
                        item = d.FirstOrDefault <DiskItem>();
                        if (item == null)
                        {
                            return(null);              // means we could not find any match
                        }
                    }
                    else
                    {
                        IEnumerable <DiskItem> d = db.Query <DiskItem>("select * from DiskItem where Path = ? and WorkspaceId = ? and FolderId = ? ", p, workspace.Id, item.Id);
                        item = d.FirstOrDefault <DiskItem>();
                        if (item == null)
                        {
                            return(null);
                        }
                    }
                }
            }

            if (item != null)
            {
                return(item);
            }
            if (workspace != null)
            {
                return(workspace);
            }


            return(null);
        }
Esempio n. 13
0
        private void DoNew(GCAction action)
        {
            //Does it still exist?
            if (!FileOrDirectoryExists(action.Path))
            {
                return;                                      // can happen when creating a new folder that immediately gets a different name
            }
            if (ThisIsFromMe(action))
            {
                return;
            }

            RestRequest    request;
            FileAttributes attr = File.GetAttributes(action.Path);

            if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
            {
                request = newReq("/rest/sync/newFolder", Method.GET);
            }
            else
            {
                request = newReq("/rest/sync/new", Method.POST);
            }


            SetUpRequest(request);
            request.AddHeader("Content-Type", "multipart/form-data");

            request.AddParameter("apiId", apiId, ParameterType.QueryString);
            request.AddParameter("key", key, ParameterType.QueryString);

            DiskItem i = new DiskItem();
            Object   o = FindParentDiskItem(action);

            if (o == null)
            {
                Console.Error.Write("Unknown parent DIR cannot sync ?", action.Path);
                return;
            }
            if (o is Workspace)
            {
                request.AddParameter("workspaceId", ((Workspace)o).Id, ParameterType.QueryString);
                i.WorkspaceId = ((Workspace)o).Id;
            }
            else if (o is DiskItem)
            {
                DiskItem f = (DiskItem)o;
                request.AddParameter("workspaceId", f.WorkspaceId, ParameterType.QueryString);
                request.AddParameter("folderId", f.Id, ParameterType.QueryString);
                i.FolderId    = f.Id;
                i.WorkspaceId = f.WorkspaceId;
            }


            if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
            {
                request.AddParameter("folderName", Path.GetFileName(action.Path), ParameterType.QueryString);
                i.Folder = true;
            }
            else
            {
                request.AddFile("file", action.Path);
            }

            var response = client.Execute <NewFileMeta>(request);

            if (response.ResponseStatus == ResponseStatus.Completed)
            {
                NewFileMeta meta = response.Data;
                if (meta.success)
                {
                    // insert new DiskItem

                    i.Id       = (long)meta.docId;
                    i.FileName = Path.GetFileName(action.Path);
                    i.Action   = "ADD";
                    i.Created  = meta.created;
                    i.Path     = Path.GetFileName(action.Path);
                    if (!i.Folder)
                    {
                        FileInfo info = new FileInfo(action.Path);
                        i.Size = info.Length;
                    }
                    i.Version = 1;
                    db.Insert(i);
                }
            }
        }