예제 #1
0
        public PerformanceItem GetSample()
        {
            var result = new PerformanceItem()
            {
                TimeSheetPercentage = 80,
                ManagerPercentage   = 20,
                Factor    = 0.75,
                DateRange = new DateRange(DateTimeUtil.GetCurrentPeriodStartDay(), DateTimeUtil.GetCurrentPeriodStartDay().AddDays(6))
            };

            var userGroup = this.GetService <DepartmentService>().GetUserGroupsByOwnerId(this.GetUserId()).FirstOrDefault();

            if (userGroup != null)
            {
                var levels = this.GetService <UserService>().GetByIds(userGroup.UserIds.Where(o => o != this.GetUserId()).ToList())
                             .ToDictionary(o => o.Id, o => o.Level);

                foreach (var level in levels)
                {
                    result.Values.Add(level.Key, new Score(level.Value));
                }
            }

            return(result);
        }
예제 #2
0
        public PerformanceItem Pull([FromBody] PerformanceItem item)
        {
            foreach (var user in item.Values)
            {
                user.Value.TimeSheetValue = this.GetService <TimeSheetService>().
                                            GetContribution(user.Key, item.DateRange.StartDate.ToLocalTime(), item.DateRange.EndDate.ToLocalTime());
            }

            return(item);
        }
예제 #3
0
 public JsonResult AddItem([FromBody] PerformanceItem item)
 {
     try {
         var userGroup = this.GetService <DepartmentService>().GetUserGroupsByOwnerId(this.GetUserId()).FirstOrDefault();
         this.GetService <UserPerformanceService>().AddItem(userGroup.Id, item);
         return(Json(new { successMsg = string.Format("Save performance successfully!") }));
     }
     catch (Exception ex)
     {
         _logger.LogError(ex.Message);
         return(Json(new { errorMsg = ex.Message }));
     }
 }
예제 #4
0
 private void LocalOrchestraUpdate(List <ActorItem> actors)
 {
     if (Sharlayan.Reader.CanGetPerformance())
     {
         PerformanceResult performance = Sharlayan.Reader.GetPerformance();
         foreach (ActorItem actor in actors)
         {
             uint perfId = actor.PerformanceID / 2;
             if (perfId < 99)
             {
                 PerformanceItem   item = performance.Performances[perfId];
                 BmpLocalPerformer perf = LocalOrchestra.FindPerformer(actor.Name);
                 if (perf != null)
                 {
                     perf.UiEnabled = item.IsReady();
                 }
                 //Console.WriteLine(string.Format("{1} ({0}) => {2}", actor.ID, actor.Name, item.IsReady()));
             }
         }
     }
 }
예제 #5
0
        public void AddItem(string userGroupId, PerformanceItem item)
        {
            var entity = Get(userGroupId);

            if (entity == null)
            {
                entity = new UserPerformance(userGroupId);
                Create(entity);
            }

            if (entity.Items.IsEmpty())
            {
                item.Id = 0;
            }
            else
            {
                item.Id = ++entity.Items.Last().Id;
            }

            entity.Items.Add(item);

            Update(entity);
        }
예제 #6
0
        public void UpdateMemory()
        {
            if (Sharlayan.MemoryHandler.Instance.IsAttached)
            {
                if (Sharlayan.Reader.CanGetActors() && Sharlayan.Reader.CanGetPerformance())
                {
                    List <string> performerNames = GetPerformerNames();

                    int pid = -1;
                    PerformanceResult perfs = Sharlayan.Reader.GetPerformance();
                    ActorResult       ares  = Sharlayan.Reader.GetActors();
                    if (ares != null)
                    {
                        foreach (ActorItem actor in ares.CurrentPCs.Values.ToList())
                        {
                            if (performerNames.Contains(actor.Name))
                            {
                                uint perfId = actor.PerformanceID / 2;
                                if (perfId >= 0 && perfId < 99 && perfs.Performances.ContainsKey(perfId))
                                {
                                    PerformanceItem item = perfs.Performances[perfId];

                                    BmpLocalPerformer perf = this.FindPerformer(actor.Name);
                                    if (perf != null)
                                    {
                                        perf.PerformanceUp = item.IsReady();
                                        perf.performanceId = perfId;
                                        perf.actorId       = actor.ID;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
예제 #7
0
        /// <summary>
        /// Reads data from an excel file and retuns this as a <see cref="FlexTable{T}"/>
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="fullFileName"></param>
        /// <returns></returns>
        public FlexTable <T> LoadFromExcel <T>(string fullFileName) where T : FlexRow
        {
            if (!File.Exists(fullFileName))
            {
                throw new FileNotFoundException(fullFileName);
            }

            PerformanceItem pi        = null;
            var             flexTable = new FlexTable <T>();

            this.stopProcessing = false;

            // start excel and turn off msg boxes

            this.UpdateStatus("Waiting for Excel to open...");
            using (Excel.Application excelApplication = new Excel.Application())
            {
                this.UpdateStatus("Excel opened");

                try
                {
                    excelApplication.DisplayAlerts = false;
                    excelApplication.EnableEvents  = false;

                    var workbook  = excelApplication.Workbooks.Open(fullFileName);
                    var worksheet = (Excel.Worksheet)workbook.Worksheets[1];

                    var allCells           = worksheet.UsedRange;
                    var colCount           = allCells.Columns.Count;
                    var rowCount           = allCells.Rows.Count;
                    var colHeader          = new Dictionary <int, string>();
                    var continueProcessing = true;

                    object[,] allCellsValues = (object[, ])allCells.Value;

                    // get header row
                    this.UpdateStatus("Reading column headers");
                    for (int idx = 1; idx <= colCount; idx++)
                    {
                        if (this.stopProcessing)
                        {
                            break;
                        }
                        var cell = allCellsValues[HeaderRow, idx];

                        if (cell != null)
                        {
                            var header = cell.ToString().Trim();
                            if (!colHeader.ContainsValue(header))
                            {
                                colHeader.Add(idx, header);
                            }
                            else
                            {
                                this.UpdateStatus(string.Format("ERROR! Duplicate column name found: {0}", header));
                                continueProcessing = false;
                            }
                        }
                    }

                    // let the header be validated (if registered to the event)
                    if (continueProcessing && this.ValidateHeader != null)
                    {
                        this.UpdateStatus("Validating header against mapping specification");

                        var eventArgs = new ValidationEventArgs(colHeader.Values.ToList());
                        this.ValidateHeader(this, eventArgs);
                        if (eventArgs.Cancel)
                        {
                            continueProcessing = false;
                        }
                    }

                    // now read the rows (if validation was a success)
                    if (continueProcessing)
                    {
                        if (RequestRequiredColumnNames != null)
                        {
                            var requiredColumnNames = this.RequestRequiredColumnNames(colHeader.Values.ToList());

                            // build the table: create all required columns
                            foreach (var header in colHeader.Values.Where(h => requiredColumnNames.Contains(h)))
                            {
                                flexTable.AddColumn(header, typeof(object));
                            }

                            // remove all unnecessary columns from the column lookup
                            foreach (var droppedColumnName in colHeader.Values.Except(requiredColumnNames).ToList())
                            {
                                var item = colHeader.First(ch => ch.Value == droppedColumnName);
                                colHeader.Remove(item.Key);
                            }
                        }
                        else
                        {
                            // build the table: create all columns found in the excel.
                            foreach (var columnName in colHeader.Values)
                            {
                                flexTable.AddColumn(columnName, typeof(object));
                            }
                        }

                        var startData = (!this.firstDataRow.HasValue) ? HeaderRow + 1 : this.firstDataRow.Value;

                        this.UpdateStatus("Reading data from Excel ...");
                        pi = PerformanceCenter.StartTiming("Excel", "reading cells");

                        for (int rowIdx = startData; rowIdx < rowCount; rowIdx++)
                        {
                            if (this.stopProcessing)
                            {
                                break;
                            }
                            this.UpdateStatus("Progress", string.Format("{0}/{1}", rowIdx, rowCount));

                            // create a new row and copy all relevant cells
                            var row = flexTable.NewRow <T>(rowIdx.ToString());
                            for (int colIdx = 1; colIdx <= colCount; colIdx++)
                            {
                                if (colHeader.ContainsKey(colIdx))
                                {
                                    row[colHeader[colIdx]] = allCellsValues[rowIdx, colIdx];
                                }
                            }

                            // skip completely empty rows!
                            if (row.ContainsValues())
                            {
                                flexTable.Add(row);
                            }
                        }
                    }
                    else
                    {
                        flexTable = null;
                    }
                }
                finally
                {
                    if (pi != null)
                    {
                        pi.StopTiming();
                        this.UpdateStatus(string.Format(@"{0} rows read in {1:hh\:mm\:ss}", flexTable.Count, pi.LatestDuration));
                    }

                    // ensure that the excel instance get's closed
                    excelApplication.Quit();
                    Debug.WriteLine("Excel closed");
                }
            }

            return(flexTable);
        }
예제 #8
0
        public static PerformanceResult GetPerformance()
        {
            var result = new PerformanceResult();

            if (!CanGetPerformance() || !MemoryHandler.Instance.IsAttached)
            {
                return(result);
            }


            try {
                var PerformanceStatusMap = (IntPtr)Scanner.Instance.Locations[Signatures.PerformanceStatusKey];

                int    entrySize       = 28;
                int    numEntries      = 99;
                byte[] performanceData = MemoryHandler.Instance.GetByteArray(Scanner.Instance.Locations[Signatures.PerformanceStatusKey], entrySize * numEntries);

                for (int i = 0; i < numEntries; i++)
                {
                    int offset = (i * entrySize);

                    //float animation = BitConverter.TryToSingle(performanceData, offset + 8);
                    byte id = performanceData[offset + 12];
                    //byte unknown1 = performanceData[offset + 13]; // No clue
                    //byte variant = performanceData[offset + 14]; // Animation (hand to left or right)
                    byte type       = performanceData[offset + 15];
                    byte status     = performanceData[offset + 21];
                    byte instrument = performanceData[offset + 22];
                    //int unknown2 = BitConverter.TryToInt16(performanceData, offset + 10);

                    if (instrument == 5)
                    {
                        Debug.WriteLine($"id -> {id}");
                        Debug.WriteLine($"status = {status}");
                        Debug.WriteLine($"instrument = {instrument}");
                    }

                    if (id >= 0 && id <= 99)
                    {
                        PerformanceItem item = new PerformanceItem();
                        //item.Animation = animation;
                        //item.Unknown1 = (byte)unknown1;
                        item.Id = (byte)id;
                        //item.Variant = (byte) variant;
                        //item.Type = (byte) type;
                        item.Status     = (Performance.Status)status;
                        item.Instrument = (Performance.Instrument)instrument;

                        if (!result.Performances.ContainsKey(id))
                        {
                            result.Performances[id] = item;
                        }
                    }
                }

                /*
                 * var PerformanceLayoutMap = (IntPtr) Scanner.Instance.Locations[Signatures.PerformanceLayoutKey];
                 *
                 * byte layout = MemoryHandler.Instance.GetByte(PerformanceLayoutMap);
                 * result.Layout = layout;
                 */
            }
            catch (Exception ex) {
                MemoryHandler.Instance.RaiseException(Logger, ex, true);
            }

            return(result);
        }
예제 #9
0
 public PerformanceItem Calculate([FromBody] PerformanceItem item)
 {
     item.Calculate();
     return(item);
 }