예제 #1
0
        public DataFileModel Delete(int id)
        {
            //Not yet implemented
            DataFileModel result = _fileManager.Delete(id);

            return(result);
        }
예제 #2
0
        public DataFileModel Put(DataModel model, int id)
        {
            //Not yet implemented
            DataFileModel result = _fileManager.Update(model, id);

            return(result);
        }
예제 #3
0
        public DataFileModel Post(DataModel model)
        {
            //Not yet implemented
            DataFileModel result = _fileManager.Insert(model);

            return(result);
        }
예제 #4
0
        public DataFileModel Get()
        {
            //Not yet implemented
            DataFileModel data = _fileManager.GetData();

            return(data);
        }
예제 #5
0
    private bool TryDeserializeDataFile(XElement element, string resourceName, out DataFileModel dataFileModel)
    {
        var model = new DataFileModel
        {
            Name     = resourceName,
            Location = Path.Combine(_baseDirectory, element.Attribute("location").Value)
        };

        dataFileModel = model;
        return(true);
    }
예제 #6
0
파일: SqlConnector.cs 프로젝트: mhdb96/HRPM
 public void File_Insert(DataFileModel model)
 {
     using (IDbConnection connection = new SqlConnection(GlobalConfig.CnnString(databaseName)))
     {
         var p = new DynamicParameters();
         p.Add("@Path", model.Path);
         p.Add("@UserId", model.User.Id);
         p.Add("@Date", model.Date);
         p.Add("@id", 0, dbType: DbType.Int32, direction: ParameterDirection.Output);
         connection.Execute("dbo.spFiles_Insert", p, commandType: CommandType.StoredProcedure);
         model.Id = p.Get <int>("@id");
     }
 }
예제 #7
0
    public MagitekResult AddDataFile(DataFileModel dfModel, string parentNodePath, string fileLocation)
    {
        var fileSource = new FileDataSource(dfModel.Name, dfModel.Location);

        var dfNode = new DataFileNode(fileSource.Name, fileSource)
        {
            DiskLocation = fileLocation,
            Model        = dfModel
        };

        Tree.TryGetNode(parentNodePath, out var parentNode);
        parentNode.AttachChildNode(dfNode);

        if (!File.Exists(fileSource.FileLocation))
        {
            return(new MagitekResult.Failed($"DataFile '{fileSource.Name}' does not exist at location '{fileSource.FileLocation}'"));
        }

        return(MagitekResult.SuccessResult);
    }
예제 #8
0
        public void UploadFile(BinaryFile file)
        {
            DataFileModel model = new DataFileModel();

            model.Date    = file.Date;
            model.User.Id = file.User.Id;
            model.Path    = FileManager.GetFileManager().SaveSessionsFile(file);
            GlobalConfig.Connection.File_Insert(model);
            var sessions = BinaryConnector.StaticLoad <List <AppSession> >(model.Path);

            foreach (var session in sessions)
            {
                if (session.MouseData != null && session.EndTime != DateTime.MinValue)
                {
                    AppModel appModel = new AppModel();
                    appModel.ProcessName = session.App.ProcessName;
                    GlobalConfig.Connection.App_Insert(appModel);
                    SessionModel sessionModel = new SessionModel();
                    sessionModel.AppId = appModel.Id;
                    sessionModel.BackspaceStrokesCount = session.KeyboardData.BackspaceStrokesCount;
                    sessionModel.StrokesCount          = session.KeyboardData.StrokesCount;
                    sessionModel.StrokeHoldTimes       = session.KeyboardData.StrokeHoldTimes;
                    sessionModel.UniqueKeysCount       = session.KeyboardData.UniqueKeysCount;
                    sessionModel.MouseClickCount       = (int)session.MouseData.MouseClickCount;
                    sessionModel.MouseClickTotalTime   = (int)session.MouseData.MouseClickTotalTime;
                    sessionModel.StartTime             = session.StartTime;
                    sessionModel.EndTime = session.EndTime;
                    sessionModel.UserId  = model.User.Id;
                    sessionModel.AppId   = appModel.Id;
                    GlobalConfig.Connection.Session_Insert(sessionModel);
                    if (session.App.Type == HRPMSharedLibrary.Enums.AppType.Browser)
                    {
                        DomainModel domainModel = new DomainModel();
                        domainModel.Domain = session.App.Content;
                        GlobalConfig.Connection.Domain_Insert(domainModel);
                        GlobalConfig.Connection.SessionDomain_Insert(sessionModel.Id, domainModel.Id);
                    }
                }
            }
        }
예제 #9
0
 public static DataSource MapToResource(this DataFileModel df) =>
 new FileDataSource(df.Name, df.Location);
        private async void LoginAsync()
        {
            IsLoading = true;

            try
            {
                // Make sure that the Graph service is configured.
                await _graphService.EnsureTokenIsPresentAsync();
            }
            catch (Exception ex)
            {
                IsLoading = false;
                return;
            }

            UserModel user = null;

            GroupModel[] userGroups = null;
            GroupModel[] allGroups  = null;

            // Get the current user, its groups and all of the groups.
            await Task.WhenAll(
                Task.Run(async() =>
            {
                user = await _graphService.GetUserAsync();
            }),
                Task.Run(async() =>
            {
                userGroups = await _graphService.GetUserGroupsAsync();
            }),
                Task.Run(async() =>
            {
                allGroups = await _graphService.GetGroupsAsync();
            }));

            // Get the group belonging to this app.
            var appGroup = allGroups.FirstOrDefault(g => g.Mail != null && g.Mail.StartsWith(
                                                        Constants.AppGroupMail));

            // If the app group doesn't exist, create it.
            if (appGroup == null)
            {
                // Create a unique mail nickname.
                var mailNickname = Constants.AppGroupMail +
                                   new string(DateTime.UtcNow.Ticks
                                              .ToString()
                                              .ToCharArray()
                                              .Take(10)
                                              .ToArray());
                appGroup = await _graphService.AddGroupAsync(GroupModel.CreateUnified(
                                                                 Constants.AppGroupDisplayName,
                                                                 Constants.AppGroupDescription,
                                                                 mailNickname));

                // Add the current user as a member of the app group.
                await _graphService.AddGroupUserAsync(appGroup, user);
            }

            // Add the current user as a member of the app group.
            var appGroupUsers = await _graphService.GetGroupUsersAsync(appGroup);

            if (appGroupUsers.All(u => u.UserPrincipalName != user.UserPrincipalName))
            {
                await _graphService.AddGroupUserAsync(appGroup, user);
            }

            // We need the file storage to be ready in order to place the data file.
            // Wait for it to be configured.
            await _graphService.WaitForGroupDriveAsync(appGroup);

            // Get the app group files and the property data file.
            var appGroupDriveItems = await _graphService.GetGroupDriveItemsAsync(appGroup);

            var dataDriveItem = appGroupDriveItems.FirstOrDefault(i => i.Name.Equals(
                                                                      Constants.DataFileName));

            // If the data file doesn't exist, create it.
            if (dataDriveItem == null)
            {
                // Get the data file template from the resources.
                var assembly = typeof(App).GetTypeInfo().Assembly;
                using (var stream = assembly.GetManifestResourceStream(Constants.DataFileResourceName))
                {
                    dataDriveItem = await _graphService.AddGroupDriveItemAsync(appGroup,
                                                                               Constants.DataFileName, stream, Constants.ExcelContentType);
                }

                if (dataDriveItem == null)
                {
                    throw new Exception("Could not create the property data file in the group.");
                }
            }

            // Get the property table.
            var propertyTable = await _graphService.GetGroupTableAsync <PropertyTableRowModel>(
                appGroup, dataDriveItem, Constants.DataFilePropertyTable);

            // Create the data file represenation.
            var dataFile = new DataFileModel
            {
                DriveItem     = dataDriveItem,
                PropertyTable = propertyTable
            };

            // Get groups that the user is a member of and represents
            // a property.
            var propertyGroups = userGroups
                                 .Where(g => propertyTable["Id"]
                                        .Values.Any(v => v.Any() &&
                                                    v[0].Type == JTokenType.String &&
                                                    v[0].Value <string>().Equals(g.Mail,
                                                                                 StringComparison.OrdinalIgnoreCase)))
                                 .ToArray();

            // Set (singleton) config.
            _configService.User     = user;
            _configService.AppGroup = appGroup;
            _configService.Groups   = new List <GroupModel>(propertyGroups);
            _configService.DataFile = dataFile;

            // Navigate to the groups view.
            ShowViewModel <GroupsViewModel>();

            // Update only the underlying field for a better UI experience.
            _isLoading = false;
        }