Пример #1
0
        public static async Task <string> GenerateHashAsync(Guid diagramId)
        {
            var result = string.Empty;

            using (DocumentDBContext docdb = new DocumentDBContext())
            {
                var id = diagramId.ToString().ToUpperInvariant();
                // var doc = await docdb.GetItemAsync<dynamic>(id, DiagramCollection);


                var input = string.Format("{0}{1}", Guid.NewGuid().ToString(), id.ToString());

                var sha        = new SHA256CryptoServiceProvider();
                var buffer     = Encoding.ASCII.GetBytes(input);
                var hash       = sha.ComputeHash(buffer);
                var hashString = string.Empty;
                foreach (var b in hash)
                {
                    hashString += b.ToString("X2");
                }
                var hashResult = new SharedDocumentResult()
                {
                    Id        = hashString,
                    DiagramId = id
                };
                var     json    = JsonConvert.SerializeObject(hashResult);
                dynamic success = await docdb.InsertOrUpdateItemAsync(DiagramCollection, json);

                result = hashResult.Id;
            }
            return(result);
        }
Пример #2
0
 /// <summary>
 /// Updates an existing diagram in the Diagrams collection
 /// NOTE: the Diagram JSON must have the id attribute or an exception will occur
 /// </summary>
 /// <param name="id"></param>
 /// <param name="diagram"></param>
 /// <returns></returns>
 static public async Task<string> UpdateDiagramAsync(string diagram)
 {
     string diagramId = string.Empty;
     try
     {
         using (DocumentDBContext docdb = new DocumentDBContext())
         {
             diagramId = await docdb.InsertOrUpdateItemAsync(DiagramCollection, diagram);
         }
     }
     catch
     {
         // handle exception...                
     }
     return diagramId;
 }
Пример #3
0
 public static bool SaveDiagram(string doc)
 {
     dynamic rtnValue = false;
     try
     {
         using (DocumentDBContext docdb = new DocumentDBContext())
         {
             rtnValue = docdb.InsertOrUpdateItemAsync("AzureLensColl", doc);
         }
     }
     catch
     {
         // handle exception...
     }
     return rtnValue;
 }
Пример #4
0
        /// <summary>
        /// Updates an existing diagram in the Diagrams collection
        /// NOTE: the Diagram JSON must have the id attribute or an exception will occur
        /// </summary>
        /// <param name="id"></param>
        /// <param name="diagram"></param>
        /// <returns></returns>
        static public async Task <string> UpdateDiagramAsync(string diagram)
        {
            string diagramId = string.Empty;

            try
            {
                using (DocumentDBContext docdb = new DocumentDBContext())
                {
                    diagramId = await docdb.InsertOrUpdateItemAsync(DiagramCollection, diagram);
                }
            }
            catch
            {
                // handle exception...
            }
            return(diagramId);
        }
Пример #5
0
        public static async Task<string> GenerateHashAsync(Guid diagramId)
        {
            var result = string.Empty;
            using (DocumentDBContext docdb = new DocumentDBContext())
            {
                var id = diagramId.ToString().ToUpperInvariant();
              // var doc = await docdb.GetItemAsync<dynamic>(id, DiagramCollection);

              
                    var input = string.Format("{0}{1}", Guid.NewGuid().ToString(), id.ToString());

                    var sha = new SHA256CryptoServiceProvider();
                    var buffer = Encoding.ASCII.GetBytes(input);
                    var hash = sha.ComputeHash(buffer);
                    var hashString = string.Empty;
                    foreach (var b in hash)
                    {
                        hashString += b.ToString("X2");
                    }
                    var hashResult = new SharedDocumentResult()
                    {
                        Id = hashString,
                        DiagramId = id
                    };
                    var json = JsonConvert.SerializeObject(hashResult);
                    dynamic success = await docdb.InsertOrUpdateItemAsync(DiagramCollection, json);
                   
                        result = hashResult.Id;
                    
              
            }
            return result;
        }