Пример #1
0
        public async Task <PersonalCloud> CreatePersonalCloud(string displayName, string nodedisplaryname)
        {
            var l  = loggerFactory.CreateLogger("PersonalCloud");
            var pc = new PersonalCloud(l, this, null)
            {
                Id = Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture),
                UpdateTimeStamp = DateTime.UtcNow.ToFileTime(),
                NodeDisplayName = nodedisplaryname,
                DisplayName     = displayName,
            };

            using (var aes = Aes.Create())
            {
                aes.KeySize = 256;
                aes.GenerateKey();
                pc.MasterKey = aes.Key;
            }
            lock (_PersonalClouds)
            {
                _PersonalClouds.Add(pc);
            }
            SavePCList();

            EnsureWebServerStarted();
            await EnsureSSDPStarted().ConfigureAwait(false);

            await nodeDiscovery.RePublish(NodeId, ServerPort).ConfigureAwait(false);

            return(pc);
        }
Пример #2
0
        private void LoadApps()
        {
            var lis = GetAppMgrs();

            foreach (var item in lis)
            {
                var s = ConfigStorage.GetApp(item.GetAppId());
                foreach (var pcc in s)
                {
                    List <AppLauncher> appls = null;
                    try
                    {
                        appls = item.Config(pcc.Item2);
                    }
                    catch (Exception e)
                    {
                        logger.LogError(e, $"Config error for {item.GetAppId()}");
                        return;
                    }
                    foreach (var appl in appls)
                    {
                        PersonalCloud pc = null;
                        lock (_PersonalClouds)
                        {
                            pc = _PersonalClouds.FirstOrDefault(x => x.Id == pcc.Item1);
                        }
                        if (pc != null)
                        {
                            appl.NodeId = NodeId;
                            pc.AddApp(appl);
                        }
                    }
                }
            }
        }
Пример #3
0
 public void ExitFromCloud(PersonalCloud pc)
 {
     lock (_PersonalClouds)
     {
         _PersonalClouds.Remove(pc);
     }
     SavePCList();
     _ = nodeDiscovery.RePublish(NodeId, ServerPort);
 }
Пример #4
0
        public async Task StopSharePersonalCloud(PersonalCloud pc)
        {
            if (pc == null)
            {
                throw new InvalidDataException("pc couldn't be null");
            }
            pc.CurrentShareCode = null;
            await nodeDiscovery.RePublish(NodeId, ServerPort).ConfigureAwait(false);

            return;
        }
Пример #5
0
        public async Task <string> SharePersonalCloud(PersonalCloud pc)
        {
            if (pc == null)
            {
                throw new InvalidDataException("pc couldn't be null");
            }
            var str = pc.GenerateShareCode();
            await nodeDiscovery.RePublish(NodeId, ServerPort).ConfigureAwait(false);

            return(str);
        }
Пример #6
0
 internal static PersonalCloudInfo FromPersonalCloud(PersonalCloud pc)
 {
     return(new PersonalCloudInfo(pc.StorageProviderInstances.Select(x => x.ProviderInfo).ToList())
     {
         Id = pc.Id,
         DisplayName = pc.DisplayName,
         NodeDisplayName = pc.NodeDisplayName,
         MasterKey = pc.MasterKey,
         TimeStamp = pc.UpdateTimeStamp,
         Apps = pc.Apps
     });
 }
Пример #7
0
        public List <StorageProviderInstance> GetStorageProviderInstances(string cloudId)
        {
            PersonalCloud personalCloud = null;

            lock (_PersonalClouds)
            {
                personalCloud = _PersonalClouds.Where(x => x.Id == cloudId).FirstOrDefault();
            }

            if (personalCloud != null)
            {
                return(personalCloud.StorageProviderInstances);
            }
            else
            {
                throw new NoSuchCloudException();
            }
        }
Пример #8
0
        public Task SetAppMgrConfig(string appid, string pcid, string jsonconfig)
        {
            var lis    = GetAppMgrs();
            var appmgr = lis.FirstOrDefault(x => x.GetAppId() == appid);

            if (appmgr != null)
            {
                var updatenet            = false;
                List <AppLauncher> appls = null;
                try
                {
                    appls = appmgr.Config(jsonconfig);
                }
                catch (Exception e)
                {
                    logger.LogError(e, $"Config error for {appmgr.GetAppId()}");
                    return(Task.CompletedTask);
                }
                ConfigStorage.SaveApp(appid, pcid, jsonconfig);
                foreach (var appl in appls)
                {
                    PersonalCloud pc = null;
                    lock (_PersonalClouds)
                    {
                        pc = _PersonalClouds.FirstOrDefault(x => x.Id == pcid);
                    }
                    if (pc != null)
                    {
                        appl.NodeId = NodeId;
                        appl.AppId  = appid;
                        pc.AddApp(appl);
                        updatenet = true;
                    }
                }
                if (updatenet)
                {
                    this.NetworkRefeshNodes();
                }
            }

            return(Task.CompletedTask);
        }
Пример #9
0
        private async Task <PersonalCloudInfo> GetPeerPCInfo(PersonalCloud pc, NodeInfo ninfo)
        {
            try
            {
                var url = new Uri(new Uri(ninfo.Url), "/api/share/cloud");
                var s   = await TopFolderClient.GetCloudInfo(httpClient.Value, url, pc.Id, pc.MasterKey).ConfigureAwait(false);

                var cfg = JsonConvert.DeserializeObject <PersonalCloudInfo>(s);
                var lis = cfg.Apps.Where(x => x.NodeId != ninfo.NodeGuid).ToList();
                foreach (var item in lis)
                {
                    cfg.Apps.Remove(item);
                }
                return(cfg);
            }
            catch (Exception e)
            {
                logger.LogError("Exception in GetPeerPCInfo", e);
                return(null);
            }
        }
Пример #10
0
        public bool RemoveStorageProvider(string cloudId, string nodeName, bool saveChanges = true)
        {
            PersonalCloud personalCloud = null;

            lock (_PersonalClouds)
            {
                personalCloud = _PersonalClouds.FirstOrDefault(x => x.Id == cloudId);
            }

            if (personalCloud != null)
            {
                bool haveChanges = personalCloud.RemoveStorageProvider(nodeName);
                if (haveChanges && saveChanges)
                {
                    SavePCList();
                }
                return(haveChanges);
            }
            else
            {
                throw new NoSuchCloudException();
            }
        }
Пример #11
0
        public bool AddStorageProvider(string cloudId, Guid nodeId, string nodeName, AzureBlobConfig azureConfig, StorageProviderVisibility visibility, bool saveChanges = true)
        {
            PersonalCloud personalCloud = null;

            lock (_PersonalClouds)
            {
                personalCloud = _PersonalClouds.FirstOrDefault(x => x.Id == cloudId);
            }

            if (personalCloud != null)
            {
                var haveChanges = personalCloud.AddStorageProvider(nodeId, nodeName, azureConfig, visibility);
                if (haveChanges && saveChanges)
                {
                    SavePCList();
                }
                return(haveChanges);
            }
            else
            {
                throw new NoSuchCloudException();
            }
        }