Example #1
0
        public void GenerateKey()
        {
            var a = CryptoUtilities.GenerateKey(32);
            //Debug.WriteLine("UTF8 - " + new String(Encoding.UTF8.GetChars(a)));
            //Debug.WriteLine("unicode [little Endian] - " + Encoding.Unicode.GetChars(a));
            //Debug.WriteLine("unicode [big endian]- " + Encoding.BigEndianUnicode.GetChars(a));
            //Debug.WriteLine("ASCI - " + Encoding.ASCII.GetChars(a));
            string b64 = Convert.ToBase64String(a);

            Debug.WriteLine("Base64 - " + b64);
            CollectionAssert.AreEqual(a, Convert.FromBase64String(b64));
            Debug.WriteLine("Byte[] - new byte[] {" + string.Join(",", a) + '}');
        }
Example #2
0
        private int RunCommand()
        {
            string rosterPath = _rosterFilePathCmd.Value();

            if (string.IsNullOrEmpty(rosterPath))
            {
                Error.WriteLine($"The roster option ({_rosterFilePathCmd.Template}) must be specified");
                return(1);
            }

            if (!ExcelFileOk(rosterPath, "roster"))
            {
                return(1);
            }

            string departmentName = _departmentCmd.Value();

            if (string.IsNullOrEmpty(departmentName))
            {
                Error.WriteLine($"A department name ({_departmentCmd.Template}) must be specified");
                return(1);
            }
            bool headerType = _rosterTypeHeaderCmd.Value() != null;

            if (headerType && _rosterTypeColumnsCmd.Value() != null)
            {
                Error.WriteLine("Must specify either headers or columns option, but not both");
                return(1);
            }

            if (Storage.Find(_arg.Value) != null)
            {
                Error.WriteLine("the description must be unique - " + _arg.Value + " already exists");
                return(1);
            }

            string dateCol = _dateColumnCmd.Value();

            if (string.IsNullOrEmpty(dateCol))
            {
                Out.WriteLine("No datecol option specified - defaulting to A");
                dateCol = "A";
            }

            string     mapPath = _mapFilePathCmd.Value();
            XLWorkbook wb;
            bool       isNew = false;

            if (string.IsNullOrEmpty(mapPath))
            {
                Out.WriteLine("No map specified - using roster file");
                wb = new XLWorkbook(rosterPath);
            }
            else if (File.Exists(mapPath))
            {
                if (!ExcelFileOk(mapPath, "map"))
                {
                    return(1);
                }
                wb = new XLWorkbook(mapPath);
            }
            else
            {
                if (!ExtensionOk(mapPath, "map"))
                {
                    return(1);
                }
                wb    = new XLWorkbook();
                isNew = true;
            }
            AddSheets(wb);
            if (isNew)
            {
                wb.SaveAs(mapPath);
            }
            else
            {
                wb.Save();
            }
            wb.Dispose();

            var secret  = CryptoUtilities.GenerateKey();
            var newInfo = new ExcelRosterFileInfo {
                Description  = _arg.Value,
                Base64Secret = Convert.ToBase64String(secret),
                MapPath      = mapPath,
                RosterPath   = rosterPath,
                RosterId     = Guid.NewGuid(),
                RosterType   = headerType ? ExcelRosterFileInfo.RosterTypes.HorizontallyListedNames : ExcelRosterFileInfo.RosterTypes.ImplicitNames,
                DateColumn   = dateCol
            };

            var res = SendEntities.CreateRoster(new Roster
            {
                Id             = newInfo.RosterId,
                RosterName     = newInfo.Description,
                Secret         = secret,
                DepartmentName = departmentName
            }, Out, Error);

            if (res == null || !res.IsSuccessStatusCode)
            {
                return(1);
            }
            Storage.Add(newInfo);
            Out.WriteLine("Successfully added with id " + newInfo.RosterId.ToString());
            return(0);
        }