コード例 #1
0
        //public static void SetDataSource<T>(this BindingSource bs, IList<T>, Control ctrlContext)
        //{
        //    bs.DataSource =
        //    return new SortableBindingList<T>(list, ctrlContext);
        //}


        public static TSource[] ToSortedArray <TSource>(this System.Collections.Generic.IEnumerable <TSource> source, Comparison <TSource> comparer)
        {
            var res = source.ToArray();

            Array.Sort(res, comparer);
            return(res);
        }
コード例 #2
0
        public async void Push(System.Collections.Generic.IEnumerable <TPackage> packages)
        {
            var buffer = _CreateBuffer(packages.ToArray());

            if (buffer.Length == 0)
            {
                return;
            }

            IWaitableValue <int> wv = null;

            try
            {
                wv = _Peer.Send(buffer, 0, buffer.Length);
            }
            catch (System.Exception ex)
            {
                Regulus.Utility.Log.Instance.WriteInfo(ex.ToString());
                ErrorEvent();
            }

            if (wv == null)
            {
                return;
            }
            var sendCount = await wv;

            _WriteEnd(sendCount);
        }
コード例 #3
0
        public static TSource[] ToSortedArray <TSource>(this System.Collections.Generic.IEnumerable <TSource> source)
            where TSource : IComparable <TSource>
        {
            var res = source.ToArray();

            Array.Sort(res);
            return(res);
        }
コード例 #4
0
        private int RefreshUI()
        {
            var selectedItem = _lstCharacters.SelectedItem;

            System.Collections.Generic.IEnumerable <NewCharacter> newCharacters = (IEnumerable <NewCharacter>)_lstCharacters;

            var items = newCharacters.ToArray();

            _lstCharacters.DataSource = items;

            return(items.Length);
        }
コード例 #5
0
        public ZipStreamResult(System.Collections.Generic.IEnumerable <string> files, string fileDownloadName) : base(ZipStreamResult.ContextType)
        {
            this.files = files.ToArray <string>();
            string name = fileDownloadName ?? "";

            if (name.Length == 0 && files.Count <string>() == 1)
            {
                name = System.IO.Path.GetFileNameWithoutExtension(files.First <string>());
            }
            if (!name.ToLower().EndsWith(ZipStreamResult.FileExtension))
            {
                name += ZipStreamResult.FileExtension;
            }
            base.FileDownloadName = HttpUtility.UrlEncode(name);
        }
コード例 #6
0
        public static String[] CreateEarlyBoundClass(String connectionString, String[] entities)
        {
            if (String.IsNullOrWhiteSpace(connectionString))
            {
                throw new Exception("Missing connection string.");
            }

            var trace = new MemorySpklTraceLogger();
            MemoryTraceLogger traceCollection = new MemoryTraceLogger();

            var        temporaryFilePath = System.IO.Path.GetTempFileName();
            var        temporaryFile     = System.IO.Path.GetFileName(temporaryFilePath);
            var        temporaryFolder   = System.IO.Path.GetDirectoryName(temporaryFilePath);
            ConfigFile mockConfigFile    = GetMockConfigFile(entities, temporaryFile, temporaryFolder);
            var        fakeContext       = new FakeServiceContext();

            try
            {
                var earlyBound = new EarlyBoundClassGeneratorTask(fakeContext, trace);
                earlyBound.ConectionString = connectionString;
                earlyBound.CreateEarlyBoundTypes(null, mockConfigFile);
            }
            catch (Exception ex)
            {
                for (int i = traceCollection.traces.Count - 1; i > 0; i--)
                {
                    if (!Regex.Match(traceCollection.traces[i], "Exiting program with exception").Success)
                    {
                        continue;
                    }

                    var snippets = traceCollection.traces[i].Split(new string[] { "Exiting program with exception: " }, StringSplitOptions.RemoveEmptyEntries);
                    throw new Exception(snippets[snippets.Length - 1], ex);
                }

                throw ex;
            }

            System.Collections.Generic.IEnumerable <String> lines = System.IO.File.ReadLines(temporaryFilePath);
            return(lines.ToArray <String>());
        }
コード例 #7
0
 internal static string[] SplitString(string original)
 {
     string[] result;
     if (string.IsNullOrEmpty(original))
     {
         result = new string[0];
     }
     else
     {
         System.Collections.Generic.IEnumerable <string> split =
             from piece in original.Split(new char[]
         {
             ','
         })
             let trimmed = piece.Trim()
                           where !string.IsNullOrEmpty(trimmed)
                           select trimmed;
         result = split.ToArray <string>();
     }
     return(result);
 }
コード例 #8
0
ファイル: TTcpClientSocket.cs プロジェクト: thomastse2001/vs
        /// Analyze the incoming buffer.
        /// 3 statuses.
        /// State, IsIncomingDataFinished, IsIncomingDataLength.
        /// 1st state, True, True. The previous data is finished. And if there is an incoming data, should analyze the length first.
        /// 2nd state, False, True. set this state if the current incoming data arrives. And should analyze the length.
        /// 3rd state, False, False. After analyzing the length, set to analyze the content.
        private void AnalyzeIncomingBuffer()
        {
            byte[] byteDataInQueue;
            int    iIndex1;/// Number of bytes that already analyzied in the data of the queue.
            int    iCopy, iInputRemaining, iOutputRemaining;
            string remoteEndPoint = "";
            string localEndPoint  = "";

            try
            {
                //if (mQueueOfIncomingBuffer == null || mQueueOfIncomingBuffer.Count < 1) { return; }
                remoteEndPoint = RemoteEndPoint;
                localEndPoint  = LocalEndPoint;
                if (ContainLengthAsHeader)
                {
                    /// The case that data contains the length as header.
                    /// TT edited on 2018-08-21 to lock the common resource.
                    while (TryDequeueAtIncomingBufferQueue(out byteDataInQueue))
                    {
                        //if (byteDataInQueue == null) { return; }
                        if (byteDataInQueue != null)
                        {
                            Logger?.Debug("AnalyzeIncomingBuffer. byteDataInQueue.Length = {0}, Server socket = {1}, Local socket = {2}", byteDataInQueue.Length, remoteEndPoint, localEndPoint);
                            /// Loop through the buffer item of the queue.
                            iIndex1 = 0;
                            while (iIndex1 < byteDataInQueue.Length)
                            {
                                /// If they are bytes of length, do following.
                                if (IsIncomingDataLength)
                                {
                                    /// If the previous data is finished, do following.
                                    if (IsIncomingDataFinished)
                                    {
                                        IsIncomingDataFinished = false;/// Go to 2nd state.
                                        IncomingLengthIndex    = 0;
                                        IncomingContentIndex   = 0;
                                        IncomingContentSize    = 0;
                                        /// Assign 4 byte to the Length buffer.
                                        if (IncomingLengthBuffer != null)
                                        {
                                            IncomingLengthBuffer = null;
                                        }
                                        IncomingLengthBuffer = new byte[4];
                                    }
                                    /// Determine the number of bytes to be read and copied.
                                    iInputRemaining  = byteDataInQueue.Length - iIndex1; /// number of bytes that input remains to be read.
                                    iOutputRemaining = 4 - IncomingLengthIndex;          /// number of bytes that output remains to be write.
                                    if (iInputRemaining >= iOutputRemaining)
                                    {
                                        /// If remaining data length is larger than or equal to 4, do following.
                                        iCopy = iOutputRemaining;
                                    }
                                    else
                                    {
                                        /// If the remaining data length is smaller than 4, do following.
                                        iCopy = iInputRemaining;
                                    }
                                    /// Copy.
                                    if (iCopy > 0)
                                    {
                                        Array.Copy(byteDataInQueue, iIndex1, IncomingLengthBuffer, IncomingLengthIndex, iCopy);
                                    }
                                    IncomingLengthIndex += iCopy;
                                    iIndex1             += iCopy;
                                    /// Check if finish to copy the length.
                                    if (IncomingLengthIndex < 4)
                                    {
                                    }                               /// do nothing and continue to loop.
                                    else
                                    {
                                        if (IncomingLengthIndex == 4)
                                        {
                                            IncomingContentSize = BitConverter.ToInt32(IncomingLengthBuffer, 0);
                                            if (IncomingContentBuffer != null)
                                            {
                                                IncomingContentBuffer = null;
                                            }
                                            if (IncomingContentSize > 0)
                                            {
                                                IncomingContentBuffer = new byte[IncomingContentSize];
                                            }

                                            IsIncomingDataLength = false; /// go to 3rd state.
                                            IncomingContentIndex = 0;     /// reset the index of content again.
                                        }
                                        else
                                        {
                                            Logger?.Error("AnalyzeIncomingBuffer. Too many bytes of length are copied. It is unexpected. Server socket = {0}, local socket = {1}", remoteEndPoint, localEndPoint);
                                            return;
                                        }
                                    }
                                }
                                else
                                {
                                    /// If they are bytes of content, do following.
                                    /// assume the memory is assigned for content.
                                    iInputRemaining  = byteDataInQueue.Length - iIndex1;
                                    iOutputRemaining = IncomingContentSize - IncomingContentIndex;
                                    if (iInputRemaining >= iOutputRemaining)
                                    {
                                        /// if remaining data length is larger than or equal to the remaining data required to read to the buffer, do following.
                                        iCopy = iOutputRemaining;
                                    }
                                    else
                                    {
                                        /// if remaining data length is smaller than the remaining data required to read to the buffer, do following.
                                        iCopy = iInputRemaining;
                                    }
                                    /// Copy.
                                    if (iCopy > 0)
                                    {
                                        Array.Copy(byteDataInQueue, iIndex1, IncomingContentBuffer, IncomingContentIndex, iCopy);
                                    }
                                    IncomingContentIndex += iCopy;
                                    iIndex1 += iCopy;
                                    /// Check if finish to copy the content.
                                    if (IncomingContentIndex < IncomingContentSize)
                                    {
                                    }                                                  /// do nothing and continue to loop.
                                    else
                                    {
                                        if (IncomingContentIndex == IncomingContentSize)
                                        {
                                            AddDataToIncomingDataQueue(DateTime.Now, IncomingContentBuffer);
                                            /// go back to 1st state.
                                            IsIncomingDataFinished = true;
                                            IsIncomingDataLength   = true;
                                        }
                                        else
                                        {
                                            Logger?.Error("AnalyzeIncomingBuffer. Too many bytes of content are copied. It is unexpected. Server socket = {0}, local socket = {1}", remoteEndPoint, localEndPoint);
                                            return;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    // /// The case that data does NOT contain the length as header.
                    // int iLengthContent = byteDataInQueue.Length;
                    // if (iLengthContent < 1) { return; }
                    // byte[] vbyteContent = new byte[iLengthContent];
                    // Array.Copy(byteDataInQueue, 0, vbyteContent, 0, iLengthContent);
                    // AddDataToIncomingDataQueue(DateTime.Now, true, ref vbyteContent);

                    /// TT edited on 2018-08-21 to lock the common resource.
                    while (TryDequeueAtIncomingBufferQueue(out byteDataInQueue))
                    {
                        if ((byteDataInQueue?.Length ?? 0) < 1)
                        {
                            /// if there is a zero-byte content, assume that it is the end of data.
                            if (IncomingBufferList != null)
                            {
                                /// https://stackoverflow.com/questions/4868113/convert-listbyte-to-one-byte-array
                                //byte[] byteFinalData = mListOfIncomingBuffer.SelectMany(x => x).ToArray();
                                byte[] byteFinalData = null;
                                System.Collections.Generic.IEnumerable <byte> oIEnumerable = null;
                                if (IncomingBufferList != null)
                                {
                                    oIEnumerable = IncomingBufferList.SelectMany(x => x);
                                }
                                if (oIEnumerable != null)
                                {
                                    byteFinalData = oIEnumerable.ToArray();
                                }
                                AddDataToIncomingDataQueue(DateTime.Now, byteFinalData);
                                /// Release memory of the list.
                                IncomingBufferList.Clear();
                                IncomingBufferList = null;
                            }
                        }
                        else
                        {
                            /// add data into temp list.
                            if (IncomingBufferList == null)
                            {
                                IncomingBufferList = new List <byte[]>();
                            }
                            IncomingBufferList.Add(byteDataInQueue);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger?.Error("Server socket = {0}, local socket = {1}", remoteEndPoint, localEndPoint);
                Logger?.Error(ex);
            }
        }
コード例 #9
0
ファイル: StringX.cs プロジェクト: claudia-gp/oblivious-oscar
 /// <summary>
 /// Return a string which is the concatenation of the strings in the collection. The separator between elements
 /// is the string providing this method. Mimics str.join(iterable) in Python.
 /// </summary>
 /// <param name="separator">Separator.</param>
 /// <param name="collection">Collection.</param>
 public static string Join(this string separator, System.Collections.Generic.IEnumerable <string> collection)
 {
     return(string.Join(separator, collection.ToArray()));
 }
コード例 #10
0
        public async Task <ProcessConsentResult> ProcessConsent(ConsentInputModel model)
        {
            ProcessConsentResult result = new ProcessConsentResult();

            ConsentResponse grantedConsent = null;

            // user clicked 'no' - send back the standard 'access_denied' response
            if (model.Button == "no")
            {
                grantedConsent = ConsentResponse.Denied;
            }
            // user clicked 'yes' - validate the data
            else if (model.Button == "yes" && model != null)
            {
                // if the user consented to some scope, build the response model
                if (model.ScopesConsented != null && model.ScopesConsented.Any())
                {
                    System.Collections.Generic.IEnumerable <string> scopes = model.ScopesConsented;
                    if (ConsentOptions.EnableOfflineAccess == false)
                    {
                        scopes = scopes.Where(x => x != IdentityServer4.IdentityServerConstants.StandardScopes.OfflineAccess);
                    }

                    grantedConsent = new ConsentResponse {
                        RememberConsent = model.RememberConsent,
                        ScopesConsented = scopes.ToArray()
                    };
                }
                else
                {
                    result.ValidationError = ConsentOptions.MustChooseOneErrorMessage;
                }
            }
            else
            {
                result.ValidationError = ConsentOptions.InvalidSelectionErrorMessage;
            }

            if (grantedConsent != null)
            {
                // validate return url is still valid
                AuthorizationRequest request = await this._interaction.GetAuthorizationContextAsync(model.ReturnUrl);

                if (request == null)
                {
                    return(result);
                }

                // communicate outcome of consent back to identityserver
                await this._interaction.GrantConsentAsync(request, grantedConsent);

                // indicate that's it ok to redirect back to authorization endpoint
                result.RedirectUri = model.ReturnUrl;
            }
            else
            {
                // we need to redisplay the consent UI
                result.ViewModel = await this.BuildViewModelAsync(model.ReturnUrl, model);
            }

            return(result);
        }
コード例 #11
0
ファイル: Generator.cs プロジェクト: flowor/RosterTools
 private string[] FileToArray(string path)
 {
     System.Collections.Generic.IEnumerable <String> lines = File.ReadLines(path);
     return(lines.ToArray());
 }
コード例 #12
0
 public void SetAffectedActors(System.Collections.Generic.IEnumerable <FightActor> actors)
 {
     this.m_customAffectedActors = actors.ToArray <FightActor>();
 }