Пример #1
0
        public static void Start(Session session, DownloadQueueItem r)
        {
            r.Processed = null;
            session.tot = session.DownloadQueue.Count;
            var oS             = session.fSession;
            var requestHeaders = oS.RequestHeaders.Clone() as HTTPRequestHeaders;

            requestHeaders["Range"] = "bytes=" + r.RangeStart + " - " + r.RangeEnd; //+ ranges[r];
            var newflags = new System.Collections.Specialized.StringDictionary {
                { "dax_id", session.dax_id }
            };

            //Interlocked.Increment(ref tot);
            //tot++;
            r.Session = FiddlerApplication.oProxy.SendRequest(requestHeaders,
                                                              oS.RequestBody,
                                                              newflags,
                                                              (sender, evtstatechangeargs) =>
                                                              QueueItemStateChange(session, evtstatechangeargs, r)
                                                              );
        }
Пример #2
0
        private static void QueueItemStateChange(Session session, StateChangeEventArgs evtstatechangeargs, DownloadQueueItem r)
        {
            if (evtstatechangeargs.newState == SessionStates.Done)
            {
                r.Processed = true;
                Interlocked.Increment(ref session.comp);
                Start(session, 1);
                //comp++;

                Application.Current.Dispatcher.Invoke(() =>
                {
                    session.Progress = Convert.ToInt32((session.comp * 100.0) / (session.tot));
                });
                var tempDQ = session.DownloadQueue.ToList();
                //lock (Session.LockObject)
                foreach (var dqitem in tempDQ)
                {
                    lock (dqitem.LockObject)
                    {
                        //Console.WriteLine(session.Session);
                        var a = dqitem;
                        var b = a.Session;
                        var c = b.state;
                        if (c != SessionStates.Done)
                        {
                            return;
                        }
                    }
                }
                if (session.Progress != 100)
                {
                    return;
                }
                lock (session.LockObject)
                {
                    Directory.CreateDirectory(Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "DaXDL"));

                    var idfiles = Directory.GetFiles(Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "DaXCaps"), Path.GetFileName(session.dax_id) + "_DaX_" + "*" + "_XaD_" + "*");
                    if (idfiles.Length > 0)
                    {
                        var destname = idfiles[0];
                        destname = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "DaXDL", destname.Substring(destname.IndexOf("_XaD_") + "_XaD_".Length));

                        using (Stream destStream = File.OpenWrite(destname))
                        {
                            foreach (string srcFileName in idfiles.OrderBy(x => x, new AlphanumComparatorFast()))
                            {
                                try
                                {
                                    using (Stream srcStream = File.OpenRead(srcFileName))
                                    {
                                        srcStream.CopyTo(destStream);
                                    }
                                    File.Delete(srcFileName);
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine(ex);
                                }
                            }
                        }
                    }
                }
                //Application.Current.Dispatcher.Invoke(() =>
                //{
                //    //Session.SubSessions.Clear();// = new ConcurrentBag<Fiddler.Session>();
                //});
                GC.Collect();
            }
        }