Наследование: IBasicProperties, IStorageItemExtraProperties
Пример #1
0
        public async static Task <string> GetFileSizeToStringAsync(this StorageFile file)
        {
            Windows.Storage.FileProperties.BasicProperties basicProperties = await file.GetBasicPropertiesAsync();

            ulong bytes = basicProperties.Size;

            double byteCount = (double)bytes;
            string size      = "0 Bytes";

            if (byteCount >= 1073741824.0)
            {
                size = String.Format("{0:##.##}", byteCount / 1073741824.0) + " GB";
            }
            else if (byteCount >= 1048576.0)
            {
                size = String.Format("{0:##.##}", byteCount / 1048576.0) + " MB";
            }
            else if (byteCount >= 1024.0)
            {
                size = String.Format("{0:##.##}", byteCount / 1024.0) + " KB";
            }
            else if (byteCount > 0 && byteCount < 1024.0)
            {
                size = byteCount.ToString() + " Bytes";
            }

            return(size);
        }
        public async void TextProperty(ClassListStroce cc)
        {
            var resourceLoader = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView();



            // Get file's basic properties.
            Windows.Storage.FileProperties.BasicProperties basicProperties =
                await(await StorageFolder.GetFolderFromPathAsync(cc.Path)).GetBasicPropertiesAsync();


            string fileSize = string.Format("{0:n0}", basicProperties.Size);


            //  Windows.Storage.FileAttributes folderAttributes = cc.storageFile.Attributes;

            // if ((folderAttributes & Windows.Storage.FileAttributes.ReadOnly) == Windows.Storage.FileAttributes.ReadOnly)
            // Debug.WriteLine("The item is read-only.");

            //  if ((folderAttributes & Windows.Storage.FileAttributes.Directory) == Windows.Storage.FileAttributes.Directory)
            // Debug.WriteLine("The item is a folder.");

            //  if ((folderAttributes & Windows.Storage.FileAttributes.Archive) == Windows.Storage.FileAttributes.Archive)
            //  Debug.WriteLine("The item is archived.");

            //  if ((folderAttributes & Windows.Storage.FileAttributes.Temporary) == Windows.Storage.FileAttributes.Temporary)
            //   Debug.WriteLine("The item is temporary.");


            textName.Text = resourceLoader.GetString("NameText") + ": " + (await StorageFolder.GetFolderFromPathAsync(cc.Path)).Name;
            var thumbnaildstorageFolder = await(await StorageFolder.GetFolderFromPathAsync(cc.Path)).GetScaledImageAsThumbnailAsync(ThumbnailMode.SingleItem, 40, ThumbnailOptions.UseCurrentScale);

            // MessageDialog messageDialog = new MessageDialog(fileProperties.ToString(), resourceLoader.GetString("InfoText"));
            //await messageDialog.ShowAsync();
            this.Title = resourceLoader.GetString("InfoText");
            BitmapImage          image     = null;
            StorageItemThumbnail thumbnail = (StorageItemThumbnail)thumbnaildstorageFolder;

            image = new BitmapImage();
            image.SetSource(thumbnail);
            img.Source = image;



            textTip.Text  = resourceLoader.GetString("TipText") + ": ";
            textTip1.Text = (await StorageFolder.GetFolderFromPathAsync(cc.Path)).DisplayType;

            textpath.Text  = resourceLoader.GetString("PathText") + ": ";
            textpath1.Text = (await StorageFolder.GetFolderFromPathAsync(cc.Path)).Path;

            textcreate.Text  = resourceLoader.GetString("CreatText") + ": ";
            textcreate1.Text = (await StorageFolder.GetFolderFromPathAsync(cc.Path)).DateCreated.ToString();
            textizm.Text     = resourceLoader.GetString("IzmenText") + ": ";
            textizm1.Text    = basicProperties.DateModified.ToLocalTime().ToString();

            // textsize.Text = resourceLoader.GetString("SizeText") + ": ";
            //  textsize1.Text = GetFileSize(basicProperties);
        }
Пример #3
0
        /// <summary>
        /// Get file size in KB
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        public async static Task <double> GetFileKBSizeAsync(this StorageFile file)
        {
            Windows.Storage.FileProperties.BasicProperties basicProperties = await file.GetBasicPropertiesAsync();

            ulong fileSize = basicProperties.Size;
            var   KBSize   = fileSize / 1024.0;

            return(KBSize);
        }
Пример #4
0
        async private void PrintDir()
        {
            filelist.Clear();
            if (CurrentFolder == null)
            {
                return;
            }
            StorageFolder parent = await CurrentFolder.GetParentAsync();

            if (parent != null)
            {
                searchTextbox.Text = "";
                filelist.Add(new Item {
                    Filename = "..", Size = "FOLDER", Folder = parent
                });
            }
            else
            {
                if (prevLocation != null)
                {
                    filelist.Add(new Item {
                        Filename = "НАЗАД", Size = "FOLDER", Folder = prevLocation
                    });
                }
            }
            IReadOnlyList <StorageFolder> folderList = await CurrentFolder.GetFoldersAsync();

            foreach (StorageFolder folder in folderList)
            {
                filelist.Add(new Item {
                    Filename = folder.DisplayName, Size = "FOLDER", Folder = folder
                });
            }
            IReadOnlyList <StorageFile> fileList = await CurrentFolder.GetFilesAsync();

            foreach (StorageFile file in fileList)
            {
                Windows.Storage.FileProperties.BasicProperties basicProperties = await file.GetBasicPropertiesAsync();

                string fileSize = ParseSize(basicProperties.Size);
                filelist.Add(new Item {
                    Filename = file.Name, Size = fileSize, File = file
                });
            }
            for (int i = 0; i < filelist.Count; ++i)
            {
                if (filelist[i].Filename == ".." || filelist[i].Filename == "НАЗАД")
                {
                    Item item = filelist[i];
                    filelist.RemoveAt(i);
                    filelist.Insert(0, item);
                }
            }
            return;
        }
Пример #5
0
        public async Task <bool> CreateFile()
        {
            bool result = false;

            await DispatcherHelper.ExecuteOnUIThreadAsync(async() =>
            {
                FileSavePicker filePicker         = new FileSavePicker();
                filePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
                filePicker.SuggestedFileName      = Path.GetFileNameWithoutExtension(Tab.TabName);

                string Extension = Path.GetExtension(Tab.TabName);
                if (Extension != "")
                {
                    filePicker.FileTypeChoices.Add("File", new List <string> {
                        Extension
                    });
                }

                foreach (string name in LanguagesHelper.GetLanguagesNames())
                {
                    List <string> Types = LanguagesHelper.GetLanguageExtensions(LanguagesHelper.GetLanguageTypeViaName(name));

                    if (Types.Count == 0)
                    {
                        Types.Add(".txt");
                    }

                    filePicker.FileTypeChoices.Add(name, Types);
                }

                StorageFile file = await filePicker.PickSaveFileAsync();
                if (file != null)
                {
                    Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Add(file);
                    Windows.Storage.FileProperties.BasicProperties date = await file.GetBasicPropertiesAsync();

                    Tab.TabDateModified        = date.DateModified.ToString();
                    Tab.TabType                = LanguagesHelper.GetLanguageType(file.FileType);
                    Tab.TabOriginalPathContent = file.Path;
                    Tab.TabName                = file.Name;

                    await TabsWriteManager.PushUpdateTabAsync(Tab, ListTabsID, true);

                    result = true;
                }
            });

            return(result);
        }
Пример #6
0
        async private void SearchFiles(StorageFolder folder)
        {
            IReadOnlyList <StorageFile> fileList = await folder.GetFilesAsync();

            foreach (StorageFile file in fileList)
            {
                if (file.DisplayName.IndexOf(searchTextbox.Text) >= 0)
                {
                    Windows.Storage.FileProperties.BasicProperties basicProperties = await file.GetBasicPropertiesAsync();

                    string fileSize = ParseSize(basicProperties.Size);
                    filelist.Add(new Item {
                        Filename = (file.Name), Size = fileSize, File = file
                    });
                }
            }
        }
 public BasicProperties getBasicProperties()
 {
     if (basicProperties == null)
         basicProperties = storageItem.GetBasicPropertiesAsync().DoSynchronously();
     return basicProperties;
 }
Пример #8
0
        public async static Task FillGeneralProperties(PropertiesFlyoutGeneral flyout, StorageFile file, BasicProperties basicProps)
        {
            try
            {
                if (!string.IsNullOrEmpty(file.DisplayType))
                    flyout.SetPropsKindTitle(file.DisplayType);

                DocumentProperties doc = await file.Properties.GetDocumentPropertiesAsync();
                if (doc != null)
                {
                    if (doc.Author != null && doc.Author.Count > 0)
                        flyout.Authors.Text = NameCreditsStr("", doc.Author);
                    else
                        flyout.HideAuthors();

                    if (!string.IsNullOrEmpty(doc.Title))
                        flyout.DocumentTitle.Text = doc.Title;
                    else
                        flyout.HideDocumentTitle();

                    if (!string.IsNullOrEmpty(doc.Comment))
                        flyout.Comments.Text = doc.Comment.Substring(0, Math.Min(200, doc.Comment.Length));
                    else
                        flyout.HideComments();

                    if (doc.Keywords != null && doc.Keywords.Count > 0)
                        flyout.Keywords.Text = NameCreditsStr("", doc.Keywords);
                    else
                        flyout.HideKeywords();
                }

                if (!string.IsNullOrEmpty(file.ContentType))
                    flyout.ContentType.Text = file.ContentType;
                else
                    flyout.HideContentType();

                if (basicProps != null && basicProps.DateModified.Year > 1700)
                    flyout.DateModified.Text = DateTime_ToString(basicProps.DateModified, EDateTimeFormat.G);
                else
                    flyout.HideDateModified();

                if (file.DateCreated.Year > 1700)
                    flyout.DateCreated.Text = DateTime_ToString(file.DateCreated, EDateTimeFormat.G);
                else
                    flyout.HideDateCreated();

                FileAttributes attr = file.Attributes;
                if ((uint)attr > 0)
                    flyout.Attributes.Text = attr.ToString();
                else
                    flyout.HideAttributes();

                //if (!string.IsNullOrEmpty(file.FolderRelativeId))
                //    flyout.FolderRelativeId.Text = file.FolderRelativeId;
                //else
                flyout.HideFolderRelativeId();

                //DisplayName
                //IsAvailable
            }
            catch (Exception ex) { Debug.WriteLine(ex.ToString()); }
        }
Пример #9
0
        public static void FillImageProperties(PropertiesFlyoutImage flyout, ImageProperties imageProps, StorageFile file, BasicProperties basicProps)
        {
            try
            {
                if (imageProps.DateTaken.Year > 1700)
                    flyout.DateTaken.Text = DateTime_ToString(imageProps.DateTaken, EDateTimeFormat.G);
                else if (basicProps != null)
                    flyout.DateTaken.Text = DateTime_ToString(basicProps.DateModified, EDateTimeFormat.G);
                else
                    flyout.DateTaken.Visibility = Visibility.Collapsed;

                if (imageProps.Width > 0 && imageProps.Height > 0)
                    flyout.Dimensions.Text = imageProps.Width.ToString() + " x " + imageProps.Height.ToString() + " pixels";
                else
                    flyout.Dimensions.Visibility = Visibility.Collapsed;

                // IMPORTANT: Need GeoCoordinate class from System.Device.Location namespace (but not avail on WinRT);
                // Not suitable: Windows.Devices.Geolocation namespace;
                // GeoCoordinate geoCoord = new GeoCoordinate();
                if (imageProps.Latitude.HasValue)
                    flyout.Latitude.Text = Util.LatOrLong_ToString(imageProps.Latitude);
                else
                    flyout.Latitude.Visibility = Visibility.Collapsed;
                if (imageProps.Longitude.HasValue)
                    flyout.Longitude.Text = Util.LatOrLong_ToString(imageProps.Longitude);
                else
                    flyout.Longitude.Visibility = Visibility.Collapsed;

                if (!string.IsNullOrEmpty(imageProps.Title))
                    flyout.ImgTitle.Text = imageProps.Title;
                else
                    flyout.ImgTitle.Visibility = Visibility.Collapsed;

                if (!string.IsNullOrEmpty(imageProps.CameraManufacturer))
                {
                    flyout.Camera.Text = imageProps.CameraManufacturer;
                    if (!string.IsNullOrEmpty(imageProps.CameraModel))
                        flyout.Camera.Text += " " + imageProps.CameraModel;
                }
                else
                    flyout.Camera.Visibility = Visibility.Collapsed;
            }
            catch (Exception ex) { Debug.WriteLine(ex.ToString()); }
        }
Пример #10
0
        public async static Task FillFileProperties(IFileProperties fileProps, StorageFile file, StorageFolder topFolder, string fileSubPath, BasicProperties basicProps)
        {
            try
            {
                fileProps.FileName = file.Name;
                fileProps.AbsolutePath = file.Path;

                fileProps.SelectedFolder = Util.FolderPath(topFolder);

                if (!string.IsNullOrEmpty(fileSubPath))
                    fileProps.ContainingFolder = fileSubPath;
                else
                    fileProps.ContainingFolder = ""; //fileProps.HideContainingFolder();

                string ftype = GetFileTypeText(file, false);
                if (!string.IsNullOrEmpty(ftype))
                    fileProps.FileType = ftype;
                else
                    fileProps.HideFileType();

                if (basicProps != null)
                    fileProps.FileSize = Util.SizeToString(basicProps.Size, "B");
                else
                    fileProps.HideFileSize();

                if (!string.IsNullOrEmpty(file.Provider.DisplayName))
                {
                    string flocation = file.Provider.DisplayName;
                    if (!string.IsNullOrEmpty(file.Provider.Id) && file.Provider.DisplayName.IndexOf(file.Provider.Id, StringComparison.OrdinalIgnoreCase) <= -1)
                        flocation += " (" + file.Provider.Id.Substring(0, 1).ToUpper() + file.Provider.Id.Substring(1) + ") ";
                    fileProps.FileLocation = flocation;
                }
                else if (!string.IsNullOrEmpty(file.Provider.Id))
                    fileProps.FileLocation = file.Provider.Id;
                else
                    fileProps.HideFileLocation();

                StorageItemThumbnail thumbnail = await file.GetThumbnailAsync(ThumbnailMode.DocumentsView, 260, ThumbnailOptions.None);
                Image image = Util.GetImage(thumbnail);
                if (image != null)
                    fileProps.FileImage = image.Source;
            }
            catch (Exception ex) { Debug.WriteLine(ex.ToString()); }
        }
Пример #11
0
        async void InitializeAllJoyn(){
            Debug.UseOSLogging(true);
            Debug.SetDebugLevel("ALLJOYN", 7);

            _bus = new BusAttachment(APPLICATION_NAME, true, 4);
            string connectSpec = "null:";
            _bus.Start();

            try
            {
                _mp3Reader = new MP3Reader();

                if (_streamingSong != null)
                {
                    _streamingSongBasicProperties = await _streamingSong.GetBasicPropertiesAsync();
                    if (_streamingSongBasicProperties != null)
                    {
                        _streamingSongMusicProperties = await _streamingSong.Properties.GetMusicPropertiesAsync();
                        if (_streamingSongMusicProperties != null)
                        {
                            await _mp3Reader.SetFileAsync(_streamingSong);

                            _bus.ConnectAsync(connectSpec).AsTask().Wait();
                            _connected = true;

                            _listeners = new Listeners(_bus, this);
                            _bus.RegisterBusListener(_listeners);
                            _mediaSource = new MediaSource(_bus);
                            _audioStream = new AudioStream(_bus, "mp3", _mp3Reader, 100, 1000);
                            _mediaSource.AddStream(_audioStream);

                            /* Register MediaServer bus object */ 
                            _bus.RegisterBusObject(_mediaSource.MediaSourceBusObject); 
                             /* Request a well known name */ 
                            _bus.RequestName(MediaServerName, (int)(RequestNameType.DBUS_NAME_REPLACE_EXISTING | RequestNameType.DBUS_NAME_DO_NOT_QUEUE));

                            /* Advertise name */
                            _bus.AdvertiseName(MediaServerName, TransportMaskType.TRANSPORT_ANY);
   
                            /* Bind a session for incoming client connections */
                            SessionOpts opts = new SessionOpts(TrafficType.TRAFFIC_MESSAGES, true, ProximityType.PROXIMITY_ANY, TransportMaskType.TRANSPORT_ANY);
                            ushort[] portOut = new ushort[1];
                            _bus.BindSessionPort(SESSION_PORT, portOut, opts, _listeners);
                        }
                    }
                }
            } catch (Exception ex)
            {
                string message = ex.Message;
                QStatus status = AllJoynException.GetErrorCode(ex.HResult);
                string errMsg = AllJoynException.GetErrorMessage(ex.HResult);
            }
        }