Exemplo n.º 1
0
        /// <summary>
        /// add all the item from the project that match one of the file includes
        /// </summary>
        private void AddNuSpecFilesCSharpVisualBasic(ProjectItems items, PackageInformation packageInfo, ProjectInformation projectInformation)
        {
            //-----get all the include able item here
            foreach (ProjectItem item in items)
            {
                //-----check if the item contains an item type property
                string itemType = ExtensionUtil.GetPropertyValue <string>(item.Properties, projectInformation.ItemType, null);
                if (!string.IsNullOrEmpty(itemType))
                {
                    object itemOutput = ExtensionUtil.GetPropertyValue <object>(item.Properties, projectInformation.ItemOutput, -1);
                    if (itemOutput != null && itemOutput.ToString() != "0")
                    {
                        string itemFullPath = ExtensionUtil.GetPropertyValue <string>(item.Properties, "FullPath", null);
                        if (!string.IsNullOrEmpty(itemFullPath))
                        {
                            try
                            {
                                string itemRelativePath = itemFullPath.Remove(0, Path.GetDirectoryName(packageInfo.ProjectFullName).Length + 1).Replace("\\", "/");
                                if (!itemRelativePath.Contains("/"))
                                {
                                    itemRelativePath = string.Format("/{0}", itemRelativePath);
                                }
                                LoggingManager.Instance.Logger.Debug(string.Format("checking item [{0}] for a possible fit", itemRelativePath));
                                FileInclude fileInclude = packageInfo.ProjectOptions.NuGetOptions.NuSpecOptions.Files.FileIncludes.FirstOrDefault(x =>
                                {
                                    string wildcard = string.Format("{0}/{1}", string.IsNullOrEmpty(x.Folder) ? "*" : x.Folder.Replace("\\", "/"), string.IsNullOrEmpty(x.Name) ? "*" : x.Name.Replace("\\", "/"));
                                    LoggingManager.Instance.Logger.Debug(string.Format("checking file include [{0}]", wildcard));
                                    return(StringUtil.MatchesWildcard(itemRelativePath, wildcard));
                                });
                                if (fileInclude != null)
                                {
                                    packageInfo.NuSpecPackage.Files.Add(new Xml.NuGet.NuSpec.File()
                                    {
                                        Source = itemFullPath, Target = fileInclude.Target
                                    });
                                    LoggingManager.Instance.Logger.Debug(string.Format("added file [{0}] under [{1}]", itemFullPath, fileInclude.Target));
                                }
                                else
                                {
                                    LoggingManager.Instance.Logger.Info(string.Format("could not add file [{0}] because no fitting file include was found", itemFullPath));
                                }
                            }
                            catch (Exception ex)
                            {
                                if (ex is ThreadAbortException || ex is ThreadInterruptedException)
                                {
                                    throw;
                                }

                                LoggingManager.Instance.Logger.Error(string.Format("error occured while adding the item [{0}]", itemFullPath), ex);
                            }
                        }
                    }
                }
                //-----check sub items if any
                AddNuSpecFilesCSharpVisualBasic(item.ProjectItems, packageInfo, projectInformation);
            }
        }
Exemplo n.º 2
0
        private void Clone(FileInclude entity)
        {
            var newEntitiy = new FileInclude();

            entity.Copy(newEntitiy);
            newEntitiy.KnowledgeID = _mapKnowledge[newEntitiy.KnowledgeID];
            _destination.ManagerFileInclude.Save(newEntitiy);
            _destination.ManagerFileInclude.SetData(newEntitiy.FileIncludeID, _source.ManagerFileInclude.GetData(entity.FileIncludeID));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Stores the file.
        /// </summary>
        /// <param name="file">The file.</param>
        /// <param name="path">The path.</param>
        /// <param name="name">The name.</param>
        /// <param name="arguments">The arguments.</param>
        /// <returns></returns>
        public override string StoreFile(Telerik.Web.UI.UploadedFile file, string path, string name, params string[] arguments)
        {
            //int fileLength = (int)file.InputStream.Length;
            //byte[] content = new byte[fileLength];
            //file.InputStream.Read(content, 0, fileLength);
            //string fullPath = CombinePath(path, name);
            //if (!Object.Equals(DataServer.GetItemRow(fullPath), null))
            //{
            //    DataServer.ReplaceItemContent(fullPath, content);
            //}
            //else
            //{
            //    DataServer.CreateItem(name, path, file.ContentType, false, fileLength, content);
            //}
            int fileLength = (int)file.InputStream.Length;

            byte[] content = new byte[fileLength];
            file.InputStream.Read(content, 0, fileLength);

            switch (path.TrimEnd(slashArray))
            {
            case "/User":

                UserFile userFile = new UserFile();
                userFile.FileName = name;
                userFile.Size     = fileLength;
                userFile.UserID   = KbContext.CurrentUserId;

                KbContext.CurrentKb.ManagerUserFile.Save(userFile);

                KbContext.CurrentKb.ManagerUserFile.SetData(userFile.UserFileID, content);

                break;

            case "/Knowledge":
                if (!knowledgeID.HasValue)
                {
                    return("Knowlede not saved");
                }

                FileInclude fileInclude = new FileInclude();
                fileInclude.FileName    = name;
                fileInclude.Size        = fileLength;
                fileInclude.KnowledgeID = knowledgeID.Value;

                var manager = KbContext.CurrentKb.ManagerFileInclude;
                manager.Save(fileInclude);
                manager.SetData(fileInclude.FileIncludeID, content);

                break;
            }
            return(string.Empty);
        }
Exemplo n.º 4
0
        /// <summary>
        /// called when a ui element is clicked
        /// </summary>
        /// <param name="sender">sender of the event</param>
        /// <param name="e">event that has been send</param>
        private void OnClick(object sender, EventArgs e)
        {
            if (sender == _uiAdd && _selectedProjectOptions != null)
            {
                FileInclude file = new FileInclude()
                {
                    Type   = _project.ValidItemTypes[0],
                    Folder = string.Format("*{0}", Constants.Random.Next(100)),
                    Name   = string.Format("*{0}", Constants.Random.Next(100)),
                    Target = "lib/content"
                };
                GuiUtil.AddItem(file, _selectedProjectOptions.NuGetOptions.NuSpecOptions.Files.FileIncludes, _uiFiles);
            }
            else if (sender == _uiRemove && _selectedFile != null)
            {
                GuiUtil.RemoveItem(_selectedFile, _selectedProjectOptions.NuGetOptions.NuSpecOptions.Files.FileIncludes, _uiFiles);
            }
            else if (sender == _uiApplyChanges && _selectedFile != null)
            {
                foreach (FileInclude f in _selectedProjectOptions.NuGetOptions.NuSpecOptions.Files.FileIncludes)
                {
                    if (f.Type == (string)_uiCurrentType.SelectedItem && f.Folder == _uiCurrentFolder.Text && f.Name == _uiCurrentName.Text && f != _selectedFile)
                    {
                        MessageBox.Show("A file include with the same type, name and folder exists already, please change the the type, name or folder");
                        return;
                    }
                }

                _selectedFile.Type    = (string)_uiCurrentType.SelectedItem;
                _selectedFile.Folder  = _uiCurrentFolder.Text;
                _selectedFile.Name    = _uiCurrentName.Text;
                _selectedFile.Target  = _uiCurrentTarget.Text;
                _selectedFile.Include = _uiCurrentInclude.Checked;

                _uiApplyChanges.Enabled = false;

                GuiUtil.RefreshItems(_uiFiles);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// calles when one of the ui elements has changed
        /// </summary>
        /// <param name="sender">sender of the event</param>
        /// <param name="e">event that was send</param>
        private void OnChange(object sender, EventArgs e)
        {
            if (!_blockEvents)
            {
                if (sender == _uiProjectIdentifiers)
                {
                    _selectedProjectOptions = (Xml.Settings.Project.Options)_uiProjectIdentifiers.SelectedItem;
                    _uiUseFromExistingNuSpec.Checked = _selectedProjectOptions != null ? _selectedProjectOptions.NuGetOptions.NuSpecOptions.Files.UseFromSettings : false;

                    SetCheckboxImage(_uiUseFromExistingNuSpec);

                    _uiCurrentType.DataSource = null;
                    _uiFiles.DataSource = null;
                    _project = null;

                    if (_selectedProjectOptions != null)
                    {
                        _project = OptionsManager.Instance.SupportedProjectInformation.FirstOrDefault(x => x.Identifier == _selectedProjectOptions.Identifier);
                        _uiCurrentType.DataSource = _project.ValidItemTypes;
                        GuiUtil.SetItem(_selectedProjectOptions.NuGetOptions.NuSpecOptions.Files.FileIncludes, _uiFiles);
                    }
                    else
                    {
                        _uiFiles.DataSource = null;
                        _uiCurrentType.DataSource = null;
                        _project = null;
                    }
                }
                else if (sender == _uiUseFromExistingNuSpec && _selectedProjectOptions != null)
                {
                    _selectedProjectOptions.NuGetOptions.NuSpecOptions.Files.UseFromSettings = _uiUseFromExistingNuSpec.Checked;
                    _uiFilesSettings.Enabled = !_uiUseFromExistingNuSpec.Checked;

                    SetCheckboxImage(_uiUseFromExistingNuSpec);
                }
                else if (sender == _uiFiles)
                {
                    _selectedFile = (FileInclude)_uiFiles.SelectedItem;

                    _blockEvents = true;

                    if (_selectedFile != null)
                    {
                        _uiCurrentType.SelectedItem = _selectedFile.Type;
                        _uiCurrentType.Enabled = true;

                        _uiCurrentFolder.Text = _selectedFile.Folder;
                        _uiCurrentFolder.Enabled = true;

                        _uiCurrentName.Text = _selectedFile.Name;
                        _uiCurrentName.Enabled = true;

                        _uiCurrentTarget.Text = _selectedFile.Target;
                        _uiCurrentTarget.Enabled = true;

                        _uiCurrentInclude.Checked = _selectedFile.Include;
                        _uiCurrentInclude.Enabled = true;

                        _uiRemove.Enabled = true;
                    }
                    else
                    {
                        _uiCurrentType.SelectedItem = null;
                        _uiCurrentType.Enabled = false;

                        _uiCurrentFolder.Text = null;
                        _uiCurrentFolder.Enabled = false;

                        _uiCurrentName.Text = null;
                        _uiCurrentName.Enabled = false;

                        _uiCurrentTarget.Text = null;
                        _uiCurrentTarget.Enabled = false;

                        _uiCurrentInclude.Checked = false;
                        _uiCurrentInclude.Enabled = false;

                        _uiRemove.Enabled = false;
                    }

                    _blockEvents = false;

                    _uiApplyChanges.Enabled = false;
                }
                else if ((sender == _uiCurrentType || sender == _uiCurrentFolder || sender == _uiCurrentName || sender == _uiCurrentTarget || sender == _uiCurrentInclude) && _selectedFile != null)
                {
                    _uiApplyChanges.Enabled = _selectedFile.Type != (string)_uiCurrentType.SelectedItem
                                        || _selectedFile.Folder != _uiCurrentFolder.Text
                                        || _selectedFile.Name != _uiCurrentName.Text
                                        || _selectedFile.Target != _uiCurrentTarget.Text
                                        || _selectedFile.Include != _uiCurrentInclude.Checked;
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// called when a ui element is clicked
        /// </summary>
        /// <param name="sender">sender of the event</param>
        /// <param name="e">event that has been send</param>
        private void OnClick(object sender, EventArgs e)
        {
            if (sender == _uiAdd && _selectedProjectOptions != null)
            {
                FileInclude file = new FileInclude()
                {
                    Type = _project.ValidItemTypes[0],
                    Folder = string.Format("*{0}", Constants.Random.Next(100)),
                    Name = string.Format("*{0}", Constants.Random.Next(100)),
                    Target = "lib/content"
                };
                GuiUtil.AddItem(file, _selectedProjectOptions.NuGetOptions.NuSpecOptions.Files.FileIncludes, _uiFiles);
            }
            else if (sender == _uiRemove && _selectedFile != null)
            {
                GuiUtil.RemoveItem(_selectedFile, _selectedProjectOptions.NuGetOptions.NuSpecOptions.Files.FileIncludes, _uiFiles);
            }
            else if (sender == _uiApplyChanges && _selectedFile != null)
            {
                foreach (FileInclude f in _selectedProjectOptions.NuGetOptions.NuSpecOptions.Files.FileIncludes)
                    if (f.Type == (string)_uiCurrentType.SelectedItem && f.Folder == _uiCurrentFolder.Text && f.Name == _uiCurrentName.Text && f != _selectedFile)
                    {
                        MessageBox.Show("A file include with the same type, name and folder exists already, please change the the type, name or folder");
                        return;
                    }

                _selectedFile.Type = (string)_uiCurrentType.SelectedItem;
                _selectedFile.Folder = _uiCurrentFolder.Text;
                _selectedFile.Name = _uiCurrentName.Text;
                _selectedFile.Target = _uiCurrentTarget.Text;
                _selectedFile.Include = _uiCurrentInclude.Checked;

                _uiApplyChanges.Enabled = false;

                GuiUtil.RefreshItems(_uiFiles);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// calles when one of the ui elements has changed
        /// </summary>
        /// <param name="sender">sender of the event</param>
        /// <param name="e">event that was send</param>
        private void OnChange(object sender, EventArgs e)
        {
            if (!_blockEvents)
            {
                if (sender == _uiProjectIdentifiers)
                {
                    _selectedProjectOptions          = (Xml.Settings.Project.Options)_uiProjectIdentifiers.SelectedItem;
                    _uiUseFromExistingNuSpec.Checked = _selectedProjectOptions != null ? _selectedProjectOptions.NuGetOptions.NuSpecOptions.Files.UseFromSettings : false;

                    SetCheckboxImage(_uiUseFromExistingNuSpec);

                    _uiCurrentType.DataSource = null;
                    _uiFiles.DataSource       = null;
                    _project = null;

                    if (_selectedProjectOptions != null)
                    {
                        _project = OptionsManager.Instance.SupportedProjectInformation.FirstOrDefault(x => x.Identifier == _selectedProjectOptions.Identifier);
                        _uiCurrentType.DataSource = _project.ValidItemTypes;
                        GuiUtil.SetItem(_selectedProjectOptions.NuGetOptions.NuSpecOptions.Files.FileIncludes, _uiFiles);
                    }
                    else
                    {
                        _uiFiles.DataSource       = null;
                        _uiCurrentType.DataSource = null;
                        _project = null;
                    }
                }
                else if (sender == _uiUseFromExistingNuSpec && _selectedProjectOptions != null)
                {
                    _selectedProjectOptions.NuGetOptions.NuSpecOptions.Files.UseFromSettings = _uiUseFromExistingNuSpec.Checked;
                    _uiFilesSettings.Enabled = !_uiUseFromExistingNuSpec.Checked;

                    SetCheckboxImage(_uiUseFromExistingNuSpec);
                }
                else if (sender == _uiFiles)
                {
                    _selectedFile = (FileInclude)_uiFiles.SelectedItem;

                    _blockEvents = true;

                    if (_selectedFile != null)
                    {
                        _uiCurrentType.SelectedItem = _selectedFile.Type;
                        _uiCurrentType.Enabled      = true;

                        _uiCurrentFolder.Text    = _selectedFile.Folder;
                        _uiCurrentFolder.Enabled = true;

                        _uiCurrentName.Text    = _selectedFile.Name;
                        _uiCurrentName.Enabled = true;

                        _uiCurrentTarget.Text    = _selectedFile.Target;
                        _uiCurrentTarget.Enabled = true;

                        _uiCurrentInclude.Checked = _selectedFile.Include;
                        _uiCurrentInclude.Enabled = true;

                        _uiRemove.Enabled = true;
                    }
                    else
                    {
                        _uiCurrentType.SelectedItem = null;
                        _uiCurrentType.Enabled      = false;

                        _uiCurrentFolder.Text    = null;
                        _uiCurrentFolder.Enabled = false;

                        _uiCurrentName.Text    = null;
                        _uiCurrentName.Enabled = false;

                        _uiCurrentTarget.Text    = null;
                        _uiCurrentTarget.Enabled = false;

                        _uiCurrentInclude.Checked = false;
                        _uiCurrentInclude.Enabled = false;

                        _uiRemove.Enabled = false;
                    }

                    _blockEvents = false;

                    _uiApplyChanges.Enabled = false;
                }
                else if ((sender == _uiCurrentType || sender == _uiCurrentFolder || sender == _uiCurrentName || sender == _uiCurrentTarget || sender == _uiCurrentInclude) && _selectedFile != null)
                {
                    _uiApplyChanges.Enabled = _selectedFile.Type != (string)_uiCurrentType.SelectedItem ||
                                              _selectedFile.Folder != _uiCurrentFolder.Text ||
                                              _selectedFile.Name != _uiCurrentName.Text ||
                                              _selectedFile.Target != _uiCurrentTarget.Text ||
                                              _selectedFile.Include != _uiCurrentInclude.Checked;
                }
            }
        }