Example #1
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 #2
0
        private void bgw_DoWork(object sender, DoWorkEventArgs e)
        {
            SnippetSearchResult result = new SnippetSearchResult();
            e.Result = result;

            KeyValuePair<string, int> search_count = (KeyValuePair<string, int>)e.Argument;

            // read snippets and populate the List
            SnippetsWS snippetRepo = new SnippetsWS();
            int searchBlock = 20;   // length of each block of snippets read via web call
            int startIndex = search_count.Value;      // current block of snippets
            int numReturnedSnippets = 0;
            int numReturnedSnippetsWithNonDefOperator = 0;

            Dictionary<string, string[]> mispelling = null;
            SortedDictionary<string, int> tags = null;
            IList<Snippet> snipList = snippetRepo.GetSnippetsForSearch(search_count.Key, out mispelling, out numReturnedSnippets,
                out numReturnedSnippetsWithNonDefOperator, out tags, searchBlock, startIndex);

            //TODO: display results with non default operator

            result.snippetNum = numReturnedSnippets;
            if (result.snippetNum <= 0)
            {
                try
                {
                    result.errorMsg = Utilities.GetResourceLocalizedMsg<ErrorCodes>(snippetRepo.LastErrorCode);
                }
                catch (Exception)
                {
                    result.errorMsg = null;
                }
                if (string.IsNullOrEmpty(result.errorMsg))
                    result.errorMsg = Properties.Resources.ErrorCodes_UNKNOWN;
            }
            int p = 1;

            foreach (Snippet s in snipList)
            {
                SnipInfo sinfo = new SnipInfo();
                if (s != null)
                {
                    sinfo.snip_image = PictureManager.GetImageOfUser(s.CreatorID, new System.Drawing.Size(50, 50), s.CreatorImageNum);
                    sinfo.snip_name = s.Name;
                    sinfo.snip_description = s.Description;
                    sinfo.snip_creator = s.CreatorName;
                    sinfo.snip_ID = s.ID;

                    bgw.ReportProgress(p++, sinfo);
                }
            }

            e.Result = new KeyValuePair<SnippetSearchResult, Dictionary<string, string[]>>(result, mispelling);
        }
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;

        }
        private void bgw_DoWork(object sender, DoWorkEventArgs e)
        {
            SnippetSaveResult sresult = new SnippetSaveResult();
            sresult.id = -1;
            sresult.validity = SnippetWrongField.OK;
            sresult.targetGroupId = -1;

            SnippetClient mysnippet = e.Argument as SnippetClient;

            if (mysnippet != null)
            {
                // check if snippet is valid
                sresult.validity = mysnippet.AreFieldsValid();
                if (sresult.validity == SnippetWrongField.OK)
                {
                    SnippetsWS s_snippetRepo = new SnippetsWS();

                    // save it
                    sresult.id = s_snippetRepo.SaveSnippet(mysnippet);
                    if (sresult.id <= 0)
                    {
                        try
                        {
                            sresult.errorMsg = Utilities.GetResourceLocalizedMsg<ErrorCodes>(s_snippetRepo.LastErrorCode);
                        }
                        catch (Exception)
                        {
                            sresult.errorMsg = null;
                        }
                        if (string.IsNullOrEmpty(sresult.errorMsg))
                            sresult.errorMsg = Properties.Resources.ErrorCodes_UNKNOWN;
                    }
                    else
                    {
                        sresult.targetGroupId = mysnippet.TargetGroupID;
                    }
                }
            }

            e.Result = sresult;
        }
Example #5
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;
            }
        }