예제 #1
0
    /// <summary>
    /// Gets the timestamp of the storage file containing the sequence numbers. This allows processing to
    /// ignore duplicates or identify missing uploads
    /// </summary>
    /// <returns>A string containing a Unixtime</returns>
    private static string GetPersistStoreCreateTime()
    {
        IsolatedStorageFile store = getStore();
        string metaFile           = LocalyticsSession.directoryName + @"\" + LocalyticsSession.metaFileName;

        if (!store.FileExists(metaFile))
        {
            SetNextSequenceNumber("1");
        }

        DateTimeOffset dto = store.GetCreationTime(metaFile);
        int            secondsSinceUnixEpoch = (int)Math.Round((dto.DateTime - new DateTime(1970, 1, 1).ToLocalTime()).TotalSeconds);

        return(secondsSinceUnixEpoch.ToString());
    }
        public override RscStoreProperties GetFileProperties(string path)
        {
            RscStoreProperties sp = new RscStoreProperties();

            IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();

            sp.CreationTime   = store.GetCreationTime(path).DateTime;
            sp.LastWriteTime  = store.GetLastWriteTime(path).DateTime;
            sp.LastAccessTime = store.GetLastAccessTime(path).DateTime;

            IsolatedStorageFileStream stream = store.OpenFile(path, FileMode.Open, FileAccess.Read);

            sp.Length = stream.Length;
            stream.Close();

            return(sp);
        }
예제 #3
0
 public static long getFileExistTime(string path)
 {
     try
     {
         using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication())
         {
             if (!file.FileExists(path))
             {
                 return(0L);
             }
             return((long)DateTime.Now.Subtract(file.GetCreationTime(path).DateTime).TotalSeconds);
         }
     }
     catch (Exception exception)
     {
         Log.e("storage", "getCreationTime file fail" + exception);
     }
     return(0L);
 }
예제 #4
0
 public static long getFileExistTime(string path)
 {
     try
     {
         using (IsolatedStorageFile userStoreForApplication = IsolatedStorageFile.GetUserStoreForApplication())
         {
             long result;
             if (!userStoreForApplication.FileExists(path))
             {
                 result = 0L;
                 return(result);
             }
             result = (long)DateTime.Now.Subtract(userStoreForApplication.GetCreationTime(path).DateTime).TotalSeconds;
             return(result);
         }
     }
     catch (Exception)
     {
     }
     return(0L);
 }
예제 #5
0
        public async Task <IFileStats> GetFileStats(CancellationToken cancellationToken = new CancellationToken())
        {
            await AwaitExtensions.SwitchOffMainThreadAsync(cancellationToken);

            var localCreationTime   = _root.GetCreationTime(_path);
            var localLastWriteTime  = _root.GetLastWriteTime(_path);
            var localLastAccessTime = _root.GetLastAccessTime(_path);

            var fileStats = new FileSystemFileStats()
            {
                Name              = _name,
                Extension         = System.IO.Path.GetExtension(_name),
                CreationTime      = localCreationTime.DateTime,
                CreationTimeUTC   = localCreationTime.UtcDateTime,
                LastWriteTime     = localLastWriteTime.DateTime,
                LastWriteTimeUTC  = localLastWriteTime.UtcDateTime,
                LastAccessTime    = localLastAccessTime.DateTime,
                LastAccessTimeUTC = localLastAccessTime.UtcDateTime
            };

            return(fileStats);
        }
예제 #6
0
        public void GetCreationTime()
        {
            IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly();

            // This is not causing an exception
            isf.GetCreationTime("doesntexist");
            isf.GetCreationTime("dir/doesntexist");

            try
            {
                isf.GetCreationTime(String.Empty);
                Assert.Fail("#Exc1");
            }
            catch (ArgumentException)
            {
            }

            try
            {
                isf.GetCreationTime("   ");
                Assert.Fail("#Exc2");
            }
            catch (ArgumentException)
            {
            }

            isf.Close();
            try
            {
                isf.GetCreationTime("doesntexist");
                Assert.Fail("#Exc3");
            }
            catch (InvalidOperationException)
            {
            }

            isf.Dispose();
            try
            {
                isf.GetCreationTime("doesntexist");
                Assert.Fail("#Exc4");
            }
            catch (ObjectDisposedException)
            {
            }
        }
예제 #7
0
        /// <summary>
        /// 获取文件列表
        /// </summary>
        private void GetFileList()
        {
            try
            {
                using (IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    string[] files = iso.GetFileNames();
                    rcList = new List <Record>();
                    foreach (string f in files)
                    {
                        Record rec = new Record()
                        {
                            FileName = f,
                            SaveTime = iso.GetCreationTime(f).DateTime
                        };
                        rcList.Add(rec);
                    }

                    this.fileList.ItemsSource = rcList;
                }
            }
            catch { }
        }
예제 #8
0
        /// <summary>
        /// Gibt einen Isolated Storage Pfad zu einem Profilbild einer Person an.
        /// Bei Bedarf wird dieses erst von Server geladen.
        /// </summary>
        /// <param name="authenticationUserId">Nutzer dessen Profilbild geladen werden soll.</param>
        /// <returns></returns>
        internal static async Task <string> GetProfilePicture(string authenticationUserId)
        {
            if (authenticationUserId == null)
            {
                return(null);
            }
            try
            {
                string fileName = authenticationUserId + ".png";
                using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    if (file.FileExists(fileName))
                    {
                        //Wenn die Datei weniger als einen Monat alt ist vewende sie.
                        if ((file.GetCreationTime(fileName).DateTime - DateTime.Now) < TimeSpan.FromDays(30))
                        {
                            return(fileName);
                        }
                        else //Ansonsten löschen und neu downloaden, dadurch immer schön aktuell.
                        {
                            file.DeleteFile(fileName);
                        }
                    }

                    //LiveConnectClient bereitstellen
                    LiveConnectClient client = new LiveConnectClient(session);

                    //Pfad des Profilbildes von Windows Live abrufen.
                    var path = authenticationUserId + "/picture";

                    var task = client.DownloadAsync((string)(await client.GetAsync(path)).Result["location"]);
                    using (var fileStream = (await task).Stream)

                    //Filestream auf Platte abspeichern
                    {
                        using (FileStream fileStreamSave = file.CreateFile(fileName))
                        {
                            byte[] buffer = new byte[8 * 1024];
                            int    length;

                            while ((length = fileStream.Read(buffer, 0, buffer.Length)) > 0)
                            {
                                fileStreamSave.Write(buffer, 0, length);
                            }

                            fileStreamSave.Flush();
                        }
                    }

                    return(fileName);
                }
            }
            catch (Exception e)
            {
                //Wenn Debugger vorhanden ist, Fehler beachten ansonsten Silent einfach ohne Profilbild arbeiten.
                if (System.Diagnostics.Debugger.IsAttached)
                {
                    throw new Exception("Could not load profile picture.", e);
                }
                else
                {
                    return(null);
                }
            }
        }
        public override DateTimeOffset GetFolderCreationTime(string path)
        {
            IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();

            return(store.GetCreationTime(path));
        }
예제 #10
0
 public DateTimeOffset GetCreationTime(string path)
 {
     return(WrappedSubject.GetCreationTime(path));
 }