示例#1
0
 MessageWriteScheduler(ICloudFactory factory, int parallelism, CancellationTokenSource source)
 {
     _factory   = factory;
     _source    = source;
     _writers   = new ConcurrentDictionary <string, MessageWriter>();
     _scheduler = new TaskSchedulerWithAffinity(parallelism);
 }
示例#2
0
        static CloudPageBlob GetBlob(ICloudFactory cloudBlobClient)
        {
            var container = cloudBlobClient.GetSysContainerReference();

            var blob = container.GetPageBlobReference(Constants.MasterDataFileName);

            return(blob);
        }
示例#3
0
		public LeaderLock(ICloudFactory account, LeaderInfo info, ApiImplementation api) {
			Require.NotNull("account", account);
			Require.NotNull("info", info);
			_account = account;
			_info = info;
			_api = api;
			_lease = RenewableBlobLease.Create(account, LeaderMethod);
		}
		public static RenewableBlobLease Create(ICloudFactory account, LeaderTask task) {
			Require.NotNull("account", account);
			Require.NotNull("task", task);

			var container = account.GetSysContainerReference();
			var blob = container.GetPageBlobReference(Constants.MasterLockFileName);
			return new RenewableBlobLease(blob, task);
		}
示例#5
0
 public LeaderLock(ICloudFactory account, LeaderInfo info, ApiImplementation api)
 {
     Require.NotNull("account", account);
     Require.NotNull("info", info);
     _account = account;
     _info    = info;
     _api     = api;
     _lease   = RenewableBlobLease.Create(account, LeaderMethod);
 }
示例#6
0
		public static async Task<LeaderInfo> Get(ICloudFactory client) {
			var blob = GetBlob(client);
			var exists = await blob.ExistsAsync();
			if (!exists) {
				return null;
			}
			var endpoint = blob.Metadata["endpoint"];
			return new LeaderInfo(endpoint);
		}
        public static RenewableBlobLease Create(ICloudFactory account, LeaderTask task)
        {
            Require.NotNull("account", account);
            Require.NotNull("task", task);

            var container = account.GetSysContainerReference();
            var blob      = container.GetPageBlobReference(Constants.MasterLockFileName);

            return(new RenewableBlobLease(blob, task));
        }
示例#8
0
 public static AuthData LoadFromStorageAccount(ICloudFactory account)
 {
     var container = account.GetSysContainerReference();
     var blob = container.GetBlockBlobReference(Constants.AuthFileName);
     if (!blob.Exists()) {
         return GetEmptyConfig();
     }
     var source = blob.DownloadText();
     return AuthData.Deserialize(source);
 }
示例#9
0
		public async Task WriteToBlob(ICloudFactory storage) {

			var blob = GetBlob(storage);

			var exists = await blob.ExistsAsync();
			if (!exists) {
				blob.Create(0, AccessCondition.GenerateIfNoneMatchCondition("*"));
			}
			blob.Metadata["endpoint"] = this._endpoint;
			await blob.SetMetadataAsync();
		}
示例#10
0
        public async Task WriteToBlob(ICloudFactory storage)
        {
            var blob = GetBlob(storage);

            var exists = await blob.ExistsAsync();

            if (!exists)
            {
                blob.Create(0, AccessCondition.GenerateIfNoneMatchCondition("*"));
            }
            blob.Metadata["endpoint"] = this._endpoint;
            await blob.SetMetadataAsync();
        }
示例#11
0
        public static async Task <LeaderInfo> Get(ICloudFactory client)
        {
            var blob   = GetBlob(client);
            var exists = await blob.ExistsAsync();

            if (!exists)
            {
                return(null);
            }
            var endpoint = blob.Metadata["endpoint"];

            return(new LeaderInfo(endpoint));
        }
示例#12
0
        public static AuthData LoadFromStorageAccount(ICloudFactory account)
        {
            var container = account.GetSysContainerReference();
            var blob      = container.GetBlockBlobReference(Constants.AuthFileName);

            if (!blob.Exists())
            {
                return(GetEmptyConfig());
            }
            var source = blob.DownloadText();

            return(AuthData.Deserialize(source));
        }
示例#13
0
    public MainViewModel(MainState state, ICloudFactory factory, CloudViewModelFactory createViewModel)
    {
        _factory = factory;
        Refresh  = ReactiveCommand.Create(state.Clouds.Refresh);

        _isLoading = Refresh
                     .IsExecuting
                     .ToProperty(this, x => x.IsLoading);

        _isReady = Refresh
                   .IsExecuting
                   .Select(executing => !executing)
                   .ToProperty(this, x => x.IsReady);

        state
        .Clouds
        .Connect()
        .Transform(ps => createViewModel(ps, factory.CreateCloud(ps.Parameters)))
        .Sort(SortExpressionComparer <ICloudViewModel> .Descending(x => x.Created))
        .ObserveOn(RxApp.MainThreadScheduler)
        .Bind(out _providers)
        .Subscribe();

        var canRemove = this
                        .WhenAnyValue(x => x.SelectedProvider)
                        .Select(provider => provider != null);

        Remove = ReactiveCommand.Create(
            () => state.Clouds.RemoveKey(SelectedProvider.Id),
            canRemove);

        var canAddProvider = this
                             .WhenAnyValue(x => x.SelectedSupportedType)
                             .Select(type => Enum.IsDefined(typeof(CloudType), type));

        Add = ReactiveCommand.Create(
            () => state.Clouds.AddOrUpdate(new CloudState {
            Type = SelectedSupportedType
        }),
            canAddProvider);

        _welcomeScreenVisible = this
                                .WhenAnyValue(x => x.SelectedProvider)
                                .Select(provider => provider == null)
                                .ToProperty(this, x => x.WelcomeScreenVisible);

        _welcomeScreenCollapsed = this
                                  .WhenAnyValue(x => x.WelcomeScreenVisible)
                                  .Select(visible => !visible)
                                  .ToProperty(this, x => x.WelcomeScreenCollapsed);

        var canUnselect = this
                          .WhenAnyValue(x => x.SelectedProvider)
                          .Select(provider => provider != null);

        Unselect = ReactiveCommand.Create(() => Unit.Default, canUnselect);
        Unselect.Subscribe(unit => SelectedProvider = null);

        var outputCollectionChanges = Clouds
                                      .ToObservableChangeSet(x => x.Id)
                                      .Publish()
                                      .RefCount();

        outputCollectionChanges
        .Filter(provider => provider.Id == state.SelectedProviderId)
        .ObserveOn(RxApp.MainThreadScheduler)
        .OnItemAdded(provider => SelectedProvider = provider)
        .Subscribe();

        outputCollectionChanges
        .OnItemRemoved(provider => SelectedProvider = null)
        .Subscribe();

        this.WhenAnyValue(x => x.SelectedProvider)
        .Skip(1)
        .Select(provider => provider?.Id ?? Guid.Empty)
        .Subscribe(id => state.SelectedProviderId = id);

        SelectedSupportedType = state.SelectedSupportedType ?? SupportedTypes.First();
        this.WhenAnyValue(x => x.SelectedSupportedType)
        .Subscribe(type => state.SelectedSupportedType = type);
    }
		public static MessageWriteScheduler Create(ICloudFactory factory, int parallelism) {
			return new MessageWriteScheduler(factory, parallelism);
		}
		MessageWriteScheduler(ICloudFactory factory, int parallelism) {
			_factory = factory;
			_writers = new ConcurrentDictionary<string, MessageWriter>();
			_scheduler = new TaskSchedulerWithAffinity(parallelism);
		}
示例#16
0
		static CloudPageBlob GetBlob(ICloudFactory cloudBlobClient) {
			var container = cloudBlobClient.GetSysContainerReference();

			var blob = container.GetPageBlobReference(Constants.MasterDataFileName);
			return blob;
		}
示例#17
0
 ApiImplementation(ICloudFactory client, LeaderInfoPoller poller)
 {
     _client = client;
     _poller = poller;
 }
示例#18
0
		public static ApiImplementation Create(ICloudFactory account, LeaderInfoPoller poller, AuthData auth) {
			return new ApiImplementation(account, poller);
		}
示例#19
0
		public LeaderInfoPoller(ICloudFactory storage) {
			_storage = storage;
		}
示例#20
0
 public static MessageWriteScheduler Create(ICloudFactory factory, int parallelism, CancellationTokenSource source)
 {
     return(new MessageWriteScheduler(factory, parallelism, source));
 }
示例#21
0
 public LeaderInfoPoller(ICloudFactory storage)
 {
     _storage = storage;
 }
示例#22
0
		ApiImplementation(ICloudFactory client, LeaderInfoPoller poller) {
			_client = client;
			_poller = poller;
		}
示例#23
0
 public static ApiImplementation Create(ICloudFactory account, LeaderInfoPoller poller, AuthData auth)
 {
     return(new ApiImplementation(account, poller));
 }