public FolderListController(DBFilesystem filesystem, DBPath root) : base()
 {
     Filesystem           = filesystem;
     Root                 = root;
     NavigationItem.Title = Root.Equals(DBPath.Root) ? "Dropbox" : root.Name;
     TableView.Source     = new MyFolderTableViewSource(this);
 }
        public void MoveTo(string input)
        {
            DBError error;
            var     components = input.Split('/');
            int     startIndex = 0;
            DBPath  path       = Root;

            if (components[0].Length == 0)
            {
                path       = DBPath.Root;
                startIndex = 1;
            }

            foreach (var component in components)
            {
                if (component == "..")
                {
                    path = path.Parent;
                }
                else
                {
                    path = path.ChildPath(component);
                }
            }
            Filesystem.MovePath(FromPath, path, out error);
            Moving   = false;
            FromPath = null;
        }
        /// <summary>
        /// Method to save the Patrol Path using the Patrol ID and the Component
        /// </summary>
        /// <param name="pathID"></param>
        /// <param name="path"></param>
        /// <param name="component"></param>
        public static void SavePatrolPath(string pathID, PathPoint path, GameKeepComponent component)
        {
            if (path == null)
            {
                return;
            }

            pathID.Replace('\'', '/');             // we must replace the ', found no other way yet
            GameServer.Database.DeleteObject(DOLDB <DBPath> .SelectObjects(DB.Column(nameof(DBPath.PathID)).IsEqualTo(pathID)));
            PathPoint root = MovementMgr.FindFirstPathPoint(path);

            //Set the current pathpoint to the rootpoint!
            path = root;
            DBPath dbp = new DBPath(pathID, ePathType.Loop);

            GameServer.Database.AddObject(dbp);

            int i = 1;

            do
            {
                DBPathPoint dbpp = new DBPathPoint(path.X, path.Y, path.Z, path.MaxSpeed);
                int         x, y;
                SaveXY(component, dbpp.X, dbpp.Y, out x, out y);
                dbpp.X = x;
                dbpp.Y = y;
                dbpp.Z = dbpp.Z - component.Z;

                dbpp.Step     = i++;
                dbpp.PathID   = pathID;
                dbpp.WaitTime = path.WaitTime;
                GameServer.Database.AddObject(dbpp);
                path = path.Next;
            } while (path != null && path != root);
        }
        public async Task <List <IFile> > ListFiles(string directory)
        {
            var exs = FileExtensions.Select(x => "." + x).ToArray();
//			Console.WriteLine (filesystem.Status);
            var dbPath  = new DBPath(directory);
            var dbFiles = await filesystem.ListFolderAsync(dbPath);

            var q = from f in dbFiles
                    let n = f.Path.Name
                            where !n.StartsWith(".")
                            where f.IsFolder || (Array.IndexOf(exs, Path.GetExtension(n)) >= 0)
                            select(IFile) new DropboxFile(f, filesystem);

            DropboxDirectoryObserver dbObserver;

            if (!dbObservers.TryGetValue(directory, out dbObserver))
            {
                dbObserver = new DropboxDirectoryObserver();
                filesystem.AddObserverForPathAndChildren(dbObserver, dbPath, () => {
                    OnFilesChanged();
                });
                dbObservers.Add(directory, dbObserver);
            }

            return(q.ToList());
        }
        public static void UpdatePathInCache(string pathID)
        {
            log.DebugFormat("Updating path {0} in path cache.", pathID);

            DBPath dbpath = GameServer.Database.SelectObjects <DBPath>("`PathID` = @PathID", new QueryParameter("@PathID", pathID)).FirstOrDefault();

            if (dbpath != null)
            {
                if (m_pathCache.ContainsKey(pathID))
                {
                    m_pathCache[pathID] = dbpath;
                }
                else
                {
                    m_pathCache.Add(dbpath.PathID, dbpath);
                }
            }

            IList <DBPathPoint>           pathPoints = GameServer.Database.SelectObjects <DBPathPoint>("`PathID` = @PathID", new QueryParameter("@PathID", pathID));
            SortedList <int, DBPathPoint> pList      = new SortedList <int, DBPathPoint>();

            if (m_pathpointCache.ContainsKey(pathID))
            {
                m_pathpointCache[pathID] = pList;
            }
            else
            {
                m_pathpointCache.Add(pathID, pList);
            }

            foreach (DBPathPoint pathPoint in pathPoints)
            {
                m_pathpointCache[pathPoint.PathID].Add(pathPoint.Step, pathPoint);
            }
        }
        /// <summary>
        /// Overwrites
        /// </summary>
        public async Task <IFile> CreateFile(string path, byte[] contents)
        {
            var dbpath = new DBPath(path);

            // Delete it so that CreateFile overwrites
            try {
                await filesystem.DeletePathAsync(dbpath);
            } catch (Exception) {
            }

            var file = await filesystem.CreateFileAsync(dbpath);

            if (file == null)
            {
                throw new Exception("Failed to create file");
            }

            if (contents != null)
            {
                var r = await file.WriteDataAsync(Foundation.NSData.FromArray(contents));

                if (!r)
                {
                    throw new Exception("Failed to write contents of new file");
                }
            }

            file.Close();

            var fileInfo = await filesystem.FileInfoForPathAsync(dbpath);

            return(new DropboxFile(fileInfo, filesystem));
        }
Exemple #7
0
        public static void UpdatePathInCache(string pathID)
        {
            log.DebugFormat("Updating path {0} in path cache.", pathID);

            DBPath dbpath = GameServer.Database.SelectObject <DBPath>("PathID='" + GameServer.Database.Escape(pathID) + "'");

            if (dbpath != null)
            {
                if (m_pathCache.ContainsKey(pathID))
                {
                    m_pathCache[pathID] = dbpath;
                }
                else
                {
                    m_pathCache.Add(dbpath.PathID, dbpath);
                }
            }

            IList <DBPathPoint>           pathPoints = GameServer.Database.SelectObjects <DBPathPoint>("PathID='" + GameServer.Database.Escape(pathID) + "'");
            SortedList <int, DBPathPoint> pList      = new SortedList <int, DBPathPoint>();

            if (m_pathpointCache.ContainsKey(pathID))
            {
                m_pathpointCache[pathID] = pList;
            }
            else
            {
                m_pathpointCache.Add(pathID, pList);
            }

            foreach (DBPathPoint pathPoint in pathPoints)
            {
                m_pathpointCache[pathPoint.PathID].Add(pathPoint.Step, pathPoint);
            }
        }
        /// <summary>
        /// loads a path from the cache
        /// </summary>
        /// <param name="pathID">path to load</param>
        /// <returns>first pathpoint of path or null if not found</returns>
        public static PathPoint LoadPath(string pathID)
        {
            lock (LockObject)
            {
                if (m_pathCache.Count == 0)
                {
                    FillPathCache();
                }

                DBPath dbpath = null;

                if (m_pathCache.ContainsKey(pathID))
                {
                    dbpath = m_pathCache[pathID];
                }

                // even if path entry not found see if pathpoints exist and try to use it
                ePathType pathType = ePathType.Once;

                if (dbpath != null)
                {
                    pathType = (ePathType)dbpath.PathType;
                }

                SortedList <int, DBPathPoint> pathPoints = null;

                if (m_pathpointCache.ContainsKey(pathID))
                {
                    pathPoints = m_pathpointCache[pathID];
                }
                else
                {
                    pathPoints = new SortedList <int, DBPathPoint>();
                }

                PathPoint prev  = null;
                PathPoint first = null;

                foreach (DBPathPoint pp in pathPoints.Values)
                {
                    PathPoint p = new PathPoint(pp.X, pp.Y, pp.Z, pp.MaxSpeed, pathType);
                    p.WaitTime = pp.WaitTime;

                    if (first == null)
                    {
                        first = p;
                    }

                    p.Prev = prev;
                    if (prev != null)
                    {
                        prev.Next = p;
                    }

                    prev = p;
                }

                return(first);
            }
        }
        public async Task <IFile> GetFile(string path)
        {
            var dbpath = new DBPath(path);

            var fileInfo = await filesystem.FileInfoForPathAsync(dbpath);

            return(new DropboxFile(fileInfo, filesystem));
        }
 public FolderListController(DBFilesystem filesystem, DBPath root)
     : base()
 {
     Filesystem = filesystem;
     Root = root;
     NavigationItem.Title = Root.Equals (DBPath.Root) ? "Dropbox" : root.Name;
     TableView.Source = new MyFolderTableViewSource (this);
 }
        /// <summary>
        /// 数据备份
        /// </summary>
        /// <param name="fr"></param>
        public string DateBackups(FormCollection fr)
        {
            bll.Errorlogbll errorlog = new bll.Errorlogbll();
            string          path     = "E:\\fabu\\ExcelFile\\database";

            if (!string.IsNullOrWhiteSpace(path))
            {
                mess = "";
                string DBPath;//备份成功后的文件在服务器的完全路径
                bool   bo = errorlog.DateBackups(path, out mess, out DBPath);
                if (bo)
                {
                    model.errorlog err = new model.errorlog()
                    {
                        ErrorMsg        = "备份数据库",
                        errorMsgDetails = "数据库备份",
                        errorSrc        = "ErrorloController.cs->DateBackups()",
                        errorTime       = DateTime.Now,
                        UserId          = userInfo.User.Id,
                        operation       = 2
                    };
                    errorlog.InsertErrorlog(err);

                    FileInfo   file = new FileInfo(Server.MapPath("~/ErrorlogPath.txt"));
                    FileStream sf   = file.Open(FileMode.OpenOrCreate);

                    StreamReader sr  = new StreamReader(sf, System.Text.Encoding.UTF8);
                    string       str = sr.ReadToEnd();
                    sr.Close();
                    str = DBPath.Replace(".bak", "") + "\r\n" + str;
                    StreamWriter sw = new StreamWriter(file.Open(FileMode.OpenOrCreate), System.Text.Encoding.UTF8);
                    sw.Write(str);
                    sw.Close();

                    return(bo.ToString() + "|" + DBPath);
                }
                else
                {
                    model.errorlog err = new model.errorlog()
                    {
                        ErrorMsg        = "备份数据库",
                        errorMsgDetails = mess,
                        errorSrc        = "ErrorloController.cs->DateBackups()",
                        errorTime       = DateTime.Now,
                        UserId          = userInfo.User.Id,
                        operation       = 2
                    };
                    errorlog.InsertErrorlog(err);
                    return(mess);
                }
            }
            //string st=  Server.MapPath("~/ErrorlogPath.txt");
            //FileInfo file = new FileInfo(st);
            // FileStream sf = file.Open(FileMode.OpenOrCreate);
            // StreamReader sr = new StreamReader(sf);
            // string str = sr.ReadLine();
            return("请输入文件路径!");
        }
        /// <summary>
        /// Method to retrieve the Patrol Path from the Patrol ID and Component
        ///
        /// We need this because we store this all using our offset system
        /// </summary>
        /// <param name="pathID">The path ID, which is the Patrol ID</param>
        /// <param name="component">The Component object</param>
        /// <returns>The Patrol path</returns>
        public static PathPoint LoadPatrolPath(string pathID, GameKeepComponent component)
        {
            SortedList sorted = new SortedList();

            pathID.Replace('\'', '/'); // we must replace the ', found no other way yet
            DBPath dbpath = GameServer.Database.SelectObjects <DBPath>("`PathID` = @PathID", new QueryParameter("@PathID", pathID)).FirstOrDefault();
            IList <DBPathPoint> pathpoints = null;
            ePathType           pathType   = ePathType.Once;

            if (dbpath != null)
            {
                pathType = (ePathType)dbpath.PathType;
            }

            if (pathpoints == null)
            {
                pathpoints = GameServer.Database.SelectObjects <DBPathPoint>("`PathID` = @PathID", new QueryParameter("@PathID", pathID));
            }

            foreach (DBPathPoint point in pathpoints)
            {
                sorted.Add(point.Step, point);
            }

            PathPoint prev  = null;
            PathPoint first = null;

            for (int i = 0; i < sorted.Count; i++)
            {
                DBPathPoint pp = (DBPathPoint)sorted.GetByIndex(i);
                PathPoint   p  = new PathPoint(pp.X, pp.Y, pp.Z, pp.MaxSpeed, pathType);

                int x, y;
                LoadXY(component, pp.X, pp.Y, out x, out y);
                p.X = x;
                p.Y = y;
                p.Z = component.AbstractKeep.Z + p.Z;

                p.WaitTime = pp.WaitTime;

                if (first == null)
                {
                    first = p;
                }

                p.Prev = prev;
                if (prev != null)
                {
                    prev.Next = p;
                }

                prev = p;
            }

            return(first);
        }
		public Task<bool> DeletePathAsync (DBPath path)
		{
			return Task.Factory.StartNew (p => {
				DBError err;
				var results = DeletePath ((DBPath)p, out err);
				if (err != null)
					throw new DBException (err);
				return results;
			}, path);
		}
		public Task<bool> MovePathAsync (DBPath fromPath, DBPath toPath)
		{
			return Task<bool>.Factory.StartNew (() => {
				DBError err;
				var results = MovePath (fromPath, toPath, out err);
				if (err != null)
					throw new DBException (err);
				return results;
			});
		}
		public Task<DBFileInfo []> ListFolderAsync (DBPath path)
		{
			return Task.Factory.StartNew (p => {
				DBError err;
				var results = ListFolder ((DBPath)p, out err);
				if (err != null)
					throw new DBException (err);
				return results;
			}, path);
		}
		public Task<DBFile> CreateFileAsync (DBPath path)
		{
			return Task.Factory.StartNew (p => {
				DBError err;
				var results = CreateFile ((DBPath)p, out err);
				if (err != null)
					throw new DBException (err);
				return results;
			}, path);
		}
        public async Task <bool> Move(string newPath)
        {
            var newDBPath = new DBPath(newPath);
            var r         = await fileSystem.MovePathAsync(fileInfo.Path, newDBPath);

            if (r)
            {
                fileInfo = await fileSystem.FileInfoForPathAsync(newDBPath);
            }
            return(r);
        }
 public Task <bool> MovePathAsync(DBPath fromPath, DBPath toPath)
 {
     return(Task <bool> .Factory.StartNew(() => {
         DBError err;
         var results = MovePath(fromPath, toPath, out err);
         if (err != null)
         {
             throw new DBException(err);
         }
         return results;
     }));
 }
 public Task <DBFile> CreateFileAsync(DBPath path)
 {
     return(Task.Factory.StartNew(p => {
         DBError err;
         var results = CreateFile((DBPath)p, out err);
         if (err != null)
         {
             throw new DBException(err);
         }
         return results;
     }, path));
 }
 public Task <bool> DeletePathAsync(DBPath path)
 {
     return(Task.Factory.StartNew(p => {
         DBError err;
         var results = DeletePath((DBPath)p, out err);
         if (err != null)
         {
             throw new DBException(err);
         }
         return results;
     }, path));
 }
 public Task <DBFileInfo []> ListFolderAsync(DBPath path)
 {
     return(Task.Factory.StartNew(p => {
         DBError err;
         var results = ListFolder((DBPath)p, out err);
         if (err != null)
         {
             throw new DBException(err);
         }
         return results;
     }, path));
 }
		public DVCFiles (DBPath path) : base (UITableViewStyle.Plain, null, true)
		{
			this.path = path;
			LoadFiles ();

			Root = new RootElement (string.IsNullOrWhiteSpace (path.Name) ? "/" : path.Name) {
				new Section (){
					new StringElement ("Loading...") {
						Alignment = UITextAlignment.Center
					}
				}
			};
		}
Exemple #23
0
        public DVCFiles(DBPath path) : base(UITableViewStyle.Plain, null, true)
        {
            this.path = path;
            LoadFiles();

            Root = new RootElement(string.IsNullOrWhiteSpace(path.Name) ? "/" : path.Name)
            {
                new Section()
                {
                    new StringElement("Loading...")
                    {
                        Alignment = UITextAlignment.Center
                    }
                }
            };
        }
Exemple #24
0
        /// <summary>
        /// Saves the path into the database
        /// </summary>
        /// <param name="pathID">The path ID</param>
        /// <param name="path">The path waypoint</param>
        public static void SavePath(string pathID, PathPoint path)
        {
            if (path == null)
            {
                return;
            }

            pathID.Replace('\'', '/');

            // First delete any path with this pathID from the database

            DBPath dbpath = GameServer.Database.SelectObject <DBPath>("PathID='" + GameServer.Database.Escape(pathID) + "'");

            if (dbpath != null)
            {
                GameServer.Database.DeleteObject(dbpath);
            }

            foreach (DBPathPoint pp in GameServer.Database.SelectObjects <DBPathPoint>("PathID='" + GameServer.Database.Escape(pathID) + "'"))
            {
                GameServer.Database.DeleteObject(pp);
            }

            // Now add this path and iterate through the PathPoint linked list to add all the path points

            PathPoint root = FindFirstPathPoint(path);

            //Set the current pathpoint to the rootpoint!
            path   = root;
            dbpath = new DBPath(pathID, root.Type);
            GameServer.Database.AddObject(dbpath);

            int i = 1;

            do
            {
                DBPathPoint dbpp = new DBPathPoint(path.X, path.Y, path.Z, path.MaxSpeed);
                dbpp.Step     = i++;
                dbpp.PathID   = pathID;
                dbpp.WaitTime = path.WaitTime;
                GameServer.Database.AddObject(dbpp);
                path = path.Next;
            }           while (path != null && path != root);

            UpdatePathInCache(pathID);
        }
Exemple #25
0
        /// <summary>
        /// Saves the path into the database
        /// </summary>
        /// <param name="pathID">The path ID</param>
        /// <param name="path">The path waypoint</param>
        public static void SavePath(string pathID, PathPoint path)
        {
            if (path == null)
            {
                return;
            }

            pathID.Replace('\'', '/');

            // First delete any path with this pathID from the database

            var dbpath = DOLDB <DBPath> .SelectObject(DB.Column(nameof(DBPath.PathID)).IsEqualTo(pathID));

            if (dbpath != null)
            {
                GameServer.Database.DeleteObject(dbpath);
            }

            GameServer.Database.DeleteObject(DOLDB <DBPathPoint> .SelectObjects(DB.Column(nameof(DBPathPoint.PathID)).IsEqualTo(pathID)));

            // Now add this path and iterate through the PathPoint linked list to add all the path points

            PathPoint root = FindFirstPathPoint(path);

            //Set the current pathpoint to the rootpoint!
            path   = root;
            dbpath = new DBPath(pathID, root.Type);
            GameServer.Database.AddObject(dbpath);

            int i = 1;

            do
            {
                DBPathPoint dbpp = new DBPathPoint((int)path.Position.X, (int)path.Position.Y, (int)path.Position.Z, path.MaxSpeed);
                dbpp.Step     = i++;
                dbpp.PathID   = pathID;
                dbpp.WaitTime = path.WaitTime;
                GameServer.Database.AddObject(dbpp);
                path = path.Next;
            }           while (path != null && path != root);

            UpdatePathInCache(pathID);
        }
Exemple #26
0
        bool IDBBase.SnapshotSupported(string dbName)
        {
            string strKey = DBPath.ToLower() + ";" + dbName.ToLower();

            if (mdictSnapshot.ContainsKey(strKey))
            {
                return(mdictSnapshot[strKey]);
            }
            else
            {
                bool   bStatus = false;
                string strSQL  = @"if exists(select 1 from sysobjects where name = 'sysdatabases' and xtype = 'V' )
begin
	if exists( select 1 from sys.databases where name = '{0}' and snapshot_isolation_state_desc = 'ON' )
		select 1 as SnapshotStatus
	else
		select 0 as SnapshotStatus
end
else
	select 0 as SnapshotStatus"    ;

                strSQL = string.Format(strSQL, dbName);

                using (SQLiteDataAdapter da = new SQLiteDataAdapter(strSQL, BulidConnectString_Master()))
                {
                    using (DataTable dt = new DataTable())
                    {
                        da.Fill(dt);
                        if (dt.Rows.Count > 0)
                        {
                            bStatus = Convert.ToBoolean(Convert.ToInt32(dt.Rows[0]["SnapshotStatus"]));
                        }
                    }
                }

                mdictSnapshot.Add(strKey, bStatus);
                return(bStatus);
            }
        }
Exemple #27
0
		public void DownloadFile(string path)
		{
			ThrowExceptionIfAppNotLinked();

			try
			{
				Task.Factory.StartNew(() =>
				{
					DBError error = null;
					DBFile file = null;
					var dbPath = new DBPath(path);

					file = _fileSystem.OpenFile(dbPath, out error);
					if (error != null)
						throw new Exception(error.Description);

						if(file.NewerStatus == null)
						{
							byte[] bytes = null;
							try
							{
								//Tracing.Log("iOSDropboxService - DownloadFile - File is already latest version; getting {0}", path);
								var data = file.ReadData(out error);
								if (error != null)
									throw new Exception(error.Description);

								bytes = new byte[data.Length];
								System.Runtime.InteropServices.Marshal.Copy(data.Bytes, bytes, 0, Convert.ToInt32(data.Length));
							}
							finally
							{
								if (file != null)
									file.Close();
							}

							if (OnCloudFileDownloaded != null)
								OnCloudFileDownloaded(path, bytes);
						}
						else
						{
							//Tracing.Log("iOSDropboxService - DownloadFile - File needs to be updated; adding observer to {0}", path);
							_watchedFiles.Add(file);
							file.AddObserver(this, () => {
								ProcessWatchedFile(file, path);
							});
						}
				});
			}
			catch(AggregateException ae)
			{
				ae.Handle((ex) =>
				{
					return false;
				});
			}
		}
		public Task<bool> CreateDirectory (string path)
		{
			var dbpath = new DBPath (path);

			return filesystem.CreateFolderAsync (dbpath);
		}
		public async Task<List<IFile>> ListFiles (string directory)
		{
			var exs = FileExtensions.Select (x => "." + x).ToArray ();
//			Console.WriteLine (filesystem.Status);
			var dbPath = new DBPath (directory);
			var dbFiles = await filesystem.ListFolderAsync (dbPath);

			var q = from f in dbFiles
					let n = f.Path.Name
					where !n.StartsWith (".")
					where f.IsFolder || (Array.IndexOf (exs, Path.GetExtension (n)) >= 0)
					select (IFile)new DropboxFile (f, filesystem);

			DropboxDirectoryObserver dbObserver;

			if (!dbObservers.TryGetValue (directory, out dbObserver)) {
				dbObserver = new DropboxDirectoryObserver ();
				filesystem.AddObserverForPathAndChildren (dbObserver, dbPath, () => {
					OnFilesChanged ();
				});
				dbObservers.Add (directory, dbObserver);
			}

			return q.ToList ();
		}
		public async Task<bool> Move (string newPath)
		{
			var newDBPath = new DBPath (newPath);
			var r = await fileSystem.MovePathAsync (fileInfo.Path, newDBPath);
			if (r) {
				fileInfo = await fileSystem.FileInfoForPathAsync (newDBPath);
			}
			return r;
		}
		public async Task<IFile> GetFile (string path)
		{
			var dbpath = new DBPath (path);

			var fileInfo = await filesystem.FileInfoForPathAsync (dbpath);

			return new DropboxFile (fileInfo, filesystem);
		}
		/// <summary>
		/// Overwrites
		/// </summary>
		public async Task<IFile> CreateFile (string path, byte[] contents)
		{
			var dbpath = new DBPath (path);

			// Delete it so that CreateFile overwrites
			try {
				await filesystem.DeletePathAsync (dbpath);				
			} catch (Exception) {
			}

			var file = await filesystem.CreateFileAsync (dbpath);
			if (file == null)
				throw new Exception ("Failed to create file");

			if (contents != null) {
				var r = await file.WriteDataAsync (Foundation.NSData.FromArray (contents));
				if (!r)
					throw new Exception ("Failed to write contents of new file");
			}

			file.Close ();

			var fileInfo = await filesystem.FileInfoForPathAsync (dbpath);

			return new DropboxFile (fileInfo, filesystem);
		}
        public Task <bool> CreateDirectory(string path)
        {
            var dbpath = new DBPath(path);

            return(filesystem.CreateFolderAsync(dbpath));
        }
Exemple #34
0
		public void CreateFolder(string path)
		{
			ThrowExceptionIfAppNotLinked();

			DBError error = null;
			var dbPath = new DBPath(path);
			_fileSystem.CreateFolder(dbPath, out error);
			if(error != null)
				throw new Exception(error.Description);
		}
Exemple #35
0
		public bool FileExists(string path)
		{
			ThrowExceptionIfAppNotLinked();

			// Unlike the Android SDK, there is no method to check if a file exists... 
			DBError error = null;
			DBPath dbPath = new DBPath(path);
			var fileInfo = _fileSystem.FileInfoForPath(dbPath, out error);
			if(error != null)
				throw new Exception(error.Description);

			return fileInfo != null;
		}
Exemple #36
0
		public void WatchFile(string path)
		{
			ThrowExceptionIfAppNotLinked();

			DBError error = null;
			var dbPath = new DBPath(path);
			var file = _fileSystem.OpenFile(dbPath, out error);
			if (error != null)
				throw new Exception(error.Description);
			if (file == null)
				return;

			file.AddObserver(this, () => {
				ProcessWatchedFile(file, path);
			});
			_watchedFiles.Add(file);

		}
		public Task<string> FetchShareLinkAsync (DBPath path, bool shorten)
		{
			return Task<string>.Factory.StartNew (() => {
				DBError err;
				var results = FetchShareLink (path, shorten, out err);
				if (err != null)
					throw new DBException (err);
				return results;
			});
		}
        void ShowCamera()
        {
            CheckDropboxLinked();

            var picker = new MediaPicker();
            MediaPickerController controller = picker.GetTakePhotoUI (new StoreCameraMediaOptions {
                Name = "latest.jpg",
                Directory = "Shooter"
            });

            // On iPad, you'll use UIPopoverController to present the controller
            PresentViewController (controller, true, null);
            controller.GetResultAsync().ContinueWith (t => {
                controller.DismissViewControllerAsync(true).ContinueWith( (t2) => {
                    // Move to Dropbox.
                    if (t.Status == TaskStatus.RanToCompletion) {
                        MediaFile photoFile = t.Result;

                        UIImage originalImage = new UIImage(photoFile.Path);
                        NSData imageData = ResizeImage(originalImage, 0.3f).AsJPEG();

                        DBPath path = new DBPath(string.Format("{0:yyyy-MM-dd-HH-mm-ss}.jpg", DateTime.Now));
                        DBError err;
                        DBFile file = DBFilesystem.SharedFilesystem.CreateFile(path, out err);
                        file.WriteDataAsync(imageData).ContinueWith(t3 => {
                            file.Close();
                        });

                        Task.Run(() => {
                            System.Threading.Thread.Sleep(1000);
                        }).ContinueWith((t3) => {
                            ShowCamera();
                        }, TaskScheduler.FromCurrentSynchronizationContext());
                    }
                });
            }, TaskScheduler.FromCurrentSynchronizationContext());
        }
Exemple #39
0
		public void UploadFile(string path, byte[] data)
		{
			ThrowExceptionIfAppNotLinked();

			try
			{
				Task.Factory.StartNew(() =>
				{
					DBError error = null;
					DBFile file = null;
					var dbPath = new DBPath(path);

					try
					{
						// Unlike the Android SDK, there is no method to check if a file exists... 
						var fileInfo = _fileSystem.FileInfoForPath(dbPath, out error);
//						if (error != null) // Ignore error; API always returns 2002 error when the file doesn't exist
//							throw new Exception(error.Description);

						if (fileInfo == null)
							file = _fileSystem.CreateFile(dbPath, out error);
						else
							file = _fileSystem.OpenFile(dbPath, out error);
						if (error != null)
							throw new Exception(error.Description);

						NSData nsData = NSData.FromArray(data);
						file.WriteData(nsData, out error);
						if (error != null)
							throw new Exception(error.Description);
					}
					finally
					{
						if (file != null)
							file.Close();
					}
				});
			}
			catch(AggregateException ae)
			{
				ae.Handle((ex) =>
				{
					return false;
				});
			}

		}
		public Task<DBFile> OpenThumbnailAsync (DBPath path, DBThumbSize size, DBThumbFormat format)
		{
			return Task<DBFile>.Factory.StartNew (() => {
				DBError err;
				var results = OpenThumbnail (path, size, format, out err);
				if (err != null)
					throw new DBException (err);
				return results;
			});
		}