示例#1
0
        public string CreateAllData(int totalRecordCount, List <SimpleRow> maps, string entityName, BackgroundWorker wrker, SetItem setItem)
        {
            int initialCount     = totalRecordCount;
            int recordCount      = totalRecordCount > 500 ? 500 : totalRecordCount;
            int noRuns           = (int)Math.Ceiling((double)totalRecordCount / (double)recordCount);
            int percDone         = 0;
            var entityCollection = new EntityCollection {
                EntityName = entityName
            };
            var mockClass = new ExpandoObject();

            foreach (var map in maps)
            {
                ((IDictionary <string, object>)mockClass)[map.LogicalName] = map.SelectedMock;
            }

            wrker.ReportProgress(0, "Getting Mockaroo Data for " + entityName);
            var    client = new MockClient(txtMockKey.Text);
            string errors = string.Empty;

            if (collection != null && collection.Entities.Count > 0)
            {
                recordCount = collection.Entities.Count;
                wrker.ReportProgress(percDone, "Creating Sample Data");
                errors           += CreateData(collection, wrker, setItem, entityName);
                totalRecordCount -= recordCount;
                SendMessageToStatusBar?.Invoke(this, new StatusBarMessageEventArgs(
                                                   (int)Math.Round((double)(initialCount - totalRecordCount) * 100 / initialCount),
                                                   $"{totalRecordCount} {entityName} Records remaining"));
            }
            while (totalRecordCount > 0)
            {
                recordCount = totalRecordCount > 1000 ? 1000 : totalRecordCount;
                List <ExpandoObject> returnData = client.GetData(mockClass, recordCount);
                wrker.ReportProgress(percDone, "Got Data, Generating Entity Collection");
                foreach (List <ExpandoObject> subList in SplitList(returnData))
                {
                    entityCollection = CreateEntityCollection(subList, entityName, maps);
                    wrker.ReportProgress(percDone, "Retrieved Mockaroo Data, Creating in Dataverse");
                    percDone += 100 / noRuns;
                    errors   += CreateData(entityCollection, wrker, setItem, entityName);

                    totalRecordCount -= subList.Count();
                    SendMessageToStatusBar?.Invoke(this, new StatusBarMessageEventArgs(
                                                       (int)Math.Round((double)(initialCount - totalRecordCount) * 100 / initialCount),
                                                       $"{totalRecordCount} {entityName} Records remaining"));
                    wrker.ReportProgress(percDone, "Created Data");
                }
            }

            return(errors);
        }
示例#2
0
        public void GetInitMockData(int recordCount, List <SimpleRow> maps, string entityName)
        {
            var mockClass = new ExpandoObject();

            foreach (var map in maps)
            {
                ((IDictionary <string, object>)mockClass)[map.LogicalName] = map.SelectedMock;
                if (map.SelectedMock is FromSet)
                {
                    //var parentSI = selectedSet.SetItems
                    //    .FirstOrDefault(si => si.entityName == simpleRow.SelectedMock.EntityName);

                    //if (parentSI == null) ((FromSet)simpleRow.SelectedMock).Values = GetLinkedRecords(
                    //                          simpleRow.SelectedMock);
                    //else
                    ((FromSet)map.SelectedMock).Values = GetLinkedRecords(map.SelectedMock);
                }
            }
            var intialCollection = new EntityCollection {
                EntityName = entityName
            };

            WorkAsync(
                new WorkAsyncInfo
            {
                Message = "Getting Mockaroo Data...",
                Work    =
                    (w, e) =>
                {
                    var client     = new MockClient(txtMockKey.Text);
                    var returnData = client.GetData(mockClass, recordCount);

                    w.ReportProgress(50, "Got Data, Generating Sample");

                    intialCollection = CreateEntityCollection(returnData, entityName, maps);
                    w.ReportProgress(50, "Populating grid");

                    e.Result = intialCollection.Entities;
                },
                ProgressChanged  = e => SetWorkingMessage(e.UserState.ToString()),
                PostWorkCallBack =
                    e =>
                {
                    if (e.Error != null)
                    {
                        LogError(e.Error.ToString());
                        MessageBox.Show(
                            e.Error.Message.ToString(),
                            "Error generating data",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error);
                        //ShowErrorNotification(
                        //    e.Error.ToString(),
                        //    new Uri("https://www.linked365.blog/"));
                        intialCollection.Entities.Clear();
                    }
                    else
                    {
                        gridSample.DataSource = e.Result;
                        collection.Entities.Clear();
                        collection.Entities.AddRange(e.Result as DataCollection <Entity>);

                        ShowResults();



                        updateEntities.Clear();

                        if (recordCount != numRecordCount.Value)
                        {
                            btnCreateBatch.Visible = true;
                            btnCreateBatch.Text    = "Create " + numRecordCount.Value + " records";
                            btnCreateData.Text     = "Create " + recordCount + " records";
                        }
                        else
                        {
                            btnCreateBatch.Visible = false;
                            btnCreateData.Text     = "Create Records";
                        }
                    }
                }
            });
        }