Exemplo n.º 1
0
        /// <summary>
        /// Interaction about Item/Category mapping
        /// </summary>
        /// <param name="state"></param>
        private void StartWork_MappingRelated(object state)
        {
            List <long> idList = state as List <long>;

            if (idList != null)
            {
                // Start get current mapping status
                AutoResetEvent     nextOneAutoResetEvent = new AutoResetEvent(false);
                List <MappingView> l = new List <MappingView>();
                EventHandler <getMappingStatus_CategoryCompletedEventArgs> h1 = (s, e) =>
                {
                    foreach (mappingStatus m in e.Result)
                    {
                        l.Add(new MappingView(ShopproHelper.ConvertToCheckedValue(m.mappingStatus1.ToString()), m.name, m.id));
                    }
                    nextOneAutoResetEvent.Set();
                };
                Globals.WSClient.getMappingStatus_CategoryCompleted += h1;
                Globals.WSClient.getMappingStatus_CategoryAsync(idList.ToArray());
                nextOneAutoResetEvent.WaitOne();
                Globals.WSClient.getMappingStatus_CategoryCompleted -= h1;

                // Hide busy indicator
                ShopproHelper.HideBusyIndicator(this);

                // Show picker
                this.Dispatcher.BeginInvoke(delegate()
                {
                    MappingPicker cp = new MappingPicker(l);
                    cp.Title         = "Tab mapping";
                    cp.Instruction   = "Add selected categories to tab or remove them from tabs:";
                    cp.Closed       += new EventHandler(cp_Closed);
                    cp.Show();
                });
            }
            else
            {
                Dictionary <long, bool> changedMapping = state as Dictionary <long, bool>;
                if (null != changedMapping)
                {
                    // Start get current mapping status
                    AutoResetEvent nextOneAutoResetEvent = new AutoResetEvent(false);

                    // TODO: optimize this?
                    foreach (long cid in changedMapping.Keys)
                    {
                        EventHandler <setMappingStatus_CategoryCompletedEventArgs> h2 = (s, e) =>
                        {
                            // TODO: error handling
                            nextOneAutoResetEvent.Set();
                        };
                        Globals.WSClient.setMappingStatus_CategoryCompleted += h2;
                        Globals.WSClient.setMappingStatus_CategoryAsync(this.selectedItemId.ToArray(), cid, (changedMapping[cid] == true) ? mappingStatusEnum.ALL : mappingStatusEnum.NONE);
                        nextOneAutoResetEvent.WaitOne();
                        Globals.WSClient.setMappingStatus_CategoryCompleted -= h2;
                    }
                }

                // Hide busy indicator
                ShopproHelper.HideBusyIndicator(this);
            }
        }