Beispiel #1
0
        /// <summary>
        /// Получить директорию папки приложения
        /// </summary>
        private string GetAppFolderDir(AppFolder appFolder, char?directorySeparator, bool lowerCase = false)
        {
            string dir;

            switch (appFolder)
            {
            case AppFolder.Config:
                dir = "Config" + directorySeparator;
                break;

            case AppFolder.Log:
                dir = "Log" + directorySeparator;
                break;

            case AppFolder.Storage:
                dir = "Storage" + directorySeparator;
                break;

            default:
                dir = "";
                break;
            }

            return(lowerCase ? dir.ToLowerInvariant() : dir);
        }
Beispiel #2
0
 /// <summary>
 /// Получить абсолютный путь из относительного
 /// </summary>
 public string GetAbsPath(ConfigParts configPart, AppFolder appFolder, string path)
 {
     return(Path.Combine(Settings.Directory,
                         GetConfigPartDir(configPart, Path.DirectorySeparatorChar),
                         GetAppFolderDir(appFolder, Path.DirectorySeparatorChar, configPart == ConfigParts.Webstation),
                         path));
 }
Beispiel #3
0
        public static WPFLanguage GetLanguageForList(string language, string tableName)
        {
            GlobalConfiguration config    = GlobalHelper.ReadConfiguration();
            AppFolder           appFolder = config.WPFConfig.AppFolders.Where(x => x.Name == DefaultAppFolders.WPFListLanguage.ToString()).FirstOrDefault();

            if (appFolder == null)
            {
                //Setup in "GlobalConfiguration.json" is missing
                return(null);
            }

            string directory = string.Format(appFolder.Value, tableName);

            if (!Directory.Exists(directory))
            {
                //directory does not exists.
                return(null);
            }

            string fileName         = tableName + " " + language + ".json";
            string completeFileName = Path.Combine(directory, fileName);

            if (!File.Exists(completeFileName))
            {
                //translation file not found;
                return(null);
            }

            WPFLanguageContainer container   = new WPFLanguageContainer();
            WPFLanguage          wPFLanguage = container.ReadFile(completeFileName);

            return(wPFLanguage);
        }
Beispiel #4
0
        /// <summary>
        /// Gets a directory corresponding to the application folder.
        /// </summary>
        public static string GetDirectory(AppFolder appFolder, char?directorySeparator, bool lowerCase = false)
        {
            string dir;

            switch (appFolder)
            {
            case AppFolder.Root:
                dir = "";
                break;

            case AppFolder.Config:
                dir = "Config" + directorySeparator;
                break;

            case AppFolder.Log:
                dir = "Log" + directorySeparator;
                break;

            case AppFolder.Storage:
                dir = "Storage" + directorySeparator;
                break;

            default:
                throw new ArgumentException("Unknown application folder.");
            }

            return(lowerCase ? dir.ToLowerInvariant() : dir);
        }
 public static DalAppFolder ToDalAppFolder(this AppFolder folder)
 {
     if (folder == null)
     {
         return(null);
     }
     return((DalAppFolder)DalMappersExpressions.ToDalAppFolderExpression().Compile()(folder));
 }
Beispiel #6
0
 public AgentInfoManager(ILogger logger,
                         AppFolder appFolder,
                         IHashCatCommandExecutorBuilder executorBuilder)
 {
     _logger            = logger;
     _executorBuilder   = executorBuilder;
     _agentInfoFilePath = Path.Combine(appFolder.Value, ArtefactsFolder, AgentInfoFile);
 }
        private void RemoveFolder(object sender, RoutedEventArgs e)
        {
            List <String> foldersToRemove = new List <string>();

            foldersToRemove.Add((sender as Button).CommandParameter as String);
            this.openedAppFolders = AppFolder.findAndRemoveFolders(this.openedAppFolders, foldersToRemove);
            this.refreshOpenedFolders();
        }
 public FormDirectoryBrowser()
 {
     InitializeComponent();
     appFolder       = new AppFolder();
     appBottomPanel  = new AppBottomPanel();
     infoFile        = new Dictionary <string, ulong>();
     CountExtensions = new Dictionary <string, int>();
     listView1_Resize(new object(), new EventArgs());
 }
        private async void loadFilesIntoGrid(AppFolder appFolder)
        {
            // get files from app folder and display in grid view
            // grid view users vlc media element library to play videos
            List <AppFile> appFiles = await appFolder.GetFiles();

            this.GV1.ItemsSource = null;
            this.GV1.ItemsSource = appFiles;
        }
Beispiel #10
0
        /*
         * Event handler to download image
         */
        public static async Task <bool> DownloadImage(object sender, RoutedEventArgs e, Image img)
        {
            try
            {
                StorageFolder AppFolder;
                string        fileName = img.Name + ".gif";

                var CheckFolder = await KnownFolders.PicturesLibrary.TryGetItemAsync("Gifology");

                if (CheckFolder == null)
                {
                    AppFolder = await KnownFolders.PicturesLibrary.CreateFolderAsync("Gifology");
                }
                else
                {
                    AppFolder = CheckFolder as StorageFolder;
                }

                try
                {
                    if (await AppFolder.TryGetItemAsync(fileName) == null)
                    {
                        var httpClient = new HttpClient();

                        var OriginalUrl = ((BitmapImage)img.Source).UriSource.OriginalString;
                        var RequestUri  = Uri.IsWellFormedUriString(ConvertSourceType(OriginalUrl, SettingsItem.GifQuality), UriKind.Absolute) ?
                                          new Uri(ConvertSourceType(OriginalUrl, SettingsItem.GifQuality)) :
                                          new Uri(ConvertSourceType(OriginalUrl, "High"));

                        HttpResponseMessage message = await httpClient.GetAsync(RequestUri);

                        StorageFile SampleFile = await AppFolder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);

                        byte[] file = await message.Content.ReadAsByteArrayAsync();

                        await FileIO.WriteBytesAsync(SampleFile, file);

                        var files = await AppFolder.GetFilesAsync();

                        return(true);
                    }
                    else
                    {
                        return(true);
                    }
                }
                catch
                {
                    return(false);
                }
            }
            catch
            {
                return(false);
            }
        }
        private void GV_SavedFolders_LV1_LoadAndDisplayFiles(object sender, SelectionChangedEventArgs e)
        {
            // empty current grid view
            this.GV1.ItemsSource = null;
            if ((AppFolder)(sender as ListView).SelectedItem == null)
            {
                return;
            }

            this.selectedFolder = (AppFolder)(sender as ListView).SelectedItem;
            this.loadFilesIntoGrid(this.selectedFolder);
        }
Beispiel #12
0
        /// <summary>
        /// 获取文件夹路径,返回的路径必定存在
        /// </summary>
        /// <param name="folder"></param>
        /// <returns></returns>
        public static string GetPath(this AppFolder folder)
        {
            var path1 = folder switch
            {
                AppFolder.Images or AppFolder.Cache => IOPath.CacheDirectory,
                AppFolder.Database => IOPath.AppDataDirectory,
                _ => throw new ArgumentOutOfRangeException(nameof(folder), folder, null),
            };
            var path = Path.Combine(path1, folder.ToString());

            IOPath.DirCreateByNotExists(path);
            return(path);
        }
Beispiel #13
0
 /// <summary>
 /// Converts the application folder to a string.
 /// </summary>
 private bool FolderToString(AppFolder appFolder, bool lowercase, out string path)
 {
     if (FolderToString(appFolder, out path))
     {
         if (lowercase)
         {
             path = path.ToLowerInvariant();
         }
         return(true);
     }
     else
     {
         return(false);
     }
 }
        public IEnumerable <AppFolder> GetFolders(string folderPath)
        {
            foreach (string path in Directory.GetDirectories(folderPath))
            {
                if (IsAccessible(path))
                {
                    DirectoryInfo info = new DirectoryInfo(path);

                    AppFolder folder = new AppFolder();
                    folder.FolderName = info.Name;
                    folder.FolderPath = info.FullName;

                    yield return(folder);
                }
            }
        }
Beispiel #15
0
        public InventoryManager(
            AppFolder appFolder,
            ILogger logger,
            IWorkedFoldersProvider workedFoldersProvider,
            IFileDescriptionBuilder descriptionBuilder,
            IKrakerApi krakerApi,
            IAgentIdManager agentIdManager)
        {
            _logger             = logger;
            _descriptionBuilder = descriptionBuilder;
            _krakerApi          = krakerApi;
            _agentIdManager     = agentIdManager;
            _workedFolders      = workedFoldersProvider.Get();
            _inventoryFilePath  = Path.Combine(appFolder.Value, ArtefactsFolder, InventoryFile);

            _fileDescriptions = new Dictionary <string, FileDescription>();
            _currentInventory = new Inventory(_fileDescriptions.Values);
        }
Beispiel #16
0
        public async Task <List <string> > ReadCSVLinesAsync()
        {
            IList <string> csvLines = new List <string>();

            try
            {
                File = await AppFolder.GetFileAsync(FullFileName);

                csvLines = await FileIO.ReadLinesAsync(File);

                return(await Task.FromResult(csvLines.ToList()));
            }
            catch (Exception)
            {
                await AppFolder.CreateFileAsync(FullFileName);

                return(await Task.FromResult(csvLines.ToList()));
            }
        }
        public string GetPathFor(AppFolder appFolder)
        {
            switch (appFolder)
            {
            case AppFolder.ActiveScenario: return(Path.Combine(this.EmpyrionRootDirectory, @"Content\Scenarios"));

            case AppFolder.Cache: return(Path.Combine(this.EmpyrionRootDirectory, @"Saves\Cache"));

            case AppFolder.Content: return(Path.Combine(this.EmpyrionRootDirectory, @"Content"));

            case AppFolder.Dedicated: return(Path.Combine(this.EmpyrionRootDirectory, @"DedicatedServer"));

            case AppFolder.Mod: return(Path.Combine(this.EmpyrionRootDirectory, @"Content\Mods"));

            case AppFolder.SaveGame: return(Path.Combine(this.EmpyrionRootDirectory, @"Saves\Games"));

            default: return(this.EmpyrionRootDirectory);
            }
        }
Beispiel #18
0
 private void btnOpenFolder_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         string    btnTag       = ((Button)sender).Tag.ToString();
         AppFolder itemSelected = globalConfiguration.WPFConfig.AppFolders.Where(x => x.Name == btnTag).FirstOrDefault();
         string    directory    = itemSelected.Value;
         if (Directory.Exists(directory))
         {
             Process.Start("explorer.exe", directory);
         }
         else
         {
             MessageBox.Show("Can't open directory:" + Environment.NewLine + directory);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Error trying to open directory:" + ex.Message);
     }
 }
        private async void OpenFolderAsync(object sender, RoutedEventArgs e)
        {
            var folderPicker = new Windows.Storage.Pickers.FolderPicker();

            folderPicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.Desktop;
            folderPicker.FileTypeFilter.Add("*");

            Windows.Storage.StorageFolder folder = await folderPicker.PickSingleFolderAsync();

            if (folder != null)
            {
                // Application now has read/write access to all contents in the picked folder
                // (including other sub-folder contents)
                Windows.Storage.AccessCache.StorageApplicationPermissions.
                FutureAccessList.AddOrReplace("PickedFolderToken", folder);
                Debug.WriteLine("Folder selected: " + folder.Name);
                // create new app folder and add it to opened folders list
                AppFolder newFolder = new AppFolder(folder.Path);
                this.openedAppFolders.Add(newFolder);
                this.refreshOpenedFolders();
            }
        }
        public void Add(IDalAppFolder entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }

            var folder = new AppFolder()
            {
                Id           = entity.Id,
                DateUploaded = entity.DateUploaded,
                Name         = entity.Name,
            };

            folder.User = _context.Set <User>().Find(entity.UserId);

            if (entity.RootFolderId != null)
            {
                folder.RootFolder = _context.Set <AppFolder>().Find(entity.RootFolderId);
            }

            _context.Set <AppFolder>().Add(folder);
        }
Beispiel #21
0
        /// <summary>
        /// Converts the application folder to a string.
        /// </summary>
        private bool FolderToString(AppFolder appFolder, out string path)
        {
            switch (appFolder)
            {
            case AppFolder.Root:
                path = "";
                return(false);

            case AppFolder.Cmd:
                path = "Cmd";
                return(true);

            case AppFolder.Config:
                path = "Config";
                return(true);

            case AppFolder.Lang:
                path = "Lang";
                return(true);

            case AppFolder.Log:
                path = "Log";
                return(true);

            case AppFolder.Storage:
                path = "Storage";
                return(true);

            case AppFolder.Temp:
                path = "Temp";
                return(true);

            default:
                throw new ScadaException("Application folder {0} not supported.", appFolder);
            }
        }
Beispiel #22
0
 /// <summary>
 /// Initializes a new instance of the class.
 /// </summary>
 public RelativePath(TopFolder topFolder, AppFolder appFolder, string path = "")
 {
     TopFolder = topFolder;
     AppFolder = appFolder;
     Path      = path ?? "";
 }
Beispiel #23
0
        public App(string virtualDirectory, string localDirectory)
        {
            this.fHandlers = new List<IAppHandler>();
            if (!virtualDirectory.StartsWith("/"))
                virtualDirectory = "/" + virtualDirectory;
            this.Mime = new HttpMimeMap();
            this.LocalDirectory = localDirectory;
            this.VirtualDirectory = virtualDirectory.StartsWith("/") ? virtualDirectory.ToLower() : "/" + virtualDirectory.ToLower();
            this.Folder = new AppFolder(this);
            this.DefaultPages = new List<string>();
            this.Active = true;

            // Generate the key
            this.Oid = this.GenerateKey();

            // Load the configuration from the local directory
            this.fConfig = AppConfig.Load(this);

            // Store the list of hosts in the AppDomain
            var hosts = fConfig.Hosts.ToArray();
            AppDomain.CurrentDomain.SetData("hosts", hosts);

            // Create a new scope and attach it to the context.
            var context = new ScriptContext();
            this.fScope = new AppScope(this, context);

            // Prepare new handlers
            var handlers = new IAppHandler[] {
                new HandlerResource(),
                new HandlerApp(),
                new HandlerView(),
                new HandlerElement(),
                new HandlerCss(),
                new HandlerJs()
            };

            // Register other handlers
            if (handlers != null && handlers.Length > 0)
            {
                for (int i = 0; i < handlers.Length; ++i)
                    this.Register(handlers[i]);
            }

            // Populate the repositories
            this.Folder.Invalidate();
        }
 private void prepareOpenedFoldersForSave()
 {
     this.saveData["GV_SavedFolders_List"] = null;
     this.saveData["GV_SavedFolders_List"] = AppFolder.getFolderLocations(this.openedAppFolders);
     this.appDataStorage.prepareForSave(this.saveData);
 }
Beispiel #25
0
 /// <summary>
 /// Gets a directory corresponding to the application folder.
 /// </summary>
 public static string GetDirectory(AppFolder appFolder, bool lowerCase = false)
 {
     return(GetDirectory(appFolder, null, lowerCase));
 }
Beispiel #26
0
 public WorkedFoldersManager(AppFolder appFolder)
 {
     _appDirectory = appFolder.Value;
 }
Beispiel #27
0
 /// <summary>
 /// Gets a directory corresponding to the configuration part and application folder.
 /// </summary>
 public static string GetDirectory(ConfigParts configPart, AppFolder appFolder, char directorySeparator)
 {
     return(GetDirectory(configPart, directorySeparator) +
            GetDirectory(appFolder, directorySeparator, configPart == ConfigParts.Web));
 }
Beispiel #28
0
 /// <summary>
 /// Gets a directory corresponding to the configuration part and application folder.
 /// </summary>
 public static string GetDirectory(ConfigParts configPart, AppFolder appFolder)
 {
     return(Path.Combine(GetDirectory(configPart), GetDirectory(appFolder, configPart == ConfigParts.Web)));
 }
Beispiel #29
0
 private LocalConfiguration()
 {
     Folders = new AppFolder();
     Files   = new AppFiles(Folders);
 }
Beispiel #30
0
 /// <summary>
 /// Получить абсолютный путь из относительного
 /// </summary>
 public string GetAbsPath(ConfigParts configPart, AppFolder appFolder, string path)
 {
     return(Path.Combine(Settings.Directory, DirectoryBuilder.GetDirectory(configPart, appFolder), path));
 }
Beispiel #31
0
 public static string GetFolderPath(this AppFolder folder) => folder.GetPath();