Exemplo n.º 1
0
        public void Execute()
        {
            MetadataHelper metadataHelper = new MetadataHelper(Service);

            LogWriter.LogInfo("ExportCommand: Retrieving entity list");
            typeCodeList = metadataHelper.RetrieveEntityList();

            FetchXmlHelper fetchXmlHelper = new FetchXmlHelper();

            LogWriter.LogInfo("ExportCommand: Buidling Fetch XML");
            string fetchXml = fetchXmlHelper.Build(entityName, metadataHelper.RetrieveEntity(entityName).EntityMetadata.Attributes);

            LogWriter.LogInfo(fetchXml);

            LogWriter.LogInfo($"ExportCommand: Exporting data from {OrganisationUrl}");
            EntityCollection entities = Service.RetrieveMultiple(new FetchExpression(fetchXml));

            LogWriter.LogInfo($"ExportCommand: Retrieved data, Count: {entities.Entities.Count}");

            Parallel.ForEach(entities.Entities, entity =>
            {
                entity["entityname"] = getEntityName(entity);
            }
                             );

            EntityCollectionSerializer ecSerializer = new EntityCollectionSerializer()
            {
                FileName = FileName,
            };

            LogWriter.LogInfo("ExportCommand: Serializing data");
            ecSerializer.Serialize(entities);

            compressFile();
        }
Exemplo n.º 2
0
        public void Execute()
        {
            int errorCount = 0, updatedCount = 0, createdCount = 0;

            if (IsZipFile)
            {
                decompress();
            }

            MetadataHelper metadataHelper           = new MetadataHelper(Service);

            LogWriter.LogInfo("ImportCommand: Retrieving entity metadata");
            typeCodeList = metadataHelper.RetrieveEntityList();

            EntityCollectionSerializer ecSerializer = new EntityCollectionSerializer();

            LogWriter.LogInfo("ImportCommand: Deserializing file");
            EntityCollection entities               = ecSerializer.Deserialize(FileName);

            LogWriter.LogInfo($"ImportCommand: Importing access team templates to {OrganisationUrl}");
            Parallel.ForEach(entities.Entities, entity =>
            {
                var entityName = entity["entityname"].ToString();
                if (typeCodeList.ContainsKey(entityName))
                {
                    entity["objecttypecode"] = typeCodeList[entity["entityname"].ToString()];
                    entity.Attributes.Remove("entityname");
                    try
                    {
                        try
                        {
                            Service.Update(entity);
                            updatedCount++;
                            LogWriter.LogInfo($"ImportCommand: Updated access team template with id {entity.Id}");
                        }
                        catch (FaultException <OrganizationServiceFault> )
                        {
                            Service.Create(entity);
                            createdCount++;
                            LogWriter.LogInfo($"ImportCommand: Created access team template with id {entity.Id}");
                        }
                    }
                    catch (FaultException <OrganizationServiceFault> fe)
                    {
                        errorCount++;
                        LogWriter.LogError($"ImportCommand: An error with id {entity.Id} - {entity["teamtemplatename"]}. Details: {fe.Message}");
                    }
                }
            }
                             );

            LogWriter.LogInfo($"ImportCommand: Summary");
            LogWriter.LogInfo($"ImportCommand: Total {entities.Entities.Count}, Updated {updatedCount}, Created {createdCount}, Error {errorCount}");
        }
        private void SaveLogs()
        {
            var sfd = new SaveFileDialog
            {
                Title  = "Select a location to save the logs",
                Filter = "XML file (*.xml)|*.xml"
            };

            if (sfd.ShowDialog() == DialogResult.OK)
            {
                var newfile = sfd.FileName;
                if (!string.IsNullOrEmpty(newfile))
                {
                    var serialized = EntityCollectionSerializer.Serialize(gridControl.Entities, SerializationStyle.Explicit);
                    serialized.Save(newfile);
                    MessageBox.Show(this, "Logs saved!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }
Exemplo n.º 4
0
 private void RetrieveMultiple(string fetch)
 {
     working = true;
     SendMessageToStatusBar(this, new StatusBarMessageEventArgs("Retrieving..."));
     tsbAbort.Enabled = true;
     WorkAsync(new WorkAsyncInfo
     {
         Message      = "Executing FetchXML...",
         IsCancelable = true,
         Work         = (worker, eventargs) =>
         {
             QueryBase query         = new FetchExpression(fetch);
             var querysignature      = dockControlBuilder.GetTreeChecksum(null);
             var attributessignature = dockControlBuilder.GetAttributesSignature();
             var start = DateTime.Now;
             EntityCollection resultCollection = null;
             EntityCollection tmpResult        = null;
             var page = 0;
             do
             {
                 if (worker.CancellationPending)
                 {
                     eventargs.Cancel = true;
                     break;
                 }
                 tmpResult = RetrieveMultiple(query);
                 if (resultCollection == null)
                 {
                     resultCollection = tmpResult;
                 }
                 else
                 {
                     resultCollection.Entities.AddRange(tmpResult.Entities);
                     resultCollection.MoreRecords      = tmpResult.MoreRecords;
                     resultCollection.PagingCookie     = tmpResult.PagingCookie;
                     resultCollection.TotalRecordCount = tmpResult.TotalRecordCount;
                     resultCollection.TotalRecordCountLimitExceeded = tmpResult.TotalRecordCountLimitExceeded;
                 }
                 if (settings.Results.RetrieveAllPages && tmpResult.MoreRecords)
                 {
                     if (query is QueryExpression qex)
                     {
                         qex.PageInfo.PageNumber++;
                         qex.PageInfo.PagingCookie = tmpResult.PagingCookie;
                     }
                     else if (query is FetchExpression fex && fex.Query is string pagefetch)
                     {
                         var pagedoc = new XmlDocument();
                         pagedoc.LoadXml(pagefetch);
                         if (pagedoc.SelectSingleNode("fetch") is XmlElement fetchnode)
                         {
                             if (!int.TryParse(fetchnode.GetAttribute("page"), out int pageno))
                             {
                                 pageno = 1;
                             }
                             pageno++;
                             fetchnode.SetAttribute("page", pageno.ToString());
                             fetchnode.SetAttribute("pagingcookie", tmpResult.PagingCookie);
                             query = new FetchExpression(pagedoc.OuterXml);
                         }
                     }
                     else
                     {
                         MessageBox.Show("Unable to retrieve more pages, unexpected query.", "Retrieve all pages", MessageBoxButtons.OK, MessageBoxIcon.Error);
                         break;
                     }
                 }
                 page++;
                 var duration = DateTime.Now - start;
                 var pageinfo = page == 1 ? "first page" : $"{page} pages";
                 worker.ReportProgress(0, $"Retrieved {pageinfo} in {duration.TotalSeconds:F2} sec");
                 SendMessageToStatusBar(this, new StatusBarMessageEventArgs($"Retrieved {resultCollection.Entities.Count} records on {pageinfo} in {duration.TotalSeconds:F2} seconds"));
             }while (!eventargs.Cancel && settings.Results.RetrieveAllPages && (query is QueryExpression || query is FetchExpression) && tmpResult.MoreRecords);
             LogUse($"RetrieveMultiple-{settings.Results.ResultOutput}", false, resultCollection?.Entities?.Count, (DateTime.Now - start).TotalMilliseconds);
             if (settings.Results.ResultOutput == ResultOutput.JSON)
             {
                 var json         = EntityCollectionSerializer.ToJSONComplex(resultCollection, Formatting.Indented);
                 eventargs.Result = json;
             }
             else if (settings.Results.ResultOutput == ResultOutput.JSONWebAPI)
             {
                 var json         = EntityCollectionSerializer.ToJSONSimple(resultCollection, Formatting.Indented);
                 eventargs.Result = json;
             }
             else
             {
                 eventargs.Result = new QueryInfo
                 {
                     Query               = query,
                     QuerySignature      = querysignature,
                     AttributesSignature = attributessignature,
                     Results             = resultCollection
                 };
             }
         },