private void FindEmptyFolders()
 {
     foreach (string path in _nodesByPath.Keys)
     {
         TreeViewNode node = _nodesByPath[path];
         CloudStorageProviderFileBase file = (CloudStorageProviderFileBase)node.Tag;
         if (file.IsFolder && node.Children.Count == 0)
         {
             node.IsEmptyFolder = true;
         }
     }
 }
        private TreeViewNode BuildNode(
            CloudStorageProviderFileBase file,
            string[] nodeParts,
            int curPart,
            out bool existing)
        {
            existing = false;
            TreeViewNode parent  = null;
            TreeViewNode curNode = null;

            string curPartKey = String.Join("/", nodeParts, 0, curPart + 1);

            if (!_nodesByPath.ContainsKey(curPartKey))
            {
                //link to the parent
                if (curPart > 0)
                {
                    string curParentPartKey = String.Join("/", nodeParts, 0, curPart);
                    parent = _nodesByPath[curParentPartKey];
                }

                curNode = new TreeViewNode(parent, nodeParts[curPart], file);

                if (parent != null)
                {
                    parent.Children.Add(curNode);
                }

                _nodesByPath.Add(curPartKey, curNode);
            }
            else
            {
                curNode  = _nodesByPath[curPartKey];
                existing = true;
            }

            return(curNode);
        }
Ejemplo n.º 3
0
        public void OnClosePopup(View item, object parameter)
        {
            if (item is CloudProviderFileSelectView)
            {
                if (parameter != null)
                {
                    CloudStorageProviderFileBase cloudFile = parameter as CloudStorageProviderFileBase;
                    if (cloudFile != null)
                    {
                        String appDataPath = String.Empty;
                        Directory.ResolvePath("{AppData}", out appDataPath);
                        if (!appDataPath.EndsWith(DLoggerManager.PathDelimiter))
                        {
                            appDataPath += DLoggerManager.PathDelimiter;
                        }
                        String vaultFullPath = String.Format("{0}{1}", appDataPath, String.Format(@"LocalVaults{0}{1}", DLoggerManager.PathDelimiter, cloudFile.Name));

                        string cloudFilePath = cloudFile.Path;

                        IEnumerable <CloudProvider> providers = cachy.Config.CloudProviders.Instance.Providers.Where(cp => cp.ID == SelectedCloudProvider.ID);
                        if (providers.Any())
                        {
                            CloudProvider provider = providers.First();
                            switch (provider.AuthType)
                            {
                            case ProviderType.AuthenticationType.Amazon:
                            {
                                string         secret       = ((App)App.Current).GetCredential(SelectedCloudProvider.ID);
                                JObject        s3ConfigJSON = JObject.Parse(secret);
                                AmazonS3Config s3Config     = AmazonS3Config.FromJSON(s3ConfigJSON);

                                if (cloudFilePath.StartsWith(s3Config.Path))
                                {
                                    cloudFilePath = cloudFilePath.Substring(s3Config.Path.Length);
                                }

                                break;
                            }
                            }
                        }

                        VaultIndex index = VaultIndexFile.Instance.CreateLocalVaultStoreIndex("Name",
                                                                                              "Description",
                                                                                              Common.SyncMode.CloudProvider,
                                                                                              SelectedCloudProvider.ID,
                                                                                              vaultFullPath,
                                                                                              cloudFilePath);

                        ClearSelectedProvider(true);
                        ((App)App.Current).NavigateToVaultsList();
                    }
                }
                else
                {
                    ClearSelectedProvider(true);
                }
            }
            else if (item is AddCloudProviderView)
            {
                if (parameter != null)
                {
                    SelectedCloudProvider = (CloudProvider)parameter;
                }
            }
        }