Beispiel #1
0
        private static void AddAttributeButCheckForDiffernce(Item sourceItem, Attribute sourceAttrib, Item destItem, Attribute destAttrib)
        {
            var test = sourceItem.GetAttributeValueAsText(sourceAttrib);
            if (destItem.GetAttributeIsAssigned(destAttrib))
            {
                // check values are same
                var testDest = destItem.GetAttributeValueAsText(destAttrib);
                if (test != testDest)
                {
                    destItem.SetAttributeValue(destAttrib, _multipleValues);
                    return;
                }

            }
            // else can set
            destItem.SetAttributeValue(destAttrib, test);
        }
Beispiel #2
0
        private static void CopyAllAttributeValues(Item itemSource, Item itemDestination)
        {
            foreach (var attrib in itemSource.Story.Attributes)
            {
                if (itemSource.GetAttributeIsAssigned(attrib)) // only copy the value if its assigned
                {
                    var attD = EnsureAttributeExists(attrib, itemDestination.Story);

                    itemDestination.SetAttributeValue(attD, itemSource.GetAttributeValueAsText(attrib));
                }
            }
        }
Beispiel #3
0
        private bool ItemHasChanged(Item source, Item copy, Dictionary<string, List<string>> differences )
        {
            if (source.Id == copy.ExternalId)
            {
                var list = new List<string>();
                differences.Add(source.Id, list);

                if (source.Name != copy.Name)
                    list.Add("FileName has changed.");
                if (source.Description != copy.Description)
                    list.Add("Description has changed.");
                if (source.IsTransparent != copy.IsTransparent)
                    list.Add("Transparency has changed.");
                if (source.ImageId != copy.ImageId || source.ImageMode != copy.ImageMode)
                    list.Add("Image has changed.");
                if (source.StartDate != copy.StartDate)
                    list.Add("Start Date has changed.");
                if (source.DurationInDays != copy.DurationInDays)
                    list.Add("Duration has changed.");

                // tags
                foreach (var tag in source.Tags)
                {
                    if (copy.Tag_FindByName(tag.Text) == null)
                        list.Add(string.Format("Tag {0} has been added.", tag.Text));
                }

                // panels
                foreach (var panel in source.Panels)
                {
                    if (panel.IsVisible && (panel.Type == Panel.PanelType.Image || panel.Type == Panel.PanelType.RichText || panel.Type == Panel.PanelType.Video) )
                    {
                        // find matching panel
                        var pD = copy.Panel_FindByTitle(panel.Title);
                        if (pD == null)
                            list.Add(string.Format("Panel {0} has been added.",panel.Title));
                        else
                        {
                            if (pD.Data != panel.Data)
                                list.Add(string.Format("Panel {0} has been modified.", panel.Title));
                        }
                    }
                }

                // attributes
                foreach (var att in source.Story.Attributes)
                {
                    var val = source.GetAttributeValueAsText(att);
                    if (att.InUse && att.IsUserDefined && !string.IsNullOrEmpty(val) && source.GetAttributeIsAssigned(att))
                    {
                        // add a simailar attribute to the target if it is not already added
                        var newAtt = copy.Story.Attribute_FindByName(att.Name);
                        if (newAtt == null)
                        {
                            list.Add(string.Format("Attribute '{0}' does not exist in story.", att.Name));
                        }
                        else 
                        {
                            var val2 = copy.GetAttributeValueAsText(newAtt);
                            if (!copy.GetAttributeIsAssigned(newAtt))
                            {
                                list.Add(string.Format("Attribute '{0}' does not exist on the item.", att.Name));
                            }
                            else  if (val != val2)
                            {
                                if (att.Type == Attribute.AttributeType.Numeric)
                                {
                                    var vald = source.GetAttributeValueAsDouble(att);
                                    var val2d = copy.GetAttributeValueAsDouble(newAtt);

                                    if (vald != val2d)
                                        list.Add(string.Format("Attribute '{0}' has changed. {1} will replace {2}", att.Name, val, val2));

                                }
                                else
                                    list.Add(string.Format("Attribute '{0}' has changed. '{1}' will replace '{2}'", att.Name, val, val2));
                            }
                        }
                    }
                }
                // relationships
                foreach (var relationship in source.Relationships)
                {
                    var item1 = copy.Story.Item_FindByExternalId(relationship.Item1.Id);
                    var item2 = copy.Story.Item_FindByExternalId(relationship.Item2.Id);

                    if (item1 != null && item2 != null)
                    {
                        // there is a relationship in the source and both items exist in the copy

                        // does the relationship exist in the copy
                        Relationship rel;
                        if (item1.Id == copy.Id)
                        {
                            rel = copy.Relationship_FindByItem(item2);
                            if (rel == null)
                                list.Add(string.Format("Relationship missing to {0}", item2.Name));
                            else
                                CheckIfRelationshipsAreDifferent(relationship, rel, list);
                        }
                        else if (item1.Id == copy.Id)
                        {
                            rel = copy.Relationship_FindByItem(item1);
                            if (rel == null)
                                list.Add(string.Format("Relationship missing to {0}", item1.Name));
                            CheckIfRelationshipsAreDifferent(relationship, rel, list);
                        }
                    }
                }

                // resources
                foreach (var res in source.Resources)
                {
                    var resNew = copy.Resource_FindByName(res.Name);
                    if (resNew != null)
                    {
                        foreach (var tag in res.Tags)
                        {
                            if (resNew.Tag_FindByName(tag.Text) == null)
                                list.Add($"Tag '{tag.Text}' is missing on Resource '{res.Name}' on item {copy.Name}");
                        }
                    }
                    else
                    {
                        list.Add($"Resource '{res.Name}' is missing on item {copy.Name}");
                    }
                }


                for (int w = 0; w < 24; w++)
                {
                    if (source.AsElement.CanvasPoints[w].X != copy.AsElement.CanvasPoints[w].X || source.AsElement.CanvasPoints[w].Y != copy.AsElement.CanvasPoints[w].Y)
                        list.Add(string.Format("Wall position '{0}' has changed.", w+1));

                }


                return list.Any();
            }
                
            return false;
        }