private static bool IsEquals(KeyValueListCM a, KeyValueListCM b)
        {
            if (ReferenceEquals(a, b))
            {
                return(true);
            }

            if (a.Values == null && b.Values == null)
            {
                return(true);
            }

            if (a.Values == null || b.Values == null)
            {
                return(false);
            }

            if (a.Values.Count != b.Values.Count)
            {
                return(false);
            }

            foreach (var fieldDto in a.Values)
            {
                var field = fieldDto;

                if (!b.Values.Any(x => x.Key == field.Key && x.Value == field.Value))
                {
                    return(false);
                }
            }

            return(true);
        }
        public Crate PackCrate_GoogleSpreadsheets()
        {
            Crate crate;

            var curFields = new KeyValueListCM(
                new KeyValueDTO
            {
                Key   = "Column_Only",
                Value = @"https://spreadsheets.google.com/feeds/spreadsheets/private/full/1o0cle_rnfVtmeLqDDeF40dRWKL6FSCuQz5E84pcCpTs"
            },
                new KeyValueDTO
            {
                Key   = "Row_Only",
                Value = @"https://spreadsheets.google.com/feeds/spreadsheets/private/full/1pzbssu5vuCqv5LMTdIQ7SCqVFaQR0_d7MnB7oGonzf0"
            },
                new KeyValueDTO
            {
                Key   = "Row_And_Column",
                Value = @"https://spreadsheets.google.com/feeds/spreadsheets/private/full/1zG93EWaycPyCdM9OJf03C2knK9Neu09OutAl2p7NZbw"
            },
                new KeyValueDTO
            {
                Key   = "Empty_First_Row",
                Value = @"https://spreadsheets.google.com/feeds/spreadsheets/private/full/1Nzf_s2OyZTxG8ppxzvypH6s1ePvUT_ALPffZchuM14o"
            },
                new KeyValueDTO
            {
                Key   = "OneRow_WithHeader",
                Value = @"https://spreadsheets.google.com/feeds/spreadsheets/private/full/1XES9LEK6WmSp5adZ8F-_cfoE7EeLMgPr6NhRPyGaSfM"
            }
                );

            return(Crate.FromContent("Select a Google Spreadsheet", curFields));
        }
        private void SetConfigurationProperties(ConfigurationProperties configProps)
        {
            var fd = new KeyValueListCM(
                new KeyValueDTO("SelectedProjectKey", configProps.SelectedProjectKey),
                new KeyValueDTO("SelectedIssueType", configProps.SelectedIssueType)
                );

            Storage.ReplaceByLabel(Crate.FromContent(ConfigurationPropertiesLabel, fd));
        }
Example #4
0
        private static void ValidateFr8ObjectCrateStructure(KeyValueListCM designTimeCrate)
        {
            var designTimeFields = designTimeCrate.Values;

            Assert.AreEqual(2, designTimeFields.Count);

            var field1 = designTimeFields[0];

            Assert.AreEqual("Plans", field1.Key);
            Assert.AreEqual("19", field1.Value);

            var field2 = designTimeFields[1];

            Assert.AreEqual("Containers", field2.Key);
            Assert.AreEqual("21", field2.Value);
        }
        public async Task <PollingDataDTO> Poll(PollingDataDTO pollingData, GDrivePollingType pollingType)
        {
            var googleAuthToken = JsonConvert.DeserializeObject <GoogleAuthDTO>(pollingData.AuthToken);
            var driveService    = await _googleDrive.CreateDriveService(googleAuthToken);

            string startPageToken;

            if (string.IsNullOrEmpty(pollingData.Payload))
            {
                var response = driveService.Changes.GetStartPageToken().Execute();
                startPageToken = response.StartPageTokenValue;
            }
            else
            {
                startPageToken = pollingData.Payload;
            }

            var changedFiles = new Dictionary <string, string>();

            var pageToken = startPageToken;

            while (pageToken != null)
            {
                var request = driveService.Changes.List(pageToken);
                request.Fields = "changes,kind,newStartPageToken,nextPageToken";
                request.Spaces = "drive";

                var changes = request.Execute();
                foreach (var change in changes.Changes)
                {
                    if (!string.IsNullOrEmpty(change.File.MimeType) &&
                        change.File.MimeType.ToUpper() == _fileTypes[pollingType])
                    {
                        if (!changedFiles.ContainsKey(change.FileId))
                        {
                            changedFiles.Add(change.FileId, change.File.Name);
                        }
                    }
                }

                if (!string.IsNullOrEmpty(changes.NewStartPageToken))
                {
                    startPageToken = changes.NewStartPageToken;
                }

                pageToken = changes.NextPageToken;
            }

            if (changedFiles.Count > 0)
            {
                var changedFilesCM = new KeyValueListCM();
                foreach (var pair in changedFiles)
                {
                    changedFilesCM.Values.Add(new KeyValueDTO(pair.Key, pair.Value));
                }

                var eventReportContent = new EventReportCM
                {
                    EventNames        = _eventNames[pollingType],
                    EventPayload      = new CrateStorage(Crate.FromContent("ChangedFiles", changedFilesCM)),
                    Manufacturer      = "Google",
                    ExternalAccountId = pollingData.ExternalAccountId
                };

                Logger.Info("Polling for Google Drive: changed files of type \"" + pollingType.ToString() + "\"");
                await _reporter.Broadcast(Crate.FromContent("Standard Event Report", eventReportContent));
            }

            pollingData.Payload = startPageToken;
            return(pollingData);
        }
        public override async Task Run()
        {
            var eventCrate = Payload.CratesOfType <EventReportCM>().FirstOrDefault()
                             ?.Get <EventReportCM>()
                             ?.EventPayload;

            KeyValueListCM changedFiles = null;

            if (eventCrate != null)
            {
                changedFiles = eventCrate
                               .CrateContentsOfType <KeyValueListCM>(x => x.Label == "ChangedFiles")
                               .SingleOrDefault();
            }

            if (changedFiles == null)
            {
                RequestPlanExecutionTermination("File list was not found in the payload.");
            }

            if (ActivityUI.AllSpreadsheetsOption.Selected)
            {
                var rows = new List <TableRowDTO>();
                foreach (var changedFile in changedFiles.Values)
                {
                    var row = new TableRowDTO();
                    row.Row.Add(TableCellDTO.Create(SpreadsheetIdLabel, changedFile.Key));
                    row.Row.Add(TableCellDTO.Create(SpreadsheetNameLabel, changedFile.Value));

                    rows.Add(row);
                }

                var tableData = new StandardTableDataCM(false, rows);

                Payload.Add(Crate.FromContent(RunTimeCrateLabel, tableData));
                Success();
            }
            else
            {
                var hasFileId = changedFiles.Values.Any(x => x.Key == ActivityUI.SpreadsheetList.Value);
                if (!hasFileId)
                {
                    RequestPlanExecutionTermination();
                }
                else
                {
                    var rows        = new List <TableRowDTO>();
                    var changedFile = changedFiles.Values.Where(x => x.Key == ActivityUI.SpreadsheetList.Value).First();

                    var row = new TableRowDTO();
                    row.Row.Add(TableCellDTO.Create(SpreadsheetIdLabel, changedFile.Key));
                    row.Row.Add(TableCellDTO.Create(SpreadsheetNameLabel, changedFile.Value));
                    rows.Add(row);

                    var tableData = new StandardTableDataCM(false, rows);

                    Payload.Add(Crate.FromContent(RunTimeCrateLabel, tableData));
                    Success();
                }
            }
        }