Example #1
0
        private void bgw_DoWork(object sender, DoWorkEventArgs e)
        {
            e.Result = string.Empty;

            int?userId = e.Argument as int?;

            if (userId != null)
            {
                // read channels
                UserWS       userRepo = new UserWS();
                List <Group> chList   = userRepo.GetChannelsOfUser((int)userId) as List <Group>;
                if (chList != null)
                {
                    chList.Sort(channelSorter);
                }

                SnippetsWS snipRepo = new SnippetsWS();
                lock (selectedChList)   // we don't want that someone is updating this while we read it and vice-versa
                {
                    selectedChList = snipRepo.GetChannels(this.SnippetId);

                    if (chList != null)
                    {
                        // populate the control
                        foreach (Group c in chList)
                        {
                            // if the snippet is already published on the channel, mark it as selected
                            bool sel = false;
                            if (selectedChList != null)
                            {
                                foreach (int cs in selectedChList)
                                {
                                    if (c.ID == cs)
                                    {
                                        sel = true;
                                        break;
                                    }
                                }
                            }

                            // populate the control
                            listChannelWiew.Invoke(new Action(() => addItemToList(c.Name, c.ID, sel)));
                        }
                    }
                }
                if ((chList == null) || (chList.Count == 0))
                {
                    e.Result = Properties.Resources.PublishNoChannelFollowed;
                }
            }
            else
            {
                e.Result = Properties.Resources.ErrorCodes_UNKNOWN;
            }
        }
Example #2
0
        /// <summary>
        /// Creates a new ViewSnippet Form and precompiles this form with the content of the given snippet
        /// </summary>
        /// <param name="pluginManager"></param>
        /// <param name="snippetId">ID of the snppet to display</param>
        public static IManageSnippetForm PrepareViewSnippetForm(IPluginManager pluginManager, long snippetId)
        {
            if (pluginManager == null)
            {
                return(null);
            }

            if (snippetId <= 0)
            {
                return(null);
            }

            // read snippets and populate the List
            SnippetsWS snippetRepo = new SnippetsWS();

            log.DebugFormat("Reading snippet {0}", snippetId);
            Snippet snip = snippetRepo.GetSnippetByID(snippetId);

            if (snip == null)
            {
                log.WarnFormat("Snippet {0} is null", snippetId);
                return(null);
            }

            //CG: Add +1 to the view stats
            System.Threading.Tasks.Task.Factory.StartNew(() => snippetRepo.StoreHit(snip));

            // Open "Add Snippet" Window
            log.DebugFormat("Loading snippet {0}", snippetId);
            pluginManager.ClosePublishSnippetWindow();

            IManageSnippetForm viewSnipForm = pluginManager.CreateViewSnippetForm();

            viewSnipForm.PrepareViewSnippet(snip);

            return(viewSnipForm);
        }
Example #3
0
        private void publishw_DoWork(object sender, DoWorkEventArgs e)
        {
            e.Result = string.Empty;

            List <int> pubChList = e.Argument as List <int>;

            // build the list of items to handle
            List <int> unpubList  = new List <int>();
            List <int> newPubList = new List <int>();

            lock (selectedChList)
            {
                if ((selectedChList != null) && (pubChList != null))
                {
                    foreach (int p in pubChList)
                    {
                        if (!selectedChList.Contains(p))
                        {
                            newPubList.Add(p);
                        }
                    }

                    foreach (int p in selectedChList)
                    {
                        if (!pubChList.Contains(p))
                        {
                            unpubList.Add(p);
                        }
                    }
                }
            }

            bool res = true;

            // UI error handling
            if ((unpubList.Count == 0) && ((pubChList == null) || (pubChList.Count == 0)))
            {
                if (pubChList == null)
                {
                    e.Result = Properties.Resources.ErrorCodes_UNKNOWN;
                }
                else
                {
                    e.Result = Properties.Resources.NoItemsSelected;
                }
            }

            // remove from publishing the unnecessary items
            if (unpubList.Count > 0)
            {
                SnippetsWS snipPrepo = new SnippetsWS();
                res &= snipPrepo.UnPublishSnippet(SnippetId, unpubList);
            }

            // publish the new items
            if (newPubList.Count > 0)
            {
                SnippetsWS snipPrepo = new SnippetsWS();
                res &= snipPrepo.PublishSnippet(SnippetId, newPubList);
            }

            if (!res)
            {
                e.Result = Properties.Resources.PublishErrorUnpublishing;
            }
        }