/// <summary>
        /// Saves the state of the workspace.
        /// </summary>
        /// <param name="workspaceState">State of the workspace.</param>
        public void SaveWorkspaceState(WorkspaceState workspaceState)
        {
            var workspaceStates = new List <WorkspaceState>();

            foreach (var workspace in this.Workspaces)
            {
                if (workspace.WorkspaceState == workspaceState)
                {
                    // Save the new change status.
                    workspaceState.HasChanges = false;

                    var targetFileName  = workspace.WorkspaceState.TempStorageFilename;
                    var targetDirectory = Path.GetDirectoryName(targetFileName);

                    if (targetDirectory == null)
                    {
                        throw new ArgumentNullException(nameof(targetDirectory));
                    }

                    if (!Directory.Exists(targetDirectory))
                    {
                        Directory.CreateDirectory(targetDirectory);
                    }

                    File.WriteAllText(targetFileName, workspace.Content);
                }

                workspaceStates.Add(workspace.WorkspaceState);
            }

            JsonUtils.SerializeJsonFile(this.WorkspaceStatesFileLocation, workspaceStates);

            workspaceState.ResetChangeState();
        }
 public WorkspaceInfo(string path, RunnableInfo[] runnables, ServerState serverState, WorkspaceState workspaceState)
 {
     Path           = path;
     Runnables      = runnables;
     ServerState    = serverState;
     WorkspaceState = workspaceState;
 }
        public virtual void RunQuery()
        {
            if (State == WorkspaceState.Busy)
            {
                return;
            }

            State = WorkspaceState.Busy;

            var sql         = getSQL();
            var queryParams = getQueryParams();

            SqlCommandDispatcher.ConnectionString = txtConnString.Text;

            _statusTextbox.Text = "Running query...";
            if (_runQueryAsync)
            {
                ThreadStart starter = new ThreadStart(() => {
                    runQueryInternal(sql, queryParams);
                });
                new Thread(starter).Start();
            }
            else
            {
                runQueryInternal(sql, queryParams);
            }
        }
        /// <summary>
        /// Deletes the state of the workspace.
        /// </summary>
        /// <param name="workspaceState">State of the workspace.</param>
        public void DeleteWorkspaceState(WorkspaceState workspaceState)
        {
            if (workspaceState.ChangeState == ChangeState.New)
            {
                return;
            }

            if (!string.IsNullOrEmpty(workspaceState.TempStorageFilename) && File.Exists(workspaceState.TempStorageFilename))
            {
                File.Delete(workspaceState.TempStorageFilename);
            }

            var workspaceStates = this.Workspaces.Select(workspace => workspace.WorkspaceState).ToList();

            JsonUtils.SerializeJsonFile(this.WorkspaceStatesFileLocation, workspaceStates);
        }
        public async Task List_workspaces()
        {
            // Arrange
            var someState = new WorkspaceState("abc", DateTimeOffset.Now);
            var someBucketStates = new Dictionary<string, WorkspaceState>();
            var expected = new List<Workspace>
            {
                new Workspace("master", someState, someBucketStates),
                new Workspace("foo", someState, someBucketStates)
            };
            
            _connector.GetsJson("/stores/acme", (IReadOnlyList<Workspace>) expected);

            // Act
            var response = await _client.ListAsync("acme", None);

            // Assert
            response.ShouldBeSameAs(expected);
        }
        /// <summary>
        /// Adds the workspace.
        /// </summary>
        /// <param name="workspaceState">State of the workspace.</param>
        /// <param name="content">The content.</param>
        /// <returns>
        /// The newly added workspace.
        /// </returns>
        public WorkspaceViewModel AddWorkspace(WorkspaceState workspaceState, string content)
        {
            var hasChanges = workspaceState.HasChanges;

            var workspace = this.AddWorkspace(
                new WorkspaceViewModel(this)
            {
                Filename       = workspaceState.SourceFilename,
                Label          = workspaceState.Label,
                WorkspaceState = workspaceState,
            });

            var highlighting = workspace.SyntaxHighlightingDefinitions.FirstOrDefault(s => s.Name == workspaceState.SyntaxHighlightingDefinition);

            if (highlighting != null)
            {
                workspace.SyntaxHighlighting = highlighting;
            }

            workspace.Document.Text = content;
            workspace.HasChanges    = hasChanges;

            return(workspace);
        }
 public Workspace(string name, WorkspaceState state, IReadOnlyDictionary<string, WorkspaceState> bucketStates)
 {
     Name = name;
     State = state;
     BucketStates = bucketStates;
 }
Exemple #8
0
        // add user to workspace
        public async Task <User> AddUserToWorkspace(UserAccountView newuser, string workspaceName)
        {
            // make a user object from user account view
            User user = new User
            {
                UserId    = newuser.Id,
                EmailId   = newuser.EmailId,
                FirstName = newuser.FirstName,
                LastName  = newuser.LastName
            };

            //insert a new document in mongo collection of user
            await _dbUser.InsertOneAsync(user);

            // get workspace by name
            var resultWorkspace = GetWorkspaceByName(workspaceName).Result;

            // add user to workspace
            resultWorkspace.Users.Add(user);

            // filter to update workpsace in monog collection
            var filterWorkspace = new FilterDefinitionBuilder <Workspace>().Where(r => r.WorkspaceId == resultWorkspace.WorkspaceId);

            //update definition for workspace
            var updateWorkspace = Builders <Workspace> .Update
                                  .Set(r => r.Users, resultWorkspace.Users)
                                  .Set(r => r.WorkspaceId, resultWorkspace.WorkspaceId);

            // update in mongo collection
            await _dbWorkSpace.UpdateOneAsync(filterWorkspace, updateWorkspace);

            // get list of default channel names given by user
            var listOfDefaultChannels = resultWorkspace.DefaultChannels;

            //make a new list of channels of channel state
            List <ChannelState> listOfDefaultChannelState = new List <ChannelState>();

            foreach (var defaultChannel in listOfDefaultChannels)
            {
                await AddUserToDefaultChannel(user, defaultChannel.ChannelId);

                ChannelState channel = new ChannelState()
                {
                    channelId          = defaultChannel.ChannelId,
                    UnreadMessageCount = 0,
                };
                // add it to the list of default channels
                listOfDefaultChannelState.Add(channel);
            }

            // get redis database and call it cache
            var cache = RedisConnectorHelper.Connection.GetDatabase();

            // CHECK THESE COMMENTED LINES ONCE AGAIN !!!!!!!!!!!!!!!!
            //string jsonString = JsonConvert.SerializeObject(resultWorkspace);
            //await cache.StringSetAsync($"{resultWorkspace.WorkspaceName}", jsonString);

            ///////////////Notification Work/////////////////////

            //get user state by email of new user
            var userstate = await GetUserStateByEmailId(user.EmailId);

            // add workspace state to user state if user state already exists
            if (userstate != null)
            {
                WorkspaceState newWorkspace = new WorkspaceState()
                {
                    WorkspaceName = workspaceName,
                };
                foreach (var channel in listOfDefaultChannelState)
                {
                    newWorkspace.ListOfChannelState.Add(channel);
                }

                userstate.ListOfWorkspaceState.Add(newWorkspace);

                // update in cache
                string jsonStringUserState = JsonConvert.SerializeObject(userstate);
                await cache.StringSetAsync($"{userstate.EmailId}", jsonStringUserState);
            }
            //else create a new user state
            else
            {
                WorkspaceState newWorkspace = new WorkspaceState()
                {
                    WorkspaceName = workspaceName,
                };
                foreach (var channel in listOfDefaultChannelState)
                {
                    newWorkspace.ListOfChannelState.Add(channel);
                }
                UserState newUserState = new UserState()
                {
                    EmailId = user.EmailId,
                };
                newUserState.ListOfWorkspaceState.Add(newWorkspace);

                // create a mongo document
                await CreateNotificationStateOfUser(newUserState);

                // add it in cache
                string jsonStringUserState = JsonConvert.SerializeObject(newUserState);
                await cache.StringSetAsync($"{newUserState.EmailId}", jsonStringUserState);
            }
            ////////////////////////////////////////////////////////
            return(user);
        }
 public static bool IsReady(this WorkspaceState state)
 {
     return(state == WorkspaceState.Ready || state == WorkspaceState.ReadyWithError);
 }