示例#1
0
        /// <summary>
        /// Creates collection of components
        /// </summary>
        /// <param name="consumer">Data consumer</param>
        /// <param name="list">List of objects</param>
        /// <param name="action">Additional acton</param>
        /// <param name="priority">Priority</param>
        /// <param name="reason">Reason</param>
        /// <returns>Collection of components</returns>
        protected void CreateDataConsumerCollection(IDataConsumer consumer, List <object> list,
                                                    Action <object> action, int priority, string reason)
        {
            IList <object> ll = consumer.GetDependentObjects();

            foreach (object o in ll)
            {
                if (o is INamedComponent)
                {
                    action(o);
                    if (!list.Contains(o))
                    {
                        list.Add(o);
                    }
                    continue;
                }
                if (o is IAssociatedObject)
                {
                    IAssociatedObject ao = o as IAssociatedObject;
                    object            ob = ao.Object;
                    action(ob);
                    if (ob is INamedComponent)
                    {
                        if (!list.Contains(ob))
                        {
                            list.Add(ob);
                        }
                        continue;
                    }
                }
            }
        }
示例#2
0
        /// <summary>
        /// Sets root data consumer
        /// </summary>
        /// <param name="consumer">The consumer to set</param>
        public void Set(IDataConsumer consumer)
        {
            List <IDataConsumer> l = new List <IDataConsumer>();

            l.Add(consumer);
            Set(l);
        }
示例#3
0
        public IDisposable Connect(IDataConsumer channel)
        {
            this.channel = channel;

            if (buffer != null)
            {
                buffer.Each(d => channel.OnData(new ArraySegment <byte>(d), null));

                // XXX this maybe is kinda wrong.
                if (continuation != null)
                {
                    continuation();
                }
            }

            if (error != null)
            {
                channel.OnError(error);
            }

            if (gotEnd)
            {
                channel.OnEnd();
            }

            return(disposable());
        }
示例#4
0
        public IDisposable Connect(IDataConsumer channel)
        {
            var fileInfo = new FileInfo(_filepath);
            using(FileStream fileStream = fileInfo.Open(FileMode.Open, FileAccess.Read)) {
                var buffer = new byte[fileInfo.Length];
                fileStream.Read(buffer, 0, (int) fileInfo.Length);
                int length = (int) fileInfo.Length;
                int offset = 0;

                if(_requestHeaders.ContainsKey(HttpRequestHeader.Range.ToString())) {
                    string range = _requestHeaders[HttpRequestHeader.Range.ToString()];
                    Regex rangeEx = new Regex(@"bytes=([\d]*)-([\d]*)");
                    if(rangeEx.IsMatch(range)) {
                        int from = Convert.ToInt32(rangeEx.Match(range).Groups[1].Value);
                        int to = Convert.ToInt32(rangeEx.Match(range).Groups[2].Value);
                        offset = from;
                        length = (to - from) +1;
                    }
                }
                ArraySegment<byte> data = new ArraySegment<byte>(buffer, offset, length);
                channel.OnData(data, null);

                _log.DebugFormat("Wrote {0} bytes to buffer", data.Array.Length);
                channel.OnEnd();
                return null;
            }
        }
        /// <summary>
        /// Returns data to a data consumer.
        /// </summary>
        /// <param name="dataConsumer">The data consumer requesting the data.
        /// </param>
        /// <returns>The data for a given data consumer.</returns>
        IEnumerable <object> IDataProvider.GetData(IDataConsumer dataConsumer)
        {
            IAxis axis = (IAxis)dataConsumer;

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

            Func <DataPoint, object> selector = null;

            if (axis == InternalActualIndependentAxis)
            {
                if (IndependentValueBinding == null)
                {
                    return(Enumerable.Range(1, ActiveDataPointCount).Cast <object>());
                }
                selector = (dataPoint) => dataPoint.ActualIndependentValue ?? dataPoint.ActualDependentValue;
            }
            else if (axis == InternalActualDependentAxis)
            {
                selector = (dataPoint) => dataPoint.ActualDependentValue;
            }

            return(ActiveDataPoints.Select(selector).Distinct());
        }
示例#6
0
        public IDisposable Connect(IDataConsumer channel)
        {
            throw new NotImplementedException();

            /*
             * var cts = new CancellationTokenSource();
             * del(
             *  (data, continuation)=>
             *  {
             *      if (channel.OnData(data, () => continuation(null)) == true)
             *      {
             *          return OwinConstants.CompletingAsynchronously;
             *      }
             *      return OwinConstants.CompletedSynchronously;
             *  },
             *  error =>
             *  {
             *      if (error == null)
             *          channel.OnEnd();
             *      else
             *          channel.OnError(error);
             *  },
             *  cts.Token);
             * return new Disposable(cts.Cancel);*/
        }
示例#7
0
        /// <summary>
        /// Sets measures to consumer
        /// </summary>
        /// <param name="consumer">The consumer</param>
        /// <param name="measures">Names of measures</param>
        /// <param name="measuresData">Measures</param>
        public static void SetMeasurements(IDataConsumer consumer, List <string> measures, List <IMeasurement> measuresData)
        {
            measuresData.Clear();
            IAssociatedObject ac = consumer as IAssociatedObject;

            foreach (string ms in measures)
            {
                for (int i = 0; i < consumer.Count; i++)
                {
                    IMeasurements     m  = consumer[i];
                    IAssociatedObject ao = m as IAssociatedObject;
                    string            on = ac.GetRelativeName(ao) + ".";

                    for (int j = 0; j < m.Count; j++)
                    {
                        IMeasurement mea = m[j];
                        string       s   = on + mea.Name;
                        if (s.Equals(ms))
                        {
                            measuresData.Add(mea);
                        }
                    }
                }
            }
        }
示例#8
0
文件: Mocks.cs 项目: yukiyuki/kayak
        static void WriteNext(IEnumerator <string> data, IDataConsumer c, bool sync)
        {
            while (true)
            {
                if (!data.MoveNext())
                {
                    c.OnEnd();
                    data.Dispose();
                    break;
                }

                var seg = new ArraySegment <byte>(Encoding.UTF8.GetBytes(data.Current));
                if (sync)
                {
                    if (c.OnData(seg, null))
                    {
                        throw new Exception("sync write should have returned false");
                    }
                }
                else
                if (c.OnData(
                        seg,
                        () => WriteNext(data, c, sync)))
                {
                    break;
                }
            }
        }
示例#9
0
        public void Render(IDataConsumer consumer, HttpResponseHead head)
        {
            var status = head.Status;
            var headers = head.Headers;

            // XXX don't reallocate every time
            var sb = new StringBuilder();

            sb.AppendFormat("HTTP/1.1 {0}\r\n", status);

            if (headers == null)
                headers = new Dictionary<string, string>();

            if (!headers.ContainsKey("Server"))
                headers["Server"] = "Kayak";

            if (!headers.ContainsKey("Date"))
                headers["Date"] = DateTime.UtcNow.ToString();

            foreach (var pair in headers)
                foreach (var line in pair.Value.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries))
                    sb.AppendFormat("{0}: {1}\r\n", pair.Key, line);

            sb.Append("\r\n");

            consumer.OnData(new ArraySegment<byte>(Encoding.ASCII.GetBytes(sb.ToString())), null);
        }
示例#10
0
        /// <summary>
        /// Realtime analysis enumerable
        /// </summary>
        /// <param name="dataConsumer">Data consumer</param>
        /// <param name="readers">Input</param>
        /// <param name="stop">Stop function</param>
        /// <param name="reason">Reason</param>
        /// <param name="timeType">Time type</param>
        /// <param name="isAbsoluteTime">The absolute time "sign"</param>
        /// <returns>The enumerable</returns>
        public static IEnumerable <object> RealtimeAnalysisEnumerableDirectory(this IDataConsumer dataConsumer,
                                                                               ILogReaderCollection readers, Func <object, bool> stop, string reason,
                                                                               TimeType timeType, bool isAbsoluteTime)
        {
            IComponentCollection cc = dataConsumer.CreateCollection(reason);

            cc.ForEach((ICalculationReason re) => { re.CalculationReason = reason; });
            cc.ForEach((IRealTimeStartStop ss) => { ss.Start(); });
            IEnumerable <ILogReader> r = readers.Readers;

            foreach (ILogReader reader in r)
            {
                cc.ForEach((IRealTimeStartStop ss) => { ss.Start(); });
                IEnumerable <object> en =
                    dataConsumer.RealtimeAnalysisEnumerable(reader, stop, reason, timeType, isAbsoluteTime);
                object ob = null;
                foreach (object o in en)
                {
                    ob = o;
                }
                yield return(ob);

                cc.ForEach((IRealTimeStartStop ss) => { ss.Stop(); });
            }
            cc.ForEach((IRealTimeStartStop ss) => { ss.Stop(); });
        }
示例#11
0
        void ProcessArrow(IDataConsumer dc, IObjectLabel label, Arrow arrow, List <Arrow> absc)
        {
            BlockPort    bp = arrow.Source;
            string       to = bp.Block;
            IObjectLabel l  = desktop[to] as IObjectLabel;

            if (l == null)
            {
                return;
            }
            DataLink dl = new DataLink();

            try
            {
                if (desktop is PureDesktopPeer)
                {
                    PureDesktopPeer pdp = desktop as PureDesktopPeer;
                    if (label.Ord < l.Ord)
                    {
                        absc.Add(arrow);
                        return;
                    }
                    pdp.AddArrowWithExistingLabels(dl, label, l, "", "");
                }
            }
            catch (Exception)
            {
                absc.Add(arrow);
            }
        }
示例#12
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="names">Names</param>
        /// <param name="consumer">Consumer</param>
        /// <param name="disassembly">Disassembly</param>
        public DisassemblyWrapper(IEnumerable <string> names, IDataConsumer consumer,
                                  IDisassemblyObject disassembly)
        {
            Dictionary <IMeasurement, MeasurementsDisasseblyWrapper> d =
                consumer.CreateDisassemblyMeasurements(disassembly);
            Dictionary <string, IMeasurement> measurements = consumer.GetAllMeasurementsByName();

            foreach (string key in measurements.Keys)
            {
                if (names.Contains(key))
                {
                    IMeasurement measurement = measurements[key];
                    if (d.ContainsKey(measurement))
                    {
                        string s = key + ".";
                        MeasurementsDisasseblyWrapper wr = d[measurement];
                        l.Add(wr);
                        IMeasurement[] mea = wr.Measurements;
                        foreach (IMeasurement mm in mea)
                        {
                            dictionary[s + mm.Name] = mm;
                        }
                        continue;
                    }
                    dictionary[key] = measurement;
                }
            }
        }
示例#13
0
        /// <summary>
        /// Creates enumerator
        /// </summary>
        /// <param name="consumer">The consumer</param>
        /// <returns>The enumerator</returns>
        protected virtual IEnumerable <object> Create(IDataConsumer consumer)
        {
            Func <object, bool> stop    = (object o) => { return(false); };
            IDesktop            desktop = (consumer as IAssociatedObject).GetRootDesktop();
            object l = null;

            desktop.ForEach((BelongsToCollectionPortable b) =>
            {
                if (b.Source == consumer)
                {
                    object o = b.Target;
                    if (o is LogHolder)
                    {
                        LogHolder llh = o as LogHolder;
                        (llh as IAssociatedObject).Prepare(true);
                        l = llh.Reader;
                    }
                }
            });
            if (l != null)
            {
                string reason = Event.Interfaces.StaticExtensionEventInterfaces.PureRealtimeLogAnalysis;
                IComponentCollection collection = consumer.CreateCollection(reason);
                collection.ForEach((ICalculationReason r) =>
                {
                    r.CalculationReason = reason;
                });
                if (isDirectoryOriented)
                {
                    return(consumer.RealtimeAnalysisEnumerableDirectory(l, stop, reason, TimeType.Second, false));
                }
                return(consumer.RealtimeAnalysisEnumerable(l, stop, reason, TimeType.Second, false));
            }
            return(null);
        }
示例#14
0
 public IDisposable Connect(IDataConsumer channel)
 {
     return new Disposable(del(
         (data, continuation) => channel.OnData(data, continuation),
         error => channel.OnError(error),
         () => channel.OnEnd()));
 }
示例#15
0
    public void SendAndReceiveData(IDataConsumer caller, string request, string payload, string method)
    {
        theCaller  = caller;
        theRequest = theCaller.getRequest();

        int numChunks = payload.Length / MAX_LENGTH + 1;

        //	Debug.Log ("the length of payload is: " + payload.Length);
        thePayLoad = theCaller.getPayLoad();


        if (method.ToLower() == "post")
        {
            postData();
            return;
        }

        if (payload.Length < MAX_LENGTH)
        {
            doneProcessing = true;
        }
        else
        {
            leftover = payload.Substring(MAX_LENGTH, payload.Length - MAX_LENGTH);
            payload  = payload.Substring(0, MAX_LENGTH);
            //payload += "LARGE-" + numChunks.ToString()+ "-" + payload;
        }

        url = urlBase + payload;
        print("url: " + url);
        coroutine = StartCoroutine(DownloadTest(url, PrintText));
    }
示例#16
0
        //private Dictionary<IMeasurements, bool> isUpdated = new Dictionary<IMeasurements, bool>();

        #endregion

        #region Ctor

        protected PhysicalFieldDataConsumer()
        {
            cons = this;
            IPhysicalField f = this;

            input = new string[f.SpaceDimension];
        }
示例#17
0
 void IMeasurements.UpdateMeasurements()
 {
     if (input[0] == null)
     {
         return;
     }
     if (isUpdated)
     {
         return;
     }
     try
     {
         IDataConsumer c = this;
         c.UpdateChildrenData();
         Calculate((double)input[0].Parameter(), (double)input[1].Parameter());
         if (hasDerivation)
         {
             for (int i = 0; i < 2; i++)
             {
                 IDerivation der = input[i] as IDerivation;
                 result[1] += dx[i] * (double)der.Derivation.Parameter();
             }
         }
         isUpdated = true;
     }
     catch (Exception e)
     {
         e.ShowError(10);
         this.Throw(e);
     }
 }
示例#18
0
        public void AddConsumer(IDataConsumer consumer)
        {
#if DETAILED_TRACE
            Trace.WriteLine("Data context builder #" + Id + " adding consumer " + consumer);
#endif
            _dataConsumers.Add(consumer);
        }
示例#19
0
        public IDisposable Connect(IDataConsumer channel)
        {
            var fileInfo = new FileInfo(_filepath);

            using (FileStream fileStream = fileInfo.Open(FileMode.Open, FileAccess.Read)) {
                var buffer = new byte[fileInfo.Length];
                fileStream.Read(buffer, 0, (int)fileInfo.Length);
                int length = (int)fileInfo.Length;
                int offset = 0;

                if (_requestHeaders.ContainsKey(HttpRequestHeader.Range.ToString()))
                {
                    string range   = _requestHeaders[HttpRequestHeader.Range.ToString()];
                    Regex  rangeEx = new Regex(@"bytes=([\d]*)-([\d]*)");
                    if (rangeEx.IsMatch(range))
                    {
                        int from = Convert.ToInt32(rangeEx.Match(range).Groups[1].Value);
                        int to   = Convert.ToInt32(rangeEx.Match(range).Groups[2].Value);
                        offset = from;
                        length = (to - from) + 1;
                    }
                }
                ArraySegment <byte> data = new ArraySegment <byte>(buffer, offset, length);
                channel.OnData(data, null);

                Log.DebugFormat("Wrote {0} bytes to buffer", data.Array.Length);
                channel.OnEnd();
                return(null);
            }
        }
示例#20
0
        public FileProcessingForm(string initialInDir, string initialOutDir)
        {
            _dataProvider = new CreatedFileDataProvider(initialInDir);
            _manager      = new WorkerManager();
            _consumer     = new FileConsumer(initialOutDir);

            // data pipeline
            _dataProvider.FileAdded += _manager.AddDataToQueue;
            _manager.DataProcessed  += _consumer.ProcessData;
            _manager.DataProcessed  += (OutputData data) =>
                                       Invoke(new Action(
                                                  () =>
            {
                // выводим на ListView
                // TODO: выводить имя конечного файла было бы практичнее,
                // но нужно избежать дублирования с Consumer
                processedFilesListView.Items.Add(data.FileName);
            }));

            InitializeComponent();

            inputFolderTextBox.Text  = initialInDir;
            outputFolderTextBox.Text = initialOutDir;

            // согласовываем состояние с WorkerManager
            this.SetState(_manager.Running);
        }
示例#21
0
 /// <summary>
 /// Start
 /// </summary>
 /// <param name="collection">Components</param>
 /// <param name="timeUnit">Time unit</param>
 /// <param name="isAbsoluteTime">Components</param>
 /// <param name="realtimeStep">Realtime step</param>
 /// <param name="dataConsumer">Data consumer</param>
 public static IRealtime StartRealtime(this IComponentCollection collection,
                                       TimeType timeUnit, bool isAbsoluteTime, IAsynchronousCalculation realtimeStep,
                                       IDataConsumer dataConsumer, IEventLog log, string reason)
 {
     if (reason.Equals(StaticExtensionEventInterfaces.Realtime))
     {
         if (currentRuntime != null)
         {
             throw new Exception();
         }
         start(reason);
         currentRuntime = Runtime.Start(collection, timeUnit, isAbsoluteTime, realtimeStep,
                                        dataConsumer, log, reason);
         if (currentRuntime == null)
         {
             stop();
         }
     }
     else
     {
         start(reason);
         return(Runtime.Start(collection, timeUnit, isAbsoluteTime, realtimeStep,
                              dataConsumer, log, reason));
     }
     return(currentRuntime);
 }
示例#22
0
        public void ShouldProduceValuesForIdentityColumns()
        {
            ValueStore    vs       = new ValueStore();
            DataProducer  producer = new DataProducer(vs);
            DataRowEntity row      = producer.ProduceRow(customerTable, 1);

            // check that the value of the identity column have not been generated
            Assert.That(vs.GetByKey(row.Fields[0].KeyValue), Is.Null);

            IDataConsumer consumer = GetImplementedType();

            if (consumer.Init("", options))
            {
                int counter = 0;
                consumer.ReportInsertionCallback = new Action(() =>
                {
                    counter++;
                });
                consumer.Consume(new List <DataRowEntity> {
                    row
                }, vs);

                // now assert that the identity value have been generated by the consumer
                Assert.That(row.Fields[0].FieldName, Is.EqualTo("CustomerId"), "Column should be customerID");
                Assert.That(vs.GetByKey(row.Fields[0].KeyValue), Is.Not.Null, consumer.GetType().ToString());
            }
        }
示例#23
0
        bool Find()
        {
            IDataConsumer cons = this;

            foreach (string s in input)
            {
                if (s == null)
                {
                    return(false);
                }
            }
            foreach (string s in output)
            {
                if (s == null)
                {
                    return(false);
                }
            }
            for (int i = 0; i < 3; i++)
            {
                object[] o  = cons.FindAlias(input[i]);
                IAlias   a  = o[0] as IAlias;
                string   n  = o[1] as string;
                AlName   an = new AlName();
                an.alias = a;
                an.name  = n;
                al[i]    = an;
            }
            for (int i = 0; i < m.Length; i++)
            {
                m[i] = this.FindMeasurement(output[i], true);
            }
            return(true);
        }
        /// <summary>
        /// Performs action with fixed step
        /// </summary>
        /// <param name="consumer">Data consumer</param>
        /// <param name="start">Start time</param>
        /// <param name="step">Step</param>
        /// <param name="count">Count of steps</param>
        /// <param name="argument">Argument</param>
        /// <param name="values">Values</param>
        /// <param name="series">Series</param>
        /// <param name="functions">Functions</param>
        /// <returns>Result of simulation</returns>
        public static Dictionary <string, object> PerformFixed(this IDataConsumer consumer, double start, double step, int count,
                                                               string argument, string[] values,
                                                               out ParametrizedSeries[] series,
                                                               out Dictionary <DoubleArrayFunction, IMeasurement[]> functions)
        {
            try
            {
                series    = null;
                functions = null;
                Dictionary <string, object> dic = consumer.CreateMeasurements(argument, values, out series, out functions);
                if (dic == null)
                {
                    return(null);
                }
                PerformFixed(consumer, start, step, count, argument, values, series, functions, StaticExtensionDataPerformerInterfaces.Calculation);
                return(dic);
            }

            catch (Exception ex)
            {
                ex.ShowError(10);
                consumer.Throw(ex);
            }
            series    = null;
            functions = null;
            return(null);
        }
        /// <summary>
        /// Creates Xml document
        /// </summary>
        /// <param name="desktop">Desktop</param>
        /// <param name="consumer">Consumer name</param>
        /// <param name="input">Input</param>
        /// <param name="start">Start</param>
        /// <param name="step">Step</param>
        /// <param name="count">Count of steps</param>
        /// <returns>Document</returns>
        static public XmlDocument CreateXmlDocument(this IDesktop desktop, string consumer,
                                                    XmlDocument input, double start, double step, int count)
        {
            IDataConsumer c = desktop.GetObject(consumer) as IDataConsumer;

            return(c.CreateXmlDocument(input, start, step, count));
        }
示例#26
0
        public void Setup()
        {
            Reset();

            _dataConsumer = new DataConsumer(
                SetupMock <IDataDependencyFactory>());
        }
示例#27
0
	    public IDisposable Connect(IDataConsumer channel)
		{
			// null continuation, consumer must swallow the data immediately.
			channel.OnData(data, null);
			channel.OnEnd();
			return null;
		}
示例#28
0
 static void SetTimeProvider(IMeasurements m, ITimeMeasureProvider provider, IDictionary <ITimeMeasureConsumer, IMeasurement> dictionary)
 {
     if (m is ITimeMeasureConsumer)
     {
         ITimeMeasureConsumer mc = m as ITimeMeasureConsumer;
         if (dictionary.ContainsKey(mc))
         {
             if (mc.Time != provider.TimeMeasurement)
             {
                 dictionary[mc] = mc.Time;
                 mc.Time        = provider.TimeMeasurement;
             }
         }
         else
         {
             dictionary[mc] = mc.Time;
             mc.Time        = provider.TimeMeasurement;
         }
     }
     if (m is IDataConsumer)
     {
         IDataConsumer dc = m as IDataConsumer;
         SetTimeProvider(dc, provider, dictionary);
     }
     if (m is MeasurementsWrapper)
     {
         MeasurementsWrapper mw = m as MeasurementsWrapper;
         int n = mw.Count;
         for (int i = 0; i < n; i++)
         {
             SetTimeProvider(mw[i], provider, dictionary);
         }
     }
 }
示例#29
0
 public IDisposable Connect(IDataConsumer channel)
 {
     // null continuation, consumer must swallow the data immediately.
     channel.OnData(data, null);
     channel.OnEnd();
     return(null);
 }
示例#30
0
 private void Reset(IDataConsumer consumer)
 {
     if (consumer is ITimeMeasureConsumer)
     {
         ITimeMeasureConsumer tc = consumer as ITimeMeasureConsumer;
         if (dictionary.ContainsKey(tc))
         {
             tc.Time = dictionary[tc];
         }
     }
     for (int i = 0; i < consumer.Count; i++)
     {
         IMeasurements m = consumer[i];
         if (m is ITimeMeasureConsumer)
         {
             ITimeMeasureConsumer mc = m as ITimeMeasureConsumer;
             if (dictionary.ContainsKey(mc))
             {
                 mc.Time = dictionary[mc];
             }
         }
         if (m is IDataConsumer)
         {
             IDataConsumer dc = m as IDataConsumer;
             Reset(dc);
         }
     }
 }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="cons">Data consumer</param>
        /// <param name="meas">Measurements</param>
        public RegessionAliasMeasureUserControl(IDataConsumer cons,
                                                IMeasurements meas) : this()
        {
            this.meas = meas;
            Control panel = HeaderControl.Object.GetHeaderControl(cons, meas);

            panel.Top  = 0;
            panel.Left = 0;
            Controls.Add(panel);
            int y = panel.Height + 10;

            for (int i = 0; i < meas.Count; i++)
            {
                IMeasurement m = meas[i];
                Label        l = new Label();
                l.Text = m.Name;
                l.Top  = y;
                l.Left = 10;
                Controls.Add(l);
                y = l.Top + l.Height + 5;
                NumericUpDown n = new NumericUpDown();
                n.Minimum = -1;
                n.Value   = -1;
                n.Left    = 10;
                n.Top     = y;
                y        += n.Height + 20;
                Controls.Add(n);
                num.Add(n);
            }
            Height = y;
        }
示例#32
0
        private void Process(List <object> l, List <RelativeMeasurements> rm, IPosition position,
                             List <object> ladd, int priority, string reason)
        {
            Action <object> act = (object obj) => { };

            if (position == null)
            {
                return;
            }
            IDataConsumer c = position.GetLabelObject <IDataConsumer>();

            if (c != null)
            {
                if (c is IAssociatedObject)
                {
                    IAssociatedObject ao = c as IAssociatedObject;
                    object            o  = ao.Object;
                    if (!ladd.Contains(o))
                    {
                        ladd.Add(o);
                    }
                }
                CreateDataConsumerCollection(c, ladd, act, priority, reason);
            }
            Process(l, rm, position.Parent, ladd, priority, reason);
        }
示例#33
0
        void fillOut()
        {
            IDataConsumer dc = consumer;
            List <string> l  = dc.GetAllMeasurements(null);

            outcoming.FillCombo(l);
        }
示例#34
0
        private void Configure(AttributeSet attributes, IDataConsumer dataConsumer)
        {
            if (dataConsumer == null)
            {
                return;
            }

            if (attributes.NeedsDatas != null)
            {
                foreach (var need in attributes.NeedsDatas)
                {
                    if (need.DataType != null || !string.IsNullOrEmpty(need.Scope))
                    {
                        dataConsumer.HasDependency(need.DataType, need.Scope);
                    }

                    if (!string.IsNullOrEmpty(need.DataProviderName))
                    {
                        _nameManager.AddResolutionHandler(
                            NameResolutionPhase.ResolveElementReferences,
                            (nm, dc, n) => dc.HasDependency(nm.ResolveDataProvider(n)),
                            dataConsumer,
                            need.DataProviderName);
                    }
                }
            }
        }
示例#35
0
 public IDisposable Connect(IDataConsumer channel)
 {
     // null continuation, consumer must swallow the data immediately.
     var bytes = new ArraySegment<byte>(dataFunc());
     channel.OnData(bytes, null);
     channel.OnEnd();
     return null;
 }
 internal NetworkService(IDataConsumer dataConsumer, Properties props)
 {
     myServerPort = props.NetworkPort;
       myDataConsumer = dataConsumer;
       myServerSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
       myServerSocket.Bind(new IPEndPoint(IPAddress.Any, myServerPort));
       myServerSocket.Listen(1024);
 }
示例#37
0
 /// <summary>Записывает данные из буфера в другой буфер</summary>
 /// <param name="DestinationBuffer">Буфер, в который необходимо совершить копирование</param>
 public void CopyTo(IDataConsumer DestinationBuffer)
 {
     foreach (BufferSegment segment in _segments.OrderBy(s => s.StartPosition))
     {
         segment.Seek(0, SeekOrigin.Begin);
         DestinationBuffer.Write(segment.StartPosition, segment.ToArray());
     }
 }
 public void Unsubscribe(IDataConsumer dataConsumer)
 {
     Utils.ThrowException(dataConsumer == null ? new ArgumentNullException("dataConsumer") : null);
     if (mDataConsumers.Contains(dataConsumer))
     {
         mDataConsumers.Remove(dataConsumer);
     }
 }
        public IDisposable Connect(IDataConsumer channel)
        {
            using(Stream source = File.OpenRead(_fileName))
            {
                var buffer = new byte[_bufferSize];
                while(source.Read(buffer, 0, buffer.Length) > 0)
                {
                    channel.OnData(new ArraySegment<byte>(buffer), null);
                }
            }

            channel.OnEnd();
            return null;
        }
示例#40
0
 public IDisposable Connect(IDataConsumer channel)
 {
     var cts = new CancellationTokenSource();
     del(
         channel.OnData,
         error =>
         {
             if (error == null)
                 channel.OnEnd();
             else
                 channel.OnError(error);
         },
         cts.Token);
     return new Disposable(cts.Cancel);
 }
        public void OnRequest(HttpRequestHead request, bool shouldKeepAlive)
        {
            var responseDelegate = responseDelegateFactory.Create(request, shouldKeepAlive, CloseConnection);

            DataSubject subject = null;
            bool requestBodyConnected = false;

            Debug.WriteLine("[{0}] {1} {2} shouldKeepAlive = {3}",
                DateTime.Now, request.Method, request.Uri, shouldKeepAlive);

            if (request.HasBody())
            {
                subject = new DataSubject(() =>
                {
                    if (requestBodyConnected) 
                        throw new InvalidOperationException("Request body was already connected.");

                    requestBodyConnected = true;

                    if (request.IsContinueExpected())
                        responseDelegate.WriteContinue();

                    return new Disposable(() =>
                    {
                        // XXX what to do?
                        // ideally we stop reading from the socket. 
                        // equivalent to a parse error
                    });
                });
            }

            requestBody = subject;

            if (remoteAddress != null)
            {
                if (request.Headers.ContainsKey("X-Forwarded-For"))
                {
                    request.Headers["X-Forwarded-For"] += "," + remoteAddress.ToString();
                }
                else
                {
                    request.Headers["X-Forwarded-For"] = remoteAddress.ToString();
                }
            }

            requestDelegate.OnRequest(request, subject, responseDelegate);
            observer.OnNext(responseDelegate);
        }
示例#42
0
        public IDisposable Connect(IDataConsumer consumer)
        {
            if (consumer == null)
                throw new ArgumentNullException();

            this.consumer = consumer;

            bool begin = false;

            state.OnConnect(out begin);

            if (begin)
                Begin();

            return new Disposable(Abort);
        }
示例#43
0
        public IDisposable Connect(IDataConsumer consumer)
        {
            if (consumer == null)
                throw new ArgumentNullException();

            this.consumer = consumer;

            bool writeContinue = false;
            bool begin = false;

            state.OnConnect(out begin, out writeContinue);

            if (writeContinue)
                RenderContinue();

            if (begin)
                BeginResponse();

            return new Disposable(Abort);
        }
示例#44
0
        public IDisposable Connect(IDataConsumer channel)
        {
            this.channel = channel;

            if (buffer != null)
            {
                buffer.Each(d => channel.OnData(new ArraySegment<byte>(d), null));

                // XXX this maybe is kinda wrong.
                if (continuation != null)
                    continuation();
            }

            if (error != null)
                channel.OnError(error);

            if (gotEnd)
                channel.OnEnd();

            return disposable();
        }
示例#45
0
 public IDisposable Connect(IDataConsumer channel)
 {
     var cts = new CancellationTokenSource();
     del(
         (data, continuation)=>
         {
             if (channel.OnData(data, () => continuation(null)) == true)
             {
                 return OwinConstants.CompletingAsynchronously;
             }
             return OwinConstants.CompletedSynchronously;
         },
         error =>
         {
             if (error == null)
                 channel.OnEnd();
             else
                 channel.OnError(error);
         },
         cts.Token);
     return new Disposable(cts.Cancel);
 }
示例#46
0
        /// <summary>
        /// Manage data that is dragged over and dropped on the <code>dropTarget</code>.
        /// Supported data is defined as one or more classes that implement IDataConsumer.
        /// </summary>
        /// <param name="dropTarget">FrameworkElement monitored for drag events</param>
        /// <param name="dragDropConsumers">Array of supported data objects</param>
        public DropManager(FrameworkElement dropTarget, IDataConsumer[] dragDropConsumers) {
            this._dropTarget = dropTarget;
            System.Diagnostics.Debug.Assert(dropTarget != null);

            this._dragDropConsumers = dragDropConsumers;
            System.Diagnostics.Debug.Assert(dragDropConsumers != null);

            bool hookDragEnter = false;
            bool hookDragOver = false;
            bool hookDrop = false;
            bool hookDragLeave = false;

            // Determine which events to hook
            foreach(IDataConsumer dragDropConsumer in this._dragDropConsumers) {
                if((dragDropConsumer.DataConsumerActions & DataConsumerActions.DragEnter) != 0)
                    hookDragEnter = true;
                if((dragDropConsumer.DataConsumerActions & DataConsumerActions.DragOver) != 0)
                    hookDragOver = true;
                if((dragDropConsumer.DataConsumerActions & DataConsumerActions.Drop) != 0)
                    hookDrop = true;
                if((dragDropConsumer.DataConsumerActions & DataConsumerActions.DragLeave) != 0)
                    hookDragLeave = true;
            }

            if((hookDragEnter == true) || (hookDragOver == true) || (hookDrop == true) || (hookDragLeave == true))
                this._dropTarget.AllowDrop = true;

            // Hook only the events needed
            if(hookDragEnter == true)
                this._dropTarget.DragEnter += new DragEventHandler(this.DropTarget_DragEnter);
            if(hookDragOver == true)
                this._dropTarget.DragOver += new DragEventHandler(this.DropTarget_DragOver);
            if(hookDrop == true)
                this._dropTarget.Drop += new DragEventHandler(this.DropTarget_Drop);
            if(hookDragLeave == true)
                this._dropTarget.DragLeave += new DragEventHandler(this.DropTarget_DragLeave);
        }
示例#47
0
		public IDisposable Connect(IDataConsumer channel) {
			return null;
		}
 /// <summary>
 /// Wraps consumer (MessageConsumer) within a buffered consumer that reads whole message into memory.
 /// Result is that HTTP Headers and Body are sent at same socket.write.
 /// Ios client seems to prefer it this way. Freaks out when payload arrives in different packet.
 /// </summary>
 /// <param name="consumer"></param>
 /// <returns></returns>
 public override IDisposable Connect(IDataConsumer consumer)
 {
     return base.Connect(new BufferedConsumerWrapper(consumer));
 }
示例#49
0
 public IDisposable Connect(IDataConsumer channel)
 {
   channel.OnData(new ArraySegment<byte>(), null);
   channel.OnEnd();
   return null;
 }
 /// <summary>
 /// Returns the data for the data points of the series.
 /// </summary>
 /// <param name="dataConsumer">Consumer of the data.</param>
 /// <returns>Sequence of data.</returns>
 protected virtual IEnumerable<object> IDataProviderGetData(IDataConsumer dataConsumer)
 {
     if (dataConsumer == ActualIndependentAxis)
     {
         return IndependentValueGroups.Select(cg => cg.IndependentValue).Distinct();
     }
     throw new NotImplementedException();
 }
 /// <summary>
 /// Returns the data for the data points of the series.
 /// </summary>
 /// <param name="dataConsumer">Consumer of the data.</param>
 /// <returns>Sequence of data.</returns>
 IEnumerable<object> IDataProvider.GetData(IDataConsumer dataConsumer)
 {
     return IDataProviderGetData(dataConsumer);
 }
 public void Render(IDataConsumer consumer, HttpResponseHead head)
 {
     if (Rendered) throw new InvalidOperationException("already rendered");
     Rendered = true;
     consumer.OnData(new ArraySegment<byte>(Encoding.ASCII.GetBytes("[headers]")), null);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="DataConsumerMutableCore"/> class.
 /// </summary>
 /// <param name="objTarget">
 /// The obj target. 
 /// </param>
 public DataConsumerMutableCore(IDataConsumer objTarget)
     : base(objTarget)
 {
 }
示例#54
0
 public IDisposable Connect(IDataConsumer channel)
 {
     this.consumer = channel;
     connect();
     return new Disposable(disconnect);
 }
 public IDisposable Connect(IDataConsumer channel)
 {
     return new Disposable(subscribe(channel));
 }
 public IDisposable Connect(IDataConsumer channel)
 {
     channel.OnData(data, null);
     channel.OnEnd();
     return null;
 }
 public void Subscribe(IDataConsumer dataConsumer)
 {
     Utils.ThrowException(dataConsumer == null ? new ArgumentNullException("dataConsumer") : null);
     mDataConsumers.Add(dataConsumer);
 }
 public void AttachConsumer(IDataConsumer consumer)
 {
     Consumers.Add(consumer);
 }
示例#59
0
 /// <summary>
 /// Manage data that is dragged over and dropped on the <code>dropTarget</code>.
 /// Supported data is defined as one or more classes that implement IDataConsumer.
 /// </summary>
 /// <param name="dropTarget">FrameworkElement monitored for drag events</param>
 /// <param name="dragDropConsumer">Supported data objects</param>
 public DropManager(FrameworkElement dropTarget, IDataConsumer dragDropConsumer)
     : this(dropTarget, new IDataConsumer[] { dragDropConsumer })
 {
 }
 void WriteSync(IDataConsumer c, string str)
 {
     c.OnData(new ArraySegment<byte>(Encoding.UTF8.GetBytes(str)), null);
 }