public DroppableItem(DroppableItem item, int count, IItemContainer startingLocation)
 {
     ItemId   = item.ItemId;
     Name     = item.Name;
     Count    = count;
     Location = startingLocation;
     startingLocation.Add(this);
 }
        public DroppableItem(Descriptor itemDescriptor, IItemContainer startingLocation)
        {
            ItemId   = itemDescriptor.ItemId;
            Name     = itemDescriptor.Name;
            Count    = itemDescriptor.Count;
            Location = startingLocation;
            startingLocation.Add(this);

            if (itemDescriptor is EquipmentDescriptor eq)
            {
                SlotType = eq.Slot;
            }
        }
Example #3
0
        /// <summary>
        /// When overriden by a derived class, changes the default behavior for adding the state file
        /// to the given parent folder.
        /// </summary>
        /// <returns>The added item.</returns>
        protected virtual IItemContainer AddStateToSolution(IItemContainer targetParent, string targetName, string sourceFile)
        {
            Guard.NotNull(() => targetParent, targetParent);
            Guard.NotNullOrEmpty(() => targetName, targetName);
            Guard.NotNullOrEmpty(() => sourceFile, sourceFile);

            tracer.Verbose(Resources.PatternManager_TraceAddingFileToSolution, targetParent.PhysicalPath, targetName);

            // BUGFIX: FBRT does not checkout the file if it exists in the 'Solution Items' directory,
            //	as the path of the 'Solution Items' folder is the path of the solution.
            var targetItem = targetParent.Find <IItem>(targetName).FirstOrDefault();

            if (targetItem != null)
            {
                targetItem.Checkout();
            }

            // This should be doing the right thing, checking out the file, replacing content, etc.
            return(targetParent.Add(sourceFile, targetName, true, false));
        }
        public void MoveTo(IItemContainer newLocation)
        {
            if (Location == newLocation || !newLocation.FitsInSlot(this))
            {
                return;
            }

            OnItemMoved?.Invoke(this, new ItemMovedEventArgs
            {
                From = Location,
                To   = newLocation,
                Item = this
            });

            int maxAdded = newLocation.Add(this);

            Location?.Remove(this);
            if (maxAdded < Count)
            {
                new DroppableItem(this, Count - maxAdded, Location);
                Count = maxAdded;
            }
            Location = newLocation;
        }
 public bool Add(IItemStack itemStackToAdd)
 {
     return(_primaryInventory.Add(itemStackToAdd));
 }
Example #6
0
        private void SyncGeneratedProjectFiles(IDictionary <string, string> generatedFiles, string sourceFolderPath, IItemContainer targetContainer)
        {
            var targetContainerPath = targetContainer.GetLogicalPath();

            tracer.Info(
                Resources.CreateGuidanceDocumentsCommand_TraceAddingExcludedFiles, targetContainer.GetLogicalPath());

            // Ensure that all (*.MHT) files on the disk are included the targetContainer
            var targetContainerFiles = Directory.GetFiles(targetContainer.PhysicalPath, GeneratedFileExtensionFilter);

            foreach (var targetContainerFile in targetContainerFiles)
            {
                var projectItem = targetContainer.Find <IItem>(targetContainerFile).FirstOrDefault();
                if (projectItem == null)
                {
                    // Add existing file to project (SCC handles the 'Add' automatically)
                    tracer.Info(
                        Resources.CreateGuidanceDocumentsCommand_TraceAddingExcludedFile, targetContainerFile, targetContainerPath);

                    targetContainer.Add(targetContainerFile);
                }
            }

            tracer.Info(
                Resources.CreateGuidanceDocumentsCommand_TraceAddingNewFiles, targetContainer.GetLogicalPath());

            // Copy all generated files to project (overwrite existing)
            foreach (var generatedFile in generatedFiles)
            {
                var generatedFileName   = generatedFile.Key;
                var targetContainerItem = targetContainer.Find <IItem>(generatedFileName).FirstOrDefault();
                if (targetContainerItem == null)
                {
                    // Add new file to project (SCC Handles the 'Add' automatically)
                    tracer.Info(
                        Resources.CreateGuidanceDocumentsCommand_TraceAddingNewFile, generatedFileName, targetContainerPath);

                    targetContainer.Add(Path.Combine(sourceFolderPath, generatedFileName));
                }
                else
                {
                    // SCC 'Checkout' existing file (or make writable), and copy file to disk location
                    tracer.Info(
                        Resources.CreateGuidanceDocumentsCommand_TraceOverwriteExistingFile, generatedFileName, targetContainerPath);

                    targetContainerItem.Checkout();
                    File.Copy(Path.Combine(sourceFolderPath, generatedFileName),
                              Path.Combine(targetContainer.PhysicalPath, generatedFileName), true);
                }
            }

            // Remove any non-current items
            var itemsToDelete        = new List <string>();
            var targetContainerItems = targetContainer.Items.OfType <IItem>();

            foreach (var targetContainerItem in targetContainerItems)
            {
                if (!generatedFiles.ContainsKey(targetContainerItem.Name))
                {
                    itemsToDelete.Add(targetContainerItem.Name);
                }
                else
                {
                    // Ensure build properties
                    tracer.Info(
                        Resources.CreateGuidanceDocumentsCommand_TraceSettingBuildAction, targetContainerItem.Name, targetContainerPath);

                    targetContainerItem.Data.ItemType      = BuildAction.Content.ToString();
                    targetContainerItem.Data.IncludeInVSIX = Boolean.TrueString.ToLowerInvariant();
                }
            }

            tracer.Info(
                Resources.CreateGuidanceDocumentsCommand_TraceDeleteSuperfluousFiles, targetContainer.GetLogicalPath());

            if (itemsToDelete.Any())
            {
                foreach (var item in itemsToDelete)
                {
                    tracer.Info(
                        Resources.CreateGuidanceDocumentsCommand_TraceDeleteSuperfluousFile, item, targetContainerPath);

                    var itemToDelete = targetContainer.Find <IItem>(item).FirstOrDefault();
                    if (itemToDelete != null)
                    {
                        itemToDelete.Delete();
                    }
                }
            }
        }
        private void SyncGeneratedProjectFiles(IDictionary<string, string> generatedFiles, string sourceFolderPath, IItemContainer targetContainer)
        {
            var targetContainerPath = targetContainer.GetLogicalPath();

            tracer.Info(
                Resources.CreateGuidanceDocumentsCommand_TraceAddingExcludedFiles, targetContainer.GetLogicalPath());

            // Ensure that all (*.MHT) files on the disk are included the targetContainer
            var targetContainerFiles = Directory.GetFiles(targetContainer.PhysicalPath, GeneratedFileExtensionFilter);
            foreach (var targetContainerFile in targetContainerFiles)
            {
                var projectItem = targetContainer.Find<IItem>(targetContainerFile).FirstOrDefault();
                if (projectItem == null)
                {
                    // Add existing file to project (SCC handles the 'Add' automatically)
                    tracer.Info(
                        Resources.CreateGuidanceDocumentsCommand_TraceAddingExcludedFile, targetContainerFile, targetContainerPath);

                    targetContainer.Add(targetContainerFile);
                }
            }

            tracer.Info(
                Resources.CreateGuidanceDocumentsCommand_TraceAddingNewFiles, targetContainer.GetLogicalPath());

            // Copy all generated files to project (overwrite existing)
            foreach (var generatedFile in generatedFiles)
            {
                var generatedFileName = generatedFile.Key;
                var targetContainerItem = targetContainer.Find<IItem>(generatedFileName).FirstOrDefault();
                if (targetContainerItem == null)
                {
                    // Add new file to project (SCC Handles the 'Add' automatically)
                    tracer.Info(
                        Resources.CreateGuidanceDocumentsCommand_TraceAddingNewFile, generatedFileName, targetContainerPath);

                    targetContainer.Add(Path.Combine(sourceFolderPath, generatedFileName));
                }
                else
                {
                    // SCC 'Checkout' existing file (or make writable), and copy file to disk location
                    tracer.Info(
                        Resources.CreateGuidanceDocumentsCommand_TraceOverwriteExistingFile, generatedFileName, targetContainerPath);

                    targetContainerItem.Checkout();
                    File.Copy(Path.Combine(sourceFolderPath, generatedFileName),
                        Path.Combine(targetContainer.PhysicalPath, generatedFileName), true);
                }
            }

            // Remove any non-current items
            var itemsToDelete = new List<string>();
            var targetContainerItems = targetContainer.Items.OfType<IItem>();
            foreach (var targetContainerItem in targetContainerItems)
            {
                if (!generatedFiles.ContainsKey(targetContainerItem.Name))
                {
                    itemsToDelete.Add(targetContainerItem.Name);
                }
                else
                {
                    // Ensure build properties
                    tracer.Info(
                        Resources.CreateGuidanceDocumentsCommand_TraceSettingBuildAction, targetContainerItem.Name, targetContainerPath);

                    targetContainerItem.Data.ItemType = BuildAction.Content.ToString();
                    targetContainerItem.Data.IncludeInVSIX = Boolean.TrueString.ToLowerInvariant();
                }
            }

            tracer.Info(
            Resources.CreateGuidanceDocumentsCommand_TraceDeleteSuperfluousFiles, targetContainer.GetLogicalPath());

            if (itemsToDelete.Any())
            {
                foreach (var item in itemsToDelete)
                {
                    tracer.Info(
                        Resources.CreateGuidanceDocumentsCommand_TraceDeleteSuperfluousFile, item, targetContainerPath);

                    var itemToDelete = targetContainer.Find<IItem>(item).FirstOrDefault();
                    if (itemToDelete != null)
                    {
                        itemToDelete.Delete();
                    }
                }
            }
        }