Esempio n. 1
0
        public User Add(User userToAdd)
        {
            var user = ((UserProvider)dataProvider).GetByName(userToAdd.Name);

            if (user != null)
            {
                throw new UserAlreadyExistsException($"Username {userToAdd.Name} already exists.");
            }

            var userModel = new DataLayer.Models.User
            {
                Id               = Guid.NewGuid(),
                Name             = userToAdd.Name,
                LastActiveTime   = null,
                LastLoginTime    = null,
                PasswordHash     = null,
                PasswordHashSalt = null
            };

            byte[] pwdHash, pwdHashSalt;
            CreatePasswordHash(userToAdd.Password, out pwdHash, out pwdHashSalt);
            userModel.PasswordHash     = pwdHash;
            userModel.PasswordHashSalt = pwdHashSalt;

            var addedUser = dataCollector.Add(userModel);

            var userDto = new User
            {
                Id       = addedUser.Id,
                Name     = addedUser.Name,
                Password = null
            };

            return(userDto);
        }
 /// <summary>
 /// Sets this items from string table to data collector.
 /// </summary>
 public void Set()
 {
     foreach (var item in (IDictionary <string, Object>)_stringTable.Items)
     {
         _dataCollector.Add(StringTablePrefix + item.Key, item.Value.ToString());
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Generate message box HTML and set to data collector
        /// </summary>
        /// <param name="text">Text of a message box</param>
        /// <param name="status">Status of a message box</param>
        /// <param name="title">Title of a message box</param>
        public void Show(string?text, MessageBoxStatus status = MessageBoxStatus.Error, string?title = null)
        {
            if (string.IsNullOrEmpty(text))
            {
                throw new ArgumentNullException(nameof(text));
            }

            var templateFile = MessageBoxTemplatesPath;

            switch (status)
            {
            case MessageBoxStatus.Information:
                templateFile += "InfoMessageBox.tpl";
                break;

            case MessageBoxStatus.Error:
                templateFile += "ErrorMessageBox.tpl";
                break;

            case MessageBoxStatus.Ok:
                templateFile += "OkMessageBox.tpl";
                break;
            }

            var tpl = _templateFactory.Load(templateFile);

            tpl.Set("Message", text);
            tpl.Set("Title", string.IsNullOrEmpty(title) ? _stringTable.GetItem("FormTitleMessageBox") : title);

            _dataCollector.Add(tpl.Get());
            _dataCollector.AddTitle(string.IsNullOrEmpty(title) ? _stringTable.GetItem("FormTitleMessageBox") : title);
        }
Esempio n. 4
0
        public DataTransfer.Models.TaskGraph Add(DataTransfer.Events.TaskGraph item)
        {
            var mappedItem = new DataTransfer.Models.TaskGraph
            {
                Id          = item.Id,
                Description = item.Description,
                Name        = item.Name,
                RootId      = null,
                UserId      = item.UserId,
                TaskSetId   = null
            };

            var added = dataCollector.Add(mappedItem);

            var ws = ServiceFactory.WorkspaceService.Get(item.WorkspaceId);

            if (ws.TaskGraphIds == null)
            {
                ws.TaskGraphIds = new List <Guid>();
            }
            ws.TaskGraphIds.Add(added.Id);

            DataCollectorFactory.workspaceCollector.Update(ws);

            return(added);
        }
Esempio n. 5
0
        public DataTransfer.Models.TaskSet Add(DataTransfer.Events.TaskSet item)
        {
            var mappedItem = new DataTransfer.Models.TaskSet
            {
                Id    = item.Id,
                Tasks = item.Tasks
            };

            return(dataCollector.Add(mappedItem));
        }
Esempio n. 6
0
        public DataTransfer.Models.Workspace Add(DataTransfer.Events.Workspace item)
        {
            item.TaskGraphIds = new List <Guid>();

            var mappedItem = new DataTransfer.Models.Workspace
            {
                Description  = item.Description,
                Name         = item.Name,
                Id           = item.Id,
                TaskGraphIds = new List <Guid>(),
                UserId       = item.UserId
            };

            return(dataCollector.Add(mappedItem));
        }
        public TaskGraph Add(DataTransfer.Events.TaskGraph item)
        {
            var userList = new List <Guid>();

            userList.Add(item.UserId);
            var mappedItem = new DataLayer.Models.TaskGraph
            {
                Id          = item.Id,
                Description = item.Description,
                Name        = item.Name,
                RootId      = null,
                ActiveUsers = userList,
                TaskSetId   = null
            };
            var added = dataCollector.Add(mappedItem);

            var ws = ServiceFactory.WorkspaceService.Get(item.WorkspaceId);

            if (ws.TaskGraphIds == null)
            {
                ws.TaskGraphIds = new List <Guid>();
            }
            ws.TaskGraphIds.Add(added.Id);

            var mappedWS = new DataLayer.Models.Workspace
            {
                Description  = ws.Description,
                Id           = ws.Id,
                Name         = ws.Name,
                ActiveUsers  = ws.ActiveUsers,
                TaskGraphIds = ws.TaskGraphIds
            };

            DataCollectorFactory.workspaceCollector.Update(mappedWS);

            return(new TaskGraph
            {
                Id = added.Id,
                ActiveUsers = added.ActiveUsers,
                Description = added.Description,
                Name = added.Name,
                RootId = added.RootId,
                TaskSetId = added.TaskSetId
            });
        }
        /// <summary>
        /// Sets the context variables to data collector
        /// </summary>
        /// <param name="containerProvider">The DI container provider.</param>
        public void SetVariables(IDIContainerProvider containerProvider)
        {
            var environment       = containerProvider.Resolve <IEnvironment>();
            var languageManager   = containerProvider.Resolve <ILanguageManagerProvider>().Get();
            var context           = containerProvider.Resolve <IAcspNetContextProvider>().Get();
            var stopWatchProvider = containerProvider.Resolve <IStopwatchProvider>();

            _dataCollector.Add(VariableNameTemplatesPath, environment.TemplatesPath);
            _dataCollector.Add(VariableNameSiteStyle, environment.SiteStyle);

            _dataCollector.Add(VariableNameCurrentLanguage, languageManager.Language);
            _dataCollector.Add(VariableNameCurrentLanguageExtension, !string.IsNullOrEmpty(languageManager.Language) ? "." + languageManager.Language : "");

            _dataCollector.Add(VariableNameSiteUrl, context.SiteUrl);
            _dataCollector.Add(VariableNameSiteVirtualPath, context.VirtualPath);

            if (!_disableAutomaticSiteTitleSet)
            {
                SetSiteTitleFromStringTable(context.Request.Path.Value, containerProvider.Resolve <IStringTable>());
            }

            _dataCollector.Add(VariableNameExecutionTime, stopWatchProvider.StopAndGetMeasurement().ToString("mm\\:ss\\:fff"));
        }
        public void SetVariables(IDIResolver resolver)
        {
            var environment       = resolver.Resolve <IEnvironment>();
            var languageManager   = resolver.Resolve <ILanguageManagerProvider>().Get();
            var context           = resolver.Resolve <IWebContextProvider>().Get();
            var stopWatchProvider = resolver.Resolve <IStopwatchProvider>();

            _dataCollector.Add(VariableNameTemplatesPath, environment.TemplatesPath);
            _dataCollector.Add(VariableNameSiteStyle, environment.SiteStyle);

            if (!string.IsNullOrEmpty(languageManager.Language))
            {
                _dataCollector.Add(VariableNameCurrentLanguage, languageManager.Language);
                _dataCollector.Add(VariableNameCurrentLanguageExtension, "." + languageManager.Language);
                _dataCollector.Add(VariableNameCurrentLanguageCultureName, Thread.CurrentThread.CurrentCulture.TextInfo.CultureName);
                _dataCollector.Add(VariableNameCurrentLanguageCultureNameExtension, "." + Thread.CurrentThread.CurrentCulture.TextInfo.CultureName);
            }
            else
            {
                _dataCollector.Add(VariableNameCurrentLanguage, (string)null);
                _dataCollector.Add(VariableNameCurrentLanguageExtension, (string)null);
                _dataCollector.Add(VariableNameCurrentLanguageCultureName, (string)null);
                _dataCollector.Add(VariableNameCurrentLanguageCultureNameExtension, (string)null);
            }

            _dataCollector.Add(VariableNameSiteUrl, context.SiteUrl);
            _dataCollector.Add(VariableNameSiteVirtualPath, context.VirtualPath);

            if (!_disableAutomaticSiteTitleSet)
            {
                SetSiteTitleFromStringTable(context.Request.Path.Value, resolver.Resolve <IStringTable>());
            }

            _dataCollector.Add(VariableNameExecutionTime, stopWatchProvider.StopAndGetMeasurement().ToString("mm\\:ss\\:fff"));
        }
        public WorkspaceTransferModel Add(WorkspaceTransferModel item)
        {
            item.TaskGraphIds = new List <Guid>();

            //var mappedItem = new Workspace
            //{
            //    Description = item.Description,
            //    Name = item.Name,
            //    Id = item.Id,
            //    TaskGraphIds = new List<Guid>(),
            //    UserId = item.UserId
            //};

            var mappedItem = Mappers[Tuple.Create(Layer.Data, Layer.DataTransfer)].Map <WorkspaceTransferModel, WorkspaceDataModel>(item);

            return(Mappers[Tuple.Create(Layer.Data, Layer.DataTransfer)].Map <WorkspaceDataModel, WorkspaceTransferModel>(dataCollector.Add(mappedItem)));
        }