コード例 #1
0
 public void ExportJobs(string filename)
 {
     string[] lines = new string[UnusedIds.Count + 1];
     lines[0] = NextId.ToString();
     for (int i = 1; i < lines.Length; ++i)
     {
         lines[i] = UnusedIds.Pop().ToString();
     }
     File.WriteAllLines(filename, lines);
 }
コード例 #2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="socket"></param>
 /// <param name="stream"></param>
 public Connection(Socket socket, Stream stream)
 {
     this.Socket         = socket;
     this.Stream         = stream;
     this.LocalEndPoint  = this.Socket.LocalEndPoint;
     this.RemoteEndPoint = this.Socket.RemoteEndPoint;
     this.ConnectTime    = DateTime.Now;
     this.ProtocolType   = this.Socket.ProtocolType;
     this.sendLocker     = new InterLocker();
     this.receiveLocker  = new InterLocker();
     this.Id             = NextId.Next();
 }
コード例 #3
0
ファイル: Program.cs プロジェクト: jamie-lord/Spindel
        public new Page Add(Page item)
        {
            var existingItem = this.Where(p => p.label == item.label).FirstOrDefault();

            if (existingItem != null)
            {
                item = existingItem;
            }
            else
            {
                item.id = NextId.ToString();
                item.x  = NextCoordinate;
                item.y  = NextCoordinate;
                base.Add(item);
            }
            return(item);
        }
コード例 #4
0
        /// <summary>
        ///
        /// </summary>
        public Connection(Socket socket, ISocketBufferProvider bufferProvider, ISocketProtocol socketProtocol = null)
        {
            this.socket         = socket;
            this.LocalEndPoint  = this.socket.LocalEndPoint;
            this.RemoteEndPoint = this.socket.RemoteEndPoint;
            this.ConnectTime    = DateTime.Now;
            this.ProtocolType   = this.socket.ProtocolType;
            this.bufferProvider = bufferProvider;

            //发送方根据得到的数据去setbuffer
            this.sendSocketAsyncEvent = new SocketAsyncEventArgs()
            {
                AcceptSocket = this.socket,
            };

            this.sendSocketAsyncEvent.Completed += SendSocketAsyncEvent_Completed;

            var buffer = this.bufferProvider.Alloc();

            this.receiveSocketAsyncEvent = new SocketAsyncEventArgs()
            {
                AcceptSocket = this.socket,
                UserToken    = new SocketUserToken()
                {
                    SocketBuffer = buffer,
                },
            };

            this.receiveSocketAsyncEvent.Completed += ReceiveSocketAsyncEvent_Completed;
            this.receiveSocketAsyncEvent.SetBuffer(buffer.Segment.Array, buffer.Segment.Offset, buffer.Segment.Count);
            //注意这里塞入的是原始数据,拿出的再加工发送
            this.sendDataQueue = new ConcurrentQueue <byte[]>();
            //这里是获取了传输的数据,并不是buffer里面的
            this.receiveDataQueue = new ConcurrentQueue <byte[]>();
            this.sendLocker       = new InterLocker();
            this.receiveLocker    = new InterLocker();
            this.dataProtocol     = socketProtocol ?? new DataProtocol();
            this.Id = NextId.Next();
        }
コード例 #5
0
ファイル: FunctionHost.cs プロジェクト: seunnuga93/jlik.me
        public static async Task <HttpResponseMessage> ShortenUrl(
            [HttpTrigger(AuthorizationLevel.Function, "post")] HttpRequestMessage req,
            [Table(Utility.TABLE, "1", Utility.KEY, Take = 1)] NextId keyTable,
            [Table(Utility.TABLE)] CloudTable tableOut,
            ILogger log)
        {
            log.LogInformation($"C# triggered function called with req: {req}");

            if (req == null)
            {
                return(req.CreateResponse(HttpStatusCode.NotFound));
            }

            var check = SecurityCheck(req);

            if (check != null)
            {
                return(check);
            }

            ShortRequest input = await req.Content.ReadAsAsync <ShortRequest>();

            if (input == null)
            {
                return(req.CreateResponse(HttpStatusCode.NotFound));
            }

            try
            {
                var result    = new List <ShortResponse>();
                var analytics = new Analytics();

                // determine whether or not to process analytics tags
                bool tagMediums = analytics.Validate(input);

                var campaign = string.IsNullOrWhiteSpace(input.Campaign) ? DefaultCampaign : input.Campaign;
                var url      = input.Input.Trim();
                var utm      = analytics.TagUtm(input);
                var wt       = analytics.TagWt(input);

                log.LogInformation($"URL: {url} Tag UTM? {utm} Tag WebTrends? {wt}");
                log.LogInformation($"Current key: {keyTable.Id}");

                // get host for building short URL
                var host = req.RequestUri.GetLeftPart(UriPartial.Authority);

                // strategy for getting a new code
                string getCode() => Utility.Encode(keyTable.Id++);

                // strategy for logging
                void logFn(string msg) => log.LogInformation(msg);

                // strategy to save the key
                async Task saveKeyAsync()
                {
                    var operation = TableOperation.Replace(keyTable);
                    await tableOut.ExecuteAsync(operation);
                }

                // strategy to insert the new short url entry
                async Task saveEntryAsync(TableEntity entry)
                {
                    var operation       = TableOperation.Insert(entry);
                    var operationResult = await tableOut.ExecuteAsync(operation);
                }

                // strategy to create a new URL and track the dependencies
                async Task saveWithTelemetryAsync(TableEntity entry)
                {
                    await TrackDependencyAsync(
                        "AzureTableStorageInsert",
                        "Insert",
                        async() => await saveEntryAsync(entry),
                        () => true);
                    await TrackDependencyAsync(
                        "AzureTableStorageUpdate",
                        "Update",
                        async() => await saveKeyAsync(),
                        () => true);
                }

                if (tagMediums)
                {
                    // this will result in multiple entries depending on the number of
                    // mediums passed in
                    result.AddRange(await analytics.BuildAsync(
                                        input,
                                        Source,
                                        host,
                                        getCode,
                                        saveWithTelemetryAsync,
                                        logFn,
                                        HttpUtility.ParseQueryString));
                }
                else
                {
                    // no tagging, just pass-through the URL
                    result.Add(await Utility.SaveUrlAsync(
                                   url,
                                   null,
                                   host,
                                   getCode,
                                   logFn,
                                   saveWithTelemetryAsync));
                }

                log.LogInformation($"Done.");
                return(req.CreateResponse(HttpStatusCode.OK, result));
            }
            catch (Exception ex)
            {
                log.LogError(ex, "An unexpected error was encountered.");
                return(req.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }