protected void LoadAssignmentData()
        {
            var    credentials = GetCredentialsFrom(User.Identity.Name);
            string path        = string.Format(
                options.AlbaAssignmentsHtmlPath,
                credentials.AlbaAccountId);

            if (io.File.Exists(path))
            {
                io.File.Delete(path);
            }

            var client = AuthClient();

            client.Authenticate(credentials);

            var assignmentsJson = client.DownloadString(
                RelativeUrlBuilder.GetTerritoryAssignments());

            string assignmentsHtml = TerritoryAssignmentParser.Parse(assignmentsJson);

            if (!io.Directory.Exists(io.Path.GetDirectoryName(path)))
            {
                io.Directory.CreateDirectory(io.Path.GetDirectoryName(path));
            }

            io.File.WriteAllText(path, assignmentsHtml);
        }
Beispiel #2
0
        public void SaveAs(string fileName)
        {
            var resultString = client.DownloadString(
                RelativeUrlBuilder.GetTerritoryAssignments());

            string html = TerritoryAssignmentParser.Parse(resultString);

            SaveAs(html, fileName);
        }
        public List <Territory> SaveAs(string fileName)
        {
            var resultString = client.DownloadString(RelativeUrlBuilder.GetAllTerritories());

            AllTerritories = TerritoryResultParser.Parse(resultString);

            var assignmentsResultString = client.DownloadString(
                RelativeUrlBuilder.GetTerritoryAssignments());

            string assignmentsHtml = TerritoryAssignmentParser.Parse(assignmentsResultString);

            var assignments = new DownloadTerritoryAssignments(client).GetAssignments(assignmentsHtml);

            foreach (var t in AllTerritories)
            {
                var assignment = assignments.FirstOrDefault(a => string.Equals(a.Number, t.Number, StringComparison.OrdinalIgnoreCase));

                if (assignment != null)
                {
                    int monthsAgoCompleted = assignment.MonthsAgoCompleted ?? 0;
                    int yearsAgoCompleted  = monthsAgoCompleted / 12;

                    t.Status             = assignment.Status;
                    t.MobileLink         = assignment.MobileLink;
                    t.SignedOutTo        = assignment.SignedOutTo;
                    t.SignedOut          = assignment.SignedOut;
                    t.LastCompletedBy    = assignment.LastCompletedBy;
                    t.LastCompleted      = assignment.LastCompleted;
                    t.MonthsAgoCompleted = assignment.MonthsAgoCompleted;
                    t.YearsAgoCompleted  = assignment.LastCompleted == null
                        ? 99
                        : yearsAgoCompleted;
                    t.NeverCompleted = assignment.LastCompleted == null;
                }
            }

            var filteredTerritories = Filter(AllTerritories);

            foreach (var t in filteredTerritories)
            {
                t.FillColor = FillColorFor(t);
            }

            var kml = new TerritoryToKmlConverter().KmlFrom(filteredTerritories);

            new KmlGateway().Save(fileName, kml);

            return(filteredTerritories.ToList());
        }
        private void Load(Guid albaAccountId)
        {
            string path = string.Format(options.AlbaAssignmentsHtmlPath, albaAccountId);

            if (System.IO.File.Exists(path))
            {
                System.IO.File.Delete(path);
            }

            var client = AuthorizationClient();

            var useCase = new DownloadTerritoryAssignments(client);

            var credentials = albaCredentialService.GetCredentialsFrom(User.Identity.Name);

            client.Authenticate(credentials);

            var resultString = client.DownloadString(
                RelativeUrlBuilder.GetTerritoryAssignments());

            string html = TerritoryAssignmentParser.Parse(resultString);

            System.IO.File.WriteAllText(path, html);
        }