Exemple #1
0
        //constructor
        public Client(string username, string client_url, string server_url, string script_file)
        {
            this.username    = username;
            this.client_url  = client_url;
            this.server_url  = server_url;
            this.script_file = script_file;
            meetingList      = new Dictionary <string, MeetingProposal>();

            IServer server = (IServer)Activator.GetObject(
                typeof(IServer),
                server_url);

            backupServers = server.addClient(this.GetInfo());
            //get meetings
            ListDelegate del = new ListDelegate(server.getMeetings);

            del.BeginInvoke(updateCallback, null);

            //execute script in new thread
            if (script_file != "")
            {
                Thread thread = new Thread(new ThreadStart(() => this.executeScript(script_file)));
                thread.Start();
            }
        }
Exemple #2
0
        public delegate void ListDelegate <T>(T t);        //this one is kinda experimental and doesn't save tooo much typing, but it's here anyway

        public static void Each <T>(this List <T> l, ListDelegate <T> del)
        {
            foreach (T t in l)
            {
                del(t);
            }
        }
Exemple #3
0
 public static void Each <T> (List <T> list, ListDelegate <T> callback)
 {
     for (int i = 0, size = list.Count; i < size; ++i)
     {
         callback(list[i], i, list);
     }
 }
Exemple #4
0
        //callback
        void updateCallback(IAsyncResult ar)
        {
            //will be called when delegate is over
            ListDelegate del = (ListDelegate)((AsyncResult)ar).AsyncDelegate;

            lock (meetingList){
                meetingList.Clear();
                meetingList = del.EndInvoke(ar);
            }
        }
 static CallbackHandler()
 {
     loadCallback = new LoadDelegate(load);
     unloadCallback = new UnloadDelegate(unload);
     openCallback = new OpenDelegate(open);
     listCallback = new ListDelegate(list);
     listFileInfoCallback = new ListFileInfoDelegate(listFileInfo);
     findCallback = new FindDelegate(find);
     findFileInfoCallback = new FindFileInfoDelegate(findFileInfo);
     existsCallback = new ExistsDelegate(exists);
 }
Exemple #6
0
        void DownloadAudioFrom(Downloadable InVideo, int count)
        {
            InVideo.Preparing = true;
            ListDelegate ld = new ListDelegate(Program.frm.UpdateList);

            Program.frm.Invoke(ld);

            string link        = InVideo.Url;
            string countPrefix = count.ToString();

            countPrefix = countPrefix.PadLeft(padLeft, '0');

            VideoInfo video = DownloadUrlResolver.GetDownloadUrls(link);

            if (video.RequiresDecryption)
            {
                DownloadUrlResolver.DecryptDownloadUrl(video);
            }

            char[] legalTitleArray = video.Title.ToCharArray();
            string legalTitle      = "";

            foreach (char c in legalTitleArray)
            {
                if (!(c == '/' || c == '\\' || c == ':' || c == '*' || c == '?' || c == '"' || c == '<' || c == '>' || c == '|'))
                {
                    legalTitle += c;
                }
            }

            if (incremental)
            {
                var audioDownloader = new AudioDownloader(video, savePath + @"\" + countPrefix + " " + legalTitle + video.AudioExtension);
                audioDownloader.DownloadProgressChanged        += (sender, _args) => DownloadProgress(_args.ProgressPercentage, InVideo);
                audioDownloader.AudioExtractionProgressChanged += (sender, _args) => ExtractionProgress(_args.ProgressPercentage, InVideo);
                audioDownloader.Execute();
            }
            else
            {
                var audioDownloader = new AudioDownloader(video, savePath + @"\" + legalTitle + video.AudioExtension);
                audioDownloader.DownloadProgressChanged        += (sender, _args) => DownloadProgress(_args.ProgressPercentage, InVideo);
                audioDownloader.AudioExtractionProgressChanged += (sender, _args) => ExtractionProgress(_args.ProgressPercentage, InVideo);
                audioDownloader.Execute();
            }

            lock (threadLocker)
            {
                Program.frm.remaining--;
            }
        }
Exemple #7
0
 public void ListMiscRequirements(ListDelegate del = null)
 {
     foreach (string s in misc_requirements)
     {
         if (del == null)
         {
             Console.WriteLine(s);
         }
         else
         {
             del(s);
         }
     }
 }
            internal RefreshViaODATAFilterList(
                CancellationToken cancellationToken,
                ODATADetailLevel odataDetail,
                Func <T, bool> condition,
                ListDelegate <T> listObjects,
                ODATAMonitorControl odataMonitorControl)
            {
                this.CancellationToken = cancellationToken;
                _odataDetailLevel      = odataDetail;
                _condition             = condition;
                _listObjects           = listObjects;
                _odataMonitorControl   = odataMonitorControl;

                CurrentPassQueue = new Queue <MonitorLastCall <T> >();
                NextPassQueue    = new Queue <MonitorLastCall <T> >();
            }
Exemple #9
0
        //Lists all available meetings
        void list()
        {
            //print meetings
            lock (meetingList){
                foreach (KeyValuePair <string, MeetingProposal> key in meetingList)
                {
                    Log.Information(key.Value.ToString());
                }
            }
            //async ask for update
            IServer server = (IServer)Activator.GetObject(
                typeof(IServer),
                server_url);
            ListDelegate del = new ListDelegate(server.getMeetings);

            del.BeginInvoke(updateCallback, null);
        }
Exemple #10
0
 public void ListSkillRequirements(ListDelegate del = null)
 {
     for (int i = 0; i < (int)SkillRequirements.Skill.kCount; ++i)
     {
         SkillRequirements.Skill skill = (SkillRequirements.Skill)i;
         int level = skill_requirements.GetRequiredLevel(skill);
         if (level > 0)
         {
             string output = SkillRequirements.SkillToSkillName(skill) + ": " + level;
             if (del == null)
             {
                 Console.WriteLine(output);
             }
             else
             {
                 del(output);
             }
         }
     }
 }
Exemple #11
0
        public void ListQuestPointRequirements(ListDelegate del = null)
        {
            foreach (Quest q in required_quests)
            {
                int    required = q.required_quest_points;
                string output   = q.name + ": " + required;

                if (required > 0)
                {
                    if (del == null)
                    {
                        Console.WriteLine(output);
                    }
                    else
                    {
                        del(output);
                    }
                }

                q.ListQuestPointRequirements(del);
            }
        }
Exemple #12
0
        public void ListRequiredQuests(ListDelegate del = null, int depth = 0)
        {
            foreach (Quest q in required_quests)
            {
                string output = "";
                for (int i = 0; i < depth; ++i)
                {
                    output += '\t';
                }

                output += q.GetName() + '\n';

                if (del == null)
                {
                    Console.WriteLine(output);
                }
                else
                {
                    del(output);
                }

                q.ListRequiredQuests(del, depth + 1);
            }
        }
Exemple #13
0
 public MainWindow()
 {
     InitializeComponent();
     listFiles = new ListDelegate(DisplayFiles);
 }
 private static extern IntPtr OgreManagedArchive_Create(String name, String archType, LoadDelegate loadCallback, UnloadDelegate unloadCallback, OpenDelegate openCallback, ListDelegate listCallback, ListFileInfoDelegate listFileInfoCallback, FindDelegate findCallback, FindFileInfoDelegate findFileInfoCallback, ExistsDelegate existsCallback
     #if FULL_AOT_COMPILE
     , IntPtr instanceHandle
     #endif
     );
Exemple #15
0
        //Вычисление значения функций типа scalar и list
        public CalcValue GeneralFunction(CalcValue[] par, DataType dt, CalcParamRun calc, ScalarDelegate scalar, ListDelegate fun)
        {
            bool isScalar = scalar != null;
            int  n        = par.Count();

            _calc     = calc.CalcParam;
            Begin     = calc.ThreadCalc.PeriodBegin;
            End       = calc.ThreadCalc.PeriodEnd;
            _interpol = _calc.Interpolation;
            var sv = new SingleValue[n];
            int ki = 0, ks = 0;

            for (int i = 0; i < n; i++)
            {
                var cvt = par[i].Type;
                if (ki == 0 && cvt == CalcValueType.IntArray)
                {
                    ki = i;
                }
                if (ks == 0 && cvt == CalcValueType.StringArray)
                {
                    ks = i;
                }
                if (cvt != CalcValueType.IntArray && cvt != CalcValueType.StringArray)
                {
                    sv[i] = par[i].SingleValue;
                }
            }
            if (ki == 0 && ks == 0)//Нет массивов
            {
                if (isScalar)
                {
                    return(new CalcValue(ScalarFunction(sv, dt, scalar)));
                }
                var ss = new SingleValue();
                foreach (var s in sv)
                {
                    ss.Error |= s.Error;
                }
                fun(sv, ss);
                if (ss.Type != SingleType.Segments && ss.Moment == null && ss.Moments == null)
                {
                    ss.Moments = new List <Moment>();
                }
                if (ss.Type == SingleType.Segments && ss.Segments == null)
                {
                    ss.Segments = new List <Segment>();
                }
                return(new CalcValue(ss));
            }
            var cv = new CalcValue[n];

            if (ki > 0)//Массивы с целыми индексами
            {
                var resi = new CalcValue(new SortedDictionary <int, VarRun>());
                foreach (var key in par[ki].IntArray.Keys)
                {
                    bool e = true;
                    for (int i = 0; i < n; i++)
                    {
                        var p = par[i];
                        if (p.Type == CalcValueType.StringArray || (p.Type == CalcValueType.IntArray && !p.IntArray.ContainsKey(key)))
                        {
                            e = false;
                        }
                        else if (p.Type == CalcValueType.IntArray)
                        {
                            cv[i] = p.IntArray[key].CalcValue;
                        }
                        else
                        {
                            cv[i] = p;
                        }
                    }
                    if (e)
                    {
                        var c = GeneralFunction(cv, dt, calc, scalar, fun);
                        resi.Error |= c.Error;
                        resi.IntArray.Add(key, new VarRun(c));
                    }
                }
                return(resi);
            }
            //Массивы со строковыми индексами
            var ress = new CalcValue(new SortedDictionary <int, VarRun>());

            foreach (var key in par[ki].StringArray.Keys)
            {
                bool e = true;
                for (int i = 0; i < n; i++)
                {
                    var p = par[i];
                    if (p.Type == CalcValueType.IntArray || (p.Type == CalcValueType.StringArray && !p.StringArray.ContainsKey(key)))
                    {
                        e = false;
                    }
                    else if (p.Type == CalcValueType.StringArray)
                    {
                        cv[i] = p.StringArray[key].CalcValue;
                    }
                    else
                    {
                        cv[i] = p;
                    }
                }
                if (e)
                {
                    var c = GeneralFunction(cv, dt, calc, scalar, fun);
                    ress.Error |= c.Error;
                    ress.StringArray.Add(key, new VarRun(c));
                }
            }
            return(ress);
        }
Exemple #16
0
 static extern void InitManagedDelegates(RunDelegate run, ExecuteDelegate execute, ExecuteBackgroundDelegate executeBackground, ReloadDelegate reload, ListDelegate list);
        /// <summary>
        /// Polls the collection of instances until each has passed the condition at least once.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="collectionToMonitor"></param>
        /// <param name="condition"></param>
        /// <param name="getName"></param>
        /// <param name="listObjects"></param>
        /// <param name="cancellationToken"></param>
        /// <param name="detailLevel">Controls the detail level of the data returned by a call to the Azure Batch Service.</param>
        /// <param name="control"></param>
        /// <returns></returns>
        public static async Task WhenAllAsync <T>(
            IEnumerable <T> collectionToMonitor,
            Func <T, bool> condition,
            Func <T, string> getName,
            ListDelegate <T> listObjects,
            CancellationToken cancellationToken,
            ODATADetailLevel detailLevel,
            ODATAMonitorControl control) where T : IRefreshable
        {
            if (null == collectionToMonitor)
            {
                throw new ArgumentNullException("collectionToMonitor");
            }

            if (null == condition)
            {
                throw new ArgumentNullException("condition");
            }

            RefreshViaODATAFilterList <T> odataRefresher = new RefreshViaODATAFilterList <T>(cancellationToken, detailLevel, condition, listObjects, control);

            // populate for first pass
            foreach (T curT in collectionToMonitor)
            {
                // filter out the instances that already meet the condition
                if (!condition(curT))
                {
                    MonitorLastCall <T> box = new MonitorLastCall <T>(curT, /* flags each instance as available to refresh "now" */ DateTime.MinValue);

                    odataRefresher.CurrentPassQueue.Enqueue(box);
                }
            }

            // process the instances in the current pass... swap queues to begin next pass
            while (!odataRefresher.CancellationToken.IsCancellationRequested &&
                   odataRefresher.CurrentPassQueue.Count > 0)
            {
                // get next instance
                MonitorLastCall <T> nextInstanceToProcess = odataRefresher.CurrentPassQueue.Dequeue();

                // build an odata filter with as many names as the limit will allow and call refresh instances as needed
                Task asyncProcessOneInstance = odataRefresher.ProcessOneInstance(nextInstanceToProcess, getName);

                // a-wait for completion
                await asyncProcessOneInstance.ConfigureAwait(continueOnCapturedContext : false);

                // if the current pass queue is empty, swap the queues to begin next pass
                if (0 == odataRefresher.CurrentPassQueue.Count)
                {
                    odataRefresher.SwapQueues();

                    // if we appear to be done, the stringbuilder might have the last predicate in it so flush that
                    if (0 == odataRefresher.CurrentPassQueue.Count)
                    {
                        // start the call to process the last predicate
                        Task asyncListTask = odataRefresher.CallListAndProcessResults();

                        // a-wait for completion
                        await asyncListTask.ConfigureAwait(continueOnCapturedContext : false);

                        // if the last predicate created new work... the swap will bring it into a new pass
                        odataRefresher.SwapQueues();
                    }
                }
            }

            //Were we cancelled?
            odataRefresher.CancellationToken.ThrowIfCancellationRequested();
        }
        void DownloadAudioFrom(Downloadable InVideo, int count)
        {
            InVideo.Preparing = true;
            ListDelegate ld = new ListDelegate(Program.frm.UpdateList);
            Program.frm.Invoke(ld);

            string link = InVideo.Url;
            string countPrefix = count.ToString();
            countPrefix = countPrefix.PadLeft(padLeft, '0');

            VideoInfo video = DownloadUrlResolver.GetDownloadUrls(link);

            if (video.RequiresDecryption)
            {
                DownloadUrlResolver.DecryptDownloadUrl(video);
            }

            char[] legalTitleArray = video.Title.ToCharArray();
            string legalTitle = "";

            foreach (char c in legalTitleArray)
            {
                if (!(c == '/' || c == '\\' || c == ':' || c == '*' || c == '?' || c == '"' || c == '<' || c == '>' || c == '|'))
                {
                    legalTitle += c;
                }
            }

            if (incremental)
            {
                var audioDownloader = new AudioDownloader(video, savePath + @"\" + countPrefix + " " + legalTitle + video.AudioExtension);
                audioDownloader.DownloadProgressChanged += (sender, _args) => DownloadProgress(_args.ProgressPercentage, InVideo);
                audioDownloader.AudioExtractionProgressChanged += (sender, _args) => ExtractionProgress(_args.ProgressPercentage, InVideo);
                audioDownloader.Execute();
            }
            else
            {
                var audioDownloader = new AudioDownloader(video, savePath + @"\" + legalTitle + video.AudioExtension);
                audioDownloader.DownloadProgressChanged += (sender, _args) => DownloadProgress(_args.ProgressPercentage, InVideo);
                audioDownloader.AudioExtractionProgressChanged += (sender, _args) => ExtractionProgress(_args.ProgressPercentage, InVideo);
                audioDownloader.Execute();
            }

            lock (threadLocker)
            {
                Program.frm.remaining--;
            }
        }
Exemple #19
0
 private bool ListAdd(ListBox Info, string domen)
 {
     if (Info.InvokeRequired)
     {
         ListDelegate DDD = new ListDelegate(ListAdd);
         return (bool)Info.Invoke(DDD, new object[] { Info, domen });
     }
     else
     {
         if (listBox1.FindString(domen) < 0)
             listBox1.Items.Add(domen);
         else return false;
         return true;
     }
 }
Exemple #20
0
 static extern void InitManagedDelegates(RunDelegate run, ExecuteDelegate execute, ExecuteBackgroundDelegate executeBackground, ReloadDelegate reload, ListDelegate list);