コード例 #1
0
        private static void CopyChanges(this ConnectionDetail connectionDetail, Label existingLabel, Label newLabel, List <Guid> deletedIds)
        {
            if (newLabel == null)
            {
                return;
            }

            foreach (var localizedLabel in newLabel.LocalizedLabels)
            {
                var existingLocalizedLabel = existingLabel.LocalizedLabels.SingleOrDefault(ll => ll.MetadataId == localizedLabel.MetadataId);

                if (existingLocalizedLabel == null)
                {
                    existingLabel.LocalizedLabels.Add(localizedLabel);
                }
                else
                {
                    connectionDetail.CopyChanges(existingLocalizedLabel, localizedLabel, deletedIds);
                }
            }

            for (var i = existingLabel.LocalizedLabels.Count - 1; i >= 0; i--)
            {
                if (deletedIds.Contains(existingLabel.LocalizedLabels[i].MetadataId.Value))
                {
                    existingLabel.LocalizedLabels.RemoveAt(i);
                }
            }

            if (newLabel.UserLocalizedLabel != null)
            {
                connectionDetail.CopyChanges(existingLabel.UserLocalizedLabel, newLabel.UserLocalizedLabel, deletedIds);
            }
        }
コード例 #2
0
 private string GetLabelText(Microsoft.Xrm.Sdk.Label label)
 {
     if (label != null && label.UserLocalizedLabel != null)
     {
         return(label.UserLocalizedLabel.Label);
     }
     return(string.Empty);
 }
コード例 #3
0
        public static string GetLabelString(Microsoft.Xrm.Sdk.Label label)
        {
            string retVal = "";

            if (label != null)
            {
                if (label.UserLocalizedLabel != null)
                {
                    retVal = (string.IsNullOrEmpty(label.UserLocalizedLabel.Label)) ? "" : label.UserLocalizedLabel.Label;
                }
            }

            return(retVal);
        }
コード例 #4
0
        public StatusCodeViewItem(
            int stateCode
            , string stateCodeName
            , int statusCode
            , string statusCodeName
            , Microsoft.Xrm.Sdk.Label stateCodeLabel
            , Microsoft.Xrm.Sdk.Label statusCodeLabel
            , StatusOptionMetadata statusOptionMetadata
            )
        {
            this.StateCode     = stateCode;
            this.StateCodeName = stateCodeName;

            this.StatusCode     = statusCode;
            this.StatusCodeName = statusCodeName;

            this.StateCodeLabel  = stateCodeLabel;
            this.StatusCodeLabel = statusCodeLabel;

            this.StatusOptionMetadata = statusOptionMetadata;
        }
コード例 #5
0
        /// <summary>
        /// Get the right label based on languageCode
        /// </summary>
        /// <param name="th"></param>
        /// <param name="languageCode"></param>
        /// <returns></returns>
        public static string GetLabel(this Microsoft.Xrm.Sdk.Label th, int?languageCode = null)
        {
            string label = string.Empty;

            if (languageCode == null)
            {
                label = th.LocalizedLabels.Select(s => s.Label).FirstOrDefault();
            }
            else
            {
                label = th.LocalizedLabels.Where(w => w.LanguageCode == languageCode).Select(s => s.Label).FirstOrDefault();
                if (string.IsNullOrEmpty(label))
                {
                    label = th.LocalizedLabels.Select(s => s.Label).FirstOrDefault();
                }
            }

            if (string.IsNullOrEmpty(label))
            {
                label = "--";
            }

            return(label);
        }
コード例 #6
0
        /// <summary>
        /// Imports a comma separated file in to the app.
        /// </summary>
        /// <param name="fileName">The file name to import.</param>
        /// <param name="entityItem">The item to import.</param>
        /// <param name="installedLanguages">The installed languages.</param>
        internal void Import(string fileName, EntityItem entityItem, Dictionary <int, string> installedLanguages)
        {
            var file = File.ReadAllLines(fileName);

            file = file.Skip(1).ToArray();
            var fileEntities = file.GroupBy(f => f.Substring(0, f.IndexOf(',')));

            foreach (var fileEntity in fileEntities)
            {
                Dictionary <string, EntityItem> attributes = new Dictionary <string, EntityItem>();
                if (entityItem.LogicalName.ToLower() == fileEntity.Key.ToLower())
                {
                    var fileAttributes = fileEntity.GroupBy(f => f.Substring(f.IndexOf(',') + 1, f.IndexOf(',', f.IndexOf(',') + 1) - f.IndexOf(',') - 1));
                    foreach (var fileAttribute in fileAttributes)
                    {
                        var attributeItem = entityItem.Children.Where(c => c.LogicalName.ToLower() == fileAttribute.Key.ToLower()).FirstOrDefault();
                        if (attributeItem != null)
                        {
                            if (!attributeItem.Loaded)
                            {
                                this.GetOptions(attributeItem);
                            }
                            var children = attributeItem.Children.ToArray();
                            attributeItem.Children.Clear();
                            foreach (var line in fileAttribute)
                            {
                                var columns    = line.Split(',');
                                int maxColumns = (installedLanguages.Count() * 2) + 4;

                                if (columns.Count() > maxColumns)
                                {
                                    List <int> columnsToDelete = new List <int>();
                                    for (int i = 0; i < columns.Length - 1; i++)
                                    {
                                        if (columns[i].StartsWith("\"") && columns[i + 1].EndsWith("\""))
                                        {
                                            columns[i] = columns[i] + "," + columns[i + 1];
                                            columns[i] = columns[i].Trim('"');
                                            columnsToDelete.Add(i + 1);
                                        }
                                    }
                                    if (columnsToDelete.Count > 0)
                                    {
                                        var cols = new List <string>(columns);
                                        for (int i = columnsToDelete.Count(); i > 0; i--)
                                        {
                                            cols.RemoveAt(columnsToDelete[i - 1]);
                                        }
                                        columns = cols.ToArray();
                                    }
                                    if (columns.Length != (installedLanguages.Count() * 2) + 4)
                                    {
                                        MessageBox.Show("Invalid number of columns in the record.");
                                    }
                                }
                                Microsoft.Xrm.Sdk.LocalizedLabel[] labels       = new Microsoft.Xrm.Sdk.LocalizedLabel[installedLanguages.Count()];
                                Microsoft.Xrm.Sdk.LocalizedLabel[] descriptions = new Microsoft.Xrm.Sdk.LocalizedLabel[installedLanguages.Count()];

                                for (int i = 0; i < installedLanguages.Count; i++)
                                {
                                    labels[i]       = new Microsoft.Xrm.Sdk.LocalizedLabel(columns[i + 4], installedLanguages.Keys.OrderBy(l => l).ToArray()[i]);
                                    descriptions[i] = new Microsoft.Xrm.Sdk.LocalizedLabel(columns[i + 4 + installedLanguages.Count], installedLanguages.Keys.OrderBy(l => l).ToArray()[i]);
                                }

                                Microsoft.Xrm.Sdk.Label label = new Microsoft.Xrm.Sdk.Label();
                                label.LocalizedLabels.AddRange(labels);
                                label.UserLocalizedLabel = label.LocalizedLabels.Where(l => l.LanguageCode == installedLanguages.Keys.First()).First();
                                Microsoft.Xrm.Sdk.Label description = new Microsoft.Xrm.Sdk.Label();
                                description.LocalizedLabels.AddRange(descriptions);
                                description.UserLocalizedLabel = description.LocalizedLabels.Where(l => l.LanguageCode == installedLanguages.Keys.First()).First();
                                int value = 0;
                                if (int.TryParse(columns[3], out value) && value != 2147483647)
                                {
                                    EntityItem child = new EntityItem(value, label, description, attributeItem);
                                    var        found = children.Where(c => c.Equals(child)).FirstOrDefault();

                                    child.Changed            = found == null;
                                    attributeItem.GlobalName = columns[2];
                                    attributeItem.Children.Add(child);
                                    attributeItem.Loaded = true;
                                    child.Parent.Changed = true;
                                }
                                else
                                {
                                    MessageBox.Show($"Invalid value - {columns[3]}");
                                }
                            }
                        }
                        else
                        {
                            MessageBox.Show($"Cannot find the attribute - {fileAttribute.Key} on entity {fileEntity.Key}");
                        }
                    }
                }
                else
                {
                    MessageBox.Show($"You can only import to the currently selected entity\r\nImport entity = {fileEntity.Key}");
                }
            }
        }
コード例 #7
0
        private static void RemoveDeletedItems(this ConnectionDetail connectionDetail, Label label, List <Guid> deletedIds)
        {
            if (label == null)
            {
                return;
            }

            for (var i = label.LocalizedLabels.Count - 1; i >= 0; i--)
            {
                if (deletedIds.Contains(label.LocalizedLabels[i].MetadataId.Value))
                {
                    label.LocalizedLabels.RemoveAt(i);
                }
            }

            if (label.UserLocalizedLabel != null)
            {
                connectionDetail.RemoveDeletedItems(label.UserLocalizedLabel, deletedIds);
            }
        }